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

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

Issue 1965583002: Move //webapk to //chrome/android/webapk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 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";
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(
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
63 /**
64 * Returns name of "Runtime Dex" asset in Chrome APK based on version.
65 * @param version
66 * @return Dex asset name.
67 */
68 public static String getRuntimeDexName(int version) {
69 return "web_apk" + version + ".dex";
70 }
71 }
OLDNEW
« no previous file with comments | « webapk/libs/common/src/org/chromium/webapk/lib/common/WebApkConstants.java ('k') | webapk/libs/runtime_library/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698