Background service doesn't run when phone is sleeping - General Questions and Answers

Hello,
I'm doing a simple Android background service that implements the raise to wake up feature. Thus, when the phone is in sleep mode (i.e. screen off) and the user raises the phone from the table, it will be waked up by the service.
When I attach the phone to the computer using the debug USB to test the application, in particular looking at the message of logcat, everything work well. Even if the screen is turned off, I can see from android studio that the service is alive and when I try to raise the phone from the table it will wake up.
However, when I detach the phone from the computer, the service won't work. In details, sometimes it works, but if I leave the phone asleep it doesn't work anymore. Checking the running services on my phone I can see that my service is alive, however it is not responsive.
What could be the problem?
I tried both making the service as background service and foreground service. The result is the same.
I'm testing the service on Android 7.0.
You can see the source code (with a precompiled binary) and/or contribute on github (look for the project called raison, I don't have the permission to put the link). The service is started after the boot of the phone or when the user opens the activity.
It doesn't seem a bug of the application (e.g. in the logic), because it works during the debug phase.
Furthermore, I don't have any power saving option and I see the service running (using the developer options).
Another note is that my phone has the double tap to wake up, however the double tap often doesn't work or is really slow (it wakes up after >10 seconds), thus seems that my system is slowing down so much during the sleep. However, applications like whatsapp work well.
There is a way to force my phone to keep the service running (without slowing it down) even in the sleep mode?
Thank you! It could be helpful also to have a feedback of the application on your phones, to see if it is just a problem of my phone or it is some behaviour of Android that prevents the correct execution of the service.
EDIT:
I've also tried to use a wake lock to keep the CPU awake (preventing the deep sleep) without success.

Related

[Q] App like Tasker or Llama

Hi.
Since coming from android I've been a frequent user of apps who lets the phone change it's settings due to specific triggers, like turning silent at night and loud in the morning, turning silent when a certain calendar happening occurs, turning of wifi when leaving home etc.
Is there anything like this for using along with windows phone?
Thanks in advance
Pemell
Actually, (some of) this is theoretically possible, but nobody has done it so far. It's also not going to be allowed on the Marketplace; you'd need to use some unofficial APIs.
For example, the DllImport Project already has shown the ability to control the phone's volume. Programmatically muting the phone at a certain time, for example one minute after a meeting is supposed to start, should be pretty easy.
The trick would be to make sure the phone also un-mutes it when the meeting ends. WP7 doesn't (officially) allow third-party software to run continuously in the background, and while you can schedule a time for the software to run, it make no guarantee ot to-the-minute accuracy. There are ways around the official restrictions, but most of them have serious battery-life considerations (although telling the process to sleep for the next 30 minutes * 60 seconds * 1000 miliseconds would probably work without draining battery). Additionally, I'm not sure how much access apps officially have to calendar data, although on interop-unlocked or full-unlocked phones there are varius ways to access that data.
For things other than volume control, like enabling or disabling WiFi (almost completely unneccessary on WP7, the WiFi power management is, if anything, too conservative already) you'd need to find the place in the OS that controls it. Probably just sending SetDevicePower to the Wifi driver would work to disable it, though I don't know if that would show up correctly in the UI.

[Q] Power saving through Tasker

I consider our Tablet to be different than a phone, in the sense that when we turn off the screen, we dont need all the background functions still running. Currently I see TF101 deep sleep battery drain caused by many different functions running in the backend...for example the location services api.
I was thinking of creating a Tasker script that turns off as many different things as possible a few minutes after the screen is turned off.....And turns them back on when the device is unlocked.
I didn't want to spend time reinventing the wheel if this has already been done....
Anyone already try this? Results?
thanks.
I decided I was over-thinking it...and went with tasker scripts to
a) Auto Turn on Airplane mode when the screen goes off
b) Auto Turn off Airplane mode when the device is unlocked.
(This involved using the "Secure Settings" plugin app to allow Airplane mode via tasker on 4.2 JB)
So far the results have been good. i don't see those map api's being called during deep sleep.

[Q] what is sleep state?

