|
40 | 40 | import android.os.Handler; |
41 | 41 | import android.os.IBinder; |
42 | 42 | import android.os.ParcelFileDescriptor; |
| 43 | +import android.os.ParcelableException; |
43 | 44 | import android.os.PowerManager; |
44 | 45 | import android.os.RemoteException; |
45 | 46 | import android.os.ServiceManager; |
@@ -403,29 +404,28 @@ private PackageInstallerSession createAndWriteApkSession( |
403 | 404 | } else { |
404 | 405 | params.installFlags |= PackageManager.INSTALL_DISABLE_VERIFICATION; |
405 | 406 | } |
406 | | - int apkSessionId = mPi.createSession( |
407 | | - params, originalSession.getInstallerPackageName(), |
408 | | - 0 /* UserHandle.SYSTEM */); |
409 | | - PackageInstallerSession apkSession = mPi.getSession(apkSessionId); |
410 | | - |
411 | 407 | try { |
| 408 | + int apkSessionId = mPi.createSession( |
| 409 | + params, originalSession.getInstallerPackageName(), |
| 410 | + 0 /* UserHandle.SYSTEM */); |
| 411 | + PackageInstallerSession apkSession = mPi.getSession(apkSessionId); |
412 | 412 | apkSession.open(); |
413 | 413 | for (String apkFilePath : apkFilePaths) { |
414 | 414 | File apkFile = new File(apkFilePath); |
415 | 415 | ParcelFileDescriptor pfd = ParcelFileDescriptor.open(apkFile, |
416 | 416 | ParcelFileDescriptor.MODE_READ_ONLY); |
417 | | - long sizeBytes = pfd.getStatSize(); |
| 417 | + long sizeBytes = (pfd == null) ? -1 : pfd.getStatSize(); |
418 | 418 | if (sizeBytes < 0) { |
419 | 419 | Slog.e(TAG, "Unable to get size of: " + apkFilePath); |
420 | 420 | return null; |
421 | 421 | } |
422 | 422 | apkSession.write(apkFile.getName(), 0, sizeBytes, pfd); |
423 | 423 | } |
424 | | - } catch (IOException e) { |
| 424 | + return apkSession; |
| 425 | + } catch (IOException | ParcelableException e) { |
425 | 426 | Slog.e(TAG, "Failure to install APK staged session " + originalSession.sessionId, e); |
426 | 427 | return null; |
427 | 428 | } |
428 | | - return apkSession; |
429 | 429 | } |
430 | 430 |
|
431 | 431 | private boolean commitApkSession(@NonNull PackageInstallerSession apkSession, |
|
0 commit comments