Am.java中:

Override
public void onRun() throws Exception {
mAm = ActivityManagerNative.getDefault();
if (mAm == null) {
System.err.println(NO_SYSTEM_ERROR_CODE);
throw new AndroidException("Can't connect to activity manager; is the system running?");
}
String op = nextArgRequired();
if (op.equals("start")) {
runStart();
... private Intent makeIntent(int defUser) throws URISyntaxException {
Intent intent = new Intent();
Intent baseIntent = intent;
boolean hasIntentInfo = false;
mStartFlags = 0;
mWaitOption = false;
mStopOption = false;
mRepeat = 0;
mProfileFile = null;
mUserId = defUser;
Uri data = null;
String type = null;
String opt;
while ((opt=nextOption()) != null) {
if (opt.equals("-a")) {
intent.setAction(nextArgRequired());
if (intent == baseIntent) {
hasIntentInfo = true;
}
} else if (opt.equals("-d")) {
data = Uri.parse(nextArgRequired());
if (intent == baseIntent) {
hasIntentInfo = true;
}
} else if (opt.equals("-t")) {
type = nextArgRequired();
if (intent == baseIntent) {
hasIntentInfo = true;
}
} else if (opt.equals("-c")) {
intent.addCategory(nextArgRequired());
if (intent == baseIntent) {
hasIntentInfo = true;
}
} else if (opt.equals("-e") || opt.equals("--es")) {
String key = nextArgRequired();
String value = nextArgRequired();
intent.putExtra(key, value);
} else if (opt.equals("--esn")) {
String key = nextArgRequired();
intent.putExtra(key, (String) null);
} else if (opt.equals("--ei")) {
String key = nextArgRequired();
String value = nextArgRequired();
intent.putExtra(key, Integer.valueOf(value));
} else if (opt.equals("--eu")) {
String key = nextArgRequired();
String value = nextArgRequired();
intent.putExtra(key, Uri.parse(value));
} else if (opt.equals("--ecn")) {
String key = nextArgRequired();
String value = nextArgRequired();
ComponentName cn = ComponentName.unflattenFromString(value);
if (cn == null) throw new IllegalArgumentException("Bad component name: " + value);
intent.putExtra(key, cn);
} else if (opt.equals("--eia")) {
String key = nextArgRequired();
String value = nextArgRequired();
String[] strings = value.split(",");
int[] list = new int[strings.length];
for (int i = 0; i < strings.length; i++) {
list[i] = Integer.valueOf(strings[i]);
}
intent.putExtra(key, list);
} else if (opt.equals("--el")) {
String key = nextArgRequired();
String value = nextArgRequired();
intent.putExtra(key, Long.valueOf(value));
} else if (opt.equals("--ela")) {
String key = nextArgRequired();
String value = nextArgRequired();
String[] strings = value.split(",");
long[] list = new long[strings.length];
for (int i = 0; i < strings.length; i++) {
list[i] = Long.valueOf(strings[i]);
}
intent.putExtra(key, list);
hasIntentInfo = true;
} else if (opt.equals("--ef")) {
String key = nextArgRequired();
String value = nextArgRequired();
intent.putExtra(key, Float.valueOf(value));
hasIntentInfo = true;
} else if (opt.equals("--efa")) {
String key = nextArgRequired();
String value = nextArgRequired();
String[] strings = value.split(",");
float[] list = new float[strings.length];
for (int i = 0; i < strings.length; i++) {
list[i] = Float.valueOf(strings[i]);
}
intent.putExtra(key, list);
hasIntentInfo = true;
} else if (opt.equals("--ez")) {
String key = nextArgRequired();
String value = nextArgRequired();
intent.putExtra(key, Boolean.valueOf(value));
} else if (opt.equals("-n")) {
String str = nextArgRequired();
ComponentName cn = ComponentName.unflattenFromString(str);
if (cn == null) throw new IllegalArgumentException("Bad component name: " + str);
intent.setComponent(cn);
if (intent == baseIntent) {
hasIntentInfo = true;
}
} else if (opt.equals("-f")) {
String str = nextArgRequired();
intent.setFlags(Integer.decode(str).intValue());
} else if (opt.equals("--grant-read-uri-permission")) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else if (opt.equals("--grant-write-uri-permission")) {
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
} else if (opt.equals("--exclude-stopped-packages")) {
intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
} else if (opt.equals("--include-stopped-packages")) {
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
} else if (opt.equals("--debug-log-resolution")) {
intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
} else if (opt.equals("--activity-brought-to-front")) {
intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
} else if (opt.equals("--activity-clear-top")) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else if (opt.equals("--activity-clear-when-task-reset")) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
} else if (opt.equals("--activity-exclude-from-recents")) {
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
} else if (opt.equals("--activity-launched-from-history")) {
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
} else if (opt.equals("--activity-multiple-task")) {
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
} else if (opt.equals("--activity-no-animation")) {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
} else if (opt.equals("--activity-no-history")) {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
} else if (opt.equals("--activity-no-user-action")) {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
} else if (opt.equals("--activity-previous-is-top")) {
intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
} else if (opt.equals("--activity-reorder-to-front")) {
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
} else if (opt.equals("--activity-reset-task-if-needed")) {
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
} else if (opt.equals("--activity-single-top")) {
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
} else if (opt.equals("--activity-clear-task")) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
} else if (opt.equals("--activity-task-on-home")) {
intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
} else if (opt.equals("--receiver-registered-only")) {
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
} else if (opt.equals("--receiver-replace-pending")) {
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
} else if (opt.equals("--selector")) {
intent.setDataAndType(data, type);
intent = new Intent();
} else if (opt.equals("-D")) {
mStartFlags |= ActivityManager.START_FLAG_DEBUG;
} else if (opt.equals("-W")) {
mWaitOption = true;
} else if (opt.equals("-P")) {
mProfileFile = nextArgRequired();
mStartFlags |= ActivityManager.START_FLAG_AUTO_STOP_PROFILER;
} else if (opt.equals("--start-profiler")) {
mProfileFile = nextArgRequired();
mStartFlags &= ~ActivityManager.START_FLAG_AUTO_STOP_PROFILER;
} else if (opt.equals("-R")) {
mRepeat = Integer.parseInt(nextArgRequired());
} else if (opt.equals("-S")) {
mStopOption = true;
} else if (opt.equals("--opengl-trace")) {
mStartFlags |= ActivityManager.START_FLAG_OPENGL_TRACES;
} else if (opt.equals("--user")) {
mUserId = parseUserArg(nextArgRequired());
} else if (opt.equals("--receiver-permission")) {
mReceiverPermission = nextArgRequired();
} else {
System.err.println("Error: Unknown option: " + opt);
return null;
}
}
intent.setDataAndType(data, type);
final boolean hasSelector = intent != baseIntent;
if (hasSelector) {
// A selector was specified; fix up.
baseIntent.setSelector(intent);
intent = baseIntent;
}
String arg = nextArg();
baseIntent = null;
if (arg == null) {
if (hasSelector) {
// If a selector has been specified, and no arguments
// have been supplied for the main Intent, then we can
// assume it is ACTION_MAIN CATEGORY_LAUNCHER; we don't
// need to have a component name specified yet, the
// selector will take care of that.
baseIntent = new Intent(Intent.ACTION_MAIN);
baseIntent.addCategory(Intent.CATEGORY_LAUNCHER);
}
} else if (arg.indexOf(':') >= 0) {
// The argument is a URI. Fully parse it, and use that result
// to fill in any data not specified so far.
baseIntent = Intent.parseUri(arg, Intent.URI_INTENT_SCHEME);
} else if (arg.indexOf('/') >= 0) {
// The argument is a component name. Build an Intent to launch
// it.
baseIntent = new Intent(Intent.ACTION_MAIN);
baseIntent.addCategory(Intent.CATEGORY_LAUNCHER);
baseIntent.setComponent(ComponentName.unflattenFromString(arg));
} else {
// Assume the argument is a package name.
baseIntent = new Intent(Intent.ACTION_MAIN);
baseIntent.addCategory(Intent.CATEGORY_LAUNCHER);
baseIntent.setPackage(arg);
}
if (baseIntent != null) {
Bundle extras = intent.getExtras();
intent.replaceExtras((Bundle)null);
Bundle uriExtras = baseIntent.getExtras();
baseIntent.replaceExtras((Bundle)null);
if (intent.getAction() != null && baseIntent.getCategories() != null) {
HashSet<String> cats = new HashSet<String>(baseIntent.getCategories());
for (String c : cats) {
baseIntent.removeCategory(c);
}
}
intent.fillIn(baseIntent, Intent.FILL_IN_COMPONENT | Intent.FILL_IN_SELECTOR);
if (extras == null) {
extras = uriExtras;
} else if (uriExtras != null) {
uriExtras.putAll(extras);
extras = uriExtras;
}
intent.replaceExtras(extras);
hasIntentInfo = true;
}
if (!hasIntentInfo) throw new IllegalArgumentException("No intent supplied");
return intent;
} private void runStart() throws Exception {
Intent intent = makeIntent(UserHandle.USER_CURRENT);
if (mUserId == UserHandle.USER_ALL) {
System.err.println("Error: Can't start service with user 'all'");
return;
}
String mimeType = intent.getType();
if (mimeType == null && intent.getData() != null
&& "content".equals(intent.getData().getScheme())) {
mimeType = mAm.getProviderMimeType(intent.getData(), mUserId);
}
do {
if (mStopOption) {
String packageName;
if (intent.getComponent() != null) {
packageName = intent.getComponent().getPackageName();
} else {
IPackageManager pm = IPackageManager.Stub.asInterface(
ServiceManager.getService("package"));
if (pm == null) {
System.err.println("Error: Package manager not running; aborting");
return;
}
List<ResolveInfo> activities = pm.queryIntentActivities(intent, mimeType, 0,
mUserId);
if (activities == null || activities.size() <= 0) {
System.err.println("Error: Intent does not match any activities: "
+ intent);
return;
} else if (activities.size() > 1) {
System.err.println("Error: Intent matches multiple activities; can't stop: "
+ intent);
return;
}
packageName = activities.get(0).activityInfo.packageName;
}
System.out.println("Stopping: " + packageName);
mAm.forceStopPackage(packageName, mUserId);
Thread.sleep(250);
} System.out.println("Starting: " + intent);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ParcelFileDescriptor fd = null; if (mProfileFile != null) {
try {
fd = ParcelFileDescriptor.open(
new File(mProfileFile),
ParcelFileDescriptor.MODE_CREATE |
ParcelFileDescriptor.MODE_TRUNCATE |
ParcelFileDescriptor.MODE_READ_WRITE);
} catch (FileNotFoundException e) {
System.err.println("Error: Unable to open file: " + mProfileFile);
return;
}
}
IActivityManager.WaitResult result = null;
int res;
if (mWaitOption) {
result = mAm.startActivityAndWait(null, null, intent, mimeType,
null, null, 0, mStartFlags, mProfileFile, fd, null, mUserId);
res = result.result;
} else {
res = mAm.startActivityAsUser(null, null, intent, mimeType,
null, null, 0, mStartFlags, mProfileFile, fd, null, mUserId);
}
PrintStream out = mWaitOption ? System.out : System.err;
boolean launched = false;
switch (res) {
case ActivityManager.START_SUCCESS:
launched = true;
break;
case ActivityManager.START_SWITCHES_CANCELED:
launched = true;
out.println(
"Warning: Activity not started because the "
+ " current activity is being kept for the user.");
break;
case ActivityManager.START_DELIVERED_TO_TOP:
launched = true;
out.println(
"Warning: Activity not started, intent has "
+ "been delivered to currently running "
+ "top-most instance.");
break;
case ActivityManager.START_RETURN_INTENT_TO_CALLER:
launched = true;
out.println(
"Warning: Activity not started because intent "
+ "should be handled by the caller");
break;
case ActivityManager.START_TASK_TO_FRONT:
launched = true;
out.println(
"Warning: Activity not started, its current "
+ "task has been brought to the front");
break;
case ActivityManager.START_INTENT_NOT_RESOLVED:
out.println(
"Error: Activity not started, unable to "
+ "resolve " + intent.toString());
break;
case ActivityManager.START_CLASS_NOT_FOUND:
out.println(NO_CLASS_ERROR_CODE);
out.println("Error: Activity class " +
intent.getComponent().toShortString()
+ " does not exist.");
break;
case ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT:
out.println(
"Error: Activity not started, you requested to "
+ "both forward and receive its result");
break;
case ActivityManager.START_PERMISSION_DENIED:
out.println(
"Error: Activity not started, you do not "
+ "have permission to access it.");
break;
default:
out.println(
"Error: Activity not started, unknown error code " + res);
break;
}
if (mWaitOption && launched) {
if (result == null) {
result = new IActivityManager.WaitResult();
result.who = intent.getComponent();
}
System.out.println("Status: " + (result.timeout ? "timeout" : "ok"));
if (result.who != null) {
System.out.println("Activity: " + result.who.flattenToShortString());
}
if (result.thisTime >= 0) {
System.out.println("ThisTime: " + result.thisTime);
}
if (result.totalTime >= 0) {
System.out.println("TotalTime: " + result.totalTime);
}
System.out.println("Complete");
}
mRepeat--;
if (mRepeat > 1) {
mAm.unhandledBack();
}
} while (mRepeat > 1);
}

