@@ -671,7 +671,7 @@ public static void pollInputDevices() {
671
671
public void keepActive () {
672
672
}
673
673
674
- // APK extension files support
674
+ // APK expansion files support
675
675
676
676
/** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */
677
677
private Object expansionFile ;
@@ -680,16 +680,43 @@ public void keepActive() {
680
680
private Method expansionFileMethod ;
681
681
682
682
/**
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
684
685
*/
686
+ @ Deprecated
685
687
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 {
686
697
// Get a ZipResourceFile representing a merger of both the main and patch files
687
698
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
+ }
690
717
691
718
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
693
720
// not a part of Android SDK we access it using reflection
694
721
expansionFile = Class .forName ("com.android.vending.expansion.zipfile.APKExpansionSupport" )
695
722
.getMethod ("getAPKExpansionZipFile" , Context .class , int .class , int .class )
@@ -701,6 +728,7 @@ public InputStream openAPKExtensionInputStream(String fileName) throws IOExcepti
701
728
ex .printStackTrace ();
702
729
expansionFile = null ;
703
730
expansionFileMethod = null ;
731
+ throw new IOException ("Could not access APK expansion support library" , ex );
704
732
}
705
733
}
706
734
@@ -709,12 +737,14 @@ public InputStream openAPKExtensionInputStream(String fileName) throws IOExcepti
709
737
try {
710
738
fileStream = (InputStream )expansionFileMethod .invoke (expansionFile , fileName );
711
739
} catch (Exception ex ) {
740
+ // calling "getInputStream" failed
712
741
ex .printStackTrace ();
713
- fileStream = null ;
742
+ throw new IOException ( "Could not open stream from APK expansion file" , ex ) ;
714
743
}
715
744
716
745
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" );
718
748
}
719
749
720
750
return fileStream ;
0 commit comments