Skip to content

Commit

Permalink
Fixed bug 4297 - Android StrictMode policy. Remove APK expansion support
Browse files Browse the repository at this point in the history
"In the second half of 2021, new apps will be required to publish with the Android App Bundle on Google Play"
(see https://developer.android.com/guide/app-bundle)
And "Android App Bundles don't support APK expansion (*.obb) files".
  • Loading branch information
1bsyl committed Aug 17, 2020
1 parent 92cb919 commit 965b466
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 437 deletions.
70 changes: 0 additions & 70 deletions android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
Expand Up @@ -1221,76 +1221,6 @@ public static void initTouch() {
}
}

// APK expansion files support

/** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */
private static Object expansionFile;

/** com.android.vending.expansion.zipfile.ZipResourceFile's getInputStream() or null. */
private static Method expansionFileMethod;

/**
* This method is called by SDL using JNI.
* @return an InputStream on success or null if no expansion file was used.
* @throws IOException on errors. Message is set for the SDL error message.
*/
public static InputStream openAPKExpansionInputStream(String fileName) throws IOException {
// Get a ZipResourceFile representing a merger of both the main and patch files
if (expansionFile == null) {
String mainHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION");
if (mainHint == null) {
return null; // no expansion use if no main version was set
}
String patchHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION");
if (patchHint == null) {
return null; // no expansion use if no patch version was set
}

Integer mainVersion;
Integer patchVersion;
try {
mainVersion = Integer.valueOf(mainHint);
patchVersion = Integer.valueOf(patchHint);
} catch (NumberFormatException ex) {
ex.printStackTrace();
throw new IOException("No valid file versions set for APK expansion files", ex);
}

try {
// To avoid direct dependency on Google APK expansion 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, SDL.getContext(), mainVersion, patchVersion);

expansionFileMethod = expansionFile.getClass()
.getMethod("getInputStream", String.class);
} catch (Exception ex) {
ex.printStackTrace();
expansionFile = null;
expansionFileMethod = null;
throw new IOException("Could not access APK expansion support library", ex);
}
}

// 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) {
// calling "getInputStream" failed
ex.printStackTrace();
throw new IOException("Could not open stream from APK expansion file", ex);
}

if (fileStream == null) {
// calling "getInputStream" was successful but null was returned
throw new IOException("Could not find path in APK expansion file");
}

return fileStream;
}

// Messagebox

/** Result of current messagebox. Also used for blocking the calling thread. */
Expand Down
10 changes: 1 addition & 9 deletions include/SDL_rwops.h
Expand Up @@ -96,15 +96,7 @@ typedef struct SDL_RWops
#if defined(__ANDROID__)
struct
{
void *fileNameRef;
void *inputStreamRef;
void *readableByteChannelRef;
void *readMethod;
void *assetFileDescriptorRef;
long position;
long size;
long offset;
int fd;
void *asset;
} androidio;
#elif defined(__WIN32__)
struct
Expand Down

0 comments on commit 965b466

Please sign in to comment.