Merge "Log the Credential Manager api invocations."
This commit is contained in:
committed by
Android (Google) Code Review
commit
c28af28dfb
@@ -39,15 +39,17 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
|
||||
implements ProviderSession.ProviderInternalCallback<Void> {
|
||||
private static final String TAG = "GetRequestSession";
|
||||
|
||||
public ClearRequestSession(Context context, int userId,
|
||||
public ClearRequestSession(Context context, int userId, int callingUid,
|
||||
IClearCredentialStateCallback callback, ClearCredentialStateRequest request,
|
||||
CallingAppInfo callingAppInfo) {
|
||||
super(context, userId, request, callback, RequestInfo.TYPE_UNDEFINED, callingAppInfo);
|
||||
super(context, userId, callingUid, request, callback, RequestInfo.TYPE_UNDEFINED,
|
||||
callingAppInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new provider session, and adds it list of providers that are contributing to
|
||||
* this session.
|
||||
*
|
||||
* @return the provider session created within this request session, for the given provider
|
||||
* info.
|
||||
*/
|
||||
@@ -111,8 +113,10 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
|
||||
Log.i(TAG, "respondToClientWithResponseAndFinish");
|
||||
try {
|
||||
mClientCallback.onSuccess();
|
||||
logApiCalled(RequestType.CLEAR_CREDENTIALS, /* isSuccessful */ true);
|
||||
} catch (RemoteException e) {
|
||||
Log.i(TAG, "Issue while propagating the response to the client");
|
||||
logApiCalled(RequestType.CLEAR_CREDENTIALS, /* isSuccessful */ false);
|
||||
}
|
||||
finishSession();
|
||||
}
|
||||
@@ -124,10 +128,12 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logApiCalled(RequestType.CLEAR_CREDENTIALS, /* isSuccessful */ false);
|
||||
finishSession();
|
||||
}
|
||||
|
||||
private void processResponses() {
|
||||
for (ProviderSession session: mProviders.values()) {
|
||||
for (ProviderSession session : mProviders.values()) {
|
||||
if (session.isProviderResponseSet()) {
|
||||
// If even one provider responded successfully, send back the response
|
||||
// TODO: Aggregate other exceptions
|
||||
|
||||
@@ -44,11 +44,12 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
|
||||
implements ProviderSession.ProviderInternalCallback<CreateCredentialResponse> {
|
||||
private static final String TAG = "CreateRequestSession";
|
||||
|
||||
CreateRequestSession(@NonNull Context context, int userId,
|
||||
CreateRequestSession(@NonNull Context context, int userId, int callingUid,
|
||||
CreateCredentialRequest request,
|
||||
ICreateCredentialCallback callback,
|
||||
CallingAppInfo callingAppInfo) {
|
||||
super(context, userId, request, callback, RequestInfo.TYPE_CREATE, callingAppInfo);
|
||||
super(context, userId, callingUid, request, callback, RequestInfo.TYPE_CREATE,
|
||||
callingAppInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +64,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
|
||||
RemoteCredentialService remoteCredentialService) {
|
||||
ProviderCreateSession providerCreateSession = ProviderCreateSession
|
||||
.createNewSession(mContext, mUserId, providerInfo,
|
||||
this, remoteCredentialService);
|
||||
this, remoteCredentialService);
|
||||
if (providerCreateSession != null) {
|
||||
Log.i(TAG, "In startProviderSession - provider session created and being added");
|
||||
mProviders.put(providerCreateSession.getComponentName().flattenToString(),
|
||||
@@ -115,8 +116,10 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
|
||||
Log.i(TAG, "respondToClientWithResponseAndFinish");
|
||||
try {
|
||||
mClientCallback.onResponse(response);
|
||||
logApiCalled(RequestType.CREATE_CREDENTIALS, /* isSuccessful */ true);
|
||||
} catch (RemoteException e) {
|
||||
Log.i(TAG, "Issue while responding to client: " + e.getMessage());
|
||||
logApiCalled(RequestType.CREATE_CREDENTIALS, /* isSuccessful */ false);
|
||||
}
|
||||
finishSession();
|
||||
}
|
||||
@@ -128,6 +131,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
|
||||
} catch (RemoteException e) {
|
||||
Log.i(TAG, "Issue while responding to client: " + e.getMessage());
|
||||
}
|
||||
logApiCalled(RequestType.CREATE_CREDENTIALS, /* isSuccessful */ false);
|
||||
finishSession();
|
||||
}
|
||||
|
||||
|
||||
@@ -269,11 +269,13 @@ public final class CredentialManagerService
|
||||
ICancellationSignal cancelTransport = CancellationSignal.createTransport();
|
||||
|
||||
int userId = UserHandle.getCallingUserId();
|
||||
int callingUid = Binder.getCallingUid();
|
||||
// New request session, scoped for this request only.
|
||||
final GetRequestSession session =
|
||||
new GetRequestSession(
|
||||
getContext(),
|
||||
userId,
|
||||
callingUid,
|
||||
callback,
|
||||
request,
|
||||
constructCallingAppInfo(callingPackage, userId));
|
||||
@@ -319,10 +321,12 @@ public final class CredentialManagerService
|
||||
|
||||
// New request session, scoped for this request only.
|
||||
int userId = UserHandle.getCallingUserId();
|
||||
int callingUid = Binder.getCallingUid();
|
||||
final CreateRequestSession session =
|
||||
new CreateRequestSession(
|
||||
getContext(),
|
||||
userId,
|
||||
callingUid,
|
||||
request,
|
||||
callback,
|
||||
constructCallingAppInfo(callingPackage, userId));
|
||||
@@ -434,10 +438,12 @@ public final class CredentialManagerService
|
||||
|
||||
// New request session, scoped for this request only.
|
||||
int userId = UserHandle.getCallingUserId();
|
||||
int callingUid = Binder.getCallingUid();
|
||||
final ClearRequestSession session =
|
||||
new ClearRequestSession(
|
||||
getContext(),
|
||||
userId,
|
||||
callingUid,
|
||||
callback,
|
||||
request,
|
||||
constructCallingAppInfo(callingPackage, userId));
|
||||
|
||||
@@ -41,10 +41,10 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
|
||||
implements ProviderSession.ProviderInternalCallback<GetCredentialResponse> {
|
||||
private static final String TAG = "GetRequestSession";
|
||||
|
||||
public GetRequestSession(Context context, int userId,
|
||||
public GetRequestSession(Context context, int userId, int callingUid,
|
||||
IGetCredentialCallback callback, GetCredentialRequest request,
|
||||
CallingAppInfo callingAppInfo) {
|
||||
super(context, userId, request, callback, RequestInfo.TYPE_GET, callingAppInfo);
|
||||
super(context, userId, callingUid, request, callback, RequestInfo.TYPE_GET, callingAppInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,8 +104,10 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
|
||||
private void respondToClientWithResponseAndFinish(GetCredentialResponse response) {
|
||||
try {
|
||||
mClientCallback.onResponse(response);
|
||||
logApiCalled(RequestType.GET_CREDENTIALS, /* isSuccessful */ true);
|
||||
} catch (RemoteException e) {
|
||||
Log.i(TAG, "Issue while responding to client with a response : " + e.getMessage());
|
||||
logApiCalled(RequestType.GET_CREDENTIALS, /* isSuccessful */ false);
|
||||
}
|
||||
finishSession();
|
||||
}
|
||||
@@ -117,6 +119,7 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
|
||||
Log.i(TAG, "Issue while responding to client with error : " + e.getMessage());
|
||||
|
||||
}
|
||||
logApiCalled(RequestType.GET_CREDENTIALS, /* isSuccessful */ false);
|
||||
finishSession();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
|
||||
package com.android.server.credentials;
|
||||
|
||||
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_API_CALLED__API_NAME__API_NAME_CLEAR_CREDENTIAL;
|
||||
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_API_CALLED__API_NAME__API_NAME_CREATE_CREDENTIAL;
|
||||
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_API_CALLED__API_NAME__API_NAME_GET_CREDENTIAL;
|
||||
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_API_CALLED__API_NAME__API_NAME_UNKNOWN;
|
||||
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_API_CALLED__API_STATUS__API_STATUS_FAILURE;
|
||||
import static com.android.internal.util.FrameworkStatsLog.CREDENTIAL_MANAGER_API_CALLED__API_STATUS__API_STATUS_SUCCESS;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.Context;
|
||||
@@ -29,6 +36,8 @@ import android.service.credentials.CallingAppInfo;
|
||||
import android.service.credentials.CredentialProviderInfo;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.util.FrameworkStatsLog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -37,28 +46,53 @@ import java.util.Map;
|
||||
* Base class of a request session, that listens to UI events. This class must be extended
|
||||
* every time a new response type is expected from the providers.
|
||||
*/
|
||||
abstract class RequestSession<T, U> implements CredentialManagerUi.CredentialManagerUiCallback{
|
||||
abstract class RequestSession<T, U> implements CredentialManagerUi.CredentialManagerUiCallback {
|
||||
private static final String TAG = "RequestSession";
|
||||
|
||||
// Metrics constants
|
||||
private static final int METRICS_API_NAME_UNKNOWN =
|
||||
CREDENTIAL_MANAGER_API_CALLED__API_NAME__API_NAME_UNKNOWN;
|
||||
private static final int METRICS_API_NAME_GET_CREDENTIAL =
|
||||
CREDENTIAL_MANAGER_API_CALLED__API_NAME__API_NAME_GET_CREDENTIAL;
|
||||
private static final int METRICS_API_NAME_CREATE_CREDENTIAL =
|
||||
CREDENTIAL_MANAGER_API_CALLED__API_NAME__API_NAME_CREATE_CREDENTIAL;
|
||||
private static final int METRICS_API_NAME_CLEAR_CREDENTIAL =
|
||||
CREDENTIAL_MANAGER_API_CALLED__API_NAME__API_NAME_CLEAR_CREDENTIAL;
|
||||
private static final int METRICS_API_STATUS_SUCCESS =
|
||||
CREDENTIAL_MANAGER_API_CALLED__API_STATUS__API_STATUS_SUCCESS;
|
||||
private static final int METRICS_API_STATUS_FAILURE =
|
||||
CREDENTIAL_MANAGER_API_CALLED__API_STATUS__API_STATUS_FAILURE;
|
||||
|
||||
// TODO: Revise access levels of attributes
|
||||
@NonNull protected final T mClientRequest;
|
||||
@NonNull protected final U mClientCallback;
|
||||
@NonNull protected final IBinder mRequestId;
|
||||
@NonNull protected final Context mContext;
|
||||
@NonNull protected final CredentialManagerUi mCredentialManagerUi;
|
||||
@NonNull protected final String mRequestType;
|
||||
@NonNull protected final Handler mHandler;
|
||||
@UserIdInt protected final int mUserId;
|
||||
@NonNull protected final CallingAppInfo mClientAppInfo;
|
||||
@NonNull
|
||||
protected final T mClientRequest;
|
||||
@NonNull
|
||||
protected final U mClientCallback;
|
||||
@NonNull
|
||||
protected final IBinder mRequestId;
|
||||
@NonNull
|
||||
protected final Context mContext;
|
||||
@NonNull
|
||||
protected final CredentialManagerUi mCredentialManagerUi;
|
||||
@NonNull
|
||||
protected final String mRequestType;
|
||||
@NonNull
|
||||
protected final Handler mHandler;
|
||||
@UserIdInt
|
||||
protected final int mUserId;
|
||||
private final int mCallingUid;
|
||||
@NonNull
|
||||
protected final CallingAppInfo mClientAppInfo;
|
||||
|
||||
protected final Map<String, ProviderSession> mProviders = new HashMap<>();
|
||||
|
||||
protected RequestSession(@NonNull Context context,
|
||||
@UserIdInt int userId, @NonNull T clientRequest, U clientCallback,
|
||||
@UserIdInt int userId, int callingUid, @NonNull T clientRequest, U clientCallback,
|
||||
@NonNull String requestType,
|
||||
CallingAppInfo callingAppInfo) {
|
||||
mContext = context;
|
||||
mUserId = userId;
|
||||
mCallingUid = callingUid;
|
||||
mClientRequest = clientRequest;
|
||||
mClientCallback = clientCallback;
|
||||
mRequestType = requestType;
|
||||
@@ -117,6 +151,33 @@ abstract class RequestSession<T, U> implements CredentialManagerUi.CredentialMan
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: move these definitions to a separate logging focused class.
|
||||
enum RequestType {
|
||||
GET_CREDENTIALS,
|
||||
CREATE_CREDENTIALS,
|
||||
CLEAR_CREDENTIALS,
|
||||
}
|
||||
|
||||
private static int getApiNameFromRequestType(RequestType requestType) {
|
||||
switch (requestType) {
|
||||
case GET_CREDENTIALS:
|
||||
return METRICS_API_NAME_GET_CREDENTIAL;
|
||||
case CREATE_CREDENTIALS:
|
||||
return METRICS_API_NAME_CREATE_CREDENTIAL;
|
||||
case CLEAR_CREDENTIALS:
|
||||
return METRICS_API_NAME_CLEAR_CREDENTIAL;
|
||||
default:
|
||||
return METRICS_API_NAME_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
protected void logApiCalled(RequestType requestType, boolean isSuccessful) {
|
||||
FrameworkStatsLog.write(FrameworkStatsLog.CREDENTIAL_MANAGER_API_CALLED,
|
||||
/* api_name */getApiNameFromRequestType(requestType), /* caller_uid */
|
||||
mCallingUid, /* api_status */
|
||||
isSuccessful ? METRICS_API_STATUS_SUCCESS : METRICS_API_STATUS_FAILURE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if at least one provider is ready for UI invocation, and no
|
||||
* provider is pending a response.
|
||||
|
||||
Reference in New Issue
Block a user