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