Unhide clearCredentialState framework api.

This API is independent of the get-credential api because at
the time of the get call, information about whether the previous /
existing user state should be cleared has already been lost. That is,
we can't have this as a parameter to the get call because it'd be
impossible to set it at that point.

Bug: 246564035
CTS-Coverage-Bug: 246637346
Test: Local Build & Deployment

Change-Id: Icc12a89039e7088bcee8fd6ae20a6349f730ac91
This commit is contained in:
Helen Qin
2022-11-23 02:49:45 +00:00
parent ee325d717a
commit 1db4fabbeb
7 changed files with 139 additions and 18 deletions

View File

@@ -12982,6 +12982,14 @@ package android.content.res.loader {
package android.credentials {
public final class ClearCredentialStateRequest implements android.os.Parcelable {
ctor public ClearCredentialStateRequest(@NonNull android.os.Bundle);
method public int describeContents();
method @NonNull public android.os.Bundle getData();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.credentials.ClearCredentialStateRequest> CREATOR;
}
public final class CreateCredentialRequest implements android.os.Parcelable {
ctor public CreateCredentialRequest(@NonNull String, @NonNull android.os.Bundle);
method public int describeContents();
@@ -13009,6 +13017,7 @@ package android.credentials {
}
public final class CredentialManager {
method public void clearCredentialState(@NonNull android.credentials.ClearCredentialStateRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Void,android.credentials.CredentialManagerException>);
method public void executeCreateCredential(@NonNull android.credentials.CreateCredentialRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.CreateCredentialResponse,android.credentials.CredentialManagerException>);
method public void executeGetCredential(@NonNull android.credentials.GetCredentialRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.CredentialManagerException>);
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright 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.credentials;
parcelable ClearCredentialStateRequest;

View File

@@ -0,0 +1,85 @@
/*
* Copyright 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.credentials;
import static java.util.Objects.requireNonNull;
import android.annotation.NonNull;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import com.android.internal.util.AnnotationValidations;
/**
* A request class for clearing a user's credential state from the credential providers.
*/
public final class ClearCredentialStateRequest implements Parcelable {
/** The request data. */
@NonNull
private final Bundle mData;
/** Returns the request data. */
@NonNull
public Bundle getData() {
return mData;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeBundle(mData);
}
@Override
public int describeContents() {
return 0;
}
@Override
public String toString() {
return "ClearCredentialStateRequest {data=" + mData + "}";
}
/**
* Constructs a {@link ClearCredentialStateRequest}.
*
* @param data the request data
*/
public ClearCredentialStateRequest(@NonNull Bundle data) {
mData = requireNonNull(data, "data must not be null");
}
private ClearCredentialStateRequest(@NonNull Parcel in) {
Bundle data = in.readBundle();
mData = data;
AnnotationValidations.validate(NonNull.class, null, mData);
}
public static final @NonNull Creator<ClearCredentialStateRequest> CREATOR =
new Creator<ClearCredentialStateRequest>() {
@Override
public ClearCredentialStateRequest[] newArray(int size) {
return new ClearCredentialStateRequest[size];
}
@Override
public ClearCredentialStateRequest createFromParcel(@NonNull Parcel in) {
return new ClearCredentialStateRequest(in);
}
};
}

View File

@@ -142,18 +142,24 @@ public final class CredentialManager {
}
/**
* Clears the current user credential session from all credential providers.
* Clears the current user credential state from all credential providers.
*
* <p>Usually invoked after your user signs out of your app so that they will not be
* automatically signed in the next time.
* You should invoked this api after your user signs out of your app to notify all credential
* providers that any stored credential session for the given app should be cleared.
*
* A credential provider may have stored an active credential session and use it to limit
* sign-in options for future get-credential calls. For example, it may prioritize the active
* credential over any other available credential. When your user explicitly signs out of your
* app and in order to get the holistic sign-in options the next time, you should call this API
* to let the provider clear any stored credential session.
*
* @param request the request data
* @param cancellationSignal an optional signal that allows for cancelling this call
* @param executor the callback will take place on this {@link Executor}
* @param callback the callback invoked when the request succeeds or fails
*
* @hide
*/
public void clearCredentialSession(
public void clearCredentialState(
@NonNull ClearCredentialStateRequest request,
@Nullable CancellationSignal cancellationSignal,
@CallbackExecutor @NonNull Executor executor,
@NonNull OutcomeReceiver<Void, CredentialManagerException> callback) {
@@ -167,8 +173,8 @@ public final class CredentialManager {
ICancellationSignal cancelRemote = null;
try {
cancelRemote = mService.clearCredentialSession(
new ClearCredentialSessionTransport(executor, callback),
cancelRemote = mService.clearCredentialState(request,
new ClearCredentialStateTransport(executor, callback),
mContext.getOpPackageName());
} catch (RemoteException e) {
e.rethrowFromSystemServer();
@@ -255,14 +261,14 @@ public final class CredentialManager {
}
}
private static class ClearCredentialSessionTransport
extends IClearCredentialSessionCallback.Stub {
private static class ClearCredentialStateTransport
extends IClearCredentialStateCallback.Stub {
// TODO: listen for cancellation to release callback.
private final Executor mExecutor;
private final OutcomeReceiver<Void, CredentialManagerException> mCallback;
private ClearCredentialSessionTransport(Executor executor,
private ClearCredentialStateTransport(Executor executor,
OutcomeReceiver<Void, CredentialManagerException> callback) {
mExecutor = executor;
mCallback = callback;

View File

@@ -17,11 +17,11 @@
package android.credentials;
/**
* Listener for clearCredentialSession request.
* Listener for clearCredentialState request.
*
* @hide
*/
interface IClearCredentialSessionCallback {
interface IClearCredentialStateCallback {
oneway void onSuccess();
oneway void onError(int errorCode, String message);
}

View File

@@ -16,9 +16,10 @@
package android.credentials;
import android.credentials.ClearCredentialStateRequest;
import android.credentials.CreateCredentialRequest;
import android.credentials.GetCredentialRequest;
import android.credentials.IClearCredentialSessionCallback;
import android.credentials.IClearCredentialStateCallback;
import android.credentials.ICreateCredentialCallback;
import android.credentials.IGetCredentialCallback;
import android.os.ICancellationSignal;
@@ -34,5 +35,5 @@ interface ICredentialManager {
@nullable ICancellationSignal executeCreateCredential(in CreateCredentialRequest request, in ICreateCredentialCallback callback, String callingPackage);
@nullable ICancellationSignal clearCredentialSession(in IClearCredentialSessionCallback callback, String callingPackage);
@nullable ICancellationSignal clearCredentialState(in ClearCredentialStateRequest request, in IClearCredentialStateCallback callback, String callingPackage);
}

View File

@@ -22,10 +22,11 @@ import android.annotation.NonNull;
import android.annotation.UserIdInt;
import android.content.Context;
import android.content.pm.PackageManager;
import android.credentials.ClearCredentialStateRequest;
import android.credentials.CreateCredentialRequest;
import android.credentials.GetCredentialOption;
import android.credentials.GetCredentialRequest;
import android.credentials.IClearCredentialSessionCallback;
import android.credentials.IClearCredentialStateCallback;
import android.credentials.ICreateCredentialCallback;
import android.credentials.ICredentialManager;
import android.credentials.IGetCredentialCallback;
@@ -206,8 +207,8 @@ public final class CredentialManagerService extends
}
@Override
public ICancellationSignal clearCredentialSession(
IClearCredentialSessionCallback callback, String callingPackage) {
public ICancellationSignal clearCredentialState(ClearCredentialStateRequest request,
IClearCredentialStateCallback callback, String callingPackage) {
// TODO: implement.
Log.i(TAG, "clearCredentialSession");
ICancellationSignal cancelTransport = CancellationSignal.createTransport();