Skip to content

Commit

Permalink
新增: 引导模式隐藏通知栏,支持长按电源键退出。修复:引导模式禁止呼出侧边栏失效的问题
Browse files Browse the repository at this point in the history
* 避免进入引导式访问时systemui崩溃

* 完全去除状态栏干扰

* 添加长按电源键触发退出引导式访问

* 将功能开关添加为选项

* 优化代码

* 修复禁止呼出侧边栏失效的问题

* 修复长按在开启小爱长按时失效的问题

---------

Co-authored-by: nxibjz <[email protected]>
Co-authored-by: HChen <[email protected]>
  • Loading branch information
3 people authored Apr 9, 2024
1 parent b48bb99 commit 6ec4571
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,51 +51,50 @@ public class ScLockApp extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
MethodData methodData = DexKit.INSTANCE.getDexKitBridge().findMethod(
FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(ClassMatcher.create()
.usingStrings("startRegionSampling")
)
.name("dispatchTouchEvent")
)
FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(ClassMatcher.create()
.usingStrings("startRegionSampling")
)
.name("dispatchTouchEvent")
)
).singleOrNull();
ClassData data = DexKit.INSTANCE.getDexKitBridge().findClass(
FindClass.create()
.matcher(ClassMatcher.create()
.usingStrings("startRegionSampling")
)
FindClass.create()
.matcher(ClassMatcher.create()
.usingStrings("startRegionSampling")
)
).singleOrNull();
FieldData fieldData = null;
if (methodData == null) {
value = 1;
methodData = DexKit.INSTANCE.getDexKitBridge().findMethod(
FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(ClassMatcher.create()
.usingStrings("SidebarTouchListener")
)
.name("onTouch")
)
FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(ClassMatcher.create()
.usingStrings("SidebarTouchListener")
)
.name("onTouch")
)
).singleOrNull();
data = DexKit.INSTANCE.getDexKitBridge().findClass(
FindClass.create()
.matcher(ClassMatcher.create()
.usingStrings("onTouch: \taction = ")
)
FindClass.create()
.matcher(ClassMatcher.create()
.usingStrings("onTouch: \taction = ")
)
).singleOrNull();
fieldData = DexKit.INSTANCE.getDexKitBridge().findField(
FindField.create()
.matcher(
FieldMatcher.create()
.declaredClass(
ClassMatcher.create()
.usingStrings("onTouch: \taction = ")
FindField.create()
.matcher(FieldMatcher.create()
.declaredClass(ClassMatcher.create()
.usingStrings("onTouch: \taction = ")
)
.type(View.class)
)
.type(View.class)
)
).singleOrNull();
}
try {
Field field = null;
// logE(TAG, "dispatchTouchEvent: " + methodData + " Constructor: " + data + " class: " + data.getInstance(lpparam.classLoader) + " f: " + fieldData.getFieldInstance(lpparam.classLoader));
if (data == null) {
logE(TAG, "Class is null");
Expand All @@ -104,16 +103,20 @@ public void init() throws NoSuchMethodException {
if (fieldData == null && value == 1) {
logE(TAG, "Field is null");
return;
}
assert fieldData != null;
Field field = fieldData.getFieldInstance(lpparam.classLoader);
} else if (fieldData != null) field = fieldData.getFieldInstance(lpparam.classLoader);
// logE(TAG, "data: " + data + " fieldData: " + fieldData + " methodData: " + methodData);
Field finalField = field;
hookAllConstructors(data.getInstance(lpparam.classLoader), new MethodHook() {
@Override
protected void after(MethodHookParam param) {
Context context = null;
if (value == 1) {
try {
context = ((View) field.get(param.thisObject)).getContext();
if (finalField == null) {
logE(TAG, "finalField is null!");
return;
}
context = ((View) finalField.get(param.thisObject)).getContext();
} catch (IllegalAccessException e) {
logE(TAG, "getContext E: " + e);
}
Expand All @@ -133,8 +136,8 @@ public void onChange(boolean selfChange) {
}
};
context.getContentResolver().registerContentObserver(
Settings.Global.getUriFor("key_lock_app"),
false, contentObserver);
Settings.Global.getUriFor("key_lock_app"),
false, contentObserver);
isListen = true;
}
}
Expand All @@ -148,14 +151,14 @@ public void onChange(boolean selfChange) {
return;
}
hookMethod(methodData.getMethodInstance(lpparam.classLoader),
new MethodHook() {
@Override
protected void before(MethodHookParam param) {
if (isLock) {
param.setResult(false);
new MethodHook() {
@Override
protected void before(MethodHookParam param) {
if (isLock) {
param.setResult(false);
}
}
}
}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,81 +45,104 @@ public class SystemLockApp extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
findAndHookMethod("com.android.server.wm.ActivityTaskManagerService",
"onSystemReady",
new MethodHook() {
@Override
protected void after(MethodHookParam param) {
try {
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
if (context == null) return;
if (!isObserver) {
ContentObserver contentObserver = new ContentObserver(new Handler(context.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri, int flags) {
isLock = getLockApp(context) != -1;
if (isLock) {
taskId = getLockApp(context);
XposedHelpers.callMethod(param.thisObject, "startSystemLockTaskMode", taskId);
} else {
XposedHelpers.callMethod(param.thisObject, "stopSystemLockTaskMode");
"onSystemReady",
new MethodHook() {
@Override
protected void after(MethodHookParam param) {
try {
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
if (context == null) return;
if (!isObserver) {
ContentObserver contentObserver = new ContentObserver(new Handler(context.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri, int flags) {
isLock = getLockApp(context) != -1;
if (isLock) {
taskId = getLockApp(context);
XposedHelpers.callMethod(param.thisObject, "startSystemLockTaskMode", taskId);
} else {
XposedHelpers.callMethod(param.thisObject, "stopSystemLockTaskMode");
}
}
};
context.getContentResolver().registerContentObserver(
Settings.Global.getUriFor("key_lock_app"),
false, contentObserver);

ContentObserver contentObserver1 = new ContentObserver(new Handler(context.getMainLooper())) {
@Override
public void onChange(boolean selfChange) {
needLockScreen = getMyLockScreen(context) == 1;
}
}
};
context.getContentResolver().registerContentObserver(
Settings.Global.getUriFor("key_lock_app"),
false, contentObserver);

ContentObserver contentObserver1 = new ContentObserver(new Handler(context.getMainLooper())) {
@Override
public void onChange(boolean selfChange) {
needLockScreen = getMyLockScreen(context) == 1;
}
};
context.getContentResolver().registerContentObserver(
Settings.Global.getUriFor("exit_lock_app_screen"),
false, contentObserver1);
isObserver = true;
};
context.getContentResolver().registerContentObserver(
Settings.Global.getUriFor("exit_lock_app_screen"),
false, contentObserver1);
isObserver = true;
}
} catch (Throwable e) {
logE(TAG, "E: " + e);
}
} catch (Throwable e) {
logE(TAG, "E: " + e);
}
}
}
);

findAndHookMethod("com.android.server.wm.LockTaskController",
"shouldLockKeyguard", int.class,
new MethodHook() {
@Override
protected void before(MethodHookParam param) {
if (needLockScreen) {
param.setResult(true);
} else {
param.setResult(false);
findAndHookMethod("com.miui.server.input.util.ShortCutActionsUtils",
"triggerHapticFeedback", boolean.class, String.class,
String.class, boolean.class, String.class,
new MethodHook() {
@Override
protected void after(MethodHookParam param) {
if (!mPrefsMap.getBoolean("system_framework_guided_access_status"))
return; // 不知道为什么还是需要重启才生效
String shortcut = (String) param.args[1];
if ("imperceptible_press_power_key".equals(shortcut) || "long_press_power_key".equals(shortcut)) {
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
isLock = getLockApp(context) != -1;
if (isLock) {
setLockApp(context, -1);
}
}
}
}
}
);

if (isPad()) {
findAndHookMethod("com.android.server.wm.MiuiCvwGestureController$GesturePointerEventListener",
"onPointerEvent", MotionEvent.class,
findAndHookMethod("com.android.server.wm.LockTaskController",
"shouldLockKeyguard", int.class,
new MethodHook() {
@Override
protected void before(MethodHookParam param) {
if (isLock) {
param.setResult(null);
if (needLockScreen) {
param.setResult(true);
} else {
param.setResult(false);
}
}
}
);

if (isPad()) {
findAndHookMethod("com.android.server.wm.MiuiCvwGestureController$GesturePointerEventListener",
"onPointerEvent", MotionEvent.class,
new MethodHook() {
@Override
protected void before(MethodHookParam param) {
if (isLock) {
param.setResult(null);
}
}
}
);
}
}

public static void setLockApp(Context context, int id) {
Settings.Global.putInt(context.getContentResolver(), "key_lock_app", id);
}

public int getLockApp(Context context) {
try {
return Settings.Global.getInt(context.getContentResolver(), "key_lock_app");

} catch (Settings.SettingNotFoundException e) {
logE(TAG, "getInt hyceiler_lock_app E: " + e);
}
Expand Down
Loading

0 comments on commit 6ec4571

Please sign in to comment.