diff options
author | Dianne Hackborn <hackbod@google.com> | 2011-11-01 17:44:04 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-11-01 17:44:04 +0000 |
commit | 88175571f23ca7cff6d21cd1d5d6345cfacaa84a (patch) | |
tree | 52b684b614aeb7104d1a83afff003ae4a089066f /cmds | |
parent | d2ff6728445fff020cef7919bca2132938e3bea6 (diff) | |
parent | f136aa341abaaf7fd6f7632d41a30b2989d93985 (diff) | |
download | frameworks_base-88175571f23ca7cff6d21cd1d5d6345cfacaa84a.zip frameworks_base-88175571f23ca7cff6d21cd1d5d6345cfacaa84a.tar.gz frameworks_base-88175571f23ca7cff6d21cd1d5d6345cfacaa84a.tar.bz2 |
am f136aa34: Merge "Various performance and other work." into ics-mr1
* commit 'f136aa341abaaf7fd6f7632d41a30b2989d93985':
Various performance and other work.
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/am/src/com/android/commands/am/Am.java | 260 |
1 files changed, 137 insertions, 123 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index 9a75e44..96c2d2b 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -60,6 +60,8 @@ public class Am { private boolean mWaitOption = false; private boolean mStopOption = false; + private int mRepeat = 0; + private String mProfileFile; private boolean mProfileAutoStop; @@ -133,6 +135,7 @@ public class Am { mDebugOption = false; mWaitOption = false; mStopOption = false; + mRepeat = 0; mProfileFile = null; Uri data = null; String type = null; @@ -278,6 +281,8 @@ public class Am { } else if (opt.equals("--start-profiler")) { mProfileFile = nextArgRequired(); mProfileAutoStop = false; + } else if (opt.equals("-R")) { + mRepeat = Integer.parseInt(nextArgRequired()); } else if (opt.equals("-S")) { mStopOption = true; } else { @@ -350,138 +355,144 @@ public class Am { mimeType = mAm.getProviderMimeType(intent.getData()); } - if (mStopOption) { - String packageName; - if (intent.getComponent() != null) { - packageName = intent.getComponent().getPackageName(); - } else { - IPackageManager pm = IPackageManager.Stub.asInterface( - ServiceManager.getService("package")); - if (pm == null) { - System.err.println("Error: Package manager not running; aborting"); - return; + do { + if (mStopOption) { + String packageName; + if (intent.getComponent() != null) { + packageName = intent.getComponent().getPackageName(); + } else { + IPackageManager pm = IPackageManager.Stub.asInterface( + ServiceManager.getService("package")); + if (pm == null) { + System.err.println("Error: Package manager not running; aborting"); + return; + } + List<ResolveInfo> activities = pm.queryIntentActivities(intent, mimeType, 0); + if (activities == null || activities.size() <= 0) { + System.err.println("Error: Intent does not match any activities: " + + intent); + return; + } else if (activities.size() > 1) { + System.err.println("Error: Intent matches multiple activities; can't stop: " + + intent); + return; + } + packageName = activities.get(0).activityInfo.packageName; } - List<ResolveInfo> activities = pm.queryIntentActivities(intent, mimeType, 0); - if (activities == null || activities.size() <= 0) { - System.err.println("Error: Intent does not match any activities: " - + intent); - return; - } else if (activities.size() > 1) { - System.err.println("Error: Intent matches multiple activities; can't stop: " - + intent); + System.out.println("Stopping: " + packageName); + mAm.forceStopPackage(packageName); + Thread.sleep(250); + } + + System.out.println("Starting: " + intent); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + ParcelFileDescriptor fd = null; + + if (mProfileFile != null) { + try { + fd = ParcelFileDescriptor.open( + new File(mProfileFile), + ParcelFileDescriptor.MODE_CREATE | + ParcelFileDescriptor.MODE_TRUNCATE | + ParcelFileDescriptor.MODE_READ_WRITE); + } catch (FileNotFoundException e) { + System.err.println("Error: Unable to open file: " + mProfileFile); return; } - packageName = activities.get(0).activityInfo.packageName; - } - System.out.println("Stopping: " + packageName); - mAm.forceStopPackage(packageName); - Thread.sleep(250); - } - - System.out.println("Starting: " + intent); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - - ParcelFileDescriptor fd = null; - - if (mProfileFile != null) { - try { - fd = ParcelFileDescriptor.open( - new File(mProfileFile), - ParcelFileDescriptor.MODE_CREATE | - ParcelFileDescriptor.MODE_TRUNCATE | - ParcelFileDescriptor.MODE_READ_WRITE); - } catch (FileNotFoundException e) { - System.err.println("Error: Unable to open file: " + mProfileFile); - return; } - } - - IActivityManager.WaitResult result = null; - int res; - if (mWaitOption) { - result = mAm.startActivityAndWait(null, intent, mimeType, + + IActivityManager.WaitResult result = null; + int res; + if (mWaitOption) { + result = mAm.startActivityAndWait(null, intent, mimeType, + null, 0, null, null, 0, false, mDebugOption, + mProfileFile, fd, mProfileAutoStop); + res = result.result; + } else { + res = mAm.startActivity(null, intent, mimeType, null, 0, null, null, 0, false, mDebugOption, mProfileFile, fd, mProfileAutoStop); - res = result.result; - } else { - res = mAm.startActivity(null, intent, mimeType, - null, 0, null, null, 0, false, mDebugOption, - mProfileFile, fd, mProfileAutoStop); - } - PrintStream out = mWaitOption ? System.out : System.err; - boolean launched = false; - switch (res) { - case IActivityManager.START_SUCCESS: - launched = true; - break; - case IActivityManager.START_SWITCHES_CANCELED: - launched = true; - out.println( - "Warning: Activity not started because the " - + " current activity is being kept for the user."); - break; - case IActivityManager.START_DELIVERED_TO_TOP: - launched = true; - out.println( - "Warning: Activity not started, intent has " - + "been delivered to currently running " - + "top-most instance."); - break; - case IActivityManager.START_RETURN_INTENT_TO_CALLER: - launched = true; - out.println( - "Warning: Activity not started because intent " - + "should be handled by the caller"); - break; - case IActivityManager.START_TASK_TO_FRONT: - launched = true; - out.println( - "Warning: Activity not started, its current " - + "task has been brought to the front"); - break; - case IActivityManager.START_INTENT_NOT_RESOLVED: - out.println( - "Error: Activity not started, unable to " - + "resolve " + intent.toString()); - break; - case IActivityManager.START_CLASS_NOT_FOUND: - out.println(NO_CLASS_ERROR_CODE); - out.println("Error: Activity class " + - intent.getComponent().toShortString() - + " does not exist."); - break; - case IActivityManager.START_FORWARD_AND_REQUEST_CONFLICT: - out.println( - "Error: Activity not started, you requested to " - + "both forward and receive its result"); - break; - case IActivityManager.START_PERMISSION_DENIED: - out.println( - "Error: Activity not started, you do not " - + "have permission to access it."); - break; - default: - out.println( - "Error: Activity not started, unknown error code " + res); - break; - } - if (mWaitOption && launched) { - if (result == null) { - result = new IActivityManager.WaitResult(); - result.who = intent.getComponent(); } - System.out.println("Status: " + (result.timeout ? "timeout" : "ok")); - if (result.who != null) { - System.out.println("Activity: " + result.who.flattenToShortString()); + PrintStream out = mWaitOption ? System.out : System.err; + boolean launched = false; + switch (res) { + case IActivityManager.START_SUCCESS: + launched = true; + break; + case IActivityManager.START_SWITCHES_CANCELED: + launched = true; + out.println( + "Warning: Activity not started because the " + + " current activity is being kept for the user."); + break; + case IActivityManager.START_DELIVERED_TO_TOP: + launched = true; + out.println( + "Warning: Activity not started, intent has " + + "been delivered to currently running " + + "top-most instance."); + break; + case IActivityManager.START_RETURN_INTENT_TO_CALLER: + launched = true; + out.println( + "Warning: Activity not started because intent " + + "should be handled by the caller"); + break; + case IActivityManager.START_TASK_TO_FRONT: + launched = true; + out.println( + "Warning: Activity not started, its current " + + "task has been brought to the front"); + break; + case IActivityManager.START_INTENT_NOT_RESOLVED: + out.println( + "Error: Activity not started, unable to " + + "resolve " + intent.toString()); + break; + case IActivityManager.START_CLASS_NOT_FOUND: + out.println(NO_CLASS_ERROR_CODE); + out.println("Error: Activity class " + + intent.getComponent().toShortString() + + " does not exist."); + break; + case IActivityManager.START_FORWARD_AND_REQUEST_CONFLICT: + out.println( + "Error: Activity not started, you requested to " + + "both forward and receive its result"); + break; + case IActivityManager.START_PERMISSION_DENIED: + out.println( + "Error: Activity not started, you do not " + + "have permission to access it."); + break; + default: + out.println( + "Error: Activity not started, unknown error code " + res); + break; } - if (result.thisTime >= 0) { - System.out.println("ThisTime: " + result.thisTime); + if (mWaitOption && launched) { + if (result == null) { + result = new IActivityManager.WaitResult(); + result.who = intent.getComponent(); + } + System.out.println("Status: " + (result.timeout ? "timeout" : "ok")); + if (result.who != null) { + System.out.println("Activity: " + result.who.flattenToShortString()); + } + if (result.thisTime >= 0) { + System.out.println("ThisTime: " + result.thisTime); + } + if (result.totalTime >= 0) { + System.out.println("TotalTime: " + result.totalTime); + } + System.out.println("Complete"); } - if (result.totalTime >= 0) { - System.out.println("TotalTime: " + result.totalTime); + mRepeat--; + if (mRepeat > 1) { + mAm.unhandledBack(); } - System.out.println("Complete"); - } + } while (mRepeat > 1); } private void runForceStop() throws Exception { @@ -1179,7 +1190,8 @@ public class Am { private static void showUsage() { System.err.println( "usage: am [subcommand] [options]\n" + - "usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>] [-S] <INTENT>\n" + + "usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]\n" + + " [--R COUNT] [-S] <INTENT>\n" + " am startservice <INTENT>\n" + " am force-stop <PACKAGE>\n" + " am broadcast <INTENT>\n" + @@ -1197,6 +1209,8 @@ public class Am { " -W: wait for launch to complete\n" + " --start-profiler <FILE>: start profiler and send results to <FILE>\n" + " -P <FILE>: like above, but profiling stops when app goes idle\n" + + " -R: repeat the activity launch <COUNT> times. Prior to each repeat,\n" + + " the top activity will be finished.\n" + " -S: force stop the target app before starting the activity\n" + "\n" + "am startservice: start a Service.\n" + |