summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Reema Bajwa <reemabajwa@google.com> 2024-03-21 13:56:01 +0000
committer Reema Bajwa <reemabajwa@google.com> 2024-03-26 18:49:10 +0000
commita68c461c04d54e00d49f2df9f50f70ab56279119 (patch)
treea73749897b302a3fdefa6e0a9ed991eb09c55256
parent65f13a355248926a720a2675f919255ebcbb5768 (diff)
Add config for cedman-autofill service
Test: Cts tests Bug: 329664717 Change-Id: I4a6567d874863766228921e144d9d15ef415ddbf
-rw-r--r--core/java/android/service/autofill/AutofillServiceInfo.java17
-rw-r--r--core/res/res/values/config.xml12
-rw-r--r--core/res/res/values/symbols.xml1
-rw-r--r--services/autofill/java/com/android/server/autofill/AutofillManagerService.java13
-rw-r--r--services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java3
-rw-r--r--services/autofill/java/com/android/server/autofill/RemoteFillService.java9
-rw-r--r--services/autofill/java/com/android/server/autofill/SecondaryProviderHandler.java5
-rw-r--r--services/autofill/java/com/android/server/autofill/Session.java33
8 files changed, 73 insertions, 20 deletions
diff --git a/core/java/android/service/autofill/AutofillServiceInfo.java b/core/java/android/service/autofill/AutofillServiceInfo.java
index 83f96629a582..0e67477fbd8e 100644
--- a/core/java/android/service/autofill/AutofillServiceInfo.java
+++ b/core/java/android/service/autofill/AutofillServiceInfo.java
@@ -312,6 +312,7 @@ public final class AutofillServiceInfo {
final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
try {
if (serviceInfo != null && isCredentialManagerAutofillService(
+ context,
serviceInfo.getComponentName())) {
// Skip this service as it is for internal use only
continue;
@@ -325,11 +326,23 @@ public final class AutofillServiceInfo {
return services;
}
- private static boolean isCredentialManagerAutofillService(ComponentName componentName) {
+ private static boolean isCredentialManagerAutofillService(Context context,
+ ComponentName componentName) {
if (componentName == null) {
return false;
}
- return componentName.equals(CREDMAN_SERVICE_COMPONENT_NAME);
+ ComponentName credAutofillService = null;
+ String credentialManagerAutofillCompName = context.getResources().getString(
+ R.string.config_defaultCredentialManagerAutofillService);
+ if (credentialManagerAutofillCompName != null && !credentialManagerAutofillCompName
+ .isEmpty()) {
+ credAutofillService = ComponentName.unflattenFromString(
+ credentialManagerAutofillCompName);
+ } else {
+ Log.w(TAG, "Invalid CredentialAutofillService");
+ }
+
+ return componentName.equals(credAutofillService);
}
@Override
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index e3f1cb619eb5..15ae3734c670 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -4795,6 +4795,18 @@
See android.credentials.CredentialManager
-->
<string name="config_defaultCredentialManagerHybridService" translatable="false"></string>
+
+ <!-- The component name, flattened to a string, for the system's credential manager
+ autofill service. This service allows interceding autofill requests and routing
+ them to credential manager.
+
+ This service must be trusted, as it can be activated without explicit consent of the user.
+ If no service with the specified name exists on the device, autofill will still
+ work with the user configured autofill service
+
+ See android.credentials.CredentialManager
+ -->
+ <string name="config_defaultCredentialManagerAutofillService" translatable="false"></string>
<!-- The component name(s), flattened to a string, for the system's credential manager
provider services. These services allow retrieving and storing credentials.
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index f4b42f6b3fb2..7593ca215f52 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3897,6 +3897,7 @@
<java-symbol type="string" name="config_defaultAppPredictionService" />
<java-symbol type="string" name="config_defaultContentSuggestionsService" />
<java-symbol type="string" name="config_defaultCredentialManagerHybridService" />
+ <java-symbol type="string" name="config_defaultCredentialManagerAutofillService" />
<java-symbol type="array" name="config_enabledCredentialProviderService" />
<java-symbol type="array" name="config_primaryCredentialProviderService" />
<java-symbol type="string" name="config_defaultSearchUiService" />
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java
index e4f1d3acce6d..1aa22505e3df 100644
--- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java
+++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java
@@ -79,6 +79,7 @@ import android.view.autofill.AutofillValue;
import android.view.autofill.IAutoFillManager;
import android.view.autofill.IAutoFillManagerClient;
+import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.infra.AbstractRemoteService;
@@ -159,6 +160,7 @@ public final class AutofillManagerService
final FrameworkResourcesServiceNameResolver mFieldClassificationResolver;
private final AutoFillUI mUi;
+ final ComponentName mCredentialAutofillService;
private final LocalLog mRequestsHistory = new LocalLog(20);
private final LocalLog mUiLatencyHistory = new LocalLog(20);
@@ -288,6 +290,16 @@ public final class AutofillManagerService
mAugmentedAutofillResolver.isTemporary(userId));
}
}
+ String credentialManagerAutofillCompName = context.getResources().getString(
+ R.string.config_defaultCredentialManagerAutofillService);
+ if (credentialManagerAutofillCompName != null
+ && !credentialManagerAutofillCompName.isEmpty()) {
+ mCredentialAutofillService = ComponentName.unflattenFromString(
+ credentialManagerAutofillCompName);
+ } else {
+ mCredentialAutofillService = null;
+ Slog.w(TAG, "Invalid CredentialAutofillService");
+ }
}
@Override // from AbstractMasterSystemService
@@ -416,7 +428,6 @@ public final class AutofillManagerService
} finally {
Binder.restoreCallingIdentity(token);
}
-
return managerService;
}
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
index e1291e5f75ec..365fef226f11 100644
--- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
+++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
@@ -1264,7 +1264,8 @@ final class AutofillManagerServiceImpl
RemoteFillService remoteService =
new RemoteFillService(
getContext(), mInfo.getServiceInfo().getComponentName(), mUserId,
- /* callbacks= */ null, mMaster.isInstantServiceAllowed());
+ /* callbacks= */ null, mMaster.isInstantServiceAllowed(),
+ mMaster.mCredentialAutofillService);
remoteService.onSavedPasswordCountRequest(receiver);
}
diff --git a/services/autofill/java/com/android/server/autofill/RemoteFillService.java b/services/autofill/java/com/android/server/autofill/RemoteFillService.java
index f914ed54fbb1..c96688c1b9ae 100644
--- a/services/autofill/java/com/android/server/autofill/RemoteFillService.java
+++ b/services/autofill/java/com/android/server/autofill/RemoteFillService.java
@@ -62,10 +62,6 @@ final class RemoteFillService extends ServiceConnector.Impl<IAutoFillService> {
private static final long TIMEOUT_IDLE_BIND_MILLIS = 5 * DateUtils.SECOND_IN_MILLIS;
private static final long TIMEOUT_REMOTE_REQUEST_MILLIS = 5 * DateUtils.SECOND_IN_MILLIS;
- private static final ComponentName CREDMAN_SERVICE_COMPONENT_NAME =
- new ComponentName("com.android.credentialmanager",
- "com.android.credentialmanager.autofill.CredentialAutofillService");
-
private final FillServiceCallbacks mCallbacks;
private final Object mLock = new Object();
private CompletableFuture<FillResponse> mPendingFillRequest;
@@ -102,14 +98,15 @@ final class RemoteFillService extends ServiceConnector.Impl<IAutoFillService> {
}
RemoteFillService(Context context, ComponentName componentName, int userId,
- FillServiceCallbacks callbacks, boolean bindInstantServiceAllowed) {
+ FillServiceCallbacks callbacks, boolean bindInstantServiceAllowed,
+ @Nullable ComponentName credentialAutofillService) {
super(context, new Intent(AutofillService.SERVICE_INTERFACE).setComponent(componentName),
Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS
| (bindInstantServiceAllowed ? Context.BIND_ALLOW_INSTANT : 0),
userId, IAutoFillService.Stub::asInterface);
mCallbacks = callbacks;
mComponentName = componentName;
- mIsCredentialAutofillService = mComponentName.equals(CREDMAN_SERVICE_COMPONENT_NAME);
+ mIsCredentialAutofillService = mComponentName.equals(credentialAutofillService);
}
@Override // from ServiceConnector.Impl
diff --git a/services/autofill/java/com/android/server/autofill/SecondaryProviderHandler.java b/services/autofill/java/com/android/server/autofill/SecondaryProviderHandler.java
index 0af703e415ff..450677968065 100644
--- a/services/autofill/java/com/android/server/autofill/SecondaryProviderHandler.java
+++ b/services/autofill/java/com/android/server/autofill/SecondaryProviderHandler.java
@@ -59,9 +59,10 @@ final class SecondaryProviderHandler implements RemoteFillService.FillServiceCal
SecondaryProviderHandler(
@NonNull Context context, int userId, boolean bindInstantServiceAllowed,
- SecondaryProviderCallback callback, ComponentName componentName) {
+ SecondaryProviderCallback callback, ComponentName componentName,
+ @Nullable ComponentName credentialAutofillService) {
mRemoteFillService = new RemoteFillService(context, componentName, userId, this,
- bindInstantServiceAllowed);
+ bindInstantServiceAllowed, credentialAutofillService);
mCallback = callback;
Slog.v(TAG, "Creating a secondary provider handler with component name, " + componentName);
}
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index d006cf6d703a..66ddef9ca85b 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -242,10 +242,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
private static final int DEFAULT__FILL_REQUEST_ID_SNAPSHOT = -2;
private static final int DEFAULT__FIELD_CLASSIFICATION_REQUEST_ID_SNAPSHOT = -2;
- private static final ComponentName CREDMAN_SERVICE_COMPONENT_NAME =
- new ComponentName("com.android.credentialmanager",
- "com.android.credentialmanager.autofill.CredentialAutofillService");
-
static final String SESSION_ID_KEY = "autofill_session_id";
static final String REQUEST_ID_KEY = "autofill_request_id";
@@ -522,6 +518,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
private final ClassificationState mClassificationState = new ClassificationState();
+ @Nullable
+ private final ComponentName mCredentialAutofillService;
+
// TODO(b/216576510): Share one BroadcastReceiver between all Sessions instead of creating a
// new one per Session.
private final BroadcastReceiver mDelayedFillBroadcastReceiver =
@@ -1471,23 +1470,26 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
mUi = ui;
mHandler = handler;
+ mCredentialAutofillService = getCredentialAutofillService(context);
+
ComponentName primaryServiceComponentName, secondaryServiceComponentName;
if (isPrimaryCredential) {
- primaryServiceComponentName = CREDMAN_SERVICE_COMPONENT_NAME;
+ primaryServiceComponentName = mCredentialAutofillService;
secondaryServiceComponentName = serviceComponentName;
} else {
primaryServiceComponentName = serviceComponentName;
- secondaryServiceComponentName = CREDMAN_SERVICE_COMPONENT_NAME;
+ secondaryServiceComponentName = mCredentialAutofillService;
}
Slog.v(TAG, "Primary service component name: " + primaryServiceComponentName
+ ", secondary service component name: " + secondaryServiceComponentName);
mRemoteFillService = primaryServiceComponentName == null ? null
: new RemoteFillService(context, primaryServiceComponentName, userId, this,
- bindInstantServiceAllowed);
+ bindInstantServiceAllowed, mCredentialAutofillService);
mSecondaryProviderHandler = secondaryServiceComponentName == null ? null
: new SecondaryProviderHandler(context, userId, bindInstantServiceAllowed,
- this::onSecondaryFillResponse, secondaryServiceComponentName);
+ this::onSecondaryFillResponse, secondaryServiceComponentName,
+ mCredentialAutofillService);
mActivityToken = activityToken;
mHasCallback = hasCallback;
mUiLatencyHistory = uiLatencyHistory;
@@ -1546,6 +1548,21 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
mLogViewEntered = false;
}
+ private ComponentName getCredentialAutofillService(Context context) {
+ ComponentName componentName = null;
+ String credentialManagerAutofillCompName = context.getResources().getString(
+ R.string.config_defaultCredentialManagerAutofillService);
+ if (credentialManagerAutofillCompName != null
+ && !credentialManagerAutofillCompName.isEmpty()) {
+ componentName = ComponentName.unflattenFromString(
+ credentialManagerAutofillCompName);
+ }
+ if (componentName == null) {
+ Slog.w(TAG, "Invalid CredentialAutofillService");
+ }
+ return componentName;
+ }
+
/**
* Gets the currently registered activity token
*