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

Commit 40b6bceb authored by Becca Hughes's avatar Becca Hughes
Browse files

Add ListEnabledProviders API method for Credential Manager

Adds ListEnabledProviders API which is a SystemApi used
by Settings and Chrome to list the enabled and user
visible installed providers.

Test: make
Bug: 253157179
CTS-Coverage-Bug: 247549381
Change-Id: I25ef3a294f051855c0a4ae104d1111f1e8b8529d
parent c5deccb2
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
@@ -196,6 +196,48 @@ public final class CredentialManager {
        }
    }

    /**
     * Gets a list of all user configurable credential providers registered on the system. This API
     * is intended for browsers and settings apps.
     *
     * @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
     */
    @RequiresPermission(
            allOf = {
                android.Manifest.permission.LIST_ENABLED_CREDENTIAL_PROVIDERS,
                android.Manifest.permission.QUERY_ALL_PACKAGES
            })
    public void listEnabledProviders(
            @Nullable CancellationSignal cancellationSignal,
            @CallbackExecutor @NonNull Executor executor,
            @NonNull
                    OutcomeReceiver<ListEnabledProvidersResponse, ListEnabledProvidersException>
                            callback) {
        requireNonNull(executor, "executor must not be null");
        requireNonNull(callback, "callback must not be null");

        if (cancellationSignal != null && cancellationSignal.isCanceled()) {
            Log.w(TAG, "listEnabledProviders already canceled");
            return;
        }

        ICancellationSignal cancelRemote = null;
        try {
            cancelRemote =
                    mService.listEnabledProviders(
                            new ListEnabledProvidersTransport(executor, callback));
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }

        if (cancellationSignal != null && cancelRemote != null) {
            cancellationSignal.setRemote(cancelRemote);
        }
    }

    /**
     * Sets a list of all user configurable credential providers registered on the system. This API
     * is intended for settings apps.
@@ -331,6 +373,33 @@ public final class CredentialManager {
        }
    }

    private static class ListEnabledProvidersTransport extends IListEnabledProvidersCallback.Stub {
        // TODO: listen for cancellation to release callback.

        private final Executor mExecutor;
        private final OutcomeReceiver<ListEnabledProvidersResponse, ListEnabledProvidersException>
                mCallback;

        private ListEnabledProvidersTransport(
                Executor executor,
                OutcomeReceiver<ListEnabledProvidersResponse, ListEnabledProvidersException>
                        callback) {
            mExecutor = executor;
            mCallback = callback;
        }

        @Override
        public void onResponse(ListEnabledProvidersResponse response) {
            mExecutor.execute(() -> mCallback.onResult(response));
        }

        @Override
        public void onError(String errorType, String message) {
            mExecutor.execute(
                    () -> mCallback.onError(new ListEnabledProvidersException(errorType, message)));
          }
    }

    private static class SetEnabledProvidersTransport extends ISetEnabledProvidersCallback.Stub {
        // TODO: listen for cancellation to release callback.

+3 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.credentials.GetCredentialRequest;
import android.credentials.IClearCredentialStateCallback;
import android.credentials.ICreateCredentialCallback;
import android.credentials.IGetCredentialCallback;
import android.credentials.IListEnabledProvidersCallback;
import android.credentials.ISetEnabledProvidersCallback;
import android.os.ICancellationSignal;

@@ -40,5 +41,7 @@ interface ICredentialManager {

    @nullable ICancellationSignal clearCredentialState(in ClearCredentialStateRequest request, in IClearCredentialStateCallback callback, String callingPackage);

    @nullable ICancellationSignal listEnabledProviders(in IListEnabledProvidersCallback callback);

    void setEnabledProviders(in List<String> providers, in int userId, in ISetEnabledProvidersCallback callback);
}
+29 −0
Original line number Diff line number Diff line
/*
 * 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 android.credentials.ListEnabledProvidersResponse;

/**
 * Listener for an listEnabledProviders request.
 *
 * @hide
 */
interface IListEnabledProvidersCallback {
    oneway void onResponse(in ListEnabledProvidersResponse response);
    oneway void onError(String errorType, String message);
}
 No newline at end of file
+74 −0
Original line number Diff line number Diff line
/*
 * 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 android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.CancellationSignal;
import android.os.OutcomeReceiver;

import com.android.internal.util.Preconditions;

/**
 * Represents an error encountered during the {@link
 * CredentialManager#listEnabledProviders(CancellationSignal Executor, OutcomeReceiver)} operation.
 *
 * @hide
 */
public class ListEnabledProvidersException extends Exception {

    @NonNull public final String errorType;

    /**
     * Constructs a {@link ListEnabledProvidersException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public ListEnabledProvidersException(@NonNull String errorType, @Nullable String message) {
        this(errorType, message, null);
    }

    /**
     * Constructs a {@link ListEnabledProvidersException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public ListEnabledProvidersException(
            @NonNull String errorType, @Nullable String message, @Nullable Throwable cause) {
        super(message, cause);
        this.errorType =
                Preconditions.checkStringNotEmpty(errorType, "errorType must not be empty");
    }

    /**
     * Constructs a {@link ListEnabledProvidersException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public ListEnabledProvidersException(@NonNull String errorType, @Nullable Throwable cause) {
        this(errorType, null, cause);
    }

    /**
     * Constructs a {@link ListEnabledProvidersException}.
     *
     * @throws IllegalArgumentException If errorType is empty.
     */
    public ListEnabledProvidersException(@NonNull String errorType) {
        this(errorType, null, null);
    }
}
+19 −0
Original line number Diff line number Diff line
/*
 * 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 ListEnabledProvidersResponse;
 No newline at end of file
Loading