diff --git a/apps/Development/AndroidManifest.xml b/apps/Development/AndroidManifest.xml
index 823130b7e..3c75a6358 100644
--- a/apps/Development/AndroidManifest.xml
+++ b/apps/Development/AndroidManifest.xml
@@ -161,11 +161,18 @@
+
+
+
+
+
+
+
diff --git a/apps/Development/res/layout/bad_behavior.xml b/apps/Development/res/layout/bad_behavior.xml
index bbc5b9f06..72275aeb1 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" />
+
+
+
+
+
+
diff --git a/apps/Development/res/values/strings.xml b/apps/Development/res/values/strings.xml
index 128144e1e..d0fd50ffe 100644
--- a/apps/Development/res/values/strings.xml
+++ b/apps/Development/res/values/strings.xml
@@ -199,5 +199,8 @@
Crash the main app thread
Crash an auxiliary app thread
Report a WTF condition
- Stop responding for 20 seconds (ANR)
+ ANR (Stop responding for 20 seconds)
+ ANR launching a new Activity
+ ANR receiving a broadcast Intent
+ ANR starting a Service
diff --git a/apps/Development/src/com/android/development/BadBehaviorActivity.java b/apps/Development/src/com/android/development/BadBehaviorActivity.java
index d3974560d..aede60b9c 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.view.View;
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 @@ public class BadBehaviorActivity extends Activity {
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 @@ public class BadBehaviorActivity extends Activity {
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));
}
});
}