atticuscornett / AtmosWeather

Atmos Weather is a lightweight weather app for receiving alerts and forecasts in the US.
https://atticuscornett.github.io/AtmosWeather/
GNU General Public License v3.0
24 stars 4 forks source link

Android: crash on start #16

Closed AeliusSaionji closed 10 months ago

AeliusSaionji commented 10 months ago
FATAL EXCEPTION: main
Process: io.atticusc.atmosweather, PID: 24104
java.lang.RuntimeException: Unable to start activity ComponentInfo{io.atticusc.atmosweather/io.atticusc.atmosweather.MainActivity}: java.lang.SecurityException: Caller io.atticusc.atmosweather needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms.
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3783)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3923)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2444)
    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:8223)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:977)
Caused by: java.lang.SecurityException: Caller io.atticusc.atmosweather 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:3057)
    at android.os.Parcel.createException(Parcel.java:3041)
    at android.os.Parcel.readException(Parcel.java:3024)
    at android.os.Parcel.readException(Parcel.java:2966)
    at android.app.IAlarmManager$Stub$Proxy.set(IAlarmManager.java:311)
    at android.app.AlarmManager.setImpl(AlarmManager.java:1084)
    at android.app.AlarmManager.setImpl(AlarmManager.java:1044)
    at android.app.AlarmManager.setExact(AlarmManager.java:808)
    at io.atticusc.atmosweather.MainActivity.startBackgroundTask(MainActivity.java:86)
    at io.atticusc.atmosweather.MainActivity.onCreate(MainActivity.java:51)
    at android.app.Activity.performCreate(Activity.java:8595)
    at android.app.Activity.performCreate(Activity.java:8573)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1457)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3765)
    ... 12 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:1339)
    at android.os.Binder.execTransact(Binder.java:1275)

Version Info

atticuscornett commented 10 months ago

Thanks for your interest in Atmos Weather! I will look into this issue shortly.

atticuscornett commented 10 months ago

Based on the error and Android version you are using, it looks like the crash was caused by this change in Android 14. In the past, I had taken for granted that the SCHEDULE_EXACT_ALARM permission was given by default and that users would not manually revoke the permission. The app uses the SCHEDULE_EXACT_ALARM permission to check for weather alerts regularly. For now, you should be able to use Atmos by manually granting permission to set alarms in app info. In the near future, I plan to release an update that adds additional permission checks and requests the permission properly.

atticuscornett commented 10 months ago

I have reviewed the alarm code and believe I have fixed all Android 14 alarm issues. I will be confirming the fixes with an emulator soon. It is admittedly not a very graceful solution - for now, it just opens the settings page for alarms without a proper explanation for why the permission is needed. However, the app will no longer crash on Android 14. If the permission is not granted, Atmos Weather will continue to work with degraded notification performance. In a future update, I plan to overhaul the permissions request flow on Android to explain permissions to the user.

atticuscornett commented 10 months ago

Tested - fix works. While testing, I also discovered that notifications are disabled by default in Android 14 as well. I have added another fix to request the notification permission for Android 14. As with the last fix, this is not a graceful solution, but it will have to do until I have more time to completely revamp the permissions setup.

atticuscornett commented 10 months ago

Both issues are confirmed fully fixed now. I will be releasing Atmos Weather v2.0.2 shortly with the fixed code.

atticuscornett commented 10 months ago

Atmos Weather v2.0.2 has been released! (https://github.com/atticuscornett/AtmosWeather/releases/tag/v2.0.2)