1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| private final Handler.Callback mHandlerCallback = new Handler.Callback() { @Override public boolean handleMessage(Message msg) { switch (msg.what) { case MSG_STREAM_VALIDATE_AND_COMMIT: handleStreamValidateAndCommit(); break; case MSG_INSTALL: handleInstall(); break; case MSG_ON_PACKAGE_INSTALLED: sendOnPackageInstalled(mContext, statusReceiver, ...); break; case MSG_SESSION_VERIFICATION_FAILURE: break; }
return true; } };
@Override public void commit(@NonNull IntentSender statusReceiver, boolean forTransfer) { dispatchStreamValidateAndCommit(); }
private void dispatchStreamValidateAndCommit() { mHandler.obtainMessage(MSG_STREAM_VALIDATE_AND_COMMIT).sendToTarget(); }
private void handleStreamValidateAndCommit() { boolean allSessionsReady = streamValidateAndCommit(); if (!allSessionsReady) { return; } mHandler.obtainMessage(MSG_INSTALL).sendToTarget(); }
private void handleInstall() { if (params.isStaged) { mStagingManager.commitSession(this); destroyInternal(); dispatchSessionFinished(PackageManager.INSTALL_SUCCEEDED, "Session staged", null); return; }
if (isApexInstallation()) { destroyInternal(); dispatchSessionFinished(PackageManager.INSTALL_FAILED_INTERNAL_ERROR, "APEX packages can only be installed using staged sessions.", null); return; }
List<PackageInstallerSession> childSessions = getChildSessionsNotLocked(); installNonStagedLocked(childSessions); }
private void installNonStagedLocked(List<PackageInstallerSession> childSessions) { final PackageManagerService.ActiveInstallSession installingSession = makeSessionActiveLocked(); if (isMultiPackage()) { } else { mPm.installStage(installingSession); } }
private PackageManagerService.ActiveInstallSession makeSessionActiveLocked(){ final IPackageInstallObserver2 localObserver; if (isApexInstallation()) { localObserver = null; } else { localObserver = new IPackageInstallObserver2.Stub() { @Override public void onUserActionRequired(Intent intent) { throw new IllegalStateException(); }
@Override public void onPackageInstalled(String basePackageName, int returnCode, String msg, Bundle extras) { destroyInternal(); dispatchSessionFinished(returnCode, msg, extras); } }; }
return new PackageManagerService.ActiveInstallSession(mPackageName, localObserver, ...); }
private void dispatchSessionFinished(int returnCode, String msg, Bundle extras) { final IntentSender statusReceiver; if (statusReceiver != null) { mHandler.obtainMessage(MSG_ON_PACKAGE_INSTALLED, args).sendToTarget(); }
final boolean success = (returnCode == PackageManager.INSTALL_SUCCEEDED);
final boolean isNewInstall = extras == null || !extras.getBoolean(Intent.EXTRA_REPLACING); if (success && isNewInstall && mPm.mInstallerService.okToSendBroadcasts() && (params.installFlags & PackageManager.INSTALL_DRY_RUN) == 0) { mPm.sendSessionCommitBroadcast(generateInfoScrubbed(true ), userId); } }
private static void sendOnPackageInstalled(Context context, IntentSender target, ...){ if (PackageManager.INSTALL_SUCCEEDED == returnCode && showNotification) { Notification notification = PackageInstallerService.buildSuccessNotification(context, ...); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(basePackageName, ..., notification); } else { final Intent fillIn = new Intent(); target.sendIntent(context, 0, fillIn, null, null); } }
|