From 8a69816648736328f90572254a964a6093e85db9 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Wed, 5 Apr 2017 15:09:44 +1000 Subject: [PATCH] Only automatically redirect to package manager when viewing app. If you open AppDetails, initiate a download + install, and then navigate away, it still pops open the install dialog for you. This is because it never deregisters the broadcast receiver. This change maintains the behaviour of always having the broadcast receiver. This is because it is only added when the download completes, and would require further refactoring to change that. Instead, we listen for the receiver, but we ask if the AppDetails view for the apk in question is actually visible to the user. If not, we don't try to initiate the package manager. --- app/src/main/java/org/fdroid/fdroid/AppDetails2.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java index 55c2ac73f..f5122e0e5 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java +++ b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java @@ -457,8 +457,14 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog unregisterInstallReceiver(); break; case Installer.ACTION_INSTALL_USER_INTERACTION: - PendingIntent installPendingIntent = - intent.getParcelableExtra(Installer.EXTRA_USER_INTERACTION_PI); + Apk apk = intent.getParcelableExtra(Installer.EXTRA_APK); + if (!isAppVisible(apk.packageName)) { + Utils.debugLog(TAG, "Ignore request for user interaction from installer, because " + apk.packageName + " is no longer showing."); + break; + } + + Utils.debugLog(TAG, "Automatically showing package manager for " + apk.packageName + " as it is being viewed by the user."); + PendingIntent installPendingIntent = intent.getParcelableExtra(Installer.EXTRA_USER_INTERACTION_PI); try { installPendingIntent.send();