OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.minting; | 5 package org.chromium.minting; |
6 | 6 |
7 import android.app.Application; | 7 import android.app.Application; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.pm.PackageManager.NameNotFoundException; | 9 import android.content.pm.PackageManager.NameNotFoundException; |
10 import android.util.Log; | 10 import android.util.Log; |
11 | 11 |
| 12 import org.chromium.minting.lib.common.WebAPKUtils; |
| 13 |
12 import java.lang.reflect.Array; | 14 import java.lang.reflect.Array; |
13 import java.util.List; | 15 import java.util.List; |
14 | 16 |
15 /** | 17 /** |
16 * Example application for a minted APK. | 18 * Example application for a minted APK. |
17 */ | 19 */ |
18 public class MintingApplication extends Application { | 20 public class MintingApplication extends Application { |
19 static final String HOST_PACKAGE_PREF = "HOST_PACKAGE_PREF"; | |
20 static final String MINT_PREFS = "MINT_PREFS"; | |
21 static final String DEFAULT_CHROME_PACKAGE_NAME = "com.google.android.apps.c
hrome"; | |
22 | |
23 // Context of Chrome. | 21 // Context of Chrome. |
24 private Context mRemoteContext = null; | 22 private Context mRemoteContext = null; |
25 | 23 |
26 private static final String TAG = "cr.MintingApplication"; | 24 private static final String TAG = "cr.MintingApplication"; |
27 /** | 25 /** |
28 * Copy all the objects from a specified field of the hostInstance to the sa
me field of the | 26 * Copy all the objects from a specified field of the hostInstance to the sa
me field of the |
29 * mintInstance. As a result, the given field of the mintInstance will conta
in all the | 27 * mintInstance. As a result, the given field of the mintInstance will conta
in all the |
30 * objects from both instances. | 28 * objects from both instances. |
31 * @param mintInstance the first instance which contains a field of the give
n fieldName. | 29 * @param mintInstance the first instance which contains a field of the give
n fieldName. |
32 * @param fieldName the name of field to expand to an Object array. | 30 * @param fieldName the name of field to expand to an Object array. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // native library directories first. If a ".so" file doesn't exit, then
search /system/lib. | 137 // native library directories first. If a ".so" file doesn't exit, then
search /system/lib. |
140 Object extDexPathList = Reflect.getField(externalLoader, "pathList"); | 138 Object extDexPathList = Reflect.getField(externalLoader, "pathList"); |
141 Object mintDexPathList = Reflect.getField(mintLoader, "pathList"); | 139 Object mintDexPathList = Reflect.getField(mintLoader, "pathList"); |
142 expandField(mintDexPathList, "nativeLibraryDirectories", extDexPathList)
; | 140 expandField(mintDexPathList, "nativeLibraryDirectories", extDexPathList)
; |
143 expandField(mintDexPathList, "nativeLibraryPathElements", extDexPathList
); | 141 expandField(mintDexPathList, "nativeLibraryPathElements", extDexPathList
); |
144 } | 142 } |
145 | 143 |
146 @Override | 144 @Override |
147 public void onCreate() { | 145 public void onCreate() { |
148 super.onCreate(); | 146 super.onCreate(); |
| 147 mRemoteContext = WebAPKUtils.getHostBrowserContext(this); |
149 try { | 148 try { |
150 String packageString = getSharedPreferences(MINT_PREFS, MODE_PRIVATE
) | 149 addExternalLoader(); |
151 .getString(HOST_PACKAGE_PREF, DEFAULT_CHROME_PACKAGE_NAME); | 150 addNativeLibrarySearchPath(); |
152 Log.w(TAG, "Getting remote context for package " + packageString); | 151 } catch (ReflectiveOperationException e) { |
153 mRemoteContext = getApplicationContext().createPackageContext( | |
154 packageString, | |
155 Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CO
DE); | |
156 try { | |
157 addExternalLoader(); | |
158 addNativeLibrarySearchPath(); | |
159 } catch (ReflectiveOperationException e) { | |
160 e.printStackTrace(); | |
161 } | |
162 Log.w(TAG, "Successfully add external loader."); | |
163 } catch (NameNotFoundException e) { | |
164 e.printStackTrace(); | 152 e.printStackTrace(); |
165 } | 153 } |
| 154 Log.w(TAG, "Successfully add external loader."); |
166 } | 155 } |
167 } | 156 } |
OLD | NEW |