From 3a2ab0baa635dd1bcfb66437ac1b2e60ba8c1205 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Tue, 19 May 2020 23:43:25 +0200 Subject: [PATCH] fixes a crash that can be triggered when uninstalling with privext Fixes the following crash: 05-19 22:39:55.535 1037 24513 W WindowManager: Attempted to add application window with unknown token Token{2f841 null}. Aborting. 05-19 22:39:55.536 10844 10844 D AndroidRuntime: Shutting down VM 05-19 22:39:55.540 10844 10844 E AndroidRuntime: FATAL EXCEPTION: main 05-19 22:39:55.540 10844 10844 E AndroidRuntime: Process: org.fdroid.fdroid.debug, PID: 10844 05-19 22:39:55.540 10844 10844 E AndroidRuntime: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@d8ae31 is not valid; is your activity running? 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.view.ViewRootImpl.setView(ViewRootImpl.java:891) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:372) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:128) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.app.Dialog.show(Dialog.java:454) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at org.fdroid.fdroid.views.AppDetailsActivity$7.onReceive(AppDetailsActivity.java:607) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:311) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:47) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:120) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:108) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.os.Looper.loop(Looper.java:166) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7529) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 05-19 22:39:55.540 10844 10844 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) The !isFinishing check was already in the installReceiver part, but somehow missing in uninstallReceiver. There's also a reference to this here: http://blackriver.to/2012/08/android-annoying-exception-unable-to-add-window-is-your-activity-running/ I don't understand this crash, especially as the dialouge still gets shown after adding this check (possibly the parent activity is finishing and then immediately restarting?). But this sems to realibly fix it. This was happening when I installed an app, used a new settings entry to unregister privext as a device owner (by calling it via binder/aidl) and then trying to uninstall the app I just installed again, whithout closing f-droid inbetween. --- .../main/java/org/fdroid/fdroid/views/AppDetailsActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsActivity.java b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsActivity.java index 669b73a6c..4af3ea8f5 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsActivity.java +++ b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsActivity.java @@ -591,7 +591,7 @@ public class AppDetailsActivity extends AppCompatActivity String errorMessage = intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE); - if (!TextUtils.isEmpty(errorMessage)) { + if (!TextUtils.isEmpty(errorMessage) && !isFinishing()) { Log.e(TAG, "uninstall aborted with errorMessage: " + errorMessage); AlertDialog.Builder alertBuilder = new AlertDialog.Builder(AppDetailsActivity.this);