0

I had working unzip code that uses ZipInputStream to unzip a large zip file from an InputStream. I have tested with some sample ZIP files on Android 5.1.1. I recently updated my development Galaxy S5 to Android 6.0.1. The same code is no longer working with the same test ZIP file. ZipInputStream.getNextEntry() is returning null on the first iteration.

Could something have changed with ZipInputStream in Android 5.1.1 vs Android 6.0.1? I cannot use ZipFile since I only have a stream as selected by the user via a Document/Content Provider.

Is there an alternative method for unzipping an InputStream? I cannot unzip from a [File] source, it must be a stream.

The code is similar to many standard snippets for unzipping:

public void unzip() {
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(mStream));
    try {
        String filename;
        ZipEntry ze;
        byte[] buffer = new byte[1024 * 8];
        int count;
        while ((ze = zis.getNextEntry()) != null) {
            filename = ze.getName();
            if (ze.isDirectory()) {
                File fmd = new File(mPath + filename);
                fmd.mkdirs();
                continue;
            }
            // openFile is a helper function that attempts to open a FileOutputStream with built in retry
            FileOutputStream fout = openFile(mPath + filename, 3, 100); 
            if (fout == null) {
                Log.e(TAG, "unzip::Failed to open file: " + mPath + filename);
                continue;
            }
            while ((count = zis.read(buffer)) != -1) {
                fout.write(buffer, 0, count);
            }
            fout.close();
            zis.closeEntry();
        }
    } catch (IOException ex) {
        Log.e(TAG, "UnzipFileTask", ex);
    } finally {
        try { zis.close(); } catch (IOException e) { }
    }
}

EDIT: Seems to have something to do with my SD card. Possibly the SD card encryption is causing issues with Android 6.0.1 on Samsung Galaxy S5. The unzip works with the ZIP file on internal storage (also encrypted).

EDIT 2: This has nothing to do with unzipping, it has everything to do with whether or not my SD card encryption is enabled. With SD card encryption off, everything works. Something is broken with Samsung's SD card encryption on Android 6.0.1 with Galaxy S5. I cannot copy files between device storage and the SD card with my app. The My Files app works though.

I am compiling against API 22, so I have not added the new runtime permissions and I understand I don't need them if my target is 22 or lower.

Greg
  • 51
  • 6
  • Android 6.0 uses, Runtime Permissions, https://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en – Htoo Aung Hlaing Mar 13 '17 at 07:54
  • Right, but I am compiling for API 22, so I thought I didn't need to use that feature yet? – Greg Mar 14 '17 at 19:06
  • Although you target to API 22, If device is Android 6.0 and above, you need to code for Runtime permissions – Htoo Aung Hlaing Mar 15 '17 at 07:19
  • Ok, I will work that and see if that gets me farther. Thing is - with SD card encryption OFF, everything works with no code changes. It only doesn't work when SD card encryption is ON. I assumed it was a Samsung encryption layer issue with how Android 6.0 handles SD cards and "external" storage. – Greg Mar 21 '17 at 14:33

0 Answers0