Android: Fixed trying to read from APK expansion files without version hint set.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Thu, 17 Sep 2015 22:30:24 +0200
changeset 98706dd5ab47534b
parent 9869 4ba43d626c4a
child 9871 381981a8adb6
Android: Fixed trying to read from APK expansion files without version hint set.

This also fixed overwriting the asset error message which is more useful if no
APK expansion files are available and the requested file was not found.
android-project/src/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Thu Sep 17 22:24:54 2015 +0200
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Thu Sep 17 22:30:24 2015 +0200
     1.3 @@ -688,12 +688,23 @@
     1.4  
     1.5      /**
     1.6       * This method is called by SDL using JNI.
     1.7 +     * @return an InputStream on success or null if no expansion file was used.
     1.8 +     * @throws IOException on errors. Message is set for the SDL error message.
     1.9       */
    1.10      public InputStream openAPKExpansionInputStream(String fileName) throws IOException {
    1.11          // Get a ZipResourceFile representing a merger of both the main and patch files
    1.12          if (expansionFile == null) {
    1.13 -            Integer mainVersion = Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
    1.14 -            Integer patchVersion = Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"));
    1.15 +            String mainHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION");
    1.16 +            if (mainHint == null) {
    1.17 +                return null; // no expansion use if no main version was set
    1.18 +            }
    1.19 +            String patchHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION");
    1.20 +            if (patchHint == null) {
    1.21 +                return null; // no expansion use if no patch version was set
    1.22 +            }
    1.23 +
    1.24 +            Integer mainVersion = Integer.valueOf(mainHint);
    1.25 +            Integer patchVersion = Integer.valueOf(patchHint);
    1.26  
    1.27              try {
    1.28                  // To avoid direct dependency on Google APK expansion library that is
     2.1 --- a/src/core/android/SDL_android.c	Thu Sep 17 22:24:54 2015 +0200
     2.2 +++ b/src/core/android/SDL_android.c	Thu Sep 17 22:30:24 2015 +0200
     2.3 @@ -790,7 +790,10 @@
     2.4                  "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
     2.5              inputStream = (*mEnv)->CallObjectMethod(mEnv, context, mid, fileNameJString);
     2.6  
     2.7 -            if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
     2.8 +            /* Exception is checked first because it always needs to be cleared.
     2.9 +             * If no exception occurred then the last SDL error message is kept.
    2.10 +             */
    2.11 +            if (Android_JNI_ExceptionOccurred(SDL_FALSE) || !inputStream) {
    2.12                  goto failure;
    2.13              }
    2.14          }