6.0.1 - Alpha - 增加全局Polyfill及扩展对象
This commit is contained in:
@@ -49,7 +49,7 @@ public abstract class LayoutInspectTileService extends TileService implements La
|
||||
public void onClick() {
|
||||
super.onClick();
|
||||
Log.d(getClass().getName(), "onClick");
|
||||
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
|
||||
// sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
|
||||
if (AccessibilityService.Companion.getInstance() == null) {
|
||||
Toast.makeText(this, R.string.text_no_accessibility_permission_to_capture, Toast.LENGTH_SHORT).show();
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
@@ -83,7 +83,6 @@ public abstract class LayoutInspectTileService extends TileService implements La
|
||||
inactive();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected abstract FullScreenFloatyWindow onCreateWindow(NodeInfo capture);
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
|
||||
import org.autojs.autojs.Pref;
|
||||
import org.autojs.autojs.R;
|
||||
|
||||
@@ -35,7 +36,7 @@ public class AccessibilityServiceTool {
|
||||
public static void goToAccessibilitySetting() {
|
||||
Context context = GlobalAppContext.get();
|
||||
if (Pref.isFirstGoToAccessibilitySetting()) {
|
||||
GlobalAppContext.toast(context.getString(R.string.text_please_choose) + context.getString(R.string.app_name));
|
||||
GlobalAppContext.toast(context.getString(R.string.text_please_choose) + " " + context.getString(R.string.app_name));
|
||||
}
|
||||
try {
|
||||
AccessibilityServiceUtils.INSTANCE.goToAccessibilitySetting(context);
|
||||
@@ -44,16 +45,18 @@ public class AccessibilityServiceTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static final String cmd = "enabled=$(settings get secure enabled_accessibility_services)\n" +
|
||||
"pkg=%s\n" +
|
||||
"if [[ $enabled == *$pkg* ]]\n" +
|
||||
"then\n" +
|
||||
"echo already_enabled\n" +
|
||||
"else\n" +
|
||||
"enabled=$pkg:$enabled\n" +
|
||||
"settings put secure enabled_accessibility_services $enabled\n" +
|
||||
"fi\n" +
|
||||
"settings put secure accessibility_enabled 1";
|
||||
private static final String cmd = """
|
||||
enabled=$(settings get secure enabled_accessibility_services)
|
||||
pkg=%s
|
||||
if [[ $enabled == *$pkg* ]]
|
||||
then
|
||||
echo already_enabled
|
||||
else
|
||||
enabled=$pkg:$enabled
|
||||
settings put secure enabled_accessibility_services $enabled
|
||||
fi
|
||||
settings put secure accessibility_enabled 1
|
||||
""";
|
||||
|
||||
public static boolean enableAccessibilityServiceByRoot(Class<? extends android.accessibilityservice.AccessibilityService> accessibilityService) {
|
||||
String serviceName = GlobalAppContext.get().getPackageName() + "/" + accessibilityService.getName();
|
||||
|
||||
@@ -18,13 +18,15 @@ public class RootTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static final String cmd = "enabled=$(settings get system pointer_location)\n" +
|
||||
"if [[ $enabled == 1 ]]\n" +
|
||||
"then\n" +
|
||||
"settings put system pointer_location 0\n" +
|
||||
"else\n" +
|
||||
"settings put system pointer_location 1\n" +
|
||||
"fi\n";
|
||||
private static final String cmd = """
|
||||
enabled=$(settings get system pointer_location)
|
||||
if [[ $enabled == 1 ]]
|
||||
then
|
||||
settings put system pointer_location 0
|
||||
else
|
||||
settings put system pointer_location 1
|
||||
fi
|
||||
""";
|
||||
|
||||
public static void togglePointerLocation() {
|
||||
try {
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
package org.autojs.autojs.tool;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class SafeJsonElement extends JsonElement {
|
||||
private final JsonElement mJsonElement;
|
||||
|
||||
public SafeJsonElement(JsonElement jsonElement) {
|
||||
mJsonElement = jsonElement;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JsonElement deepCopy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonArray() {
|
||||
return mJsonElement.isJsonArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonObject() {
|
||||
return mJsonElement.isJsonObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonPrimitive() {
|
||||
return mJsonElement.isJsonPrimitive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonNull() {
|
||||
return mJsonElement.isJsonNull();
|
||||
}
|
||||
|
||||
public JsonObject getAsJsonObject() {
|
||||
return mJsonElement.getAsJsonObject();
|
||||
}
|
||||
|
||||
public SafeJsonObject getAsSafeJsonObject() {
|
||||
try {
|
||||
return new SafeJsonObject(mJsonElement.getAsJsonObject());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArray getAsJsonArray() {
|
||||
return mJsonElement.getAsJsonArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonPrimitive getAsJsonPrimitive() {
|
||||
return mJsonElement.getAsJsonPrimitive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNull getAsJsonNull() {
|
||||
return mJsonElement.getAsJsonNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return mJsonElement.getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return mJsonElement.getAsNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return mJsonElement.getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAsDouble() {
|
||||
return mJsonElement.getAsDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAsFloat() {
|
||||
return mJsonElement.getAsFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAsLong() {
|
||||
return mJsonElement.getAsLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
return mJsonElement.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return mJsonElement.getAsByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getAsCharacter() {
|
||||
return mJsonElement.getAsCharacter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return mJsonElement.getAsBigDecimal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getAsBigInteger() {
|
||||
return mJsonElement.getAsBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getAsShort() {
|
||||
return mJsonElement.getAsShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mJsonElement.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
package org.autojs.autojs.tool;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class SafeJsonObject extends JsonElement {
|
||||
|
||||
private final JsonObject mJsonObject;
|
||||
|
||||
public SafeJsonObject(JsonObject jsonObject) {
|
||||
mJsonObject = jsonObject;
|
||||
}
|
||||
|
||||
public JsonObject deepCopy() {
|
||||
return mJsonObject.deepCopy();
|
||||
}
|
||||
|
||||
public void add(String property, JsonElement value) {
|
||||
mJsonObject.add(property, value);
|
||||
}
|
||||
|
||||
public JsonElement remove(String property) {
|
||||
return mJsonObject.remove(property);
|
||||
}
|
||||
|
||||
public void addProperty(String property, String value) {
|
||||
mJsonObject.addProperty(property, value);
|
||||
}
|
||||
|
||||
public void addProperty(String property, Number value) {
|
||||
mJsonObject.addProperty(property, value);
|
||||
}
|
||||
|
||||
public void addProperty(String property, Boolean value) {
|
||||
mJsonObject.addProperty(property, value);
|
||||
}
|
||||
|
||||
public void addProperty(String property, Character value) {
|
||||
mJsonObject.addProperty(property, value);
|
||||
}
|
||||
|
||||
public Set<Map.Entry<String, JsonElement>> entrySet() {
|
||||
return mJsonObject.entrySet();
|
||||
}
|
||||
|
||||
public Set<String> keySet() {
|
||||
return mJsonObject.keySet();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mJsonObject.size();
|
||||
}
|
||||
|
||||
public boolean has(String memberName) {
|
||||
return mJsonObject.has(memberName);
|
||||
}
|
||||
|
||||
public JsonElement get(String memberName) {
|
||||
return mJsonObject.get(memberName);
|
||||
}
|
||||
|
||||
public JsonPrimitive getAsJsonPrimitive(String memberName) {
|
||||
return mJsonObject.getAsJsonPrimitive(memberName);
|
||||
}
|
||||
|
||||
public JsonArray getAsJsonArray(String memberName) {
|
||||
return mJsonObject.getAsJsonArray(memberName);
|
||||
}
|
||||
|
||||
public JsonObject getAsJsonObject(String memberName) {
|
||||
return mJsonObject.getAsJsonObject(memberName);
|
||||
}
|
||||
|
||||
public boolean isJsonArray() {
|
||||
return mJsonObject.isJsonArray();
|
||||
}
|
||||
|
||||
public boolean isJsonObject() {
|
||||
return mJsonObject.isJsonObject();
|
||||
}
|
||||
|
||||
public boolean isJsonPrimitive() {
|
||||
return mJsonObject.isJsonPrimitive();
|
||||
}
|
||||
|
||||
public boolean isJsonNull() {
|
||||
return mJsonObject.isJsonNull();
|
||||
}
|
||||
|
||||
public JsonObject getAsJsonObject() {
|
||||
return mJsonObject.getAsJsonObject();
|
||||
}
|
||||
|
||||
public JsonArray getAsJsonArray() {
|
||||
return mJsonObject.getAsJsonArray();
|
||||
}
|
||||
|
||||
public JsonPrimitive getAsJsonPrimitive() {
|
||||
return mJsonObject.getAsJsonPrimitive();
|
||||
}
|
||||
|
||||
public JsonNull getAsJsonNull() {
|
||||
return mJsonObject.getAsJsonNull();
|
||||
}
|
||||
|
||||
public boolean getAsBoolean() {
|
||||
return mJsonObject.getAsBoolean();
|
||||
}
|
||||
|
||||
public Number getAsNumber() {
|
||||
return mJsonObject.getAsNumber();
|
||||
}
|
||||
|
||||
public String getAsString() {
|
||||
return mJsonObject.getAsString();
|
||||
}
|
||||
|
||||
public double getAsDouble() {
|
||||
return mJsonObject.getAsDouble();
|
||||
}
|
||||
|
||||
public float getAsFloat() {
|
||||
return mJsonObject.getAsFloat();
|
||||
}
|
||||
|
||||
public long getAsLong() {
|
||||
return mJsonObject.getAsLong();
|
||||
}
|
||||
|
||||
public int getAsInt() {
|
||||
return mJsonObject.getAsInt();
|
||||
}
|
||||
|
||||
public byte getAsByte() {
|
||||
return mJsonObject.getAsByte();
|
||||
}
|
||||
|
||||
public char getAsCharacter() {
|
||||
return mJsonObject.getAsCharacter();
|
||||
}
|
||||
|
||||
public BigDecimal getAsBigDecimal() {
|
||||
return mJsonObject.getAsBigDecimal();
|
||||
}
|
||||
|
||||
public BigInteger getAsBigInteger() {
|
||||
return mJsonObject.getAsBigInteger();
|
||||
}
|
||||
|
||||
public short getAsShort() {
|
||||
return mJsonObject.getAsShort();
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,36 @@ package org.autojs.autojs.tool;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.DhcpInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.Log;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import static android.content.Context.WIFI_SERVICE;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/11.
|
||||
*/
|
||||
|
||||
public class WifiTool {
|
||||
|
||||
public static String getWifiAddress(Context context) {
|
||||
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
if(wifiMgr == null){
|
||||
return null;
|
||||
public static String getRouterIp(Context context) {
|
||||
byte[] ipAddressByte = getIpAddressByte(context);
|
||||
try {
|
||||
return InetAddress.getByAddress(ipAddressByte).getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
Log.e(WifiTool.class.getSimpleName(), "Error getting Hotspot IP address ", e);
|
||||
return "0.0.0.0";
|
||||
}
|
||||
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
|
||||
int ip = wifiInfo.getIpAddress();
|
||||
return Formatter.formatIpAddress(ip);
|
||||
}
|
||||
|
||||
public static String getRouterIp(Context context){
|
||||
WifiManager wifiService = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
if(wifiService == null){
|
||||
return null;
|
||||
private static byte[] getIpAddressByte(Context context) {
|
||||
WifiManager manager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
DhcpInfo dhcp = manager.getDhcpInfo();
|
||||
int ipAddress = dhcp.gateway;
|
||||
if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
|
||||
ipAddress = Integer.reverseBytes(ipAddress);
|
||||
}
|
||||
DhcpInfo dhcpInfo = wifiService.getDhcpInfo();
|
||||
return Formatter.formatIpAddress(dhcpInfo.gateway);
|
||||
return BigInteger.valueOf(ipAddress).toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,15 +155,14 @@ public class CircularMenu implements Recorder.OnStateChangedListener, LayoutInsp
|
||||
mWindow.collapse();
|
||||
if (!RootTool.isRootAvailable()) {
|
||||
DialogUtils.showDialog(new NotAskAgainDialog.Builder(mContext, "CircularMenu.root")
|
||||
.title(R.string.text_device_not_rooted)
|
||||
.content(R.string.prompt_device_not_rooted)
|
||||
.neutralText(R.string.text_device_rooted)
|
||||
.positiveText(R.string.ok)
|
||||
.onNeutral(((dialog, which) -> mRecorder.start()))
|
||||
.title(R.string.text_no_root_access)
|
||||
.content(R.string.no_root_access_for_record)
|
||||
.negativeText(R.string.text_quit)
|
||||
.positiveText(R.string.text_insist_on_record)
|
||||
.onPositive(((dialog, which) -> mRecorder.start()))
|
||||
.build());
|
||||
} else {
|
||||
mRecorder.start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,9 +155,7 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
if (checked && !isAccessibilityServiceEnabled) {
|
||||
enableAccessibilityService();
|
||||
} else if (!checked && isAccessibilityServiceEnabled) {
|
||||
if (!AccessibilityService.Companion.disable()) {
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
}
|
||||
disableAccessibilityService();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,26 +175,27 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
}
|
||||
boolean checked = holder.getSwitchCompat().isChecked();
|
||||
if (checked && !enabled) {
|
||||
if (new NotAskAgainDialog.Builder(context, "DrawerFragment.usage_stats")
|
||||
.title(R.string.text_usage_stats_permission)
|
||||
.content(R.string.description_usage_stats_permission)
|
||||
.positiveText(R.string.ok)
|
||||
.dismissListener(dialog -> {
|
||||
if (context != null) {
|
||||
IntentUtil.requestAppUsagePermission(context);
|
||||
}
|
||||
})
|
||||
.show() == null) {
|
||||
if (context != null) {
|
||||
IntentUtil.requestAppUsagePermission(context);
|
||||
}
|
||||
if (getUsageStatsDialog(context) == null) {
|
||||
syncSwitchState();
|
||||
}
|
||||
}
|
||||
if (!checked && enabled) {
|
||||
} else if (!checked && enabled) {
|
||||
IntentUtil.requestAppUsagePermission(context);
|
||||
}
|
||||
}
|
||||
|
||||
private MaterialDialog getUsageStatsDialog(Context context) {
|
||||
return new NotAskAgainDialog.Builder(context, "DrawerFragment.usage_stats")
|
||||
.title(R.string.text_usage_stats_permission)
|
||||
.content(R.string.description_usage_stats_permission)
|
||||
.positiveText(R.string.ok)
|
||||
.dismissListener(dialog -> {
|
||||
if (context != null) {
|
||||
IntentUtil.requestAppUsagePermission(context);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
void showOrDismissFloatingWindow(DrawerMenuItemViewHolder holder) {
|
||||
boolean isFloatingWindowShowing = FloatyWindowManger.isCircularMenuShowing();
|
||||
boolean checked = holder.getSwitchCompat().isChecked();
|
||||
@@ -273,6 +272,7 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
private boolean hasWriteSecureSettingsAccess() {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
@SuppressLint("WrongConstant")
|
||||
int checkVal = context.checkCallingOrSelfPermission(WRITE_SECURE_SETTINGS_PERMISSION);
|
||||
return checkVal == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
@@ -373,7 +373,7 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
Observable.fromCallable(() -> Pref.shouldEnableAccessibilityServiceByRoot() && !isAccessibilityServiceEnabled())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(needed -> {
|
||||
if (needed) {
|
||||
if (needed && RootTool.isRootAvailable()) {
|
||||
enableAccessibilityServiceByRoot();
|
||||
}
|
||||
});
|
||||
@@ -457,11 +457,17 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
}
|
||||
|
||||
private void enableAccessibilityService() {
|
||||
if (!Pref.shouldEnableAccessibilityServiceByRoot()) {
|
||||
if (Pref.shouldEnableAccessibilityServiceByRoot() && RootTool.isRootAvailable()) {
|
||||
enableAccessibilityServiceByRoot();
|
||||
} else {
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
}
|
||||
}
|
||||
|
||||
private void disableAccessibilityService() {
|
||||
if (!AccessibilityService.Companion.disable()) {
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
return;
|
||||
}
|
||||
enableAccessibilityServiceByRoot();
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
|
||||
Reference in New Issue
Block a user