Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java

Issue 2954933002: WebApk needs to be restarted to notice that host browser was uninstalled. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java
diff --git a/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java b/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java
index 693cb384e5b99553502f4d6c03a657d502e3e931..0331d40d759c42bea52172c89c1a447cca0a332b 100644
--- a/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java
+++ b/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java
@@ -9,6 +9,7 @@ import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.AsyncTask;
@@ -98,13 +99,14 @@ public class MainActivity extends Activity {
String runtimeHostInPreferences = WebApkUtils.getHostBrowserFromSharedPreference(this);
String runtimeHost = WebApkUtils.getHostBrowserPackageName(this);
+ boolean isInstalled = isInstalled(getPackageManager(), runtimeHost);
if (!TextUtils.isEmpty(runtimeHostInPreferences)
- && !runtimeHostInPreferences.equals(runtimeHost)) {
+ && (!runtimeHostInPreferences.equals(runtimeHost) || !isInstalled)) {
deleteSharedPref(this);
deleteInternalStorageAsync();
}
- if (!TextUtils.isEmpty(runtimeHost)) {
+ if (isInstalled) {
launchInHostBrowser(runtimeHost);
finish();
return;
@@ -275,4 +277,16 @@ public class MainActivity extends Activity {
InstallHostBrowserDialog.show(this, listener, hostUrl, lastResortHostBrowserPackageName,
lastResortHostBrowserApplicationName, R.drawable.last_resort_runtime_host_logo);
}
+
+ /** 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;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698