/* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.development; import android.app.Activity; import android.app.ActivityManagerNative; import android.app.IActivityController; import android.app.IActivityManager; 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.Handler; import android.os.IBinder; import android.os.IPowerManager; import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; import android.util.Log; import android.view.View; 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", 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 broadcast receiver -- about to hang"); try { Thread.sleep(20000); } catch (InterruptedException e) { Log.wtf(TAG, e); } Log.i(TAG, "broadcast receiver hang finished -- returning"); } }; 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 service start -- about to hang"); try { Thread.sleep(30000); } catch (InterruptedException e) { Log.wtf(TAG, e); } Log.i(TAG, "service hang finished -- stopping and returning"); stopSelf(); return START_NOT_STICKY; } } public static class BadController extends IActivityController.Stub { private int mDelay; public BadController(int delay) { mDelay = delay; } public boolean activityStarting(Intent intent, String pkg) { try { ActivityManagerNative.getDefault().setActivityController(null, false); } catch (RemoteException e) { Log.e(TAG, "Can't call IActivityManager.setActivityController", e); } if (mDelay > 0) { Log.i(TAG, "in activity controller -- about to hang"); try { Thread.sleep(mDelay); } catch (InterruptedException e) { Log.wtf(TAG, e); } Log.i(TAG, "activity controller hang finished -- disabling and returning"); mDelay = 0; } return true; } public boolean activityResuming(String pkg) { return true; } public boolean appCrashed(String proc, int pid, String m, String m2, long time, String st) { return true; } public int appEarlyNotResponding(String processName, int pid, String annotation) { return 0; } public int appNotResponding(String proc, int pid, String st) { return 0; } public int systemNotResponding(String message) { return 0; } } 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