Miracast Enabler v2.0.0-rc1: LSPosed module rewrite
Complete rewrite from KernelSU shell scripts to LSPosed module using modern libxposed API. Hooks Android's hidden Wi-Fi Display framework to enable native Miracast support on Android 12+ devices. - Framework resource hooks (config_enableWifiDisplay) - WifiDisplayStatus feature state override - System feature and permission injection - Settings Cast UI integration - Quick Settings tile - Settings activity with device-specific options
This commit is contained in:
@@ -27,7 +27,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("de.robv.android.xposed:api:82")
|
||||
compileOnly("io.github.libxposed:api:101.0.1")
|
||||
implementation("androidx.preference:preference:1.2.1")
|
||||
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||
implementation("com.google.android.material:material:1.11.0")
|
||||
|
||||
@@ -2,30 +2,22 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
android:label="Miracast Enabler"
|
||||
android:label="@string/app_name"
|
||||
android:description="@string/app_description"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar"
|
||||
android:supportsRtl="true">
|
||||
|
||||
<!-- LSPosed module metadata -->
|
||||
<!-- LSPosed modern API: module metadata via META-INF/xposed/ files -->
|
||||
<meta-data
|
||||
android:name="xposedmodule"
|
||||
android:value="true" />
|
||||
<meta-data
|
||||
android:name="xposedminversion"
|
||||
android:value="82" />
|
||||
<meta-data
|
||||
android:name="xposeddescription"
|
||||
android:value="Enables native Miracast (Wi-Fi Display) on Android devices" />
|
||||
<meta-data
|
||||
android:name="xposedscope"
|
||||
android:resource="@array/xposed_scope" />
|
||||
|
||||
<!-- Settings launcher -->
|
||||
<activity
|
||||
android:name=".ui.SettingsActivity"
|
||||
android:exported="true"
|
||||
android:label="Miracast Enabler">
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
@@ -36,7 +28,7 @@
|
||||
<service
|
||||
android:name=".tile.MiracastTileService"
|
||||
android:icon="@drawable/ic_cast"
|
||||
android:label="Miracast"
|
||||
android:label="@string/tile_label"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
|
||||
@@ -1,37 +1,78 @@
|
||||
package com.miracast.enabler;
|
||||
|
||||
import de.robv.android.xposed.IXposedHookLoadPackage;
|
||||
import de.robv.android.xposed.IXposedHookZygoteInit;
|
||||
import de.robv.android.xposed.XposedBridge;
|
||||
import de.robv.android.xposed.callbacks.XC_LoadPackage;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import io.github.libxposed.api.XposedInterface;
|
||||
import io.github.libxposed.api.XposedModule;
|
||||
import io.github.libxposed.api.XposedModuleInterface;
|
||||
|
||||
import com.miracast.enabler.hooks.FrameworkResourceHook;
|
||||
import com.miracast.enabler.hooks.DisplayManagerHook;
|
||||
import com.miracast.enabler.hooks.SystemServerHook;
|
||||
import com.miracast.enabler.hooks.MediaRouterHook;
|
||||
|
||||
public class MainHook implements IXposedHookLoadPackage, IXposedHookZygoteInit {
|
||||
public class MainHook extends XposedModule {
|
||||
|
||||
private static final String TAG = "MiracastEnabler";
|
||||
|
||||
@Override
|
||||
public void initZygote(StartupParam startupParam) {
|
||||
XposedBridge.log(TAG + ": initZygote");
|
||||
FrameworkResourceHook.hookZygote();
|
||||
public MainHook() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
switch (lpparam.packageName) {
|
||||
case "android":
|
||||
XposedBridge.log(TAG + ": hooking system_server");
|
||||
SystemServerHook.hook(lpparam);
|
||||
DisplayManagerHook.hook(lpparam);
|
||||
break;
|
||||
case "com.android.settings":
|
||||
XposedBridge.log(TAG + ": hooking Settings");
|
||||
MediaRouterHook.hookSettings(lpparam);
|
||||
break;
|
||||
public void onModuleLoaded(ModuleLoadedParam param) {
|
||||
log(TAG, "module loaded in " + param.getProcessName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSystemServerStarting(SystemServerStartingParam param) {
|
||||
log(TAG, "onSystemServerStarting");
|
||||
hookResourcesBoolean(param.getClassLoader());
|
||||
DisplayManagerHook.hook(this, param);
|
||||
SystemServerHook.hook(this, param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageLoaded(PackageLoadedParam param) {
|
||||
String pkg = param.getPackageName();
|
||||
log(TAG, "onPackageLoaded " + pkg);
|
||||
|
||||
hookResourcesBoolean(param.getDefaultClassLoader());
|
||||
|
||||
if ("com.android.settings".equals(pkg)) {
|
||||
MediaRouterHook.hookSettings(this, param);
|
||||
}
|
||||
}
|
||||
|
||||
private void hookResourcesBoolean(ClassLoader classLoader) {
|
||||
try {
|
||||
var method = Resources.class.getDeclaredMethod("getBoolean", int.class);
|
||||
hook(method).intercept(new ResourceBooleanHooker());
|
||||
log(TAG, "hooked Resources.getBoolean");
|
||||
} catch (Throwable t) {
|
||||
log(TAG, "failed to hook Resources.getBoolean: " + t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String tag, String msg) {
|
||||
log(0, tag, msg);
|
||||
}
|
||||
|
||||
private static class ResourceBooleanHooker implements XposedInterface.Hooker {
|
||||
@Override
|
||||
public Object intercept(XposedInterface.Chain chain) throws Throwable {
|
||||
Object result = chain.proceed();
|
||||
int resId = (int) chain.getArg(0);
|
||||
try {
|
||||
Resources res = (Resources) chain.getThisObject();
|
||||
String name = res.getResourceEntryName(resId);
|
||||
if ("config_enableWifiDisplay".equals(name)) {
|
||||
return true;
|
||||
} else if ("config_wifiDisplaySupportsProtectedBuffers".equals(name)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Resources.NotFoundException ignored) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,56 @@
|
||||
package com.miracast.enabler.hooks;
|
||||
|
||||
import de.robv.android.xposed.XC_MethodHook;
|
||||
import de.robv.android.xposed.XposedBridge;
|
||||
import de.robv.android.xposed.XposedHelpers;
|
||||
import de.robv.android.xposed.callbacks.XC_LoadPackage;
|
||||
import io.github.libxposed.api.XposedInterface;
|
||||
import io.github.libxposed.api.XposedModule;
|
||||
import io.github.libxposed.api.XposedModuleInterface;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Hooks in system_server targeting WifiDisplayAdapter and WifiDisplayController
|
||||
* to ensure the WFD stack initializes and scans correctly.
|
||||
*
|
||||
* On some builds, WifiDisplayController.requestStartScan() has additional
|
||||
* gating checks beyond the resource flag. This hook ensures scanning proceeds.
|
||||
*/
|
||||
public class DisplayManagerHook {
|
||||
|
||||
private static final String TAG = "MiracastEnabler/Display";
|
||||
|
||||
public static void hook(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
hookWifiDisplayFeatureState(lpparam);
|
||||
hookWifiDisplayController(lpparam);
|
||||
public static void hook(XposedModule module, XposedModuleInterface.SystemServerStartingParam param) {
|
||||
hookFeatureState(module, param);
|
||||
hookController(module, param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook WifiDisplayStatus.getFeatureState() to always return FEATURE_STATE_ON (3).
|
||||
* This ensures that any code checking the feature state (Settings, SystemUI)
|
||||
* sees WFD as fully enabled.
|
||||
*/
|
||||
private static void hookWifiDisplayFeatureState(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
private static void hookFeatureState(XposedModule module, XposedModuleInterface.SystemServerStartingParam param) {
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
"android.hardware.display.WifiDisplayStatus",
|
||||
lpparam.classLoader,
|
||||
"getFeatureState",
|
||||
new XC_MethodHook() {
|
||||
@Override
|
||||
protected void afterHookedMethod(MethodHookParam param) {
|
||||
param.setResult(3); // FEATURE_STATE_ON
|
||||
}
|
||||
}
|
||||
);
|
||||
XposedBridge.log(TAG + ": hooked WifiDisplayStatus.getFeatureState -> ON");
|
||||
Class<?> clazz = param.getClassLoader()
|
||||
.loadClass("android.hardware.display.WifiDisplayStatus");
|
||||
Method method = clazz.getDeclaredMethod("getFeatureState");
|
||||
module.hook(method).intercept(new FeatureStateHooker());
|
||||
module.log(0, TAG, "hooked WifiDisplayStatus.getFeatureState -> ON");
|
||||
} catch (Throwable t) {
|
||||
XposedBridge.log(TAG + ": failed to hook getFeatureState");
|
||||
XposedBridge.log(t);
|
||||
module.log(0, TAG, "failed to hook getFeatureState: " + t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook WifiDisplayController to ensure scanning is not blocked by
|
||||
* vendor-specific checks (e.g., missing WFD IE support flag).
|
||||
*/
|
||||
private static void hookWifiDisplayController(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
private static void hookController(XposedModule module, XposedModuleInterface.SystemServerStartingParam param) {
|
||||
try {
|
||||
Class<?> controllerClass = XposedHelpers.findClass(
|
||||
"com.android.server.display.WifiDisplayController",
|
||||
lpparam.classLoader
|
||||
);
|
||||
|
||||
// Log when scan starts to confirm the WFD stack is active
|
||||
XposedHelpers.findAndHookMethod(
|
||||
controllerClass,
|
||||
"requestStartScan",
|
||||
new XC_MethodHook() {
|
||||
@Override
|
||||
protected void beforeHookedMethod(MethodHookParam param) {
|
||||
XposedBridge.log(TAG + ": WifiDisplayController.requestStartScan() called");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
XposedBridge.log(TAG + ": hooked WifiDisplayController");
|
||||
Class<?> clazz = param.getClassLoader()
|
||||
.loadClass("com.android.server.display.WifiDisplayController");
|
||||
Method method = clazz.getDeclaredMethod("requestStartScan");
|
||||
module.hook(method).intercept(new ScanHooker());
|
||||
module.log(0, TAG, "hooked WifiDisplayController.requestStartScan");
|
||||
} catch (Throwable t) {
|
||||
// Controller class name may differ or not exist — non-fatal
|
||||
XposedBridge.log(TAG + ": WifiDisplayController hook skipped: " + t.getMessage());
|
||||
module.log(0, TAG, "WifiDisplayController hook skipped: " + t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static class FeatureStateHooker implements XposedInterface.Hooker {
|
||||
@Override
|
||||
public Object intercept(XposedInterface.Chain chain) throws Throwable {
|
||||
chain.proceed();
|
||||
return 3; // FEATURE_STATE_ON
|
||||
}
|
||||
}
|
||||
|
||||
private static class ScanHooker implements XposedInterface.Hooker {
|
||||
@Override
|
||||
public Object intercept(XposedInterface.Chain chain) throws Throwable {
|
||||
return chain.proceed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,4 @@
|
||||
package com.miracast.enabler.hooks;
|
||||
|
||||
import android.content.res.Resources;
|
||||
|
||||
import de.robv.android.xposed.XC_MethodHook;
|
||||
import de.robv.android.xposed.XposedBridge;
|
||||
import de.robv.android.xposed.XposedHelpers;
|
||||
|
||||
/**
|
||||
* Hooks Resources.getBoolean() globally (in zygote) so that every process —
|
||||
* including system_server, Settings, and SystemUI — sees
|
||||
* config_enableWifiDisplay = true and
|
||||
* config_wifiDisplaySupportsProtectedBuffers = true.
|
||||
*
|
||||
* This is the primary mechanism: WifiDisplayAdapter in DisplayManagerService
|
||||
* checks these resources at startup to decide whether to register the WFD
|
||||
* display adapter at all.
|
||||
*/
|
||||
public class FrameworkResourceHook {
|
||||
|
||||
private static final String TAG = "MiracastEnabler/Resource";
|
||||
|
||||
public static void hookZygote() {
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
Resources.class,
|
||||
"getBoolean",
|
||||
int.class,
|
||||
new XC_MethodHook() {
|
||||
@Override
|
||||
protected void afterHookedMethod(MethodHookParam param) {
|
||||
int resId = (int) param.args[0];
|
||||
try {
|
||||
Resources res = (Resources) param.thisObject;
|
||||
String name = res.getResourceEntryName(resId);
|
||||
if ("config_enableWifiDisplay".equals(name)) {
|
||||
param.setResult(true);
|
||||
} else if ("config_wifiDisplaySupportsProtectedBuffers".equals(name)) {
|
||||
param.setResult(true);
|
||||
}
|
||||
} catch (Resources.NotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
XposedBridge.log(TAG + ": hooked Resources.getBoolean");
|
||||
} catch (Throwable t) {
|
||||
XposedBridge.log(TAG + ": failed to hook Resources.getBoolean");
|
||||
XposedBridge.log(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Resource hooking is now handled directly in MainHook via ResourceBooleanHooker.
|
||||
// This class is kept as a placeholder for any future resource-specific hooks.
|
||||
|
||||
@@ -1,90 +1,33 @@
|
||||
package com.miracast.enabler.hooks;
|
||||
|
||||
import de.robv.android.xposed.XC_MethodHook;
|
||||
import de.robv.android.xposed.XposedBridge;
|
||||
import de.robv.android.xposed.XposedHelpers;
|
||||
import de.robv.android.xposed.callbacks.XC_LoadPackage;
|
||||
import io.github.libxposed.api.XposedInterface;
|
||||
import io.github.libxposed.api.XposedModule;
|
||||
import io.github.libxposed.api.XposedModuleInterface;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Hooks in the Settings app to make WFD (Miracast) sinks visible
|
||||
* in the Cast / Connected Devices UI.
|
||||
*
|
||||
* Android Settings checks WifiDisplayStatus.getFeatureState() to decide
|
||||
* whether to show the Wi-Fi Display settings section. We force it to
|
||||
* FEATURE_STATE_ON so the WFD option appears.
|
||||
*
|
||||
* We also hook in Settings to ensure the WifiDisplaySettings fragment
|
||||
* is reachable and not filtered out.
|
||||
*/
|
||||
public class MediaRouterHook {
|
||||
|
||||
private static final String TAG = "MiracastEnabler/Router";
|
||||
|
||||
public static void hookSettings(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
hookFeatureStateInSettings(lpparam);
|
||||
hookWifiDisplaySettings(lpparam);
|
||||
public static void hookSettings(XposedModule module, XposedModuleInterface.PackageLoadedParam param) {
|
||||
hookFeatureStateInSettings(module, param);
|
||||
hookWifiDisplaySettings(module, param);
|
||||
}
|
||||
|
||||
/**
|
||||
* In the Settings process, hook WifiDisplayStatus.getFeatureState()
|
||||
* to return FEATURE_STATE_ON. This makes the Wi-Fi Display section
|
||||
* appear in Cast preferences.
|
||||
*/
|
||||
private static void hookFeatureStateInSettings(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
private static void hookFeatureStateInSettings(XposedModule module, XposedModuleInterface.PackageLoadedParam param) {
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
"android.hardware.display.WifiDisplayStatus",
|
||||
lpparam.classLoader,
|
||||
"getFeatureState",
|
||||
new XC_MethodHook() {
|
||||
@Override
|
||||
protected void afterHookedMethod(MethodHookParam param) {
|
||||
param.setResult(3); // FEATURE_STATE_ON
|
||||
}
|
||||
}
|
||||
);
|
||||
XposedBridge.log(TAG + ": hooked getFeatureState in Settings");
|
||||
Class<?> clazz = param.getDefaultClassLoader()
|
||||
.loadClass("android.hardware.display.WifiDisplayStatus");
|
||||
Method method = clazz.getDeclaredMethod("getFeatureState");
|
||||
module.hook(method).intercept(new FeatureStateOnHooker());
|
||||
module.log(0, TAG, "hooked getFeatureState in Settings");
|
||||
} catch (Throwable t) {
|
||||
XposedBridge.log(TAG + ": failed to hook getFeatureState in Settings");
|
||||
XposedBridge.log(t);
|
||||
module.log(0, TAG, "failed to hook getFeatureState in Settings: " + t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to hook the WifiDisplaySettings fragment to ensure it initializes
|
||||
* even if the Settings app tries to hide it based on device config.
|
||||
*/
|
||||
private static void hookWifiDisplaySettings(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
// On AOSP Settings, WifiDisplaySettings is a PreferenceFragment that
|
||||
// checks isAvailable() based on the feature state. Since we already
|
||||
// hook getFeatureState, this should work. But some OEMs override
|
||||
// the availability check separately.
|
||||
String[] possibleClasses = {
|
||||
"com.android.settings.wfd.WifiDisplaySettings",
|
||||
"com.android.settings.display.WifiDisplaySettings",
|
||||
"com.android.settings.connecteddevice.WifiDisplaySettings",
|
||||
};
|
||||
|
||||
for (String className : possibleClasses) {
|
||||
try {
|
||||
Class<?> clazz = XposedHelpers.findClass(className, lpparam.classLoader);
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"isAvailable",
|
||||
new XC_MethodHook() {
|
||||
@Override
|
||||
protected void afterHookedMethod(MethodHookParam param) {
|
||||
param.setResult(true);
|
||||
}
|
||||
}
|
||||
);
|
||||
XposedBridge.log(TAG + ": hooked " + className + ".isAvailable()");
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// Also try hooking the preference controller that gates WFD visibility
|
||||
private static void hookWifiDisplaySettings(XposedModule module, XposedModuleInterface.PackageLoadedParam param) {
|
||||
String[] controllerClasses = {
|
||||
"com.android.settings.wfd.WifiDisplayPreferenceController",
|
||||
"com.android.settings.display.WifiDisplayPreferenceController",
|
||||
@@ -92,23 +35,56 @@ public class MediaRouterHook {
|
||||
|
||||
for (String className : controllerClasses) {
|
||||
try {
|
||||
Class<?> clazz = XposedHelpers.findClass(className, lpparam.classLoader);
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"getAvailabilityStatus",
|
||||
new XC_MethodHook() {
|
||||
@Override
|
||||
protected void afterHookedMethod(MethodHookParam param) {
|
||||
param.setResult(0); // AVAILABLE = 0
|
||||
}
|
||||
}
|
||||
);
|
||||
XposedBridge.log(TAG + ": hooked " + className + ".getAvailabilityStatus()");
|
||||
Class<?> clazz = param.getDefaultClassLoader().loadClass(className);
|
||||
Method method = clazz.getDeclaredMethod("getAvailabilityStatus");
|
||||
module.hook(method).intercept(new AvailabilityHooker());
|
||||
module.log(0, TAG, "hooked " + className + ".getAvailabilityStatus()");
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
XposedBridge.log(TAG + ": no WifiDisplaySettings class found to hook (non-fatal)");
|
||||
String[] fragmentClasses = {
|
||||
"com.android.settings.wfd.WifiDisplaySettings",
|
||||
"com.android.settings.display.WifiDisplaySettings",
|
||||
"com.android.settings.connecteddevice.WifiDisplaySettings",
|
||||
};
|
||||
|
||||
for (String className : fragmentClasses) {
|
||||
try {
|
||||
Class<?> clazz = param.getDefaultClassLoader().loadClass(className);
|
||||
Method method = clazz.getDeclaredMethod("isAvailable");
|
||||
module.hook(method).intercept(new IsAvailableHooker());
|
||||
module.log(0, TAG, "hooked " + className + ".isAvailable()");
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
module.log(0, TAG, "no WifiDisplaySettings class found (non-fatal)");
|
||||
}
|
||||
|
||||
private static class FeatureStateOnHooker implements XposedInterface.Hooker {
|
||||
@Override
|
||||
public Object intercept(XposedInterface.Chain chain) throws Throwable {
|
||||
chain.proceed();
|
||||
return 3; // FEATURE_STATE_ON
|
||||
}
|
||||
}
|
||||
|
||||
private static class AvailabilityHooker implements XposedInterface.Hooker {
|
||||
@Override
|
||||
public Object intercept(XposedInterface.Chain chain) throws Throwable {
|
||||
chain.proceed();
|
||||
return 0; // AVAILABLE
|
||||
}
|
||||
}
|
||||
|
||||
private static class IsAvailableHooker implements XposedInterface.Hooker {
|
||||
@Override
|
||||
public Object intercept(XposedInterface.Chain chain) throws Throwable {
|
||||
chain.proceed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,54 +2,35 @@ package com.miracast.enabler.hooks;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import de.robv.android.xposed.XC_MethodHook;
|
||||
import de.robv.android.xposed.XposedBridge;
|
||||
import de.robv.android.xposed.XposedHelpers;
|
||||
import de.robv.android.xposed.callbacks.XC_LoadPackage;
|
||||
import io.github.libxposed.api.XposedInterface;
|
||||
import io.github.libxposed.api.XposedModule;
|
||||
import io.github.libxposed.api.XposedModuleInterface;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Hooks in system_server to:
|
||||
* 1. Force hasSystemFeature("android.software.wifi_display") = true
|
||||
* 2. Grant CONFIGURE_WIFI_DISPLAY and CONTROL_WIFI_DISPLAY permissions
|
||||
* to our package so the QS tile can control WFD.
|
||||
*/
|
||||
public class SystemServerHook {
|
||||
|
||||
private static final String TAG = "MiracastEnabler/System";
|
||||
private static final String OUR_PACKAGE = "com.miracast.enabler";
|
||||
|
||||
public static void hook(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
hookSystemFeature(lpparam);
|
||||
hookPermissions(lpparam);
|
||||
public static void hook(XposedModule module, XposedModuleInterface.SystemServerStartingParam param) {
|
||||
hookSystemFeature(module, param);
|
||||
hookPermissions(module, param);
|
||||
}
|
||||
|
||||
private static void hookSystemFeature(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
private static void hookSystemFeature(XposedModule module, XposedModuleInterface.SystemServerStartingParam param) {
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
"android.app.ApplicationPackageManager",
|
||||
lpparam.classLoader,
|
||||
"hasSystemFeature",
|
||||
String.class,
|
||||
new XC_MethodHook() {
|
||||
@Override
|
||||
protected void afterHookedMethod(MethodHookParam param) {
|
||||
String feature = (String) param.args[0];
|
||||
if ("android.software.wifi_display".equals(feature)
|
||||
|| "android.hardware.wifi.direct".equals(feature)) {
|
||||
param.setResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
XposedBridge.log(TAG + ": hooked hasSystemFeature");
|
||||
Method method = param.getClassLoader()
|
||||
.loadClass("android.app.ApplicationPackageManager")
|
||||
.getDeclaredMethod("hasSystemFeature", String.class);
|
||||
module.hook(method).intercept(new SystemFeatureHooker());
|
||||
module.log(0, TAG, "hooked hasSystemFeature");
|
||||
} catch (Throwable t) {
|
||||
XposedBridge.log(TAG + ": failed to hook hasSystemFeature");
|
||||
XposedBridge.log(t);
|
||||
module.log(0, TAG, "failed to hook hasSystemFeature: " + t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void hookPermissions(XC_LoadPackage.LoadPackageParam lpparam) {
|
||||
// Try multiple permission check paths — the class name varies by Android version
|
||||
private static void hookPermissions(XposedModule module, XposedModuleInterface.SystemServerStartingParam param) {
|
||||
String[] permClasses = {
|
||||
"com.android.server.pm.permission.PermissionManagerServiceImpl",
|
||||
"com.android.server.pm.permission.PermissionManagerService",
|
||||
@@ -57,49 +38,23 @@ public class SystemServerHook {
|
||||
|
||||
for (String className : permClasses) {
|
||||
try {
|
||||
Class<?> clazz = XposedHelpers.findClass(className, lpparam.classLoader);
|
||||
XposedHelpers.findAndHookMethod(
|
||||
clazz,
|
||||
"checkPermission",
|
||||
String.class, String.class, int.class,
|
||||
new XC_MethodHook() {
|
||||
@Override
|
||||
protected void afterHookedMethod(MethodHookParam param) {
|
||||
String perm = (String) param.args[0];
|
||||
String pkg = (String) param.args[1];
|
||||
if (OUR_PACKAGE.equals(pkg) && isWfdPermission(perm)) {
|
||||
param.setResult(PackageManager.PERMISSION_GRANTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
XposedBridge.log(TAG + ": hooked permissions via " + className);
|
||||
Class<?> clazz = param.getClassLoader().loadClass(className);
|
||||
Method method = clazz.getDeclaredMethod("checkPermission", String.class, String.class, int.class);
|
||||
module.hook(method).intercept(new PermissionHooker());
|
||||
module.log(0, TAG, "hooked permissions via " + className);
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: hook the UID-based checkUidPermission
|
||||
try {
|
||||
XposedHelpers.findAndHookMethod(
|
||||
"android.app.ActivityManager",
|
||||
lpparam.classLoader,
|
||||
"checkComponentPermission",
|
||||
String.class, int.class, int.class, boolean.class,
|
||||
new XC_MethodHook() {
|
||||
@Override
|
||||
protected void afterHookedMethod(MethodHookParam param) {
|
||||
String perm = (String) param.args[0];
|
||||
if (perm != null && isWfdPermission(perm)) {
|
||||
param.setResult(PackageManager.PERMISSION_GRANTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
XposedBridge.log(TAG + ": hooked permissions via ActivityManager fallback");
|
||||
Method method = param.getClassLoader()
|
||||
.loadClass("android.app.ActivityManager")
|
||||
.getDeclaredMethod("checkComponentPermission", String.class, int.class, int.class, boolean.class);
|
||||
module.hook(method).intercept(new ComponentPermissionHooker());
|
||||
module.log(0, TAG, "hooked permissions via ActivityManager fallback");
|
||||
} catch (Throwable t) {
|
||||
XposedBridge.log(TAG + ": failed to hook permissions");
|
||||
XposedBridge.log(t);
|
||||
module.log(0, TAG, "failed to hook permissions: " + t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,4 +62,42 @@ public class SystemServerHook {
|
||||
return "android.permission.CONFIGURE_WIFI_DISPLAY".equals(perm)
|
||||
|| "android.permission.CONTROL_WIFI_DISPLAY".equals(perm);
|
||||
}
|
||||
|
||||
private static class SystemFeatureHooker implements XposedInterface.Hooker {
|
||||
@Override
|
||||
public Object intercept(XposedInterface.Chain chain) throws Throwable {
|
||||
Object result = chain.proceed();
|
||||
String feature = (String) chain.getArg(0);
|
||||
if ("android.software.wifi_display".equals(feature)
|
||||
|| "android.hardware.wifi.direct".equals(feature)) {
|
||||
return true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static class PermissionHooker implements XposedInterface.Hooker {
|
||||
@Override
|
||||
public Object intercept(XposedInterface.Chain chain) throws Throwable {
|
||||
Object result = chain.proceed();
|
||||
String perm = (String) chain.getArg(0);
|
||||
String pkg = (String) chain.getArg(1);
|
||||
if (OUR_PACKAGE.equals(pkg) && isWfdPermission(perm)) {
|
||||
return PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ComponentPermissionHooker implements XposedInterface.Hooker {
|
||||
@Override
|
||||
public Object intercept(XposedInterface.Chain chain) throws Throwable {
|
||||
Object result = chain.proceed();
|
||||
String perm = (String) chain.getArg(0);
|
||||
if (perm != null && isWfdPermission(perm)) {
|
||||
return PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Miracast Enabler</string>
|
||||
<string name="app_description">Enables native Miracast (Wi-Fi Display) on Android devices</string>
|
||||
<string name="tile_label">Miracast</string>
|
||||
<string name="tile_scanning">Scanning…</string>
|
||||
<string name="tile_connected">Connected</string>
|
||||
@@ -57,9 +58,4 @@
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="xposed_scope">
|
||||
<item>android</item>
|
||||
<item>com.android.systemui</item>
|
||||
<item>com.android.settings</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
3
app/src/main/resources/META-INF/xposed/module.prop
Normal file
3
app/src/main/resources/META-INF/xposed/module.prop
Normal file
@@ -0,0 +1,3 @@
|
||||
minApiVersion=100
|
||||
targetApiVersion=100
|
||||
staticScope=false
|
||||
3
app/src/main/resources/META-INF/xposed/scope.list
Normal file
3
app/src/main/resources/META-INF/xposed/scope.list
Normal file
@@ -0,0 +1,3 @@
|
||||
android
|
||||
com.android.systemui
|
||||
com.android.settings
|
||||
Reference in New Issue
Block a user