Update AppDetails buttons after upgrading app to latest version.

Prior to this, it would only update the "Uninstall"/"Run"/"Upgrade"
buttons after a fresh install, or an uninstall.

This change is a bit more liberal in how often we try to update the
view, due to a race condition with PackageManager and AppDetails2.
AppDetails2 listens for InstalledAppProviderService in onResume, but
sometimes that is too late (the notification has already fired).
This commit is contained in:
Peter Serwylo 2017-04-12 14:36:03 +10:00
parent a9b2ac9388
commit 6c12707720
2 changed files with 15 additions and 1 deletions

View File

@ -469,9 +469,20 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
case Installer.ACTION_INSTALL_COMPLETE: case Installer.ACTION_INSTALL_COMPLETE:
adapter.clearProgress(); adapter.clearProgress();
unregisterInstallReceiver(); unregisterInstallReceiver();
// Don't try and update the view here, because the InstalledAppProviderService // Ideally, we wouldn't try to update the view here, because the InstalledAppProviderService
// hasn't had time to do its thing and mark the app as installed. Instead, we // hasn't had time to do its thing and mark the app as installed. Instead, we
// wait for that service to notify us, and then we will respond in appObserver. // wait for that service to notify us, and then we will respond in appObserver.
// Having said that, there are some cases where the PackageManager doesn't
// return control back to us until after it has already braodcast to the
// InstalledAppProviderService. This means that we are not listening for any
// feedback from InstalledAppProviderService (we intentionally stop listening in
// onPause). Empirically, this happens when upgrading an app rather than a clean
// install. However given the nature of this race condition, it may be different
// on different operating systems. As such, we'll just update our view now. It may
// happen again in our appObserver, but that will only cause a little more load
// on the system, it shouldn't cause a different UX.
onAppChanged();
break; break;
case Installer.ACTION_INSTALL_INTERRUPTED: case Installer.ACTION_INSTALL_INTERRUPTED:
adapter.clearProgress(); adapter.clearProgress();

View File

@ -10,6 +10,7 @@ import android.content.pm.Signature;
import android.net.Uri; import android.net.Uri;
import android.os.Process; import android.os.Process;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log;
import org.acra.ACRA; import org.acra.ACRA;
import org.fdroid.fdroid.Hasher; import org.fdroid.fdroid.Hasher;
@ -173,6 +174,7 @@ public class InstalledAppProviderService extends IntentService {
if (ACTION_INSERT.equals(action)) { if (ACTION_INSERT.equals(action)) {
PackageInfo packageInfo = getPackageInfo(intent, packageName); PackageInfo packageInfo = getPackageInfo(intent, packageName);
if (packageInfo != null) { if (packageInfo != null) {
Log.i(TAG, "Marking " + packageName + " as installed");
File apk = new File(packageInfo.applicationInfo.publicSourceDir); File apk = new File(packageInfo.applicationInfo.publicSourceDir);
if (apk.isDirectory()) { if (apk.isDirectory()) {
FilenameFilter filter = new FilenameFilter() { FilenameFilter filter = new FilenameFilter() {
@ -204,6 +206,7 @@ public class InstalledAppProviderService extends IntentService {
} }
} }
} else if (ACTION_DELETE.equals(action)) { } else if (ACTION_DELETE.equals(action)) {
Log.i(TAG, "Marking " + packageName + " as no longer installed");
deleteAppFromDb(this, packageName); deleteAppFromDb(this, packageName);
} }
notifyEvents.onNext(null); notifyEvents.onNext(null);