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