首先,对不起我的英语,我是巴西人。
我已经尝试了所有内容,我发现最相关的代码是使用xposed框架的模块,它需要超级用户访问权限才能在系统和模块中安装二进制文件。
模块:http://repo.xposed.info/module/com.semon.cameranotify 当相机正在使用而没有输入通知时,它会打开LED。
apk descompiled java code:
package com.semon.cameranotify.mod;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.XposedHelpers.ClassNotFoundError;
public class LedServiceHook {
public static final String ACTION_CHANGE_LED = "com.semon.cameranotify.change_led";
private static final String CAMERA_ENABLE = "mCameraEnable";
private static final String CLASS_BATTERY_SERVICE_LED = "com.android.server.BatteryService$Led";
public static final String PACKAGE_NAME = "com.android.systemui";
private static final String TAG = "LedServiceHook";
private static Object mBatteryLed = null;
private static BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(LedServiceHook.ACTION_CHANGE_LED)) {
LedServiceHook.changeLedColor(intent.getBooleanExtra("enable", false));
}
}
};
private static final int mCameraOpenedColor = -16711936;
private static void changeLedColor(boolean enable) {
if (mBatteryLed != null) {
try {
Object batteryLight = XposedHelpers.getObjectField(mBatteryLed, "mBatteryLight");
if (batteryLight == null) {
return;
}
if (enable) {
XposedHelpers.setAdditionalInstanceField(mBatteryLed, CAMERA_ENABLE, Boolean.valueOf(true));
XposedHelpers.callMethod(batteryLight, "setColor", new Object[]{Integer.valueOf(mCameraOpenedColor)});
return;
}
XposedHelpers.setAdditionalInstanceField(mBatteryLed, CAMERA_ENABLE, Boolean.valueOf(false));
XposedHelpers.callMethod(batteryLight, "turnOff", new Object[0]);
XposedHelpers.callMethod(mBatteryLed, "updateLightsLocked", new Object[0]);
} catch (Throwable t) {
XposedBridge.log(t);
}
}
}
public static void init(ClassLoader classLoader) {
try {
Class<?> batteryServiceClass = XposedHelpers.findClass(CLASS_BATTERY_SERVICE_LED, classLoader);
XposedBridge.hookAllConstructors(batteryServiceClass, new XC_MethodHook() {
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
LedServiceHook.mBatteryLed = param.thisObject;
Context context = (Context) XposedHelpers.getObjectField(XposedHelpers.getSurroundingThis(param.thisObject), "mContext");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(LedServiceHook.ACTION_CHANGE_LED);
context.registerReceiver(LedServiceHook.mBroadcastReceiver, intentFilter);
}
});
XposedHelpers.findAndHookMethod(batteryServiceClass, "updateLightsLocked", new Object[]{new XC_MethodHook() {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Object cameraEnableObj = XposedHelpers.getAdditionalInstanceField(LedServiceHook.mBatteryLed, LedServiceHook.CAMERA_ENABLE);
if (cameraEnableObj != null && ((Boolean) cameraEnableObj).booleanValue()) {
param.setResult(null);
}
}
}});
} catch (ClassNotFoundError e) {
} catch (Throwable t) {
XposedBridge.log(t);
}
}
}
系统包com.android.server
中的LightsService.java包含更改的原生方法。
有没有人知道有关调用此类方法的可能方法的任何好主意(LightsService.java)?