| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java
|
| index 115f9f8ffab3330a57811ac6498f2de2881fc4da..2581a0081d627d05b5ffb1a3d3c1c0c900875d84 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappRegistry.java
|
| @@ -6,10 +6,14 @@ package org.chromium.chrome.browser.webapps;
|
|
|
| import android.content.Context;
|
| import android.content.SharedPreferences;
|
| +import android.content.pm.PackageManager;
|
| +import android.content.pm.PackageManager.NameNotFoundException;
|
| import android.os.AsyncTask;
|
|
|
| +import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.VisibleForTesting;
|
| import org.chromium.base.annotations.CalledByNative;
|
| +import org.chromium.webapk.lib.common.WebApkConstants;
|
|
|
| import java.util.Collections;
|
| import java.util.HashSet;
|
| @@ -173,9 +177,10 @@ public class WebappRegistry {
|
| }
|
|
|
| /**
|
| - * Deletes the data for all "old" web apps.
|
| + * 1. Deletes the data for all "old" web apps.
|
| * "Old" web apps have not been opened by the user in the last 3 months, or have had their last
|
| * used time set to 0 by the user clearing their history. Cleanup is run, at most, once a month.
|
| + * 2. Deletes the data for all WebAPKs that have been uninstalled in the last a month.
|
| *
|
| * @param context Context to open the registry with.
|
| * @param currentTime The current time which will be checked to decide if the task should be run
|
| @@ -191,10 +196,17 @@ public class WebappRegistry {
|
|
|
| Set<String> currentWebapps = getRegisteredWebappIds(preferences);
|
| Set<String> retainedWebapps = new HashSet<String>(currentWebapps);
|
| + PackageManager pm = context.getPackageManager();
|
| for (String id : currentWebapps) {
|
| - long lastUsed = new WebappDataStorage(context, id).getLastUsedTime();
|
| - if ((currentTime - lastUsed) < WEBAPP_UNOPENED_CLEANUP_DURATION) continue;
|
| -
|
| + if (id.startsWith(WebApkConstants.WEBAPK_ID_PREFIX)) {
|
| + if (isWebApkInstalled(pm,
|
| + id.replace(WebApkConstants.WEBAPK_ID_PREFIX, ""))) {
|
| + continue;
|
| + }
|
| + } else {
|
| + long lastUsed = new WebappDataStorage(context, id).getLastUsedTime();
|
| + if ((currentTime - lastUsed) < WEBAPP_UNOPENED_CLEANUP_DURATION) continue;
|
| + }
|
| WebappDataStorage.deleteDataForWebapp(context, id);
|
| retainedWebapps.remove(id);
|
| }
|
| @@ -208,6 +220,15 @@ public class WebappRegistry {
|
| }.execute();
|
| }
|
|
|
| + private static boolean isWebApkInstalled(PackageManager pm, String webApkPakcage) {
|
| + assert !ThreadUtils.runningOnUiThread();
|
| + try {
|
| + pm.getPackageInfo(webApkPakcage, PackageManager.GET_ACTIVITIES);
|
| + } catch (NameNotFoundException e) {
|
| + return false;
|
| + }
|
| + return true;
|
| + }
|
| /**
|
| * Deletes the data of all web apps, as well as the registry tracking the web apps.
|
| */
|
|
|