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.
This commit is contained in:
Peter Serwylo 2017-04-05 15:09:44 +10:00
parent be11a785e5
commit 8a69816648

View File

@ -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();