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

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

Issue 2912393005: Add support for webapk without runtimeHost (part 2) (Closed)
Patch Set: pkotwicz@'s comments. Created 3 years, 7 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/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 5305627ad1024625525f1076a228dd15da83a90f..e8444e2bd64668abfc7678216184d1a3e1f4f1f3 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
@@ -11,8 +11,8 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
-import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.Bundle;
import android.text.TextUtils;
import org.chromium.webapk.lib.common.WebApkConstants;
@@ -38,42 +38,6 @@ public class WebApkUtils {
Arrays.asList("com.google.android.apps.chrome", "com.android.chrome", "com.chrome.beta",
"com.chrome.dev", "com.chrome.canary"));
- /** Stores information about a potential host browser for the WebAPK. */
- public static class BrowserItem {
- private String mPackageName;
- private CharSequence mApplicationLabel;
- private Drawable mIcon;
- private boolean mSupportWebApks;
-
- public BrowserItem(String packageName, CharSequence applicationLabel, Drawable icon,
- boolean supportWebApks) {
- mPackageName = packageName;
- mApplicationLabel = applicationLabel;
- mIcon = icon;
- mSupportWebApks = supportWebApks;
- }
-
- /** Returns the package name of a browser. */
- public String getPackageName() {
- return mPackageName;
- }
-
- /** Returns the application name of a browser. */
- public CharSequence getApplicationName() {
- return mApplicationLabel;
- }
-
- /** Returns a drawable of the browser icon. */
- public Drawable getApplicationIcon() {
- return mIcon;
- }
-
- /** Returns whether the browser supports WebAPKs. */
- public boolean supportWebApks() {
- return mSupportWebApks;
- }
- }
-
/**
* 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
@@ -86,6 +50,14 @@ public class WebApkUtils {
sHostPackage = null;
}
+ /**
+ * Returns a list of browsers that supports WebAPKs. TODO(hanxi): Replace this function once we
pkotwicz 2017/06/05 19:18:20 Nit: 'supports' -> 'support' (because browsers is
Xi Han 2017/06/06 15:12:28 Ya, sorry for the typo.
+ * figure out a better way to know which browser supports WebAPKs.
+ */
+ public static List<String> getBrowsersSupportingWebApk() {
+ return sBrowsersSupportingWebApk;
+ }
+
/**
* Returns a Context for the host browser that was specified when building the WebAPK.
* @param context A context.
@@ -121,6 +93,14 @@ public class WebApkUtils {
/** Returns the <meta-data> value in the Android Manifest for {@link key}. */
public static String readMetaDataFromManifest(Context context, String key) {
+ Bundle metadata = readMetaData(context);
+ if (metadata == null) return null;
+
+ return metadata.getString(key);
+ }
+
+ /** Returns the <meta-data> in the Android Manifest. */
+ public static Bundle readMetaData(Context context) {
ApplicationInfo ai = null;
try {
ai = context.getPackageManager().getApplicationInfo(
@@ -128,7 +108,7 @@ public class WebApkUtils {
} catch (NameNotFoundException e) {
return null;
}
- return ai.metaData.getString(key);
+ return ai.metaData;
}
/**
@@ -169,34 +149,11 @@ public class WebApkUtils {
return null;
}
- /**
- * Returns a list of browsers to choose host browser from. The list includes all the installed
- * browsers, and if none of the installed browser supports WebAPKs, Chrome will be added to the
- * list as well.
- */
- public static List<BrowserItem> getBrowserInfosForHostBrowserSelection(
- PackageManager packageManager) {
+ /** Returns a list of ResolveInfo for all of the installed browsers. */
+ public static List<ResolveInfo> getInstalledBrowserResolveInfos(PackageManager packageManager) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
- List<ResolveInfo> resolvedActivityList = packageManager.queryIntentActivities(
+ return packageManager.queryIntentActivities(
browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
-
- boolean hasBrowserSupportingWebApks = false;
- List<BrowserItem> browsers = new ArrayList<>();
- for (ResolveInfo info : resolvedActivityList) {
- boolean supportsWebApk = false;
- if (sBrowsersSupportingWebApk.contains(info.activityInfo.packageName)) {
- supportsWebApk = true;
- hasBrowserSupportingWebApks = true;
- }
- browsers.add(new BrowserItem(info.activityInfo.packageName,
- info.loadLabel(packageManager), info.loadIcon(packageManager), supportsWebApk));
- }
-
- if (hasBrowserSupportingWebApks) return browsers;
-
- // TODO(hanxi): add Chrome's icon to WebAPKs.
- browsers.add(new BrowserItem("com.android.chrome", "Chrome", null, true));
- return browsers;
}
/**
@@ -229,12 +186,10 @@ public class WebApkUtils {
/** Returns a set of package names of all the installed browsers on the device. */
public static Set<String> getInstalledBrowsers(PackageManager packageManager) {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
- List<ResolveInfo> resolvedActivityList = packageManager.queryIntentActivities(
- browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
+ List<ResolveInfo> resolvedInfos = getInstalledBrowserResolveInfos(packageManager);
Set<String> packagesSupportingWebApks = new HashSet<String>();
- for (ResolveInfo info : resolvedActivityList) {
+ for (ResolveInfo info : resolvedInfos) {
packagesSupportingWebApks.add(info.activityInfo.packageName);
}
return packagesSupportingWebApks;
@@ -264,13 +219,4 @@ public class WebApkUtils {
editor.putString(SHARED_PREF_RUNTIME_HOST, hostPackage);
editor.apply();
}
-
- /** Deletes the SharedPreferences. */
- public static void deleteSharedPref(Context context) {
- SharedPreferences sharedPref =
- context.getSharedPreferences(WebApkConstants.PREF_PACKAGE, Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = sharedPref.edit();
- editor.clear();
- editor.apply();
- }
}

Powered by Google App Engine
This is Rietveld 408576698