| Index: webapk/shell_apk/src/org/chromium/webapk/shell_apk/WebApkApplication.java
|
| diff --git a/webapk/shell_apk/src/org/chromium/webapk/shell_apk/WebApkApplication.java b/webapk/shell_apk/src/org/chromium/webapk/shell_apk/WebApkApplication.java
|
| deleted file mode 100644
|
| index 2513b061f7021a3d074dc7fa7203a9b35c0b4d05..0000000000000000000000000000000000000000
|
| --- a/webapk/shell_apk/src/org/chromium/webapk/shell_apk/WebApkApplication.java
|
| +++ /dev/null
|
| @@ -1,155 +0,0 @@
|
| -// Copyright 2015 The Chromium Authors. All rights reserved.
|
| -// Use of this source code is governed by a BSD-style license that can be
|
| -// found in the LICENSE file.
|
| -
|
| -package org.chromium.webapk.shell_apk;
|
| -
|
| -import android.app.Application;
|
| -import android.content.Context;
|
| -import android.util.Log;
|
| -
|
| -import org.chromium.webapk.lib.common.WebApkUtils;
|
| -
|
| -import java.lang.reflect.Array;
|
| -import java.util.List;
|
| -
|
| -/**
|
| - * Example application for a minted APK.
|
| - */
|
| -public class WebApkApplication extends Application {
|
| - // Context of Chrome.
|
| - private Context mRemoteContext = null;
|
| -
|
| - private static final String TAG = "cr.WebApkApplication";
|
| - /**
|
| - * Copy all the objects from a specified field of the hostInstance to the same field of the
|
| - * mintInstance. As a result, the given field of the mintInstance will contain all the
|
| - * objects from both instances.
|
| - * @param mintInstance the first instance which contains a field of the given fieldName.
|
| - * @param fieldName the name of field to expand to an Object array.
|
| - * @param hostInstance the second instance which has a field of the given fieldName.
|
| - * @throws NoSuchFieldException
|
| - * @throws IllegalArgumentException
|
| - * @throws IllegalAccessException
|
| - */
|
| - private static void expandField(Object mintInstance, String fieldName, Object hostInstance)
|
| - throws NoSuchFieldException, IllegalArgumentException,
|
| - IllegalAccessException {
|
| - try {
|
| - Object hostCurrentDirs = Reflect.getField(hostInstance, fieldName);
|
| - Object mintCurrentDirs = Reflect.getField(mintInstance, fieldName);
|
| - // Switched from an array to an ArrayList in Lollipop.
|
| - if (mintCurrentDirs instanceof List) {
|
| - List<Object> mintDirsAsList = (List<Object>) mintCurrentDirs;
|
| - concatAndRemoveEndDuplicates(mintDirsAsList, (List<Object>) hostCurrentDirs);
|
| - } else {
|
| - Object[] mintDirsAsArray = (Object[]) mintCurrentDirs;
|
| - Object[] hostDirsAsArray = (Object[]) hostCurrentDirs;
|
| - Reflect.setField(mintInstance, fieldName,
|
| - concatAndRemoveEndDuplicates(mintDirsAsArray, hostDirsAsArray));
|
| - }
|
| - } catch (ReflectiveOperationException e) {
|
| - e.printStackTrace();
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Combines two arrays into a new array.
|
| - * If the two arrays end with duplicated elements, keep one copy only. For example,
|
| - * the first array is [A, B, C, D], and the second array is [E, F, C, D], the combined one is
|
| - * [A, B, E, F, C, D]. The unique elements are stored before the duplicates.
|
| - * The arrays must be of the same type.
|
| - * @param mintArrays: the array from a WebAPK
|
| - * @param hostArrays: the array from the host
|
| - * @return: a combined array consists of [WebAPK unique elements, host's unique elements,
|
| - * duplicated one]
|
| - */
|
| - private static Object[] concatAndRemoveEndDuplicates(Object[] mintArrays, Object[] hostArrays) {
|
| - int duplicate1 = mintArrays.length - 1;
|
| - int duplicate2 = hostArrays.length - 1;
|
| - int count = 0;
|
| - while (duplicate1 >= 0 && duplicate2 >= 0
|
| - && mintArrays[duplicate1].toString().equals(hostArrays[duplicate2].toString())) {
|
| - --duplicate1;
|
| - --duplicate2;
|
| - ++count;
|
| - }
|
| - Object[] combined = (Object[]) Array.newInstance(mintArrays.getClass().getComponentType(),
|
| - mintArrays.length + hostArrays.length - count);
|
| - if (mintArrays.length - count > 0) {
|
| - System.arraycopy(mintArrays, 0, combined, 0, mintArrays.length - count);
|
| - }
|
| - System.arraycopy(hostArrays, 0, combined, mintArrays.length - count, hostArrays.length);
|
| - return combined;
|
| - }
|
| -
|
| - /**
|
| - * Add the unique elements of the second list to the first one.
|
| - * If the two lists end with duplicated elements, keep one copy only. For example,
|
| - * the first list is [A, B, C, D], and the second list is [E, F, C, D], the combined one is
|
| - * [A, B, E, F, C, D]. The unique elements are store before the duplicates.
|
| - * The lists must be of the same type.
|
| - * @param mintList: the list from a WebAPK
|
| - * @param hostList: the list from the host
|
| - * @return: a combined list consists of [WebAPK unique elements, host's unique elements,
|
| - * duplicated one]
|
| - */
|
| - private static void concatAndRemoveEndDuplicates(List<Object> mintList, List<Object> hostList) {
|
| - int duplicate1 = mintList.size() - 1;
|
| - int duplicate2 = hostList.size() - 1;
|
| - while (duplicate1 >= 0 && duplicate2 >= 0
|
| - && mintList.get(duplicate1).toString().equals(hostList.get(duplicate2).toString()))
|
| - {
|
| - --duplicate1;
|
| - --duplicate2;
|
| - }
|
| - for (int i = 0; i < duplicate2 + 1; i++) {
|
| - mintList.add(duplicate1 + i, hostList.get(i));
|
| - }
|
| - }
|
| -
|
| - private void addExternalLoader() throws ReflectiveOperationException {
|
| - if (mRemoteContext == null) {
|
| - Log.w(TAG, "Failed to add external loader since the remote context is null.");
|
| - return;
|
| - }
|
| - ClassLoader externalLoader = mRemoteContext.getClassLoader();
|
| - ClassLoader mintLoader = getClassLoader();
|
| -
|
| - Object extDexPathList = Reflect.getField(externalLoader, "pathList");
|
| - Object mintDexPathList = Reflect.getField(mintLoader, "pathList");
|
| - expandField(mintDexPathList, "dexElements", extDexPathList);
|
| - }
|
| -
|
| - private void addNativeLibrarySearchPath() throws ReflectiveOperationException {
|
| - if (mRemoteContext == null) {
|
| - Log.w(TAG, "Failed to add external loader since the remote context is null.");
|
| - return;
|
| - }
|
| - ClassLoader externalLoader = mRemoteContext.getClassLoader();
|
| - ClassLoader mintLoader = getClassLoader();
|
| -
|
| - // Since both WebAPK and its host have the "system/lib" and "vendor/lib" at the end of
|
| - // the native library directory path list, we want to add host's directories before the
|
| - // system directory, and only keep one copy of the system directories.
|
| - // This is because when System.loadLibrary() is called, we want it search the host's
|
| - // native library directories first. If a ".so" file doesn't exit, then search /system/lib.
|
| - Object extDexPathList = Reflect.getField(externalLoader, "pathList");
|
| - Object mintDexPathList = Reflect.getField(mintLoader, "pathList");
|
| - expandField(mintDexPathList, "nativeLibraryDirectories", extDexPathList);
|
| - expandField(mintDexPathList, "nativeLibraryPathElements", extDexPathList);
|
| - }
|
| -
|
| - @Override
|
| - public void onCreate() {
|
| - super.onCreate();
|
| - mRemoteContext = WebApkUtils.getHostBrowserContext(this);
|
| - try {
|
| - addExternalLoader();
|
| - addNativeLibrarySearchPath();
|
| - } catch (ReflectiveOperationException e) {
|
| - e.printStackTrace();
|
| - }
|
| - Log.w(TAG, "Successfully add external loader.");
|
| - }
|
| -}
|
|
|