Fix inline extservices implementation for multiuser.

Fixes: 148428064
Test: atest android.inputmethodservice.cts.hostside.MultiuserTest
Change-Id: I0c4966329189b0c1f141a14755033d795b560885
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
index e28ef0f..4f18f35 100644
--- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
+++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
@@ -216,7 +216,7 @@
         updateRemoteAugmentedAutofillService();
 
         final ComponentName componentName = RemoteInlineSuggestionRenderService
-                .getServiceComponentName(getContext());
+                .getServiceComponentName(getContext(), mUserId);
         if (componentName != null) {
             mRemoteInlineSuggestionRenderService = new RemoteInlineSuggestionRenderService(
                     getContext(), componentName, InlineSuggestionRenderService.SERVICE_INTERFACE,
diff --git a/services/autofill/java/com/android/server/autofill/RemoteInlineSuggestionRenderService.java b/services/autofill/java/com/android/server/autofill/RemoteInlineSuggestionRenderService.java
index f9e08e6..31dc23f 100644
--- a/services/autofill/java/com/android/server/autofill/RemoteInlineSuggestionRenderService.java
+++ b/services/autofill/java/com/android/server/autofill/RemoteInlineSuggestionRenderService.java
@@ -20,6 +20,7 @@
 import android.Manifest;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.annotation.UserIdInt;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -86,7 +87,7 @@
     }
 
     @Nullable
-    private static ServiceInfo getServiceInfo(Context context) {
+    private static ServiceInfo getServiceInfo(Context context, int userId) {
         final String packageName =
                 context.getPackageManager().getServicesSystemSharedLibraryPackageName();
         if (packageName == null) {
@@ -96,8 +97,8 @@
 
         final Intent intent = new Intent(InlineSuggestionRenderService.SERVICE_INTERFACE);
         intent.setPackage(packageName);
-        final ResolveInfo resolveInfo = context.getPackageManager().resolveService(intent,
-                PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
+        final ResolveInfo resolveInfo = context.getPackageManager().resolveServiceAsUser(intent,
+                PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, userId);
         final ServiceInfo serviceInfo = resolveInfo == null ? null : resolveInfo.serviceInfo;
         if (resolveInfo == null || serviceInfo == null) {
             Slog.w(TAG, "No valid components found.");
@@ -115,8 +116,8 @@
     }
 
     @Nullable
-    public static ComponentName getServiceComponentName(Context context) {
-        final ServiceInfo serviceInfo = getServiceInfo(context);
+    public static ComponentName getServiceComponentName(Context context, @UserIdInt int userId) {
+        final ServiceInfo serviceInfo = getServiceInfo(context, userId);
         if (serviceInfo == null) return null;
 
         final ComponentName componentName = new ComponentName(serviceInfo.packageName,