mirror of
https://github.com/encounter/SDL.git
synced 2025-12-08 13:15:10 +00:00
Fixed bug 4297 - Android StrictMode policy. Remove APK expansion support
"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".
This commit is contained in:
@@ -1221,76 +1221,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
}
|
||||
}
|
||||
|
||||
// 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. */
|
||||
|
||||
Reference in New Issue
Block a user