Skip to content

Commit 313a93d

Browse files
krutonAndroid (Google) Code Review
authored andcommitted
Merge "Close streams for forward-locked apps"
2 parents 011d778 + 3f99afc commit 313a93d

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

services/java/com/android/server/pm/PackageManagerService.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
import java.util.zip.ZipOutputStream;
142142

143143
import libcore.io.ErrnoException;
144+
import libcore.io.IoUtils;
144145
import libcore.io.Libcore;
145146

146147
/**
@@ -6946,9 +6947,8 @@ private int setPermissionsLI(PackageParser.Package newPackage) {
69466947
} catch (IOException e) {
69476948
Slog.e(TAG, "Couldn't create a new zip file for the public parts of a" +
69486949
" forward-locked app.");
6950+
destResourceFile.delete();
69496951
return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
6950-
} finally {
6951-
//TODO clean up the extracted public files
69526952
}
69536953
retCode = mInstaller.setForwardLockPerm(getApkName(newPackage.mPath),
69546954
newPackage.applicationInfo.uid);
@@ -6990,38 +6990,34 @@ private void extractPublicFiles(PackageParser.Package newPackage,
69906990
File publicZipFile) throws IOException {
69916991
final FileOutputStream fstr = new FileOutputStream(publicZipFile);
69926992
final ZipOutputStream publicZipOutStream = new ZipOutputStream(fstr);
6993-
final ZipFile privateZip = new ZipFile(newPackage.mPath);
6994-
6995-
// Copy manifest, resources.arsc and res directory to public zip
6993+
try {
6994+
final ZipFile privateZip = new ZipFile(newPackage.mPath);
6995+
try {
6996+
// Copy manifest, resources.arsc and res directory to public zip
69966997

6997-
final Enumeration<? extends ZipEntry> privateZipEntries = privateZip.entries();
6998-
while (privateZipEntries.hasMoreElements()) {
6999-
final ZipEntry zipEntry = privateZipEntries.nextElement();
7000-
final String zipEntryName = zipEntry.getName();
7001-
if ("AndroidManifest.xml".equals(zipEntryName)
7002-
|| "resources.arsc".equals(zipEntryName)
7003-
|| zipEntryName.startsWith("res/")) {
7004-
try {
7005-
copyZipEntry(zipEntry, privateZip, publicZipOutStream);
7006-
} catch (IOException e) {
7007-
try {
7008-
publicZipOutStream.close();
7009-
throw e;
7010-
} finally {
7011-
publicZipFile.delete();
6998+
final Enumeration<? extends ZipEntry> privateZipEntries = privateZip.entries();
6999+
while (privateZipEntries.hasMoreElements()) {
7000+
final ZipEntry zipEntry = privateZipEntries.nextElement();
7001+
final String zipEntryName = zipEntry.getName();
7002+
if ("AndroidManifest.xml".equals(zipEntryName)
7003+
|| "resources.arsc".equals(zipEntryName)
7004+
|| zipEntryName.startsWith("res/")) {
7005+
copyZipEntry(zipEntry, privateZip, publicZipOutStream);
70127006
}
70137007
}
7008+
} finally {
7009+
try { privateZip.close(); } catch (IOException e) { }
70147010
}
7015-
}
70167011

7017-
publicZipOutStream.finish();
7018-
publicZipOutStream.flush();
7019-
FileUtils.sync(fstr);
7020-
publicZipOutStream.close();
7021-
FileUtils.setPermissions(
7022-
publicZipFile.getAbsolutePath(),
7023-
FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP|FileUtils.S_IROTH,
7024-
-1, -1);
7012+
publicZipOutStream.finish();
7013+
publicZipOutStream.flush();
7014+
FileUtils.sync(fstr);
7015+
publicZipOutStream.close();
7016+
FileUtils.setPermissions(publicZipFile.getAbsolutePath(), FileUtils.S_IRUSR
7017+
| FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1);
7018+
} finally {
7019+
IoUtils.closeQuietly(publicZipOutStream);
7020+
}
70257021
}
70267022

70277023
private static void copyZipEntry(ZipEntry zipEntry,
@@ -7040,11 +7036,15 @@ private static void copyZipEntry(ZipEntry zipEntry,
70407036
}
70417037
outZipStream.putNextEntry(newEntry);
70427038

7043-
InputStream data = inZipFile.getInputStream(zipEntry);
7044-
while ((num = data.read(buffer)) > 0) {
7045-
outZipStream.write(buffer, 0, num);
7039+
final InputStream data = inZipFile.getInputStream(zipEntry);
7040+
try {
7041+
while ((num = data.read(buffer)) > 0) {
7042+
outZipStream.write(buffer, 0, num);
7043+
}
7044+
outZipStream.flush();
7045+
} finally {
7046+
IoUtils.closeQuietly(data);
70467047
}
7047-
outZipStream.flush();
70487048
}
70497049

70507050
private void deleteTempPackageFiles() {

0 commit comments

Comments
 (0)