Commit 64644f5b by lihuaikun

整理架构

parent f7bcbea6
package com.android.launcher3.auto_get_permission;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.GestureDescription;
import android.annotation.TargetApi;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Build;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.util.Logger;
import java.util.List;
public class AccessibilityNodeOperateUtil {
private static final String TAG = "AccessibilityNodeOperateUtil";
public static AccessibilityNodeInfo getChildNodeEqual(AccessibilityNodeInfo root, String text) {
if (root == null)
return null;
if (root.getChildCount() > 0) {
for (int i = 0; i < root.getChildCount(); i++) {
AccessibilityNodeInfo child = root.getChild(i);
if (child == null)
continue;
Logger.e(TAG, child.getViewIdResourceName() + "\t" + child.getChildCount() + "child child\t" + child.toString());
List<AccessibilityNodeInfo> nodeInfoList = child.findAccessibilityNodeInfosByText(text);
if (nodeInfoList != null && nodeInfoList.size() > 0) {
for (AccessibilityNodeInfo findNode : nodeInfoList) {
Logger.e(TAG, findNode.getChildCount() + "fuzzy \t" + findNode.toString());
if (findNode.getText() == null)
continue;
if (findNode.getText().toString().equals(text)) {
Logger.e(TAG, "find equal \t" + findNode.toString());
return findNode;
}
}
}
child = getChildNodeEqual(child, text);
if (child == null) {
continue;
}
if (child.getContentDescription() == null) {
continue;
}
if (child.getContentDescription().toString().equals(text)) {
// Logger.e(TAG, "find equal \t" + child.toString());
return child;
}
}
}
return null;
}
public static AccessibilityNodeInfo getChildNodeEqualByContentDesc(AccessibilityNodeInfo root, String text) {
if (root == null)
return null;
if (root.getChildCount() > 0) {
for (int i = 0; i < root.getChildCount(); i++) {
AccessibilityNodeInfo child = root.getChild(i);
if (child == null)
continue;
// Logger.e(TAG, child.getViewIdResourceName() + "\t" + child.getChildCount() + "child child\t" + child.toString());
if (child.getContentDescription() != null && child.getContentDescription().toString().equals(text)) {
// Logger.e(TAG, "find equal \t" + child.toString());
return child;
}
child = getChildNodeEqualByContentDesc(child, text);
if (child == null) {
continue;
}
if (child.getContentDescription() == null) {
continue;
}
if (child.getContentDescription().toString().equals(text)) {
// Logger.e(TAG, "find equal \t" + child.toString());
return child;
}
}
}
return null;
}
public static AccessibilityNodeInfo getChildNodeByIdEqualText(AccessibilityNodeInfo root, String viewId, String text) {
if (root == null)
return null;
List<AccessibilityNodeInfo> nodeInfoList = root.findAccessibilityNodeInfosByViewId(viewId);
if (nodeInfoList != null && nodeInfoList.size() > 0) {
for (AccessibilityNodeInfo childNode : nodeInfoList) {
if (childNode.getText() == null)
continue;
if (childNode.getText().toString().equals(text)) {
// Logger.e(TAG, "find equal \t" + childNode.toString());
return childNode;
}
}
}
return null;
}
@TargetApi(Build.VERSION_CODES.O)
public static boolean click(AccessibilityService service, Rect bounds) {
Path path = new Path();
path.moveTo(bounds.left + (bounds.right - bounds.left) / 2, bounds.top + (bounds.bottom - bounds.top) / 2);
path.lineTo(bounds.left + (bounds.right - bounds.left) / 2, bounds.top + (bounds.bottom - bounds.top) / 2);
GestureDescription description = new GestureDescription.Builder().addStroke(new GestureDescription.StrokeDescription(path, 0, 50)).build();
boolean isDispatch = service.dispatchGesture(description, new AccessibilityService.GestureResultCallback() {
@Override
public void onCompleted(GestureDescription gestureDescription) {
// Logger.e(TAG, "onCompleted");
}
@Override
public void onCancelled(GestureDescription gestureDescription) {
super.onCancelled(gestureDescription);
// Logger.e(TAG, "onCancelled");
}
}, null);
// Logger.e(TAG, "isDispatch\t" + isDispatch);
return isDispatch;
}
}
package com.android.launcher3.auto_get_permission;
import android.accessibilityservice.AccessibilityService;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.manager.LauncherManager;
import com.android.launcher3.util.KToast;
import com.android.launcher3.util.Logger;
import com.android.launcher3.util.PermissionUtil;
import com.android.launcher3.util.SystemUtils;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BACK;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_HOME;
public abstract class BaseAutoGetPermission {
private static final String TAG = "BaseAutoGetPermission";
public static final long MAX_SEARCH_TIME = 4000;
public static final int BREAK_WHILE = 2;
// public static String appName = "倍知守护孩子端";
public static String appName = "dankal_launcher";
public boolean isRunning;
private KToast toast;
private PermissionOpenAccessiblityService service;
// private boolean breadWhile = false;
private Handler handler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
if (!isRunning) {
service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
}
break;
}
}
};
public BaseAutoGetPermission(PermissionOpenAccessiblityService service) {
this.service = service;
isRunning = false;
isFinish = false;
handler.sendEmptyMessageDelayed(0, 1000);
// Logger.e(TAG, "onServiceConnected\t");
service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
showToastLong("辅助权限设置已开启,请根据提示点击,如无提示请等待片刻");
toast = new KToast(service.getApplicationContext());
}
private boolean isFinish = false;
public int step;
public void start() {
isRunning = true;
}
public void stop() {
isRunning = false;
}
public void operateAccessibilityEvent(AccessibilityEvent event){
if (step == 1) {
if (event.getClassName() != null) {
if (event.getSource() != null) {
if (PermissionUtil.checkDeviceAdminPermission(getApplicationContext())) {
resetStep();
} else {
requestkDeviceAdmin(event);
}
} else {
if (SystemUtils.isOPPO()) {
if ("android.widget.FrameLayout".equals(event.getClassName()) && event.getPackageName().equals("com.sohu.inputmethod.sogouoem")) {
showToastLong("请在此处手动输入验证码");
}
}
}
}
}
if (step == 2) {
if (event.getClassName() != null) {
if (SystemUtils.isNOKIA() && event.getSource() == null) {
getService().performGlobalAction(GLOBAL_ACTION_HOME);
getService().performGlobalAction(GLOBAL_ACTION_BACK);
}
if (event.getSource() != null) {
if (PermissionUtil.checkBatteryOptimize(getApplicationContext())) {
resetStep();
} else {
requestBatteryOptimize(event);
}
}
}
}
if (step == 3) {
if (event.getClassName() != null) {
if (event.getSource() != null) {
if (PermissionUtil.checkAppUsagePermission(getApplicationContext())) {
resetStep();
} else {
requestUsageAppPermission(event);
}
}
}
}
if (step == 4) {
if (event.getClassName() != null) {
if (event.getSource() == null)
return;
if (!PermissionUtil.enAbleADB(getApplicationContext())) {
resetStep();
} else {
requestCloseUSB(event);
}
}
}
if (step == 5) {
if (event.getClassName() != null) {
if (event.getSource() == null)
return;
if (PermissionUtil.isNotificationListenersEnabled(getApplicationContext())) {
resetStep();
} else {
requestNotificationPermission(event);
}
}
}
//设置默认桌面
if (step == 6) {
if (PermissionUtil.isDefaultHome(getApplicationContext()))
return;
if (event.getSource() == null)
return;
if (event.getClassName() == null)
return;
if (PermissionUtil.isDefaultHome(getApplicationContext())) {
resetStep();
} else {
requestDefaultLauncher(event);
}
}
if (!PermissionUtil.checkDeviceAdminPermission(getApplicationContext())) {
if (step != 1) {
if (SystemUtils.isMIUI()) {
if (event.getClassName().toString().contains("com.android.settings")) {
step = 1;
operateAccessibilityEvent(event);
return;
}
}
gotoDeviceAdminPermissionSetting();
sleep();
return;
}
if (step == 1) {
if (PermissionUtil.checkDeviceAdminPermission(getApplicationContext())) {
resetStep();
} else {
return;
}
}
}
if (!PermissionUtil.checkBatteryOptimize(getApplicationContext()) && !SystemUtils.isSAMSUNG()) {
if (step != 2) {
if (SystemUtils.isMIUI()) {
if (event.getClassName().toString().contains("com.android.settings")) {
step = 2;
operateAccessibilityEvent(event);
}
}
gotoBatteryOptimize();
sleep();
return;
}
if (step == 2) {
if (PermissionUtil.checkBatteryOptimize(getApplicationContext())) {
resetStep();
} else {
// if (SystemUtils.isNOKIA()) {
// if (event.getSource() != null) {
// requestBatteryOptimize(event);
// }
// }
return;
}
}
}
if (!PermissionUtil.checkAppUsagePermission(getApplicationContext())) {
if (step != 3) {
gotoAppUsagePermission();
sleep();
return;
}
if (step == 3) {
if (PermissionUtil.checkAppUsagePermission(getApplicationContext())) {
resetStep();
} else {
// requestUsageAppPermission(event);
return;
}
}
}
if (PermissionUtil.enAbleADB(getApplicationContext())) {
if (step != 4) {
gotoDeveloperChoice();
sleep();
requestCloseUSB(event);
return;
}
if (step == 4) {
if (!PermissionUtil.enAbleADB(getApplicationContext())) {
resetStep();
} else {
// requestCloseUSB(event);
return;
}
}
}
if (!PermissionUtil.isNotificationListenersEnabled(getApplicationContext())) {
if (step != 5) {
gotoNotificationSettings();
sleep();
requestNotificationPermission(event);
return;
}
if (step == 5) {
if (PermissionUtil.isNotificationListenersEnabled(getApplicationContext())) {
resetStep();
} else {
// requestNotificationPermission(event);
return;
}
}
}
if (!PermissionUtil.isDefaultHome(getApplicationContext())) {
if (step != 6) {
if (!SystemUtils.isMEIZU()) {
gotoDefaultLauncherSetting();
} else {
//8.0设置换了布局viewid
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
gotoDefaultLauncherSetting();
} else {
gotoSystemSettings();
}
}
sleep();
return;
}
if (step == 6) {
if (PermissionUtil.isDefaultHome(getApplicationContext())) {
resetStep();
} else {
return;
}
}
}
if (!isFinish) {
isFinish = true;
Logger.e(TAG, "finish");
LauncherManager.getInstance().changeExitState(false);
service. finish();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
service.disableSelf();
}
}
}
public void showToastLong(String msg) {
handler.post(new Runnable() {
@Override
public void run() {
Logger.e(TAG, "showToastLong\t" + msg);
toast.setText("倍知守护提醒您 : \n" + msg);
toast.show();
}
});
}
/**
* 跳转之后停顿等待一会
*/
public void sleep() {
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void sleepLong() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void sleepLongLong() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void sleepShort() {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void sleepWarnningDialogByXiaomi() {
try {
Logger.e(TAG, "sleepWarnningDialogByXiaomi start");
Thread.sleep(5000);
Logger.e(TAG, "sleepWarnningDialogByXiaomi\t" + Thread.currentThread().getName());
} catch (InterruptedException e) {
Logger.e(TAG, "sleepWarnningDialogByXiaomi InterruptedException");
}
}
public boolean performAction(AccessibilityNodeInfo accessibilityNodeInfo1, int action) {
boolean result = false;
if (accessibilityNodeInfo1 != null) {
if (accessibilityNodeInfo1.isClickable()) {
result = accessibilityNodeInfo1.performAction(action);
Logger.e(TAG, "child \t" + result);
// if (result) {
// dismissToast();
// return result;
// }
} else {
if (accessibilityNodeInfo1.getParent() != null) {
result = accessibilityNodeInfo1.getParent().performAction(action);
Logger.e(TAG, "parent\t" + result);
// if (result) {
// dismissToast();
// return result;
// }
}
}
if (!result && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Rect bounds = new Rect();
accessibilityNodeInfo1.getBoundsInScreen(bounds);
result = AccessibilityNodeOperateUtil.click(service, bounds);
Logger.e(TAG, "android o genture\t" + result);
// if (result) {
// dismissToast();
// return result;
// }
}
}
return result;
}
public boolean clickXiaomiSafeWarning(AccessibilityNodeInfo sourceNode) {
int count = 3;
Logger.e(TAG, "clickXiaomiSafeWarning");
while (count > 0) {
Logger.e(TAG, "enter DeviceManagerApplyActivity");
sleepWarnningDialogByXiaomi();
AccessibilityNodeInfo nextStepNodeInfo = AccessibilityNodeOperateUtil.getChildNodeEqual(sourceNode, "下一步");
if (nextStepNodeInfo != null) {
nextStepNodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
--count;
}
AccessibilityNodeInfo allowBtnNode = AccessibilityNodeOperateUtil.getChildNodeEqual(sourceNode, "允许");
if (allowBtnNode != null) {
allowBtnNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
--count;
return true;
}
}
return false;
}
public Context getApplicationContext() {
return service.getApplicationContext();
}
public void resetStep() {
// 针对某些机型获取权限之后短暂时间内依然返回false
// if (step == 1) {
// PermissionUtil.isAdminDevice = true;
// try {
// Thread.sleep(2000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
// PermissionUtil.isAdminDevice = false;
// }
if (step == 2) {
// if (SystemUtils.isMIUI()) {
PermissionUtil.isBatterySaveClose = true;
// }
}
step = 0;
service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
}
public AccessibilityService getService() {
return service;
}
public void gotoDeviceAdminPermissionSetting() {
step = 1;
PermissionUtil.gotoDeviceAdminPermissionSetting(getApplicationContext());
}
public void gotoBatteryOptimize() {
step = 2;
PermissionUtil.gotoBatteryOptimize(getApplicationContext());
}
public void gotoAppUsagePermission() {
if (SystemUtils.isMIUI()) {
PermissionUtil.gotoSystemSetting(getApplicationContext());
} else {
PermissionUtil.gotoAppUsagePermission(getApplicationContext());
}
step = 3;
}
public void gotoDeveloperChoice() {
PermissionUtil.gotoDeveloperChoice(getApplicationContext());
step = 4;
}
public void gotoNotificationSettings() {
PermissionUtil.goToNotificationAccessSetting(getApplicationContext());
step = 5;
}
public void gotoDefaultLauncherSetting() {
PermissionUtil.setDefaultL(getApplicationContext());
step = 6;
}
public void gotoSystemSettings() {
PermissionUtil.gotoSystemSetting(getApplicationContext());
step = 6;
}
public abstract void requestkDeviceAdmin(AccessibilityEvent event);
public abstract void requestBatteryOptimize(AccessibilityEvent event);
public abstract void requestUsageAppPermission(AccessibilityEvent event);
public abstract void requestCloseUSB(AccessibilityEvent event);
public abstract void requestNotificationPermission(AccessibilityEvent event);
public abstract void requestDefaultLauncher(AccessibilityEvent event);
}
package com.android.launcher3.auto_get_permission;
import android.accessibilityservice.AccessibilityService;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.*;
/**
* 通用的权限获取
*/
public class GeneralAutoGetPermission extends BaseAutoGetPermission {
public GeneralAutoGetPermission(PermissionOpenAccessiblityService service) {
super(service);
}
@Override
public void requestkDeviceAdmin(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$DeviceAdminSettingsActivity".equals(event.getClassName().toString())) {
// 已跳转到设备管理器页面
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, appName);
if (!performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】应用并点击");
return;
} else {
sleep();
}
} else if ("com.android.settings.DeviceAdminAdd".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/restricted_action");
if (nodeInfoList != null && nodeInfoList.size() > 0) {
nodeInfoList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
resetStep();
} else {
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, "激活");
if (accessibilityNodeInfo1 != null && performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【启用/激活此设备管理员】");
return;
}
}
}
}
@Override
public void requestBatteryOptimize(AccessibilityEvent event) {
}
@Override
public void requestUsageAppPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$UsageAccessSettingsActivity".equals(event.getClassName())) {
getChildNodeEqual(sourceNode, appName);
sleep();
List<AccessibilityNodeInfo> appListNodeList = null;
// getChildNodeEqual(sourceNode,appName);
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (appListNodeList == null || appListNodeList.isEmpty()) {
//
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/apps_list");
}
if (appListNodeList != null && appListNodeList.size() > 0) {
AccessibilityNodeInfo appListNode = appListNodeList.get(0);
AccessibilityNodeInfo targetAppItem = null;
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (appListNode.isScrollable()) {
appListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
appListNode.refresh();
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
} else {
break;
}
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】并点击");
return;
} else {
List<AccessibilityNodeInfo> switcherNodeList = targetAppItem.getParent().findAccessibilityNodeInfosByViewId("com.android.settings:id/app_switch");
if (switcherNodeList != null && !switcherNodeList.isEmpty() && performAction(switcherNodeList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
// resetStep();
}
}
}
} else if ("android.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo allowNode = getChildNodeEqual(sourceNode, "允许");
if (allowNode == null) {
allowNode = getChildNodeEqual(sourceNode, "确定");
}
if (performAction(allowNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
/**
* 使用记录访问权限(华为设备不同设备标题不同)
*/
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && (event.getText().toString().contains("使用情况访问权限") || event.getText().toString().contains("使用记录访问权限") || event.getText().toString().contains("使用量数据访问"))) {
if (SystemUtils.isSAMSUNG()) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许追踪使用情况");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【允许追踪使用情况】并返回上一页");
return;
}
} else if (SystemUtils.isNOKIA()) {
sleep();
List<AccessibilityNodeInfo> switchWidgetNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetNodeList != null && switchWidgetNodeList.size() > 0) {
if (switchWidgetNodeList.get(0).isChecked()) {
resetStep();
}
switchWidgetNodeList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
AccessibilityNodeInfo textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许访问使用记录");
if (textViewNode != null && textViewNode.getParent() != null) {
if (textViewNode.getParent().isClickable()) {
textViewNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许查看使用情况");
if (performAction(textViewNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【允许查看使用情况】并返回上一页");
return;
}
}
}
}
}
@Override
public void requestCloseUSB(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode=event.getSource();
if ("com.android.settings.Settings$DevelopmentSettingsActivity".equals(event.getClassName())) {
// oppo也是这个页面
getChildNodeEqual(sourceNode, "USB 调试");
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (listViewNodes == null || listViewNodes.isEmpty()) {
listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
}
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB调试");
if (usbNode == null) {
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
long time = System.currentTimeMillis();
while (usbNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB调试");
if (usbNode == null) {
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
}
if (usbNode != null && usbNode.getParent() != null) {
if (SystemUtils.isOPPO()) {
List<AccessibilityNodeInfo> switchWidgetList = usbNode.getParent().findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetList != null && !switchWidgetList.isEmpty()) {
switchWidgetList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
resetStep();
}
} else {
usbNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
// resetStep();
}
}
}
}
}
@Override
public void requestNotificationPermission(AccessibilityEvent event) {
}
@Override
public void requestDefaultLauncher(AccessibilityEvent event) {
AccessibilityNodeInfo nodeInfo=event.getSource();
if ("com.android.internal.app.ResolverActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetAppNode = getChildNodeEqual(nodeInfo, appName);
if (targetAppNode != null && targetAppNode.getParent() != null) {
targetAppNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
}
List<AccessibilityNodeInfo> alwaysBtnList = nodeInfo.findAccessibilityNodeInfosByViewId("android:id/button_always");
if (alwaysBtnList != null && alwaysBtnList.size() > 0) {
alwaysBtnList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
// AccessibilityNodeInfo alwaysBtn = getChildNodeByIdEqualText(nodeInfo, "android:id/button_always");
}
}
}
package com.android.launcher3.auto_get_permission.honor;
import android.accessibilityservice.AccessibilityService;
import android.content.ComponentName;
import android.content.Intent;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.util.Logger;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BACK;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.getChildNodeByIdEqualText;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.getChildNodeEqual;
public class HonorAutoPermissionGetter extends BaseAutoGetPermission {
private static final String TAG="HonorAutoPermissionGetter";
public HonorAutoPermissionGetter(PermissionOpenAccessiblityService service) {
super(service);
}
@Override
public void start() {
super.start();
}
@Override
public void stop() {
super.stop();
}
@Override
public void requestkDeviceAdmin(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$DeviceAdminSettingsActivity".equals(event.getClassName().toString())) {
// 已跳转到设备管理器页面
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, appName);
if (!performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】应用并点击");
return;
} else {
sleep();
}
}else if ("com.android.settings.DeviceAdminAdd".equals(event.getClassName().toString())) {
AccessibilityNodeInfo accessibilityNodeInfo = getChildNodeByIdEqualText(sourceNode, "com.android.settings:id/action_button", "激活");
// List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/action_button");
// if (nodeInfoList != null && nodeInfoList.size() > 0) {
// nodeInfoList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
// sleep();
//
// }
if (performAction(accessibilityNodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【启用/激活此设备管理员】");
return;
}
}
}
@Override
public void requestBatteryOptimize(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode=event.getSource();
if ("com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity".equals(event.getClassName())) {
List<AccessibilityNodeInfo> listViewNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/lv_listview");
if (listViewNodeList != null && listViewNodeList.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodeList.get(0);
AccessibilityNodeInfo targetAppNode = getChildNodeByIdEqualText(listViewNode, "com.huawei.systemmanager:id/tv_title", appName);
long time = System.currentTimeMillis();
while (targetAppNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
targetAppNode = getChildNodeByIdEqualText(listViewNode, "com.huawei.systemmanager:id/tv_title", appName);
}
// 将自动管理的swicher关闭
if (targetAppNode.getParent() != null) {
List<AccessibilityNodeInfo> switcherNodes = targetAppNode.getParent().findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/switcher");
if (switcherNodes != null && switcherNodes.size() > 0) {
if (switcherNodes.get(0).isCheckable()) {
if (switcherNodes.get(0).isChecked()) {
targetAppNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
} else {
List<AccessibilityNodeInfo> manualBtnList = sourceNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/listitem_all_manual");
long time2 = System.currentTimeMillis();
while ((manualBtnList == null || manualBtnList.size() <= 0) && System.currentTimeMillis() - time2 < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
manualBtnList = sourceNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/listitem_all_manual");
}
if (manualBtnList.size() > 0 && manualBtnList.get(0).getParent() != null) {
manualBtnList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
}
}
}
}
}
}
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
List<AccessibilityNodeInfo> switcherNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/switcher");
if (switcherNodes != null && switcherNodes.size() > 0) {
for (AccessibilityNodeInfo switcherNode : switcherNodes) {
if (switcherNode.isCheckable() && !switcherNode.isChecked()) {
switcherNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
//
// performGlobalAction(GLOBAL_ACTION_BACK);
// sleep();
}
}
if ("com.huawei.systemmanager.appcontrol.activity.BatchManuControlActivity".equals(event.getClassName())) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo nodeInfo = getChildNodeByIdEqualText(listViewNode, "com.huawei.systemmanager:id/tv_title", appName);
long time = System.currentTimeMillis();
while (nodeInfo == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
nodeInfo = getChildNodeByIdEqualText(listViewNode, "com.huawei.systemmanager:id/tv_title", appName);
}
if (nodeInfo != null && nodeInfo.getParent() != null) {
AccessibilityNodeInfo linearNode = nodeInfo.getParent();
List<AccessibilityNodeInfo> checkBoxNodeList = linearNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/auto_checkbox");
if (checkBoxNodeList != null && checkBoxNodeList.size() > 0) {
if (!checkBoxNodeList.get(0).isChecked()) {
checkBoxNodeList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
List<AccessibilityNodeInfo> checkBoxNode2List = linearNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/associate_checkbox");
if (checkBoxNode2List != null && checkBoxNode2List.size() > 0) {
if (!checkBoxNode2List.get(0).isChecked()) {
checkBoxNode2List.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
List<AccessibilityNodeInfo> checkBoxNode3List = linearNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/background_checkbox");
if (checkBoxNode3List != null && checkBoxNode3List.size() > 0) {
if (!checkBoxNode3List.get(0).isChecked()) {
checkBoxNode3List.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
// PermissionUtil.isIgnoreBatteryOptimize = true;
// resetStep();
gotoBatteryOptimizeOnlyHUAWEI();
sleep();
}
}
}
long time2 = System.currentTimeMillis();
if ("com.android.settings.Settings$HighPowerApplicationsActivity".equals(event.getClassName())) {
boolean loadFinish = false;
do {
AccessibilityNodeInfo allAppNodeInfo = getChildNodeEqual(sourceNode, "所有应用");
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许");
if (allAppNodeInfo != null) {
loadFinish = true;
getChildNodeEqual(sourceNode, appName);
List<AccessibilityNodeInfo> listViewNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodeList != null && listViewNodeList.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodeList.get(0);
AccessibilityNodeInfo targetAppNode = getChildNodeEqual(listViewNode, appName);
long time = System.currentTimeMillis();
while (nodeInfo == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
targetAppNode = getChildNodeEqual(listViewNode, appName);
}
if (performAction(targetAppNode, AccessibilityNodeInfo.ACTION_CLICK)) {
Logger.e(TAG, "忽略电池\t" + targetAppNode.toString());
sleepShort();
} else {
showToastLong("请找到【" + appName + "】并点击");
return;
}
}
} else {
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
loadFinish = true;
nodeInfo.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
} else {
showToastLong("请点击【允许】");
return;
}
}
} while (!loadFinish && System.currentTimeMillis() - time2 < MAX_SEARCH_TIME);
}
if ("android.widget.FrameLayout".equals(event.getClassName())) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "所有应用");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepLongLong();
sourceNode.refresh();
operateAccessibilityEvent(event);
} else {
showToastLong("请点击【所有应用】");
return;
}
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
if (event.getText() != null && event.getText().toString().contains(appName)) {
AccessibilityNodeInfo acceptTvNode = getChildNodeEqual(sourceNode, "允许");
if (acceptTvNode != null && acceptTvNode.getParent() != null) {
acceptTvNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
AccessibilityNodeInfo deterBtnNode = getChildNodeEqual(sourceNode, "确定");
if (performAction(deterBtnNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
} else {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
}
}
}
@Override
public void requestUsageAppPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$UsageAccessSettingsActivity".equals(event.getClassName())) {
getChildNodeEqual(sourceNode, appName);
sleep();
List<AccessibilityNodeInfo> appListNodeList = null;
// getChildNodeEqual(sourceNode,appName);
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (appListNodeList == null || appListNodeList.isEmpty()) {
//
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/apps_list");
}
if (appListNodeList != null && appListNodeList.size() > 0) {
AccessibilityNodeInfo appListNode = appListNodeList.get(0);
AccessibilityNodeInfo targetAppItem = null;
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (appListNode.isScrollable()) {
appListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
appListNode.refresh();
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
} else {
break;
}
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】并点击");
return;
} else {
List<AccessibilityNodeInfo> switcherNodeList = targetAppItem.getParent().findAccessibilityNodeInfosByViewId("com.android.settings:id/app_switch");
if (switcherNodeList != null && !switcherNodeList.isEmpty() && performAction(switcherNodeList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
// resetStep();
}
}
}
} else if ("android.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo allowNode = getChildNodeEqual(sourceNode, "允许");
if (allowNode == null) {
allowNode = getChildNodeEqual(sourceNode, "确定");
}
if (performAction(allowNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
/**
* 使用记录访问权限(华为设备不同设备标题不同)
*/
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && (event.getText().toString().contains("使用情况访问权限") || event.getText().toString().contains("使用记录访问权限") || event.getText().toString().contains("使用量数据访问"))) {
if (SystemUtils.isSAMSUNG()) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许追踪使用情况");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【允许追踪使用情况】并返回上一页");
return;
}
} else if (SystemUtils.isNOKIA()) {
sleep();
List<AccessibilityNodeInfo> switchWidgetNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetNodeList != null && switchWidgetNodeList.size() > 0) {
if (switchWidgetNodeList.get(0).isChecked()) {
resetStep();
}
switchWidgetNodeList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
AccessibilityNodeInfo textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许访问使用记录");
if (textViewNode != null && textViewNode.getParent() != null) {
if (textViewNode.getParent().isClickable()) {
textViewNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许查看使用情况");
if (performAction(textViewNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【允许查看使用情况】并返回上一页");
return;
}
}
}
}
}
@Override
public void requestCloseUSB(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode=event.getSource();
if ("com.android.settings.Settings$DevelopmentSettingsActivity".equals(event.getClassName())) {
// oppo也是这个页面
getChildNodeEqual(sourceNode, "USB 调试");
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (listViewNodes == null || listViewNodes.isEmpty()) {
listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
}
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB调试");
if (usbNode == null) {
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
long time = System.currentTimeMillis();
while (usbNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB调试");
if (usbNode == null) {
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
}
if (usbNode != null && usbNode.getParent() != null) {
if (SystemUtils.isOPPO()) {
List<AccessibilityNodeInfo> switchWidgetList = usbNode.getParent().findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetList != null && !switchWidgetList.isEmpty()) {
switchWidgetList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
resetStep();
}
} else {
usbNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
// resetStep();
}
}
}
}
}
@Override
public void requestNotificationPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$NotificationAccessSettingsActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetApp = getChildNodeEqual(sourceNode, appName);
if (!performAction(targetApp, AccessibilityNodeInfo.ACTION_CLICK)) {
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (nodeInfoList != null && nodeInfoList.size() > 0) {
AccessibilityNodeInfo listViewNode = nodeInfoList.get(0);
AccessibilityNodeInfo targetAppItem = getChildNodeByIdEqualText(listViewNode, "android:id/title", appName);
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
}
}
targetAppItem = getChildNodeByIdEqualText(listViewNode, "android:id/title", appName);
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请点击【" + appName + "】");
return;
}
} else {
showToastLong("请点击【" + appName + "】");
}
}
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
// 允许
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/button1");
if (nodeInfoList != null && nodeInfoList.size() > 0 && performAction(nodeInfoList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
return;
} else {
showToastLong("请点击【允许】");
return;
}
}
}
@Override
public void requestDefaultLauncher(AccessibilityEvent event) {
AccessibilityNodeInfo nodeInfo = event.getSource();
if ("com.android.settings.HWSettings".equals(event.getClassName())) {
AccessibilityNodeInfo accessibilityNodeInfo = getChildNodeEqual(nodeInfo, "应用和通知");
if (performAction(accessibilityNodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
return;
} else {
showToastLong("请点击【应用和通知】");
return;
}
}
if ("com.android.settings.Settings$AppAndNotificationDashboardActivity".equals(event.getClassName())) {
AccessibilityNodeInfo defaultAppSetting = getChildNodeEqual(nodeInfo, "默认应用");
if (performAction(defaultAppSetting, AccessibilityNodeInfo.ACTION_CLICK)) {
return;
} else {
showToastLong("请点击【默认应用】");
return;
}
}
if ("com.android.settings.SubSettings".equals(event.getClassName()) && TextUtils.equals("[默认应用]", event.getText().toString())) {
// 默认应用
AccessibilityNodeInfo defaultLauncherSetting = getChildNodeEqual(nodeInfo, "桌面");
if (performAction(defaultLauncherSetting, AccessibilityNodeInfo.ACTION_CLICK)) {
return;
} else {
showToastLong("请点击【桌面】");
return;
}
}
if ("com.android.settings.Settings$PreferredSettingsActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetAppNode = getChildNodeEqual(nodeInfo, appName);
if (performAction(targetAppNode, AccessibilityNodeInfo.ACTION_CLICK)) {
} else {
showToastLong("请点击【" + appName + "】");
return;
}
return;
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
if (event.getText() != null) {
String text = event.getText().toString();
if (text.contains("更换默认桌面")) {
AccessibilityNodeInfo changeBtn = getChildNodeEqual(nodeInfo, "更换");
if (performAction(changeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【更换】");
return;
}
return;
}
}
}
if (!"com.android.settings.HWSettings".equals(event.getClassName())) {
if (event.getPackageName().toString().contains("com.android.settings")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
} else {
gotoDefaultLauncherSetting();
sleep();
}
}
}
public void gotoBatteryOptimizeOnlyHUAWEI() {
Intent intent = new Intent();
ComponentName componentName = new ComponentName("com.android.settings", "com.android.settings.Settings$HighPowerApplicationsActivity");
intent.setComponent(componentName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getService().startActivity(intent);
}
}
package com.android.launcher3.auto_get_permission.huawei;
import android.accessibilityservice.AccessibilityService;
import android.content.ComponentName;
import android.content.Intent;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.util.Logger;
import com.android.launcher3.util.PermissionUtil;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BACK;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_HOME;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.*;
public class HuaweiAutoPermissionGetter extends BaseAutoGetPermission {
private static final String TAG = "HuaweiAutoPermissionGetter";
public HuaweiAutoPermissionGetter(PermissionOpenAccessiblityService service) {
super(service);
}
@Override
public void requestkDeviceAdmin(AccessibilityEvent event) {
}
@Override
public void requestBatteryOptimize(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity".equals(event.getClassName())) {
List<AccessibilityNodeInfo> listViewNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/lv_listview");
if (listViewNodeList != null && listViewNodeList.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodeList.get(0);
AccessibilityNodeInfo targetAppNode = getChildNodeByIdEqualText(listViewNode, "com.huawei.systemmanager:id/tv_title", appName);
long time = System.currentTimeMillis();
while (targetAppNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
targetAppNode = getChildNodeByIdEqualText(listViewNode, "com.huawei.systemmanager:id/tv_title", appName);
}
// 将自动管理的swicher关闭
if (targetAppNode.getParent() != null) {
List<AccessibilityNodeInfo> switcherNodes = targetAppNode.getParent().findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/switcher");
if (switcherNodes != null && switcherNodes.size() > 0) {
if (switcherNodes.get(0).isCheckable()) {
if (switcherNodes.get(0).isChecked()) {
targetAppNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
} else {
List<AccessibilityNodeInfo> manualBtnList = sourceNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/listitem_all_manual");
long time2 = System.currentTimeMillis();
while ((manualBtnList == null || manualBtnList.size() <= 0) && System.currentTimeMillis() - time2 < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
manualBtnList = sourceNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/listitem_all_manual");
}
if (manualBtnList.size() > 0 && manualBtnList.get(0).getParent() != null) {
manualBtnList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
}
}
}
}
}
}
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
List<AccessibilityNodeInfo> switcherNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/switcher");
if (switcherNodes != null && switcherNodes.size() > 0) {
for (AccessibilityNodeInfo switcherNode : switcherNodes) {
if (switcherNode.isCheckable() && !switcherNode.isChecked()) {
switcherNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
//
// performGlobalAction(GLOBAL_ACTION_BACK);
// sleep();
}
}
if ("com.huawei.systemmanager.appcontrol.activity.BatchManuControlActivity".equals(event.getClassName())) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo nodeInfo = getChildNodeByIdEqualText(listViewNode, "com.huawei.systemmanager:id/tv_title", appName);
long time = System.currentTimeMillis();
while (nodeInfo == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
nodeInfo = getChildNodeByIdEqualText(listViewNode, "com.huawei.systemmanager:id/tv_title", appName);
}
if (nodeInfo != null && nodeInfo.getParent() != null) {
AccessibilityNodeInfo linearNode = nodeInfo.getParent();
List<AccessibilityNodeInfo> checkBoxNodeList = linearNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/auto_checkbox");
if (checkBoxNodeList != null && checkBoxNodeList.size() > 0) {
if (!checkBoxNodeList.get(0).isChecked()) {
checkBoxNodeList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
List<AccessibilityNodeInfo> checkBoxNode2List = linearNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/associate_checkbox");
if (checkBoxNode2List != null && checkBoxNode2List.size() > 0) {
if (!checkBoxNode2List.get(0).isChecked()) {
checkBoxNode2List.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
List<AccessibilityNodeInfo> checkBoxNode3List = linearNode.findAccessibilityNodeInfosByViewId("com.huawei.systemmanager:id/background_checkbox");
if (checkBoxNode3List != null && checkBoxNode3List.size() > 0) {
if (!checkBoxNode3List.get(0).isChecked()) {
checkBoxNode3List.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
// PermissionUtil.isIgnoreBatteryOptimize = true;
// resetStep();
gotoBatteryOptimizeOnlyHUAWEI();
sleep();
}
}
}
long time2 = System.currentTimeMillis();
if ("com.android.settings.Settings$HighPowerApplicationsActivity".equals(event.getClassName())) {
boolean loadFinish = false;
do {
AccessibilityNodeInfo allAppNodeInfo = getChildNodeEqual(sourceNode, "所有应用");
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许");
if (allAppNodeInfo != null) {
loadFinish = true;
getChildNodeEqual(sourceNode, appName);
List<AccessibilityNodeInfo> listViewNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodeList != null && listViewNodeList.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodeList.get(0);
AccessibilityNodeInfo targetAppNode = getChildNodeEqual(listViewNode, appName);
long time = System.currentTimeMillis();
while (nodeInfo == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
targetAppNode = getChildNodeEqual(listViewNode, appName);
}
if (performAction(targetAppNode, AccessibilityNodeInfo.ACTION_CLICK)) {
Logger.e(TAG, "忽略电池\t" + targetAppNode.toString());
sleepShort();
} else {
showToastLong("请找到【" + appName + "】并点击");
return;
}
}
} else {
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
loadFinish = true;
nodeInfo.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
} else {
showToastLong("请点击【允许】");
return;
}
}
} while (!loadFinish && System.currentTimeMillis() - time2 < MAX_SEARCH_TIME);
}
if ("android.widget.FrameLayout".equals(event.getClassName())) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "所有应用");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepLongLong();
sourceNode.refresh();
operateAccessibilityEvent(event);
} else {
showToastLong("请点击【所有应用】");
return;
}
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
if (event.getText() != null && event.getText().toString().contains(appName)) {
AccessibilityNodeInfo acceptTvNode = getChildNodeEqual(sourceNode, "允许");
if (acceptTvNode != null && acceptTvNode.getParent() != null) {
acceptTvNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
AccessibilityNodeInfo deterBtnNode = getChildNodeEqual(sourceNode, "确定");
if (performAction(deterBtnNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
} else {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
}
}
}
@Override
public void requestUsageAppPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$UsageAccessSettingsActivity".equals(event.getClassName())) {
getChildNodeEqual(sourceNode, appName);
sleep();
List<AccessibilityNodeInfo> appListNodeList = null;
// getChildNodeEqual(sourceNode,appName);
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (appListNodeList == null || appListNodeList.isEmpty()) {
//
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/apps_list");
}
if (appListNodeList != null && appListNodeList.size() > 0) {
AccessibilityNodeInfo appListNode = appListNodeList.get(0);
AccessibilityNodeInfo targetAppItem = null;
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (appListNode.isScrollable()) {
appListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
appListNode.refresh();
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
} else {
break;
}
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】并点击");
return;
} else {
List<AccessibilityNodeInfo> switcherNodeList = targetAppItem.getParent().findAccessibilityNodeInfosByViewId("com.android.settings:id/app_switch");
if (switcherNodeList != null && !switcherNodeList.isEmpty() && performAction(switcherNodeList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
// resetStep();
}
}
}
} else if ("android.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo allowNode = getChildNodeEqual(sourceNode, "允许");
if (allowNode == null) {
allowNode = getChildNodeEqual(sourceNode, "确定");
}
if (performAction(allowNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
/**
* 使用记录访问权限(华为设备不同设备标题不同)
*/
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && (event.getText().toString().contains("使用情况访问权限") || event.getText().toString().contains("使用记录访问权限") || event.getText().toString().contains("使用量数据访问"))) {
if (SystemUtils.isSAMSUNG()) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许追踪使用情况");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【允许追踪使用情况】并返回上一页");
return;
}
} else if (SystemUtils.isNOKIA()) {
sleep();
List<AccessibilityNodeInfo> switchWidgetNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetNodeList != null && switchWidgetNodeList.size() > 0) {
if (switchWidgetNodeList.get(0).isChecked()) {
resetStep();
}
switchWidgetNodeList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
AccessibilityNodeInfo textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许访问使用记录");
if (textViewNode != null && textViewNode.getParent() != null) {
if (textViewNode.getParent().isClickable()) {
textViewNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许查看使用情况");
if (performAction(textViewNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【允许查看使用情况】并返回上一页");
return;
}
}
}
}
}
@Override
public void requestCloseUSB(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode=event.getSource();
if ("com.android.settings.Settings$DevelopmentSettingsActivity".equals(event.getClassName())) {
// oppo也是这个页面
getChildNodeEqual(sourceNode, "USB 调试");
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (listViewNodes == null || listViewNodes.isEmpty()) {
listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
}
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB调试");
if (usbNode == null) {
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
long time = System.currentTimeMillis();
while (usbNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB调试");
if (usbNode == null) {
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
}
if (usbNode != null && usbNode.getParent() != null) {
if (SystemUtils.isOPPO()) {
List<AccessibilityNodeInfo> switchWidgetList = usbNode.getParent().findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetList != null && !switchWidgetList.isEmpty()) {
switchWidgetList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
resetStep();
}
} else {
usbNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
// resetStep();
}
}
}
}
}
@Override
public void requestNotificationPermission(AccessibilityEvent event) {
}
@Override
public void requestDefaultLauncher(AccessibilityEvent event) {
AccessibilityNodeInfo nodeInfo=event.getSource();
if ("com.android.settings.HWSettings".equals(event.getClassName())) {
AccessibilityNodeInfo accessibilityNodeInfo = getChildNodeEqual(nodeInfo, "应用和通知");
if (performAction(accessibilityNodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
return;
} else {
showToastLong("请点击【应用和通知】");
return;
}
}
if ("com.android.settings.Settings$AppAndNotificationDashboardActivity".equals(event.getClassName())) {
AccessibilityNodeInfo defaultAppSetting = getChildNodeEqual(nodeInfo, "默认应用");
if (performAction(defaultAppSetting, AccessibilityNodeInfo.ACTION_CLICK)) {
return;
} else {
showToastLong("请点击【默认应用】");
return;
}
}
if ("com.android.settings.SubSettings".equals(event.getClassName()) && TextUtils.equals("[默认应用]", event.getText().toString())) {
// 默认应用
AccessibilityNodeInfo defaultLauncherSetting = getChildNodeEqual(nodeInfo, "桌面");
if (performAction(defaultLauncherSetting, AccessibilityNodeInfo.ACTION_CLICK)) {
return;
} else {
showToastLong("请点击【桌面】");
return;
}
}
if ("com.android.settings.Settings$PreferredSettingsActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetAppNode = getChildNodeEqual(nodeInfo, appName);
if (performAction(targetAppNode, AccessibilityNodeInfo.ACTION_CLICK)) {
} else {
showToastLong("请点击【" + appName + "】");
return;
}
return;
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
if (event.getText() != null) {
String text = event.getText().toString();
if (text.contains("更换默认桌面")) {
AccessibilityNodeInfo changeBtn = getChildNodeEqual(nodeInfo, "更换");
if (performAction(changeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【更换】");
return;
}
return;
}
}
}
if (!"com.android.settings.HWSettings".equals(event.getClassName())) {
if (event.getPackageName().toString().contains("com.android.settings")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
} else {
gotoDefaultLauncherSetting();
sleep();
}
}
}
public void gotoBatteryOptimizeOnlyHUAWEI() {
Intent intent = new Intent();
ComponentName componentName = new ComponentName("com.android.settings", "com.android.settings.Settings$HighPowerApplicationsActivity");
intent.setComponent(componentName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getService().startActivity(intent);
}
}
package com.android.launcher3.auto_get_permission.meizu;
import android.accessibilityservice.AccessibilityService;
import android.os.Build;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.util.Logger;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BACK;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.*;
public class MeizuAutoPermissionGetter extends BaseAutoGetPermission {
private static final String TAG = "MeizuAutoPermissionGetter";
public MeizuAutoPermissionGetter(PermissionOpenAccessiblityService service) {
super(service);
}
@Override
public void requestkDeviceAdmin(AccessibilityEvent event) {
}
@Override
public void requestBatteryOptimize(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
// 魅族 权限管理 ->后台管理-> 打开应用开关
if ("com.meizu.safe.SecurityMainActivity".equals(event.getClassName().toString())) {
// 手机管家页面
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, "权限管理");
if (accessibilityNodeInfo1 != null && accessibilityNodeInfo1.getParent() != null) {
Logger.e(TAG, accessibilityNodeInfo1.getParent().toString());
boolean success = performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK);
if (!success) {
sleep();
} else {
showToastLong("请点击【权限管理】");
return;
}
}
return;
}
if ("com.meizu.safe.permission.PermissionMainActivity".equals(event.getClassName().toString())) {
// 权限管理页面
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, "后台管理");
if (accessibilityNodeInfo1 != null && performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
} else {
showToastLong("请点击【后台管理】");
return;
}
return;
}
if ("com.meizu.safe.permission.SmartBGActivity".equals(event.getClassName().toString())) {
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeByIdEqualText(sourceNode, "com.meizu.safe:id/name", appName);
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.meizu.safe:id/list");
if (nodeInfoList != null && nodeInfoList.size() > 0) {
AccessibilityNodeInfo listViewNode = nodeInfoList.get(0);
long time = System.currentTimeMillis();
while (accessibilityNodeInfo1 == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode == null) {
break;
}
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
accessibilityNodeInfo1 = getChildNodeByIdEqualText(sourceNode, "com.meizu.safe:id/name", appName);
}
}
if (accessibilityNodeInfo1 != null && performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
} else {
showToastLong("请找到【" + appName + "】应用并点击");
return;
}
}
if ("android.app.AlertDialog".equals(event.getClassName().toString())) {
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, "允许后台运行");
if (accessibilityNodeInfo1 != null && performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【允许后台运行】");
return;
}
}
}
@Override
public void requestUsageAppPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$UsageAccessSettingsActivity".equals(event.getClassName())) {
getChildNodeEqual(sourceNode, appName);
sleep();
List<AccessibilityNodeInfo> appListNodeList = null;
// getChildNodeEqual(sourceNode,appName);
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (appListNodeList == null || appListNodeList.isEmpty()) {
//
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/apps_list");
}
if (appListNodeList != null && appListNodeList.size() > 0) {
AccessibilityNodeInfo appListNode = appListNodeList.get(0);
AccessibilityNodeInfo targetAppItem = null;
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (appListNode.isScrollable()) {
appListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
appListNode.refresh();
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
} else {
break;
}
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】并点击");
return;
} else {
List<AccessibilityNodeInfo> switcherNodeList = targetAppItem.getParent().findAccessibilityNodeInfosByViewId("com.android.settings:id/app_switch");
if (switcherNodeList != null && !switcherNodeList.isEmpty() && performAction(switcherNodeList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
// resetStep();
}
}
}
} else if ("android.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo allowNode = getChildNodeEqual(sourceNode, "允许");
if (allowNode == null) {
allowNode = getChildNodeEqual(sourceNode, "确定");
}
if (performAction(allowNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
/**
* 使用记录访问权限(华为设备不同设备标题不同)
*/
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && (event.getText().toString().contains("使用情况访问权限") || event.getText().toString().contains("使用记录访问权限") || event.getText().toString().contains("使用量数据访问"))) {
if (SystemUtils.isSAMSUNG()) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许追踪使用情况");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【允许追踪使用情况】并返回上一页");
return;
}
} else if (SystemUtils.isNOKIA()) {
sleep();
List<AccessibilityNodeInfo> switchWidgetNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetNodeList != null && switchWidgetNodeList.size() > 0) {
if (switchWidgetNodeList.get(0).isChecked()) {
resetStep();
}
switchWidgetNodeList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
AccessibilityNodeInfo textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许访问使用记录");
if (textViewNode != null && textViewNode.getParent() != null) {
if (textViewNode.getParent().isClickable()) {
textViewNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许查看使用情况");
if (performAction(textViewNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【允许查看使用情况】并返回上一页");
return;
}
}
}
}
}
@Override
public void requestCloseUSB(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$DevelopmentSettingsActivity".equals(event.getClassName()) && event.getText() != null && event.getText().toString().contains("开发者选项")) {
AccessibilityNodeInfo usbNode = getChildNodeEqual(sourceNode, "USB 调试");
if (performAction(usbNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【USB 调试】");
return;
}
}
}
@Override
public void requestNotificationPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode=event.getSource();
if ("com.android.settings.Settings$NotificationAccessSettingsActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetApp = getChildNodeEqual(sourceNode, appName);
if (!performAction(targetApp, AccessibilityNodeInfo.ACTION_CLICK)) {
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (nodeInfoList != null && nodeInfoList.size() > 0) {
AccessibilityNodeInfo listViewNode = nodeInfoList.get(0);
AccessibilityNodeInfo targetAppItem = getChildNodeByIdEqualText(listViewNode, "android:id/title", appName);
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
}
}
targetAppItem = getChildNodeByIdEqualText(listViewNode, "android:id/title", appName);
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请点击【" + appName + "】");
return;
}
} else {
showToastLong("请点击【" + appName + "】");
}
}
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
// 允许
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/button1");
if (nodeInfoList != null && nodeInfoList.size() > 0 && performAction(nodeInfoList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
return;
} else {
showToastLong("请点击【允许】");
return;
}
}
}
@Override
public void requestDefaultLauncher(AccessibilityEvent event) {
AccessibilityNodeInfo nodeInfo=event.getSource();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
if ("com.android.internal.app.MzResolverActivity".equals(event.getClassName())) {
AccessibilityNodeInfo checkBoxNode = getChildNodeEqual(nodeInfo, "默认使用该应用打开");
if (performAction(checkBoxNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【默认使用该应用打开】");
return;
}
AccessibilityNodeInfo targetAppNode = getChildNodeEqual(nodeInfo, appName);
if (performAction(targetAppNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【" + appName + "】");
return;
}
}
} else {
if ("com.android.settings.Settings".equals(event.getClassName().toString())) {
// 设置页面
List<AccessibilityNodeInfo> recycleListNodes = nodeInfo.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (recycleListNodes != null && !recycleListNodes.isEmpty()) {
AccessibilityNodeInfo recyclerListNode = recycleListNodes.get(0);
AccessibilityNodeInfo appManageNode = getChildNodeEqual(recyclerListNode, "应用管理");
long time = System.currentTimeMillis();
while (appManageNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (recyclerListNode.isScrollable()) {
recyclerListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
recyclerListNode.refresh();
} else {
break;
}
appManageNode = getChildNodeEqual(recyclerListNode, "应用管理");
}
if (performAction(appManageNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
return;
} else {
showToastLong("请点击【应用管理】");
return;
}
}
} else if ("com.android.settings.Settings$ManageApplicationsActivity".equals(event.getClassName().toString())) {
AccessibilityNodeInfo defaultLauncherNode = getChildNodeEqual(nodeInfo, "默认应用");
if (performAction(defaultLauncherNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
return;
} else {
showToastLong("请点击【默认应用】");
return;
}
} else if ("com.android.settings.SubSettings".equals(event.getClassName().toString())) {
if (event.getText() != null && !TextUtils.isEmpty(event.getText().toString())) {
if ("[默认应用]".equals(event.getText().toString())) {
AccessibilityNodeInfo launcherNode = getChildNodeEqual(nodeInfo, "桌面");
if (performAction(launcherNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
return;
} else {
showToastLong("请点击【桌面】");
return;
}
} else if ("[桌面]".equals(event.getText().toString())) {
AccessibilityNodeInfo targetNode = getChildNodeEqual(nodeInfo, appName);
if (performAction(targetNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
return;
} else {
showToastLong("请点击【" + appName + "】");
return;
}
}
}
}
if (event.getPackageName() != null && event.getPackageName().equals("com.android.settings")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
// gotoDeviceAdminPermissionSetting();
return;
}
gotoSystemSettings();
sleep();
}
}
}
package com.android.launcher3.auto_get_permission.nokia;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.util.Logger;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.*;
public class NokiaAutoPermissionGetter extends BaseAutoGetPermission {
private static final String TAG="NokiaAutoPermissionGetter";
public NokiaAutoPermissionGetter(PermissionOpenAccessiblityService service) {
super(service);
}
@Override
public void requestkDeviceAdmin(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$DeviceAdminSettingsActivity".equals(event.getClassName().toString())) {
// 已跳转到设备管理器页面
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, appName);
if (!performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】应用并点击");
return;
} else {
sleep();
}
} else if ("com.android.settings.DeviceAdminAdd".equals(event.getClassName().toString())) {
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, "启用此设备管理应用");
if (accessibilityNodeInfo1 != null && performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【启用/激活此设备管理员】");
return;
}
}
}
@Override
public void requestBatteryOptimize(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode=event.getSource();
if ("com.evenwell.powersaving.g3.exception.PowerSaverExceptionActivity".equals(event.getClassName().toString())) {
Logger.e(TAG, "enter PowerSaverExceptionActivity");
// sleep();
sleepLong();
getChildNodeEqual(sourceNode, appName);
List<AccessibilityNodeInfo> appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.evenwell.powersaving.g3:id/applist");
if (appListNodeList != null && appListNodeList.size() > 0) {
AccessibilityNodeInfo appListNode = appListNodeList.get(0);
AccessibilityNodeInfo targetAppNode = getChildNodeByIdEqualText(appListNode, "com.evenwell.powersaving.g3:id/appName", appName);
long time = System.currentTimeMillis();
while (targetAppNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (appListNode.isScrollable()) {
appListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
appListNode.refresh();
} else {
break;
}
targetAppNode = getChildNodeByIdEqualText(appListNode, "com.evenwell.powersaving.g3:id/appName", appName);
}
if (targetAppNode.getParent() != null) {
AccessibilityNodeInfo linearLayoutNode = targetAppNode.getParent();
List<AccessibilityNodeInfo> checkBoxNodeInfoList = linearLayoutNode.findAccessibilityNodeInfosByViewId("com.evenwell.powersaving.g3:id/appCheckBoxhWidgetDisAuto");
if (checkBoxNodeInfoList != null && checkBoxNodeInfoList.size() > 0) {
checkBoxNodeInfoList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
List<AccessibilityNodeInfo> appCheckBoxhWidgetBAMNodeInfoList = linearLayoutNode.findAccessibilityNodeInfosByViewId("com.evenwell.powersaving.g3:id/appCheckBoxhWidgetBAM");
if (appCheckBoxhWidgetBAMNodeInfoList != null && appCheckBoxhWidgetBAMNodeInfoList.size() > 0) {
appCheckBoxhWidgetBAMNodeInfoList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
}
return;
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
List<AccessibilityNodeInfo> deterBtnNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/button1");
if (deterBtnNodeList != null && deterBtnNodeList.size() > 0) {
deterBtnNodeList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
return;
}
}
@Override
public void requestUsageAppPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$UsageAccessSettingsActivity".equals(event.getClassName())) {
getChildNodeEqual(sourceNode, appName);
sleep();
List<AccessibilityNodeInfo> appListNodeList = null;
// getChildNodeEqual(sourceNode,appName);
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (appListNodeList == null || appListNodeList.isEmpty()) {
//
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/apps_list");
}
if (appListNodeList != null && appListNodeList.size() > 0) {
AccessibilityNodeInfo appListNode = appListNodeList.get(0);
AccessibilityNodeInfo targetAppItem = null;
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (appListNode.isScrollable()) {
appListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
appListNode.refresh();
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
} else {
break;
}
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】并点击");
return;
} else {
List<AccessibilityNodeInfo> switcherNodeList = targetAppItem.getParent().findAccessibilityNodeInfosByViewId("com.android.settings:id/app_switch");
if (switcherNodeList != null && !switcherNodeList.isEmpty() && performAction(switcherNodeList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
// resetStep();
}
}
}
} else if ("android.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo allowNode = getChildNodeEqual(sourceNode, "允许");
if (allowNode == null) {
allowNode = getChildNodeEqual(sourceNode, "确定");
}
if (performAction(allowNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
/**
* 使用记录访问权限(华为设备不同设备标题不同)
*/
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && (event.getText().toString().contains("使用情况访问权限") || event.getText().toString().contains("使用记录访问权限") || event.getText().toString().contains("使用量数据访问"))) {
if (SystemUtils.isSAMSUNG()) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许追踪使用情况");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【允许追踪使用情况】并返回上一页");
return;
}
} else if (SystemUtils.isNOKIA()) {
sleep();
List<AccessibilityNodeInfo> switchWidgetNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetNodeList != null && switchWidgetNodeList.size() > 0) {
if (switchWidgetNodeList.get(0).isChecked()) {
resetStep();
}
switchWidgetNodeList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
AccessibilityNodeInfo textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许访问使用记录");
if (textViewNode != null && textViewNode.getParent() != null) {
if (textViewNode.getParent().isClickable()) {
textViewNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许查看使用情况");
if (performAction(textViewNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【允许查看使用情况】并返回上一页");
return;
}
}
}
}
}
@Override
public void requestCloseUSB(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings".equals(event.getClassName())) {
List<AccessibilityNodeInfo> recyclerViewListNode = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/dashboard_container");
if (recyclerViewListNode != null && recyclerViewListNode.size() > 0) {
AccessibilityNodeInfo recyclerViewNode = recyclerViewListNode.get(0);
AccessibilityNodeInfo developerChoiceNode = getChildNodeByIdEqualText(recyclerViewNode, "android:id/title", "开发者选项");
long time = System.currentTimeMillis();
while (developerChoiceNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (recyclerViewNode.isScrollable()) {
recyclerViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
recyclerViewNode.refresh();
} else {
break;
}
developerChoiceNode = getChildNodeByIdEqualText(recyclerViewNode, "android:id/title", "开发者选项");
}
if (performAction(developerChoiceNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
} else {
showToastLong("请点击【开发者选项】");
return;
}
}
}
// 三星不同版本之前的开发者选项的界面不一样 所以需要两种判断
if ("com.android.settings.Settings$DevelopmentSettingsDashboardActivity".equals(event.getClassName())) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
long time = System.currentTimeMillis();
while (usbNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
if (performAction(usbNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【USB 调试】");
return;
}
}
}
if ("com.android.settings.Settings$DevelopmentSettingsActivity".equals(event.getClassName())) {
AccessibilityNodeInfo usbNode = getChildNodeEqual(sourceNode, "USB调试");
if (!performAction(usbNode, AccessibilityNodeInfo.ACTION_CLICK)) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
usbNode = getChildNodeEqual(listViewNode, "USB调试");
long time = System.currentTimeMillis();
while (usbNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
usbNode = getChildNodeEqual(listViewNode, "USB调试");
}
if (performAction(usbNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【USB 调试】");
return;
}
}
}
}
}
@Override
public void requestNotificationPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode=event.getSource();
if ("com.android.settings.Settings$NotificationAccessSettingsActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetApp = getChildNodeEqual(sourceNode, appName);
if (!performAction(targetApp, AccessibilityNodeInfo.ACTION_CLICK)) {
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (nodeInfoList != null && nodeInfoList.size() > 0) {
AccessibilityNodeInfo listViewNode = nodeInfoList.get(0);
AccessibilityNodeInfo targetAppItem = getChildNodeByIdEqualText(listViewNode, "android:id/title", appName);
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
}
}
targetAppItem = getChildNodeByIdEqualText(listViewNode, "android:id/title", appName);
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请点击【" + appName + "】");
return;
}
} else {
showToastLong("请点击【" + appName + "】");
}
}
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
// 允许
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/button1");
if (nodeInfoList != null && nodeInfoList.size() > 0 && performAction(nodeInfoList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
return;
} else {
showToastLong("请点击【允许】");
return;
}
}
}
@Override
public void requestDefaultLauncher(AccessibilityEvent event) {
AccessibilityNodeInfo nodeInfo=event.getSource();
if ("com.android.internal.app.ResolverActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetAppNode = getChildNodeEqual(nodeInfo, appName);
if (targetAppNode != null && targetAppNode.getParent() != null) {
targetAppNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
}
List<AccessibilityNodeInfo> alwaysBtnList = nodeInfo.findAccessibilityNodeInfosByViewId("android:id/button_always");
if (alwaysBtnList != null && alwaysBtnList.size() > 0) {
alwaysBtnList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
// AccessibilityNodeInfo alwaysBtn = getChildNodeByIdEqualText(nodeInfo, "android:id/button_always");
}
}
}
package com.android.launcher3.auto_get_permission.oppo;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.util.Logger;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BACK;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.*;
public class OppoAutoPermissionGetter extends BaseAutoGetPermission {
public static final String TAG = "OppoAutoPermissionGetter";
public OppoAutoPermissionGetter(PermissionOpenAccessiblityService service) {
super(service);
}
@Override
public void requestkDeviceAdmin(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
Logger.e(TAG, "isOPPO" + event.getClassName());
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && event.getText().toString().equals("[设备管理器]")) {
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, appName);
if (accessibilityNodeInfo1 != null && accessibilityNodeInfo1.getParent() != null) {
accessibilityNodeInfo1.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
}
} else if ("com.android.settings.DeviceAdminAdd".equals(event.getClassName().toString()) || "com.coloros.settings.feature.security.ColorDeviceAdminAdd".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/restricted_action");
if (nodeInfoList != null && nodeInfoList.size() > 0) {
nodeInfoList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
resetStep();
}
} else if ("com.android.settings.Settings$DeviceAdminSettingsActivity".equals(event.getClassName().toString())) {
// 已跳转到设备管理器页面
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, appName);
if (accessibilityNodeInfo1 != null && accessibilityNodeInfo1.getParent() != null) {
if (SystemUtils.isSAMSUNG()) {
accessibilityNodeInfo1.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
Logger.e(TAG, "performAction ACTION_CLICK");
}
if (SystemUtils.isHONOR()) {
accessibilityNodeInfo1.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
Logger.e(TAG, "performAction ACTION_CLICK");
} else {
accessibilityNodeInfo1.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
sleep();
}
}
if (event.getPackageName() != null && event.getPackageName().equals("com.android.settings")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
// gotoDeviceAdminPermissionSetting();
return;
}
if (event.getPackageName() == null) {
gotoDeviceAdminPermissionSetting();
sleep();
}
//
}
@Override
public void requestBatteryOptimize(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.applications.InstalledAppDetailsTop".equals(event.getClassName())) {
boolean isTargetApp = getChildNodeEqual(sourceNode, appName) != null;
if (isTargetApp) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listView = listViewNodes.get(0);
AccessibilityNodeInfo allowAutoStart = getChildNodeEqual(listView, "允许自动启动");
if (allowAutoStart != null && allowAutoStart.getParent() != null) {
List<AccessibilityNodeInfo> listNode = allowAutoStart.getParent().findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (listNode != null && listNode.size() > 0) {
listNode.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
AccessibilityNodeInfo allowOtherAppAutoStart = getChildNodeEqual(listView, "允许其他应用自动启动");
if (allowOtherAppAutoStart != null && allowOtherAppAutoStart.getParent() != null) {
List<AccessibilityNodeInfo> listNode = allowOtherAppAutoStart.getParent().findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (listNode != null && listNode.size() > 0) {
listNode.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
}
}
// getChildNodeEqual(sourceNode, "允许其他应用自动启动");
AccessibilityNodeInfo batterySaveNode = getChildNodeEqual(sourceNode, "耗电保护");
if (batterySaveNode != null && batterySaveNode.getParent() != null) {
batterySaveNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
}
}
} else if ("com.coloros.powermanager.fuelgaue.PowerAppsBgSetting".equals(event.getClassName())) {
boolean isTargetApp = getChildNodeEqual(sourceNode, appName) != null;
if (isTargetApp) {
AccessibilityNodeInfo node = getChildNodeEqual(sourceNode, "允许后台运行");
if (node != null && node.getParent() != null) {
node.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
resetStep();
}
}
}
}
@Override
public void requestUsageAppPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$UsageAccessSettingsActivity".equals(event.getClassName())) {
getChildNodeEqual(sourceNode, appName);
sleep();
List<AccessibilityNodeInfo> appListNodeList = null;
// getChildNodeEqual(sourceNode,appName);
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (appListNodeList == null || appListNodeList.isEmpty()) {
//
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/apps_list");
}
if (appListNodeList != null && appListNodeList.size() > 0) {
AccessibilityNodeInfo appListNode = appListNodeList.get(0);
AccessibilityNodeInfo targetAppItem = null;
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (appListNode.isScrollable()) {
appListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
appListNode.refresh();
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
} else {
break;
}
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】并点击");
return;
} else {
List<AccessibilityNodeInfo> switcherNodeList = targetAppItem.getParent().findAccessibilityNodeInfosByViewId("com.android.settings:id/app_switch");
if (switcherNodeList != null && !switcherNodeList.isEmpty() && performAction(switcherNodeList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
// resetStep();
}
}
}
} else if ("android.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo allowNode = getChildNodeEqual(sourceNode, "允许");
if (allowNode == null) {
allowNode = getChildNodeEqual(sourceNode, "确定");
}
if (performAction(allowNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
/**
* 使用记录访问权限(华为设备不同设备标题不同)
*/
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && (event.getText().toString().contains("使用情况访问权限") || event.getText().toString().contains("使用记录访问权限") || event.getText().toString().contains("使用量数据访问"))) {
if (SystemUtils.isSAMSUNG()) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许追踪使用情况");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【允许追踪使用情况】并返回上一页");
return;
}
} else if (SystemUtils.isNOKIA()) {
sleep();
List<AccessibilityNodeInfo> switchWidgetNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetNodeList != null && switchWidgetNodeList.size() > 0) {
if (switchWidgetNodeList.get(0).isChecked()) {
resetStep();
}
switchWidgetNodeList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
AccessibilityNodeInfo textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许访问使用记录");
if (textViewNode != null && textViewNode.getParent() != null) {
if (textViewNode.getParent().isClickable()) {
textViewNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许查看使用情况");
if (performAction(textViewNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【允许查看使用情况】并返回上一页");
return;
}
}
}
}
}
@Override
public void requestCloseUSB(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$DevelopmentSettingsActivity".equals(event.getClassName())) {
// oppo也是这个页面
getChildNodeEqual(sourceNode, "USB 调试");
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (listViewNodes == null || listViewNodes.isEmpty()) {
listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
}
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB调试");
if (usbNode == null) {
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
long time = System.currentTimeMillis();
while (usbNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB调试");
if (usbNode == null) {
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
}
if (usbNode != null && usbNode.getParent() != null) {
if (SystemUtils.isOPPO()) {
List<AccessibilityNodeInfo> switchWidgetList = usbNode.getParent().findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetList != null && !switchWidgetList.isEmpty()) {
switchWidgetList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
resetStep();
}
} else {
usbNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
// resetStep();
}
}
}
}
}
@Override
public void requestNotificationPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.coloros.securitypermission.permission.PermissionNotificationActivity".equals(event.getClassName())) {
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (nodeInfoList == null || nodeInfoList.isEmpty()) {
nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.coloros.securitypermission:id/list_view");
}
if (nodeInfoList != null && nodeInfoList.size() > 0) {
AccessibilityNodeInfo listViewNode = nodeInfoList.get(0);
getChildNodeEqual(listViewNode, appName);
AccessibilityNodeInfo targetAppItem = getChildNodeByIdEqualText(listViewNode, "com.coloros.securitypermission:id/name", appName);
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
}
}
targetAppItem = getChildNodeByIdEqualText(listViewNode, "com.coloros.securitypermission:id/name", appName);
}
if (performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【" + appName + "】");
return;
}
}
} else if ("com.coloros.securitypermission.common.l.a".equals(event.getClassName())) {
AccessibilityNodeInfo allowNode = getChildNodeEqual(sourceNode, "允许");
if (performAction(allowNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【允许】");
return;
}
}
}
@Override
public void requestDefaultLauncher(AccessibilityEvent event) {
AccessibilityNodeInfo nodeInfo = event.getSource();
if ("android.app.Dialog".equals(event.getClassName()) || "com.android.internal.app.ResolverActivity".equals(event.getClassName())) {
AccessibilityNodeInfo neverRemindNode = getChildNodeEqual(nodeInfo, "不再提醒");
if (neverRemindNode != null && neverRemindNode.performAction(AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
} else {
if (neverRemindNode.getParent() != null) {
if (neverRemindNode.getParent().isClickable()) {
neverRemindNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
}
}
}
List<AccessibilityNodeInfo> pagerNodeList = nodeInfo.findAccessibilityNodeInfosByViewId("oppo:id/oppo_pager");
if (pagerNodeList == null || pagerNodeList.isEmpty()) {
pagerNodeList = nodeInfo.findAccessibilityNodeInfosByViewId("oppo:id/resolver_scroll_panel");
}
if (pagerNodeList != null && !pagerNodeList.isEmpty()) {
AccessibilityNodeInfo pageNode = pagerNodeList.get(0);
AccessibilityNodeInfo targetAppNode = getChildNodeEqualByContentDesc(pageNode, appName);
if (targetAppNode == null) {
targetAppNode = getChildNodeEqual(pageNode, appName);
}
if (targetAppNode != null && targetAppNode.isClickable()) {
targetAppNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepLong();
resetStep();
} else {
if (targetAppNode.getParent() != null) {
targetAppNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepLong();
resetStep();
}
}
}
}
}
}
package com.android.launcher3.auto_get_permission.samsung;
import android.accessibilityservice.AccessibilityService;
import android.os.Build;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BACK;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_HOME;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.getChildNodeByIdEqualText;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.getChildNodeEqual;
public class SamsungAutoPermissionGetter extends BaseAutoGetPermission {
public SamsungAutoPermissionGetter(PermissionOpenAccessiblityService service) {
super(service);
}
@Override
public void requestkDeviceAdmin(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$DeviceAdminSettingsActivity".equals(event.getClassName().toString())) {
// 已跳转到设备管理器页面
AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, appName);
if (!performAction(accessibilityNodeInfo1, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】应用并点击");
return;
} else {
sleepShort();
}
return;
} else if ("com.android.settings.DeviceAdminAdd".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/restricted_action");
if (nodeInfoList != null && nodeInfoList.size() > 0 && nodeInfoList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
return;
} else {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "启动");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
return;
}
showToastLong("请点击【启用/激活此设备管理员】");
return;
}
}
if (event.getPackageName() != null && event.getPackageName().equals("com.android.settings")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
// gotoDeviceAdminPermissionSetting();
return;
}
if (event.getPackageName() == null) {
gotoDeviceAdminPermissionSetting();
sleep();
}
//
}
@Override
public void requestBatteryOptimize(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
// 三星 自动运行应用程序 -> 打开应用开关 -> 电池管理 -> 未监视的应用程序 -> 添加应用
// if ("com.samsung.android.sm.score.ui.ScoreBoardActivity".equals(event.getClassName().toString())) {
// AccessibilityNodeInfo sourceNode = event.getSource();
// AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, "自动运行应用程序");
// if (accessibilityNodeInfo1 != null && accessibilityNodeInfo1.getParent() != null) {
// accessibilityNodeInfo1.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
// sleep();
// }
//
// }
//
// if ("com.samsung.android.sm.autorun.ui.AutoRunActivity".equals(event.getClassName().toString())) {
//
// AccessibilityNodeInfo sourceNode = event.getSource();
//
// getChildNodeEqual(sourceNode, appName);
// AccessibilityNodeInfo frameLayoutNode = sourceNode.findAccessibilityNodeInfosByViewId("com.samsung.android.sm_cn:id/active_applications_detail").get(0).getParent().getParent();
//
//
//// frameLayoutNode.getCollectionInfo()'
//
//// for ()
////
// Logger.e(TAG, sourceNode.findAccessibilityNodeInfosByViewId("com.samsung.android.sm_cn:id/app_name").size() + "");
////
//// Logger.e(TAG, "\t" + sourceNode.findAccessibilityNodeInfosByViewId("com.samsung.android.sm_cn:id/active_applications_detail").get(0).getParent().getChildCount());
//
//// AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeEqual(sourceNode, appName);
// AccessibilityNodeInfo accessibilityNodeInfo1 = getChildNodeByIdEqualText(sourceNode, "com.samsung.android.sm_cn:id/app_name", appName);
//
//
// accessibilityNodeInfo1.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
// sleep();
// }
}
@Override
public void requestUsageAppPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$UsageAccessSettingsActivity".equals(event.getClassName())) {
getChildNodeEqual(sourceNode, appName);
sleep();
List<AccessibilityNodeInfo> appListNodeList = null;
// getChildNodeEqual(sourceNode,appName);
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (appListNodeList == null || appListNodeList.isEmpty()) {
//
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/apps_list");
}
if (appListNodeList != null && appListNodeList.size() > 0) {
AccessibilityNodeInfo appListNode = appListNodeList.get(0);
AccessibilityNodeInfo targetAppItem = null;
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (appListNode.isScrollable()) {
appListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
appListNode.refresh();
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
} else {
break;
}
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】并点击");
return;
} else {
List<AccessibilityNodeInfo> switcherNodeList = targetAppItem.getParent().findAccessibilityNodeInfosByViewId("com.android.settings:id/app_switch");
if (switcherNodeList != null && !switcherNodeList.isEmpty() && performAction(switcherNodeList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
// resetStep();
}
}
}
} else if ("android.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo allowNode = getChildNodeEqual(sourceNode, "允许");
if (allowNode == null) {
allowNode = getChildNodeEqual(sourceNode, "确定");
}
if (performAction(allowNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
/**
* 使用记录访问权限(华为设备不同设备标题不同)
*/
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && (event.getText().toString().contains("使用情况访问权限") || event.getText().toString().contains("使用记录访问权限") || event.getText().toString().contains("使用量数据访问"))) {
if (SystemUtils.isSAMSUNG()) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许追踪使用情况");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【允许追踪使用情况】并返回上一页");
return;
}
} else if (SystemUtils.isNOKIA()) {
sleep();
List<AccessibilityNodeInfo> switchWidgetNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetNodeList != null && switchWidgetNodeList.size() > 0) {
if (switchWidgetNodeList.get(0).isChecked()) {
resetStep();
}
switchWidgetNodeList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
AccessibilityNodeInfo textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许访问使用记录");
if (textViewNode != null && textViewNode.getParent() != null) {
if (textViewNode.getParent().isClickable()) {
textViewNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许查看使用情况");
if (performAction(textViewNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【允许查看使用情况】并返回上一页");
return;
}
}
}
}
}
@Override
public void requestCloseUSB(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings".equals(event.getClassName())) {
List<AccessibilityNodeInfo> recyclerViewListNode = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/dashboard_container");
if (recyclerViewListNode != null && recyclerViewListNode.size() > 0) {
AccessibilityNodeInfo recyclerViewNode = recyclerViewListNode.get(0);
AccessibilityNodeInfo developerChoiceNode = getChildNodeByIdEqualText(recyclerViewNode, "android:id/title", "开发者选项");
long time = System.currentTimeMillis();
while (developerChoiceNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (recyclerViewNode.isScrollable()) {
recyclerViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
recyclerViewNode.refresh();
} else {
break;
}
developerChoiceNode = getChildNodeByIdEqualText(recyclerViewNode, "android:id/title", "开发者选项");
}
if (performAction(developerChoiceNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
} else {
showToastLong("请点击【开发者选项】");
return;
}
}
}
// 三星不同版本之前的开发者选项的界面不一样 所以需要两种判断
if ("com.android.settings.Settings$DevelopmentSettingsDashboardActivity".equals(event.getClassName())) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
long time = System.currentTimeMillis();
while (usbNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
usbNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "USB 调试");
}
if (performAction(usbNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【USB 调试】");
return;
}
}
}
if ("com.android.settings.Settings$DevelopmentSettingsActivity".equals(event.getClassName())) {
AccessibilityNodeInfo usbNode = getChildNodeEqual(sourceNode, "USB调试");
if (!performAction(usbNode, AccessibilityNodeInfo.ACTION_CLICK)) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
usbNode = getChildNodeEqual(listViewNode, "USB调试");
long time = System.currentTimeMillis();
while (usbNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
usbNode = getChildNodeEqual(listViewNode, "USB调试");
}
if (performAction(usbNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【USB 调试】");
return;
}
}
}
}
}
@Override
public void requestNotificationPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode=event.getSource();
if ("com.android.settings.Settings$NotificationAccessSettingsActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetApp = getChildNodeEqual(sourceNode, appName);
if (!performAction(targetApp, AccessibilityNodeInfo.ACTION_CLICK)) {
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (nodeInfoList != null && nodeInfoList.size() > 0) {
AccessibilityNodeInfo listViewNode = nodeInfoList.get(0);
AccessibilityNodeInfo targetAppItem = getChildNodeByIdEqualText(listViewNode, "android:id/title", appName);
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
}
}
targetAppItem = getChildNodeByIdEqualText(listViewNode, "android:id/title", appName);
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请点击【" + appName + "】");
return;
}
} else {
showToastLong("请点击【" + appName + "】");
}
}
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
// 允许
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/button1");
if (nodeInfoList != null && nodeInfoList.size() > 0 && performAction(nodeInfoList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
return;
} else {
showToastLong("请点击【允许】");
return;
}
}
}
@Override
public void requestDefaultLauncher(AccessibilityEvent event) {
AccessibilityNodeInfo nodeInfo=event.getSource();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
if ("com.android.settings.applications.InstalledAppDetailsTop".equals(event.getClassName())) {
boolean isTargetApp = getChildNodeEqual(nodeInfo, appName) != null;
if (isTargetApp) {
List<AccessibilityNodeInfo> listViewNodes = nodeInfo.findAccessibilityNodeInfosByViewId("com.android.settings:id/list");
if (listViewNodes != null && !listViewNodes.isEmpty()) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo defaultLauncherNode = getChildNodeEqual(listViewNode, "主屏幕");
long time = System.currentTimeMillis();
while (defaultLauncherNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
listViewNode.refresh();
sleepShort();
} else {
break;
}
defaultLauncherNode = getChildNodeEqual(listViewNode, "主屏幕");
}
if (performAction(defaultLauncherNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【主屏幕】");
return;
}
} else {
showToastLong("请点击【主屏幕】");
}
return;
}
}
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && event.getText().toString().equals("[主屏幕]")) {
AccessibilityNodeInfo accessibilityNodeInfo = getChildNodeEqual(nodeInfo, appName);
if (performAction(accessibilityNodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
getService().performGlobalAction(GLOBAL_ACTION_HOME);
} else {
showToastLong("请点击【" + appName + "】");
return;
}
return;
}
if ("android.app.Dialog".equals(event.getClassName()) && event.getText() != null && event.getText().toString().contains("选择您要使用的主屏幕")) {
AccessibilityNodeInfo accessibilityNodeInfo = getChildNodeEqual(nodeInfo, appName);
if (performAction(accessibilityNodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
getService().performGlobalAction(GLOBAL_ACTION_HOME);
} else {
showToastLong("请点击【" + appName + "】");
return;
}
return;
}
if (event.getPackageName() != null && event.getPackageName().equals("com.android.settings")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
// gotoDeviceAdminPermissionSetting();
return;
}
gotoDefaultLauncherSetting();
sleep();
} else {
if ("com.android.internal.app.ResolverActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetAppNode = getChildNodeEqual(nodeInfo, appName);
if (targetAppNode != null && targetAppNode.getParent() != null) {
targetAppNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
}
List<AccessibilityNodeInfo> alwaysBtnList = nodeInfo.findAccessibilityNodeInfosByViewId("android:id/button_always");
if (alwaysBtnList != null && alwaysBtnList.size() > 0 && performAction(alwaysBtnList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
} else {
showToastLong("请选择默认使用桌面为" + appName);
return;
}
// AccessibilityNodeInfo alwaysBtn = getChildNodeByIdEqualText(nodeInfo, "android:id/button_always");
}
}
}
}
package com.android.launcher3.auto_get_permission.vivo;
import android.accessibilityservice.AccessibilityService;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.util.PermissionUtil;
import com.android.launcher3.util.SystemUtils;
import java.util.List;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BACK;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.getChildNodeByIdEqualText;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.getChildNodeEqual;
public class VivoAutoPermissionGetter extends BaseAutoGetPermission {
public VivoAutoPermissionGetter(PermissionOpenAccessiblityService service) {
super(service);
}
@Override
public void requestkDeviceAdmin(AccessibilityEvent event) {
}
@Override
public void requestBatteryOptimize(AccessibilityEvent event) {
}
@Override
public void requestUsageAppPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$UsageAccessSettingsActivity".equals(event.getClassName())) {
getChildNodeEqual(sourceNode, appName);
sleep();
List<AccessibilityNodeInfo> appListNodeList = null;
// getChildNodeEqual(sourceNode,appName);
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (appListNodeList == null || appListNodeList.isEmpty()) {
//
appListNodeList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/apps_list");
}
if (appListNodeList != null && appListNodeList.size() > 0) {
AccessibilityNodeInfo appListNode = appListNodeList.get(0);
AccessibilityNodeInfo targetAppItem = null;
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
long time = System.currentTimeMillis();
while (targetAppItem == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (appListNode.isScrollable()) {
appListNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
appListNode.refresh();
targetAppItem = getChildNodeByIdEqualText(appListNode, "com.android.settings:id/app_name", appName);
if (targetAppItem == null) {
targetAppItem = getChildNodeByIdEqualText(appListNode, "android:id/title", appName);
}
} else {
break;
}
}
if (!performAction(targetAppItem, AccessibilityNodeInfo.ACTION_CLICK)) {
showToastLong("请找到【" + appName + "】并点击");
return;
} else {
List<AccessibilityNodeInfo> switcherNodeList = targetAppItem.getParent().findAccessibilityNodeInfosByViewId("com.android.settings:id/app_switch");
if (switcherNodeList != null && !switcherNodeList.isEmpty() && performAction(switcherNodeList.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
// resetStep();
}
}
}
} else if ("android.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo allowNode = getChildNodeEqual(sourceNode, "允许");
if (allowNode == null) {
allowNode = getChildNodeEqual(sourceNode, "确定");
}
if (performAction(allowNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
} else {
showToastLong("请点击【确定】");
return;
}
}
/**
* 使用记录访问权限(华为设备不同设备标题不同)
*/
if ("com.android.settings.SubSettings".equals(event.getClassName()) && event.getText() != null && (event.getText().toString().contains("使用情况访问权限") || event.getText().toString().contains("使用记录访问权限") || event.getText().toString().contains("使用量数据访问"))) {
if (SystemUtils.isSAMSUNG()) {
AccessibilityNodeInfo nodeInfo = getChildNodeEqual(sourceNode, "允许追踪使用情况");
if (performAction(nodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【允许追踪使用情况】并返回上一页");
return;
}
} else if (SystemUtils.isNOKIA()) {
sleep();
List<AccessibilityNodeInfo> switchWidgetNodeList = sourceNode.findAccessibilityNodeInfosByViewId("android:id/switch_widget");
if (switchWidgetNodeList != null && switchWidgetNodeList.size() > 0) {
if (switchWidgetNodeList.get(0).isChecked()) {
resetStep();
}
switchWidgetNodeList.get(0).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
AccessibilityNodeInfo textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许访问使用记录");
if (textViewNode != null && textViewNode.getParent() != null) {
if (textViewNode.getParent().isClickable()) {
textViewNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
resetStep();
}
} else {
textViewNode = getChildNodeByIdEqualText(sourceNode, "android:id/title", "允许查看使用情况");
if (performAction(textViewNode, AccessibilityNodeInfo.ACTION_CLICK)) {
resetStep();
} else {
showToastLong("请点击【允许查看使用情况】并返回上一页");
return;
}
}
}
}
}
@Override
public void requestCloseUSB(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.Settings$DevelopmentSettingsActivity".equals(event.getClassName())) {
if (SystemUtils.isVIVO() && event.getText() != null && event.getText().toString().equals("[开发]")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
return;
}
}
if ("com.vivo.settings.VivoSubSettings".equals(event.getClassName()) && event.getText() != null && event.getText().toString().equals("[更多设置]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo developerNode = getChildNodeEqual(listViewNode, "开发者选项");
long time = System.currentTimeMillis();
while (developerNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (developerNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
developerNode = getChildNodeEqual(listViewNode, "开发者选项");
}
if (performAction(developerNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【开发者选项】");
return;
}
}
return;
}
if ("com.vivo.settings.DevelpmentSettingsActivity2".equals(event.getClassName())) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo developerNode = getChildNodeEqual(listViewNode, "USB 调试");
long time = System.currentTimeMillis();
while (developerNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (developerNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
developerNode = getChildNodeEqual(listViewNode, "USB 调试");
}
if (performAction(developerNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepLong();
} else {
showToastLong("请点击【USB 调试】");
return;
}
}
}
if ("android.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo cancelNode = getChildNodeEqual(sourceNode, "取消");
if (performAction(cancelNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepLong();
resetStep();
return;
} else {
showToastLong("请点击【取消】");
return;
}
}
if ("com.android.settings".equals(event.getPackageName())) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
// gotoDeviceAdminPermissionSetting();
return;
}
// }
gotoDeveloperChoice();
}
@Override
public void requestNotificationPermission(AccessibilityEvent event) {
}
@Override
public void requestDefaultLauncher(AccessibilityEvent event) {
AccessibilityNodeInfo nodeInfo = event.getSource();
if ("com.android.settings.Settings".equals(event.getClassName())) {
AccessibilityNodeInfo safeNode = getChildNodeEqual(nodeInfo, "安全");
if (performAction(safeNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
return;
} else {
showToastLong("请点击【安全】");
return;
}
}
if ("com.vivo.settings.VivoSubSettings".equals(event.getClassName())) {
if (event.getText() != null) {
if (event.getText().toString().equals("[安全]")) {
AccessibilityNodeInfo changeLauncherNode = getChildNodeEqual(nodeInfo, "更换系统桌面");
if (performAction(changeLauncherNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【更换系统桌面】");
}
return;
} else if (event.getText().toString().equals("[更换系统桌面]")) {
AccessibilityNodeInfo lockLauncher = getChildNodeEqual(nodeInfo, "主屏键锁定系统桌面");
//
if (lockLauncher == null) {
showToastLong("请点击【允许更换桌面】");
return;
}
PermissionUtil.startVIVOManager(getApplicationContext());
sleep();
return;
}
}
}
if ("com.iqoo.secure.MainActivity".equals(event.getClassName())) {
AccessibilityNodeInfo softwareMGNode = getChildNodeEqual(nodeInfo, "软件管理");
if (performAction(softwareMGNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
return;
} else {
showToastLong("请点击【软件管理】");
return;
}
}
if ("com.iqoo.secure.appmanager.AppManagerActivity".equals(event.getClassName())) {
AccessibilityNodeInfo permissionMGNode = getChildNodeEqual(nodeInfo, "权限管理");
if (performAction(permissionMGNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
return;
} else {
showToastLong("请点击【权限管理】");
return;
}
}
if ("com.iqoo.secure.safeguard.PurviewTabActivity".equals(event.getClassName())) {
AccessibilityNodeInfo defaultAppMGNode = getChildNodeEqual(nodeInfo, "默认软件设置");
if (performAction(defaultAppMGNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
return;
} else {
showToastLong("请点击【默认软件设置】");
return;
}
}
if ("com.iqoo.secure.ui.phoneoptimize.DefaultAppSettingActivity".equals(event.getClassName())) {
AccessibilityNodeInfo lanucherNode = getChildNodeEqual(nodeInfo, "桌面");
if (performAction(lanucherNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
return;
} else {
showToastLong("请点击【桌面】");
return;
}
}
if ("com.iqoo.secure.ui.phoneoptimize.DefaultAppResolveActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetAppName = getChildNodeEqual(nodeInfo, appName);
if (performAction(targetAppName, AccessibilityNodeInfo.ACTION_CLICK)) {
return;
} else {
showToastLong("请选择默认桌面为" + appName);
return;
}
}
if ("com.iqoo.secure.ui.phoneoptimize.DefaultAppConfirmActivity".equals(event.getClassName())) {
AccessibilityNodeInfo deterNode = getChildNodeEqual(nodeInfo, "更换");
if (performAction(deterNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
resetStep();
return;
} else {
showToastLong("请点击【更换】");
return;
}
}
if (event.getPackageName() != null && (event.getPackageName().equals("com.android.settings"))) {
if (!"com.android.settings.Settings".equals(event.getClassName())) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
return;
}
}
gotoDefaultLauncherSetting();
}
}
package com.android.launcher3.auto_get_permission.xiaomi;
import android.accessibilityservice.AccessibilityService;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.accessibility.PermissionOpenAccessiblityService;
import com.android.launcher3.auto_get_permission.BaseAutoGetPermission;
import com.android.launcher3.util.Logger;
import com.android.launcher3.util.PermissionUtil;
import java.util.List;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BACK;
import static com.android.launcher3.auto_get_permission.AccessibilityNodeOperateUtil.*;
public class XiaoMiAutoPermissionGetter extends BaseAutoGetPermission {
public static final String TAG = "XiaoMiAutoPermissionGetter";
public XiaoMiAutoPermissionGetter(PermissionOpenAccessiblityService service) {
super(service);
}
@Override
public void requestkDeviceAdmin(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.MiuiSettings".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> listViewNodeS = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodeS != null && listViewNodeS.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodeS.get(0);
AccessibilityNodeInfo targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "密码、隐私与安全");
long time = System.currentTimeMillis();
while (targetNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "密码、隐私与安全");
}
if (targetNode != null && performAction(targetNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【密码、隐私与安全】");
return;
}
}
return;
} else if ("com.android.settings.SubSettings".equals(event.getClassName())) {
String title = event.getText().toString();
if (TextUtils.equals(title, "[密码、隐私与安全]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "系统安全");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "系统安全");
}
if (systemSafeBtn != null && performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【系统安全】");
return;
}
}
return;
}
if (TextUtils.equals(title, "[系统安全]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "特殊应用权限");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "特殊应用权限");
}
if (systemSafeBtn != null && performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【系统安全】");
return;
}
}
return;
}
if (TextUtils.equals(title, "[特殊应用权限]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "设备管理应用");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "设备管理应用");
}
if (systemSafeBtn != null && performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【系统安全】");
}
}
return;
}
if (TextUtils.equals(title, "[设备管理应用]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "com.android.settings:id/name", appName);
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "com.android.settings:id/name", appName);
}
if (systemSafeBtn != null && performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【系统安全】");
return;
}
}
return;
}
} else if ("com.android.settings.DeviceAdminAdd".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> nodeInfoList = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/restricted_action");
if (nodeInfoList != null && nodeInfoList.size() > 0 && nodeInfoList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK)) {
sleep();
// resetStep();
return;
} else {
showToastLong("请点击启用/激活此设备管理员");
return;
}
}
Logger.e(TAG, "gotoDeviceAdminPermissionSetting\t" + event.getClassName().toString());
if ("com.miui.permcenter.install.DeviceManagerApplyActivity".equals(event.getClassName())) {
boolean finish = clickXiaomiSafeWarning(sourceNode);
if (finish) {
resetStep();
}
return;
}
if (event.getPackageName() != null && event.getPackageName().equals("com.android.settings")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
// gotoDeviceAdminPermissionSetting();
return;
}
if (event.getPackageName() == null) {
gotoDeviceAdminPermissionSetting();
sleep();
}
}
@Override
public void requestBatteryOptimize(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.MiuiSettings".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> listViewNodeS = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodeS != null && listViewNodeS.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodeS.get(0);
AccessibilityNodeInfo targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "应用设置");
long time = System.currentTimeMillis();
while (targetNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "应用设置");
}
if (targetNode != null && performAction(targetNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【应用设置】");
return;
}
}
return;
} else if ("com.android.settings.SubSettings".equals(event.getClassName())) {
String title = event.getText().toString();
if (TextUtils.equals(title, "[应用设置]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "应用管理");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "应用管理");
}
if (systemSafeBtn != null && performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【应用管理】");
return;
}
}
return;
}
}
if ("com.miui.appmanager.AppManagerMainActivity".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.miui.securitycenter:id/app_manager_list_view");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "com.miui.securitycenter:id/am_label", appName);
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "com.miui.securitycenter:id/am_label", appName);
}
if (systemSafeBtn != null && performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请找到【" + appName + "】并点击");
return;
}
}
return;
}
Logger.e(TAG, "gotoDeviceAdminPermissionSetting\t" + event.getClassName().toString());
if ("com.miui.appmanager.ApplicationsDetailsActivity".equals(event.getClassName().toString()) && event.getText() != null && event.getText().toString().contains(appName)) {
List<AccessibilityNodeInfo> scrollViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.miui.securitycenter:id/am_scrollview");
if (scrollViewNodes != null && scrollViewNodes.size() > 0) {
AccessibilityNodeInfo scrollViewNode = scrollViewNodes.get(0);
List<AccessibilityNodeInfo> switcherBtnNode = scrollViewNode.findAccessibilityNodeInfosByViewId("com.miui.securitycenter:id/am_switch");
// AccessibilityNodeInfo systemSafeBtn = getChildNodeEqual(sourceNode, "自启动");
long time = System.currentTimeMillis();
while ((switcherBtnNode == null || switcherBtnNode.size() <= 0) && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (scrollViewNode != null) {
scrollViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
scrollViewNode.refresh();
} else {
break;
}
switcherBtnNode = scrollViewNode.findAccessibilityNodeInfosByViewId("com.miui.securitycenter:id/am_switch");
}
if (switcherBtnNode != null && performAction(switcherBtnNode.get(0), AccessibilityNodeInfo.ACTION_CLICK)) {
if (!switcherBtnNode.get(0).isChecked()) {
switcherBtnNode.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
}
} else {
showToastLong("请点击【自启动】");
return;
}
}
}
if ("miui.app.AlertDialog".equals(event.getClassName())) {
AccessibilityNodeInfo acceptBtnNode = getChildNodeEqual(sourceNode, "确定");
if (acceptBtnNode != null && performAction(acceptBtnNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
getService().performGlobalAction(GLOBAL_ACTION_BACK);
} else {
showToastLong("请点击【确定】");
return;
}
}
if ("com.miui.appmanager.ApplicationsDetailsActivity".equals(event.getClassName().toString()) && event.getText() != null && event.getText().toString().contains(appName)) {
List<AccessibilityNodeInfo> scrollViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.miui.securitycenter:id/am_scrollview");
if (scrollViewNodes != null && scrollViewNodes.size() > 0) {
AccessibilityNodeInfo scrollViewNode = scrollViewNodes.get(0);
AccessibilityNodeInfo batterySaveBtn = getChildNodeEqual(sourceNode, "省电策略");
long time = System.currentTimeMillis();
while (batterySaveBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (scrollViewNode != null) {
scrollViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
scrollViewNode.refresh();
} else {
break;
}
batterySaveBtn = getChildNodeEqual(sourceNode, "省电策略");
}
if (batterySaveBtn != null && performAction(batterySaveBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【省电策略】");
return;
}
}
return;
}
if ("com.miui.powerkeeper.ui.HiddenAppsConfigActivity".equals(event.getClassName()) && event.getText() != null && event.getText().toString().contains(appName)) {
// 省电策略
AccessibilityNodeInfo accessibilityNodeInfo = getChildNodeEqual(sourceNode, "无限制");
if (accessibilityNodeInfo != null && performAction(accessibilityNodeInfo, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
} else {
showToastLong("请点击【无限制】");
return;
}
}
if (event.getPackageName() != null && event.getPackageName().equals("com.android.settings")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
// gotoDeviceAdminPermissionSetting();
return;
}
gotoBatteryOptimize();
sleep();
}
@Override
public void requestUsageAppPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.MiuiSettings".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> listViewNodeS = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodeS != null && listViewNodeS.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodeS.get(0);
AccessibilityNodeInfo targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "密码、隐私与安全");
long time = System.currentTimeMillis();
while (targetNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "密码、隐私与安全");
}
if (performAction(targetNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【密码、隐私与安全】");
return;
}
}
return;
} else if ("com.android.settings.SubSettings".equals(event.getClassName())) {
String title = event.getText().toString();
if (TextUtils.equals(title, "[密码、隐私与安全]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "系统安全");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "系统安全");
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【系统安全】");
return;
}
}
return;
} else if (TextUtils.equals(title, "[系统安全]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "特殊应用权限");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "特殊应用权限");
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【特殊应用权限】");
return;
}
}
return;
} else if (TextUtils.equals(title, "[特殊应用权限]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "使用情况访问权限");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "使用情况访问权限");
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【使用情况访问权限】");
return;
}
}
return;
} else if (TextUtils.equals(title, "[使用情况访问权限]")) {
AccessibilityNodeInfo allowPermissionNode = getChildNodeEqual(sourceNode, "允许查看使用情况");
if (allowPermissionNode != null && allowPermissionNode.getParent() != null) {
allowPermissionNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
resetStep();
} else {
sleepLong();
AccessibilityNodeInfo loadingNode = getChildNodeEqual(sourceNode, "正在加载...");
long time = System.currentTimeMillis();
while (loadingNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
sleepLong();
sourceNode.refresh();
return;
}
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("com.android.settings:id/apps_list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", appName);
long time2 = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time2 < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", appName);
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【" + appName + "】");
return;
}
}
}
return;
}
}
if (event.getPackageName() != null && (event.getPackageName().equals("com.android.settings") || event.getPackageName().equals("com.miui.securitycenter"))) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
return;
}
gotoAppUsagePermission();
}
@Override
public void requestCloseUSB(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.MiuiSettings".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> listViewNodeS = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodeS != null && listViewNodeS.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodeS.get(0);
AccessibilityNodeInfo targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "更多设置");
long time = System.currentTimeMillis();
while (targetNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "更多设置");
}
if (performAction(targetNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【更多设置】");
return;
}
}
return;
} else if ("com.android.settings.SubSettings".equals(event.getClassName())) {
String title = event.getText().toString();
if (TextUtils.equals(title, "[更多设置]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "开发者选项");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "开发者选项");
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【开发者选项】");
return;
}
}
return;
}
if (TextUtils.equals(title, "[开发者选项]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "USB 调试");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "USB 调试");
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
systemSafeBtn.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleepShort();
if (!PermissionUtil.enAbleADB(getApplicationContext())) {
resetStep();
}
} else {
showToastLong("请点击【USB 调试】");
return;
}
}
return;
}
}
if (event.getPackageName() != null && event.getPackageName().equals("com.android.settings")) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
// gotoDeviceAdminPermissionSetting();
return;
}
gotoDeveloperChoice();
}
@Override
public void requestNotificationPermission(AccessibilityEvent event) {
AccessibilityNodeInfo sourceNode = event.getSource();
if ("com.android.settings.MiuiSettings".equals(event.getClassName().toString())) {
List<AccessibilityNodeInfo> listViewNodeS = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodeS != null && listViewNodeS.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodeS.get(0);
AccessibilityNodeInfo targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "密码、隐私与安全");
long time = System.currentTimeMillis();
while (targetNode == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode.isScrollable()) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
listViewNode.refresh();
} else {
break;
}
targetNode = getChildNodeByIdEqualText(listViewNode, "android:id/title", "密码、隐私与安全");
}
if (performAction(targetNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【密码、隐私与安全】");
return;
}
}
return;
} else if ("com.android.settings.SubSettings".equals(event.getClassName())) {
String title = event.getText().toString();
if (TextUtils.equals(title, "[密码、隐私与安全]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "系统安全");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "系统安全");
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【系统安全】");
return;
}
}
return;
}
if (TextUtils.equals(title, "[系统安全]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "特殊应用权限");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "特殊应用权限");
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【特殊应用权限】");
return;
}
}
return;
}
if (TextUtils.equals(title, "[特殊应用权限]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "通知使用权");
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", "通知使用权");
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【通知使用权】");
return;
}
}
return;
}
if (TextUtils.equals(title, "[通知使用权]")) {
List<AccessibilityNodeInfo> listViewNodes = sourceNode.findAccessibilityNodeInfosByViewId("android:id/list");
if (listViewNodes != null && listViewNodes.size() > 0) {
AccessibilityNodeInfo listViewNode = listViewNodes.get(0);
AccessibilityNodeInfo systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", appName);
long time = System.currentTimeMillis();
while (systemSafeBtn == null && System.currentTimeMillis() - time < MAX_SEARCH_TIME) {
if (listViewNode != null) {
listViewNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
sleepShort();
} else {
break;
}
systemSafeBtn = getChildNodeByIdEqualText(sourceNode, "android:id/title", appName);
}
if (performAction(systemSafeBtn, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
} else {
showToastLong("请点击【" + appName + "】");
return;
}
}
return;
}
}
if ("android.app.AlertDialog".equals(event.getClassName()) && event.getText() != null && event.getText().toString().contains(appName)) {
AccessibilityNodeInfo acceptBtnNode = getChildNodeEqual(sourceNode, "允许");
if (performAction(acceptBtnNode, AccessibilityNodeInfo.ACTION_CLICK)) {
sleepShort();
resetStep();
getService().performGlobalAction(GLOBAL_ACTION_BACK);
} else {
showToastLong("请点击【允许】");
return;
}
}
if (event.getPackageName() != null && (event.getPackageName().equals("com.android.settings") || event.getPackageName().equals("com.miui.securitycenter"))) {
getService().performGlobalAction(GLOBAL_ACTION_BACK);
sleepShort();
return;
}
gotoAppUsagePermission();
}
@Override
public void requestDefaultLauncher(AccessibilityEvent event) {
AccessibilityNodeInfo nodeInfo=event.getSource();
if ("com.android.internal.app.ResolverActivity".equals(event.getClassName())) {
AccessibilityNodeInfo targetAppNode = getChildNodeEqual(nodeInfo, appName);
if (targetAppNode != null && targetAppNode.getParent() != null) {
targetAppNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
sleep();
}
List<AccessibilityNodeInfo> alwaysBtnList = nodeInfo.findAccessibilityNodeInfosByViewId("android:id/button_always");
if (alwaysBtnList != null && alwaysBtnList.size() > 0) {
alwaysBtnList.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
// AccessibilityNodeInfo alwaysBtn = getChildNodeByIdEqualText(nodeInfo, "android:id/button_always");
}
}
}
......@@ -112,7 +112,8 @@ public class PackageManageActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_package_manage);
LauncherManager.getInstance().changeExitState(false);
LauncherManager.getInstance().changeExitState(true);
LauncherManager.getInstance().setInterceptSystemSetting(false);
tvAdd = findViewById(R.id.tv_add);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment