OpenLauncherTeam / openlauncher

Customizable and Open Source Launcher for Android
Apache License 2.0
1.41k stars 413 forks source link

Crash reports when adding PWAs #697

Closed chrysn closed 1 year ago

chrysn commented 1 year ago

General Information

Description

Adding a PWA launcher from Chromium sometimes produces a crash screen:

Log

A crash report was shown:

Build version: 0.7.4 Build date: 1980-01-01 00:00:00 Current date: 2022-09-01 08:33:01 Device: Sony E5823

Stack trace:
java.lang.RuntimeException: Unable to start receiver com.benny.openlauncher.receivers.ShortcutReceiver: java.lang.RuntimeException: Setup has not been initialised! at android.app.ActivityThread.handleReceiver(ActivityThread.java:3072) at android.app.ActivityThread.-wrap18(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6186) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) Caused by: java.lang.RuntimeException: Setup has not been initialised! at com.benny.openlauncher.manager.Setup.get(Setup.java:25) at com.benny.openlauncher.manager.Setup.appLoader(Setup.java:47) at com.benny.openlauncher.receivers.ShortcutReceiver.onReceive(ShortcutReceiver.java:54) at android.app.ActivityThread.handleReceiver(ActivityThread.java:3065) ... 8 more

Further references

PWA shortcuts were introduced in #637 by @Apollo3zehn -- if you read this and it does ring a bell, hints would be appreciated.

Next steps

I'll yet have to see whether I can make anything of this or fix it myself.

Apollo3zehn commented 1 year ago

According to your posted stack trace, the static Setup.java was not initialized: https://github.com/OpenLauncherTeam/openlauncher/blob/a80293e38e7e08525c002a801c25dd643b75f853/app/src/main/java/com/benny/openlauncher/manager/Setup.java#L23-L28

Searching the code shows that only in the HomeActivity, the setup is being initialized: https://github.com/OpenLauncherTeam/openlauncher/blob/22e681e5dada9cb9e7c4fece4428e65040ecfa89/app/src/main/java/com/benny/openlauncher/activity/HomeActivity.java#L186-L188

I do not know why this activity is not executed (and thus the Setup is not being initialized) but maybe it is sufficient to initialize it right before https://github.com/OpenLauncherTeam/openlauncher/blob/a80293e38e7e08525c002a801c25dd643b75f853/app/src/main/java/com/benny/openlauncher/receivers/ShortcutReceiver.java#L54

Unfortunately I am no Java and no App developer, I have not the required understanding to say for sure what the solution is.

chrysn commented 1 year ago

Thanks for your input. Based on this, I'd guess that this could all be happening when the launcher app has been unloaded by the OS for being inactive; this would often not show in testing as there one'd be hopping back and forth between the launcher and the PWA installer, and in my tests I've been using Chromium for some time before I pushed the 'install' button.

Ptitg commented 1 year ago

Only before Android Oreo. Since Oreo ShortcutReceiver was deprecated in favor of ShortcutManager.pinRequestShortcut(). I made a patch (https://github.com/Ptitg/openlauncher/tree/fix/adding_pwa_crash), but I don't have the right version of android to test. If someone can test. If it's OK, I'll make a pull request.