Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xposed Module #132

Open
victor141516 opened this issue Nov 25, 2021 · 5 comments
Open

Xposed Module #132

victor141516 opened this issue Nov 25, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@victor141516
Copy link

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

@adolfintel
Copy link
Owner

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.

@victor141516
Copy link
Author

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

@adolfintel
Copy link
Owner

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

@victor141516
Copy link
Author

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.

@Electric1447 Electric1447 added the enhancement New feature or request label Dec 5, 2021
@authorisation
Copy link

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants