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

Commit c837a52a authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[ADI][47/N] remove retry mechanism

Removing retry as it was creating complicated UX scenarios.

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

Change-Id: I63cfa4647d096bc8883dc807ca4dc6a61c6620f7
parent 9c6d8a77
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -955,6 +955,7 @@ public class PackageInstaller {
    public static final int DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT = 1;
    /**
     * For an incomplete developer verification, the user has asked to retry the verification.
     * Notice that this is currently not supported.
     * @hide
     */
    @FlaggedApi(Flags.FLAG_VERIFICATION_SERVICE)
+0 −2
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@
    <!-- [CHAR LIMIT=15] -->
    <string name="cancel">Cancel</string>
    <!-- [CHAR LIMIT=15] -->
    <string name="try_again">Try again</string>
    <!-- [CHAR LIMIT=15] -->
    <string name="install_anyway">Install anyway</string>
    <!-- [CHAR LIMIT=15] -->
    <string name="dont_install">Don\'t install</string>
+19 −66
Original line number Diff line number Diff line
@@ -16,19 +16,17 @@

package com.android.packageinstaller;

import static android.content.pm.PackageInstaller.EXTRA_SESSION_ID;
import static android.content.pm.PackageInstaller.SessionInfo;
import static android.content.pm.PackageInstaller.SessionInfo.INVALID_ID;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_WARN;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_ERROR;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_INSTALL_ANYWAY;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_RETRY;
import static android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo.DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_DEVELOPER_BLOCKED;
import static android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo.DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_LITE_VERIFICATION;
import static android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo.DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_NETWORK_UNAVAILABLE;
import static android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo.DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_DEVELOPER_BLOCKED;
import static android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo.DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_UNKNOWN;
import static android.content.pm.PackageInstaller.EXTRA_SESSION_ID;
import static android.content.pm.PackageInstaller.SessionInfo;
import static android.content.pm.PackageInstaller.SessionInfo.INVALID_ID;

import static com.android.packageinstaller.PackageUtil.AppSnippet;

@@ -53,10 +51,6 @@ import java.io.File;
public class ConfirmDeveloperVerification extends Activity {

    private static final String TAG = ConfirmDeveloperVerification.class.getSimpleName();
    public static final int FLAG_VERIFICATION_FAILED_MAY_RETRY = 1 << 0;
    public static final int FLAG_VERIFICATION_FAILED_MAY_BYPASS = 1 << 1;
    public static final int FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS =
            FLAG_VERIFICATION_FAILED_MAY_RETRY | FLAG_VERIFICATION_FAILED_MAY_BYPASS;

    private final boolean mLocalLOGV = false;
    private PackageManager mPackageManager;
@@ -110,7 +104,7 @@ public class ConfirmDeveloperVerification extends Activity {
            return;
        }

        int dialogTypeFlag = getUserConfirmationDialogFlag(verificationInfo);
        boolean isBypassAllowed = isBypassAllowed(verificationInfo);
        int userActionNeededReason = verificationInfo.getUserActionNeededReason();
        int msgResId = getDialogMessageResourceId(userActionNeededReason);

@@ -119,35 +113,9 @@ public class ConfirmDeveloperVerification extends Activity {
                .setTitle(mAppSnippet.label)
                .setMessage(msgResId);

        if ((dialogTypeFlag & FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS)
                == FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS) {
            // allow retry and bypass
            builder.setPositiveButton(R.string.try_again, (dialog, which) -> {
                mPackageInstaller.setDeveloperVerificationUserResponse(sessionId,
                        DEVELOPER_VERIFICATION_USER_RESPONSE_RETRY);
                finish();
            }).setNegativeButton(R.string.dont_install, (dialog, which) -> {
                mPackageInstaller.setDeveloperVerificationUserResponse(sessionId,
                        DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT);
                finish();
            }).setNeutralButton(R.string.install_anyway, (dialog, which) -> {
                mPackageInstaller.setDeveloperVerificationUserResponse(sessionId,
                        DEVELOPER_VERIFICATION_USER_RESPONSE_INSTALL_ANYWAY);
                finish();
            });
        } else if ((dialogTypeFlag & FLAG_VERIFICATION_FAILED_MAY_RETRY) != 0) {
            // only allow retry
            builder.setPositiveButton(R.string.ok, (dialog, which) -> {
                mPackageInstaller.setDeveloperVerificationUserResponse(sessionId,
                        PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT);
                finish();
            }).setNegativeButton(R.string.try_again, (dialog, which) -> {
                mPackageInstaller.setDeveloperVerificationUserResponse(sessionId,
                        DEVELOPER_VERIFICATION_USER_RESPONSE_RETRY);
                finish();
            });
        } else if ((dialogTypeFlag & FLAG_VERIFICATION_FAILED_MAY_BYPASS) != 0) {
            // only allow bypass

        if (isBypassAllowed) {
            // allow bypass
            builder.setPositiveButton(R.string.dont_install, (dialog, which) -> {
                mPackageInstaller.setDeveloperVerificationUserResponse(sessionId,
                        DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT);
@@ -204,41 +172,26 @@ public class ConfirmDeveloperVerification extends Activity {
    }

    /**
     * Returns the correct type of dialog based on the verification policy and the reason for user
     * action.
     * Returns whether the user can choose to bypass the verification result and force installation,
     * based on the verification policy and the reason for user action.
     */
    public static int getUserConfirmationDialogFlag(
    public static boolean isBypassAllowed(
            PackageInstaller.DeveloperVerificationUserConfirmationInfo verificationInfo) {
        int userActionNeededReason = verificationInfo.getUserActionNeededReason();
        int verificationPolicy = verificationInfo.getVerificationPolicy();

        return switch (userActionNeededReason) {
            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_DEVELOPER_BLOCKED -> 0;
            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_DEVELOPER_BLOCKED -> false;

            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_NETWORK_UNAVAILABLE -> {
                int flag = FLAG_VERIFICATION_FAILED_MAY_RETRY;
                if (verificationPolicy == DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN
                        || verificationPolicy == DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_WARN) {
                    flag |= FLAG_VERIFICATION_FAILED_MAY_BYPASS;
                }
                yield flag;
            }

            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_UNKNOWN -> {
                int flag = 0;
                if (verificationPolicy == DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN
                        || verificationPolicy == DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_WARN) {
                    flag |= FLAG_VERIFICATION_FAILED_MAY_BYPASS;
                }
                yield flag;
            }

            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_LITE_VERIFICATION ->
                    FLAG_VERIFICATION_FAILED_MAY_BYPASS;
            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_NETWORK_UNAVAILABLE,
                 DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_UNKNOWN,
                 DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_LITE_VERIFICATION ->
                // Only disallow bypass if policy is closed.
                verificationPolicy != DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED;

            default -> {
                Log.e(TAG, "Unknown user action needed reason: " + userActionNeededReason);
                yield 0;
                yield false;
            }
        };
    }
+15 −55
Original line number Diff line number Diff line
@@ -16,24 +16,19 @@

package com.android.packageinstaller.v2.ui.fragments;

import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_WARN;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_INSTALL_ANYWAY;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_USER_RESPONSE_RETRY;
import static android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo.DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_DEVELOPER_BLOCKED;
import static android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo.DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_LITE_VERIFICATION;
import static android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo.DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_NETWORK_UNAVAILABLE;
import static android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo.DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_UNKNOWN;

import static com.android.packageinstaller.ConfirmDeveloperVerification.FLAG_VERIFICATION_FAILED_MAY_BYPASS;
import static com.android.packageinstaller.ConfirmDeveloperVerification.FLAG_VERIFICATION_FAILED_MAY_RETRY;
import static com.android.packageinstaller.ConfirmDeveloperVerification.FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo;
import android.os.Bundle;
import android.util.Log;
@@ -79,7 +74,7 @@ public class DeveloperVerificationConfirmationFragment extends DialogFragment {
        DeveloperVerificationUserConfirmationInfo verificationInfo =
                mDialogData.getVerificationInfo();
        assert verificationInfo != null;
        int dialogTypeFlag = getUserConfirmationDialogFlag(verificationInfo);
        boolean isBypassAllowed = isBypassAllowed(verificationInfo);
        int userActionNeededReasonReason = verificationInfo.getUserActionNeededReason();
        int msgResId = getDialogMessageResourceId(userActionNeededReasonReason);

@@ -88,27 +83,7 @@ public class DeveloperVerificationConfirmationFragment extends DialogFragment {
                .setTitle(mDialogData.getAppLabel())
                .setMessage(msgResId);

        if ((dialogTypeFlag & FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS)
                == FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS) {
            // allow retry and bypass
            builder.setPositiveButton(R.string.try_again,
                            (dialog, which) -> mInstallActionListener.setVerificationUserResponse(
                                    DEVELOPER_VERIFICATION_USER_RESPONSE_RETRY))
                    .setNegativeButton(R.string.dont_install,
                            (dialog, which) -> mInstallActionListener.setVerificationUserResponse(
                                    DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT))
                    .setNeutralButton(R.string.install_anyway,
                            (dialog, which) -> mInstallActionListener.setVerificationUserResponse(
                                    DEVELOPER_VERIFICATION_USER_RESPONSE_INSTALL_ANYWAY));
        } else if ((dialogTypeFlag & FLAG_VERIFICATION_FAILED_MAY_RETRY) != 0) {
            // only allow retry
            builder.setPositiveButton(R.string.ok,
                            (dialog, which) -> mInstallActionListener.setVerificationUserResponse(
                                    DEVELOPER_VERIFICATION_USER_RESPONSE_ABORT))
                    .setNegativeButton(R.string.try_again,
                            (dialog, which) -> mInstallActionListener.setVerificationUserResponse(
                                    DEVELOPER_VERIFICATION_USER_RESPONSE_RETRY));
        } else if ((dialogTypeFlag & FLAG_VERIFICATION_FAILED_MAY_BYPASS) != 0) {
        if (isBypassAllowed) {
            // only allow bypass
            builder.setPositiveButton(R.string.dont_install,
                            (dialog, which) -> mInstallActionListener.setVerificationUserResponse(
@@ -166,41 +141,26 @@ public class DeveloperVerificationConfirmationFragment extends DialogFragment {
    }

    /**
     * Returns the correct type of dialog based on the verification policy and the reason for user
     * action
     * Returns whether the user can choose to bypass the verification result and force installation,
     * based on the verification policy and the reason for user action.
     */
    private int getUserConfirmationDialogFlag(
            DeveloperVerificationUserConfirmationInfo verificationInfo) {
    private static boolean isBypassAllowed(
            PackageInstaller.DeveloperVerificationUserConfirmationInfo verificationInfo) {
        int userActionNeededReason = verificationInfo.getUserActionNeededReason();
        int verificationPolicy = verificationInfo.getVerificationPolicy();

        return switch (userActionNeededReason) {
            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_DEVELOPER_BLOCKED -> 0;

            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_NETWORK_UNAVAILABLE -> {
                int flag = FLAG_VERIFICATION_FAILED_MAY_RETRY;
                if (verificationPolicy == DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN
                        || verificationPolicy == DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_WARN) {
                    flag |= FLAG_VERIFICATION_FAILED_MAY_BYPASS;
                }
                yield flag;
            }
            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_DEVELOPER_BLOCKED -> false;

            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_UNKNOWN -> {
                int flag = 0;
                if (verificationPolicy == DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN
                        || verificationPolicy == DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_WARN) {
                    flag |= FLAG_VERIFICATION_FAILED_MAY_BYPASS;
                }
                yield flag;
            }

            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_LITE_VERIFICATION ->
                    FLAG_VERIFICATION_FAILED_MAY_BYPASS;
            case DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_NETWORK_UNAVAILABLE,
                 DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_UNKNOWN,
                 DEVELOPER_VERIFICATION_USER_ACTION_NEEDED_REASON_LITE_VERIFICATION ->
                    // Only disallow bypass if policy is closed.
                    verificationPolicy != DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED;

            default -> {
                Log.e(LOG_TAG, "Unknown user action needed reason: " + userActionNeededReason);
                yield 0;
                yield false;
            }
        };
    }
+15 −19
Original line number Diff line number Diff line
@@ -16,16 +16,12 @@

package com.android.packageinstaller.test;

import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_FAILED_REASON_NETWORK_UNAVAILABLE;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_FAILED_REASON_DEVELOPER_BLOCKED;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_FAILED_REASON_NETWORK_UNAVAILABLE;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_FAILED_REASON_UNKNOWN;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED;
import static android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN;

import static com.android.packageinstaller.ConfirmDeveloperVerification.FLAG_VERIFICATION_FAILED_MAY_BYPASS;
import static com.android.packageinstaller.ConfirmDeveloperVerification.FLAG_VERIFICATION_FAILED_MAY_RETRY;
import static com.android.packageinstaller.ConfirmDeveloperVerification.FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS;

import static com.google.common.truth.Truth.assertThat;

import android.content.pm.PackageInstaller.DeveloperVerificationUserConfirmationInfo;
@@ -41,61 +37,61 @@ public class VerificationConfirmationDialogTest {

    @Test
    public void policyOpen_packageBlocked_onlyAck() {
        int flag = ConfirmDeveloperVerification.getUserConfirmationDialogFlag(
        boolean isBypassAllowed = ConfirmDeveloperVerification.isBypassAllowed(
                new DeveloperVerificationUserConfirmationInfo(
                        DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN,
                        DEVELOPER_VERIFICATION_FAILED_REASON_DEVELOPER_BLOCKED));

        assertThat(flag).isEqualTo(0);
        assertThat(isBypassAllowed).isFalse();
    }

    @Test
    public void policyOpen_noNetwork_mayRetryMayBypass() {
        int flag = ConfirmDeveloperVerification.getUserConfirmationDialogFlag(
    public void policyOpen_noNetwork_mayBypass() {
        boolean isBypassAllowed = ConfirmDeveloperVerification.isBypassAllowed(
                new DeveloperVerificationUserConfirmationInfo(
                        DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN,
                        DEVELOPER_VERIFICATION_FAILED_REASON_NETWORK_UNAVAILABLE));

        assertThat(flag).isEqualTo(FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS);
        assertThat(isBypassAllowed).isTrue();
    }

    @Test
    public void policyOpen_unknown_mayBypass() {
        int flag = ConfirmDeveloperVerification.getUserConfirmationDialogFlag(
        boolean isBypassAllowed = ConfirmDeveloperVerification.isBypassAllowed(
                new DeveloperVerificationUserConfirmationInfo(
                        DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN,
                        DEVELOPER_VERIFICATION_FAILED_REASON_UNKNOWN));

        assertThat(flag).isEqualTo(FLAG_VERIFICATION_FAILED_MAY_BYPASS);
        assertThat(isBypassAllowed).isTrue();
    }

    @Test
    public void policyClosed_packageBlocked_onlyAck() {
        int flag = ConfirmDeveloperVerification.getUserConfirmationDialogFlag(
        boolean isBypassAllowed = ConfirmDeveloperVerification.isBypassAllowed(
                new DeveloperVerificationUserConfirmationInfo(
                        DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED,
                        DEVELOPER_VERIFICATION_FAILED_REASON_DEVELOPER_BLOCKED));

        assertThat(flag).isEqualTo(0);
        assertThat(isBypassAllowed).isFalse();
    }

    @Test
    public void policyClosed_noNetwork_mayRetry() {
        int flag = ConfirmDeveloperVerification.getUserConfirmationDialogFlag(
    public void policyClosed_noNetwork_onlyAck() {
        boolean isBypassAllowed = ConfirmDeveloperVerification.isBypassAllowed(
                new DeveloperVerificationUserConfirmationInfo(
                        DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED,
                        DEVELOPER_VERIFICATION_FAILED_REASON_NETWORK_UNAVAILABLE));

        assertThat(flag).isEqualTo(FLAG_VERIFICATION_FAILED_MAY_RETRY);
        assertThat(isBypassAllowed).isFalse();
    }

    @Test
    public void policyClosed_unknown_onlyAck() {
        int flag = ConfirmDeveloperVerification.getUserConfirmationDialogFlag(
        boolean isBypassAllowed = ConfirmDeveloperVerification.isBypassAllowed(
                new DeveloperVerificationUserConfirmationInfo(
                        DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED,
                        DEVELOPER_VERIFICATION_FAILED_REASON_UNKNOWN));

        assertThat(flag).isEqualTo(0);
        assertThat(isBypassAllowed).isFalse();
    }
}
Loading