Skip to content

Commit c2e9ac8

Browse files
author
Kim Rinnewitz
committed
Fix SDL File Handling
While updating the SDL2 recipe to version 2.0.4 in PR #713, the SDLActivity was not updated accordingly. SDL 2.0.4 expects the Activity to have a method called "openAPKExpansionInputStream" while this method was called "openAPKExtensionInputStream" in older versions. SDL2 is not able to read files when the method is missing.
1 parent 0ac1013 commit c2e9ac8

File tree

1 file changed

+37
-7
lines changed
  • pythonforandroid/bootstraps/sdl2/build/src/main/java/org/libsdl/app

1 file changed

+37
-7
lines changed

pythonforandroid/bootstraps/sdl2/build/src/main/java/org/libsdl/app/SDLActivity.java

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ public static void pollInputDevices() {
671671
public void keepActive() {
672672
}
673673

674-
// APK extension files support
674+
// APK expansion files support
675675

676676
/** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */
677677
private Object expansionFile;
@@ -680,16 +680,43 @@ public void keepActive() {
680680
private Method expansionFileMethod;
681681

682682
/**
683-
* This method is called by SDL using JNI.
683+
* This method was called by SDL using JNI.
684+
* @deprecated because of an incorrect name
684685
*/
686+
@Deprecated
685687
public InputStream openAPKExtensionInputStream(String fileName) throws IOException {
688+
return openAPKExpansionInputStream(fileName);
689+
}
690+
691+
/**
692+
* This method is called by SDL using JNI.
693+
* @return an InputStream on success or null if no expansion file was used.
694+
* @throws IOException on errors. Message is set for the SDL error message.
695+
*/
696+
public InputStream openAPKExpansionInputStream(String fileName) throws IOException {
686697
// Get a ZipResourceFile representing a merger of both the main and patch files
687698
if (expansionFile == null) {
688-
Integer mainVersion = Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
689-
Integer patchVersion = Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"));
699+
String mainHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION");
700+
if (mainHint == null) {
701+
return null; // no expansion use if no main version was set
702+
}
703+
String patchHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION");
704+
if (patchHint == null) {
705+
return null; // no expansion use if no patch version was set
706+
}
707+
708+
Integer mainVersion;
709+
Integer patchVersion;
710+
try {
711+
mainVersion = Integer.valueOf(mainHint);
712+
patchVersion = Integer.valueOf(patchHint);
713+
} catch (NumberFormatException ex) {
714+
ex.printStackTrace();
715+
throw new IOException("No valid file versions set for APK expansion files", ex);
716+
}
690717

691718
try {
692-
// To avoid direct dependency on Google APK extension library that is
719+
// To avoid direct dependency on Google APK expansion library that is
693720
// not a part of Android SDK we access it using reflection
694721
expansionFile = Class.forName("com.android.vending.expansion.zipfile.APKExpansionSupport")
695722
.getMethod("getAPKExpansionZipFile", Context.class, int.class, int.class)
@@ -701,6 +728,7 @@ public InputStream openAPKExtensionInputStream(String fileName) throws IOExcepti
701728
ex.printStackTrace();
702729
expansionFile = null;
703730
expansionFileMethod = null;
731+
throw new IOException("Could not access APK expansion support library", ex);
704732
}
705733
}
706734

@@ -709,12 +737,14 @@ public InputStream openAPKExtensionInputStream(String fileName) throws IOExcepti
709737
try {
710738
fileStream = (InputStream)expansionFileMethod.invoke(expansionFile, fileName);
711739
} catch (Exception ex) {
740+
// calling "getInputStream" failed
712741
ex.printStackTrace();
713-
fileStream = null;
742+
throw new IOException("Could not open stream from APK expansion file", ex);
714743
}
715744

716745
if (fileStream == null) {
717-
throw new IOException();
746+
// calling "getInputStream" was successful but null was returned
747+
throw new IOException("Could not find path in APK expansion file");
718748
}
719749

720750
return fileStream;

0 commit comments

Comments
 (0)