summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Egnor <egnor@google.com>2010-01-07 21:17:24 -0800
committerDan Egnor <egnor@google.com>2010-01-07 21:17:24 -0800
commitb4e39aebf6b27aa0ed094a75bde8b2bacda28d98 (patch)
tree76a6420335b703de46ec66f2b9d8c247c24ef4ce
parentf1474e5399192d2eea8ee3a497575057356abc9c (diff)
downloadandroid_development-b4e39aebf6b27aa0ed094a75bde8b2bacda28d98.tar.gz
android_development-b4e39aebf6b27aa0ed094a75bde8b2bacda28d98.tar.bz2
android_development-b4e39aebf6b27aa0ed094a75bde8b2bacda28d98.zip
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.
-rw-r--r--apps/Development/AndroidManifest.xml7
-rw-r--r--apps/Development/res/layout/bad_behavior.xml15
-rw-r--r--apps/Development/res/values/strings.xml5
-rw-r--r--apps/Development/src/com/android/development/BadBehaviorActivity.java76
4 files changed, 94 insertions, 9 deletions
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 @@
<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 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" />
+ <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 128144e1e..d0fd50ffe 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 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));
}
});
}