ServeIt
ServeIt copied to clipboard
Can we disable Android doze mode while the server is up?
The http server is working pretty well! I'll be using it for caching a few huge files related to Windows reinstallations while using my smartphone as a wifi 5Ghz hotspot :)
But it seems that the smartphone is going into doze mode oftenly and suspending ServerIt from time to time.
[Update:] Adding this to AndroidManifest.xml:
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
And this to main.dart, in startServer():
final PermissionStatus permissionStatus = await Permission.ignoreBatteryOptimizations.request();
Seems to help!
@panreyes Thanks for reporting the issue, I will check on this once & update
Hi again. The server worked for me pretty well this weekend, although my smartphone still went to sleep mode oftenly. The solution I mentioned earlier helped a bit, but seems that Android ends up ignoring it anyway and putting the app in deep sleep mode.
I'm currently testing another permission, WAKE_LOCK.
Requires 3 changes:
- A new dependency, wakelock: ^0.4.0
- Android permission: android.permission.WAKE_LOCK
- Importing, enabling and disabling it in main.dart:
import 'package:wakelock/wakelock.dart';
Wakelock.enable(); // in startServer
Wakelock.disable(); // in stopServer
It's been around 20 minutes and the smartphone seems that it's not getting into deep sleep even if it's locked, with the screen turned off and not charging. Crossing my fingers to see if this will be good enough! 🤞 I'll confirm in one hour :)
[Update] It's still alive, working flawlessly, and I haven't touched my smartphone in one hour! 🙌🥳
@panreyes This is a great feature and I wanted to check on this myself. But I'm little cautious here
- Need to check on the battery consumption, If the app consumes more juice than needed in the background then it is bad (And that's the reason Android is so strict on this)
- If someone installs the app & keeps it running on the background it could potentially be a security issue. We need to have some flag to toggle the background wake lock option & make sure there is a notification that says app is running background. Please feel free to raise a PR if you would like otherwise I will work on my free time 😄