diff options
author | Narayan Kamath <narayan@google.com> | 2014-06-12 17:19:43 +0100 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2014-07-02 12:43:52 +0100 |
commit | cef0b39b9211882f59b6bfe1148e2cd247056693 (patch) | |
tree | 03394664c25a7981063b558a76936278f8f4ea4f /packages/DefaultContainerService | |
parent | 160a6e5b99de15ce755e2e5521dce32d81ab180a (diff) | |
download | frameworks_base-cef0b39b9211882f59b6bfe1148e2cd247056693.zip frameworks_base-cef0b39b9211882f59b6bfe1148e2cd247056693.tar.gz frameworks_base-cef0b39b9211882f59b6bfe1148e2cd247056693.tar.bz2 |
Fix native crashes when APKs can't be opened.
There was lax / incomplete error checking around the
construction of Apk handles. This change changes the ApkHandle
API and makes it throw IOException if the zipfile couldn't
be opened.
Additionally :
- Fix a resource leak in DefaultContainerService
- Report errors correctly during package moves.
bug: 15563874
(cherry picked from commit ec4516470d7ce6e47769591d678c838bd3f6f388)
Change-Id: Ia35b464355467d0d36faf34fae85acbbab3f2896
Diffstat (limited to 'packages/DefaultContainerService')
-rw-r--r-- | packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java index 52db30a..168fb41 100644 --- a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java +++ b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java @@ -50,6 +50,7 @@ import android.util.Slog; import com.android.internal.app.IMediaContainerService; import com.android.internal.content.NativeLibraryHelper; +import com.android.internal.content.NativeLibraryHelper.ApkHandle; import com.android.internal.content.PackageHelper; import java.io.BufferedInputStream; @@ -107,8 +108,27 @@ public class DefaultContainerService extends IntentService { return null; } - return copyResourceInner(packageURI, cid, key, resFileName, publicResFileName, - isExternal, isForwardLocked, abiOverride); + + if (isExternal) { + // Make sure the sdcard is mounted. + String status = Environment.getExternalStorageState(); + if (!status.equals(Environment.MEDIA_MOUNTED)) { + Slog.w(TAG, "Make sure sdcard is mounted."); + return null; + } + } + + ApkHandle handle = null; + try { + handle = ApkHandle.create(packageURI.getPath()); + return copyResourceInner(packageURI, cid, key, resFileName, publicResFileName, + isExternal, isForwardLocked, handle, abiOverride); + } catch (IOException ioe) { + Slog.w(TAG, "Problem opening APK: " + packageURI.getPath()); + return null; + } finally { + IoUtils.closeQuietly(handle); + } } /** @@ -329,21 +349,11 @@ public class DefaultContainerService extends IntentService { private String copyResourceInner(Uri packageURI, String newCid, String key, String resFileName, String publicResFileName, boolean isExternal, boolean isForwardLocked, - String abiOverride) { - - if (isExternal) { - // Make sure the sdcard is mounted. - String status = Environment.getExternalStorageState(); - if (!status.equals(Environment.MEDIA_MOUNTED)) { - Slog.w(TAG, "Make sure sdcard is mounted."); - return null; - } - } - + ApkHandle handle, String abiOverride) { // The .apk file String codePath = packageURI.getPath(); File codeFile = new File(codePath); - NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(codePath); + String[] abiList = Build.SUPPORTED_ABIS; if (abiOverride != null) { abiList = new String[] { abiOverride }; @@ -850,14 +860,14 @@ public class DefaultContainerService extends IntentService { private int calculateContainerSize(File apkFile, boolean forwardLocked, String abiOverride) throws IOException { - NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(apkFile); - final int abi = NativeLibraryHelper.findSupportedAbi(handle, - (abiOverride != null) ? new String[] { abiOverride } : Build.SUPPORTED_ABIS); - + ApkHandle handle = null; try { + handle = ApkHandle.create(apkFile); + final int abi = NativeLibraryHelper.findSupportedAbi(handle, + (abiOverride != null) ? new String[] { abiOverride } : Build.SUPPORTED_ABIS); return calculateContainerSize(handle, apkFile, abi, forwardLocked); } finally { - handle.close(); + IoUtils.closeQuietly(handle); } } |