Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
refactoring Xposed logic
  • Loading branch information
MIkhail Aminov committed Sep 8, 2023
1 parent 18b608c commit d71b272
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 76 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/main/assets/xposed_init
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ru.n00byara.motionsenseunlocker.components.xposed.Xposed
ru.n00byara.motionsenseunlocker.components.xposed.XposedEntry

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.n00byara.motionsenseunlocker.components.xposed;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class XposedEntry implements IXposedHookLoadPackage {
private XposedLauncher XposedLauncher = new XposedLauncher();

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (android.os.Build.VERSION.SDK_INT != 33) {
XposedBridge.log("Android 13 supported only!");
return;
}

XposedLauncher.handleLoadPackage(lpparam);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.n00byara.motionsenseunlocker.components.xposed;

import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import ru.n00byara.motionsenseunlocker.components.xposed.mods.ModPacks;
import ru.n00byara.motionsenseunlocker.components.xposed.mods.XposedModPack;

public class XposedLauncher {
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
for (Class<? extends XposedModPack> mod : ModPacks.getMods(lpparam.packageName)) {
try {
XposedModPack instance = mod.getConstructor().newInstance();
instance.handleLoadPackage(lpparam);
} catch (Throwable T) {
XposedBridge.log("Start Error in " + mod.getName());
XposedBridge.log(T);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ru.n00byara.motionsenseunlocker.components.xposed.mods;

public class Constants {
public static final String SETTINGS_PACKAGE = "com.android.settings";
public static final String OSLO_PACKAGE = "com.google.oslo";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.n00byara.motionsenseunlocker.components.xposed.mods;

import java.util.ArrayList;

import ru.n00byara.motionsenseunlocker.components.xposed.mods.oslo.service.OsloEnableDetector;
import ru.n00byara.motionsenseunlocker.components.xposed.mods.oslo.service.actions.MediaPlayerAction;
import ru.n00byara.motionsenseunlocker.components.xposed.mods.settings.aware.AwareHelper;

public class ModPacks {
public static ArrayList<Class<? extends XposedModPack>> getMods(String packageName) {
ArrayList<Class<? extends XposedModPack>> modPacks = new ArrayList<>();

switch (packageName) {
case Constants.OSLO_PACKAGE:
modPacks.add(MediaPlayerAction.class);
modPacks.add(OsloEnableDetector.class);
break;
case Constants.SETTINGS_PACKAGE:
modPacks.add(AwareHelper.class);
break;
}

return modPacks;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.n00byara.motionsenseunlocker.components.xposed.mods;

import de.robv.android.xposed.callbacks.XC_LoadPackage;

public abstract class XposedModPack {
public abstract void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.n00byara.motionsenseunlocker.components.xposed.mods.oslo.service;

import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import ru.n00byara.motionsenseunlocker.components.xposed.mods.XposedModPack;

public class OsloEnableDetector extends XposedModPack {
private Class<?> OsloEnableDetector;
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
OsloEnableDetector = XposedHelpers.findClass("com.google.oslo.service.OsloEnableDetector", lpparam.classLoader);

XposedHelpers.findAndHookMethod(OsloEnableDetector, "getAirplaneModeEnabled", XC_MethodReplacement.returnConstant(false));
XposedHelpers.findAndHookMethod(OsloEnableDetector, "getBatterySaverEnabled", XC_MethodReplacement.returnConstant(false));
XposedHelpers.findAndHookMethod(OsloEnableDetector, "getCountryOverride", XC_MethodReplacement.returnConstant(true));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.n00byara.motionsenseunlocker.components.xposed.mods.oslo.service.actions;

import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import ru.n00byara.motionsenseunlocker.components.xposed.mods.XposedModPack;

public class MediaPlayerAction extends XposedModPack {
private Class<?> MediaPlayerAction;

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
MediaPlayerAction = XposedHelpers.findClass("com.google.oslo.service.actions.MediaPlayerAction", lpparam.classLoader);

XposedHelpers.findAndHookMethod(MediaPlayerAction, "isSupportedApp", String.class, XC_MethodReplacement.returnConstant(true));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.n00byara.motionsenseunlocker.components.xposed.mods.settings.aware;

import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import ru.n00byara.motionsenseunlocker.components.xposed.mods.XposedModPack;

public class AwareHelper extends XposedModPack {
private Class<?> AwareHelper;
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
AwareHelper = XposedHelpers.findClass("com.google.android.settings.aware.AwareHelper", lpparam.classLoader);

XposedHelpers.findAndHookMethod(AwareHelper, "isAirplaneModeOn", XC_MethodReplacement.returnConstant(false));
XposedHelpers.findAndHookMethod(AwareHelper, "isBatterySaverModeOn", XC_MethodReplacement.returnConstant(false));
}
}

0 comments on commit d71b272

Please sign in to comment.