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

Commit 026b01f0 authored by Reema Bajwa's avatar Reema Bajwa Committed by Android (Google) Code Review
Browse files

Merge "Add OutcomeReceiver to provider APIs and share classes with developer...

Merge "Add OutcomeReceiver to provider APIs and share classes with developer APIs Test: Built locally CTS-Coverage-Bug:247549381"
parents dda4bb62 01e3d07d
Loading
Loading
Loading
Loading
+14 −18
Original line number Diff line number Diff line
@@ -16,13 +16,12 @@

package android.service.credentials;

import android.annotation.NonNull;
import android.app.PendingIntent;
import android.app.slice.Slice;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import java.util.Objects;

/**
@@ -32,29 +31,26 @@ import java.util.Objects;
 * @hide
 */
public final class Action implements Parcelable {
    /** Info to be displayed with this action on the UI. */
    private final @NonNull Slice mInfo;
    /**
     * The pending intent to be invoked when the user selects this action.
     */
    /** Slice object containing display content to be displayed with this action on the UI. */
    private final @NonNull Slice mSlice;
    /** The pending intent to be invoked when the user selects this action. */
    private final @NonNull PendingIntent mPendingIntent;

    /**
     * Constructs an action to be displayed on the UI.
     *
     * @param actionInfo The info to be displayed along with this action.
     * @param pendingIntent The intent to be invoked when the user selects this action.
     * @throws NullPointerException If {@code actionInfo}, or {@code pendingIntent} is null.
     * @param slice the display content to be displayed on the UI, along with this action
     * @param pendingIntent the intent to be invoked when the user selects this action
     */
    public Action(@NonNull Slice actionInfo, @NonNull PendingIntent pendingIntent) {
        Objects.requireNonNull(actionInfo, "actionInfo must not be null");
    public Action(@NonNull Slice slice, @NonNull PendingIntent pendingIntent) {
        Objects.requireNonNull(slice, "slice must not be null");
        Objects.requireNonNull(pendingIntent, "pendingIntent must not be null");
        mInfo = actionInfo;
        mSlice = slice;
        mPendingIntent = pendingIntent;
    }

    private Action(@NonNull Parcel in) {
        mInfo = in.readParcelable(Slice.class.getClassLoader(), Slice.class);
        mSlice = in.readParcelable(Slice.class.getClassLoader(), Slice.class);
        mPendingIntent = in.readParcelable(PendingIntent.class.getClassLoader(),
                PendingIntent.class);
    }
@@ -78,15 +74,15 @@ public final class Action implements Parcelable {

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        mInfo.writeToParcel(dest, flags);
        mSlice.writeToParcel(dest, flags);
        mPendingIntent.writeToParcel(dest, flags);
    }

    /**
     * Returns the action info as a {@link Slice} object, to be displayed on the UI.
     * Returns a {@code Slice} object containing the display content to be displayed on the UI.
     */
    public @NonNull Slice getActionInfo() {
        return mInfo;
    public @NonNull Slice getSlice() {
        return mSlice;
    }

    /**
+0 −64
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.service.credentials;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.RemoteException;
import android.util.Log;

/**
 * Callback to be invoked as a response to {@link CreateCredentialRequest}.
 *
 * @hide
 */
public final class CreateCredentialCallback {
    private static final String TAG = "CreateCredentialCallback";

    private final ICreateCredentialCallback mCallback;

    /** @hide */
    public CreateCredentialCallback(@NonNull ICreateCredentialCallback callback) {
        mCallback = callback;
    }

    /**
     * Invoked on a successful response for {@link CreateCredentialRequest}
     * @param response The response from the credential provider.
     */
    public void onSuccess(@NonNull CreateCredentialResponse response) {
        try {
            mCallback.onSuccess(response);
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
        }
    }

    /**
     * Invoked on a failure response for {@link CreateCredentialRequest}
     * @param errorCode The code defining the type of error.
     * @param message The message corresponding to the failure.
     */
    public void onFailure(int errorCode, @Nullable CharSequence message) {
        Log.w(TAG, "onFailure: " + message);
        try {
            mCallback.onFailure(errorCode, message);
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
        }
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -16,12 +16,11 @@

package android.service.credentials;

import android.annotation.NonNull;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import com.android.internal.util.Preconditions;

import java.util.Objects;
+1 −2
Original line number Diff line number Diff line
@@ -16,12 +16,11 @@

package android.service.credentials;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import com.android.internal.util.Preconditions;

import java.util.ArrayList;
+0 −100
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.service.credentials;

import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import static java.util.Objects.requireNonNull;

import com.android.internal.util.Preconditions;

/**
 * A Credential object that contains type specific data that is returned from the credential
 * provider to the framework. Framework then converts it to an app facing representation and
 * returns to the calling app.
 *
 * @hide
 */
public final class Credential implements Parcelable {
    /** The type of this credential. */
    private final @NonNull String mType;

    /** The data associated with this credential. */
    private final @NonNull Bundle mData;

    /**
     * Constructs a credential object.
     *
     * @param type The type of the credential.
     * @param data The data of the credential that is passed back to the framework, and eventually
     *             to the calling app.
     * @throws NullPointerException If {@code data} is null.
     * @throws IllegalArgumentException If {@code type} is null or empty.
     */
    public Credential(@NonNull String type, @NonNull Bundle data) {
        Preconditions.checkStringNotEmpty(type, "type must not be null, or empty");
        requireNonNull(data, "data must not be null");
        this.mType = type;
        this.mData = data;
    }

    private Credential(@NonNull Parcel in) {
        mType = in.readString16NoHelper();
        mData = in.readBundle();
    }

    /**
     * Returns the type of the credential.
     */
    public @NonNull String getType() {
        return mType;
    }

    /**
     * Returns the data associated with the credential.
     */
    public @NonNull Bundle getData() {
        return mData;
    }

    public static final @NonNull Creator<Credential> CREATOR = new Creator<Credential>() {
        @Override
        public Credential createFromParcel(@NonNull Parcel in) {
            return new Credential(in);
        }

        @Override
        public Credential[] newArray(int size) {
            return new Credential[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString8(mType);
        dest.writeBundle(mData);
    }
}
Loading