Chromium Code Reviews| Index: mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java |
| diff --git a/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java b/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java |
| index 2503eb087476c5a510515aa22595e90e80c352c8..a6bb0d3d786f35de01095794c72eace6a3efc0cb 100644 |
| --- a/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java |
| +++ b/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java |
| @@ -5,9 +5,11 @@ |
| package org.chromium.mojo_shell_apk; |
| import android.content.Context; |
| +import android.util.Log; |
| import org.chromium.base.JNINamespace; |
| +import java.io.File; |
| import java.util.ArrayList; |
| import java.util.Arrays; |
| import java.util.List; |
| @@ -17,25 +19,50 @@ import java.util.List; |
| **/ |
| @JNINamespace("mojo") |
| public class MojoMain { |
| + private static final String TAG = "MojoMain"; |
| + |
| + private static final String LOCAL_APP_DIRECTORY = "local_apps"; |
| + private static final String NETWORK_LIBRARY_APP = "network_service.mojo"; |
|
qsr
2014/12/05 17:02:58
Can you comment on those?
ppi
2014/12/10 16:21:00
Done.
|
| + |
| /** |
| * A guard flag for calling nativeInit() only once. |
| **/ |
| private static boolean sInitialized = false; |
| /** |
| + * Deletes directories holding the temporary files. This should be called early on shell startup |
| + * to clean up after the previous run. |
| + */ |
| + static void clearTemporaryFiles(Context context) { |
| + FileHelper.deleteRecursively(getLocalAppsDir(context)); |
| + } |
| + |
| + /** |
| * Initializes the native system. |
| **/ |
| static void ensureInitialized(Context applicationContext, String[] parameters) { |
| if (sInitialized) |
| return; |
| - List<String> parametersList = new ArrayList<String>(); |
| - // Program name. |
| - parametersList.add("mojo_shell"); |
| - if (parameters != null) { |
| - parametersList.addAll(Arrays.asList(parameters)); |
| + |
| + try { |
| + FileHelper.extractFromAssets(applicationContext, NETWORK_LIBRARY_APP, |
| + getLocalAppsDir(applicationContext), false); |
| + |
| + List<String> parametersList = new ArrayList<String>(); |
| + // Program name. |
| + parametersList.add("mojo_shell"); |
| + if (parameters != null) { |
| + parametersList.addAll(Arrays.asList(parameters)); |
| + } |
| + |
| + nativeInit(applicationContext, |
| + parametersList.toArray(new String[parametersList.size()]), |
| + getLocalAppsDir(applicationContext).getAbsolutePath()); |
| + sInitialized = true; |
| + } catch (Exception e) { |
| + Log.e(TAG, "MojoMain initialization failed.", e); |
| + throw new RuntimeException(e); |
| } |
| - nativeInit(applicationContext, parametersList.toArray(new String[parametersList.size()])); |
| - sInitialized = true; |
| } |
| /** |
| @@ -45,10 +72,15 @@ public class MojoMain { |
| nativeStart(appUrl); |
| } |
| + private static File getLocalAppsDir(Context context) { |
| + return context.getDir(LOCAL_APP_DIRECTORY, Context.MODE_PRIVATE); |
| + } |
| + |
| /** |
| * Initializes the native system. This API should be called only once per process. |
| **/ |
| - private static native void nativeInit(Context context, String[] parameters); |
| + private static native void nativeInit(Context context, String[] parameters, |
| + String bundledAppsDirectory); |
| private static native void nativeStart(String appUrl); |
| } |