Draw view before screen off or while screen off - android

Target: sleep screen for e-ink device.
Setup: e-ink device with android 4.4.2, firmware sources not available.
What I've tried already:
1) Overlay with zero brightness
add receiver for android.intent.action.SCREEN_OFF/android.intent.action.SCREEN_ON;
on screen off add fullscreen view in WindowManager with flags 'FLAG_TURN_SCREEN_ON', 'FLAG_KEEP_SCREEN_ON' and brightness set to '0';
Problems: device is not sleeping since screen is on, flicker since we're preventing device from going to sleep;
2) Simulate POWER_KEY press
add receiver for android.intent.action.SCREEN_OFF/android.intent.action.SCREEN_ON;
start fullscreen activity with flag 'FLAG_TURN_SCREEN_ON';
after activity is started simulate send POWER_KEY press with 'input keyevent 26';
Problems: root needed, flicker since we're preventing device from going to sleep;
What I want:
Solution that will not require root and will put device to sleep.

On the second thought - it seems not quite possible as it is.
Because, looking at the logs I saw that SurfaceFlinger is releasing screen before ActivityManager displays my activity. So, activity is actually get rendered it's just the screen won't update since system already received sleep-signal.
Maybe this could be figured out with NDK and fw sources.

Related

Can't simulate sleep mode on Android emulator

I am trying to put my emulators into sleep mode to test some behavior.
For this, I deactivate the charger, set the battery to "uncharging" and a low battery %. Then I lock the screen over the power button (swipe to unlock is activated).
Then I start some background operation (for example an IntentService) without holding a wake lock and leave the app, but everything just keeps running as if the screen was on.
The emulator seems to not fall into sleep.
Not a duplicate since I am already following these exact steps (as described above)

My app keeps screen on

My android app is able to run on the bakground and I'd like it to do so wenever the user stops interacting with the phone.
I the app is open and the user does nothing with it for x time, I expected Android to lock the screen (which is what i want).
However, the app simply keep th screen on. Why?
I do not use android:keepScreenOn="true" anywhere on the app.
Are you acquiring a WakeLock ?
If yes you should use PARTIAL_WAKE_LOCK instead FULL_WAKE_LOCK or SCREEN_BRIGHT_WAKE_LOCK the first lets the screen go off, the others don't
Well, turns out it was my fault, not the apps.
I had enabled 'Keep screen awake while charging', and since I had the phone connected to the computer, the screen never locked...
I'll leave this here in case someone else is in the same situation.

Android Lock Screen appears behind home screen occasionally

Android 4+
We're developing a lock screen app (not a widget). The app listens for SCREEN_OFF, and generates the activity, so that when SCREEN_ON is received, the user sees the activity in front of the security features using FLAG_SHOW_WHEN_LOCKED.
We've found that on rare occasions around 1 in every 50 to 100 times, the activity appears behind the Home screen rather than in front of the lock screen. We cannot replicate the issue, and it doesn't appear to happen when connected for debugging (I've sat and locked/unlocked my phone and not seen it, then taken the cable out and it happens in the next few times).
The activity appears to display over the wallpaper, with the home screen icons over the top of the activity.
3 questions:
1) Is it possible to "listen" for when the home screen gets started so that we could just finish() the activity at that point?
2) Is it possible to ensure that the activity runs over the lock screen all the time?
3) How would you test this to try to replicate the fault? I cannot figure out why it does it at all and cannot replicate it.
TIA

Capturing touch events even while system is in sleep

I'm developing an app which requires the system to get the touch events even after the system goes to sleep mode or after the user locks the screen, I tried searching for a solution but it is hard to find one.
Should I want to set any permissions or is there any inbuilt methods or can I override any methods to perform this functionality.
I'm developing an app which requires the system to get the touch events even after the system goes to sleep mode or after the user locks the screen
Fortunately, this is not possible. Otherwise, the device would not be asleep, and battery life would suffer as a result.
Here is a link that shows how to prevent the phone from sleeping.
If you couple that with, say a black screen to 'pretend' the hone is sleeping but actually running your code. So your code can still intercept touch event
Then you need to install your app as a service and make it start when the device is turned on.
You will not need NDK or rooted device for that (sorry, got a short night :) )

How do I force screen on (if it's sleeping), in my Activity?

I am writing an Android alarm-like app.
I want to let the user to choose if to always keep the screen on for the whole application duration, or if she want it to go to sleep according to her device power manager settings.
The first scenario is correctly handled with this code:
getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
But - in the second scenario - when the screen has been swichted off by power manager, I can play a sound via AudioManager, but I can't force the screen to switch on...
I'm using Build.VERSION.SDK = 10 and testing on a Samsung device with Android 2.3.4.
You can maintain a WakeLock, and acquire the WakeLock when you want to turn the screen on.
You can check out WakeLock here.

Categories

Resources