OpenPods icon indicating copy to clipboard operation
OpenPods copied to clipboard

Xposed Module

Open victor141516 opened this issue 3 years ago • 5 comments

Hey I'm trying to do this by myself but I'm a newbie on Android development. The idea is to add a Xposed module to the app that enables the native battery indicator.

I made a simple module that sets the battery level to 50% (not very helpful) and I think you only need to feed it with the real value and that should be all.

The code of the module is as simple as:

public class MyModule implements IXposedHookLoadPackage {

    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        XposedHelpers.findAndHookMethod("android.bluetooth.BluetoothDevice", lpparam.classLoader, "getBatteryLevel", new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
                param.setResult(50);
            }
        });
    }
}

Some tweaks should be done, like checking the device is indeed a non-natively-compatible one.

I don't know if this idea is not new, I didn't see anything related in the issues.

An image of my "always 50% airpods pro" module: https://i.imgur.com/M4xQGht.png

victor141516 avatar Nov 25 '21 17:11 victor141516

If you could reuse code from this app to make a working xposed module, that would be absolutely awesome. With xposed you could probably get rid of the workaround for the randomized mac addresses, battery optimization, etc.

Keep me posted, I'm really interested.

adolfintel avatar Nov 25 '21 17:11 adolfintel

I'm trying but I don't really understand what I'm doing. I suppose I should subscribe to PodsService and somehow retrieve the charging level. I also tried to copy the content of startAirPodsScanner to the Xposed method, but getSystemService and getApplicationContext are not found and I don't know what's happening here. Your help is greatly appreciated

victor141516 avatar Nov 26 '21 14:11 victor141516

I never programmed a Magisk module but I imagine there is some way to access BLE without going through the limited Android APIs like OpenPods does. If there is, all you have to do is listen for all beacons that have the right UUID, read the manufacturer specific data field 76, make sure the length is 27 bytes and do the decoding as explained here

adolfintel avatar Nov 26 '21 18:11 adolfintel

I'll try to work on this when I have time, but I feel like an Android developer can do the thing in 5 minutes. It's just adding a few config lines and creating the class that's on the OP, replacing the 50 for the actual generating function.

victor141516 avatar Nov 30 '21 15:11 victor141516

Any updates on this?

authorisation avatar Sep 10 '22 15:09 authorisation