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

Side by Side Diff: chrome/android/webapk/libs/common/src/org/chromium/webapk/lib/common/WebApkUtils.java

Issue 2011613003: Upstream: Extract "WebAPK service" implementation from Chrome APK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.webapk.lib.common;
6
7 import android.content.Context;
8 import android.content.pm.ApplicationInfo;
9 import android.content.pm.PackageManager;
10 import android.content.pm.PackageManager.NameNotFoundException;
11 import android.os.Bundle;
12
13 /**
14 * Contains utility methods for interacting with WebAPKs.
15 */
16 public class WebApkUtils {
17
18 private static final String DEFAULT_CHROME_PACKAGE_NAME = "com.google.androi d.apps.chrome";
gone 2016/05/25 21:11:02 nit: Kind of weird to hard-code this. Is there an
pkotwicz 2016/05/26 01:11:41 Ok, I have removed the default.
19
20 /**
21 * Caches the value read from Application Metadata which specifies the host browser's package
22 * name.
23 */
24 private static String sHostPackage;
25
26 /**
27 * Returns a Context for the host browser that was specified when building t he WebAPK.
28 * @param context A context.
29 * @return The remote context. Returns null on an error.
30 */
31 public static Context getHostBrowserContext(Context context) {
32 try {
33 String hostPackage = getHostBrowserPackageName(context);
34 return context.getApplicationContext().createPackageContext(
gone 2016/05/25 21:11:02 ContextUtils.getApplicationContext()?
pkotwicz 2016/05/26 01:11:41 Unfortunately the code in chrome/android/webapk ca
35 hostPackage,
36 Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_IN CLUDE_CODE);
37 } catch (NameNotFoundException e) {
38 e.printStackTrace();
39 }
40 return null;
41 }
42
43 /**
44 * Returns the package name for the host browser that was specified when bui lding the WebAPK.
45 * @param context A context.
46 * @return The package name. Returns null on an error.
47 */
48 public static String getHostBrowserPackageName(Context context) {
49 if (sHostPackage != null) return sHostPackage;
50 String hostPackage = null;
51 try {
52 ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
53 context.getPackageName(), PackageManager.GET_META_DATA);
54 Bundle bundle = ai.metaData;
55 hostPackage = bundle.getString("runtimeHost");
56 } catch (NameNotFoundException e) {
57 e.printStackTrace();
58 }
59 sHostPackage = hostPackage != null ? hostPackage : DEFAULT_CHROME_PACKAG E_NAME;
60 return sHostPackage;
61 }
62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698