UserHandle.java

 /** @hide A user id to indicate all users on the device */
public static final int USER_ALL = -1;
/** @hide A user handle to indicate all users on the device */
public static final UserHandle ALL = new UserHandle(USER_ALL);
/** @hide A user id to indicate the currently active user */
public static final int USER_CURRENT = -2;
/** @hide A user handle to indicate the current user of the device */
public static final UserHandle CURRENT = new UserHandle(USER_CURRENT);

ComponentName.java


Am命令的更多相关文章

  1. Cmder--Windows下命令行利器

    cmder cmder是一个增强型命令行工具,不仅可以使用windows下的所有命令,更爽的是可以使用linux的命令,shell命令. 安装包 安装包链接 下载后,直接解压即用. 修改命令提示符λ为 ...

  2. 【每日一linux命令4】常用参数:

     下面所列的是常见的参数(选项)义: --help,-h                              显示帮助信息 --version,-V                        ...

  3. .NET Core系列 : 1、.NET Core 环境搭建和命令行CLI入门

    2016年6月27日.NET Core & ASP.NET Core 1.0在Redhat峰会上正式发布,社区里涌现了很多文章,我也计划写个系列文章,原因是.NET Core的入门门槛相当高, ...

  4. MVVM模式解析和在WPF中的实现(三)命令绑定

    MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  5. SQLServer执行命令出现“目录无效的提示”

    异常处理汇总-数据库系列  http://www.cnblogs.com/dunitian/p/4522990.html 一般都是清理垃圾清理过头了,把不该删的目录删了 网上说法: 问题描述: 1.s ...

  6. SQLServer文件收缩-图形化+命令

    汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql 收缩前 图形化演示: 不仅仅可以收缩日记文件,数据库文件也是可以收缩的,只不过日记收缩比 ...

  7. 让 windows 下的命令行程序 cmd.exe 用起来更顺手

    在 Windows 下使用 Larave 框架做开发,从 Composer 到 artisan 总是避免不了和 cmd.exe 打交道,系统默认的命令行界面却是不怎么好看,且每行显示的字符数是做了限制 ...

  8. [版本控制之道] Git 常用的命令总结(欢迎收藏备用)

    坚持每天学习,坚持每天复习,技术永远学不完,自己永远要前进 总结日常开发生产中常用的Git版本控制命令 ------------------------------main-------------- ...

  9. git 命令

    切换仓库地址: git remote set-url origin xxx.git切换分支:git checkout name撤销修改:git checkout -- file删除文件:git rm  ...

  10. svn 常用命令总结

    svn 命令篇 svn pget svn:ignore // 查看忽略项 svn commit -m "提交说明" // 提交修改 svn up(update) // 获取最新版本 ...

