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

Commit 033c16fa authored by Helen Qin's avatar Helen Qin
Browse files

Activity canceled due to settings launch should trigger a different

code.

This should leads to not user cancelation developer error but rather
interrupted so that the developer can retry the call.

Test: local deployment
Bug: 265233253
Change-Id: Id23434d91c353d850ea75f26395f2920b6947898
parent f104ba94
Loading
Loading
Loading
Loading
+18 −16
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.credentials.ui;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Bundle;
@@ -25,6 +26,9 @@ import android.os.Parcelable;

import com.android.internal.util.AnnotationValidations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Base dialog result data.
 *
@@ -55,29 +59,27 @@ public class BaseDialogResult implements Parcelable {
    private static final String EXTRA_BASE_RESULT =
            "android.credentials.ui.extra.BASE_RESULT";

    /** @hide **/
    @IntDef(prefix = {"RESULT_CODE_"}, value = {
            RESULT_CODE_DIALOG_USER_CANCELED,
            RESULT_CODE_CANCELED_AND_LAUNCHED_SETTINGS,
            RESULT_CODE_DIALOG_COMPLETE_WITH_SELECTION,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ResultCode {}

    /** User intentionally canceled the dialog. */
    public static final int RESULT_CODE_DIALOG_CANCELED = 0;
    /**
     * User made a selection and the dialog finished. The user selection result is in the
     * {@code resultData}.
     */
    public static final int RESULT_CODE_DIALOG_COMPLETE_WITH_SELECTION = 1;
    public static final int RESULT_CODE_DIALOG_USER_CANCELED = 0;
    /**
     * The user has acknowledged the consent page rendered for when they first used Credential
     * Manager on this device.
     */
    public static final int RESULT_CODE_CREDENTIAL_MANAGER_CONSENT_ACKNOWLEDGED = 2;
    /**
     * The user has acknowledged the consent page rendered for enabling a new provider.
     * This should only happen during the first time use. The provider info is in the
     * The user has consented to switching to a new default provider. The provider info is in the
     * {@code resultData}.
     */
    public static final int RESULT_CODE_PROVIDER_ENABLED = 3;
    public static final int RESULT_CODE_CANCELED_AND_LAUNCHED_SETTINGS = 1;
    /**
     * The user has consented to switching to a new default provider. The provider info is in the
     * User made a selection and the dialog finished. The user selection result is in the
     * {@code resultData}.
     */
    public static final int RESULT_CODE_DEFAULT_PROVIDER_CHANGED = 4;
    public static final int RESULT_CODE_DIALOG_COMPLETE_WITH_SELECTION = 2;

    @NonNull
    private final IBinder mRequestToken;
+12 −2
Original line number Diff line number Diff line
@@ -99,10 +99,20 @@ class CredentialManagerRepo(
    )
  }

  fun onCancel() {
  // The dialog is canceled by the user.
  fun onUserCancel() {
    onCancel(BaseDialogResult.RESULT_CODE_DIALOG_USER_CANCELED)
  }

  // The dialog is canceled because we launched into settings.
  fun onSettingLaunchCancel() {
    onCancel(BaseDialogResult.RESULT_CODE_DIALOG_COMPLETE_WITH_SELECTION)
  }

  private fun onCancel(cancelCode: Int) {
    val resultData = Bundle()
    BaseDialogResult.addToBundle(BaseDialogResult(requestInfo.token), resultData)
    resultReceiver?.send(BaseDialogResult.RESULT_CODE_DIALOG_CANCELED, resultData)
    resultReceiver?.send(cancelCode, resultData)
  }

  fun onOptionSelected(
+2 −2
Original line number Diff line number Diff line
@@ -147,12 +147,12 @@ class CreateCredentialViewModel(
  }

  fun onDisabledProvidersSelected() {
    credManRepo.onCancel()
    credManRepo.onSettingLaunchCancel()
    dialogResult.tryEmit(DialogResult(ResultState.LAUNCH_SETTING_CANCELED))
  }

  fun onCancel() {
    credManRepo.onCancel()
    credManRepo.onUserCancel()
    dialogResult.tryEmit(DialogResult(ResultState.NORMAL_CANCELED))
  }

+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ class GetCredentialViewModel(private val credManRepo: CredentialManagerRepo) : V
  }

  fun onCancel() {
    credManRepo.onCancel()
    credManRepo.onUserCancel()
    dialogResult.tryEmit(DialogResult(ResultState.NORMAL_CANCELED))
  }
}
+8 −3
Original line number Diff line number Diff line
@@ -107,9 +107,14 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
    }

    @Override
    public void onUiCancellation() {
    public void onUiCancellation(boolean isUserCancellation) {
        if (isUserCancellation) {
            respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_USER_CANCELED,
                    "User cancelled the selector");
        } else {
            respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_INTERRUPTED,
                    "The UI was interrupted - please try again.");
        }
    }

    private void respondToClientWithResponseAndFinish(CreateCredentialResponse response) {
Loading