|
@@ -1,10 +1,13 @@
|
|
|
package org.libsdl.app;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
+import java.lang.reflect.Method;
|
|
|
|
|
|
import android.app.*;
|
|
|
import android.content.*;
|
|
@@ -20,7 +23,6 @@ import android.graphics.*;
|
|
|
import android.media.*;
|
|
|
import android.hardware.*;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
SDL Activity
|
|
|
*/
|
|
@@ -296,6 +298,7 @@ public class SDLActivity extends Activity {
|
|
|
int is_accelerometer, int nbuttons,
|
|
|
int naxes, int nhats, int nballs);
|
|
|
public static native int nativeRemoveJoystick(int device_id);
|
|
|
+ public static native String nativeGetHint(String name);
|
|
|
|
|
|
/**
|
|
|
* This method is called by SDL using JNI.
|
|
@@ -531,7 +534,52 @@ public class SDLActivity extends Activity {
|
|
|
mJoystickHandler.pollInputDevices();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ // APK extension files support
|
|
|
+
|
|
|
+ /** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */
|
|
|
+ private Object expansionFile;
|
|
|
+
|
|
|
+ /** com.android.vending.expansion.zipfile.ZipResourceFile's getInputStream() or null. */
|
|
|
+ private Method expansionFileMethod;
|
|
|
+
|
|
|
+ public InputStream openAPKExtensionInputStream(String fileName) throws IOException {
|
|
|
+ // Get a ZipResourceFile representing a merger of both the main and patch files
|
|
|
+ if (expansionFile == null) {
|
|
|
+ Integer mainVersion = Integer.parseInt(nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
|
|
|
+ Integer patchVersion = Integer.parseInt(nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"));
|
|
|
+
|
|
|
+ try {
|
|
|
+ // To avoid direct dependency on Google APK extension library that is
|
|
|
+ // not a part of Android SDK we access it using reflection
|
|
|
+ expansionFile = Class.forName("com.android.vending.expansion.zipfile.APKExpansionSupport")
|
|
|
+ .getMethod("getAPKExpansionZipFile", Context.class, int.class, int.class)
|
|
|
+ .invoke(null, this, mainVersion, patchVersion);
|
|
|
+
|
|
|
+ expansionFileMethod = expansionFile.getClass()
|
|
|
+ .getMethod("getInputStream", String.class);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ expansionFile = null;
|
|
|
+ expansionFileMethod = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get an input stream for a known file inside the expansion file ZIPs
|
|
|
+ InputStream fileStream;
|
|
|
+ try {
|
|
|
+ fileStream = (InputStream)expansionFileMethod.invoke(expansionFile, fileName);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ fileStream = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fileStream == null) {
|
|
|
+ throw new IOException();
|
|
|
+ }
|
|
|
+
|
|
|
+ return fileStream;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|