From 5c0f07c4f6d7e3c70dfc637abd3e6c5480c50ef6 Mon Sep 17 00:00:00 2001 From: paulhu Date: Thu, 26 Dec 2019 17:08:52 +0800 Subject: [PATCH] Add an override for getUser in ContextWrapper This is to fix an issue when calling getUser for a context that is different than the context of the current foreground user. getUser for a ContextWrapper would call the base class Context#getUser which returns the user of the current foreground process rather than returning the user of the calling context. Currently, this is a bug that does not meet the ContextWrapper class Javadoc. It looks like the ContextWrapper call was missed in Ib772ec4438e57a2ad4950821b9432f9842998451. Fix: 144024489 Test: called the API from a test App with a different context than the current application context. Change-Id: I58ec9fda24bf135ba8c648a905ef0c81d36ea098 Merged-In: I2d24f5141e8cbc2546c8dc5894a1aeab376b7632 (cherry-pick from ag/9673528) --- core/java/android/content/ContextWrapper.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java index 22b345faf816..877557f4f590 100644 --- a/core/java/android/content/ContextWrapper.java +++ b/core/java/android/content/ContextWrapper.java @@ -943,6 +943,12 @@ public class ContextWrapper extends Context { return mBase.getUserId(); } + /** @hide */ + @Override + public UserHandle getUser() { + return mBase.getUser(); + } + @Override public Context createConfigurationContext(Configuration overrideConfiguration) { return mBase.createConfigurationContext(overrideConfiguration);