Ensure apps are not kept in "Updates" when their repo is disabled.

This caused problems when users then tried to action the pending
install, where it would no longer have enough information to install the
app. Although it may be technically possible to keep enough information
around in memory to make the app installable, but it is not worth the
effort. If a user intentionally disables a repo, we should no longer be
responsible for keeping information about its apps around.

Fixes #995.
This commit is contained in:
Peter Serwylo 2017-08-08 21:12:59 +10:00
parent a71eb243fa
commit f3c48f8d6b
3 changed files with 25 additions and 2 deletions

View File

@ -16,6 +16,7 @@ import android.support.v4.content.LocalBroadcastManager;
import org.fdroid.fdroid.data.Apk;
import org.fdroid.fdroid.data.App;
import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.installer.ErrorDialogActivity;
import java.util.ArrayList;
@ -76,6 +77,7 @@ public final class AppUpdateStatusManager {
public static final String REASON_UPDATES_AVAILABLE = "updatesavailable";
public static final String REASON_CLEAR_ALL_UPDATES = "clearallupdates";
public static final String REASON_CLEAR_ALL_INSTALLED = "clearallinstalled";
public static final String REASON_REPO_DISABLED = "repodisabled";
/**
* If this is present and true, then the broadcast has been sent in response to the {@link AppUpdateStatus#status}
@ -203,6 +205,22 @@ public final class AppUpdateStatusManager {
apksPendingInstall = context.getSharedPreferences("apks-pending-install", Context.MODE_PRIVATE);
}
public void removeAllByRepo(Repo repo) {
boolean hasRemovedSome = false;
Iterator<AppUpdateStatus> it = getAll().iterator();
while (it.hasNext()) {
AppUpdateStatus status = it.next();
if (status.apk.repoId == repo.getId()) {
it.remove();
hasRemovedSome = true;
}
}
if (hasRemovedSome) {
notifyChange(REASON_REPO_DISABLED);
}
}
@Nullable
public AppUpdateStatus get(String key) {
synchronized (appMapping) {

View File

@ -10,6 +10,8 @@ import android.net.Uri;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import org.fdroid.fdroid.AppUpdateStatusManager;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Schema.RepoTable;
import org.fdroid.fdroid.data.Schema.RepoTable.Cols;
@ -242,6 +244,8 @@ public class RepoProvider extends FDroidProvider {
int appCount = resolver.delete(appUri, null, null);
Utils.debugLog(TAG, "Removed " + appCount + " apps from repo " + repo.address + ".");
AppUpdateStatusManager.getInstance(context).removeAllByRepo(repo);
AppProvider.Helper.recalculatePreferredMetadata(context);
}

View File

@ -362,9 +362,10 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
AppUpdateStatusManager manager = AppUpdateStatusManager.getInstance(context);
String reason = intent.getStringExtra(AppUpdateStatusManager.EXTRA_REASON_FOR_CHANGE);
if (AppUpdateStatusManager.BROADCAST_APPSTATUS_LIST_CHANGED.equals(intent.getAction()) &&
AppUpdateStatusManager.REASON_READY_TO_INSTALL.equals(
intent.getStringExtra(AppUpdateStatusManager.EXTRA_REASON_FOR_CHANGE))) {
(AppUpdateStatusManager.REASON_READY_TO_INSTALL.equals(reason) ||
AppUpdateStatusManager.REASON_REPO_DISABLED.equals(reason))) {
updateBadge = true;
}