diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-07-12 14:50:08 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2012-07-12 14:50:08 -0700 |
commit | 5b6b54020711fcd54c6d500908675c8aba525a18 (patch) | |
tree | fe1eb47a1a5b1132c0b8a2b6149334d718bb5d8d /apps/Development | |
parent | 15060a5ca7f2455a3674792ae8b94536c913174e (diff) | |
download | android_development-5b6b54020711fcd54c6d500908675c8aba525a18.tar.gz android_development-5b6b54020711fcd54c6d500908675c8aba525a18.tar.bz2 android_development-5b6b54020711fcd54c6d500908675c8aba525a18.zip |
New development tool for creating cache files.
Change-Id: I5d4bc5f41a08225a618f68b7afb3b5b3037d96d6
Diffstat (limited to 'apps/Development')
-rw-r--r-- | apps/Development/AndroidManifest.xml | 8 | ||||
-rw-r--r-- | apps/Development/res/layout/bad_behavior.xml | 2 | ||||
-rw-r--r-- | apps/Development/res/layout/cache_abuser.xml | 53 | ||||
-rw-r--r-- | apps/Development/res/values/strings.xml | 7 | ||||
-rw-r--r-- | apps/Development/src/com/android/development/CacheAbuser.java | 190 |
5 files changed, 259 insertions, 1 deletions
diff --git a/apps/Development/AndroidManifest.xml b/apps/Development/AndroidManifest.xml index f2bf60ceb..32738dd33 100644 --- a/apps/Development/AndroidManifest.xml +++ b/apps/Development/AndroidManifest.xml @@ -38,6 +38,7 @@ <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" /> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="com.google.android.googleapps.permission.ACCESS_GOOGLE_PASSWORD" /> <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" /> <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.ALL_SERVICES" /> @@ -169,6 +170,13 @@ </receiver> <service android:name="BadBehaviorActivity$BadService" /> + <activity android:name="CacheAbuser" android:label="Cache Abuser"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.TEST" /> + </intent-filter> + </activity> + <activity android:name="ConfigurationViewer" android:label="Configuration"> <intent-filter> <action android:name="android.intent.action.MAIN" /> diff --git a/apps/Development/res/layout/bad_behavior.xml b/apps/Development/res/layout/bad_behavior.xml index ce10ebba5..6415da679 100644 --- a/apps/Development/res/layout/bad_behavior.xml +++ b/apps/Development/res/layout/bad_behavior.xml @@ -21,7 +21,7 @@ <LinearLayout android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="wrap_content"> <Button android:id="@+id/bad_behavior_crash_main" android:layout_width="match_parent" diff --git a/apps/Development/res/layout/cache_abuser.xml b/apps/Development/res/layout/cache_abuser.xml new file mode 100644 index 000000000..8e212a94c --- /dev/null +++ b/apps/Development/res/layout/cache_abuser.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2012 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. +--> + +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <Button android:id="@+id/start_internal_abuse" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/cache_abuser_start_internal_abuse" /> + + <Button android:id="@+id/start_slow_internal_abuse" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/cache_abuser_start_slow_internal_abuse" /> + + <Button android:id="@+id/start_external_abuse" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/cache_abuser_start_external_abuse" /> + + <Button android:id="@+id/start_slow_external_abuse" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/cache_abuser_start_slow_external_abuse" /> + + <Button android:id="@+id/stop_abuse" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/cache_abuser_stop_abuse" /> + + </LinearLayout> + +</ScrollView> diff --git a/apps/Development/res/values/strings.xml b/apps/Development/res/values/strings.xml index 0f4763cb1..10879316f 100644 --- a/apps/Development/res/values/strings.xml +++ b/apps/Development/res/values/strings.xml @@ -220,6 +220,13 @@ <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> + <!-- CacheAbuser --> + <string name="cache_abuser_start_internal_abuse">Quickly abuse internal cache</string> + <string name="cache_abuser_start_slow_internal_abuse">Slowly abuse internal cache</string> + <string name="cache_abuser_start_external_abuse">Quickly abuse external cache</string> + <string name="cache_abuser_start_slow_external_abuse">Slowly abuse external cache</string> + <string name="cache_abuser_stop_abuse">Stop cache abuse</string> + <!-- MediaScannerActivity --> <string name="scancard">Scan SD card</string> <string name="numsongs"># of albums</string> diff --git a/apps/Development/src/com/android/development/CacheAbuser.java b/apps/Development/src/com/android/development/CacheAbuser.java new file mode 100644 index 000000000..489018f32 --- /dev/null +++ b/apps/Development/src/com/android/development/CacheAbuser.java @@ -0,0 +1,190 @@ +/* + * 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 java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +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.AsyncTask; +import android.os.Bundle; +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 CacheAbuser extends Activity { + Button mStartInternalAbuse; + Button mStartSlowInternalAbuse; + Button mStartExternalAbuse; + Button mStartSlowExternalAbuse; + Button mStopAbuse; + + AsyncTask<Void, Void, Void> mInternalAbuseTask; + AsyncTask<Void, Void, Void> mExternalAbuseTask; + + static class AbuseTask extends AsyncTask<Void, Void, Void> { + final File mBaseDir; + final boolean mQuick; + final byte[] mBuffer; + + AbuseTask(File cacheDir, boolean quick) { + File dir = new File(cacheDir, quick ? "quick" : "slow"); + mBaseDir = new File(dir, Long.toString(System.currentTimeMillis())); + mQuick = quick; + mBuffer = quick ? new byte[1024*1024] : new byte[1024]; + } + + @Override + protected Void doInBackground(Void... params) { + long num = 0; + while (!isCancelled()) { + long dir1num = num/100; + long dir2num = num%100; + File dir = new File(mBaseDir, Long.toString(dir1num)); + File file = new File(dir, Long.toString(dir2num)); + FileOutputStream fos = null; + try { + dir.mkdirs(); + fos = new FileOutputStream(file, false); + fos.write(mBuffer); + } catch (IOException e) { + Log.w("CacheAbuser", "Write failed to " + file + ": " + e); + try { + wait(5*1000); + } catch (InterruptedException e1) { + } + } finally { + try { + if (fos != null) { + fos.close(); + } + } catch (IOException e) { + } + } + num++; + } + return null; + } + } + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + setContentView(R.layout.cache_abuser); + + mStartInternalAbuse = (Button) findViewById(R.id.start_internal_abuse); + mStartInternalAbuse.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + if (mInternalAbuseTask == null) { + mInternalAbuseTask = new AbuseTask(getCacheDir(), true); + mInternalAbuseTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + updateButtonState(); + } + } + }); + + mStartSlowInternalAbuse = (Button) findViewById(R.id.start_slow_internal_abuse); + mStartSlowInternalAbuse.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + if (mInternalAbuseTask == null) { + mInternalAbuseTask = new AbuseTask(getCacheDir(), false); + mInternalAbuseTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + updateButtonState(); + } + } + }); + + mStartExternalAbuse = (Button) findViewById(R.id.start_external_abuse); + mStartExternalAbuse.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + if (mExternalAbuseTask == null) { + mExternalAbuseTask = new AbuseTask(getExternalCacheDir(), true); + mExternalAbuseTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + updateButtonState(); + } + } + }); + + mStartSlowExternalAbuse = (Button) findViewById(R.id.start_slow_external_abuse); + mStartSlowExternalAbuse.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + if (mExternalAbuseTask == null) { + mExternalAbuseTask = new AbuseTask(getExternalCacheDir(), false); + mExternalAbuseTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + updateButtonState(); + } + } + }); + + mStopAbuse = (Button) findViewById(R.id.stop_abuse); + mStopAbuse.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + stopAbuse(); + } + }); + + updateButtonState(); + } + + @Override + public void onStart() { + super.onStart(); + updateButtonState(); + } + + @Override + public void onStop() { + super.onStop(); + stopAbuse(); + } + + void stopAbuse() { + if (mInternalAbuseTask != null) { + mInternalAbuseTask.cancel(false); + mInternalAbuseTask = null; + } + if (mExternalAbuseTask != null) { + mExternalAbuseTask.cancel(false); + mExternalAbuseTask = null; + } + updateButtonState(); + } + + void updateButtonState() { + mStartInternalAbuse.setEnabled(mInternalAbuseTask == null); + mStartSlowInternalAbuse.setEnabled(mInternalAbuseTask == null); + mStartExternalAbuse.setEnabled(mExternalAbuseTask == null); + mStartSlowExternalAbuse.setEnabled(mExternalAbuseTask == null); + mStopAbuse.setEnabled(mInternalAbuseTask != null + || mExternalAbuseTask != null); + } +} |