As the title asks, what is it? I know that turning off the screen with power button is not sleeping. I believe it is the state when it takes more than a second (lag) to unlock the screen. This means that the phone was in sleep state and I woke it up. But the question remains, that what is it? How and when is it activated? What happens when the phone is sleeping? Effect on battery (I believe it's positive)? The notifications like sms and call? Is only the screen asleep or are the other functions sleeping as well? Final question, Can I activate the sleep mode with the help of an application if it helps save the battery?
Note that I don't want to use battery saver apps because I don't want anything on my phone to stop. I paid for the whole phone, "including" gps, wifi and things like that. Smartphones are for us, we are not for smartphones.
usman farhat said:
As the title asks, what is it? I know that turning off the screen with power button is not sleeping. I believe it is the state when it takes more than a second (lag) to unlock the screen. This means that the phone was in sleep state and I woke it up. But the question remains, that what is it? How and when is it activated? What happens when the phone is sleeping? Effect on battery (I believe it's positive)? The notifications like sms and call? Is only the screen asleep or are the other functions sleeping as well? Final question, Can I activate the sleep mode with the help of an application if it helps save the battery?
Note that I don't want to use battery saver apps because I don't want anything on my phone to stop. I paid for the whole phone, "including" gps, wifi and things like that. Smartphones are for us, we are not for smartphones.
Click to expand...
Click to collapse
Technically; sleep mode starts the moment the screen is switched off. With the exception of applications which can prevent the phone from fully 'sleeping'. A good and obvious example is the music application which keeps the phone awake in order to play music.
There's really nothing special about sleep mode except that the phone will execute a lot more tasks together but less frequently in order to save power, so you're still able to receive all messages, emails, calls and all notifications (from apps). Applications can also be informed about the change in power state (awake to sleep and sleep to awake) and therefore change the way they behave.
The amount of sleep time the phone gets is dependent on the apps you have installed and the amount of emails, calls and other notifications you get. There isn't a way to enable 'sleep mode' with an application as it would make little difference if your display is on. Your display is the main cause of power consumption, as is true with all smartphones.
Battery Saver apps are dangerous, by killing apps they have a negative impact on the phone. If the application is needed, the phone will restart it and add to the CPU cycles. The same goes with memory freeing apps. GPS/Bluetooth/WiFi are there for when you need them. Keeping them on when they're not needed is a waste of the phone's resources. As the more CPU cycles they use, the more power they consume.
DennisBold said:
Technically; sleep mode starts the moment the screen is switched off. With the exception of applications which can prevent the phone from fully 'sleeping'. A good and obvious example is the music application which keeps the phone awake in order to play music.
There's really nothing special about sleep mode except that the phone will execute a lot more tasks together but less frequently in order to save power, so you're still able to receive all messages, emails, calls and all notifications (from apps). Applications can also be informed about the change in power state (awake to sleep and sleep to awake) and therefore change the way they behave.
The amount of sleep time the phone gets is dependent on the apps you have installed and the amount of emails, calls and other notifications you get. There isn't a way to enable 'sleep mode' with an application as it would make little difference if your display is on. Your display is the main cause of power consumption, as is true with all smartphones.
Battery Saver apps are dangerous, by killing apps they have a negative impact on the phone. If the application is needed, the phone will restart it and add to the CPU cycles. The same goes with memory freeing apps. GPS/Bluetooth/WiFi are there for when you need them. Keeping them on when they're not needed is a waste of the phone's resources. As the more CPU cycles they use, the more power they consume.
Click to expand...
Click to collapse
That's a good explanation
I have read about term "deep sleep" while searching for this, but the explanations on the internet are not clear to me. I have understood a part of it, that this state comes when phone is at rest for too long. The phone pauses apps and their processes, except those who are downloading e.g games and only does basic tasks such as incoming communications (message, call etc.) and sync. Again, I could not find answer to when it state/mode starts.
About GPS/Bluetooth/WiFi: I said this because I had seen people talking about how they have to force otherwise unnecessary restrictions on them and thus have to worry too much to save their batteries. This is what I don't like. Technology is made to facilitate people and to make their lives easy, that's what I believe. On the other hand, I always keep bluetooth off because I need it very rarely. Well, you may have other preferences but I have to keep gps on in order to geo tag photos and to make it ready whenever I open maps etc. Wifi according to me is life blood of smartphones. So I can't live without it either.
When I had Nokia 5800 I had to turn off auto rotate because its menu took time to refresh if I turned the phone by mistake. That was the time when I came to know how bad it feels to go through the settings to turn it on when I need it urgently.

[Q] In need of app for keeping CPU active despite sleep

hi, guys.
"wake my android pro" is an app that turns on the screen for 500ms every T period, where T is user defined. Problem is i am worried about screen wearing too soon, with all those fire ups.
Next choice is never turning the screen off. That's another component spending its life. I would rather avoid it.
"Regpon" is another app. It keeps wifi working with a wifi wakelock, less than a partial wakelock it seems. Then, anything not concerning wifi is beyond it. I have tried it but it doesn't satisfy my need [EDIT: keeps cpu active and wifi active while WLAN is connected, only. Despite its "link to wifi status" option, it always ends when wlan disconnects]
There is another app, whose name isn't coming to me right now. wakelockcontrol, maybe [EDIT: the correct name is "Wake Lock - PowerManager"]. It supposedly employs a wake lock. The user would be able to pick the depth of the wakelock. Unfotunately, it achieves even less than regpon in my device.
Finally, if you can point me to a standalone screen on switch, I'll work with that. In other words, a simple app that I can execute programatically with llama or automateit and which only turns the screen on with one tap [EDIT: Llama has this feature built in. It would be nice to get a stand alone app, though]
ty.
I found another [incomplete] solution: Settings>Developer options>Stay awake
If you think that serves the sole purpose of keeping the screen on, you are misinformed. "Stay awake" has a wakelock, probably less than partial too. I have found it as effective as Regpon, only more stable.
I am still seeking for help.
PS: It amazes me I can`t find any simple "turn device on" application. Heck, I wouldn`t know how to do it in tasker without locale, either. Llama does it pretty well, tough.
PARTIAL SOLUTION reached
I arrived at a partial solution:
0) WiFi module is always on (as in turned on, not active)
1) keepconnonapp keeps llamaapp active
2) Llama is able to detect wlan connection and turn screen on accordingly
3) Whenever wifi is connected, regponapp keeps CPU active for Skype and Csipsimple
4) If kept active both Skype and Csipsimple are able to reconnect automatically.
I consider this solution as partial because it requires interaction between many applications, which might deem it unstable.
DESCRIPTION:
keepconnon: app. Sends "packets" /) to a user defined server. Keeps wifi on when screen is off, but CPU can't be kept alive for neither Skype nor Csipsimple. CPU stays active enough for Llama to run.
regpon: app. Keeps the wifi and cpu ON (as in active, cpu is active) even when the screen is off. Details are unknown. Its wakelock is only effective when there is an active connection, as in: [if left alone] after you disconnect from wlan the device can't reconnect automatically.
Llama: app. Automation application with built in screen turn on (otherwise you should use tasker with a locale plugin)
PURPOSE
To use a tablet as a base phone. Must handle incoming calls even if screen is off. Must be able to recover from modem resets. Having in mind that screen will remain turned off most of the time. Must work in a non-rooted device.
EXPECTED SOLUTION
Run a service that keeps CPU and WiFi active under all circumstances.
I expected this to have been a lot easier, eh he. Still waiting for opinions, haha.

