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

Unable to block NlpWakelock #1

Open
xtphty opened this issue Dec 4, 2013 · 14 comments
Open

Unable to block NlpWakelock #1

xtphty opened this issue Dec 4, 2013 · 14 comments

Comments

@xtphty
Copy link

xtphty commented Dec 4, 2013

I'm running CM11 on an Htc One. This mod doesnt seem to have any effect on the Nlp Wakelock in Google Play Services (location service stuff). I blocked both wakelock and alarms for the Google Play Services app, but battery stats still show it waking the phone while its off. Any ideas what can cause this ?

@t2k269
Copy link
Owner

t2k269 commented Dec 4, 2013

I am also using cm11, let me try it tmr. did you enable Google now?
On Dec 4, 2013 11:22 PM, "xtphty" [email protected] wrote:

I'm running CM11 on an Htc One. This mod doesnt seem to have any effect on
the Nlp Wakelock in Google Play Services (location service stuff). I
blocked both wakelock and alarms for the Google Play Services app, but
battery stats still show it locking the phone while its off. Any ideas what
can cause this ?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1
.

@xtphty
Copy link
Author

xtphty commented Dec 4, 2013

Yeah the Nlp wakelocks seem to occur only if google now is enabled and you have location services set to high accuracy. I tried blocking wakelocks on Google Search app too but it didnt help. Disabling GPS location services (battery saving mode under location settings) seems to stop the locks, but then all other apps (like weather widgets) also lose the GPS privilege and don't update location.

@t2k269
Copy link
Owner

t2k269 commented Dec 4, 2013

my xposed module can prevent an app to acquire wakelock if the app is
acquiring the wakelock directly. if indirect, it may fail to prevent, let
me check the source code of android to see what can I do. will update u
later.
On Dec 4, 2013 11:51 PM, "xtphty" [email protected] wrote:

Yeah the Nlp wakelocks seem to occur only if google now is enabled and you
have location services set to high accuracy. Disabling GPS location
services (battery saving mode under location settings) seems to stop the
locks, but then all other apps (like weather widgets) also lose the GPS
privilege and don't update location.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-29816735
.

@xtphty
Copy link
Author

xtphty commented Dec 4, 2013

I noticed this posted on reddit claiming to be able to do it https://play.google.com/store/apps/details?id=in.andro.wlt

But I'm skeptical of installing a closed source module from an unknown dev

@t2k269
Copy link
Owner

t2k269 commented Dec 4, 2013

good! I will try it tomorrow, since now is midnight in my timezone.

longer battery life is always my goal.

thanks for your information!
On Dec 5, 2013 12:07 AM, "xtphty" [email protected] wrote:

I noticed this posted on reddit claiming to be able to do it
https://play.google.com/store/apps/details?id=in.andro.wlt

But I'm skeptical of installing a closed source module from an unknown dev


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-29818336
.

@Dzakus
Copy link

