aboutsummaryrefslogtreecommitdiffstats
path: root/support/android
diff options
context:
space:
mode:
authorPaul Rouget <me@paulrouget.com>2018-04-11 16:04:07 +0800
committerPaul Rouget <me@paulrouget.com>2018-04-27 15:34:52 +0800
commit9fb5795f3720bc090b221ed0850fb95b24704cb7 (patch)
tree02ae3fa1c77a85930dec490d57e1c907b287a562 /support/android
parent21517504cb95c969e8eb9f5e97273b98f9237a7d (diff)
downloadservo-9fb5795f3720bc090b221ed0850fb95b24704cb7.tar.gz
servo-9fb5795f3720bc090b221ed0850fb95b24704cb7.zip
delegate resource reading to embedder
Diffstat (limited to 'support/android')
-rw-r--r--support/android/apk/app/src/main/java/com/mozilla/servo/MainActivity.java77
1 files changed, 0 insertions, 77 deletions
diff --git a/support/android/apk/app/src/main/java/com/mozilla/servo/MainActivity.java b/support/android/apk/app/src/main/java/com/mozilla/servo/MainActivity.java
index 04c57511b3e..e2ca624bc08 100644
--- a/support/android/apk/app/src/main/java/com/mozilla/servo/MainActivity.java
+++ b/support/android/apk/app/src/main/java/com/mozilla/servo/MainActivity.java
@@ -52,12 +52,6 @@ public class MainActivity extends android.app.NativeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
- try {
- extractAssets();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
final Intent intent = getIntent();
if (intent != null && intent.getAction().equals(Intent.ACTION_VIEW)) {
final String url = intent.getDataString();
@@ -223,81 +217,10 @@ public class MainActivity extends android.app.NativeActivity {
}
}
- private boolean needsToExtractAssets(String path) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- int version = BuildConfig.VERSION_CODE;
-
- if (!new File(path).exists()) {
- // Assets folder doesn't exist, resources need to be copied
- prefs.edit().putInt(PREF_KEY_RESOURCES_SYNC, version).apply();
- return true;
- }
-
- if (version != prefs.getInt(PREF_KEY_RESOURCES_SYNC, -1)) {
- // Also force a reextract when the version changes and the resources may be updated
- // This can be improved by generating a hash or version number of the resources
- // instead of using version code of the app
- prefs.edit().putInt(PREF_KEY_RESOURCES_SYNC, version).apply();
- return true;
- }
- return false;
- }
-
private File getAppDataDir() {
File file = getExternalFilesDir(null);
return file != null ? file : getFilesDir();
}
- /**
- * extracts assets/ in the APK to /sdcard/servo.
- */
- private void extractAssets() throws IOException {
- String path = getAppDataDir().getAbsolutePath();
- if (!needsToExtractAssets(path)) {
- return;
- }
-
- ZipFile zipFile = null;
- File targetDir = new File(path);
- try {
- zipFile = new ZipFile(this.getApplicationInfo().sourceDir);
- for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); ) {
- ZipEntry entry = e.nextElement();
- if (entry.isDirectory() || !entry.getName().startsWith("assets/")) {
- continue;
- }
- File targetFile = new File(targetDir, entry.getName().substring("assets/".length()));
- targetFile.getParentFile().mkdirs();
- byte[] tempBuffer = new byte[(int)entry.getSize()];
- BufferedInputStream is = null;
- FileOutputStream os = null;
- try {
- is = new BufferedInputStream(zipFile.getInputStream(entry));
- os = new FileOutputStream(targetFile);
- is.read(tempBuffer);
- os.write(tempBuffer);
- } finally {
- try {
- if (is != null) {
- is.close();
- }
- if (os != null) {
- os.close();
- }
- } catch (Exception ex) {
- Log.e(LOGTAG, Log.getStackTraceString(ex));
- }
- }
- }
- } finally {
- try {
- if (zipFile != null) {
- zipFile.close();
- }
- } catch (Exception e) {
- Log.e(LOGTAG, Log.getStackTraceString(e));
- }
- }
- }
private void set_url(String url) {
try {