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

Unified Diff: shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java

Issue 782013002: Android: decouple mojo shell from the network service. (Closed) Base URL: https://github.com/domokit/mojo.git@build-rule-for-the-network-service
Patch Set: Rebase. Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java
diff --git a/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java b/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java
index 2503eb087476c5a510515aa22595e90e80c352c8..e2dbc61c3dadb64e5d06e868ba4755aa23b3c7b9 100644
--- a/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoMain.java
+++ b/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,52 @@ import java.util.List;
**/
@JNINamespace("mojo")
public class MojoMain {
+ private static final String TAG = "MojoMain";
+
+ // Directory where applications bundled with the shell will be extracted.
+ private static final String LOCAL_APP_DIRECTORY = "local_apps";
+ // Individual applications bundled with the shell as assets.
+ private static final String NETWORK_LIBRARY_APP = "network_service.mojo";
+
/**
* 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 +74,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);
}

Powered by Google App Engine
This is Rietveld 408576698