urbandroid-team / dont-kill-my-app

Android vendors, don't kill my app!
Creative Commons Attribution 4.0 International
1.25k stars 2.48k forks source link

Nokia 6.1 with Android 9 is working! #20

Open rzetzsche opened 5 years ago

rzetzsche commented 5 years ago

Hi Together,

I appreciate your awesome work. It drives me nuts that device manufactures doing all the different battery saver implementations without any transparency for us developers. We're often dealing with problems were our app will be closed, without any chance to get it to run. This often happens with Chinese manufactures like Huawei, Oppo, Nubia or ZTE.

Nevertheless I have a Nokia 6.1 with Android 9 running and this works like a charm with our app so I can't verify your score for this particular device/manufacturer.

We've disabled the battery optimization, using a foreground service and schedule alarms via AlarmManager's setAlarmClock method. With this setup we aren't experiencing force closing after 20 minutes or stopping of scheduled alarms.

On which circumstances and devices do you experience this problems?

petrnalevka commented 5 years ago

Big thanks for the feedback. This is interesting. Maybe the problem with Sleep as Android is we are keeping a partial (CPU) wake lock, this is what we have to do to collect all sensor data. Th eonly alternative is sensor batching which could be more battery efficient on devices which support it, but Google killed sensor batching in Android 6.0 with the limit on alarm execution...

We will test if wake lock is the condition which makes evenwell kill the process. This would make some apps unaffected but still would affect all the sport tracking apps IMHO..

rzetzsche commented 5 years ago

On the Nokia Section you are mentioning that your app will be forced closed after 20 minutes. Do you experience this force closing or is only the sensor gathering not working?

We are scheduling more frequently alarms via setAlarmClock Method (ca. 8 times per day). Do you also schedule more than one per day? Or only that alarm in the morning? Maybe the frequency of alarms is also a problem.

einstein95 commented 5 years ago

Partially related and I'm not sure if this should go into another issue, but on my Nokia 6.1 which came with Android One and later upgraded to Pie, I didn't have this package installed. Odd.

polyzen commented 5 years ago

The "Battery protection" app is still there after pm uninstall --user 0 com.evenwell.powersaving.g3, even with rebooting. Is this okay?

Edit: Also still there after pm uninstall --user 0 com.evenwell.powersaving.g3.overlay.base.s600ww.

Edit 2: Also uninstalled com.evenwell.batteryprotect and com.evenwell.batteryprotect.overlay.base.s600ww. Now at least the app info for Battery protection says "Not installed for this user", and it is not running.

polyzen commented 5 years ago

To add onto the original post, I have had to regularly relaunch the ProtonMail email client, and it seems now that Nokia app killing may have been the cause. I have not attempted disabling battery optimization, as my searches did not suggest needing to. We'll see if this is now resolved.

Edit: Looking good.

steviator commented 5 years ago

The Nokia page seems to imply that root is required to delete the packages from the phone, but the following commands stop the power management craziness for me without root. (This is important because there is no method to unlock the bootloader or gain root access at present on most Nokia devices, which means this is the only method of fixing most Nokia devices)

adb shell 
pm uninstall --user 0 com.evenwell.powersaving.g3
pm uninstall --user 0 com.evenwell.powersaving.g3.overlay.base.s600ww
pm uninstall --user 0 com.evenwell.batteryprotect
pm uninstall --user 0 com.evenwell.batteryprotect.overlay.base.s600ww

Issuing these commands from the cmd command line by prepending "adb shell " seems to bring up a slew of exceptions, but they work fine when executed in the adb shell directly.

petrnalevka commented 5 years ago

Many thanks I did update that..

Artaud commented 5 years ago

Hello guys, we just found out the reason why users report that force stopping the Battery protection app did not help - the com.evenwell.powersaving.g3 package is a different app. It's actually called Power saver, so hopefully force stopping that one would result in background processes working better. I've changed the listing for Nokia.

Sorry for the confusion.

polyzen commented 5 years ago

Any idea how to reinstall the Battery protection app? ;D

$ pm install --user 0 /system/product/priv-app/BatteryProtect/BatteryProtect.apk
Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.evenwell.batteryprotect is not allowed to install/upgrade with platform key.]
$ pm install --user 0 /product/overlay/com.evenwell.batteryprotect.overlay.base.600WW.apk
Failure [INSTALL_FAILED_INTERNAL_ERROR: Package couldn't be installed in /data/app/com.evenwell.batteryprotect.overlay.base.s600ww-dO7Mp97BMCyGHHScouNEvw==: Overlay com.evenwell.batteryprotect.overlay.base.s600ww is static and cannot be upgraded.]
kushsaini10 commented 5 years ago

Any idea how to reinstall the Battery protection app? ;D

$ pm install --user 0 /system/product/priv-app/BatteryProtect/BatteryProtect.apk
Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.evenwell.batteryprotect is not allowed to install/upgrade with platform key.]
$ pm install --user 0 /product/overlay/com.evenwell.batteryprotect.overlay.base.600WW.apk
Failure [INSTALL_FAILED_INTERNAL_ERROR: Package couldn't be installed in /data/app/com.evenwell.batteryprotect.overlay.base.s600ww-dO7Mp97BMCyGHHScouNEvw==: Overlay com.evenwell.batteryprotect.overlay.base.s600ww is static and cannot be upgraded.]

Factory reset should be the solution for this.

polyzen commented 5 years ago

Well, yeah, but if anyone has a less destructive solution, please share.

kushsaini10 commented 5 years ago

Find another user of Nokia 6.1 and ask him to share those system app's APK with you. System apps can be shared by ES File Explorer as described in this link - https://www.androidsage.com/2017/02/07/how-to-extract-system-apps-from-android-device-pull-stock-apk-files-via-adb/

polyzen commented 5 years ago

The APK's are still available at the file paths shown in my earlier comment.

Mikaela commented 5 years ago

@polyzen I wonder if you need the -r flag as I don't see it in your command compared to https://github.com/urbandroid-team/dont-kill-my-app/issues/25#issuecomment-454958722 .

polyzen commented 5 years ago

Thanks @Mikaela, but unfortunately that gives me the same errors as before. It seems like the OP installed as root.

steviator commented 5 years ago

There is no less destructive solution for packages that have been removed by pm uninstall than factory restore AFAIK.

During installation, when user zero is created, a copy of most system apps is made by a user with a greater privilege level than a normal user.

Without rooting your device which is impossible on most Nokias, you cannot gain enough privileges to re-install the system apps into the users system directory.

Its possible that making another user might make another copy of those system apps, but I believe that happens exactly once during installation.

If it's any consolation, I havent noticed any difference in battery life without battery protection.

rzetzsche commented 5 years ago

@petrnalevka Have you already tested your Nokia 6.1 with the suggested foreground service and turned off battery optimizations? I can now also confirm that the Nokia 5 with the Android 9 update (released a couple of weeks ago) is also working with a foreground service and turned off battery optimizations.

If the battery optimizations are turned on, we're also experiencing app force closes after 20 Minutes.

For me the rating of Nokia devices is way to high, because I am thinking that this devices are way more reliable then for example Huawei devices.

petrnalevka commented 5 years ago

@rzetzsche our foreground service for sleep tracking in Sleep as Android gets killed after 20 minutes even it is a foreground service and even the app is not battery optimized.

But we don't know implementation details of the Nokia battery optimization.. maybe some other parameters also play a role here. I'm not saying all foreground services get killed - I don't know that. Our process keeps a wake lock for instance maybe this is another criteria for killing it? Hard to say..

I think the rating is really deserved as Nokia is historically the very first OEM which kills foreground processes (at least some of them for sure) which shall only be killed in case the device is critically low on memory without any way to configure the system to not do it..

rzetzsche commented 5 years ago

@petrnalevka Ok but that's not the case with our app. I understand your points and know how frustrating it can be. But also Huawei is killing foreground services after a undefined time span and a display turned off and I'm pretty sure that Huawei was killing foreground services before Nokia.

Also I'am not sure, why Huawei for example deserves a 3 star rating. They've started with all that battery crap, are pushing all these settings every EMUI version to another place in the system settings and also partly ignore those settings [1].

For me there shouldn't be a rating difference of 2 between Huawei and Nokia.

[1] https://twitter.com/videolan/status/1022033608670961665

petrnalevka commented 5 years ago

@rzetzsche On Huawei you can setup your device so that foreground services are not killed. The only option on Nokia is to uninstall an APK through adb which wast majority of users cannot do.. This is why they deserve the worst crap score IMHO.. OnePlus is better off as they allow you to configure it but they revert your settings with firmware updates, this is why they get 1+ over Huawei and Xiaomi..

So the logic behind the score now is: (5 crap) foreground services are killed by default and users cannot configure it otherwise (4 crap) foreground services are killed by default and users cannot reliably configure it otherwise (3 crap) foreground services are killed by default but users can reliably configure it otherwise (2 crap) foreground services are killed only when user explicitly configure there phone to do so.. (1 * crap) particular foreground services are killed only when user explicitly configure those services so..

Hope that makes sense..

rzetzsche commented 5 years ago

@petrnalevka I can absolutely understand your point of view. But I think it's a little bit of a personal take on the whole topic. Because a normal foreground service on Nokia devices is working for us. So there is something we're actually missing to understand what Nokia is doing.

I'm also believing that Huawei shouldn't fall in the 3* rating category because "foreground services are killed by default but users can reliably configure it otherwise" isn't the truth. VLC complained exactly about it and we're seeing this issues as well. Sometimes the configuration will fail and the app will killed as well. Also they should be penalized for making it a standard in the Chinese Android world and, even more problematic, change the location of the settings every time they released a new EMUI version.

But that's my personal take on that topic as well.

petrnalevka commented 5 years ago

@rzetzsche I agree with Huawei.. in fact we plan to put it into 4 crap category.. as we have a P10 in the office which we cannot configure reliably to to not keep processes. But it is a single instance so far and we are waiting for more feedback on this, it may well be a firmware bug on a particular device. We don't know yet.

Regarding Nokia... This is definitely something to discuses. But even Huawei or OnePlus do have options which can disable this non-standard behavior. Even Nokia would not handle all foreground services equal still a major difference is Nokia cannot be configured in anyway.. there is nothing to advice to users.. other than ADB which is a no go for most..