Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75c5b4bb authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[ADI][53/N] correct a user action condition check

Privileged installer means installers that have INSTALL_PACKAGES
permission, not privileged app. Fixing the condition check and also
clarifies it in the javadoc.

BUG: 360129657
FLAG: android.content.pm.verification_service
Test: manual

Change-Id: I2eacca74170c6497a958e3cdda113cf6945e569d
parent 31c4658f
Loading
Loading
Loading
Loading
+34 −13
Original line number Diff line number Diff line
@@ -450,10 +450,14 @@ public class PackageInstaller {
     * installation result returned via the {@link IntentSender} in
     * {@link Session#commit(IntentSender)}. However, along with this reason code, installers can
     * receive different status codes from {@link #EXTRA_STATUS} depending on their target SDK and
     * privileged status:
     * <p>
     *      Non-privileged installers targeting
     *      {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM API 35}
     * permission status:
     * <ul>
     * <li>
     *      Installers without the
     *      {@link android.Manifest.permission#INSTALL_PACKAGES INSTALL_PACKAGES} permission
     *      but with the
     *      {@link android.Manifest.permission#REQUEST_INSTALL_PACKAGES REQUEST_INSTALL_PACKAGES}
     *      permission and targeting {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM API 35}
     *      or less will first receive the
     *      {@link #STATUS_PENDING_USER_ACTION} status code without this reason code. They will be
     *      forced through the user action flow to allow the OS to inform the user of such
@@ -461,24 +465,41 @@ public class PackageInstaller {
     *      to bypass the verification result and chooses to do so, the installation will proceed.
     *      Otherwise, the installer will receive the {@link #STATUS_FAILURE_ABORTED} status code
     *      along with this reason code that explains why the verification had failed.
     * </p>
     * <p>
     *     Privileged installer targeting
     *     {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM API 35}
     * </li>
     * <li>
     *     Installers with the
     *     {@link android.Manifest.permission#INSTALL_PACKAGES INSTALL_PACKAGES} permission and
     *     targeting {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM API 35}
     *     or less will directly receive the
     *     {@link #STATUS_FAILURE_ABORTED} status code. This is because they are not expected to
     *     have the capability of handling the {@link #STATUS_PENDING_USER_ACTION} flow, so the
     *     installation will directly fail. This reason code will be supplied to them for
     *     providing additional information.
     * </p>
     * <p>
     *     All installers targeting {@link android.os.Build.VERSION_CODES#BAKLAVA API 36}
     *     or higher will receive a {@link #STATUS_FAILURE_ABORTED}
     * </li>
     * <li>
     *     For all installers targeting {@link android.os.Build.VERSION_CODES#BAKLAVA API 36}
     *     or higher:
     *     <ul>
     *     <li>For situations that require user input, such as when the developer verification
     *     policy allows the user to bypass a verification failure caused by network issues,
     *     the installer will receive a {@link #STATUS_PENDING_USER_ACTION} status code without
     *     this reason code. The installer will be forced through the user action flow to allow the
     *     OS to inform the user of such verification context before continuing to fail the
     *     installation. If the user has the option to bypass the verification result and chooses
     *     to do so, the installation will proceed. Otherwise, the install will receive the
     *     {@link #STATUS_FAILURE_ABORTED} status code along with this reason code that explains why
     *     the verification had failed.
     *     </li>
     *     <li>For all other situations, the installer will receive a
     *     {@link #STATUS_FAILURE_ABORTED}
     *     status code along with this reason code, so the installers can explain the failure to the
     *     user accordingly. An {@link Intent#EXTRA_INTENT} will also be populated with an intent
     *     that can provide additional context where appropriate, should the installer prefer to
     *     defer to the OS to explain the failure to the user.
     * </p>
     *     </li>
     *     </ul>
     * </li>
     * </ul>
     */
    @FlaggedApi(Flags.FLAG_VERIFICATION_SERVICE)
    public static final String EXTRA_DEVELOPER_VERIFICATION_FAILURE_REASON =
+14 −6
Original line number Diff line number Diff line
@@ -3508,9 +3508,12 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        /**
         * User will be notified about a failed or incomplete developer verification in the
         * following scenarios:
         * 1. The installer is the system package installer.
         * 2. If it's a non-blocking failure and the installer targets Baklava or above.
         * 3. If the installer targets less than Baklava and the installer is not a privileged app.
         * <ul>
         * <li>The installer is the system package installer.</li>
         * <li>If it's a non-blocking failure and the installer targets Baklava or above.</li>
         * <li>If the installer targets less than Baklava and the installer does not have </li>
         * {@link android.Manifest.permission#INSTALL_PACKAGES INSTALL_PACKAGES} permission.
         * </ul>
         * For other cases, the installer will receive a failure status code in its IntentSender
         */
        private boolean shouldSendUserActionForVerification(boolean blockingFailure) {
@@ -3536,11 +3539,16 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                return true;
            }

            if (CompatChanges.isChangeEnabled(NOTIFY_USER_VERIFICATION_INCOMPLETE,
                    getInstallerUid())) {
            final int installerUid = getInstallerUid();
            if (CompatChanges.isChangeEnabled(NOTIFY_USER_VERIFICATION_INCOMPLETE, installerUid)) {
                // Target SDK of the installer >= 36, non blocking failures can be bypassed upon
                // user confirmation.
                return !blockingFailure;
            } else {
                return !installerInfo.isPrivilegedApp();
                // Target SDK of the installer <= 35. Installers that do not have the
                // privileged installation permission will need to request for user action.
                return PackageManager.PERMISSION_GRANTED != snapshot.checkUidPermission(
                        Manifest.permission.INSTALL_PACKAGES, installerUid);
            }
        }