pambsoftware / beefcake

Training planner and logger for Android
1 stars 0 forks source link

Disable lockscreen while Beefcake is active #1

Closed windmueller closed 9 years ago

windmueller commented 9 years ago

I would like a setting which allows Beefcake to disable the lockscreen of a device while the app is active, so I do not have to unlock the screen after each set. This can be done with the permission DISABLE_KEYGUARD.

pambsoftware commented 9 years ago

That permission is deprecated since API 13. When I used the deprecated code the unlocking worked fine but locking (keyguardLock.reenableKeyguard()) didn't work at all. I tried using the recommended flags instead: getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

but even though it works the lock screen shows (flashes) for 0.1secs and then disappears every time an activity is shown. Very ugly. There is a bug related to this: https://code.google.com/p/android-developer-preview/issues/detail?id=1902 (have only tried with Nexus 5 so far so maybe it works on other phones).

pambsoftware commented 9 years ago

I've tried on S4 running KitKat as well, same problem. The code I'm using is:

@Override
protected void onResume() {
    super.onResume();

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean disableKeyguard = sharedPrefs.getBoolean(PrefsFragment.DISABLE_KEYGUARD, false);

    if (disableKeyguard) {
        try {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        } catch (SecurityException e) {
            //kindle code goes here
        }
    } else {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    }
}

I know the locking probably should go in onPause or onStop. I will put it there if I get this to work.

windmueller commented 9 years ago

What happens if you also use FLAG_KEEP_SCREEN_ON?

I never implemented this myself but I use several apps which are able to do this. e.g. Mighty Grocery. There are several examples on GitHub on how to use these flags, but I am unsure which of them just disable the keyguard.

pambsoftware commented 9 years ago

Well, then it sounds like the idea rather is that the screen is kept on during the use of the app (meaning the lock screen will never even try to load), am I right? That is probably much easier (but was never in the initial request :P), but has the drawback that the screen is always on which will drain the battery faster.

I did try with that flag getting the same problem but then I manually triggered the screen lock by pressing the power button.

windmueller commented 9 years ago

It was not in the initial request because I thought it would be possible without leaving the screen on. When I use Mighty Grocery while shopping, I turn off the screen manually. When I turn the screen back on, the keyguard is disabled.

pambsoftware commented 9 years ago

"When I turn the screen back on, the keyguard is disabled."

That is how you want it right? (also meaning they have solved it, wonder how)

windmueller commented 9 years ago

To be absolutely precise: When I turn on my phone while Beefcake is active, I do not want to have to unlock my phone. Instead, it should behave like I have no secure keyguard at all.

pambsoftware commented 9 years ago

I don't know how to solve that. The current way is annoying (even though it works) since the lock screen flashes in the foreground every time a new activity starts. Perhaps it could be added anyway and you can test it out?

windmueller commented 9 years ago

Of course, I can test this change. Do you want to implement it in a beta or should I install an APK manually?

pambsoftware commented 9 years ago

We'll make a beta. Thanks again for your help!

Cheers On Jan 4, 2015 10:36 PM, "Stephan Windmüller" notifications@github.com wrote:

Of course, I can test this change. Do you want to implement it in a beta or should I install an APK manually?

— Reply to this email directly or view it on GitHub https://github.com/pambsoftware/beefcake/issues/1#issuecomment-68650156.

windmueller commented 9 years ago

I tested the RC1, but it does not behave like expected.

The device still seems to be locked despite the fact that the lock screen is hidden. The screen flashes every time I switch to a new activity. But more interesting is the fact that the phone still behaves like it is locked, e.g. the screen timeout is very short.

pambsoftware commented 9 years ago
  1. Yes, the flashing is something we're not sure how to get rid of since it seems like Android first shows the lock screen and then the flags disabling the lock screen (in onResume) are added making the lock screen to disappear (which gives that ugly annoying flash effect). We never change the screen timeout so that behavior is expected. It would use the screen timeout you have your phone set to.
  2. What if you have "Keep screen on" checked but "Disable screen lock" unchecked? Then you should only need to unlock if you manually turn off the screen by pressing Power.
  3. Using 2 and manually turning off the screen could in turn be solved by setting "Automatically lock"(after sleep...) to X seconds and disable "Power button instantly locks" under Android Security settings.
windmueller commented 9 years ago
  1. I think that you got the code for disabling the lock screen right, but the issue is that the phone does lock in the first place. Perhaps you do not need to disable the secure lock, but prevent the phone from locking.
  2. My workflow is: Turn on the screen, entering the exercise data, and then turn off the screen with the power button. So not pressing the power button is not an option for me, leaving the screen on consumes way too much power.
  3. As I said, the app "Mighty Grocery" prevents the phone from locking in the first place without needing to modify any settings, so there should be a way to do it.
pambsoftware commented 9 years ago

I e-mailed the developer of Might Grocery and got a reply in 33min! :) He explained that they are using the deprecated API that I avoided on purpose. Perhaps the only way right now is to use it. I'll try.

windmueller commented 9 years ago

Yeah, those guys have a really good support, I contacted them before, too. Waiting now for the next RC. :)

pambsoftware commented 9 years ago

His advice solved it! :) Will come in RC2 tomorrow.