diff options
4 files changed, 111 insertions, 8 deletions
diff --git a/core/java/android/credentials/CredentialManager.java b/core/java/android/credentials/CredentialManager.java index 30ee118d3b59..c9a0626341b7 100644 --- a/core/java/android/credentials/CredentialManager.java +++ b/core/java/android/credentials/CredentialManager.java @@ -62,10 +62,10 @@ public final class CredentialManager { * <p>The execution can potentially launch UI flows to collect user consent to using a * credential, display a picker when multiple credentials exist, etc. * - * @param request the request specifying type(s) of credentials to get from the user. - * @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. + * @param request the request specifying type(s) of credentials to get from the user + * @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 */ public void executeGetCredential( @NonNull GetCredentialRequest request, @@ -101,10 +101,10 @@ public final class CredentialManager { * <p>The execution can potentially launch UI flows to collect user consent to creating * or storing the new credential, etc. * - * @param request the request specifying type(s) of credentials to get from the user. - * @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. + * @param request the request specifying type(s) of credentials to get from the user + * @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 */ public void executeCreateCredential( @NonNull CreateCredentialRequest request, @@ -135,6 +135,44 @@ public final class CredentialManager { } } + /** + * Clears the current user credential session 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. + * + * @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( + @Nullable CancellationSignal cancellationSignal, + @CallbackExecutor @NonNull Executor executor, + @NonNull OutcomeReceiver<Void, CredentialManagerException> callback) { + requireNonNull(executor, "executor must not be null"); + requireNonNull(callback, "callback must not be null"); + + if (cancellationSignal != null && cancellationSignal.isCanceled()) { + Log.w(TAG, "executeCreateCredential already canceled"); + return; + } + + ICancellationSignal cancelRemote = null; + try { + cancelRemote = mService.clearCredentialSession( + new ClearCredentialSessionTransport(executor, callback), + mContext.getOpPackageName()); + } catch (RemoteException e) { + e.rethrowFromSystemServer(); + } + + if (cancellationSignal != null && cancelRemote != null) { + cancellationSignal.setRemote(cancelRemote); + } + } + private static class GetCredentialTransport extends IGetCredentialCallback.Stub { // TODO: listen for cancellation to release callback. @@ -184,4 +222,29 @@ public final class CredentialManager { () -> mCallback.onError(new CredentialManagerException(errorCode, message))); } } + + private static class ClearCredentialSessionTransport + extends IClearCredentialSessionCallback.Stub { + // TODO: listen for cancellation to release callback. + + private final Executor mExecutor; + private final OutcomeReceiver<Void, CredentialManagerException> mCallback; + + private ClearCredentialSessionTransport(Executor executor, + OutcomeReceiver<Void, CredentialManagerException> callback) { + mExecutor = executor; + mCallback = callback; + } + + @Override + public void onSuccess() { + mCallback.onResult(null); + } + + @Override + public void onError(int errorCode, String message) { + mExecutor.execute( + () -> mCallback.onError(new CredentialManagerException(errorCode, message))); + } + } } diff --git a/core/java/android/credentials/IClearCredentialSessionCallback.aidl b/core/java/android/credentials/IClearCredentialSessionCallback.aidl new file mode 100644 index 000000000000..903e7f56cd2e --- /dev/null +++ b/core/java/android/credentials/IClearCredentialSessionCallback.aidl @@ -0,0 +1,27 @@ +/* + * 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; + +/** + * Listener for clearCredentialSession request. + * + * @hide + */ +interface IClearCredentialSessionCallback { + oneway void onSuccess(); + oneway void onError(int errorCode, String message); +}
\ No newline at end of file diff --git a/core/java/android/credentials/ICredentialManager.aidl b/core/java/android/credentials/ICredentialManager.aidl index b0f27f9164f3..35688d7fe113 100644 --- a/core/java/android/credentials/ICredentialManager.aidl +++ b/core/java/android/credentials/ICredentialManager.aidl @@ -18,6 +18,7 @@ package android.credentials; import android.credentials.CreateCredentialRequest; import android.credentials.GetCredentialRequest; +import android.credentials.IClearCredentialSessionCallback; import android.credentials.ICreateCredentialCallback; import android.credentials.IGetCredentialCallback; import android.os.ICancellationSignal; @@ -32,4 +33,6 @@ interface ICredentialManager { @nullable ICancellationSignal executeGetCredential(in GetCredentialRequest request, in IGetCredentialCallback callback, String callingPackage); @nullable ICancellationSignal executeCreateCredential(in CreateCredentialRequest request, in ICreateCredentialCallback callback, String callingPackage); + + @nullable ICancellationSignal clearCredentialSession(in IClearCredentialSessionCallback callback, String callingPackage); } diff --git a/services/credentials/java/com/android/server/credentials/CredentialManagerService.java b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java index 40412db2ed5e..321f022f526f 100644 --- a/services/credentials/java/com/android/server/credentials/CredentialManagerService.java +++ b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.credentials.CreateCredentialRequest; import android.credentials.GetCredentialRequest; +import android.credentials.IClearCredentialSessionCallback; import android.credentials.ICreateCredentialCallback; import android.credentials.ICredentialManager; import android.credentials.IGetCredentialCallback; @@ -155,5 +156,14 @@ public final class CredentialManagerService extends ICancellationSignal cancelTransport = CancellationSignal.createTransport(); return cancelTransport; } + + @Override + public ICancellationSignal clearCredentialSession( + IClearCredentialSessionCallback callback, String callingPackage) { + // TODO: implement. + Log.i(TAG, "clearCredentialSession"); + ICancellationSignal cancelTransport = CancellationSignal.createTransport(); + return cancelTransport; + } } } |