随机推荐

  1. .Net程序员学习Linux(二)

    本次知识点:递归命令符,wc命令,文档编辑器 vi的简单使用,文本常用操作命令,find查询文件命令,grep匹配文本中对应的关键字 递归命令符 递归对于程序猿来说不默认,经常用于级联关系,一层套一层 ...

  2. SqlSugar-执行Sql语句查询实例

    使用SqlSugar执行sql语句 1.简单查询 SqlSugarClient db = SugarContext.GetInstance(); //执行sql语句,处理 //1.执行sql,转成li ...

  3. python中文件类的应用

    python中对文件.文件夹的操作需要涉及到os模块和shutil模块. 创建文件: 1) os.mknod("test.txt") 创建空文件 2) open("tes ...

  4. Redhat linux DNS配置指南(SCANIP配置手册)

    在oracle 11g的RAC中增加了SCAN IP,而使用 SCAN IP的一种方式就是使用DNS,这里介绍在Redhat Linux 5.4中DNS的详细配置操作在配置DNS之前修改主机名Redh ...

  5. 跨域的小小总结:js跨域及跨域的几种解决方法

    一.什么是跨域?? js跨域请求就是使用js访问iframe里的不同域名下的页面内容,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同的域的iframe框架中的数据.即只要域名.协议. ...

  6. Angularjs总结(五)指令运用及常用控件的赋值操作

    1.常用指令 <div ng-controller="jsyd-controller"> <div style="float:left;width:10 ...

  7. pl/sql编程

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...

  8. 一个由IsPrime算法引发的细节问题

    //******************************* // //    2014年9月18日星期四,于宿舍撰写 //    作者:夏华林 // //******************* ...

  9. 转载:Python正则表达式

    原文在  http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html 1. 正则表达式基础 1.1. 简单介绍 正则表达式并不是Python ...

  10. gnome中文翻译之po

    文件类型: po: 用msginit分析pot文件,生成各语言对应的po文件,比如中文的zh_CN.po. mo: 用msgfmt将po文件编译生成mo文件,这是二进制文件,不能直接编辑. gmo: ...