| Index: chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/WebApkUtils.java
|
| diff --git a/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/WebApkUtils.java b/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/WebApkUtils.java
|
| index 2ff261fcd01624e22fb44b61db6a92528b2fb0eb..a22a85f28f95ddecae57071c4965faed3b9e7035 100644
|
| --- a/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/WebApkUtils.java
|
| +++ b/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/WebApkUtils.java
|
| @@ -38,11 +38,7 @@ public class WebApkUtils {
|
| Arrays.asList("com.google.android.apps.chrome", "com.android.chrome", "com.chrome.beta",
|
| "com.chrome.dev", "com.chrome.canary"));
|
|
|
| - /**
|
| - * Caches the package name of the host browser. {@link sHostPackage} might refer to a browser
|
| - * which has been uninstalled. A notification can keep the WebAPK process alive after the host
|
| - * browser has been uninstalled.
|
| - */
|
| + /** Caches the package name of the host browser. */
|
| private static String sHostPackage;
|
|
|
| /** For testing only. */
|
| @@ -81,7 +77,7 @@ public class WebApkUtils {
|
| * @return The package name. Returns null on an error.
|
| */
|
| public static String getHostBrowserPackageName(Context context) {
|
| - if (sHostPackage == null) {
|
| + if (sHostPackage == null || !isInstalled(context.getPackageManager(), sHostPackage)) {
|
| sHostPackage = getHostBrowserPackageNameInternal(context);
|
| if (sHostPackage != null) {
|
| writeHostBrowserToSharedPref(context, sHostPackage);
|
| @@ -91,6 +87,18 @@ public class WebApkUtils {
|
| return sHostPackage;
|
| }
|
|
|
| + /** Returns whether the application is installed. */
|
| + private static boolean isInstalled(PackageManager packageManager, String packageName) {
|
| + if (TextUtils.isEmpty(packageName)) return false;
|
| +
|
| + try {
|
| + packageManager.getApplicationInfo(packageName, 0);
|
| + } catch (PackageManager.NameNotFoundException e) {
|
| + return false;
|
| + }
|
| + return true;
|
| + }
|
| +
|
| /** Returns the <meta-data> value in the Android Manifest for {@link key}. */
|
| public static String readMetaDataFromManifest(Context context, String key) {
|
| Bundle metadata = readMetaData(context);
|
|
|