新增 app.startActivity(), app.sendBroadcast(), app.startService()支持root模式
新增 app.intentToShell()
This commit is contained in:
@@ -190,14 +190,6 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onTextContextMenuItem(int id) {
|
|
||||||
if (id == android.R.id.paste) {
|
|
||||||
ClipboardUtil.setClip(getContext(), ClipboardUtil.getClip(getContext()).toString());
|
|
||||||
}
|
|
||||||
return super.onTextContextMenuItem(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
//该方法中内联了很多函数来提高效率 但是 这是必要的吗???
|
//该方法中内联了很多函数来提高效率 但是 这是必要的吗???
|
||||||
// 绘制文本着色
|
// 绘制文本着色
|
||||||
private void drawText(Canvas canvas) {
|
private void drawText(Canvas canvas) {
|
||||||
|
|||||||
@@ -62,7 +62,11 @@ module.exports = function (runtime, global) {
|
|||||||
throw new Error("class " + i + " not found");
|
throw new Error("class " + i + " not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context.startActivity(app.intent(i).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
if(i && i.root) {
|
||||||
|
shell("am start " + app.intentToShell(i), true);
|
||||||
|
}else{
|
||||||
|
context.startActivity(app.intent(i).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.sendBroadcast = function (i) {
|
app.sendBroadcast = function (i) {
|
||||||
@@ -71,7 +75,19 @@ module.exports = function (runtime, global) {
|
|||||||
app.sendLocalBroadcastSync(app.intent({ action: runtime.getProperty("broadcast." + i) }));
|
app.sendLocalBroadcastSync(app.intent({ action: runtime.getProperty("broadcast." + i) }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context.sendBroadcast(app.intent(i));
|
if(i && i.root) {
|
||||||
|
shell("am broadcast " + app.intentToShell(i), true);
|
||||||
|
}else{
|
||||||
|
context.sendBroadcast(app.intent(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.startService = function(i) {
|
||||||
|
if(i && i.root) {
|
||||||
|
shell("am startservice " + app.intentToShell(i), true);
|
||||||
|
}else{
|
||||||
|
context.startService(app.intent(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.sendEmail = function (options) {
|
app.sendEmail = function (options) {
|
||||||
@@ -139,6 +155,101 @@ module.exports = function (runtime, global) {
|
|||||||
versionName: org.autojs.autojs.BuildConfig.VERSION_NAME
|
versionName: org.autojs.autojs.BuildConfig.VERSION_NAME
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.intentToShell = function(i) {
|
||||||
|
var cmd = "";
|
||||||
|
function quoteStr(str) {
|
||||||
|
return "'" + str.replace("'", "\\'") + "'";
|
||||||
|
}
|
||||||
|
function isInt(value) {
|
||||||
|
return Bumber.isInteger(value) && value <= java.lang.Integer.MAX_VALUE && value >= java.lang.Integer.MIN_VALUE;
|
||||||
|
}
|
||||||
|
function typeChar(value){
|
||||||
|
if(typeof(value) == 'boolean'){
|
||||||
|
return 'z';
|
||||||
|
}
|
||||||
|
if(typeof(value) == 'number'){
|
||||||
|
if(Number.isInteger(value)){
|
||||||
|
if(isInt(value)){
|
||||||
|
return 'i';
|
||||||
|
}else{
|
||||||
|
return 'l';
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return 'f';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new TypeError("unknown type: " + value);
|
||||||
|
}
|
||||||
|
function addOption(option, param, quote) {
|
||||||
|
if(quote == undefined || quote === true){
|
||||||
|
param = quoteStr(param);
|
||||||
|
}
|
||||||
|
cmd += " -" + option + " " + param;
|
||||||
|
}
|
||||||
|
if (i.className && i.packageName) {
|
||||||
|
addOption("n", i.packageName + "/" + i.className);
|
||||||
|
}
|
||||||
|
if (i.extras) {
|
||||||
|
for (var key in i.extras) {
|
||||||
|
let value = i.extras[key];
|
||||||
|
if(typeof(value) == 'string'){
|
||||||
|
addOption("-es", quoteStr(key) + ' ' + quoteStr(value), false);
|
||||||
|
}else if(Array.isArray(value)){
|
||||||
|
if(value.length == 0){
|
||||||
|
throw new Error('Empty array: ' + key);
|
||||||
|
}
|
||||||
|
var e = value[0];
|
||||||
|
if(typeof(e) == 'string'){
|
||||||
|
cmd += ' --esa ' + quoteStr(key) + ' ';
|
||||||
|
for(let str of value){
|
||||||
|
cmd += quoteStr(str) + ',';
|
||||||
|
}
|
||||||
|
cmd = cmd.substring(0, cmd.length - 1);
|
||||||
|
}else{
|
||||||
|
addOption('-e' + typeChar(e) + 'a', quoteStr(key) + ' ' + value, false);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
addOption('-e' + typeChar(value), quoteStr(key) + ' ' + value, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i.category) {
|
||||||
|
if (i.category instanceof Array) {
|
||||||
|
for (var j = 0; i < i.category.length; j++) {
|
||||||
|
addOption('c', i.category[j], false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addOption('c', i.category, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i.action) {
|
||||||
|
if (i.action.indexOf(".") == -1) {
|
||||||
|
i.action = "android.intent.action." + i.action;
|
||||||
|
}
|
||||||
|
addOption('a', i.action);
|
||||||
|
}
|
||||||
|
if (i.flags) {
|
||||||
|
let flags = 0;
|
||||||
|
if (Array.isArray(i.flags)) {
|
||||||
|
for (let j = 0; j < i.flags.length; j++) {
|
||||||
|
flags |= parseIntentFlag(i.flags[j]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
flags = parseIntentFlag(i.flags);
|
||||||
|
}
|
||||||
|
addOption('f', flags, false);
|
||||||
|
}
|
||||||
|
if (i.type) {
|
||||||
|
addOption('t', i.type, false);
|
||||||
|
}
|
||||||
|
if (i.data) {
|
||||||
|
addOption('d', i.data, false);
|
||||||
|
}
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
global.__asGlobal__(app, ['launchPackage', 'launch', 'launchApp', 'getPackageName', 'getAppName', 'openAppSetting']);
|
global.__asGlobal__(app, ['launchPackage', 'launch', 'launchApp', 'getPackageName', 'getAppName', 'openAppSetting']);
|
||||||
|
|
||||||
function parseIntentFlag(flag) {
|
function parseIntentFlag(flag) {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":439,"versionName":"4.0.4 Alpha10","enabled":true,"outputFile":"commonRelease-4.0.4 Alpha10.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.0.4 Alpha10.apk","properties":{}}]
|
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":440,"versionName":"4.0.4 Alpha11","enabled":true,"outputFile":"commonRelease-4.0.4 Alpha11.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.0.4 Alpha11.apk","properties":{}}]
|
||||||
@@ -3,6 +3,7 @@ package com.stardust.util;
|
|||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user