Applications don't work anymore in sleep mode on Huawei P8

Hello,
I have an unrooted Huawei P8. Emui 3.1 - Software version B350. Android 5.1.1 Lollipop.
I noticed a strange behaviour when my phone goes into sleep and I can not find anything on the net about this problem.
There is some time I have installed an application "SMSReminder" which notifies me every 5 minutes when I received a SMS that I have not read yet. What I have noticed is when the phone is idle for some time, the application apparently has no more priority to do the reminders though when I unlock the screen, the notification occurs immediately because the App still running on. I thought that here was to be the app that was buggy and I gave up.
Unless I installed another application "Keycut" for managing a smartbutton inserted into the jack (which can manage functions like switching on torch without unlocking the phone, or turn off the wifi). And I have exactly the same behavior. While all the priorities are activated in the notifications and the app is allowed to operate when the phone is in standby, after a while, the smartbouton no longer works. As if the phone was in deep sleep and could not be unlocked only by a call, the button "Power ON" or receiving new SMS.
Concerning the battery management, I work in "smart" mode, but I tried the "High Performance" mode and it have the same behaviour.
There is a menu to select the apps you want to leave during the sleep of the phone. They remain well functioning but no longer react during the sleep.
I therefore appeal for your help to find out if there is a solution and if anyone has encountered this behavior.
thank you in advance
I also have the same issue, would love a fix

Categories

Resources