Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes on startup. Missing SCHEDULE_EXACT_ALARM or USE_EXACT_ALARM permission? #1187

Closed
op3 opened this issue Jan 2, 2025 · 4 comments
Closed
Milestone

Comments

@op3
Copy link

op3 commented Jan 2, 2025

GPSLogger was working fine until a few days ago, when it suddenly started to misbehave. The background service is no longer running, and when I try to open GPSLogger, it crashes immediately:

type: crash
osVersion: google/shiba/shiba:15/AP4A.241205.013/2024123000:user/release-keys
flags: dev options enabled
package: com.mendhak.gpslogger:132, targetSdk 35
process: com.mendhak.gpslogger
processUptime: 344 + 620 ms
installer: com.looker.droidify

java.lang.RuntimeException: Unable to start service com.mendhak.gpslogger.GpsLoggingService@a5a0560 with Intent { cmp=com.mendhak.gpslogger/.GpsLoggingService (has extras) }: java.lang.SecurityException: Caller com.mendhak.gpslogger needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms.
	at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5280)
	at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2555)
	at android.os.Handler.dispatchMessage(Handler.java:109)
	at android.os.Looper.loopOnce(Looper.java:232)
	at android.os.Looper.loop(Looper.java:317)
	at android.app.ActivityThread.main(ActivityThread.java:8826)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
	at com.android.internal.os.ExecInit.main(ExecInit.java:50)
	at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
	at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:369)
Caused by: java.lang.SecurityException: Caller com.mendhak.gpslogger needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms.
	at android.os.Parcel.createExceptionOrNull(Parcel.java:3240)
	at android.os.Parcel.createException(Parcel.java:3224)
	at android.os.Parcel.readException(Parcel.java:3200)
	at android.os.Parcel.readException(Parcel.java:3142)
	at android.app.IAlarmManager$Stub$Proxy.set(IAlarmManager.java:319)
	at android.app.AlarmManager.setImpl(AlarmManager.java:1096)
	at android.app.AlarmManager.setImpl(AlarmManager.java:1045)
	at android.app.AlarmManager.setExactAndAllowWhileIdle(AlarmManager.java:1324)
	at com.mendhak.gpslogger.GpsLoggingService$$ExternalSyntheticApiModelOutline4.m(R8$$SyntheticClass:0)
	at com.mendhak.gpslogger.GpsLoggingService.setupAutoSendTimers(GpsLoggingService.java:334)
	at com.mendhak.gpslogger.GpsLoggingService.startLogging(GpsLoggingService.java:425)
	at com.mendhak.gpslogger.GpsLoggingService.onStartCommand(GpsLoggingService.java:145)
	at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5262)
	... 11 more

I am using GrapheneOS on a Pixel 8, with Android 15. I activated SFTP upload a few days ago (which was working). Not sure if that is related.

@mendhak
Copy link
Owner

mendhak commented Jan 2, 2025

I am guessing that the problem might be this bit:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
am.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, sender);
}
else {
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, sender);
}

The app hasn't been allowed to use exact alarms so it's just crashing.
Can you go check in the OS settings, whether GPSLogger is allowed to work in the background. Usually that's the case where 'exact alarms' get denied. I'm not sure about Graphene but in Pixel under app settings > app batery usage > "Allow background usage".

That said, there's the proper fix for it which is to see if exact alarms are allowed, and to fall back to normal alarms. I've done it here:

if(AlarmManagerCompat.canScheduleExactAlarms(nextPointAlarmManager)){
LOG.debug("Setting exact alarm for {}s", preferenceHelper.getMinimumLoggingInterval());
AlarmManagerCompat.setExactAndAllowWhileIdle(nextPointAlarmManager, AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000L, pi);
}
else {
LOG.debug("Setting inexact alarm for {}s (exact alarm disallowed/not available)", preferenceHelper.getMinimumLoggingInterval());
AlarmManagerCompat.setAndAllowWhileIdle(nextPointAlarmManager, AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000L, pi);
}

But of course I missed it for the auto sender.

Yes it's somewhat related, if you enabled SFTP uploads then the 'auto send timer' alarm code kicked in which I missed in the Android 15 prep work.

@op3
Copy link
Author

op3 commented Jan 2, 2025

Thank you! I had to open App settings → App battery usage: “Allow background usage” was enabled, but I had to change it from “Optimized” to “Unrestricted”. Now, GPSLogger is opening properly again.

mendhak added a commit that referenced this issue Jan 2, 2025
…on Android 15 when background usage was denied.

Issue #1187
@mendhak mendhak mentioned this issue Jan 2, 2025
@mendhak
Copy link
Owner

mendhak commented Jan 2, 2025

OK thanks for confirming that. I've just pushed a fix to the pull request, I'll include it in v133.

@mendhak mendhak added this to the v133 milestone Jan 2, 2025
@mendhak
Copy link
Owner

mendhak commented Jan 7, 2025

v133 is now in FDroid and releases.

@mendhak mendhak closed this as completed Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants