Merge "Add exponential broadcast flood to the BadBehaviorActivity." into nyc-dev

am: b91c55da77

* commit 'b91c55da77dc267c38e4472661682373acceda2e':
  Add exponential broadcast flood to the BadBehaviorActivity.

Change-Id: I01ba323e6f8947ca025331528a3d83a5ccf426a1
This commit is contained in:
Joe Onorato
2016-04-21 22:42:16 +00:00
committed by android-build-merger
3 changed files with 46 additions and 0 deletions

View File

@@ -78,6 +78,11 @@
android:layout_height="wrap_content"
android:text="@string/bad_behavior_wedge_system_label" />
<Button android:id="@+id/bad_behavior_broadcast_flood"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bad_behavior_broadcast_flood" />
</LinearLayout>
</ScrollView>

View File

@@ -229,6 +229,7 @@
<string name="bad_behavior_anr_service_label">ANR starting a Service</string>
<string name="bad_behavior_anr_system_label">System ANR (in ActivityManager)</string>
<string name="bad_behavior_wedge_system_label">Wedge system (5 minute system ANR)</string>
<string name="bad_behavior_broadcast_flood">Flood the system with broadcasts</string>
<!-- CacheAbuser -->
<string name="cache_abuser_start_internal_abuse">Quickly abuse internal cache</string>

View File

@@ -26,6 +26,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IPowerManager;
import android.os.Process;
@@ -38,6 +39,10 @@ import android.widget.Button;
public class BadBehaviorActivity extends Activity {
private static final String TAG = "BadBehaviorActivity";
private static final String BROADCAST_FLOOD = "com.android.development.BROADCAST_FLOOD";
private Handler mHandler = new Handler();
private static class BadBehaviorException extends RuntimeException {
BadBehaviorException() {
super("Whatcha gonna do, whatcha gonna do",
@@ -113,6 +118,25 @@ public class BadBehaviorActivity extends Activity {
}
}
int mFloodBroadcastsSent;
int mFloodBroadcastsReceived;
public class ExponentialReceiver extends BroadcastReceiver {
String name;
@Override
public void onReceive(Context context, Intent intent) {
final int N = 5;
mFloodBroadcastsReceived++;
for (int i=0; i<N; i++) {
mFloodBroadcastsSent++;
Log.i(TAG, this.name + " sent=" + mFloodBroadcastsSent
+ " received=" + mFloodBroadcastsReceived);
context.sendBroadcast(new Intent(BROADCAST_FLOOD));
}
}
};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -240,5 +264,21 @@ public class BadBehaviorActivity extends Activity {
startActivity(intent.putExtra("dummy", true));
}
});
Button broadcast_flood = (Button) findViewById(R.id.bad_behavior_broadcast_flood);
broadcast_flood.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Let's create and register some broadcast receivers
IntentFilter filter = new IntentFilter(BROADCAST_FLOOD);
for (int i=0; i<30; i++) {
ExponentialReceiver receiver = new ExponentialReceiver();
receiver.name = "ExponentialReceiver " + i;
registerReceiver(receiver, filter);
}
// Now open the floodgates
mFloodBroadcastsSent = 1;
sendBroadcast(new Intent(BROADCAST_FLOOD));
}
});
}
}