Am.java revision e2bdca5c4330b6bc9cc26480ae4c1eefe5ee9ce9
1/* 2** 3** Copyright 2007, The Android Open Source Project 4** 5** Licensed under the Apache License, Version 2.0 (the "License"); 6** you may not use this file except in compliance with the License. 7** You may obtain a copy of the License at 8** 9** http://www.apache.org/licenses/LICENSE-2.0 10** 11** Unless required by applicable law or agreed to in writing, software 12** distributed under the License is distributed on an "AS IS" BASIS, 13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14** See the License for the specific language governing permissions and 15** limitations under the License. 16*/ 17 18 19package com.android.commands.am; 20 21import android.app.ActivityManager; 22import android.app.ActivityManagerNative; 23import android.app.IActivityController; 24import android.app.IActivityManager; 25import android.app.IInstrumentationWatcher; 26import android.app.Instrumentation; 27import android.content.ComponentName; 28import android.content.Context; 29import android.content.IIntentReceiver; 30import android.content.Intent; 31import android.content.pm.IPackageManager; 32import android.content.pm.ResolveInfo; 33import android.net.Uri; 34import android.os.Bundle; 35import android.os.ParcelFileDescriptor; 36import android.os.RemoteException; 37import android.os.ServiceManager; 38import android.os.SystemProperties; 39import android.util.AndroidException; 40import android.view.Display; 41import android.view.IWindowManager; 42 43import java.io.BufferedReader; 44import java.io.File; 45import java.io.FileNotFoundException; 46import java.io.IOException; 47import java.io.InputStreamReader; 48import java.io.PrintStream; 49import java.net.URISyntaxException; 50import java.util.HashSet; 51import java.util.List; 52 53public class Am { 54 55 private IActivityManager mAm; 56 private String[] mArgs; 57 private int mNextArg; 58 private String mCurArgData; 59 60 private int mStartFlags = 0; 61 private boolean mWaitOption = false; 62 private boolean mStopOption = false; 63 64 private int mRepeat = 0; 65 private int mUserId = 0; 66 67 private String mProfileFile; 68 69 // These are magic strings understood by the Eclipse plugin. 70 private static final String FATAL_ERROR_CODE = "Error type 1"; 71 private static final String NO_SYSTEM_ERROR_CODE = "Error type 2"; 72 private static final String NO_CLASS_ERROR_CODE = "Error type 3"; 73 74 /** 75 * Command-line entry point. 76 * 77 * @param args The command-line arguments 78 */ 79 public static void main(String[] args) { 80 try { 81 (new Am()).run(args); 82 } catch (IllegalArgumentException e) { 83 showUsage(); 84 System.err.println("Error: " + e.getMessage()); 85 } catch (Exception e) { 86 e.printStackTrace(System.err); 87 System.exit(1); 88 } 89 } 90 91 private void run(String[] args) throws Exception { 92 if (args.length < 1) { 93 showUsage(); 94 return; 95 } 96 97 mAm = ActivityManagerNative.getDefault(); 98 if (mAm == null) { 99 System.err.println(NO_SYSTEM_ERROR_CODE); 100 throw new AndroidException("Can't connect to activity manager; is the system running?"); 101 } 102 103 mArgs = args; 104 String op = args[0]; 105 mNextArg = 1; 106 107 if (op.equals("start")) { 108 runStart(); 109 } else if (op.equals("startservice")) { 110 runStartService(); 111 } else if (op.equals("force-stop")) { 112 runForceStop(); 113 } else if (op.equals("kill")) { 114 runKill(); 115 } else if (op.equals("kill-all")) { 116 runKillAll(); 117 } else if (op.equals("instrument")) { 118 runInstrument(); 119 } else if (op.equals("broadcast")) { 120 sendBroadcast(); 121 } else if (op.equals("profile")) { 122 runProfile(); 123 } else if (op.equals("dumpheap")) { 124 runDumpHeap(); 125 } else if (op.equals("set-debug-app")) { 126 runSetDebugApp(); 127 } else if (op.equals("clear-debug-app")) { 128 runClearDebugApp(); 129 } else if (op.equals("monitor")) { 130 runMonitor(); 131 } else if (op.equals("screen-compat")) { 132 runScreenCompat(); 133 } else if (op.equals("display-size")) { 134 runDisplaySize(); 135 } else if (op.equals("display-density")) { 136 runDisplayDensity(); 137 } else if (op.equals("to-uri")) { 138 runToUri(false); 139 } else if (op.equals("to-intent-uri")) { 140 runToUri(true); 141 } else if (op.equals("switch-user")) { 142 runSwitchUser(); 143 } else if (op.equals("stop-user")) { 144 runStopUser(); 145 } else { 146 throw new IllegalArgumentException("Unknown command: " + op); 147 } 148 } 149 150 private Intent makeIntent() throws URISyntaxException { 151 Intent intent = new Intent(); 152 Intent baseIntent = intent; 153 boolean hasIntentInfo = false; 154 155 mStartFlags = 0; 156 mWaitOption = false; 157 mStopOption = false; 158 mRepeat = 0; 159 mProfileFile = null; 160 mUserId = 0; 161 Uri data = null; 162 String type = null; 163 164 String opt; 165 while ((opt=nextOption()) != null) { 166 if (opt.equals("-a")) { 167 intent.setAction(nextArgRequired()); 168 if (intent == baseIntent) { 169 hasIntentInfo = true; 170 } 171 } else if (opt.equals("-d")) { 172 data = Uri.parse(nextArgRequired()); 173 if (intent == baseIntent) { 174 hasIntentInfo = true; 175 } 176 } else if (opt.equals("-t")) { 177 type = nextArgRequired(); 178 if (intent == baseIntent) { 179 hasIntentInfo = true; 180 } 181 } else if (opt.equals("-c")) { 182 intent.addCategory(nextArgRequired()); 183 if (intent == baseIntent) { 184 hasIntentInfo = true; 185 } 186 } else if (opt.equals("-e") || opt.equals("--es")) { 187 String key = nextArgRequired(); 188 String value = nextArgRequired(); 189 intent.putExtra(key, value); 190 } else if (opt.equals("--esn")) { 191 String key = nextArgRequired(); 192 intent.putExtra(key, (String) null); 193 } else if (opt.equals("--ei")) { 194 String key = nextArgRequired(); 195 String value = nextArgRequired(); 196 intent.putExtra(key, Integer.valueOf(value)); 197 } else if (opt.equals("--eu")) { 198 String key = nextArgRequired(); 199 String value = nextArgRequired(); 200 intent.putExtra(key, Uri.parse(value)); 201 } else if (opt.equals("--ecn")) { 202 String key = nextArgRequired(); 203 String value = nextArgRequired(); 204 ComponentName cn = ComponentName.unflattenFromString(value); 205 if (cn == null) throw new IllegalArgumentException("Bad component name: " + value); 206 intent.putExtra(key, cn); 207 } else if (opt.equals("--eia")) { 208 String key = nextArgRequired(); 209 String value = nextArgRequired(); 210 String[] strings = value.split(","); 211 int[] list = new int[strings.length]; 212 for (int i = 0; i < strings.length; i++) { 213 list[i] = Integer.valueOf(strings[i]); 214 } 215 intent.putExtra(key, list); 216 } else if (opt.equals("--el")) { 217 String key = nextArgRequired(); 218 String value = nextArgRequired(); 219 intent.putExtra(key, Long.valueOf(value)); 220 } else if (opt.equals("--ela")) { 221 String key = nextArgRequired(); 222 String value = nextArgRequired(); 223 String[] strings = value.split(","); 224 long[] list = new long[strings.length]; 225 for (int i = 0; i < strings.length; i++) { 226 list[i] = Long.valueOf(strings[i]); 227 } 228 intent.putExtra(key, list); 229 hasIntentInfo = true; 230 } else if (opt.equals("--ef")) { 231 String key = nextArgRequired(); 232 String value = nextArgRequired(); 233 intent.putExtra(key, Float.valueOf(value)); 234 hasIntentInfo = true; 235 } else if (opt.equals("--efa")) { 236 String key = nextArgRequired(); 237 String value = nextArgRequired(); 238 String[] strings = value.split(","); 239 float[] list = new float[strings.length]; 240 for (int i = 0; i < strings.length; i++) { 241 list[i] = Float.valueOf(strings[i]); 242 } 243 intent.putExtra(key, list); 244 hasIntentInfo = true; 245 } else if (opt.equals("--ez")) { 246 String key = nextArgRequired(); 247 String value = nextArgRequired(); 248 intent.putExtra(key, Boolean.valueOf(value)); 249 } else if (opt.equals("-n")) { 250 String str = nextArgRequired(); 251 ComponentName cn = ComponentName.unflattenFromString(str); 252 if (cn == null) throw new IllegalArgumentException("Bad component name: " + str); 253 intent.setComponent(cn); 254 if (intent == baseIntent) { 255 hasIntentInfo = true; 256 } 257 } else if (opt.equals("-f")) { 258 String str = nextArgRequired(); 259 intent.setFlags(Integer.decode(str).intValue()); 260 } else if (opt.equals("--grant-read-uri-permission")) { 261 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 262 } else if (opt.equals("--grant-write-uri-permission")) { 263 intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 264 } else if (opt.equals("--exclude-stopped-packages")) { 265 intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES); 266 } else if (opt.equals("--include-stopped-packages")) { 267 intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); 268 } else if (opt.equals("--debug-log-resolution")) { 269 intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION); 270 } else if (opt.equals("--activity-brought-to-front")) { 271 intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); 272 } else if (opt.equals("--activity-clear-top")) { 273 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 274 } else if (opt.equals("--activity-clear-when-task-reset")) { 275 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 276 } else if (opt.equals("--activity-exclude-from-recents")) { 277 intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 278 } else if (opt.equals("--activity-launched-from-history")) { 279 intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); 280 } else if (opt.equals("--activity-multiple-task")) { 281 intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 282 } else if (opt.equals("--activity-no-animation")) { 283 intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 284 } else if (opt.equals("--activity-no-history")) { 285 intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 286 } else if (opt.equals("--activity-no-user-action")) { 287 intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION); 288 } else if (opt.equals("--activity-previous-is-top")) { 289 intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); 290 } else if (opt.equals("--activity-reorder-to-front")) { 291 intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 292 } else if (opt.equals("--activity-reset-task-if-needed")) { 293 intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 294 } else if (opt.equals("--activity-single-top")) { 295 intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 296 } else if (opt.equals("--activity-clear-task")) { 297 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 298 } else if (opt.equals("--activity-task-on-home")) { 299 intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME); 300 } else if (opt.equals("--receiver-registered-only")) { 301 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); 302 } else if (opt.equals("--receiver-replace-pending")) { 303 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); 304 } else if (opt.equals("--selector")) { 305 intent.setDataAndType(data, type); 306 intent = new Intent(); 307 } else if (opt.equals("-D")) { 308 mStartFlags |= ActivityManager.START_FLAG_DEBUG; 309 } else if (opt.equals("-W")) { 310 mWaitOption = true; 311 } else if (opt.equals("-P")) { 312 mProfileFile = nextArgRequired(); 313 mStartFlags |= ActivityManager.START_FLAG_AUTO_STOP_PROFILER; 314 } else if (opt.equals("--start-profiler")) { 315 mProfileFile = nextArgRequired(); 316 mStartFlags &= ~ActivityManager.START_FLAG_AUTO_STOP_PROFILER; 317 } else if (opt.equals("-R")) { 318 mRepeat = Integer.parseInt(nextArgRequired()); 319 } else if (opt.equals("-S")) { 320 mStopOption = true; 321 } else if (opt.equals("--opengl-trace")) { 322 mStartFlags |= ActivityManager.START_FLAG_OPENGL_TRACES; 323 } else if (opt.equals("--user")) { 324 mUserId = Integer.parseInt(nextArgRequired()); 325 } else { 326 System.err.println("Error: Unknown option: " + opt); 327 return null; 328 } 329 } 330 intent.setDataAndType(data, type); 331 332 final boolean hasSelector = intent != baseIntent; 333 if (hasSelector) { 334 // A selector was specified; fix up. 335 baseIntent.setSelector(intent); 336 intent = baseIntent; 337 } 338 339 String arg = nextArg(); 340 baseIntent = null; 341 if (arg == null) { 342 if (hasSelector) { 343 // If a selector has been specified, and no arguments 344 // have been supplied for the main Intent, then we can 345 // assume it is ACTION_MAIN CATEGORY_LAUNCHER; we don't 346 // need to have a component name specified yet, the 347 // selector will take care of that. 348 baseIntent = new Intent(Intent.ACTION_MAIN); 349 baseIntent.addCategory(Intent.CATEGORY_LAUNCHER); 350 } 351 } else if (arg.indexOf(':') >= 0) { 352 // The argument is a URI. Fully parse it, and use that result 353 // to fill in any data not specified so far. 354 baseIntent = Intent.parseUri(arg, Intent.URI_INTENT_SCHEME); 355 } else if (arg.indexOf('/') >= 0) { 356 // The argument is a component name. Build an Intent to launch 357 // it. 358 baseIntent = new Intent(Intent.ACTION_MAIN); 359 baseIntent.addCategory(Intent.CATEGORY_LAUNCHER); 360 baseIntent.setComponent(ComponentName.unflattenFromString(arg)); 361 } else { 362 // Assume the argument is a package name. 363 baseIntent = new Intent(Intent.ACTION_MAIN); 364 baseIntent.addCategory(Intent.CATEGORY_LAUNCHER); 365 baseIntent.setPackage(arg); 366 } 367 if (baseIntent != null) { 368 Bundle extras = intent.getExtras(); 369 intent.replaceExtras((Bundle)null); 370 Bundle uriExtras = baseIntent.getExtras(); 371 baseIntent.replaceExtras((Bundle)null); 372 if (intent.getAction() != null && baseIntent.getCategories() != null) { 373 HashSet<String> cats = new HashSet<String>(baseIntent.getCategories()); 374 for (String c : cats) { 375 baseIntent.removeCategory(c); 376 } 377 } 378 intent.fillIn(baseIntent, Intent.FILL_IN_COMPONENT | Intent.FILL_IN_SELECTOR); 379 if (extras == null) { 380 extras = uriExtras; 381 } else if (uriExtras != null) { 382 uriExtras.putAll(extras); 383 extras = uriExtras; 384 } 385 intent.replaceExtras(extras); 386 hasIntentInfo = true; 387 } 388 389 if (!hasIntentInfo) throw new IllegalArgumentException("No intent supplied"); 390 return intent; 391 } 392 393 private void runStartService() throws Exception { 394 Intent intent = makeIntent(); 395 System.out.println("Starting service: " + intent); 396 ComponentName cn = mAm.startService(null, intent, intent.getType(), 0); 397 if (cn == null) { 398 System.err.println("Error: Not found; no service started."); 399 } 400 } 401 402 private void runStart() throws Exception { 403 Intent intent = makeIntent(); 404 405 String mimeType = intent.getType(); 406 if (mimeType == null && intent.getData() != null 407 && "content".equals(intent.getData().getScheme())) { 408 mimeType = mAm.getProviderMimeType(intent.getData()); 409 } 410 411 do { 412 if (mStopOption) { 413 String packageName; 414 if (intent.getComponent() != null) { 415 packageName = intent.getComponent().getPackageName(); 416 } else { 417 IPackageManager pm = IPackageManager.Stub.asInterface( 418 ServiceManager.getService("package")); 419 if (pm == null) { 420 System.err.println("Error: Package manager not running; aborting"); 421 return; 422 } 423 List<ResolveInfo> activities = pm.queryIntentActivities(intent, mimeType, 0, 424 mUserId); 425 if (activities == null || activities.size() <= 0) { 426 System.err.println("Error: Intent does not match any activities: " 427 + intent); 428 return; 429 } else if (activities.size() > 1) { 430 System.err.println("Error: Intent matches multiple activities; can't stop: " 431 + intent); 432 return; 433 } 434 packageName = activities.get(0).activityInfo.packageName; 435 } 436 System.out.println("Stopping: " + packageName); 437 mAm.forceStopPackage(packageName); 438 Thread.sleep(250); 439 } 440 441 System.out.println("Starting: " + intent); 442 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 443 444 ParcelFileDescriptor fd = null; 445 446 if (mProfileFile != null) { 447 try { 448 fd = ParcelFileDescriptor.open( 449 new File(mProfileFile), 450 ParcelFileDescriptor.MODE_CREATE | 451 ParcelFileDescriptor.MODE_TRUNCATE | 452 ParcelFileDescriptor.MODE_READ_WRITE); 453 } catch (FileNotFoundException e) { 454 System.err.println("Error: Unable to open file: " + mProfileFile); 455 return; 456 } 457 } 458 459 IActivityManager.WaitResult result = null; 460 int res; 461 if (mWaitOption) { 462 result = mAm.startActivityAndWait(null, intent, mimeType, 463 null, null, 0, mStartFlags, mProfileFile, fd, null); 464 res = result.result; 465 } else { 466 res = mAm.startActivity(null, intent, mimeType, 467 null, null, 0, mStartFlags, mProfileFile, fd, null); 468 } 469 PrintStream out = mWaitOption ? System.out : System.err; 470 boolean launched = false; 471 switch (res) { 472 case ActivityManager.START_SUCCESS: 473 launched = true; 474 break; 475 case ActivityManager.START_SWITCHES_CANCELED: 476 launched = true; 477 out.println( 478 "Warning: Activity not started because the " 479 + " current activity is being kept for the user."); 480 break; 481 case ActivityManager.START_DELIVERED_TO_TOP: 482 launched = true; 483 out.println( 484 "Warning: Activity not started, intent has " 485 + "been delivered to currently running " 486 + "top-most instance."); 487 break; 488 case ActivityManager.START_RETURN_INTENT_TO_CALLER: 489 launched = true; 490 out.println( 491 "Warning: Activity not started because intent " 492 + "should be handled by the caller"); 493 break; 494 case ActivityManager.START_TASK_TO_FRONT: 495 launched = true; 496 out.println( 497 "Warning: Activity not started, its current " 498 + "task has been brought to the front"); 499 break; 500 case ActivityManager.START_INTENT_NOT_RESOLVED: 501 out.println( 502 "Error: Activity not started, unable to " 503 + "resolve " + intent.toString()); 504 break; 505 case ActivityManager.START_CLASS_NOT_FOUND: 506 out.println(NO_CLASS_ERROR_CODE); 507 out.println("Error: Activity class " + 508 intent.getComponent().toShortString() 509 + " does not exist."); 510 break; 511 case ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT: 512 out.println( 513 "Error: Activity not started, you requested to " 514 + "both forward and receive its result"); 515 break; 516 case ActivityManager.START_PERMISSION_DENIED: 517 out.println( 518 "Error: Activity not started, you do not " 519 + "have permission to access it."); 520 break; 521 default: 522 out.println( 523 "Error: Activity not started, unknown error code " + res); 524 break; 525 } 526 if (mWaitOption && launched) { 527 if (result == null) { 528 result = new IActivityManager.WaitResult(); 529 result.who = intent.getComponent(); 530 } 531 System.out.println("Status: " + (result.timeout ? "timeout" : "ok")); 532 if (result.who != null) { 533 System.out.println("Activity: " + result.who.flattenToShortString()); 534 } 535 if (result.thisTime >= 0) { 536 System.out.println("ThisTime: " + result.thisTime); 537 } 538 if (result.totalTime >= 0) { 539 System.out.println("TotalTime: " + result.totalTime); 540 } 541 System.out.println("Complete"); 542 } 543 mRepeat--; 544 if (mRepeat > 1) { 545 mAm.unhandledBack(); 546 } 547 } while (mRepeat > 1); 548 } 549 550 private void runForceStop() throws Exception { 551 mAm.forceStopPackage(nextArgRequired()); 552 } 553 554 private void runKill() throws Exception { 555 mAm.killBackgroundProcesses(nextArgRequired()); 556 } 557 558 private void runKillAll() throws Exception { 559 mAm.killAllBackgroundProcesses(); 560 } 561 562 private void sendBroadcast() throws Exception { 563 Intent intent = makeIntent(); 564 IntentReceiver receiver = new IntentReceiver(); 565 System.out.println("Broadcasting: " + intent); 566 mAm.broadcastIntent(null, intent, null, receiver, 0, null, null, null, true, false, 567 mUserId); 568 receiver.waitForFinish(); 569 } 570 571 private void runInstrument() throws Exception { 572 String profileFile = null; 573 boolean wait = false; 574 boolean rawMode = false; 575 boolean no_window_animation = false; 576 Bundle args = new Bundle(); 577 String argKey = null, argValue = null; 578 IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); 579 580 String opt; 581 while ((opt=nextOption()) != null) { 582 if (opt.equals("-p")) { 583 profileFile = nextArgRequired(); 584 } else if (opt.equals("-w")) { 585 wait = true; 586 } else if (opt.equals("-r")) { 587 rawMode = true; 588 } else if (opt.equals("-e")) { 589 argKey = nextArgRequired(); 590 argValue = nextArgRequired(); 591 args.putString(argKey, argValue); 592 } else if (opt.equals("--no_window_animation") 593 || opt.equals("--no-window-animation")) { 594 no_window_animation = true; 595 } else { 596 System.err.println("Error: Unknown option: " + opt); 597 return; 598 } 599 } 600 601 String cnArg = nextArgRequired(); 602 ComponentName cn = ComponentName.unflattenFromString(cnArg); 603 if (cn == null) throw new IllegalArgumentException("Bad component name: " + cnArg); 604 605 InstrumentationWatcher watcher = null; 606 if (wait) { 607 watcher = new InstrumentationWatcher(); 608 watcher.setRawOutput(rawMode); 609 } 610 float[] oldAnims = null; 611 if (no_window_animation) { 612 oldAnims = wm.getAnimationScales(); 613 wm.setAnimationScale(0, 0.0f); 614 wm.setAnimationScale(1, 0.0f); 615 } 616 617 if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher)) { 618 throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString()); 619 } 620 621 if (watcher != null) { 622 if (!watcher.waitForFinish()) { 623 System.out.println("INSTRUMENTATION_ABORTED: System has crashed."); 624 } 625 } 626 627 if (oldAnims != null) { 628 wm.setAnimationScales(oldAnims); 629 } 630 } 631 632 static void removeWallOption() { 633 String props = SystemProperties.get("dalvik.vm.extra-opts"); 634 if (props != null && props.contains("-Xprofile:wallclock")) { 635 props = props.replace("-Xprofile:wallclock", ""); 636 props = props.trim(); 637 SystemProperties.set("dalvik.vm.extra-opts", props); 638 } 639 } 640 641 private void runProfile() throws Exception { 642 String profileFile = null; 643 boolean start = false; 644 boolean wall = false; 645 int profileType = 0; 646 647 String process = null; 648 649 String cmd = nextArgRequired(); 650 651 if ("start".equals(cmd)) { 652 start = true; 653 wall = "--wall".equals(nextOption()); 654 process = nextArgRequired(); 655 } else if ("stop".equals(cmd)) { 656 process = nextArg(); 657 } else { 658 // Compatibility with old syntax: process is specified first. 659 process = cmd; 660 cmd = nextArgRequired(); 661 if ("start".equals(cmd)) { 662 start = true; 663 } else if (!"stop".equals(cmd)) { 664 throw new IllegalArgumentException("Profile command " + process + " not valid"); 665 } 666 } 667 668 ParcelFileDescriptor fd = null; 669 670 if (start) { 671 profileFile = nextArgRequired(); 672 try { 673 fd = ParcelFileDescriptor.open( 674 new File(profileFile), 675 ParcelFileDescriptor.MODE_CREATE | 676 ParcelFileDescriptor.MODE_TRUNCATE | 677 ParcelFileDescriptor.MODE_READ_WRITE); 678 } catch (FileNotFoundException e) { 679 System.err.println("Error: Unable to open file: " + profileFile); 680 return; 681 } 682 } 683 684 try { 685 if (wall) { 686 // XXX doesn't work -- this needs to be set before booting. 687 String props = SystemProperties.get("dalvik.vm.extra-opts"); 688 if (props == null || !props.contains("-Xprofile:wallclock")) { 689 props = props + " -Xprofile:wallclock"; 690 //SystemProperties.set("dalvik.vm.extra-opts", props); 691 } 692 } else if (start) { 693 //removeWallOption(); 694 } 695 if (!mAm.profileControl(process, start, profileFile, fd, profileType)) { 696 wall = false; 697 throw new AndroidException("PROFILE FAILED on process " + process); 698 } 699 } finally { 700 if (!wall) { 701 //removeWallOption(); 702 } 703 } 704 } 705 706 private void runDumpHeap() throws Exception { 707 boolean managed = !"-n".equals(nextOption()); 708 String process = nextArgRequired(); 709 String heapFile = nextArgRequired(); 710 ParcelFileDescriptor fd = null; 711 712 try { 713 fd = ParcelFileDescriptor.open( 714 new File(heapFile), 715 ParcelFileDescriptor.MODE_CREATE | 716 ParcelFileDescriptor.MODE_TRUNCATE | 717 ParcelFileDescriptor.MODE_READ_WRITE); 718 } catch (FileNotFoundException e) { 719 System.err.println("Error: Unable to open file: " + heapFile); 720 return; 721 } 722 723 if (!mAm.dumpHeap(process, managed, heapFile, fd)) { 724 throw new AndroidException("HEAP DUMP FAILED on process " + process); 725 } 726 } 727 728 private void runSetDebugApp() throws Exception { 729 boolean wait = false; 730 boolean persistent = false; 731 732 String opt; 733 while ((opt=nextOption()) != null) { 734 if (opt.equals("-w")) { 735 wait = true; 736 } else if (opt.equals("--persistent")) { 737 persistent = true; 738 } else { 739 System.err.println("Error: Unknown option: " + opt); 740 return; 741 } 742 } 743 744 String pkg = nextArgRequired(); 745 mAm.setDebugApp(pkg, wait, persistent); 746 } 747 748 private void runClearDebugApp() throws Exception { 749 mAm.setDebugApp(null, false, true); 750 } 751 752 private void runSwitchUser() throws Exception { 753 String user = nextArgRequired(); 754 mAm.switchUser(Integer.parseInt(user)); 755 } 756 757 private void runStopUser() throws Exception { 758 String user = nextArgRequired(); 759 int res = mAm.stopUser(Integer.parseInt(user), null); 760 if (res != ActivityManager.USER_OP_SUCCESS) { 761 String txt = ""; 762 switch (res) { 763 case ActivityManager.USER_OP_IS_CURRENT: 764 txt = " (Can't stop current user)"; 765 break; 766 case ActivityManager.USER_OP_UNKNOWN_USER: 767 txt = " (Unknown user " + user + ")"; 768 break; 769 } 770 System.err.println("Switch failed: " + res + txt); 771 } 772 } 773 774 class MyActivityController extends IActivityController.Stub { 775 final String mGdbPort; 776 777 static final int STATE_NORMAL = 0; 778 static final int STATE_CRASHED = 1; 779 static final int STATE_EARLY_ANR = 2; 780 static final int STATE_ANR = 3; 781 782 int mState; 783 784 static final int RESULT_DEFAULT = 0; 785 786 static final int RESULT_CRASH_DIALOG = 0; 787 static final int RESULT_CRASH_KILL = 1; 788 789 static final int RESULT_EARLY_ANR_CONTINUE = 0; 790 static final int RESULT_EARLY_ANR_KILL = 1; 791 792 static final int RESULT_ANR_DIALOG = 0; 793 static final int RESULT_ANR_KILL = 1; 794 static final int RESULT_ANR_WAIT = 1; 795 796 int mResult; 797 798 Process mGdbProcess; 799 Thread mGdbThread; 800 boolean mGotGdbPrint; 801 802 MyActivityController(String gdbPort) { 803 mGdbPort = gdbPort; 804 } 805 806 @Override 807 public boolean activityResuming(String pkg) throws RemoteException { 808 synchronized (this) { 809 System.out.println("** Activity resuming: " + pkg); 810 } 811 return true; 812 } 813 814 @Override 815 public boolean activityStarting(Intent intent, String pkg) throws RemoteException { 816 synchronized (this) { 817 System.out.println("** Activity starting: " + pkg); 818 } 819 return true; 820 } 821 822 @Override 823 public boolean appCrashed(String processName, int pid, String shortMsg, String longMsg, 824 long timeMillis, String stackTrace) throws RemoteException { 825 synchronized (this) { 826 System.out.println("** ERROR: PROCESS CRASHED"); 827 System.out.println("processName: " + processName); 828 System.out.println("processPid: " + pid); 829 System.out.println("shortMsg: " + shortMsg); 830 System.out.println("longMsg: " + longMsg); 831 System.out.println("timeMillis: " + timeMillis); 832 System.out.println("stack:"); 833 System.out.print(stackTrace); 834 System.out.println("#"); 835 int result = waitControllerLocked(pid, STATE_CRASHED); 836 return result == RESULT_CRASH_KILL ? false : true; 837 } 838 } 839 840 @Override 841 public int appEarlyNotResponding(String processName, int pid, String annotation) 842 throws RemoteException { 843 synchronized (this) { 844 System.out.println("** ERROR: EARLY PROCESS NOT RESPONDING"); 845 System.out.println("processName: " + processName); 846 System.out.println("processPid: " + pid); 847 System.out.println("annotation: " + annotation); 848 int result = waitControllerLocked(pid, STATE_EARLY_ANR); 849 if (result == RESULT_EARLY_ANR_KILL) return -1; 850 return 0; 851 } 852 } 853 854 @Override 855 public int appNotResponding(String processName, int pid, String processStats) 856 throws RemoteException { 857 synchronized (this) { 858 System.out.println("** ERROR: PROCESS NOT RESPONDING"); 859 System.out.println("processName: " + processName); 860 System.out.println("processPid: " + pid); 861 System.out.println("processStats:"); 862 System.out.print(processStats); 863 System.out.println("#"); 864 int result = waitControllerLocked(pid, STATE_ANR); 865 if (result == RESULT_ANR_KILL) return -1; 866 if (result == RESULT_ANR_WAIT) return 1; 867 return 0; 868 } 869 } 870 871 void killGdbLocked() { 872 mGotGdbPrint = false; 873 if (mGdbProcess != null) { 874 System.out.println("Stopping gdbserver"); 875 mGdbProcess.destroy(); 876 mGdbProcess = null; 877 } 878 if (mGdbThread != null) { 879 mGdbThread.interrupt(); 880 mGdbThread = null; 881 } 882 } 883 884 int waitControllerLocked(int pid, int state) { 885 if (mGdbPort != null) { 886 killGdbLocked(); 887 888 try { 889 System.out.println("Starting gdbserver on port " + mGdbPort); 890 System.out.println("Do the following:"); 891 System.out.println(" adb forward tcp:" + mGdbPort + " tcp:" + mGdbPort); 892 System.out.println(" gdbclient app_process :" + mGdbPort); 893 894 mGdbProcess = Runtime.getRuntime().exec(new String[] { 895 "gdbserver", ":" + mGdbPort, "--attach", Integer.toString(pid) 896 }); 897 final InputStreamReader converter = new InputStreamReader( 898 mGdbProcess.getInputStream()); 899 mGdbThread = new Thread() { 900 @Override 901 public void run() { 902 BufferedReader in = new BufferedReader(converter); 903 String line; 904 int count = 0; 905 while (true) { 906 synchronized (MyActivityController.this) { 907 if (mGdbThread == null) { 908 return; 909 } 910 if (count == 2) { 911 mGotGdbPrint = true; 912 MyActivityController.this.notifyAll(); 913 } 914 } 915 try { 916 line = in.readLine(); 917 if (line == null) { 918 return; 919 } 920 System.out.println("GDB: " + line); 921 count++; 922 } catch (IOException e) { 923 return; 924 } 925 } 926 } 927 }; 928 mGdbThread.start(); 929 930 // Stupid waiting for .5s. Doesn't matter if we end early. 931 try { 932 this.wait(500); 933 } catch (InterruptedException e) { 934 } 935 936 } catch (IOException e) { 937 System.err.println("Failure starting gdbserver: " + e); 938 killGdbLocked(); 939 } 940 } 941 mState = state; 942 System.out.println(""); 943 printMessageForState(); 944 945 while (mState != STATE_NORMAL) { 946 try { 947 wait(); 948 } catch (InterruptedException e) { 949 } 950 } 951 952 killGdbLocked(); 953 954 return mResult; 955 } 956 957 void resumeController(int result) { 958 synchronized (this) { 959 mState = STATE_NORMAL; 960 mResult = result; 961 notifyAll(); 962 } 963 } 964 965 void printMessageForState() { 966 switch (mState) { 967 case STATE_NORMAL: 968 System.out.println("Monitoring activity manager... available commands:"); 969 break; 970 case STATE_CRASHED: 971 System.out.println("Waiting after crash... available commands:"); 972 System.out.println("(c)ontinue: show crash dialog"); 973 System.out.println("(k)ill: immediately kill app"); 974 break; 975 case STATE_EARLY_ANR: 976 System.out.println("Waiting after early ANR... available commands:"); 977 System.out.println("(c)ontinue: standard ANR processing"); 978 System.out.println("(k)ill: immediately kill app"); 979 break; 980 case STATE_ANR: 981 System.out.println("Waiting after ANR... available commands:"); 982 System.out.println("(c)ontinue: show ANR dialog"); 983 System.out.println("(k)ill: immediately kill app"); 984 System.out.println("(w)ait: wait some more"); 985 break; 986 } 987 System.out.println("(q)uit: finish monitoring"); 988 } 989 990 void run() throws RemoteException { 991 try { 992 printMessageForState(); 993 994 mAm.setActivityController(this); 995 mState = STATE_NORMAL; 996 997 InputStreamReader converter = new InputStreamReader(System.in); 998 BufferedReader in = new BufferedReader(converter); 999 String line; 1000 1001 while ((line = in.readLine()) != null) { 1002 boolean addNewline = true; 1003 if (line.length() <= 0) { 1004 addNewline = false; 1005 } else if ("q".equals(line) || "quit".equals(line)) { 1006 resumeController(RESULT_DEFAULT); 1007 break; 1008 } else if (mState == STATE_CRASHED) { 1009 if ("c".equals(line) || "continue".equals(line)) { 1010 resumeController(RESULT_CRASH_DIALOG); 1011 } else if ("k".equals(line) || "kill".equals(line)) { 1012 resumeController(RESULT_CRASH_KILL); 1013 } else { 1014 System.out.println("Invalid command: " + line); 1015 } 1016 } else if (mState == STATE_ANR) { 1017 if ("c".equals(line) || "continue".equals(line)) { 1018 resumeController(RESULT_ANR_DIALOG); 1019 } else if ("k".equals(line) || "kill".equals(line)) { 1020 resumeController(RESULT_ANR_KILL); 1021 } else if ("w".equals(line) || "wait".equals(line)) { 1022 resumeController(RESULT_ANR_WAIT); 1023 } else { 1024 System.out.println("Invalid command: " + line); 1025 } 1026 } else if (mState == STATE_EARLY_ANR) { 1027 if ("c".equals(line) || "continue".equals(line)) { 1028 resumeController(RESULT_EARLY_ANR_CONTINUE); 1029 } else if ("k".equals(line) || "kill".equals(line)) { 1030 resumeController(RESULT_EARLY_ANR_KILL); 1031 } else { 1032 System.out.println("Invalid command: " + line); 1033 } 1034 } else { 1035 System.out.println("Invalid command: " + line); 1036 } 1037 1038 synchronized (this) { 1039 if (addNewline) { 1040 System.out.println(""); 1041 } 1042 printMessageForState(); 1043 } 1044 } 1045 1046 } catch (IOException e) { 1047 e.printStackTrace(); 1048 } finally { 1049 mAm.setActivityController(null); 1050 } 1051 } 1052 } 1053 1054 private void runMonitor() throws Exception { 1055 String opt; 1056 String gdbPort = null; 1057 while ((opt=nextOption()) != null) { 1058 if (opt.equals("--gdb")) { 1059 gdbPort = nextArgRequired(); 1060 } else { 1061 System.err.println("Error: Unknown option: " + opt); 1062 return; 1063 } 1064 } 1065 1066 MyActivityController controller = new MyActivityController(gdbPort); 1067 controller.run(); 1068 } 1069 1070 private void runScreenCompat() throws Exception { 1071 String mode = nextArgRequired(); 1072 boolean enabled; 1073 if ("on".equals(mode)) { 1074 enabled = true; 1075 } else if ("off".equals(mode)) { 1076 enabled = false; 1077 } else { 1078 System.err.println("Error: enabled mode must be 'on' or 'off' at " + mode); 1079 return; 1080 } 1081 1082 String packageName = nextArgRequired(); 1083 do { 1084 try { 1085 mAm.setPackageScreenCompatMode(packageName, enabled 1086 ? ActivityManager.COMPAT_MODE_ENABLED 1087 : ActivityManager.COMPAT_MODE_DISABLED); 1088 } catch (RemoteException e) { 1089 } 1090 packageName = nextArg(); 1091 } while (packageName != null); 1092 } 1093 1094 private void runDisplaySize() throws Exception { 1095 String size = nextArgRequired(); 1096 int m, n; 1097 if ("reset".equals(size)) { 1098 m = n = -1; 1099 } else { 1100 int div = size.indexOf('x'); 1101 if (div <= 0 || div >= (size.length()-1)) { 1102 System.err.println("Error: bad size " + size); 1103 return; 1104 } 1105 String mstr = size.substring(0, div); 1106 String nstr = size.substring(div+1); 1107 try { 1108 m = Integer.parseInt(mstr); 1109 n = Integer.parseInt(nstr); 1110 } catch (NumberFormatException e) { 1111 System.err.println("Error: bad number " + e); 1112 return; 1113 } 1114 } 1115 1116 if (m < n) { 1117 int tmp = m; 1118 m = n; 1119 n = tmp; 1120 } 1121 1122 IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.checkService( 1123 Context.WINDOW_SERVICE)); 1124 if (wm == null) { 1125 System.err.println(NO_SYSTEM_ERROR_CODE); 1126 throw new AndroidException("Can't connect to window manager; is the system running?"); 1127 } 1128 1129 try { 1130 if (m >= 0 && n >= 0) { 1131 // TODO(multidisplay): For now Configuration only applies to main screen. 1132 wm.setForcedDisplaySize(Display.DEFAULT_DISPLAY, m, n); 1133 } else { 1134 wm.clearForcedDisplaySize(Display.DEFAULT_DISPLAY); 1135 } 1136 } catch (RemoteException e) { 1137 } 1138 } 1139 1140 private void runDisplayDensity() throws Exception { 1141 String densityStr = nextArgRequired(); 1142 int density; 1143 if ("reset".equals(densityStr)) { 1144 density = -1; 1145 } else { 1146 try { 1147 density = Integer.parseInt(densityStr); 1148 } catch (NumberFormatException e) { 1149 System.err.println("Error: bad number " + e); 1150 return; 1151 } 1152 if (density < 72) { 1153 System.err.println("Error: density must be >= 72"); 1154 return; 1155 } 1156 } 1157 1158 IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.checkService( 1159 Context.WINDOW_SERVICE)); 1160 if (wm == null) { 1161 System.err.println(NO_SYSTEM_ERROR_CODE); 1162 throw new AndroidException("Can't connect to window manager; is the system running?"); 1163 } 1164 1165 try { 1166 if (density > 0) { 1167 // TODO(multidisplay): For now Configuration only applies to main screen. 1168 wm.setForcedDisplayDensity(Display.DEFAULT_DISPLAY, density); 1169 } else { 1170 wm.clearForcedDisplayDensity(Display.DEFAULT_DISPLAY); 1171 } 1172 } catch (RemoteException e) { 1173 } 1174 } 1175 1176 private void runToUri(boolean intentScheme) throws Exception { 1177 Intent intent = makeIntent(); 1178 System.out.println(intent.toUri(intentScheme ? Intent.URI_INTENT_SCHEME : 0)); 1179 } 1180 1181 private class IntentReceiver extends IIntentReceiver.Stub { 1182 private boolean mFinished = false; 1183 1184 @Override 1185 public void performReceive(Intent intent, int resultCode, String data, Bundle extras, 1186 boolean ordered, boolean sticky, int sendingUser) throws RemoteException { 1187 String line = "Broadcast completed: result=" + resultCode; 1188 if (data != null) line = line + ", data=\"" + data + "\""; 1189 if (extras != null) line = line + ", extras: " + extras; 1190 System.out.println(line); 1191 mFinished = true; 1192 notifyAll(); 1193 } 1194 1195 public synchronized void waitForFinish() { 1196 try { 1197 while (!mFinished) wait(); 1198 } catch (InterruptedException e) { 1199 throw new IllegalStateException(e); 1200 } 1201 } 1202 } 1203 1204 private class InstrumentationWatcher extends IInstrumentationWatcher.Stub { 1205 private boolean mFinished = false; 1206 private boolean mRawMode = false; 1207 1208 /** 1209 * Set or reset "raw mode". In "raw mode", all bundles are dumped. In "pretty mode", 1210 * if a bundle includes Instrumentation.REPORT_KEY_STREAMRESULT, just print that. 1211 * @param rawMode true for raw mode, false for pretty mode. 1212 */ 1213 public void setRawOutput(boolean rawMode) { 1214 mRawMode = rawMode; 1215 } 1216 1217 public void instrumentationStatus(ComponentName name, int resultCode, Bundle results) { 1218 synchronized (this) { 1219 // pretty printer mode? 1220 String pretty = null; 1221 if (!mRawMode && results != null) { 1222 pretty = results.getString(Instrumentation.REPORT_KEY_STREAMRESULT); 1223 } 1224 if (pretty != null) { 1225 System.out.print(pretty); 1226 } else { 1227 if (results != null) { 1228 for (String key : results.keySet()) { 1229 System.out.println( 1230 "INSTRUMENTATION_STATUS: " + key + "=" + results.get(key)); 1231 } 1232 } 1233 System.out.println("INSTRUMENTATION_STATUS_CODE: " + resultCode); 1234 } 1235 notifyAll(); 1236 } 1237 } 1238 1239 public void instrumentationFinished(ComponentName name, int resultCode, 1240 Bundle results) { 1241 synchronized (this) { 1242 // pretty printer mode? 1243 String pretty = null; 1244 if (!mRawMode && results != null) { 1245 pretty = results.getString(Instrumentation.REPORT_KEY_STREAMRESULT); 1246 } 1247 if (pretty != null) { 1248 System.out.println(pretty); 1249 } else { 1250 if (results != null) { 1251 for (String key : results.keySet()) { 1252 System.out.println( 1253 "INSTRUMENTATION_RESULT: " + key + "=" + results.get(key)); 1254 } 1255 } 1256 System.out.println("INSTRUMENTATION_CODE: " + resultCode); 1257 } 1258 mFinished = true; 1259 notifyAll(); 1260 } 1261 } 1262 1263 public boolean waitForFinish() { 1264 synchronized (this) { 1265 while (!mFinished) { 1266 try { 1267 if (!mAm.asBinder().pingBinder()) { 1268 return false; 1269 } 1270 wait(1000); 1271 } catch (InterruptedException e) { 1272 throw new IllegalStateException(e); 1273 } 1274 } 1275 } 1276 return true; 1277 } 1278 } 1279 1280 private String nextOption() { 1281 if (mCurArgData != null) { 1282 String prev = mArgs[mNextArg - 1]; 1283 throw new IllegalArgumentException("No argument expected after \"" + prev + "\""); 1284 } 1285 if (mNextArg >= mArgs.length) { 1286 return null; 1287 } 1288 String arg = mArgs[mNextArg]; 1289 if (!arg.startsWith("-")) { 1290 return null; 1291 } 1292 mNextArg++; 1293 if (arg.equals("--")) { 1294 return null; 1295 } 1296 if (arg.length() > 1 && arg.charAt(1) != '-') { 1297 if (arg.length() > 2) { 1298 mCurArgData = arg.substring(2); 1299 return arg.substring(0, 2); 1300 } else { 1301 mCurArgData = null; 1302 return arg; 1303 } 1304 } 1305 mCurArgData = null; 1306 return arg; 1307 } 1308 1309 private String nextArg() { 1310 if (mCurArgData != null) { 1311 String arg = mCurArgData; 1312 mCurArgData = null; 1313 return arg; 1314 } else if (mNextArg < mArgs.length) { 1315 return mArgs[mNextArg++]; 1316 } else { 1317 return null; 1318 } 1319 } 1320 1321 private String nextArgRequired() { 1322 String arg = nextArg(); 1323 if (arg == null) { 1324 String prev = mArgs[mNextArg - 1]; 1325 throw new IllegalArgumentException("Argument expected after \"" + prev + "\""); 1326 } 1327 return arg; 1328 } 1329 1330 private static void showUsage() { 1331 System.err.println( 1332 "usage: am [subcommand] [options]\n" + 1333 "usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]\n" + 1334 " [--R COUNT] [-S] [--opengl-trace] <INTENT>\n" + 1335 " am startservice <INTENT>\n" + 1336 " am force-stop <PACKAGE>\n" + 1337 " am kill <PACKAGE>\n" + 1338 " am kill-all\n" + 1339 " am broadcast <INTENT>\n" + 1340 " am instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w]\n" + 1341 " [--no-window-animation] <COMPONENT>\n" + 1342 " am profile start <PROCESS> <FILE>\n" + 1343 " am profile stop [<PROCESS>]\n" + 1344 " am dumpheap [flags] <PROCESS> <FILE>\n" + 1345 " am set-debug-app [-w] [--persistent] <PACKAGE>\n" + 1346 " am clear-debug-app\n" + 1347 " am monitor [--gdb <port>]\n" + 1348 " am screen-compat [on|off] <PACKAGE>\n" + 1349 " am display-size [reset|MxN]\n" + 1350 " am display-density [reset|DENSITY]\n" + 1351 " am to-uri [INTENT]\n" + 1352 " am to-intent-uri [INTENT]\n" + 1353 " am switch-user <USER_ID>\n" + 1354 " am stop-user <USER_ID>\n" + 1355 "\n" + 1356 "am start: start an Activity. Options are:\n" + 1357 " -D: enable debugging\n" + 1358 " -W: wait for launch to complete\n" + 1359 " --start-profiler <FILE>: start profiler and send results to <FILE>\n" + 1360 " -P <FILE>: like above, but profiling stops when app goes idle\n" + 1361 " -R: repeat the activity launch <COUNT> times. Prior to each repeat,\n" + 1362 " the top activity will be finished.\n" + 1363 " -S: force stop the target app before starting the activity\n" + 1364 " --opengl-trace: enable tracing of OpenGL functions\n" + 1365 "\n" + 1366 "am startservice: start a Service.\n" + 1367 "\n" + 1368 "am force-stop: force stop everything associated with <PACKAGE>.\n" + 1369 "\n" + 1370 "am kill: Kill all processes associated with <PACKAGE>. Only kills.\n" + 1371 " processes that are safe to kill -- that is, will not impact the user\n" + 1372 " experience.\n" + 1373 "\n" + 1374 "am kill-all: Kill all background processes.\n" + 1375 "\n" + 1376 "am broadcast: send a broadcast Intent.\n" + 1377 "\n" + 1378 "am instrument: start an Instrumentation. Typically this target <COMPONENT>\n" + 1379 " is the form <TEST_PACKAGE>/<RUNNER_CLASS>. Options are:\n" + 1380 " -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with\n" + 1381 " [-e perf true] to generate raw output for performance measurements.\n" + 1382 " -e <NAME> <VALUE>: set argument <NAME> to <VALUE>. For test runners a\n" + 1383 " common form is [-e <testrunner_flag> <value>[,<value>...]].\n" + 1384 " -p <FILE>: write profiling data to <FILE>\n" + 1385 " -w: wait for instrumentation to finish before returning. Required for\n" + 1386 " test runners.\n" + 1387 " --no-window-animation: turn off window animations will running.\n" + 1388 "\n" + 1389 "am profile: start and stop profiler on a process.\n" + 1390 "\n" + 1391 "am dumpheap: dump the heap of a process. Options are:\n" + 1392 " -n: dump native heap instead of managed heap\n" + 1393 "\n" + 1394 "am set-debug-app: set application <PACKAGE> to debug. Options are:\n" + 1395 " -w: wait for debugger when application starts\n" + 1396 " --persistent: retain this value\n" + 1397 "\n" + 1398 "am clear-debug-app: clear the previously set-debug-app.\n" + 1399 "\n" + 1400 "am monitor: start monitoring for crashes or ANRs.\n" + 1401 " --gdb: start gdbserv on the given port at crash/ANR\n" + 1402 "\n" + 1403 "am screen-compat: control screen compatibility mode of <PACKAGE>.\n" + 1404 "\n" + 1405 "am display-size: override display size.\n" + 1406 "\n" + 1407 "am display-density: override display density.\n" + 1408 "\n" + 1409 "am to-uri: print the given Intent specification as a URI.\n" + 1410 "\n" + 1411 "am to-intent-uri: print the given Intent specification as an intent: URI.\n" + 1412 "\n" + 1413 "am switch-user: switch to put USER_ID in the foreground, starting" + 1414 " execution of that user if it is currently stopped.\n" + 1415 "\n" + 1416 "am stop-user: stop execution of USER_ID, not allowing it to run any" + 1417 " code until a later explicit switch to it.\n" + 1418 "\n" + 1419 "<INTENT> specifications include these flags and arguments:\n" + 1420 " [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]\n" + 1421 " [-c <CATEGORY> [-c <CATEGORY>] ...]\n" + 1422 " [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]\n" + 1423 " [--esn <EXTRA_KEY> ...]\n" + 1424 " [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]\n" + 1425 " [--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]\n" + 1426 " [--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]\n" + 1427 " [--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]\n" + 1428 " [--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]\n" + 1429 " [--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]\n" + 1430 " [--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]\n" + 1431 " [--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]\n" + 1432 " [--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]\n" + 1433 " [-n <COMPONENT>] [-f <FLAGS>]\n" + 1434 " [--grant-read-uri-permission] [--grant-write-uri-permission]\n" + 1435 " [--debug-log-resolution] [--exclude-stopped-packages]\n" + 1436 " [--include-stopped-packages]\n" + 1437 " [--activity-brought-to-front] [--activity-clear-top]\n" + 1438 " [--activity-clear-when-task-reset] [--activity-exclude-from-recents]\n" + 1439 " [--activity-launched-from-history] [--activity-multiple-task]\n" + 1440 " [--activity-no-animation] [--activity-no-history]\n" + 1441 " [--activity-no-user-action] [--activity-previous-is-top]\n" + 1442 " [--activity-reorder-to-front] [--activity-reset-task-if-needed]\n" + 1443 " [--activity-single-top] [--activity-clear-task]\n" + 1444 " [--activity-task-on-home]\n" + 1445 " [--receiver-registered-only] [--receiver-replace-pending]\n" + 1446 " [--selector]\n" + 1447 " [<URI> | <PACKAGE> | <COMPONENT>]\n" 1448 ); 1449 } 1450} 1451