summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tim Yu <yunicorn@google.com> 2025-03-12 22:33:31 -0700
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2025-03-12 22:33:31 -0700
commit46caf6b6dc358e68199310bc718dee4c20335a5b (patch)
tree2effc577a902839ca8f11f6becab38a0df3bfec1
parent2ce896fb8c136f53f4e300703e7c559739859829 (diff)
parent28c42ccc8c0074a1b7bd20592db936647c4fe97e (diff)
[RESTRICT AUTOMERGE] Fix Autofill Inflating as User 0 am: 28c42ccc8c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/29639115 Change-Id: Idf1ab141cd1670e56f4910c91d9471c0c2991a90 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--services/autofill/java/com/android/server/autofill/Helper.java24
-rw-r--r--services/autofill/java/com/android/server/autofill/Session.java34
-rw-r--r--services/autofill/java/com/android/server/autofill/ui/DialogFillUi.java10
-rw-r--r--services/autofill/java/com/android/server/autofill/ui/FillUi.java13
-rw-r--r--services/autofill/java/com/android/server/autofill/ui/SaveUi.java5
5 files changed, 68 insertions, 18 deletions
diff --git a/services/autofill/java/com/android/server/autofill/Helper.java b/services/autofill/java/com/android/server/autofill/Helper.java
index 7557071d0d4b..6bbb5ce96aed 100644
--- a/services/autofill/java/com/android/server/autofill/Helper.java
+++ b/services/autofill/java/com/android/server/autofill/Helper.java
@@ -16,10 +16,13 @@
package com.android.server.autofill;
+import static android.Manifest.permission.INTERACT_ACROSS_USERS;
+
import static com.android.server.autofill.Helper.sDebug;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.assist.AssistStructure;
@@ -29,6 +32,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.metrics.LogMaker;
+import android.os.UserHandle;
import android.os.UserManager;
import android.service.autofill.Dataset;
import android.service.autofill.InternalSanitizer;
@@ -102,6 +106,26 @@ public final class Helper {
}
/**
+ * Creates the context as the foreground user
+ *
+ * <p>Returns the current context as the current foreground user
+ */
+ @RequiresPermission(INTERACT_ACROSS_USERS)
+ public static Context getUserContext(Context context) {
+ int userId = ActivityManager.getCurrentUser();
+ Context c = context.createContextAsUser(UserHandle.of(userId), /* flags= */ 0);
+ if (sDebug) {
+ Slog.d(
+ TAG,
+ "Current User: "
+ + userId
+ + ", context created as: "
+ + c.getContentResolver().getUserId());
+ }
+ return c;
+ }
+
+ /**
* Checks the URI permissions of the remote view,
* to see if the current userId is able to access it.
*
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index fb26f427dad7..6797333c1c6d 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -4490,11 +4490,17 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
// Try to get the custom Icon, if one was passed through FillResponse
int iconResourceId = response.getIconResourceId();
if (iconResourceId != 0) {
- serviceIcon = mService.getMaster().getContext().getPackageManager()
- .getDrawable(
- mService.getServicePackageName(),
- iconResourceId,
- null);
+ long token = Binder.clearCallingIdentity();
+ try {
+ serviceIcon =
+ mService.getMaster()
+ .getContext()
+ .getPackageManager()
+ .getDrawable(
+ mService.getServicePackageName(), iconResourceId, null);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
// Custom icon wasn't fetched, use the default package icon instead
@@ -4520,11 +4526,19 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
// Try to get the custom Service name, if one was passed through FillResponse
int customServiceNameId = response.getServiceDisplayNameResourceId();
if (customServiceNameId != 0) {
- serviceLabel = mService.getMaster().getContext().getPackageManager()
- .getText(
- mService.getServicePackageName(),
- customServiceNameId,
- null);
+ long token = Binder.clearCallingIdentity();
+ try {
+ serviceLabel =
+ mService.getMaster()
+ .getContext()
+ .getPackageManager()
+ .getText(
+ mService.getServicePackageName(),
+ customServiceNameId,
+ null);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
// Custom label wasn't fetched, use the default package name instead
diff --git a/services/autofill/java/com/android/server/autofill/ui/DialogFillUi.java b/services/autofill/java/com/android/server/autofill/ui/DialogFillUi.java
index fa414e3b172b..5a71b895a57c 100644
--- a/services/autofill/java/com/android/server/autofill/ui/DialogFillUi.java
+++ b/services/autofill/java/com/android/server/autofill/ui/DialogFillUi.java
@@ -95,6 +95,7 @@ final class DialogFillUi {
private final ComponentName mComponentName;
private final int mThemeId;
private final @NonNull Context mContext;
+ private final @NonNull Context mUserContext;
private final @NonNull UiCallback mCallback;
private final @NonNull ListView mListView;
private final @Nullable ItemsAdapter mAdapter;
@@ -104,6 +105,8 @@ final class DialogFillUi {
private @Nullable AnnounceFilterResult mAnnounceFilterResult;
private boolean mDestroyed;
+ // System has all permissions, see b/228957088
+ @SuppressWarnings("AndroidFrameworkRequiresPermission")
DialogFillUi(@NonNull Context context, @NonNull FillResponse response,
@NonNull AutofillId focusedViewId, @Nullable String filterText,
@Nullable Drawable serviceIcon, @Nullable String servicePackageName,
@@ -117,6 +120,7 @@ final class DialogFillUi {
mComponentName = componentName;
mContext = new ContextThemeWrapper(context, mThemeId);
+ mUserContext = Helper.getUserContext(mContext);
final LayoutInflater inflater = LayoutInflater.from(mContext);
final View decor = inflater.inflate(R.layout.autofill_fill_dialog, null);
@@ -224,7 +228,7 @@ final class DialogFillUi {
};
final View content = presentation.applyWithTheme(
- mContext, (ViewGroup) decor, interceptionHandler, mThemeId);
+ mUserContext, (ViewGroup) decor, interceptionHandler, mThemeId);
container.addView(content);
container.setVisibility(View.VISIBLE);
}
@@ -263,7 +267,7 @@ final class DialogFillUi {
return true;
};
final View content = presentation.applyWithTheme(
- mContext, (ViewGroup) decor, interceptionHandler, mThemeId);
+ mUserContext, (ViewGroup) decor, interceptionHandler, mThemeId);
container.addView(content);
container.setVisibility(View.VISIBLE);
container.setFocusable(true);
@@ -305,7 +309,7 @@ final class DialogFillUi {
try {
if (sVerbose) Slog.v(TAG, "setting remote view for " + focusedViewId);
view = presentation.applyWithTheme(
- mContext, null, interceptionHandler, mThemeId);
+ mUserContext, null, interceptionHandler, mThemeId);
} catch (RuntimeException e) {
Slog.e(TAG, "Error inflating remote views", e);
continue;
diff --git a/services/autofill/java/com/android/server/autofill/ui/FillUi.java b/services/autofill/java/com/android/server/autofill/ui/FillUi.java
index cdfe7bb4f4a7..80e23d261357 100644
--- a/services/autofill/java/com/android/server/autofill/ui/FillUi.java
+++ b/services/autofill/java/com/android/server/autofill/ui/FillUi.java
@@ -102,6 +102,7 @@ final class FillUi {
new AutofillWindowPresenter();
private final @NonNull Context mContext;
+ private final @NonNull Context mUserContext;
private final @NonNull AnchoredWindow mWindow;
@@ -134,6 +135,8 @@ final class FillUi {
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
}
+ // System has all permissions, see b/228957088
+ @SuppressWarnings("AndroidFrameworkRequiresPermission")
FillUi(@NonNull Context context, @NonNull FillResponse response,
@NonNull AutofillId focusedViewId, @Nullable String filterText,
@NonNull OverlayControl overlayControl, @NonNull CharSequence serviceLabel,
@@ -145,6 +148,7 @@ final class FillUi {
mCallback = callback;
mFullScreen = isFullScreen(context);
mContext = new ContextThemeWrapper(context, mThemeId);
+ mUserContext = Helper.getUserContext(mContext);
final LayoutInflater inflater = LayoutInflater.from(mContext);
@@ -232,7 +236,7 @@ final class FillUi {
throw new RuntimeException("Permission error accessing RemoteView");
}
content = response.getPresentation().applyWithTheme(
- mContext, decor, interceptionHandler, mThemeId);
+ mUserContext, decor, interceptionHandler, mThemeId);
container.addView(content);
} catch (RuntimeException e) {
callback.onCanceled();
@@ -273,7 +277,7 @@ final class FillUi {
if (headerPresentation != null) {
interactionBlocker = newInteractionBlocker();
mHeader = headerPresentation.applyWithTheme(
- mContext, null, interactionBlocker, mThemeId);
+ mUserContext, null, interactionBlocker, mThemeId);
final LinearLayout headerContainer =
decor.findViewById(R.id.autofill_dataset_header);
applyCancelAction(mHeader, response.getCancelIds());
@@ -292,7 +296,7 @@ final class FillUi {
interactionBlocker = newInteractionBlocker();
}
mFooter = footerPresentation.applyWithTheme(
- mContext, null, interactionBlocker, mThemeId);
+ mUserContext, null, interactionBlocker, mThemeId);
applyCancelAction(mFooter, response.getCancelIds());
// Footer not supported on some platform e.g. TV
if (sVerbose) Slog.v(TAG, "adding footer");
@@ -321,7 +325,7 @@ final class FillUi {
try {
if (sVerbose) Slog.v(TAG, "setting remote view for " + focusedViewId);
view = presentation.applyWithTheme(
- mContext, null, interceptionHandler, mThemeId);
+ mUserContext, null, interceptionHandler, mThemeId);
} catch (RuntimeException e) {
Slog.e(TAG, "Error inflating remote views", e);
continue;
@@ -783,6 +787,7 @@ final class FillUi {
pw.print(prefix); pw.print("mContentHeight: "); pw.println(mContentHeight);
pw.print(prefix); pw.print("mDestroyed: "); pw.println(mDestroyed);
pw.print(prefix); pw.print("mContext: "); pw.println(mContext);
+ pw.print(prefix); pw.print("mUserContext: "); pw.println(mUserContext);
pw.print(prefix); pw.print("theme id: "); pw.print(mThemeId);
switch (mThemeId) {
case THEME_ID_DARK:
diff --git a/services/autofill/java/com/android/server/autofill/ui/SaveUi.java b/services/autofill/java/com/android/server/autofill/ui/SaveUi.java
index 70382f1d5274..c4fb9da70208 100644
--- a/services/autofill/java/com/android/server/autofill/ui/SaveUi.java
+++ b/services/autofill/java/com/android/server/autofill/ui/SaveUi.java
@@ -174,6 +174,8 @@ final class SaveUi {
private boolean mDestroyed;
+ // System has all permissions, see b/228957088
+ @SuppressWarnings("AndroidFrameworkRequiresPermission")
SaveUi(@NonNull Context context, @NonNull PendingUi pendingUi,
@NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon,
@Nullable String servicePackageName, @NonNull ComponentName componentName,
@@ -191,7 +193,7 @@ final class SaveUi {
mComponentName = componentName;
mCompatMode = compatMode;
- context = new ContextThemeWrapper(context, mThemeId) {
+ context = new ContextThemeWrapper(Helper.getUserContext(context), mThemeId) {
@Override
public void startActivity(Intent intent) {
if (resolveActivity(intent) == null) {
@@ -230,6 +232,7 @@ final class SaveUi {
return null;
}
};
+
final LayoutInflater inflater = LayoutInflater.from(context);
final View view = inflater.inflate(R.layout.autofill_save, null);