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

Commit c3627997 authored by Arpan Kaphle's avatar Arpan Kaphle
Browse files

Emit Simple Metrics for Set/GetCredProvider APIs

This adds our 'quick metric' to check the status of our other API
methods. Final changes to come soon.

Bug: 271135048
Test: Build Test
Change-Id: I52efc7fdceb03df1e57d494c516425cd77679703
parent 9a18aa50
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -706,11 +706,18 @@ public final class CredentialManagerService
        public void setEnabledProviders(
                List<String>  primaryProviders, List<String> providers, int userId,
                ISetEnabledProvidersCallback callback) {
            final int callingUid = Binder.getCallingUid();
            if (!hasWriteSecureSettingsPermission()) {
                try {
                    MetricUtilities.logApiCalledSimpleV2(
                            ApiName.SET_ENABLED_PROVIDERS,
                            ApiStatus.FAILURE, callingUid);
                    callback.onError(
                            PERMISSION_DENIED_ERROR, PERMISSION_DENIED_WRITE_SECURE_SETTINGS_ERROR);
                } catch (RemoteException e) {
                    MetricUtilities.logApiCalledSimpleV2(
                            ApiName.SET_ENABLED_PROVIDERS,
                            ApiStatus.FAILURE, callingUid);
                    Slog.e(TAG, "Issue with invoking response: ", e);
                }
                return;
@@ -744,10 +751,16 @@ public final class CredentialManagerService
            if (!writeEnabledStatus || !writePrimaryStatus) {
                Slog.e(TAG, "Failed to store setting containing enabled or primary providers");
                try {
                    MetricUtilities.logApiCalledSimpleV2(
                            ApiName.SET_ENABLED_PROVIDERS,
                            ApiStatus.FAILURE, callingUid);
                    callback.onError(
                            "failed_setting_store",
                            "Failed to store setting containing enabled or primary providers");
                } catch (RemoteException e) {
                    MetricUtilities.logApiCalledSimpleV2(
                            ApiName.SET_ENABLED_PROVIDERS,
                            ApiStatus.FAILURE, callingUid);
                    Slog.e(TAG, "Issue with invoking error response: ", e);
                    return;
                }
@@ -755,8 +768,14 @@ public final class CredentialManagerService

            // Call the callback.
            try {
                MetricUtilities.logApiCalledSimpleV2(
                        ApiName.SET_ENABLED_PROVIDERS,
                        ApiStatus.SUCCESS, callingUid);
                callback.onResponse();
            } catch (RemoteException e) {
                MetricUtilities.logApiCalledSimpleV2(
                        ApiName.SET_ENABLED_PROVIDERS,
                        ApiStatus.FAILURE, callingUid);
                Slog.e(TAG, "Issue with invoking response: ", e);
                // TODO: Propagate failure
            }
@@ -805,10 +824,15 @@ public final class CredentialManagerService
        public List<CredentialProviderInfo> getCredentialProviderServices(
                int userId, int providerFilter) {
            verifyGetProvidersPermission();

            return CredentialProviderInfoFactory.getCredentialProviderServices(
            final int callingUid = Binder.getCallingUid();
            MetricUtilities.logApiCalledSimpleV2(
                    ApiName.GET_CREDENTIAL_PROVIDER_SERVICES,
                    ApiStatus.SUCCESS, callingUid);
            return CredentialProviderInfoFactory
            .getCredentialProviderServices(
                mContext, userId, providerFilter, getEnabledProvidersForUser(userId),
                getPrimaryProvidersForUserId(mContext, userId));

        }

        @Override
+17 −0
Original line number Diff line number Diff line
@@ -24,8 +24,11 @@ import static android.credentials.ui.RequestInfo.TYPE_UNDEFINED;
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_CLEAR_CREDENTIAL;
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_CREATE_CREDENTIAL;
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_GET_CREDENTIAL;
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_GET_CREDENTIAL_PROVIDER_SERVICES;
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_GET_CREDENTIAL_VIA_REGISTRY;
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE;
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_REGISTER_CREDENTIAL_DESCRIPTION;
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_SET_ENABLED_PROVIDERS;
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_UNKNOWN;

import android.credentials.ui.RequestInfo;
@@ -45,6 +48,20 @@ CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_GET_CREDENTIAL_VIA
            CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_CLEAR_CREDENTIAL),
    IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE(
CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE
    ),

    SET_ENABLED_PROVIDERS(
            CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_SET_ENABLED_PROVIDERS),

    GET_CREDENTIAL_PROVIDER_SERVICES(
    CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_GET_CREDENTIAL_PROVIDER_SERVICES),

    REGISTER_CREDENTIAL_DESCRIPTION(
    CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_REGISTER_CREDENTIAL_DESCRIPTION
    ),

    UNREGISTER_CREDENTIAL_DESCRIPTION(
    CREDENTIAL_MANAGER_INITIAL_PHASE_REPORTED__API_NAME__API_NAME_REGISTER_CREDENTIAL_DESCRIPTION
    );

    private static final String TAG = "ApiName";