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

Commit bc5af82c authored by Arpan Kaphle's avatar Arpan Kaphle Committed by Automerger Merge Worker
Browse files

Merge "Placing InitialPhase Emit in Proper Locations" into udc-dev am: 4df2f384

parents e269d098 4df2f384
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -46,9 +46,11 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta

    public ClearRequestSession(Context context, int userId, int callingUid,
            IClearCredentialStateCallback callback, ClearCredentialStateRequest request,
            CallingAppInfo callingAppInfo, CancellationSignal cancellationSignal) {
            CallingAppInfo callingAppInfo, CancellationSignal cancellationSignal,
            long startedTimestamp) {
        super(context, userId, callingUid, request, callback, RequestInfo.TYPE_UNDEFINED,
                callingAppInfo, cancellationSignal);
                callingAppInfo, cancellationSignal, startedTimestamp);
        setupInitialPhaseMetric(ApiName.CLEAR_CREDENTIAL.getMetricCode(), MetricUtilities.ZERO);
    }

    /**
+4 −2
Original line number Diff line number Diff line
@@ -53,9 +53,11 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
            CreateCredentialRequest request,
            ICreateCredentialCallback callback,
            CallingAppInfo callingAppInfo,
            CancellationSignal cancellationSignal) {
            CancellationSignal cancellationSignal,
            long startedTimestamp) {
        super(context, userId, callingUid, request, callback, RequestInfo.TYPE_CREATE,
                callingAppInfo, cancellationSignal);
                callingAppInfo, cancellationSignal, startedTimestamp);
        setupInitialPhaseMetric(ApiName.CREATE_CREDENTIAL.getMetricCode(), MetricUtilities.UNIT);
    }

    /**
+30 −6
Original line number Diff line number Diff line
@@ -230,7 +230,9 @@ public final class CredentialManagerService
            return;
        }

        throw new SecurityException("Caller is missing permission: QUERY_ALL_PACKAGES or LIST_ENABLED_CREDENTIAL_PROVIDERS");
        throw new SecurityException(
                "Caller is missing permission: QUERY_ALL_PACKAGES or "
                        + "LIST_ENABLED_CREDENTIAL_PROVIDERS");
    }

    private boolean hasPermission(String permission) {
@@ -402,6 +404,7 @@ public final class CredentialManagerService
                GetCredentialRequest request,
                IGetCredentialCallback callback,
                final String callingPackage) {
            final long timestampBegan = System.nanoTime();
            Log.i(TAG, "starting executeGetCredential with callingPackage: " + callingPackage);
            ICancellationSignal cancelTransport = CancellationSignal.createTransport();

@@ -423,7 +426,8 @@ public final class CredentialManagerService
                            callback,
                            request,
                            constructCallingAppInfo(callingPackage, userId, request.getOrigin()),
                            CancellationSignal.fromTransport(cancelTransport));
                            CancellationSignal.fromTransport(cancelTransport),
                            timestampBegan);

            processGetCredential(request, callback, session);
            return cancelTransport;
@@ -502,6 +506,9 @@ public final class CredentialManagerService
                                    + e.getMessage());
                }
            }

            finalizeAndEmitInitialPhaseMetric(session);
            // TODO(b/271135048) - May still be worth emitting in the empty cases above.
            providerSessions.forEach(ProviderSession::invokeSession);
        }

@@ -510,6 +517,7 @@ public final class CredentialManagerService
                CreateCredentialRequest request,
                ICreateCredentialCallback callback,
                String callingPackage) {
            final long timestampBegan = System.nanoTime();
            Log.i(TAG, "starting executeCreateCredential with callingPackage: "
                    + callingPackage);
            ICancellationSignal cancelTransport = CancellationSignal.createTransport();
@@ -532,7 +540,8 @@ public final class CredentialManagerService
                            request,
                            callback,
                            constructCallingAppInfo(callingPackage, userId, request.getOrigin()),
                            CancellationSignal.fromTransport(cancelTransport));
                            CancellationSignal.fromTransport(cancelTransport),
                            timestampBegan);

            processCreateCredential(request, callback, session);
            return cancelTransport;
@@ -560,10 +569,17 @@ public final class CredentialManagerService
                }
            }

            finalizeAndEmitInitialPhaseMetric(session);
            // Iterate over all provider sessions and invoke the request
            providerSessions.forEach(ProviderSession::invokeSession);
        }

        private void finalizeAndEmitInitialPhaseMetric(RequestSession session) {
            var initMetric = session.mInitialPhaseMetric;
            initMetric.setCredentialServiceBeginQueryTimeNanoseconds(System.nanoTime());
            MetricUtilities.logApiCalled(initMetric);
        }

        @Override
        public void setEnabledProviders(
                List<String> providers, int userId, ISetEnabledProvidersCallback callback) {
@@ -648,6 +664,7 @@ public final class CredentialManagerService
                        }
                        MetricUtilities.logApiCalled(ApiName.IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE,
                                ApiStatus.SUCCESS, callingUid);
                        // TODO(b/271135048) - Update asap to use the new logging types
                        return true;
                    }
                }
@@ -677,12 +694,15 @@ public final class CredentialManagerService
                    mContext, userId, providerFilter, getEnabledProviders());
        }

        @SuppressWarnings("GuardedBy") // ErrorProne requires service.mLock which is the same
        // this.mLock
        private Set<ServiceInfo> getEnabledProviders() {
            Set<ServiceInfo> enabledProviders = new HashSet<>();
            synchronized (mLock) {
                runForUser(
                        (service) -> {
                            enabledProviders.add(service.getCredentialProviderInfo().getServiceInfo());
                            enabledProviders.add(
                                    service.getCredentialProviderInfo().getServiceInfo());
                        });
            }
            return enabledProviders;
@@ -693,6 +713,7 @@ public final class CredentialManagerService
                ClearCredentialStateRequest request,
                IClearCredentialStateCallback callback,
                String callingPackage) {
            final long timestampBegan = System.nanoTime();
            Log.i(TAG, "starting clearCredentialState with callingPackage: " + callingPackage);
            final int userId = UserHandle.getCallingUserId();
            int callingUid = Binder.getCallingUid();
@@ -710,7 +731,8 @@ public final class CredentialManagerService
                            callback,
                            request,
                            constructCallingAppInfo(callingPackage, userId, null),
                            CancellationSignal.fromTransport(cancelTransport));
                            CancellationSignal.fromTransport(cancelTransport),
                            timestampBegan);

            // Initiate all provider sessions
            // TODO: Determine if provider needs to have clear capability in their manifest
@@ -729,6 +751,8 @@ public final class CredentialManagerService
                }
            }

            finalizeAndEmitInitialPhaseMetric(session);

            // Iterate over all provider sessions and invoke the request
            providerSessions.forEach(ProviderSession::invokeSession);
            return cancelTransport;
+9 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.credentials;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Context;
import android.credentials.CredentialOption;
import android.credentials.CredentialProviderInfo;
import android.credentials.GetCredentialException;
import android.credentials.GetCredentialRequest;
@@ -36,6 +37,7 @@ import com.android.server.credentials.metrics.ApiStatus;
import com.android.server.credentials.metrics.ProviderStatusForMetrics;

import java.util.ArrayList;
import java.util.stream.Collectors;

/**
 * Central session for a single getCredentials request. This class listens to the
@@ -47,9 +49,14 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest,
    private static final String TAG = "GetRequestSession";
    public GetRequestSession(Context context, int userId, int callingUid,
            IGetCredentialCallback callback, GetCredentialRequest request,
            CallingAppInfo callingAppInfo, CancellationSignal cancellationSignal) {
            CallingAppInfo callingAppInfo, CancellationSignal cancellationSignal,
            long startedTimestamp) {
        super(context, userId, callingUid, request, callback, RequestInfo.TYPE_GET,
                callingAppInfo, cancellationSignal);
                callingAppInfo, cancellationSignal, startedTimestamp);
        int numTypes = (request.getCredentialOptions().stream()
                .map(CredentialOption::getType).collect(
                Collectors.toSet())).size(); // Dedupe type strings
        setupInitialPhaseMetric(ApiName.GET_CREDENTIAL.getMetricCode(), numTypes);
    }

    /**
+19 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.server.credentials.metrics.ApiName;
import com.android.server.credentials.metrics.ApiStatus;
import com.android.server.credentials.metrics.CandidatePhaseMetric;
import com.android.server.credentials.metrics.ChosenProviderMetric;
import com.android.server.credentials.metrics.InitialPhaseMetric;

import java.util.Map;

@@ -39,7 +40,10 @@ public class MetricUtilities {

    public static final int DEFAULT_INT_32 = -1;
    public static final int[] DEFAULT_REPEATED_INT_32 = new int[0];

    // Used for single count metric emits, such as singular amounts of various types
    public static final int UNIT = 1;
    // Used for zero count metric emits, such as zero amounts of various types
    public static final int ZERO = 0;

    /**
     * This retrieves the uid of any package name, given a context and a component name for the
@@ -155,4 +159,18 @@ public class MetricUtilities {
        }
    }

    /**
     * Handles the metric emit for the initial phase.
     *
     * @param initialPhaseMetric contains all the data for this emit
     */
    protected static void logApiCalled(InitialPhaseMetric initialPhaseMetric) {
        /*
        FrameworkStatsLog.write(FrameworkStatsLog.INITIAL_PHASE,
        .. session_id .. initialPhaseMetric.getSessionId(),
        ...
        TODO Immediately - Fill in asap now that the split atom is checked in.
         */
    }

}
Loading