Am命令

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


时间: 2024-10-19 11:57:06

Am命令的相关文章

linux常用命令--netstat

简介 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接等等. 常用参数 -a (all)显示所有选项,提示:LISTEN和LISTENING的状态只有用-a或者-l才能看到-t (tcp)仅显示tcp相关选项-u (udp)仅显示udp相关选项-n 拒绝显示别名,能显示数字的全部转化成数字.-l 仅列出有在 Listen (监听) 的服務状态 -p 显示建立相关链接的程序名-r 显示路由信息,路由

使用fruitstrap实现命令行将IPA包安装到iOS设备上

Requirements Mac OS X. Tested on Snow Leopard only. You need to have a valid iPhone development certificate installed. Xcode must be installed, along with the SDK for your iOS version. Usage fruitstrap [-d] -b <app> [device_id] Optional -d flag laun

Linux基础命令小结

注意:Linux严格区分大小写 老男孩方法论经验之谈: 有一种方法叫做没方法 有两种方法,左右为难 有三种方法才叫有方法 停止一个命令:CTR + C 1.创建目录 英文:make directorys 命令:mkdir 实例:三种方式 mkdir /data cd / mkdir data cd /;mkdir data mkdir x y z    表示同时创建多个目录 mkdir -p /data/x/y   表示同时创建多级目录(递归创建),切记不可用mkdir /data/x/y 2.

10.6 监控io性能 - 10.7 free命令 - 10.8 ps命令 - 10.9 查看网络状态 - 10.10 linux下抓包

- 10.6 监控io性能 - 10.7 free命令 - 10.8 ps命令 - 10.9 查看网络状态 - 10.10 linux下抓包 - 扩展tcp三次握手四次挥手 http://www.doc88.com/p-9913773324388.html  - tshark几个用法:http://www.aminglinux.com/bbs/thread-995-1-1.html  # 10.6 监控io性能 ![mark](http://oqxf7c508.bkt.clouddn.com/b

uboot下的命令使用示例

1.usb 可以使用此命令读取u盘里的内容,此命令加上相关参数可以有以下功能: 1.1usb start 在使用u盘之前必须启动此命令以初始化好fat文件系统环境,笔者的输出如下: jello # usb start(Re)start USB...USB:   Starting the controllerscanning bus for devices... 5 USB Device(s) found       scanning bus for storage devices... usb_

reset master和reset slave命令解析和区别

reset master删除所有index file 中记录的所有binlog 文件,将日志索引文件清空,创建一个新的日志文件,这个命令通常仅仅用于第一次用于搭建主从关系的时的主库, 注意: reset master 不同于purge binary log的两处地方1.reset master 将删除日志索引文件中记录的所有binlog文件,创建一个新的日志文件 起始值从000001 开始,然而purge binary log 命令并不会修改记录binlog的顺序的数值2.reset maste

【Windows10&nbsp;IoT开发系列】Powershell命令行实用程序

原文:[Windows10 IoT开发系列]Powershell命令行实用程序 更新帐户密码: 强烈建议你更新默认的管理员帐户密码.若要更新帐户密码,你可以发出以下命令: net user Administrator [new password]​ (其中 [new password] 表示你选择的强密码). 创建本地用户帐户: 如果你想要授予其他人访问你的 Windows IoT Core 设备的权限,你可以通过在 net user [username] [password] /add​ 中键

windows下cmd命令行显示UTF8字符设置(CHCP命令)

在中文windows系统中,如果一个文本文件是utf-8编码的,那么在cmd.exe命令行窗口(所谓的dos窗口)中不能正确显示文件中的内容.在默认情况下,命令行窗口中使用的代码页是中文或者美国的,即编码是中文字符集或者西文字符集. 如果想正确显示UTF-8字符,可以按照以下步骤操作: 1.打开CMD.exe命令行窗口 2.通过 chcp命令改变代码页,UTF-8的代码页为65001 1 chcp 65001 执行该操作后,代码页就被变成UTF-8了.但是,在窗口中仍旧不能正确显示UTF-8字符

WAF——针对Web应用发起的攻击,包括但不限于以下攻击类型:SQL注入、XSS跨站、Webshell上传、命令注入、非法HTTP协议请求、非授权文件访问等

核心概念 WAF Web应用防火墙(Web Application Firewall),简称WAF. Web攻击 针对Web应用发起的攻击,包括但不限于以下攻击类型:SQL注入.XSS跨站.Webshell上传.命令注入.非法HTTP协议请求.非授权文件访问等.

Linux 帮助命令

help 命令只能显示 shell 内部的命令帮助信息,而对于外部命令的帮助信息只能使用 man 或者 info 命令查看,info 指令是 man 指令的详细内容 [[email protected] ~]# help pwd [[email protected] ~]# man pwd [[email protected] ~]# info pwd