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

Commit 332070ab authored by Helen Qin's avatar Helen Qin Committed by Android (Google) Code Review
Browse files

Merge "Activity canceled due to settings launch should trigger a different code."

parents b70fde0e 033c16fa
Loading
Loading
Loading
Loading
+18 −16
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.credentials.ui;
package android.credentials.ui;


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


import com.android.internal.util.AnnotationValidations;
import com.android.internal.util.AnnotationValidations;


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

/**
/**
 * Base dialog result data.
 * Base dialog result data.
 *
 *
@@ -55,29 +59,27 @@ public class BaseDialogResult implements Parcelable {
    private static final String EXTRA_BASE_RESULT =
    private static final String EXTRA_BASE_RESULT =
            "android.credentials.ui.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. */
    /** User intentionally canceled the dialog. */
    public static final int RESULT_CODE_DIALOG_CANCELED = 0;
    public static final int RESULT_CODE_DIALOG_USER_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;
    /**
    /**
     * The user has acknowledged the consent page rendered for when they first used Credential
     * The user has consented to switching to a new default provider. The provider info is in the
     * 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
     * {@code resultData}.
     * {@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}.
     * {@code resultData}.
     */
     */
    public static final int RESULT_CODE_DEFAULT_PROVIDER_CHANGED = 4;
    public static final int RESULT_CODE_DIALOG_COMPLETE_WITH_SELECTION = 2;


    @NonNull
    @NonNull
    private final IBinder mRequestToken;
    private final IBinder mRequestToken;
+12 −2
Original line number Original line 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()
    val resultData = Bundle()
    BaseDialogResult.addToBundle(BaseDialogResult(requestInfo.token), resultData)
    BaseDialogResult.addToBundle(BaseDialogResult(requestInfo.token), resultData)
    resultReceiver?.send(BaseDialogResult.RESULT_CODE_DIALOG_CANCELED, resultData)
    resultReceiver?.send(cancelCode, resultData)
  }
  }


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


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


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


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


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


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


    private void respondToClientWithResponseAndFinish(CreateCredentialResponse response) {
    private void respondToClientWithResponseAndFinish(CreateCredentialResponse response) {
Loading