Expand BadBehaviorActivity to add a few new flavors of ANR.

In addition to the basic sleep-for-20, add activity launch,
ordered broadcast, and service start that go to special bad
versions that sleep for a while to cause the respective sorts
of ANR to trigger.
diff --git a/apps/Development/AndroidManifest.xml b/apps/Development/AndroidManifest.xml
index 823130b..3c75a63 100644
--- a/apps/Development/AndroidManifest.xml
+++ b/apps/Development/AndroidManifest.xml
@@ -161,11 +161,18 @@
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </activity>
+
         <activity android:name="BadBehaviorActivity" android:label="Bad Behavior">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.TEST" />
             </intent-filter>
         </activity>
+        <receiver android:name="BadBehaviorActivity$BadReceiver">
+            <intent-filter>
+                <action android:name="com.android.development.BAD_BEHAVIOR" />
+            </intent-filter>
+        </receiver>
+        <service android:name="BadBehaviorActivity$BadService" />
     </application>
 </manifest>
diff --git a/apps/Development/res/layout/bad_behavior.xml b/apps/Development/res/layout/bad_behavior.xml
index bbc5b9f..72275ae 100644
--- a/apps/Development/res/layout/bad_behavior.xml
+++ b/apps/Development/res/layout/bad_behavior.xml
@@ -44,4 +44,19 @@
             android:layout_height="wrap_content"
             android:text="@string/bad_behavior_anr_label" />
 
+    <Button android:id="@+id/bad_behavior_anr_activity"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/bad_behavior_anr_activity_label" />
+
+    <Button android:id="@+id/bad_behavior_anr_broadcast"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/bad_behavior_anr_broadcast_label" />
+
+    <Button android:id="@+id/bad_behavior_anr_service"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/bad_behavior_anr_service_label" />
+
 </LinearLayout>
diff --git a/apps/Development/res/values/strings.xml b/apps/Development/res/values/strings.xml
index 128144e..d0fd50f 100644
--- a/apps/Development/res/values/strings.xml
+++ b/apps/Development/res/values/strings.xml
@@ -199,5 +199,8 @@
     <string name="bad_behavior_crash_main_label">Crash the main app thread</string>
     <string name="bad_behavior_crash_thread_label">Crash an auxiliary app thread</string>
     <string name="bad_behavior_wtf_label">Report a WTF condition</string>
-    <string name="bad_behavior_anr_label">Stop responding for 20 seconds (ANR)</string>
+    <string name="bad_behavior_anr_label">ANR (Stop responding for 20 seconds)</string>
+    <string name="bad_behavior_anr_activity_label">ANR launching a new Activity</string>
+    <string name="bad_behavior_anr_broadcast_label">ANR receiving a broadcast Intent</string>
+    <string name="bad_behavior_anr_service_label">ANR starting a Service</string>
 </resources>
diff --git a/apps/Development/src/com/android/development/BadBehaviorActivity.java b/apps/Development/src/com/android/development/BadBehaviorActivity.java
index d397456..aede60b 100644
--- a/apps/Development/src/com/android/development/BadBehaviorActivity.java
+++ b/apps/Development/src/com/android/development/BadBehaviorActivity.java
@@ -17,6 +17,11 @@
 package com.android.development;
 
 import android.app.Activity;
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.IPowerManager;
@@ -27,16 +32,49 @@
 import android.widget.Button;
 
 public class BadBehaviorActivity extends Activity {
-    static class BadBehaviorException extends RuntimeException {
+    private static final String TAG = "BadBehaviorActivity";
+
+    private static class BadBehaviorException extends RuntimeException {
         BadBehaviorException() {
             super("Whatcha gonna do, whatcha gonna do",
                     new IllegalStateException("When they come for you"));
         }
     }
 
+    public static class BadReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            Log.i(TAG, "in BadReceiver.onReceive() -- about to hang");
+            try { Thread.sleep(20000); } catch (InterruptedException e) { Log.wtf(TAG, e); }
+        }
+    };
+
+    public static class BadService extends Service {
+        @Override
+        public IBinder onBind(Intent intent) {
+            return null;
+        }
+
+        @Override
+        public int onStartCommand(Intent intent, int flags, int id) {
+            Log.i(TAG, "in BadService.onStartCommand() -- about to hang");
+            try { Thread.sleep(30000); } catch (InterruptedException e) { Log.wtf(TAG, e); }
+            stopSelf();
+            return START_NOT_STICKY;
+        }
+    }
+
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
+
+        if (getIntent().getBooleanExtra("anr", false)) {
+            Log.i(TAG, "in ANR activity -- about to hang");
+            try { Thread.sleep(20000); } catch (InterruptedException e) { Log.wtf(TAG, e); }
+            finish();
+            return;
+        }
+
         setContentView(R.layout.bad_behavior);
 
         Button crash_system = (Button) findViewById(R.id.bad_behavior_crash_system);
@@ -47,7 +85,7 @@
                     IPowerManager pm = IPowerManager.Stub.asInterface(b);
                     pm.crash("Crashed by BadBehaviorActivity");
                 } catch (RemoteException e) {
-                    Log.e("BadBehavior", "Can't call IPowerManager.crash()", e);
+                    Log.e(TAG, "Can't call IPowerManager.crash()", e);
                 }
             }
         });
@@ -69,17 +107,39 @@
 
         Button wtf = (Button) findViewById(R.id.bad_behavior_wtf);
         wtf.setOnClickListener(new View.OnClickListener() {
-            public void onClick(View v) { Log.wtf("BadBehavior", "Apps Behaving Badly"); }
+            public void onClick(View v) { Log.wtf(TAG, "Apps Behaving Badly"); }
         });
 
         Button anr = (Button) findViewById(R.id.bad_behavior_anr);
         anr.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
-                try {
-                    Thread.sleep(20000);
-                } catch (InterruptedException e) {
-                    throw new IllegalStateException(e);
-                }
+                Log.i(TAG, "ANR pressed -- about to hang");
+                try { Thread.sleep(20000); } catch (InterruptedException e) { Log.wtf(TAG, e); }
+            }
+        });
+
+        Button anr_activity = (Button) findViewById(R.id.bad_behavior_anr_activity);
+        anr_activity.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                Intent intent = new Intent(BadBehaviorActivity.this, BadBehaviorActivity.class);
+                Log.i(TAG, "ANR activity pressed -- about to launch");
+                startActivity(intent.putExtra("anr", true));
+            }
+        });
+
+        Button anr_broadcast = (Button) findViewById(R.id.bad_behavior_anr_broadcast);
+        anr_broadcast.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                Log.i(TAG, "ANR broadcast pressed -- about to send");
+                sendOrderedBroadcast(new Intent("com.android.development.BAD_BEHAVIOR"), null);
+            }
+        });
+
+        Button anr_service = (Button) findViewById(R.id.bad_behavior_anr_service);
+        anr_service.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                Log.i(TAG, "ANR service pressed -- about to start");
+                startService(new Intent(BadBehaviorActivity.this, BadService.class));
             }
         });
     }