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);
}
/** @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);
Am命令的更多相关文章
-
Cmder--Windows下命令行利器
cmder cmder是一个增强型命令行工具,不仅可以使用windows下的所有命令,更爽的是可以使用linux的命令,shell命令. 安装包 安装包链接 下载后,直接解压即用. 修改命令提示符λ为 ...
-
【每日一linux命令4】常用参数:
下面所列的是常见的参数(选项)义: --help,-h 显示帮助信息 --version,-V ...
-
.NET Core系列 : 1、.NET Core 环境搭建和命令行CLI入门
2016年6月27日.NET Core & ASP.NET Core 1.0在Redhat峰会上正式发布,社区里涌现了很多文章,我也计划写个系列文章,原因是.NET Core的入门门槛相当高, ...
-
MVVM模式解析和在WPF中的实现(三)命令绑定
MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
-
SQLServer执行命令出现“目录无效的提示”
异常处理汇总-数据库系列 http://www.cnblogs.com/dunitian/p/4522990.html 一般都是清理垃圾清理过头了,把不该删的目录删了 网上说法: 问题描述: 1.s ...
-
SQLServer文件收缩-图形化+命令
汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql 收缩前 图形化演示: 不仅仅可以收缩日记文件,数据库文件也是可以收缩的,只不过日记收缩比 ...
-
让 windows 下的命令行程序 cmd.exe 用起来更顺手
在 Windows 下使用 Larave 框架做开发,从 Composer 到 artisan 总是避免不了和 cmd.exe 打交道,系统默认的命令行界面却是不怎么好看,且每行显示的字符数是做了限制 ...
-
[版本控制之道] Git 常用的命令总结(欢迎收藏备用)
坚持每天学习,坚持每天复习,技术永远学不完,自己永远要前进 总结日常开发生产中常用的Git版本控制命令 ------------------------------main-------------- ...
-
git 命令
切换仓库地址: git remote set-url origin xxx.git切换分支:git checkout name撤销修改:git checkout -- file删除文件:git rm ...
-
svn 常用命令总结
svn 命令篇 svn pget svn:ignore // 查看忽略项 svn commit -m "提交说明" // 提交修改 svn up(update) // 获取最新版本 ...
随机推荐
-
铁区MES部分页面展示
激活码: 76231722-2e7554593-b750-07e2f4844531 TIP: 若您激活不成功,可能是因为您所安装的软件版本较低,请尝试以下激活码 激活码: RXWY-A25421-K5 ...
-
JSON解析实例——使用Json-lib
JSON解析实例——使用Json-lib Json-lib下载及使用 本文介绍用一个类库进行JSON解析. 工具下载地址:http://sourceforge.net/projects/json-li ...
-
求教——使用node做表单,刷新浏览器页面,浏览器为什么会重复提交上次所填的信息
最近在学些node,按照<nodejs实战>上的代码做练习,发现有表单重复提交的问题 第一次打开页面,显示如图是get请求 图1 现在我们提交aaa,显示如图,post请求 图2 刷新页面 ...
-
busybox rx 命令
rx命令使用xmodem传送文件,只需要串口线就传送. 在文件系统输入如下命令,传送文件到板子上,板子上保存文件的名称为file rx file 在secureCRT中选择Transfer->S ...
-
通过Delphi获得qq安装路径
procedure TForm1.Button2Click(Sender: TObject); var Reg:TRegistry; Val:TStrings; ii:System.Integer; ...
-
Unity3d 随机地图生成
2D解析图: 3D地形: 嘿嘿.
-
Visual Studio 2015 Update 3 RC 候选预览版粗来了
.Net 基金会 http://www.dotnetfoundation.org/ 更新的真快,刚打完2的补丁包,3就粗来了............ https://www.visualstudio. ...
-
Oracle安装过程物理内存检查及临时temp空间不足解决办法
物理内存 – 此先决条件将测试系统物理内存总量是否至少为 922MB (944128.0KB). 预期值 : N/A 实际值 : N/A 错误列表: – 可用物理内存 PRVF-7531 : 无法在节 ...
-
MySQL事物管理
sql语句对数据库操作构成事物. 事物的特性:ACID •Atomicity(原子性):一个事物要么全都被执行,要么全都不执行,不会存在执行结束在中间环节.如果事物在执行过程中发生异常,则会回滚到事物 ...
-
Docker(2):快速入门及常用命令
什么是Docker? Docker 是世界领先的软件容器平台.开发人员利用 Docker 可以消除协作编码时“在我的机器上可正常工作”的问题.运维人员利用 Docker 可以在隔离容器中并行运行和管理 ...