artyommironov/nanji

Crash of appearance-settings, if 'alarms & reminders'-permission is not allowed (@Android 14)

Closed this issue · 11 comments

revuwa commented

If I click on:
image
the app crashes with the following log:

type: crash
osVersion: google/{name}/{name}:14/UD1A.230803.041/2023102300:user/release-keys
package: com.kazufukurou.nanji:41
process: com.kazufukurou.nanji
processUptime: 1378 + 177 ms
installer: com.machiav3lli.fdroid

java.lang.RuntimeException: Unable to start receiver com.kazufukurou.nanji.ui.WidgetProvider: java.lang.SecurityException: Caller com.kazufukurou.nanji needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms.
	at android.app.ActivityThread.handleReceiver(ActivityThread.java:4469)
	at android.app.ActivityThread.-$$Nest$mhandleReceiver(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2263)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:205)
	at android.os.Looper.loop(Looper.java:294)
	at android.app.ActivityThread.main(ActivityThread.java:8199)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ExecInit.main(ExecInit.java:49)
	at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
	at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:359)
Caused by: java.lang.SecurityException: Caller com.kazufukurou.nanji 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:3066)
	at android.os.Parcel.createException(Parcel.java:3050)
	at android.os.Parcel.readException(Parcel.java:3026)
	at android.os.Parcel.readException(Parcel.java:2968)
	at android.app.IAlarmManager$Stub$Proxy.set(IAlarmManager.java:311)
	at android.app.AlarmManager.setImpl(AlarmManager.java:1093)
	at android.app.AlarmManager.setImpl(AlarmManager.java:1045)
	at android.app.AlarmManager.setExact(AlarmManager.java:809)
	at com.kazufukurou.nanji.ui.WidgetProvider.h(SourceFile:40)
	at com.kazufukurou.nanji.ui.WidgetProvider.i(SourceFile:247)
	at com.kazufukurou.nanji.ui.WidgetProvider.onUpdate(SourceFile:9)
	at android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:71)
	at com.kazufukurou.nanji.ui.WidgetProvider.onReceive(SourceFile:6)
	at android.app.ActivityThread.handleReceiver(ActivityThread.java:4460)
	... 11 more
Caused by: android.os.RemoteException: Remote stack trace:
	at com.android.server.alarm.AlarmManagerService$5.set(AlarmManagerService.java:2981)
	at android.app.IAlarmManager$Stub.onTransact(IAlarmManager.java:181)
	at android.os.Binder.execTransactInternal(Binder.java:1368)
	at android.os.Binder.execTransact(Binder.java:1299)

If I manually give the needed permission:
image
and restart the app, it works pretty well.

Probably it's a good idea to ask for this permission on (first) app startup. What do you think?

inson1 commented

For me it doesnt need any permissons and it doesnt crashes.

I think it shouldnt need Alarm permisson. Idk why does it need it.

Device: Xiaomi Redmi note 8 Pro
OS: Android 11 MIUI 12.5.7
Version: 1.4.2

Why does it need it @artyommironov?

revuwa commented

For me it doesnt need any permissons and it doesnt crashes.

I think it shouldnt need Alarm permisson. Idk why does it need it.

Device: Xiaomi Redmi note 8 Pro OS: Android 11 MIUI 12.5.7 Version: 1.4.2

Why does it need it @artyommironov?

To make this a bit clearer. Before my upgrade to Android 14, I didn't need these permissions either.
It should have something to do with changes to the operating system structure, I think.

inson1 commented

only thing I found about alarms in android 14 docs (https://source.android.com/docs/setup/about/android-14-release) is this

"Full-screen intent limits
To prevent ad spam and credential phishing, starting with Android 14, the default USE_FULL_SCREEN_INTENT permission to send full-screen notifications can be granted only to apps that provide calling and alarm functionalities. See Full-screen intent limits for more information."

But I dont think we are using it. And if yes then I dont get it why we need it in appearance

inson1 commented

@revuwa Did you try creating the widget? Or did you do enything else? Before adding the permisson. Its just wierd that it would crash on appearance.

inson1 commented

ok, this is why https://developer.android.com/about/versions/14/changes/schedule-exact-alarms - new change in android 14 and this is I guess missing?

"Existing best-practices for the SCHEDULE_EXACT_ALARM permission still apply, including the following:

Check the permission with canScheduleExactAlarms() before scheduling exact alarms.
Set up your app to listen and properly react to the foreground broadcast AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED, which the system sends when the user grants the permission."

com.android.alarm.permission.SET_ALARM doesnt need alarm permission - https://blog.mindorks.com/what-are-the-different-protection-levels-in-android-permission/#:~:text=one%20by%20one.-,Normal%20Permissions,to%20use%20date%20or%20time.

inson1 commented

We need that for updating widgets. Arent there other options for updating widgets? @artyommironov Without user permission?
I still dont get it why it crashed on appearance.
Ok it should be added after openning the app + listener for permission changed to request permisson again if the permission is ungranted
And USE_EXACT_ALARM (no granting the permission needed) cant be used. https://support.google.com/googleplay/android-developer/answer/9888170?sjid=10510309997098831402-AP

inson1 commented

@revuwa Btw this app doesnt yet even targets the android 14, so please report all problems you can find

On my device alarm permission is granted by default on app fresh install, but if I disable it manually then I get same crash.

I still dont get it why it crashed on appearance.

@inson1 This is because when root settings screen goes background (close, switch to other screen) it calls widget update, which in turn schedules next update using the exact alarm.

Arent there other options for updating widgets?

what about using this instead

WorkManager seems can be used for this, I wil try it first.

inson1 commented

@artyommironov You dont have Adroid 14 I guess. Its new thing in Android 14. It wasnt in basic release notes, but for example here it is https://developer.android.com/about/versions/14/behavior-changes-all

It was first thing I found, I dont care what we use, it just have to do its work without any new permission from user.

revuwa commented

@artyommironov Thank you so much ❤️