gpslogger icon indicating copy to clipboard operation
gpslogger copied to clipboard

Start on boot not working Android12

Open hellcoderGIT opened this issue 1 year ago • 3 comments

on Android 12, starting logging on boot does not seem to work anymore.

Requirements for a foreground service to start on boot are pretty long for Android12+: https://developer.android.com/guide/components/foreground-services#background-start-restrictions (but reading through it, it should still be possible)

Will be working on this for one of my own projects and report back if I find a solution.

hellcoderGIT avatar Jul 25 '22 03:07 hellcoderGIT

I did some testing on my device and emulator too, and I'm able to get start on bootup, but only after I unlock the screen.

If that is what you are seeing too, the reason matches up with this thread: https://stackoverflow.com/questions/43144921/android-boot-completed-doesnt-fire-until-user-has-gone-past-lock-screen

By default, apps do not run during Direct Boot mode. If your app needs to take action during Direct Boot mode, you can register app components that should be run during this mode...

If your app needs to access data while running in Direct Boot mode, use device encrypted storage. Device encrypted storage contains data encrypted with a key that is only available after a device has performed a successful verified boot.

For data that should be encrypted with a key associated with user credentials, such as a PIN or password, use credential encrypted storage. Credential encrypted storage is only available after the user has successfully unlocked the device, up until when the user restarts the device again. If the user enables the lock screen after unlocking the device, this doesn't lock credential encrypted storage.

So the unencrypted storage is available to use before the unlock, but the documentation also mentions that it shouldn't be used for general purpose storage

Don't use device encrypted storage as a general-purpose encrypted store. For private user information, or encrypted data that isn't needed during Direct Boot mode, use credential encrypted storage.

I wouldn't be able to use this because GPSLogger makes use of a loooott of values in the encrypted context as part of normal operations, and I wouldn't want to transfer them over to the unencrypted context.

mendhak avatar Jul 29 '22 20:07 mendhak

hm no that's not the behavior I'm seeing, it's just never starting after boot/unlock. Some people suggested app might take up to 5minutes to start after boot, but it's not that either. Your Phone is on Android 12?

I'm on a Oneplus Nord with the latest stable version of your app, maybe it's a phone specific problem. Tried the debugging log but not seeing anything in there.

hellcoderGIT avatar Jul 30 '22 05:07 hellcoderGIT

Ay, caramba, just found out the Oneplus OS has a special config section "App Auto-Launch" which blocks most apps automatically from starting on boot, i disabled it there and it now works as expected.

Sorry, all good, can't trust these customized android operating systems, I knew there was battery optimization for background processes but not that they disable autostart as they choose.

hellcoderGIT avatar Jul 30 '22 06:07 hellcoderGIT

Very good, thanks for sharing that. Yeah different OS customizations are trying to improve on the stock OS in different ways, and it takes some discovering to work your way backwards from unintended behaviors. Your comment will hopefully be useful to future searchers.

mendhak avatar Aug 27 '22 11:08 mendhak