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

Commit 4ebb7ace authored by Helen Qin's avatar Helen Qin
Browse files

Address api feedback in b/323068332

Bug: 323068332
Test: cts attached under the same topic
Change-Id: I6d1a2fbcff147056326b428d928b21df3d961a35
parent e4b14783
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -4485,6 +4485,7 @@ package android.credentials.selection {
    ctor public FailureResult(int, @Nullable String);
    method public int getErrorCode();
    method @Nullable public String getErrorMessage();
    method public static void sendFailureResult(@NonNull android.os.ResultReceiver, @NonNull android.credentials.selection.FailureResult);
    field public static final int ERROR_CODE_CANCELED_AND_LAUNCHED_SETTINGS = 2; // 0x2
    field public static final int ERROR_CODE_DIALOG_CANCELED_BY_USER = 1; // 0x1
    field public static final int ERROR_CODE_UI_FAILURE = 0; // 0x0
@@ -4546,17 +4547,13 @@ package android.credentials.selection {
  @FlaggedApi("android.credentials.flags.configurable_selector_ui_enabled") public final class RequestToken {
  }
  @FlaggedApi("android.credentials.flags.configurable_selector_ui_enabled") public final class ResultHelper {
    method public static void sendFailureResult(@NonNull android.os.ResultReceiver, @NonNull android.credentials.selection.FailureResult);
    method public static void sendUserSelectionResult(@NonNull android.os.ResultReceiver, @NonNull android.credentials.selection.UserSelectionResult);
  }
  @FlaggedApi("android.credentials.flags.configurable_selector_ui_enabled") public final class UserSelectionResult {
    ctor public UserSelectionResult(@NonNull String, @NonNull String, @NonNull String, @Nullable android.credentials.selection.ProviderPendingIntentResponse);
    method @NonNull public String getEntryKey();
    method @NonNull public String getEntrySubkey();
    method @Nullable public android.credentials.selection.ProviderPendingIntentResponse getPendingIntentProviderResponse();
    method @NonNull public String getProviderId();
    method public static void sendUserSelectionResult(@NonNull android.os.ResultReceiver, @NonNull android.credentials.selection.UserSelectionResult);
  }
}
+24 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Intent;
import android.os.Bundle;
import android.os.ResultReceiver;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -35,6 +38,24 @@ import java.lang.annotation.RetentionPolicy;
@SystemApi
@FlaggedApi(FLAG_CONFIGURABLE_SELECTOR_UI_ENABLED)
public final class FailureResult {

    /**
     * Sends the {@code failureResult} that caused the UI to stop back to the CredentialManager
     * service.
     *
     * @param resultReceiver the ResultReceiver sent from the system service, that can be extracted
     *                      from the launch intent via
     *                      {@link IntentHelper#extractResultReceiver(Intent)}
     */
    public static void sendFailureResult(@NonNull ResultReceiver resultReceiver,
            @NonNull FailureResult failureResult) {
        FailureDialogResult result = failureResult.toFailureDialogResult();
        Bundle resultData = new Bundle();
        FailureDialogResult.addToBundle(result, resultData);
        resultReceiver.send(failureResult.errorCodeToResultCode(),
                resultData);
    }

    @Nullable
    private final String mErrorMessage;
    @NonNull
@@ -53,6 +74,9 @@ public final class FailureResult {
    /**
     * The UI was stopped due to a failure, e.g. because it failed to parse the incoming data,
     * or it encountered an irrecoverable internal issue.
     *
     * This code also serves as a default value to use for failures that do not fall into any other
     * error code category or for backward compatibility.
     */
    public static final int ERROR_CODE_UI_FAILURE = 0;
    /** The user intentionally canceled the dialog. */
+0 −70
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.credentials.selection;

import static android.credentials.flags.Flags.FLAG_CONFIGURABLE_SELECTOR_UI_ENABLED;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.content.Intent;
import android.os.Bundle;
import android.os.ResultReceiver;

/**
 * Utilities for sending the UI results back to the system service.
 *
 * @hide
 */
@SystemApi
@FlaggedApi(FLAG_CONFIGURABLE_SELECTOR_UI_ENABLED)
public final class ResultHelper {
    /**
     * Sends the {@code failureResult} that caused the UI to stop back to the CredentialManager
     * service.
     *
     * @param resultReceiver the ResultReceiver sent from the system service, that can be extracted
     *                      from the launch intent via
     *                      {@link IntentHelper#extractResultReceiver(Intent)}
     */
    public static void sendFailureResult(@NonNull ResultReceiver resultReceiver,
            @NonNull FailureResult failureResult) {
        FailureDialogResult result = failureResult.toFailureDialogResult();
        Bundle resultData = new Bundle();
        FailureDialogResult.addToBundle(result, resultData);
        resultReceiver.send(failureResult.errorCodeToResultCode(),
                resultData);
    }

    /**
     * Sends the completed {@code userSelectionResult} back to the CredentialManager service.
     *
     * @param resultReceiver the ResultReceiver sent from the system service, that can be extracted
     *                       from the launch intent via
     *                       {@link IntentHelper#extractResultReceiver(Intent)}
     */
    public static void sendUserSelectionResult(@NonNull ResultReceiver resultReceiver,
            @NonNull UserSelectionResult userSelectionResult) {
        UserSelectionDialogResult result = userSelectionResult.toUserSelectionDialogResult();
        Bundle resultData = new Bundle();
        UserSelectionDialogResult.addToBundle(result, resultData);
        resultReceiver.send(BaseDialogResult.RESULT_CODE_DIALOG_COMPLETE_WITH_SELECTION,
                resultData);
    }

    private ResultHelper() {}
}
+19 −0
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Intent;
import android.os.Bundle;
import android.os.ResultReceiver;

import com.android.internal.util.Preconditions;

@@ -34,6 +37,22 @@ import com.android.internal.util.Preconditions;
@SystemApi
@FlaggedApi(FLAG_CONFIGURABLE_SELECTOR_UI_ENABLED)
public final class UserSelectionResult {
    /**
     * Sends the completed {@code userSelectionResult} back to the CredentialManager service.
     *
     * @param resultReceiver the ResultReceiver sent from the system service, that can be extracted
     *                       from the launch intent via
     *                       {@link IntentHelper#extractResultReceiver(Intent)}
     */
    public static void sendUserSelectionResult(@NonNull ResultReceiver resultReceiver,
            @NonNull UserSelectionResult userSelectionResult) {
        UserSelectionDialogResult result = userSelectionResult.toUserSelectionDialogResult();
        Bundle resultData = new Bundle();
        UserSelectionDialogResult.addToBundle(result, resultData);
        resultReceiver.send(BaseDialogResult.RESULT_CODE_DIALOG_COMPLETE_WITH_SELECTION,
                resultData);
    }

    @NonNull
    private final String mProviderId;
    @NonNull