Handle ParcelableException instead of crashing system server
Unhandled exception is causing system server to crash. Bug: 146790672 Test: builds successfully Change-Id: Ibfe53ee0309dcec6fd3b24f8b67fcb78f5ce7fd5
This commit is contained in:
@@ -49,6 +49,7 @@ import android.os.IBinder;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.os.ParcelableException;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
@@ -570,18 +571,17 @@ public class StagingManager {
|
|||||||
} else {
|
} else {
|
||||||
params.installFlags |= PackageManager.INSTALL_DISABLE_VERIFICATION;
|
params.installFlags |= PackageManager.INSTALL_DISABLE_VERIFICATION;
|
||||||
}
|
}
|
||||||
int apkSessionId = mPi.createSession(
|
|
||||||
params, originalSession.getInstallerPackageName(),
|
|
||||||
0 /* UserHandle.SYSTEM */);
|
|
||||||
PackageInstallerSession apkSession = mPi.getSession(apkSessionId);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
int apkSessionId = mPi.createSession(
|
||||||
|
params, originalSession.getInstallerPackageName(),
|
||||||
|
0 /* UserHandle.SYSTEM */);
|
||||||
|
PackageInstallerSession apkSession = mPi.getSession(apkSessionId);
|
||||||
apkSession.open();
|
apkSession.open();
|
||||||
for (String apkFilePath : apkFilePaths) {
|
for (String apkFilePath : apkFilePaths) {
|
||||||
File apkFile = new File(apkFilePath);
|
File apkFile = new File(apkFilePath);
|
||||||
ParcelFileDescriptor pfd = ParcelFileDescriptor.open(apkFile,
|
ParcelFileDescriptor pfd = ParcelFileDescriptor.open(apkFile,
|
||||||
ParcelFileDescriptor.MODE_READ_ONLY);
|
ParcelFileDescriptor.MODE_READ_ONLY);
|
||||||
long sizeBytes = pfd.getStatSize();
|
long sizeBytes = (pfd == null) ? -1 : pfd.getStatSize();
|
||||||
if (sizeBytes < 0) {
|
if (sizeBytes < 0) {
|
||||||
Slog.e(TAG, "Unable to get size of: " + apkFilePath);
|
Slog.e(TAG, "Unable to get size of: " + apkFilePath);
|
||||||
throw new PackageManagerException(errorCode,
|
throw new PackageManagerException(errorCode,
|
||||||
@@ -589,11 +589,11 @@ public class StagingManager {
|
|||||||
}
|
}
|
||||||
apkSession.write(apkFile.getName(), 0, sizeBytes, pfd);
|
apkSession.write(apkFile.getName(), 0, sizeBytes, pfd);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
return apkSession;
|
||||||
|
} catch (IOException | ParcelableException e) {
|
||||||
Slog.e(TAG, "Failure to install APK staged session " + originalSession.sessionId, e);
|
Slog.e(TAG, "Failure to install APK staged session " + originalSession.sessionId, e);
|
||||||
throw new PackageManagerException(errorCode, "Failed to write APK session", e);
|
throw new PackageManagerException(errorCode, "Failed to create/write APK session", e);
|
||||||
}
|
}
|
||||||
return apkSession;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user