OSDN Git Service

Pass in the user defined by Context.
authorJeff Sharkey <jsharkey@android.com>
Fri, 2 Feb 2018 20:25:31 +0000 (13:25 -0700)
committerJeff Sharkey <jsharkey@google.com>
Sat, 3 Feb 2018 02:11:45 +0000 (02:11 +0000)
The majority of Manager-style classes already use Context.getUserId()
when making calls into the OS, so clean up the remaining callers to
unify behind this strategy.

This gives @SystemApi developers a nice clean interface to interact
across user boundaries, instead of manually adding "AsUser" or
"ForUser" method variants, which would quickly become unsustainable.

Test: builds, boots
Bug: 72863821
Exempt-From-Owner-Approval: trivial changes
Change-Id: Ib772ec4438e57a2ad4950821b9432f9842998451

50 files changed:
api/current.txt
api/test-current.txt
core/java/android/accounts/AccountManager.java
core/java/android/app/Activity.java
core/java/android/app/ActivityManager.java
core/java/android/app/AlarmManager.java
core/java/android/app/AppOpsManager.java
core/java/android/app/ApplicationPackageManager.java
core/java/android/app/ContextImpl.java
core/java/android/app/Instrumentation.java
core/java/android/app/KeyguardManager.java
core/java/android/app/NotificationManager.java
core/java/android/app/PendingIntent.java
core/java/android/app/SystemServiceRegistry.java
core/java/android/app/TaskStackBuilder.java
core/java/android/app/WallpaperManager.java
core/java/android/app/admin/DevicePolicyManager.java
core/java/android/app/usage/UsageStatsManager.java
core/java/android/appwidget/AppWidgetManager.java
core/java/android/bluetooth/BluetoothA2dp.java
core/java/android/bluetooth/BluetoothA2dpSink.java
core/java/android/bluetooth/BluetoothAvrcpController.java
core/java/android/bluetooth/BluetoothHeadsetClient.java
core/java/android/bluetooth/BluetoothHealth.java
core/java/android/bluetooth/BluetoothHidDevice.java
core/java/android/bluetooth/BluetoothHidHost.java
core/java/android/bluetooth/BluetoothMap.java
core/java/android/bluetooth/BluetoothMapClient.java
core/java/android/bluetooth/BluetoothPan.java
core/java/android/bluetooth/BluetoothPbap.java
core/java/android/bluetooth/BluetoothPbapClient.java
core/java/android/bluetooth/BluetoothSap.java
core/java/android/content/ContentResolver.java
core/java/android/content/Context.java
core/java/android/content/pm/PackageManager.java
core/java/android/content/pm/ResolveInfo.java
core/java/android/content/pm/ShortcutManager.java
core/java/android/database/AbstractCursor.java
core/java/android/hardware/display/DisplayManager.java
core/java/android/hardware/fingerprint/FingerprintManager.java
core/java/android/net/VpnService.java
core/java/android/nfc/NfcActivityManager.java
core/java/android/nfc/cardemulation/CardEmulation.java
core/java/android/nfc/cardemulation/NfcFCardEmulation.java
core/java/android/os/storage/StorageManager.java
core/java/android/provider/ContactsInternal.java
core/java/android/provider/Settings.java
core/java/android/text/format/DateFormat.java
core/java/android/view/accessibility/AccessibilityManager.java
core/java/com/android/internal/policy/PhoneWindow.java

