17
17
package com .android .development ;
18
18
19
19
import android .app .Activity ;
20
+ import android .app .ActivityManagerNative ;
21
+ import android .app .IActivityController ;
22
+ import android .app .IActivityManager ;
20
23
import android .app .Service ;
21
24
import android .content .BroadcastReceiver ;
22
25
import android .content .Context ;
@@ -45,8 +48,9 @@ private static class BadBehaviorException extends RuntimeException {
45
48
public static class BadReceiver extends BroadcastReceiver {
46
49
@ Override
47
50
public void onReceive (Context context , Intent intent ) {
48
- Log .i (TAG , "in BadReceiver.onReceive() -- about to hang" );
51
+ Log .i (TAG , "in broadcast receiver -- about to hang" );
49
52
try { Thread .sleep (20000 ); } catch (InterruptedException e ) { Log .wtf (TAG , e ); }
53
+ Log .i (TAG , "broadcast receiver hang finished -- returning" );
50
54
}
51
55
};
52
56
@@ -58,20 +62,63 @@ public IBinder onBind(Intent intent) {
58
62
59
63
@ Override
60
64
public int onStartCommand (Intent intent , int flags , int id ) {
61
- Log .i (TAG , "in BadService.onStartCommand() -- about to hang" );
65
+ Log .i (TAG , "in service start -- about to hang" );
62
66
try { Thread .sleep (30000 ); } catch (InterruptedException e ) { Log .wtf (TAG , e ); }
67
+ Log .i (TAG , "service hang finished -- stopping and returning" );
63
68
stopSelf ();
64
69
return START_NOT_STICKY ;
65
70
}
66
71
}
67
72
73
+ public static class BadController extends IActivityController .Stub {
74
+ private int mDelay ;
75
+
76
+ public BadController (int delay ) { mDelay = delay ; }
77
+
78
+ public boolean activityStarting (Intent intent , String pkg ) {
79
+ try {
80
+ ActivityManagerNative .getDefault ().setActivityController (null );
81
+ } catch (RemoteException e ) {
82
+ Log .e (TAG , "Can't call IActivityManager.setActivityController" , e );
83
+ }
84
+
85
+ if (mDelay > 0 ) {
86
+ Log .i (TAG , "in activity controller -- about to hang" );
87
+ try { Thread .sleep (mDelay ); } catch (InterruptedException e ) { Log .wtf (TAG , e ); }
88
+ Log .i (TAG , "activity controller hang finished -- disabling and returning" );
89
+ mDelay = 0 ;
90
+ }
91
+
92
+ return true ;
93
+ }
94
+
95
+ public boolean activityResuming (String pkg ) {
96
+ return true ;
97
+ }
98
+
99
+ public boolean appCrashed (String proc , int pid , String m , String m2 , long time , String st ) {
100
+ return true ;
101
+ }
102
+
103
+ public int appNotResponding (String proc , int pid , String st ) {
104
+ return 0 ;
105
+ }
106
+ }
107
+
68
108
@ Override
69
109
public void onCreate (Bundle icicle ) {
70
110
super .onCreate (icicle );
71
111
72
112
if (getIntent ().getBooleanExtra ("anr" , false )) {
73
113
Log .i (TAG , "in ANR activity -- about to hang" );
74
114
try { Thread .sleep (20000 ); } catch (InterruptedException e ) { Log .wtf (TAG , e ); }
115
+ Log .i (TAG , "activity hang finished -- finishing" );
116
+ finish ();
117
+ return ;
118
+ }
119
+
120
+ if (getIntent ().getBooleanExtra ("dummy" , false )) {
121
+ Log .i (TAG , "in dummy activity -- finishing" );
75
122
finish ();
76
123
return ;
77
124
}
@@ -127,6 +174,7 @@ public void onClick(View v) {
127
174
public void onClick (View v ) {
128
175
Log .i (TAG , "ANR pressed -- about to hang" );
129
176
try { Thread .sleep (20000 ); } catch (InterruptedException e ) { Log .wtf (TAG , e ); }
177
+ Log .i (TAG , "hang finished -- returning" );
130
178
}
131
179
});
132
180
@@ -154,5 +202,35 @@ public void onClick(View v) {
154
202
startService (new Intent (BadBehaviorActivity .this , BadService .class ));
155
203
}
156
204
});
205
+
206
+ Button anr_system = (Button ) findViewById (R .id .bad_behavior_anr_system );
207
+ anr_system .setOnClickListener (new View .OnClickListener () {
208
+ public void onClick (View v ) {
209
+ Intent intent = new Intent (BadBehaviorActivity .this , BadBehaviorActivity .class );
210
+ Log .i (TAG , "ANR system pressed -- about to engage" );
211
+ try {
212
+ ActivityManagerNative .getDefault ().setActivityController (
213
+ new BadController (20000 ));
214
+ } catch (RemoteException e ) {
215
+ Log .e (TAG , "Can't call IActivityManager.setActivityController" , e );
216
+ }
217
+ startActivity (intent .putExtra ("dummy" , true ));
218
+ }
219
+ });
220
+
221
+ Button wedge_system = (Button ) findViewById (R .id .bad_behavior_wedge_system );
222
+ wedge_system .setOnClickListener (new View .OnClickListener () {
223
+ public void onClick (View v ) {
224
+ Intent intent = new Intent (BadBehaviorActivity .this , BadBehaviorActivity .class );
225
+ Log .i (TAG , "Wedge system pressed -- about to engage" );
226
+ try {
227
+ ActivityManagerNative .getDefault ().setActivityController (
228
+ new BadController (300000 ));
229
+ } catch (RemoteException e ) {
230
+ Log .e (TAG , "Can't call IActivityManager.setActivityController" , e );
231
+ }
232
+ startActivity (intent .putExtra ("dummy" , true ));
233
+ }
234
+ });
157
235
}
158
236
}
0 commit comments