Skip to content

Commit 67c89f3

Browse files
committed
Handle ParcelableException instead of crashing system server
Unhandled exception is causing system server to crash. Bug: 146790672 Test: builds successfully Change-Id: Ibfe53ee0309dcec6fd3b24f8b67fcb78f5ce7fd5 Merged-In: Ibfe53ee0309dcec6fd3b24f8b67fcb78f5ce7fd5
1 parent 0342ffa commit 67c89f3

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

services/core/java/com/android/server/pm/StagingManager.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import android.os.Handler;
4141
import android.os.IBinder;
4242
import android.os.ParcelFileDescriptor;
43+
import android.os.ParcelableException;
4344
import android.os.PowerManager;
4445
import android.os.RemoteException;
4546
import android.os.ServiceManager;
@@ -403,29 +404,28 @@ private PackageInstallerSession createAndWriteApkSession(
403404
} else {
404405
params.installFlags |= PackageManager.INSTALL_DISABLE_VERIFICATION;
405406
}
406-
int apkSessionId = mPi.createSession(
407-
params, originalSession.getInstallerPackageName(),
408-
0 /* UserHandle.SYSTEM */);
409-
PackageInstallerSession apkSession = mPi.getSession(apkSessionId);
410-
411407
try {
408+
int apkSessionId = mPi.createSession(
409+
params, originalSession.getInstallerPackageName(),
410+
0 /* UserHandle.SYSTEM */);
411+
PackageInstallerSession apkSession = mPi.getSession(apkSessionId);
412412
apkSession.open();
413413
for (String apkFilePath : apkFilePaths) {
414414
File apkFile = new File(apkFilePath);
415415
ParcelFileDescriptor pfd = ParcelFileDescriptor.open(apkFile,
416416
ParcelFileDescriptor.MODE_READ_ONLY);
417-
long sizeBytes = pfd.getStatSize();
417+
long sizeBytes = (pfd == null) ? -1 : pfd.getStatSize();
418418
if (sizeBytes < 0) {
419419
Slog.e(TAG, "Unable to get size of: " + apkFilePath);
420420
return null;
421421
}
422422
apkSession.write(apkFile.getName(), 0, sizeBytes, pfd);
423423
}
424-
} catch (IOException e) {
424+
return apkSession;
425+
} catch (IOException | ParcelableException e) {
425426
Slog.e(TAG, "Failure to install APK staged session " + originalSession.sessionId, e);
426427
return null;
427428
}
428-
return apkSession;
429429
}
430430

431431
private boolean commitApkSession(@NonNull PackageInstallerSession apkSession,

0 commit comments

Comments
 (0)