index 10fdea4..c3e1ba0 100644 (file)
@@ -11616,15 +11616,15 @@ package android.content.res {
 
   public final class AssetManager implements java.lang.AutoCloseable {
     method public void close();
-    method public final java.lang.String[] getLocales();
-    method public final java.lang.String[] list(java.lang.String) throws java.io.IOException;
-    method public final java.io.InputStream open(java.lang.String) throws java.io.IOException;
-    method public final java.io.InputStream open(java.lang.String, int) throws java.io.IOException;
-    method public final android.content.res.AssetFileDescriptor openFd(java.lang.String) throws java.io.IOException;
-    method public final android.content.res.AssetFileDescriptor openNonAssetFd(java.lang.String) throws java.io.IOException;
-    method public final android.content.res.AssetFileDescriptor openNonAssetFd(int, java.lang.String) throws java.io.IOException;
-    method public final android.content.res.XmlResourceParser openXmlResourceParser(java.lang.String) throws java.io.IOException;
-    method public final android.content.res.XmlResourceParser openXmlResourceParser(int, java.lang.String) throws java.io.IOException;
+    method public java.lang.String[] getLocales();
+    method public java.lang.String[] list(java.lang.String) throws java.io.IOException;
+    method public java.io.InputStream open(java.lang.String) throws java.io.IOException;
+    method public java.io.InputStream open(java.lang.String, int) throws java.io.IOException;
+    method public android.content.res.AssetFileDescriptor openFd(java.lang.String) throws java.io.IOException;
+    method public android.content.res.AssetFileDescriptor openNonAssetFd(java.lang.String) throws java.io.IOException;
+    method public android.content.res.AssetFileDescriptor openNonAssetFd(int, java.lang.String) throws java.io.IOException;
+    method public android.content.res.XmlResourceParser openXmlResourceParser(java.lang.String) throws java.io.IOException;
+    method public android.content.res.XmlResourceParser openXmlResourceParser(int, java.lang.String) throws java.io.IOException;
     field public static final int ACCESS_BUFFER = 3; // 0x3
     field public static final int ACCESS_RANDOM = 1; // 0x1
     field public static final int ACCESS_STREAMING = 2; // 0x2
index 92bf24d..60e5c28 100644 (file)
@@ -183,10 +183,7 @@ package android.content {
   }
 
   public abstract class Context {
-    method public abstract int getUserId();
-  }
-
-  public class ContextWrapper extends android.content.Context {
+    method public android.os.UserHandle getUser();
     method public int getUserId();
   }
 
index 782733f..5176d71 100644 (file)
@@ -680,7 +680,7 @@ public class AccountManager {
      */
     @NonNull
     public Account[] getAccountsByType(String type) {
-        return getAccountsByTypeAsUser(type, Process.myUserHandle());
+        return getAccountsByTypeAsUser(type, mContext.getUser());
     }
 
     /** @hide Same as {@link #getAccountsByType(String)} but for a specific user. */
@@ -2006,7 +2006,7 @@ public class AccountManager {
             final AccountManagerCallback<Bundle> callback,
             final Handler handler) {
         return confirmCredentialsAsUser(account, options, activity, callback, handler,
-                Process.myUserHandle());
+                mContext.getUser());
     }
 
     /**
@@ -3208,7 +3208,7 @@ public class AccountManager {
         return finishSessionAsUser(
                 sessionBundle,
                 activity,
-                Process.myUserHandle(),
+                mContext.getUser(),
                 callback,
                 handler);
     }
index 04c44a3..d3ee590 100644 (file)
@@ -5832,7 +5832,7 @@ public class Activity extends ContextThemeWrapper
                         ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName,
                         mParent == null ? mToken : mParent.mToken,
                         mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null,
-                        UserHandle.myUserId());
+                        getUserId());
             return target != null ? new PendingIntent(target) : null;
         } catch (RemoteException e) {
             // Empty
index e2ce8b1..ae47a68 100644 (file)
@@ -1691,7 +1691,7 @@ public class ActivityManager {
             if (maxNum < 0) {
                 throw new IllegalArgumentException("The requested number of tasks should be >= 0");
             }
-            return getService().getRecentTasks(maxNum, flags, UserHandle.myUserId()).getList();
+            return getService().getRecentTasks(maxNum, flags, mContext.getUserId()).getList();
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -2685,7 +2685,7 @@ public class ActivityManager {
     public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
         try {
             return getService().clearApplicationUserData(packageName, false,
-                    observer, UserHandle.myUserId());
+                    observer, mContext.getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -2724,7 +2724,7 @@ public class ActivityManager {
         try {
             @SuppressWarnings("unchecked")
             final ParceledListSlice<GrantedUriPermission> castedList = getService()
-                    .getGrantedUriPermissions(packageName, UserHandle.myUserId());
+                    .getGrantedUriPermissions(packageName, mContext.getUserId());
             return castedList;
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
@@ -2743,7 +2743,7 @@ public class ActivityManager {
     public void clearGrantedUriPermissions(String packageName) {
         try {
             getService().clearGrantedUriPermissions(packageName,
-                    UserHandle.myUserId());
+                    mContext.getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -3528,7 +3528,7 @@ public class ActivityManager {
     public void killBackgroundProcesses(String packageName) {
         try {
             getService().killBackgroundProcesses(packageName,
-                    UserHandle.myUserId());
+                    mContext.getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -3586,7 +3586,7 @@ public class ActivityManager {
     @SystemApi
     @RequiresPermission(Manifest.permission.FORCE_STOP_PACKAGES)
     public void forceStopPackage(String packageName) {
-        forceStopPackageAsUser(packageName, UserHandle.myUserId());
+        forceStopPackageAsUser(packageName, mContext.getUserId());
     }
 
     /**
index 382719b..124f933 100644 (file)
@@ -178,6 +178,7 @@ public class AlarmManager {
     public static final int FLAG_IDLE_UNTIL = 1<<4;
 
     private final IAlarmManager mService;
+    private final Context mContext;
     private final String mPackageName;
     private final boolean mAlwaysExact;
     private final int mTargetSdkVersion;
@@ -265,6 +266,7 @@ public class AlarmManager {
     AlarmManager(IAlarmManager service, Context ctx) {
         mService = service;
 
+        mContext = ctx;
         mPackageName = ctx.getPackageName();
         mTargetSdkVersion = ctx.getApplicationInfo().targetSdkVersion;
         mAlwaysExact = (mTargetSdkVersion < Build.VERSION_CODES.KITKAT);
@@ -1028,7 +1030,7 @@ public class AlarmManager {
      * @see #ACTION_NEXT_ALARM_CLOCK_CHANGED
      */
     public AlarmClockInfo getNextAlarmClock() {
-        return getNextAlarmClock(UserHandle.myUserId());
+        return getNextAlarmClock(mContext.getUserId());
     }
 
     /**
index e923fb2..4c9fb74 100644 (file)
@@ -1670,7 +1670,7 @@ public class AppOpsManager {
     /** @hide */
     public void resetAllModes() {
         try {
-            mService.resetAllModes(UserHandle.myUserId(), null);
+            mService.resetAllModes(mContext.getUserId(), null);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
index 6b0a2f9..13117bc 100644 (file)
@@ -140,6 +140,11 @@ public class ApplicationPackageManager extends PackageManager {
     }
 
     @Override
+    public int getUserId() {
+        return mContext.getUserId();
+    }
+
+    @Override
     public PackageInfo getPackageInfo(String packageName, int flags)
             throws NameNotFoundException {
         return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
index 6496110..5ead18b 100644 (file)
@@ -164,7 +164,7 @@ class ContextImpl extends Context {
 
     private final @Nullable IBinder mActivityToken;
 
-    private final @Nullable UserHandle mUser;
+    private final @NonNull UserHandle mUser;
 
     private final ApplicationContentResolver mContentResolver;
 
@@ -1565,8 +1565,7 @@ class ContextImpl extends Context {
     public boolean bindService(Intent service, ServiceConnection conn,
             int flags) {
         warnIfCallingFromSystemProcess();
-        return bindServiceCommon(service, conn, flags, mMainThread.getHandler(),
-                Process.myUserHandle());
+        return bindServiceCommon(service, conn, flags, mMainThread.getHandler(), getUser());
     }
 
     /** @hide */
@@ -2038,8 +2037,7 @@ class ContextImpl extends Context {
     @Override
     public Context createPackageContext(String packageName, int flags)
             throws NameNotFoundException {
-        return createPackageContextAsUser(packageName, flags,
-                mUser != null ? mUser : Process.myUserHandle());
+        return createPackageContextAsUser(packageName, flags, mUser);
     }
 
     @Override
@@ -2235,6 +2233,12 @@ class ContextImpl extends Context {
 
     /** {@hide} */
     @Override
+    public UserHandle getUser() {
+        return mUser;
+    }
+
+    /** {@hide} */
+    @Override
     public int getUserId() {
         return mUser.getIdentifier();
     }
@@ -2382,7 +2386,7 @@ class ContextImpl extends Context {
             }
         }
 
-        mContentResolver = new ApplicationContentResolver(this, mainThread, user);
+        mContentResolver = new ApplicationContentResolver(this, mainThread);
     }
 
     void setResources(Resources r) {
@@ -2498,13 +2502,10 @@ class ContextImpl extends Context {
 
     private static final class ApplicationContentResolver extends ContentResolver {
         private final ActivityThread mMainThread;
-        private final UserHandle mUser;
 
-        public ApplicationContentResolver(
-                Context context, ActivityThread mainThread, UserHandle user) {
+        public ApplicationContentResolver(Context context, ActivityThread mainThread) {
             super(context);
             mMainThread = Preconditions.checkNotNull(mainThread);
-            mUser = Preconditions.checkNotNull(user);
         }
 
         @Override
@@ -2550,7 +2551,7 @@ class ContextImpl extends Context {
 
         /** @hide */
         protected int resolveUserIdFromAuthority(String auth) {
-            return ContentProvider.getUserIdFromAuthority(auth, mUser.getIdentifier());
+            return ContentProvider.getUserIdFromAuthority(auth, getUserId());
         }
     }
 }
index 67f5a2e..7f87814 100644 (file)
@@ -1679,7 +1679,7 @@ public class Instrumentation {
     public void execStartActivities(Context who, IBinder contextThread,
             IBinder token, Activity target, Intent[] intents, Bundle options) {
         execStartActivitiesAsUser(who, contextThread, token, target, intents, options,
-                UserHandle.myUserId());
+                who.getUserId());
     }
 
     /**
index 553099f..4a3fcaf 100644 (file)
@@ -407,7 +407,7 @@ public class KeyguardManager {
      * password.
      */
     public boolean isDeviceLocked() {
-        return isDeviceLocked(UserHandle.myUserId());
+        return isDeviceLocked(mContext.getUserId());
     }
 
     /**
@@ -432,7 +432,7 @@ public class KeyguardManager {
      * @return true if a PIN, pattern or password was set.
      */
     public boolean isDeviceSecure() {
-        return isDeviceSecure(UserHandle.myUserId());
+        return isDeviceSecure(mContext.getUserId());
     }
 
     /**
index 49c03ab..ae4ac3c 100644 (file)
@@ -351,7 +351,7 @@ public class NotificationManager {
      */
     public void notify(String tag, int id, Notification notification)
     {
-        notifyAsUser(tag, id, notification, new UserHandle(UserHandle.myUserId()));
+        notifyAsUser(tag, id, notification, mContext.getUser());
     }
 
     /**
@@ -412,7 +412,7 @@ public class NotificationManager {
      */
     public void cancel(String tag, int id)
     {
-        cancelAsUser(tag, id, new UserHandle(UserHandle.myUserId()));
+        cancelAsUser(tag, id, mContext.getUser());
     }
 
     /**
@@ -440,7 +440,7 @@ public class NotificationManager {
         String pkg = mContext.getPackageName();
         if (localLOGV) Log.v(TAG, pkg + ": cancelAll()");
         try {
-            service.cancelAllNotifications(pkg, UserHandle.myUserId());
+            service.cancelAllNotifications(pkg, mContext.getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1264,7 +1264,7 @@ public class NotificationManager {
         final String pkg = mContext.getPackageName();
         try {
             final ParceledListSlice<StatusBarNotification> parceledList
-                    = service.getAppActiveNotifications(pkg, UserHandle.myUserId());
+                    = service.getAppActiveNotifications(pkg, mContext.getUserId());
             final List<StatusBarNotification> list = parceledList.getList();
             return list.toArray(new StatusBarNotification[list.size()]);
         } catch (RemoteException e) {
index d6429ae..315259b 100644 (file)
@@ -345,7 +345,7 @@ public final class PendingIntent implements Parcelable {
                     ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
                     null, null, requestCode, new Intent[] { intent },
                     resolvedType != null ? new String[] { resolvedType } : null,
-                    flags, options, UserHandle.myUserId());
+                    flags, options, context.getUserId());
             return target != null ? new PendingIntent(target) : null;
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
@@ -486,7 +486,7 @@ public final class PendingIntent implements Parcelable {
                 ActivityManager.getService().getIntentSender(
                     ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
                     null, null, requestCode, intents, resolvedTypes, flags, options,
-                    UserHandle.myUserId());
+                    context.getUserId());
             return target != null ? new PendingIntent(target) : null;
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
@@ -544,8 +544,7 @@ public final class PendingIntent implements Parcelable {
      */
     public static PendingIntent getBroadcast(Context context, int requestCode,
             Intent intent, @Flags int flags) {
-        return getBroadcastAsUser(context, requestCode, intent, flags,
-                new UserHandle(UserHandle.myUserId()));
+        return getBroadcastAsUser(context, requestCode, intent, flags, context.getUser());
     }
 
     /**
@@ -644,7 +643,7 @@ public final class PendingIntent implements Parcelable {
                     serviceKind, packageName,
                     null, null, requestCode, new Intent[] { intent },
                     resolvedType != null ? new String[] { resolvedType } : null,
-                    flags, null, UserHandle.myUserId());
+                    flags, null, context.getUserId());
             return target != null ? new PendingIntent(target) : null;
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
index 4310434..87f32b2 100644 (file)
@@ -38,6 +38,7 @@ import android.content.ClipboardManager;
 import android.content.Context;
 import android.content.IRestrictionsManager;
 import android.content.RestrictionsManager;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.CrossProfileApps;
 import android.content.pm.ICrossProfileApps;
 import android.content.pm.IShortcutService;
@@ -724,8 +725,9 @@ final class SystemServiceRegistry {
                     service = IPrintManager.Stub.asInterface(ServiceManager
                             .getServiceOrThrow(Context.PRINT_SERVICE));
                 }
-                return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(),
-                        UserHandle.getAppId(Process.myUid()));
+                final int userId = ctx.getUserId();
+                final int appId = UserHandle.getAppId(ctx.getApplicationInfo().uid);
+                return new PrintManager(ctx.getOuterContext(), service, userId, appId);
             }});
 
         registerService(Context.COMPANION_DEVICE_SERVICE, CompanionDeviceManager.class,
@@ -780,12 +782,12 @@ final class SystemServiceRegistry {
             }});
 
         registerService(Context.TV_INPUT_SERVICE, TvInputManager.class,
-                new StaticServiceFetcher<TvInputManager>() {
+                new CachedServiceFetcher<TvInputManager>() {
             @Override
-            public TvInputManager createService() throws ServiceNotFoundException {
+            public TvInputManager createService(ContextImpl ctx) throws ServiceNotFoundException {
                 IBinder iBinder = ServiceManager.getServiceOrThrow(Context.TV_INPUT_SERVICE);
                 ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder);
-                return new TvInputManager(service, UserHandle.myUserId());
+                return new TvInputManager(service, ctx.getUserId());
             }});
 
         registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class,
index ab59747..b99b327 100644 (file)
@@ -230,7 +230,7 @@ public class TaskStackBuilder {
      * Context.startActivity(Intent, Bundle)} for more details.
      */
     public void startActivities(Bundle options) {
-        startActivities(options, new UserHandle(UserHandle.myUserId()));
+        startActivities(options, mSourceContext.getUser());
     }
 
     /**
index 39bccc3..19240e2 100644 (file)
@@ -1003,7 +1003,7 @@ public class WallpaperManager {
                 Log.w(TAG, "WallpaperService not running");
                 throw new RuntimeException(new DeadSystemException());
             } else {
-                return sGlobals.mService.getWallpaperInfo(UserHandle.myUserId());
+                return sGlobals.mService.getWallpaperInfo(mContext.getUserId());
             }
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
@@ -1151,7 +1151,7 @@ public class WallpaperManager {
             ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(
                     "res:" + resources.getResourceName(resid),
                     mContext.getOpPackageName(), null, false, result, which, completion,
-                    UserHandle.myUserId());
+                    mContext.getUserId());
             if (fd != null) {
                 FileOutputStream fos = null;
                 boolean ok = false;
@@ -1256,7 +1256,7 @@ public class WallpaperManager {
             boolean allowBackup, @SetWallpaperFlags int which)
             throws IOException {
         return setBitmap(fullImage, visibleCropHint, allowBackup, which,
-                UserHandle.myUserId());
+                mContext.getUserId());
     }
 
     /**
@@ -1403,7 +1403,7 @@ public class WallpaperManager {
         try {
             ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
                     mContext.getOpPackageName(), visibleCropHint, allowBackup,
-                    result, which, completion, UserHandle.myUserId());
+                    result, which, completion, mContext.getUserId());
             if (fd != null) {
                 FileOutputStream fos = null;
                 try {
@@ -1640,7 +1640,7 @@ public class WallpaperManager {
     @SystemApi
     @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT)
     public boolean setWallpaperComponent(ComponentName name) {
-        return setWallpaperComponent(name, UserHandle.myUserId());
+        return setWallpaperComponent(name, mContext.getUserId());
     }
 
     /**
index e190fd4..26eb3bc 100644 (file)
@@ -140,7 +140,7 @@ public class DevicePolicyManager {
     /** @hide test will override it. */
     @VisibleForTesting
     protected int myUserId() {
-        return UserHandle.myUserId();
+        return mContext.getUserId();
     }
 
     /**
@@ -5511,7 +5511,7 @@ public class DevicePolicyManager {
     @SystemApi
     public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
         throwIfParentInstance("getProfileOwner");
-        return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
+        return getProfileOwnerAsUser(mContext.getUserId());
     }
 
     /**
@@ -5539,7 +5539,7 @@ public class DevicePolicyManager {
     public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
         if (mService != null) {
             try {
-                return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
+                return mService.getProfileOwnerName(mContext.getUserId());
             } catch (RemoteException re) {
                 throw re.rethrowFromSystemServer();
             }
index edb6a74..cf35902 100644 (file)
@@ -301,7 +301,7 @@ public final class UsageStatsManager {
      */
     public boolean isAppInactive(String packageName) {
         try {
-            return mService.isAppInactive(packageName, UserHandle.myUserId());
+            return mService.isAppInactive(packageName, mContext.getUserId());
         } catch (RemoteException e) {
             // fall through and return default
         }
@@ -313,7 +313,7 @@ public final class UsageStatsManager {
      */
     public void setAppInactive(String packageName, boolean inactive) {
         try {
-            mService.setAppInactive(packageName, inactive, UserHandle.myUserId());
+            mService.setAppInactive(packageName, inactive, mContext.getUserId());
         } catch (RemoteException e) {
             // fall through
         }
index a55bbda..a2c75a6 100644 (file)
@@ -459,10 +459,9 @@ public class AppWidgetManager {
      */
     public static final String META_DATA_APPWIDGET_PROVIDER = "android.appwidget.provider";
 
+    private final Context mContext;
     private final String mPackageName;
-
     private final IAppWidgetService mService;
-
     private final DisplayMetrics mDisplayMetrics;
 
     /**
@@ -481,6 +480,7 @@ public class AppWidgetManager {
      * @hide
      */
     public AppWidgetManager(Context context, IAppWidgetService service) {
+        mContext = context;
         mPackageName = context.getOpPackageName();
         mService = service;
         mDisplayMetrics = context.getResources().getDisplayMetrics();
@@ -845,7 +845,7 @@ public class AppWidgetManager {
         }
 
         if (profile == null) {
-            profile = Process.myUserHandle();
+            profile = mContext.getUser();
         }
 
         try {
@@ -924,7 +924,7 @@ public class AppWidgetManager {
         if (mService == null) {
             return;
         }
-        bindAppWidgetIdIfAllowed(appWidgetId, Process.myUserHandle(), provider, options);
+        bindAppWidgetIdIfAllowed(appWidgetId, mContext.getUser(), provider, options);
     }
 
     /**
@@ -944,7 +944,7 @@ public class AppWidgetManager {
         if (mService == null) {
             return false;
         }
-        return bindAppWidgetIdIfAllowed(appWidgetId, UserHandle.myUserId(), provider, null);
+        return bindAppWidgetIdIfAllowed(appWidgetId, mContext.getUserId(), provider, null);
     }
 
     /**
@@ -968,7 +968,7 @@ public class AppWidgetManager {
         if (mService == null) {
             return false;
         }
-        return bindAppWidgetIdIfAllowed(appWidgetId, UserHandle.myUserId(), provider, options);
+        return bindAppWidgetIdIfAllowed(appWidgetId, mContext.getUserId(), provider, options);
     }
 
     /**
@@ -1030,7 +1030,7 @@ public class AppWidgetManager {
             return false;
         }
         try {
-            return mService.hasBindAppWidgetPermission(packageName, UserHandle.myUserId());
+            return mService.hasBindAppWidgetPermission(packageName, mContext.getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1050,7 +1050,7 @@ public class AppWidgetManager {
         if (mService == null) {
             return;
         }
-        setBindAppWidgetPermission(packageName, UserHandle.myUserId(), permission);
+        setBindAppWidgetPermission(packageName, mContext.getUserId(), permission);
     }
 
     /**
index b255a43..a2e714e 100644 (file)
@@ -262,7 +262,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth A2DP Service with " + intent);
             return false;
         }
index faab000..13f0aaf 100755 (executable)
@@ -182,7 +182,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth A2DP Service with " + intent);
             return false;
         }
index 5f0e5d9..e7c8944 100644 (file)
@@ -138,7 +138,7 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth AVRCP Controller Service with " + intent);
             return false;
         }
index 031287f..397b906 100644 (file)
@@ -427,7 +427,7 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth Headset Client Service with " + intent);
             return false;
         }
index 57a0197..b967fb2 100644 (file)
@@ -491,7 +491,7 @@ public final class BluetoothHealth implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth Health Service with " + intent);
             return false;
         }
index 2fab305..77ab731 100644 (file)
@@ -236,7 +236,7 @@ public final class BluetoothHidDevice implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth HID Device Service with " + intent);
             return false;
         }
index 8ad0f9d..0ca39f1 100644 (file)
@@ -279,7 +279,7 @@ public final class BluetoothHidHost implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth HID Service with " + intent);
             return false;
         }
index 5b55b23..0fa1d5d 100644 (file)
@@ -109,7 +109,7 @@ public final class BluetoothMap implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth MAP Service with " + intent);
             return false;
         }
index af3b662..4f21d93 100644 (file)
@@ -125,7 +125,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth MAP MCE Service with " + intent);
             return false;
         }
index 866b063..9f401eb 100644 (file)
@@ -147,7 +147,7 @@ public final class BluetoothPan implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth Pan Service with " + intent);
             return false;
         }
index 7944354..c60e9e0 100644 (file)
@@ -163,7 +163,7 @@ public class BluetoothPbap implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth Pbap Service with " + intent);
             return false;
         }
index 01b3f6e..1446adc 100644 (file)
@@ -116,7 +116,7 @@ public final class BluetoothPbapClient implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth PBAP Client Service with " + intent);
             return false;
         }
index 4848162..c51e39a 100644 (file)
@@ -147,7 +147,7 @@ public final class BluetoothSap implements BluetoothProfile {
         ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
         intent.setComponent(comp);
         if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
-                android.os.Process.myUserHandle())) {
+                mContext.getUser())) {
             Log.e(TAG, "Could not bind to Bluetooth SAP Service with " + intent);
             return false;
         }
index 8d2e141..cba76ed 100644 (file)
@@ -2999,6 +2999,11 @@ public abstract class ContentResolver {
     }
 
     /** @hide */
+    public int getUserId() {
+        return mContext.getUserId();
+    }
+
+    /** @hide */
     public Drawable getTypeDrawable(String mimeType) {
         return MimeIconUtils.loadMimeIcon(mContext, mimeType);
     }
index f2eb4a0..145b17f 100644 (file)
@@ -4705,13 +4705,22 @@ public abstract class Context {
             throws PackageManager.NameNotFoundException;
 
     /**
-     * Get the userId associated with this context
-     * @return user id
-     *
+     * Get the user associated with this context
+     * @hide
+     */
+    @TestApi
+    public UserHandle getUser() {
+        return android.os.Process.myUserHandle();
+    }
+
+    /**
+     * Get the user associated with this context
      * @hide
      */
     @TestApi
-    public abstract @UserIdInt int getUserId();
+    public @UserIdInt int getUserId() {
+        return android.os.UserHandle.myUserId();
+    }
 
     /**
      * Return a new Context object for the current Context but whose resources
index 0b4231f..4e5f835 100644 (file)
@@ -2965,6 +2965,11 @@ public abstract class PackageManager {
      */
     public static final int VERSION_CODE_HIGHEST = -1;
 
+    /** {@hide} */
+    public int getUserId() {
+        return UserHandle.myUserId();
+    }
+
     /**
      * Retrieve overall information about an application package that is
      * installed on the system.
@@ -5212,7 +5217,7 @@ public abstract class PackageManager {
      */
     @Deprecated
     public void getPackageSizeInfo(String packageName, IPackageStatsObserver observer) {
-        getPackageSizeInfoAsUser(packageName, UserHandle.myUserId(), observer);
+        getPackageSizeInfoAsUser(packageName, getUserId(), observer);
     }
 
     /**
index 3f63d80..fc2eba2 100644 (file)
@@ -277,7 +277,7 @@ public class ResolveInfo implements Parcelable {
             dr = pm.getDrawable(ci.packageName, iconResourceId, ai);
         }
         if (dr != null) {
-            return pm.getUserBadgedIcon(dr, new UserHandle(UserHandle.myUserId()));
+            return pm.getUserBadgedIcon(dr, new UserHandle(pm.getUserId()));
         }
         return ci.loadIcon(pm);
     }
index 30222b7..25e0ccd 100644 (file)
@@ -770,6 +770,6 @@ public class ShortcutManager {
     /** @hide injection point */
     @VisibleForTesting
     protected int injectMyUserId() {
-        return UserHandle.myUserId();
+        return mContext.getUserId();
     }
 }
index fdb702f..76fa008 100644 (file)
@@ -395,7 +395,7 @@ public abstract class AbstractCursor implements CrossProcessCursor {
      */
     @Override
     public void setNotificationUri(ContentResolver cr, Uri notifyUri) {
-        setNotificationUri(cr, notifyUri, UserHandle.myUserId());
+        setNotificationUri(cr, notifyUri, cr.getUserId());
     }
 
     /** @hide - set the notification uri but with an observer for a particular user's view */
index 22fb8e7..6b2059e 100644 (file)
@@ -649,7 +649,7 @@ public final class DisplayManager {
     @TestApi
     @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS)
     public void setBrightnessConfiguration(BrightnessConfiguration c) {
-        setBrightnessConfigurationForUser(c, UserHandle.myUserId(), mContext.getPackageName());
+        setBrightnessConfigurationForUser(c, mContext.getUserId(), mContext.getPackageName());
     }
 
     /**
index 2dfe673..92d6bbb 100644 (file)
@@ -375,7 +375,7 @@ public class FingerprintManager implements BiometricFingerprintConstants {
     @RequiresPermission(USE_FINGERPRINT)
     public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel,
             int flags, @NonNull AuthenticationCallback callback, @Nullable Handler handler) {
-        authenticate(crypto, cancel, flags, callback, handler, UserHandle.myUserId());
+        authenticate(crypto, cancel, flags, callback, handler, mContext.getUserId());
     }
 
     /**
@@ -496,7 +496,7 @@ public class FingerprintManager implements BiometricFingerprintConstants {
         if (callback == null) {
             throw new IllegalArgumentException("Must supply a calback");
         }
-        authenticate(UserHandle.myUserId(), null, cancel, bundle, executor, receiver, callback);
+        authenticate(mContext.getUserId(), null, cancel, bundle, executor, receiver, callback);
     }
 
     /**
@@ -532,7 +532,7 @@ public class FingerprintManager implements BiometricFingerprintConstants {
         if (callback == null) {
             throw new IllegalArgumentException("Must supply a callback");
         }
-        authenticate(UserHandle.myUserId(), crypto, cancel,
+        authenticate(mContext.getUserId(), crypto, cancel,
                 bundle, executor, receiver, callback);
     }
 
@@ -724,7 +724,7 @@ public class FingerprintManager implements BiometricFingerprintConstants {
      */
     @RequiresPermission(USE_FINGERPRINT)
     public List<Fingerprint> getEnrolledFingerprints() {
-        return getEnrolledFingerprints(UserHandle.myUserId());
+        return getEnrolledFingerprints(mContext.getUserId());
     }
 
     /**
@@ -739,7 +739,7 @@ public class FingerprintManager implements BiometricFingerprintConstants {
     public boolean hasEnrolledFingerprints() {
         if (mService != null) try {
             return mService.hasEnrolledFingerprints(
-                    UserHandle.myUserId(), mContext.getOpPackageName());
+                    mContext.getUserId(), mContext.getOpPackageName());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
index 185b181..712576f 100644 (file)
@@ -192,7 +192,7 @@ public class VpnService extends Service {
      */
     public static Intent prepare(Context context) {
         try {
-            if (getService().prepareVpn(context.getPackageName(), null, UserHandle.myUserId())) {
+            if (getService().prepareVpn(context.getPackageName(), null, context.getUserId())) {
                 return null;
             }
         } catch (RemoteException e) {
@@ -219,7 +219,7 @@ public class VpnService extends Service {
         String packageName = context.getPackageName();
         try {
             // Only prepare if we're not already prepared.
-            int userId = UserHandle.myUserId();
+            int userId = context.getUserId();
             if (!cm.prepareVpn(packageName, null, userId)) {
                 cm.prepareVpn(null, packageName, userId);
             }
index c7d4c65..958063a 100644 (file)
@@ -393,7 +393,7 @@ public final class NfcActivityManager extends IAppCallback.Stub
                                     "either scheme file or scheme content");
                             continue;
                         }
-                        uri = ContentProvider.maybeAddUserId(uri, UserHandle.myUserId());
+                        uri = ContentProvider.maybeAddUserId(uri, activity.getUserId());
                         validUris.add(uri);
                     }
 
@@ -410,7 +410,7 @@ public final class NfcActivityManager extends IAppCallback.Stub
         } finally {
             Binder.restoreCallingIdentity(ident);
         }
-        return new BeamShareData(message, uris, new UserHandle(UserHandle.myUserId()), flags);
+        return new BeamShareData(message, uris, activity.getUser(), flags);
     }
 
     /** Callback from NFC service, usually on binder thread */
index 6dd7993..15d02f2 100644 (file)
@@ -201,7 +201,7 @@ public final class CardEmulation {
      */
     public boolean isDefaultServiceForCategory(ComponentName service, String category) {
         try {
-            return sService.isDefaultServiceForCategory(UserHandle.myUserId(), service, category);
+            return sService.isDefaultServiceForCategory(mContext.getUserId(), service, category);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -210,7 +210,7 @@ public final class CardEmulation {
                 return false;
             }
             try {
-                return sService.isDefaultServiceForCategory(UserHandle.myUserId(), service,
+                return sService.isDefaultServiceForCategory(mContext.getUserId(), service,
                         category);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to recover CardEmulationService.");
@@ -232,7 +232,7 @@ public final class CardEmulation {
      */
     public boolean isDefaultServiceForAid(ComponentName service, String aid) {
         try {
-            return sService.isDefaultServiceForAid(UserHandle.myUserId(), service, aid);
+            return sService.isDefaultServiceForAid(mContext.getUserId(), service, aid);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -241,7 +241,7 @@ public final class CardEmulation {
                 return false;
             }
             try {
-                return sService.isDefaultServiceForAid(UserHandle.myUserId(), service, aid);
+                return sService.isDefaultServiceForAid(mContext.getUserId(), service, aid);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
                 return false;
@@ -326,7 +326,7 @@ public final class CardEmulation {
             List<String> aids) {
         AidGroup aidGroup = new AidGroup(aids, category);
         try {
-            return sService.registerAidGroupForService(UserHandle.myUserId(), service, aidGroup);
+            return sService.registerAidGroupForService(mContext.getUserId(), service, aidGroup);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -335,7 +335,7 @@ public final class CardEmulation {
                 return false;
             }
             try {
-                return sService.registerAidGroupForService(UserHandle.myUserId(), service,
+                return sService.registerAidGroupForService(mContext.getUserId(), service,
                         aidGroup);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
@@ -360,7 +360,7 @@ public final class CardEmulation {
      */
     public List<String> getAidsForService(ComponentName service, String category) {
         try {
-            AidGroup group =  sService.getAidGroupForService(UserHandle.myUserId(), service,
+            AidGroup group =  sService.getAidGroupForService(mContext.getUserId(), service,
                     category);
             return (group != null ? group.getAids() : null);
         } catch (RemoteException e) {
@@ -370,7 +370,7 @@ public final class CardEmulation {
                 return null;
             }
             try {
-                AidGroup group = sService.getAidGroupForService(UserHandle.myUserId(), service,
+                AidGroup group = sService.getAidGroupForService(mContext.getUserId(), service,
                         category);
                 return (group != null ? group.getAids() : null);
             } catch (RemoteException ee) {
@@ -397,7 +397,7 @@ public final class CardEmulation {
      */
     public boolean removeAidsForService(ComponentName service, String category) {
         try {
-            return sService.removeAidGroupForService(UserHandle.myUserId(), service, category);
+            return sService.removeAidGroupForService(mContext.getUserId(), service, category);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -406,7 +406,7 @@ public final class CardEmulation {
                 return false;
             }
             try {
-                return sService.removeAidGroupForService(UserHandle.myUserId(), service, category);
+                return sService.removeAidGroupForService(mContext.getUserId(), service, category);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
                 return false;
@@ -537,7 +537,7 @@ public final class CardEmulation {
      */
     public boolean setDefaultServiceForCategory(ComponentName service, String category) {
         try {
-            return sService.setDefaultServiceForCategory(UserHandle.myUserId(), service, category);
+            return sService.setDefaultServiceForCategory(mContext.getUserId(), service, category);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -546,7 +546,7 @@ public final class CardEmulation {
                 return false;
             }
             try {
-                return sService.setDefaultServiceForCategory(UserHandle.myUserId(), service,
+                return sService.setDefaultServiceForCategory(mContext.getUserId(), service,
                         category);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
@@ -560,7 +560,7 @@ public final class CardEmulation {
      */
     public boolean setDefaultForNextTap(ComponentName service) {
         try {
-            return sService.setDefaultForNextTap(UserHandle.myUserId(), service);
+            return sService.setDefaultForNextTap(mContext.getUserId(), service);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -569,7 +569,7 @@ public final class CardEmulation {
                 return false;
             }
             try {
-                return sService.setDefaultForNextTap(UserHandle.myUserId(), service);
+                return sService.setDefaultForNextTap(mContext.getUserId(), service);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
                 return false;
@@ -582,7 +582,7 @@ public final class CardEmulation {
      */
     public List<ApduServiceInfo> getServices(String category) {
         try {
-            return sService.getServices(UserHandle.myUserId(), category);
+            return sService.getServices(mContext.getUserId(), category);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -591,7 +591,7 @@ public final class CardEmulation {
                 return null;
             }
             try {
-                return sService.getServices(UserHandle.myUserId(), category);
+                return sService.getServices(mContext.getUserId(), category);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
                 return null;
index f2b5ebc..80e8579 100644 (file)
@@ -118,7 +118,7 @@ public final class NfcFCardEmulation {
             throw new NullPointerException("service is null");
         }
         try {
-            return sService.getSystemCodeForService(UserHandle.myUserId(), service);
+            return sService.getSystemCodeForService(mContext.getUserId(), service);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -127,7 +127,7 @@ public final class NfcFCardEmulation {
                 return null;
             }
             try {
-                return sService.getSystemCodeForService(UserHandle.myUserId(), service);
+                return sService.getSystemCodeForService(mContext.getUserId(), service);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
                 ee.rethrowAsRuntimeException();
@@ -164,7 +164,7 @@ public final class NfcFCardEmulation {
             throw new NullPointerException("service or systemCode is null");
         }
         try {
-            return sService.registerSystemCodeForService(UserHandle.myUserId(),
+            return sService.registerSystemCodeForService(mContext.getUserId(),
                     service, systemCode);
         } catch (RemoteException e) {
             // Try one more time
@@ -174,7 +174,7 @@ public final class NfcFCardEmulation {
                 return false;
             }
             try {
-                return sService.registerSystemCodeForService(UserHandle.myUserId(),
+                return sService.registerSystemCodeForService(mContext.getUserId(),
                         service, systemCode);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
@@ -195,7 +195,7 @@ public final class NfcFCardEmulation {
             throw new NullPointerException("service is null");
         }
         try {
-            return sService.removeSystemCodeForService(UserHandle.myUserId(), service);
+            return sService.removeSystemCodeForService(mContext.getUserId(), service);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -204,7 +204,7 @@ public final class NfcFCardEmulation {
                 return false;
             }
             try {
-                return sService.removeSystemCodeForService(UserHandle.myUserId(), service);
+                return sService.removeSystemCodeForService(mContext.getUserId(), service);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
                 ee.rethrowAsRuntimeException();
@@ -230,7 +230,7 @@ public final class NfcFCardEmulation {
             throw new NullPointerException("service is null");
         }
         try {
-            return sService.getNfcid2ForService(UserHandle.myUserId(), service);
+            return sService.getNfcid2ForService(mContext.getUserId(), service);
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -239,7 +239,7 @@ public final class NfcFCardEmulation {
                 return null;
             }
             try {
-                return sService.getNfcid2ForService(UserHandle.myUserId(), service);
+                return sService.getNfcid2ForService(mContext.getUserId(), service);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
                 ee.rethrowAsRuntimeException();
@@ -273,7 +273,7 @@ public final class NfcFCardEmulation {
             throw new NullPointerException("service or nfcid2 is null");
         }
         try {
-            return sService.setNfcid2ForService(UserHandle.myUserId(),
+            return sService.setNfcid2ForService(mContext.getUserId(),
                     service, nfcid2);
         } catch (RemoteException e) {
             // Try one more time
@@ -283,7 +283,7 @@ public final class NfcFCardEmulation {
                 return false;
             }
             try {
-                return sService.setNfcid2ForService(UserHandle.myUserId(),
+                return sService.setNfcid2ForService(mContext.getUserId(),
                         service, nfcid2);
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
@@ -381,7 +381,7 @@ public final class NfcFCardEmulation {
      */
     public List<NfcFServiceInfo> getNfcFServices() {
         try {
-            return sService.getNfcFServices(UserHandle.myUserId());
+            return sService.getNfcFServices(mContext.getUserId());
         } catch (RemoteException e) {
             // Try one more time
             recoverService();
@@ -390,7 +390,7 @@ public final class NfcFCardEmulation {
                 return null;
             }
             try {
-                return sService.getNfcFServices(UserHandle.myUserId());
+                return sService.getNfcFServices(mContext.getUserId());
             } catch (RemoteException ee) {
                 Log.e(TAG, "Failed to reach CardEmulationService.");
                 return null;
index f4deeed..f593e80 100644 (file)
@@ -1096,7 +1096,7 @@ public class StorageManager {
     public @NonNull List<StorageVolume> getStorageVolumes() {
         final ArrayList<StorageVolume> res = new ArrayList<>();
         Collections.addAll(res,
-                getVolumeList(UserHandle.myUserId(), FLAG_REAL_STATE | FLAG_INCLUDE_INVISIBLE));
+                getVolumeList(mContext.getUserId(), FLAG_REAL_STATE | FLAG_INCLUDE_INVISIBLE));
         return res;
     }
 
@@ -1107,7 +1107,7 @@ public class StorageManager {
      * {@link Context#getExternalFilesDir(String)}.
      */
     public @NonNull StorageVolume getPrimaryStorageVolume() {
-        return getVolumeList(UserHandle.myUserId(), FLAG_REAL_STATE | FLAG_INCLUDE_INVISIBLE)[0];
+        return getVolumeList(mContext.getUserId(), FLAG_REAL_STATE | FLAG_INCLUDE_INVISIBLE)[0];
     }
 
     /** {@hide} */
index 2cd1d48..362eba9 100644 (file)
@@ -68,7 +68,7 @@ public class ContactsInternal {
             }
         }
         // Launch on the current profile.
-        startQuickContactWithErrorToastForUser(context, intent, Process.myUserHandle());
+        startQuickContactWithErrorToastForUser(context, intent, context.getUser());
     }
 
     public static void startQuickContactWithErrorToastForUser(Context context, Intent intent,
index e3b8a10..881837f 100644 (file)
@@ -2255,7 +2255,7 @@ public final class Settings {
          * @return the corresponding value, or null if not present
          */
         public static String getString(ContentResolver resolver, String name) {
-            return getStringForUser(resolver, name, UserHandle.myUserId());
+            return getStringForUser(resolver, name, resolver.getUserId());
         }
 
         /** @hide */
@@ -2282,7 +2282,7 @@ public final class Settings {
          * @return true if the value was set, false on database errors
          */
         public static boolean putString(ContentResolver resolver, String name, String value) {
-            return putStringForUser(resolver, name, value, UserHandle.myUserId());
+            return putStringForUser(resolver, name, value, resolver.getUserId());
         }
 
         /** @hide */
@@ -2336,7 +2336,7 @@ public final class Settings {
          * or not a valid integer.
          */
         public static int getInt(ContentResolver cr, String name, int def) {
-            return getIntForUser(cr, name, def, UserHandle.myUserId());
+            return getIntForUser(cr, name, def, cr.getUserId());
         }
 
         /** @hide */
@@ -2369,7 +2369,7 @@ public final class Settings {
          */
         public static int getInt(ContentResolver cr, String name)
                 throws SettingNotFoundException {
-            return getIntForUser(cr, name, UserHandle.myUserId());
+            return getIntForUser(cr, name, cr.getUserId());
         }
 
         /** @hide */
@@ -2397,7 +2397,7 @@ public final class Settings {
          * @return true if the value was set, false on database errors
          */
         public static boolean putInt(ContentResolver cr, String name, int value) {
-            return putIntForUser(cr, name, value, UserHandle.myUserId());
+            return putIntForUser(cr, name, value, cr.getUserId());
         }
 
         /** @hide */
@@ -2421,7 +2421,7 @@ public final class Settings {
          * or not a valid {@code long}.
          */
         public static long getLong(ContentResolver cr, String name, long def) {
-            return getLongForUser(cr, name, def, UserHandle.myUserId());
+            return getLongForUser(cr, name, def, cr.getUserId());
         }
 
         /** @hide */
@@ -2456,7 +2456,7 @@ public final class Settings {
          */
         public static long getLong(ContentResolver cr, String name)
                 throws SettingNotFoundException {
-            return getLongForUser(cr, name, UserHandle.myUserId());
+            return getLongForUser(cr, name, cr.getUserId());
         }
 
         /** @hide */
@@ -2484,7 +2484,7 @@ public final class Settings {
          * @return true if the value was set, false on database errors
          */
         public static boolean putLong(ContentResolver cr, String name, long value) {
-            return putLongForUser(cr, name, value, UserHandle.myUserId());
+            return putLongForUser(cr, name, value, cr.getUserId());
         }
 
         /** @hide */
@@ -2508,7 +2508,7 @@ public final class Settings {
          * or not a valid float.
          */
         public static float getFloat(ContentResolver cr, String name, float def) {
-            return getFloatForUser(cr, name, def, UserHandle.myUserId());
+            return getFloatForUser(cr, name, def, cr.getUserId());
         }
 
         /** @hide */
@@ -2542,7 +2542,7 @@ public final class Settings {
          */
         public static float getFloat(ContentResolver cr, String name)
                 throws SettingNotFoundException {
-            return getFloatForUser(cr, name, UserHandle.myUserId());
+            return getFloatForUser(cr, name, cr.getUserId());
         }
 
         /** @hide */
@@ -2573,7 +2573,7 @@ public final class Settings {
          * @return true if the value was set, false on database errors
          */
         public static boolean putFloat(ContentResolver cr, String name, float value) {
-            return putFloatForUser(cr, name, value, UserHandle.myUserId());
+            return putFloatForUser(cr, name, value, cr.getUserId());
         }
 
         /** @hide */
@@ -2591,7 +2591,7 @@ public final class Settings {
          * @param outConfig Where to place the configuration settings.
          */
         public static void getConfiguration(ContentResolver cr, Configuration outConfig) {
-            adjustConfigurationForUser(cr, outConfig, UserHandle.myUserId(),
+            adjustConfigurationForUser(cr, outConfig, cr.getUserId(),
                     false /* updateSettingsIfEmpty */);
         }
 
@@ -2644,7 +2644,7 @@ public final class Settings {
          * @return true if the values were set, false on database errors
          */
         public static boolean putConfiguration(ContentResolver cr, Configuration config) {
-            return putConfigurationForUser(cr, config, UserHandle.myUserId());
+            return putConfigurationForUser(cr, config, cr.getUserId());
         }
 
         /** @hide */
@@ -2664,7 +2664,7 @@ public final class Settings {
         /** @deprecated - Do not use */
         @Deprecated
         public static boolean getShowGTalkServiceStatus(ContentResolver cr) {
-            return getShowGTalkServiceStatusForUser(cr, UserHandle.myUserId());
+            return getShowGTalkServiceStatusForUser(cr, cr.getUserId());
         }
 
         /**
@@ -2680,7 +2680,7 @@ public final class Settings {
         /** @deprecated - Do not use */
         @Deprecated
         public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
-            setShowGTalkServiceStatusForUser(cr, flag, UserHandle.myUserId());
+            setShowGTalkServiceStatusForUser(cr, flag, cr.getUserId());
         }
 
         /**
@@ -4732,7 +4732,7 @@ public final class Settings {
          * @return the corresponding value, or null if not present
          */
         public static String getString(ContentResolver resolver, String name) {
-            return getStringForUser(resolver, name, UserHandle.myUserId());
+            return getStringForUser(resolver, name, resolver.getUserId());
         }
 
         /** @hide */
@@ -4786,7 +4786,7 @@ public final class Settings {
          * @return true if the value was set, false on database errors
          */
         public static boolean putString(ContentResolver resolver, String name, String value) {
-            return putStringForUser(resolver, name, value, UserHandle.myUserId());
+            return putStringForUser(resolver, name, value, resolver.getUserId());
         }
 
         /** @hide */
@@ -4859,7 +4859,7 @@ public final class Settings {
                 @NonNull String name, @Nullable String value, @Nullable String tag,
                 boolean makeDefault) {
             return putStringForUser(resolver, name, value, tag, makeDefault,
-                    UserHandle.myUserId());
+                    resolver.getUserId());
         }
 
         /**
@@ -4880,7 +4880,7 @@ public final class Settings {
         public static void resetToDefaults(@NonNull ContentResolver resolver,
                 @Nullable String tag) {
             resetToDefaultsAsUser(resolver, tag, RESET_MODE_PACKAGE_DEFAULTS,
-                    UserHandle.myUserId());
+                    resolver.getUserId());
         }
 
         /**
@@ -4947,7 +4947,7 @@ public final class Settings {
          * or not a valid integer.
          */
         public static int getInt(ContentResolver cr, String name, int def) {
-            return getIntForUser(cr, name, def, UserHandle.myUserId());
+            return getIntForUser(cr, name, def, cr.getUserId());
         }
 
         /** @hide */
@@ -4984,7 +4984,7 @@ public final class Settings {
          */
         public static int getInt(ContentResolver cr, String name)
                 throws SettingNotFoundException {
-            return getIntForUser(cr, name, UserHandle.myUserId());
+            return getIntForUser(cr, name, cr.getUserId());
         }
 
         /** @hide */
@@ -5016,7 +5016,7 @@ public final class Settings {
          * @return true if the value was set, false on database errors
          */
         public static boolean putInt(ContentResolver cr, String name, int value) {
-            return putIntForUser(cr, name, value, UserHandle.myUserId());
+            return putIntForUser(cr, name, value, cr.getUserId());
         }
 
         /** @hide */
@@ -5040,7 +5040,7 @@ public final class Settings {
          * or not a valid {@code long}.
          */
         public static long getLong(ContentResolver cr, String name, long def) {
-            return getLongForUser(cr, name, def, UserHandle.myUserId());
+            return getLongForUser(cr, name, def, cr.getUserId());
         }
 
         /** @hide */
@@ -5075,7 +5075,7 @@ public final class Settings {
          */
         public static long getLong(ContentResolver cr, String name)
                 throws SettingNotFoundException {
-            return getLongForUser(cr, name, UserHandle.myUserId());
+            return getLongForUser(cr, name, cr.getUserId());
         }
 
         /** @hide */
@@ -5103,7 +5103,7 @@ public final class Settings {
          * @return true if the value was set, false on database errors
          */
         public static boolean putLong(ContentResolver cr, String name, long value) {
-            return putLongForUser(cr, name, value, UserHandle.myUserId());
+            return putLongForUser(cr, name, value, cr.getUserId());
         }
 
         /** @hide */
@@ -5127,7 +5127,7 @@ public final class Settings {
          * or not a valid float.
          */
         public static float getFloat(ContentResolver cr, String name, float def) {
-            return getFloatForUser(cr, name, def, UserHandle.myUserId());
+            return getFloatForUser(cr, name, def, cr.getUserId());
         }
 
         /** @hide */
@@ -5161,7 +5161,7 @@ public final class Settings {
          */
         public static float getFloat(ContentResolver cr, String name)
                 throws SettingNotFoundException {
-            return getFloatForUser(cr, name, UserHandle.myUserId());
+            return getFloatForUser(cr, name, cr.getUserId());
         }
 
         /** @hide */
@@ -5192,7 +5192,7 @@ public final class Settings {
          * @return true if the value was set, false on database errors
          */
         public static boolean putFloat(ContentResolver cr, String name, float value) {
-            return putFloatForUser(cr, name, value, UserHandle.myUserId());
+            return putFloatForUser(cr, name, value, cr.getUserId());
         }
 
         /** @hide */
@@ -7999,7 +7999,7 @@ public final class Settings {
          */
         @Deprecated
         public static final boolean isLocationProviderEnabled(ContentResolver cr, String provider) {
-            return isLocationProviderEnabledForUser(cr, provider, UserHandle.myUserId());
+            return isLocationProviderEnabledForUser(cr, provider, cr.getUserId());
         }
 
         /**
@@ -8031,7 +8031,7 @@ public final class Settings {
         @Deprecated
         public static final void setLocationProviderEnabled(ContentResolver cr,
                 String provider, boolean enabled) {
-            setLocationProviderEnabledForUser(cr, provider, enabled, UserHandle.myUserId());
+            setLocationProviderEnabledForUser(cr, provider, enabled, cr.getUserId());
         }
 
         /**
@@ -11467,7 +11467,7 @@ public final class Settings {
          * @return the corresponding value, or null if not present
          */
         public static String getString(ContentResolver resolver, String name) {
-            return getStringForUser(resolver, name, UserHandle.myUserId());
+            return getStringForUser(resolver, name, resolver.getUserId());
         }
 
         /** @hide */
@@ -11490,7 +11490,7 @@ public final class Settings {
          */
         public static boolean putString(ContentResolver resolver,
                 String name, String value) {
-            return putStringForUser(resolver, name, value, null, false, UserHandle.myUserId());
+            return putStringForUser(resolver, name, value, null, false, resolver.getUserId());
         }
 
         /**
@@ -11539,7 +11539,7 @@ public final class Settings {
                 @NonNull String name, @Nullable String value, @Nullable String tag,
                 boolean makeDefault) {
             return putStringForUser(resolver, name, value, tag, makeDefault,
-                    UserHandle.myUserId());
+                    resolver.getUserId());
         }
 
         /**
@@ -11560,7 +11560,7 @@ public final class Settings {
         public static void resetToDefaults(@NonNull ContentResolver resolver,
                 @Nullable String tag) {
             resetToDefaultsAsUser(resolver, tag, RESET_MODE_PACKAGE_DEFAULTS,
-                    UserHandle.myUserId());
+                    resolver.getUserId());
         }
 
         /**
index 413cd10..eba9129 100755 (executable)
@@ -166,7 +166,7 @@ public class DateFormat {
      * @return true if 24 hour time format is selected, false otherwise.
      */
     public static boolean is24HourFormat(Context context) {
-        return is24HourFormat(context, UserHandle.myUserId());
+        return is24HourFormat(context, context.getUserId());
     }
 
     /**
@@ -270,7 +270,7 @@ public class DateFormat {
      * @hide
      */
     public static String getTimeFormatString(Context context) {
-        return getTimeFormatString(context, UserHandle.myUserId());
+        return getTimeFormatString(context, context.getUserId());
     }
 
     /**
index b4499d1..b49b5bc 100644 (file)
@@ -273,7 +273,7 @@ public final class AccessibilityManager {
                                         == PackageManager.PERMISSION_GRANTED) {
                     userId = UserHandle.USER_CURRENT;
                 } else {
-                    userId = UserHandle.myUserId();
+                    userId = context.getUserId();
                 }
                 sInstance = new AccessibilityManager(context, null, userId);
             }
index 34b5ec8..03a7cd2 100644 (file)
@@ -3158,7 +3158,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
             Bundle args = new Bundle();
             args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, event.getDeviceId());
             return ((SearchManager)getContext().getSystemService(Context.SEARCH_SERVICE))
-                    .launchLegacyAssist(null, UserHandle.myUserId(), args);
+                    .launchLegacyAssist(null, getContext().getUserId(), args);
         }
         return result;
     }