Review logging in CredManService & CredManServiceImpl

Test: built locally
Bug: 270568738

Change-Id: Ia8ca314b22b1ac65ee7c2a5a0067c824ddaf899a
This commit is contained in:
Reema Bajwa
2023-03-22 07:15:30 +00:00
parent 204f951464
commit c1f0f9f54b
2 changed files with 44 additions and 53 deletions

View File

@@ -159,12 +159,10 @@ public final class CredentialManagerService
int resolvedUserId, boolean disabled, String[] serviceNames) {
getOrConstructSystemServiceListLock(resolvedUserId);
if (serviceNames == null || serviceNames.length == 0) {
Slog.i(TAG, "serviceNames sent in newServiceListLocked is null, or empty");
return new ArrayList<>();
}
List<CredentialManagerServiceImpl> serviceList = new ArrayList<>(serviceNames.length);
for (String serviceName : serviceNames) {
Log.i(TAG, "in newServiceListLocked, service: " + serviceName);
if (TextUtils.isEmpty(serviceName)) {
continue;
}
@@ -172,7 +170,7 @@ public final class CredentialManagerService
serviceList.add(
new CredentialManagerServiceImpl(this, mLock, resolvedUserId, serviceName));
} catch (PackageManager.NameNotFoundException | SecurityException e) {
Log.i(TAG, "Unable to add serviceInfo : " + e.getMessage());
Slog.e(TAG, "Unable to add serviceInfo : ", e);
}
}
return serviceList;
@@ -400,7 +398,7 @@ public final class CredentialManagerService
userId);
callingAppInfo = new CallingAppInfo(realPackageName, packageInfo.signingInfo, origin);
} catch (PackageManager.NameNotFoundException e) {
Log.i(TAG, "Issue while retrieving signatureInfo : " + e.getMessage());
Slog.e(TAG, "Issue while retrieving signatureInfo : ", e);
callingAppInfo = new CallingAppInfo(realPackageName, null, origin);
}
return callingAppInfo;
@@ -413,7 +411,8 @@ public final class CredentialManagerService
IGetCredentialCallback callback,
final String callingPackage) {
final long timestampBegan = System.nanoTime();
Log.i(TAG, "starting executeGetCredential with callingPackage: " + callingPackage);
Slog.d(TAG, "starting executeGetCredential with callingPackage: "
+ callingPackage);
ICancellationSignal cancelTransport = CancellationSignal.createTransport();
if (request.getOrigin() != null) {
@@ -522,11 +521,10 @@ public final class CredentialManagerService
GetCredentialException.TYPE_NO_CREDENTIAL,
"No credentials available on this device.");
} catch (RemoteException e) {
Log.i(
Slog.e(
TAG,
"Issue invoking onError on IGetCredentialCallback "
+ "callback: "
+ e.getMessage());
+ "callback: ", e);
}
}
@@ -541,7 +539,7 @@ public final class CredentialManagerService
ICreateCredentialCallback callback,
String callingPackage) {
final long timestampBegan = System.nanoTime();
Log.i(TAG, "starting executeCreateCredential with callingPackage: "
Slog.d(TAG, "starting executeCreateCredential with callingPackage: "
+ callingPackage);
ICancellationSignal cancelTransport = CancellationSignal.createTransport();
@@ -584,11 +582,10 @@ public final class CredentialManagerService
CreateCredentialException.TYPE_NO_CREATE_OPTIONS,
"No create options available.");
} catch (RemoteException e) {
Log.i(
Slog.e(
TAG,
"Issue invoking onError on ICreateCredentialCallback "
+ "callback: "
+ e.getMessage());
+ "callback: ", e);
}
}
@@ -603,21 +600,19 @@ public final class CredentialManagerService
initMetric.setCredentialServiceBeginQueryTimeNanoseconds(System.nanoTime());
MetricUtilities.logApiCalled(initMetric, ++session.mSequenceCounter);
} catch (Exception e) {
Log.w(TAG, "Unexpected error during metric logging: " + e);
Log.w(TAG, "Unexpected error during metric logging: ", e);
}
}
@Override
public void setEnabledProviders(
List<String> providers, int userId, ISetEnabledProvidersCallback callback) {
Log.i(TAG, "setEnabledProviders");
if (!hasWriteSecureSettingsPermission()) {
try {
callback.onError(
PERMISSION_DENIED_ERROR, PERMISSION_DENIED_WRITE_SECURE_SETTINGS_ERROR);
} catch (RemoteException e) {
Log.e(TAG, "Issue with invoking response: " + e.getMessage());
Slog.e(TAG, "Issue with invoking response: ", e);
}
return;
}
@@ -644,7 +639,7 @@ public final class CredentialManagerService
"failed_setting_store",
"Failed to store setting containing enabled providers");
} catch (RemoteException e) {
Log.i(TAG, "Issue with invoking error response: " + e.getMessage());
Slog.e(TAG, "Issue with invoking error response: ", e);
return;
}
}
@@ -653,7 +648,7 @@ public final class CredentialManagerService
try {
callback.onResponse();
} catch (RemoteException e) {
Log.i(TAG, "Issue with invoking response: " + e.getMessage());
Slog.e(TAG, "Issue with invoking response: ", e);
// TODO: Propagate failure
}
@@ -665,7 +660,8 @@ public final class CredentialManagerService
@Override
public boolean isEnabledCredentialProviderService(
ComponentName componentName, String callingPackage) {
Log.i(TAG, "isEnabledCredentialProviderService");
Slog.d(TAG, "isEnabledCredentialProviderService with componentName: "
+ componentName.flattenToString());
// TODO(253157366): Check additional set of services.
final int userId = UserHandle.getCallingUserId();
@@ -683,10 +679,10 @@ public final class CredentialManagerService
MetricUtilities.logApiCalled(
ApiName.IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE,
ApiStatus.FAILURE, callingUid);
Log.w(
Slog.w(
TAG,
"isEnabledCredentialProviderService: Component name does not"
+ " match package name.");
"isEnabledCredentialProviderService: Component name does "
+ "not match package name.");
return false;
}
MetricUtilities.logApiCalled(ApiName.IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE,
@@ -703,7 +699,6 @@ public final class CredentialManagerService
@Override
public List<CredentialProviderInfo> getCredentialProviderServices(
int userId, int providerFilter) {
Log.i(TAG, "getCredentialProviderServices");
verifyGetProvidersPermission();
return CredentialProviderInfoFactory.getCredentialProviderServices(
@@ -713,7 +708,6 @@ public final class CredentialManagerService
@Override
public List<CredentialProviderInfo> getCredentialProviderServicesForTesting(
int providerFilter) {
Log.i(TAG, "getCredentialProviderServicesForTesting");
verifyGetProvidersPermission();
final int userId = UserHandle.getCallingUserId();
@@ -734,8 +728,8 @@ public final class CredentialManagerService
.getServiceInfo().getComponentName());
} catch (NullPointerException e) {
// Safe check
Log.i(TAG, "Skipping provider as either the providerInfo"
+ "or serviceInfo is null - weird");
Slog.e(TAG, "Skipping provider as either the providerInfo"
+ " or serviceInfo is null - weird");
}
});
}
@@ -748,7 +742,8 @@ public final class CredentialManagerService
IClearCredentialStateCallback callback,
String callingPackage) {
final long timestampBegan = System.nanoTime();
Log.i(TAG, "starting clearCredentialState with callingPackage: " + callingPackage);
Slog.d(TAG, "starting clearCredentialState with callingPackage: "
+ callingPackage);
final int userId = UserHandle.getCallingUserId();
int callingUid = Binder.getCallingUid();
enforceCallingPackage(callingPackage, callingUid);
@@ -775,13 +770,13 @@ public final class CredentialManagerService
if (providerSessions.isEmpty()) {
try {
// TODO("Replace with properly defined error type")
callback.onError("UNKNOWN", "No crdentials available on this " + "device");
callback.onError("UNKNOWN", "No credentials available on "
+ "this device");
} catch (RemoteException e) {
Log.i(
Slog.e(
TAG,
"Issue invoking onError on IClearCredentialStateCallback "
+ "callback: "
+ e.getMessage());
+ "callback: ", e);
}
}
@@ -796,7 +791,7 @@ public final class CredentialManagerService
public void registerCredentialDescription(
RegisterCredentialDescriptionRequest request, String callingPackage)
throws IllegalArgumentException, NonCredentialProviderCallerException {
Log.i(TAG, "registerCredentialDescription");
Slog.d(TAG, "registerCredentialDescription with callingPackage: " + callingPackage);
if (!isCredentialDescriptionApiEnabled()) {
throw new UnsupportedOperationException();
@@ -814,7 +809,9 @@ public final class CredentialManagerService
public void unregisterCredentialDescription(
UnregisterCredentialDescriptionRequest request, String callingPackage)
throws IllegalArgumentException {
Log.i(TAG, "registerCredentialDescription");
Slog.d(TAG, "unregisterCredentialDescription with callingPackage: "
+ callingPackage);
if (!isCredentialDescriptionApiEnabled()) {
throw new UnsupportedOperationException();

View File

@@ -23,7 +23,6 @@ import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.credentials.CredentialProviderInfo;
import android.service.credentials.CredentialProviderInfoFactory;
import android.util.Log;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
@@ -41,14 +40,15 @@ public final class CredentialManagerServiceImpl extends
// TODO(b/210531) : Make final when update flow is fixed
@GuardedBy("mLock")
@NonNull private CredentialProviderInfo mInfo;
@NonNull
private CredentialProviderInfo mInfo;
CredentialManagerServiceImpl(
@NonNull CredentialManagerService master,
@NonNull Object lock, int userId, String serviceName)
throws PackageManager.NameNotFoundException {
super(master, lock, userId);
Log.i(TAG, "in CredentialManagerServiceImpl constructed with: " + serviceName);
Slog.d(TAG, "CredentialManagerServiceImpl constructed for: " + serviceName);
synchronized (mLock) {
newServiceInfoLocked(ComponentName.unflattenFromString(serviceName));
}
@@ -63,10 +63,8 @@ public final class CredentialManagerServiceImpl extends
@NonNull CredentialManagerService master,
@NonNull Object lock, int userId, CredentialProviderInfo providerInfo) {
super(master, lock, userId);
Log.i(TAG, "in CredentialManagerServiceImpl constructed with system constructor: "
+ providerInfo.isSystemProvider()
+ " , " + providerInfo.getServiceInfo() == null ? "" :
providerInfo.getServiceInfo().getComponentName().flattenToString());
Slog.d(TAG, "CredentialManagerServiceImpl constructed for: "
+ providerInfo.getServiceInfo().getComponentName().flattenToString());
mInfo = providerInfo;
}
@@ -76,12 +74,12 @@ public final class CredentialManagerServiceImpl extends
throws PackageManager.NameNotFoundException {
// TODO : Test update flows with multiple providers
if (mInfo != null) {
Log.i(TAG, "newServiceInfoLocked with : "
Slog.d(TAG, "newServiceInfoLocked, mInfo not null : "
+ mInfo.getServiceInfo().getComponentName().flattenToString() + " , "
+ serviceComponent.getPackageName());
+ serviceComponent.flattenToString());
} else {
Log.i(TAG, "newServiceInfoLocked with null mInfo , "
+ serviceComponent.getPackageName());
Slog.d(TAG, "newServiceInfoLocked, mInfo null, "
+ serviceComponent.flattenToString());
}
mInfo = CredentialProviderInfoFactory.create(
getContext(), serviceComponent,
@@ -90,18 +88,18 @@ public final class CredentialManagerServiceImpl extends
}
/**
* Starts a provider session and associates it with the given request session. */
* Starts a provider session and associates it with the given request session.
*/
@Nullable
@GuardedBy("mLock")
public ProviderSession initiateProviderSessionForRequestLocked(
RequestSession requestSession, List<String> requestOptions) {
if (!requestOptions.isEmpty() && !isServiceCapableLocked(requestOptions)) {
Log.i(TAG, "Service is not capable");
Slog.d(TAG, "Service does not have the required capabilities");
return null;
}
Slog.i(TAG, "in initiateProviderSessionForRequest in CredManServiceImpl");
if (mInfo == null) {
Slog.i(TAG, "in initiateProviderSessionForRequest in CredManServiceImpl, "
Slog.w(TAG, "in initiateProviderSessionForRequest in CredManServiceImpl, "
+ "but mInfo is null. This shouldn't happen");
return null;
}
@@ -114,15 +112,11 @@ public final class CredentialManagerServiceImpl extends
@GuardedBy("mLock")
boolean isServiceCapableLocked(List<String> requestedOptions) {
if (mInfo == null) {
Slog.i(TAG, "in isServiceCapable, mInfo is null");
return false;
}
for (String capability : requestedOptions) {
if (mInfo.hasCapability(capability)) {
Slog.i(TAG, "Provider can handle: " + capability);
return true;
} else {
Slog.i(TAG, "Provider cannot handle: " + capability);
}
}
return false;
@@ -146,7 +140,7 @@ public final class CredentialManagerServiceImpl extends
try {
newServiceInfoLocked(mInfo.getServiceInfo().getComponentName());
} catch (PackageManager.NameNotFoundException e) {
Log.i(TAG, "Issue while updating serviceInfo: " + e.getMessage());
Slog.e(TAG, "Issue while updating serviceInfo: " + e.getMessage());
}
}
}