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.
This commit is contained in:
@@ -161,11 +161,18 @@
|
|||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="BadBehaviorActivity" android:label="Bad Behavior">
|
<activity android:name="BadBehaviorActivity" android:label="Bad Behavior">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.TEST" />
|
<category android:name="android.intent.category.TEST" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</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>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -44,4 +44,19 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/bad_behavior_anr_label" />
|
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>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -199,5 +199,8 @@
|
|||||||
<string name="bad_behavior_crash_main_label">Crash the main app thread</string>
|
<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_crash_thread_label">Crash an auxiliary app thread</string>
|
||||||
<string name="bad_behavior_wtf_label">Report a WTF condition</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>
|
</resources>
|
||||||
|
|||||||
@@ -17,6 +17,11 @@
|
|||||||
package com.android.development;
|
package com.android.development;
|
||||||
|
|
||||||
import android.app.Activity;
|
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.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.IPowerManager;
|
import android.os.IPowerManager;
|
||||||
@@ -27,16 +32,49 @@ import android.view.View;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
public class BadBehaviorActivity extends Activity {
|
public class BadBehaviorActivity extends Activity {
|
||||||
static class BadBehaviorException extends RuntimeException {
|
private static final String TAG = "BadBehaviorActivity";
|
||||||
|
|
||||||
|
private static class BadBehaviorException extends RuntimeException {
|
||||||
BadBehaviorException() {
|
BadBehaviorException() {
|
||||||
super("Whatcha gonna do, whatcha gonna do",
|
super("Whatcha gonna do, whatcha gonna do",
|
||||||
new IllegalStateException("When they come for you"));
|
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
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(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);
|
setContentView(R.layout.bad_behavior);
|
||||||
|
|
||||||
Button crash_system = (Button) findViewById(R.id.bad_behavior_crash_system);
|
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);
|
IPowerManager pm = IPowerManager.Stub.asInterface(b);
|
||||||
pm.crash("Crashed by BadBehaviorActivity");
|
pm.crash("Crashed by BadBehaviorActivity");
|
||||||
} catch (RemoteException e) {
|
} 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);
|
Button wtf = (Button) findViewById(R.id.bad_behavior_wtf);
|
||||||
wtf.setOnClickListener(new View.OnClickListener() {
|
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);
|
Button anr = (Button) findViewById(R.id.bad_behavior_anr);
|
||||||
anr.setOnClickListener(new View.OnClickListener() {
|
anr.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
try {
|
Log.i(TAG, "ANR pressed -- about to hang");
|
||||||
Thread.sleep(20000);
|
try { Thread.sleep(20000); } catch (InterruptedException e) { Log.wtf(TAG, e); }
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new IllegalStateException(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));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user