Dzakus commented Dec 9, 2013

    private static final String CLASS_WAKELOCK = "android.os.PowerManager.WakeLock";
    private XSharedPreferences prefs;

    public void initZygote(IXposedHookZygoteInit.StartupParam paramStartupParam) throws Throwable{
        prefs = new XSharedPreferences(Common.PACKAGE_NAME, "WLTSettings");
    }

    public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable{
        Class WakeLockClass  = XposedHelpers.findClass(CLASS_WAKELOCK , lpparam.classLoader);

        XposedHelpers.findAndHookMethod(WakeLockClass  , "acquire", new XC_MethodHook(){
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable{
                String tag = (String) XposedHelpers.getObjectField(param.thisObject, "mTag");
                String sett = prefs.getString(lpparam.packageName + "/filterWakeLockTags", "-1");
                if (sett.equals(""))
                    sett = "-1";
                if ((sett.equals("-1")) || (sett.contains(tag))){
                    XposedBridge.log("WLT UNBLK:" + lpparam.packageName + " and aquire wakelock:" + tag);
                }
            }

        );
    }

Similar hook for method "release"
Disclaimer: Not tested. Written in notepad quickly. Used only to present ideas. Based on the applications mentioned above.

If you want you can collect wakelock tags and make black/whitelist (above app doesn't do it)

Context context = XposedHelpers.getObjectField(param.thisObject, "mContext");
Intent i = new Intent(SettingsReceiver.ACTION_NEW_WAKELOCK);
i.setExtra(SettingsReceiver.EXTRA_TAG, tag);
context.sendBroadcast(i);

Disclaimer as above.

SettingsReceiver is simply class which extends BroadcastReceiver and is mentioned in AndroidManifest.xml

Sorry for my english. I'm learning. I accept all criticism. I really want to learn it.

@xtphty
Copy link
Author

xtphty commented Dec 9, 2013

Oh I didnt know you could just hook the base PowerManager class! This would be a great solution, I'll try and test it out if I get a chance.

I also like the idea of logging the wakelock usage (denied and accepted both), would make it much easier to block / whitelist them. Another suggestion would be to only allow certain wakelocks when the screen is on, which should prevent functionality from breaking without sacrificing battery.

P.S. your English is fine, understood what you meant perfectly.

@Dzakus
Copy link

Dzakus commented Dec 9, 2013

@t2k269 If you want an example of code that you notify me. I have such a thing implemented in a private project. My project wants shared with other users, but just as I'm done it.

Other method to get context:

XposedHelpers.findAndHookMethod(Application.class, "onCreate", new XC_MethodHook(){
 protected void beforeHookedMethod(MethodHookParam param) throws Throwable{
AppContext = param.thisObject; 
}
})

Disclaimer as above.

I do not know how it affects the system ie. whether it is at all times correct, but I think so.

@t2k269
Copy link
Owner

t2k269 commented Dec 10, 2013

I have given up on the NLP wakelock issue basically, since I don't want to do system wise hacking. I just want to affect the behavior per app, this can prevent system failure. Therefore, for this issue, I think the best method to reduce NLP wakelock is writing a app to listen on Location service, and disable it if it didn't use it for a specific idle period.

Now, I am trying to improve my sleep quality. Due to my job nature, my phone can't be silent at all. I am very appreciate the app group profile feature of CM. The feature works perfectly except Whatsapp, I try to force it to use notification volume but failed. The reason may be that the setAudioStreamType method is native in AudioManager. I am really need to solve this asap. So, this issue will be first priority.

If you want to contribute on this module, please feel free to commit changes. Since this is my first repository in github, if you need me to so something for you, please let me know. Thanks!

@Dzakus
Copy link

Dzakus commented Dec 10, 2013

Whatsapp

Did you try Whatsapp+? Maybe he already has the desired changes?

@Dzakus
Copy link

Dzakus commented Dec 10, 2013

setAudioStreamType

You really need to hook this function?

I think you could also other to avoid problem.
Ex. If app use a notification with sound then hook http://developer.android.com/reference/android/app/Notification.Builder.html build

XposedHelpers.findAndHookMethod(Notification.Builder.class, "build", new XC_MethodHook(){
 protected void afterHookedMethod(MethodHookParam param) throws Throwable{
Notification builder = (Notification) parma.getResult();
Notification.audioStreamType = Notification.STREAM_DEFAULT;
}
}
)

I'm sorry, but I do not have enough time to look closely at it In addition WhatsApps not working for me

@t2k269
Copy link
Owner

t2k269 commented Dec 11, 2013

Dzakus, I know the actual problem already... after digging in the CM code, I found that the CM profile only applied to android.media.Ringtone, absolutely not implemented in android.media.MediaPlayer.

So I am trying to skip the "start()" method in "android.media.MediaPlayer" if CM profile is muting the package.

In addition, I will use your code

XposedHelpers.findAndHookMethod(Application.class, "onCreate", new XC_MethodHook(){
 protected void beforeHookedMethod(MethodHookParam param) throws Throwable{
AppContext = param.thisObject; 
}
})

to implement it (Thank you very much)

@lonige
Copy link

lonige commented Dec 18, 2013

How about delaying alarm of Google Play Service instead of blocking wakelock and alarm of the Service? It doesn't work either?

I love location based services of Google Now, but I think it reports location too frequently to drain battery too much.

No need to block it completely, just adjusting its frequency would suffice...

So now I'm testing with Alarm Multiplier set to x10.. I'll check and see Alarm Count and battery usage.

@shreknel
Copy link

I've set my Alarm Multiplier to x5 and after a reboot and monitoring for an hour didn't notice any decrease in frequency (alarm still seems to be scheduled about once per minute...)
I've put the multiplier on com.google.android.gms, maybe that's not the one registering the alarm...

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

No branches or pull requests

5 participants