Remove version check, allow version downgrades to appear in Updates tab correctly.

The version check guarded against downgrades, and would not notify the
user if it found a downgrade in the apk cache. However this was from
before we could ask `AppUpdateStatusManager#isPendingInstall(hash)`. Now
we don't need to care whether it is an upgrade or a downgrade, because
there is a more authoritative source as to whether this apk is
interesting to us or not.
This commit is contained in:
Peter Serwylo 2017-04-28 08:38:02 +10:00
parent 0d1e00b6cf
commit 25edfffcbe

View File

@ -43,6 +43,7 @@ public class AppUpdateStatusService extends IntentService {
@Override
protected void onHandleIntent(@Nullable Intent intent) {
Utils.debugLog(TAG, "Scanning apk cache to see if we need to prompt the user to install any apks.");
List<Apk> apksReadyToInstall = new ArrayList<>();
File cacheDir = ApkCache.getApkCacheDir(this);
for (String repoDirName : cacheDir.list()) {
@ -76,31 +77,15 @@ public class AppUpdateStatusService extends IntentService {
return null;
}
PackageInfo installedInfo = null;
try {
installedInfo = getPackageManager().getPackageInfo(downloadedApk.packageName, PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException ignored) { }
if (installedInfo == null) {
if (AppUpdateStatusManager.getInstance(this).isPendingInstall(downloadedApk.hash)) {
Utils.debugLog(TAG, downloadedApk.packageName + " is not installed, so presuming we need to notify the user about installing it.");
Utils.debugLog(TAG, downloadedApk.packageName + " is pending install, so we need to notify the user about installing it.");
return downloadedApk;
} else {
// It was probably downloaded for a previous install, and then subsequently removed
// (but stayed in the cache, as is the designed behaviour). Under these circumstances
// we don't want to tell the user to try and install it.
Utils.debugLog(TAG, downloadedApk.packageName + " is NOT pending install, probably just left over from a previous install.");
return null;
}
}
if (installedInfo.versionCode >= downloadedInfo.versionCode) {
Utils.debugLog(TAG, downloadedApk.packageName + " already installed with versionCode " + installedInfo.versionCode + " and downloaded apk is only " + downloadedInfo.versionCode + ", so ignoring downloaded apk.");
return null;
}
return downloadedApk;
}
/**
* There could be multiple apks with the same hash, provided by different repositories.
* This method looks for all matching records in the database. It then asks each of these