diff options
-rw-r--r-- | apps/Development/AndroidManifest.xml | 5 | ||||
-rw-r--r-- | cmds/monkey/src/com/android/commands/monkey/Monkey.java | 134 | ||||
-rw-r--r-- | samples/ApiDemos/Android.mk | 2 | ||||
-rw-r--r-- | samples/ApiDemos/tests/Android.mk | 2 | ||||
-rw-r--r-- | sys-img/images_arm64-v8a_source.prop_template | 2 | ||||
-rw-r--r-- | sys-img/images_armeabi-v7a_source.prop_template | 2 | ||||
-rw-r--r-- | sys-img/images_armeabi_source.prop_template | 2 | ||||
-rw-r--r-- | sys-img/images_mips_source.prop_template | 2 | ||||
-rw-r--r-- | sys-img/images_x86_64_source.prop_template | 2 | ||||
-rw-r--r-- | sys-img/images_x86_source.prop_template | 2 | ||||
-rw-r--r-- | tools/idegen/src/Configuration.java | 2 |
11 files changed, 146 insertions, 11 deletions
diff --git a/apps/Development/AndroidManifest.xml b/apps/Development/AndroidManifest.xml index 5847201ae..c1233a6e2 100644 --- a/apps/Development/AndroidManifest.xml +++ b/apps/Development/AndroidManifest.xml @@ -16,7 +16,8 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.development" - android:versionCode="1" android:versionName="1.0"> + android:versionCode="1" android:versionName="1.0" + android:sharedUserId="android.uid.system"> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> @@ -54,7 +55,7 @@ android:icon="@mipmap/ic_launcher_devtools"> <intent-filter> <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> + <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name="PackageBrowser" android:label="Package Browser"> diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java index dfcb4b02c..3e6917e97 100644 --- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java +++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java @@ -49,11 +49,13 @@ import java.io.InputStreamReader; import java.io.Writer; import java.security.SecureRandom; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Random; +import android.app.ActivityManager; /** * Application that injects random key events and other actions into the system. */ @@ -68,6 +70,12 @@ public class Monkey { private final static int DEBUG_ALLOW_ANY_RESTARTS = 0; + private final static String DEFAULT_LAUNCHER_PKG_NAME = + "com.android.launcher"; + + private final static String DEFAULT_LAUNCHER_CLASS_NAME = + "com.android.launcher2.Launcher"; + private IActivityManager mAm; private IWindowManager mWm; @@ -208,6 +216,9 @@ public class Monkey { /** The random number generator **/ Random mRandom = null; + /** Quit after the maximum number of activity launches is reached **/ + long mMaxActivityLaunches = -1; + /** Dropped-event statistics **/ long mDroppedKeyEvents = 0; @@ -225,6 +236,18 @@ public class Monkey { /** Device idle time. This is for the scripted monkey. **/ long mDeviceSleepTime = 30000; + /** The delay after App switch event. **/ + long mAppSwitchDelay = 0; + + /** Ensure Launcher in foreground before launching application */ + boolean mLauchLauncher = false; + + long mLauchLauncherDelay = -1; + + String mLauncherPkgName = null; + + String mLauncherClsName = null; + boolean mRandomizeScript = false; boolean mScriptLog = false; @@ -235,6 +258,9 @@ public class Monkey { /** a filename to the setup script (if any) */ private String mSetupFileName = null; + /** Sort the app list */ + private boolean mSortAppList = false; + /** filenames of the script (if any) */ private ArrayList<String> mScriptFileNames = new ArrayList<String>(); @@ -779,6 +805,15 @@ public class Monkey { mKillProcessAfterError = true; } else if (opt.equals("--hprof")) { mGenerateHprof = true; + } else if(opt.equals("--launch-app-after-launcher")){ + mLauchLauncher = true; + mLauncherPkgName = DEFAULT_LAUNCHER_PKG_NAME; + mLauncherClsName = DEFAULT_LAUNCHER_CLASS_NAME; + } else if(opt.equals("--launch-app-after-app")){ + mLauchLauncher = true; + mLauchLauncherDelay = nextOptionLong("delay (in ms) after app launch"); + mLauncherPkgName = nextOptionData(); + mLauncherClsName = nextOptionData(); } else if (opt.equals("--pct-touch")) { int i = MonkeySourceRandom.FACTOR_TOUCH; mFactors[i] = -nextOptionLong("touch events percentage"); @@ -828,6 +863,8 @@ public class Monkey { mServerPort = (int) nextOptionLong("Server port to listen on for commands"); } else if (opt.equals("--setup")) { mSetupFileName = nextOptionData(); + } else if (opt.equals("--sort-app-list")) { + mSortAppList = true; } else if (opt.equals("-f")) { mScriptFileNames.add(nextOptionData()); } else if (opt.equals("--profile-wait")) { @@ -838,6 +875,8 @@ public class Monkey { "(in milliseconds)"); } else if (opt.equals("--randomize-script")) { mRandomizeScript = true; + } else if (opt.equals("--max-activity-launches")) { + mMaxActivityLaunches = nextOptionLong("max activity launches"); } else if (opt.equals("--script-log")) { mScriptLog = true; } else if (opt.equals("--bugreport")) { @@ -845,6 +884,8 @@ public class Monkey { } else if (opt.equals("--periodic-bugreport")){ mGetPeriodicBugreport = true; mBugreportFrequency = nextOptionLong("Number of iterations"); + } else if (opt.equals("--delay-appswitch")) { + mAppSwitchDelay = nextOptionLong("Delay(in ms) after app switch event"); } else if (opt.equals("-h")) { showUsage(); return false; @@ -1038,6 +1079,16 @@ public class Monkey { return false; } + if (mSortAppList) { + Collections.sort(mMainApps); + if (mVerbose >= 2) { // very verbose + System.out.println("// Sorted main activity list"); + for (ComponentName cn : mMainApps) { + System.out.println("// + Using main activity " + cn); + } + } + } + return true; } @@ -1052,6 +1103,7 @@ public class Monkey { private int runMonkeyCycles() { int eventCounter = 0; int cycleCounter = 0; + int numActivityLaunches = 0; boolean shouldReportAnrTraces = false; boolean shouldReportDumpsysMemInfo = false; @@ -1148,7 +1200,47 @@ public class Monkey { MonkeyEvent ev = mEventSource.getNextEvent(); if (ev != null) { + if (ev instanceof MonkeyActivityEvent && mLauchLauncher) { + launchHomeScreen(); + try { + long delay = mAppSwitchDelay; + if (mLauchLauncherDelay >= 0) { + delay = mLauchLauncherDelay; + } + System.out.println("After Launcher Before app launch sleep " + + delay + " ms"); + Thread.sleep(delay); + } catch (InterruptedException e1) { + System.out.println("Monkey interrupted in sleep after Home Screen Launch."); + } + } + + if ((mMaxActivityLaunches > -1) && (ev instanceof MonkeyActivityEvent)) { + if (numActivityLaunches >= mMaxActivityLaunches) { + if (mVerbose > 0) { + System.out.println("Exit Monkey," + + " reached max number of activity launches:" + + numActivityLaunches); + return eventCounter; + } + } + numActivityLaunches++; + } + int injectCode = ev.injectEvent(mWm, mAm, mVerbose); + + if ((mAppSwitchDelay > 0) && (ev instanceof MonkeyActivityEvent)) { + if (mVerbose > 0) { + System.out.println("After App switch about to sleep " + + mAppSwitchDelay + " ms"); + } + try { + Thread.sleep(mAppSwitchDelay); + } catch (InterruptedException e1) { + System.out.println("** Monkey interrupted in sleep after App switch."); + } + } + if (injectCode == MonkeyEvent.INJECT_FAIL) { System.out.println(" // Injection Failed"); if (ev instanceof MonkeyKeyEvent) { @@ -1198,6 +1290,44 @@ public class Monkey { } /** + * Check for Top Activity if not Home, launch Home + **/ + private void launchHomeScreen() { + //Get Current forground Activity + boolean launcherIsForeground = isLauncherForeground(); + // Launch HomeScreen if it is not the current top activity + if (!launcherIsForeground) { + System.out.println("Launching Home Screen pkg:" + + mLauncherPkgName + " class:" + mLauncherClsName); + ComponentName lauchHomeApp = new ComponentName(mLauncherPkgName, mLauncherClsName); + MonkeyActivityEvent mActEvent = new MonkeyActivityEvent(lauchHomeApp); + mActEvent.injectEvent(mWm, mAm, mVerbose); + } + return; + } + + /** + * Returns true if the launcher is in the foreground + **/ + private boolean isLauncherForeground() { + boolean launcherForeground = false; + try { + List<ActivityManager.RunningAppProcessInfo> mRunningProcessInfo= mAm.getRunningAppProcesses(); + for (ActivityManager.RunningAppProcessInfo pi : mRunningProcessInfo) { + if (pi.processName.equals(mLauncherPkgName) && + pi.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { + launcherForeground = true; + break; + } + } + } catch (Exception e) { + System.out.println("isLauncherForeground Exception, ex:" + e); + e.printStackTrace(); + } + return launcherForeground; + } + + /** * Send SIGNAL_USR1 to all processes. This will generate large (5mb) * profiling reports in data/misc, so use with care. */ @@ -1358,6 +1488,7 @@ public class Monkey { usage.append(" [--setup scriptfile] [-f scriptfile [-f scriptfile] ...]\n"); usage.append(" [--port port]\n"); usage.append(" [-s SEED] [-v [-v] ...]\n"); + usage.append(" [--sort-app-list]\n"); usage.append(" [--throttle MILLISEC] [--randomize-throttle]\n"); usage.append(" [--profile-wait MILLISEC]\n"); usage.append(" [--device-sleep-time MILLISEC]\n"); @@ -1365,6 +1496,9 @@ public class Monkey { usage.append(" [--script-log]\n"); usage.append(" [--bugreport]\n"); usage.append(" [--periodic-bugreport]\n"); + usage.append(" [--delay-appswitch MILLISEC]\n"); + usage.append(" [--launch-app-after-launcher\n"); + usage.append(" [--launch-app-after-app MILLISEC PACKAGE_NAME CLASS_NAME]\n"); usage.append(" COUNT\n"); System.err.println(usage.toString()); } diff --git a/samples/ApiDemos/Android.mk b/samples/ApiDemos/Android.mk index 66100b168..656718f98 100644 --- a/samples/ApiDemos/Android.mk +++ b/samples/ApiDemos/Android.mk @@ -18,7 +18,7 @@ LOCAL_PACKAGE_NAME := ApiDemos LOCAL_SDK_VERSION := current -include $(BUILD_PACKAGE) +#include $(BUILD_PACKAGE) # Use the folloing include to make our test apk. include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/samples/ApiDemos/tests/Android.mk b/samples/ApiDemos/tests/Android.mk index f975662dc..116b4b6ef 100644 --- a/samples/ApiDemos/tests/Android.mk +++ b/samples/ApiDemos/tests/Android.mk @@ -19,5 +19,5 @@ LOCAL_INSTRUMENTATION_FOR := ApiDemos LOCAL_SDK_VERSION := current -include $(BUILD_PACKAGE) +#include $(BUILD_PACKAGE) diff --git a/sys-img/images_arm64-v8a_source.prop_template b/sys-img/images_arm64-v8a_source.prop_template index 1a18cf874..0fa83e91e 100644 --- a/sys-img/images_arm64-v8a_source.prop_template +++ b/sys-img/images_arm64-v8a_source.prop_template @@ -1,6 +1,6 @@ Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION} Pkg.UserSrc=false -Pkg.Revision=1 +Pkg.Revision=3 AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION} AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME} SystemImage.Abi=${TARGET_CPU_ABI} diff --git a/sys-img/images_armeabi-v7a_source.prop_template b/sys-img/images_armeabi-v7a_source.prop_template index 9c7a332a5..9def03da9 100644 --- a/sys-img/images_armeabi-v7a_source.prop_template +++ b/sys-img/images_armeabi-v7a_source.prop_template @@ -1,6 +1,6 @@ Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION} Pkg.UserSrc=false -Pkg.Revision=1 +Pkg.Revision=3 AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION} AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME} SystemImage.Abi=armeabi-v7a diff --git a/sys-img/images_armeabi_source.prop_template b/sys-img/images_armeabi_source.prop_template index 91e9d212f..98281d2db 100644 --- a/sys-img/images_armeabi_source.prop_template +++ b/sys-img/images_armeabi_source.prop_template @@ -1,6 +1,6 @@ Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION} Pkg.UserSrc=false -Pkg.Revision=1 +Pkg.Revision=3 AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION} AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME} SystemImage.Abi=armeabi diff --git a/sys-img/images_mips_source.prop_template b/sys-img/images_mips_source.prop_template index 78dc63f29..a53eb04e5 100644 --- a/sys-img/images_mips_source.prop_template +++ b/sys-img/images_mips_source.prop_template @@ -1,6 +1,6 @@ Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION} Pkg.UserSrc=false -Pkg.Revision=1 +Pkg.Revision=3 AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION} AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME} SystemImage.Abi=mips diff --git a/sys-img/images_x86_64_source.prop_template b/sys-img/images_x86_64_source.prop_template index 1a18cf874..0fa83e91e 100644 --- a/sys-img/images_x86_64_source.prop_template +++ b/sys-img/images_x86_64_source.prop_template @@ -1,6 +1,6 @@ Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION} Pkg.UserSrc=false -Pkg.Revision=1 +Pkg.Revision=3 AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION} AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME} SystemImage.Abi=${TARGET_CPU_ABI} diff --git a/sys-img/images_x86_source.prop_template b/sys-img/images_x86_source.prop_template index 1a18cf874..0fa83e91e 100644 --- a/sys-img/images_x86_source.prop_template +++ b/sys-img/images_x86_source.prop_template @@ -1,6 +1,6 @@ Pkg.Desc=Android SDK Platform ${PLATFORM_VERSION} Pkg.UserSrc=false -Pkg.Revision=1 +Pkg.Revision=3 AndroidVersion.ApiLevel=${PLATFORM_SDK_VERSION} AndroidVersion.CodeName=${PLATFORM_VERSION_CODENAME} SystemImage.Abi=${TARGET_CPU_ABI} diff --git a/tools/idegen/src/Configuration.java b/tools/idegen/src/Configuration.java index c09be1a40..0cd863f49 100644 --- a/tools/idegen/src/Configuration.java +++ b/tools/idegen/src/Configuration.java @@ -147,7 +147,7 @@ public class Configuration { } // Keep track of .jar files. - if (path.endsWith(".jar")) { + if (path.endsWith(".jar") && !file.isDirectory()) { if (!excludes.exclude(path)) { jarFiles.add(file); } else { |