Cleanup USER_OWNER in various services

Bug: 19913735
Change-Id: I980370bab18e1b9ccf4043eed2b9fd721a940f72
diff --git a/core/java/android/os/UserHandle.java b/core/java/android/os/UserHandle.java
index 48ede4f..edfdf0a 100644
--- a/core/java/android/os/UserHandle.java
+++ b/core/java/android/os/UserHandle.java
@@ -57,15 +57,15 @@
 
     /**
      * @hide A user id constant to indicate the "owner" user of the device
-     * @deprecated Consider using either USER_SYSTEM constant or
-     * UserInfo.isPrimary().
+     * @deprecated Consider using either {@link UserHandle#USER_SYSTEM} constant or
+     * check the target user's flag {@link android.content.pm.UserInfo#isAdmin}.
      */
     public static final int USER_OWNER = 0;
 
     /**
      * @hide A user handle to indicate the primary/owner user of the device
-     * @deprecated Consider using either SYSTEM constant or
-     * UserInfo.isPrimary().
+     * @deprecated Consider using either {@link UserHandle#SYSTEM} constant or
+     * check the target user's flag {@link android.content.pm.UserInfo#isAdmin}.
      */
     public static final UserHandle OWNER = new UserHandle(USER_OWNER);
 
@@ -280,6 +280,7 @@
      * Returns true if this UserHandle refers to the owner user; false otherwise.
      * @return true if this UserHandle refers to the owner user; false otherwise.
      * @hide
+     * TODO: find an alternative to this Api.
      */
     @SystemApi
     public final boolean isOwner() {
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
index fa87270..2385060 100644
--- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
@@ -363,7 +363,8 @@
 
                     // ... and see if these are hosts we've been awaiting.
                     // NOTE: We are backing up and restoring only the owner.
-                    if (newPackageAdded && userId == UserHandle.USER_OWNER) {
+                    // TODO: http://b/22388012
+                    if (newPackageAdded && userId == UserHandle.USER_SYSTEM) {
                         final int uid = getUidForPackage(pkgName, userId);
                         if (uid >= 0 ) {
                             resolveHostUidLocked(pkgName, uid);
@@ -2729,7 +2730,7 @@
             Host host = lookupHostLocked(oldHostId);
             if (host != null) {
                 final int uid = getUidForPackage(NEW_KEYGUARD_HOST_PACKAGE,
-                        UserHandle.USER_OWNER);
+                        UserHandle.USER_SYSTEM);
                 if (uid >= 0) {
                     host.id = new HostId(uid, KEYGUARD_HOST_ID, NEW_KEYGUARD_HOST_PACKAGE);
                 }
@@ -2750,7 +2751,7 @@
     private static AtomicFile getSavedStateFile(int userId) {
         File dir = Environment.getUserSystemDirectory(userId);
         File settingsFile = getStateFile(userId);
-        if (!settingsFile.exists() && userId == UserHandle.USER_OWNER) {
+        if (!settingsFile.exists() && userId == UserHandle.USER_SYSTEM) {
             if (!dir.exists()) {
                 dir.mkdirs();
             }
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index d5c4a41..fd67b41 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -271,7 +271,7 @@
         int sysUiUid = -1;
         try {
             sysUiUid = mContext.getPackageManager().getPackageUid("com.android.systemui",
-                    UserHandle.USER_OWNER);
+                    UserHandle.USER_SYSTEM);
         } catch (PackageManager.NameNotFoundException e) {
             // Some platforms, such as wearables do not have a system ui.
             Log.w(TAG, "Unable to resolve SystemUI's UID.", e);
diff --git a/services/core/java/com/android/server/DeviceIdleController.java b/services/core/java/com/android/server/DeviceIdleController.java
index 46fd28a..2f4ad3f 100644
--- a/services/core/java/com/android/server/DeviceIdleController.java
+++ b/services/core/java/com/android/server/DeviceIdleController.java
@@ -1689,7 +1689,7 @@
         }
 
         if (args != null) {
-            int userId = UserHandle.USER_OWNER;
+            int userId = UserHandle.USER_SYSTEM;
             for (int i=0; i<args.length; i++) {
                 String arg = args[i];
                 if ("-h".equals(arg)) {
diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java
index b418aba..6559eb36ae 100644
--- a/services/core/java/com/android/server/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/InputMethodManagerService.java
@@ -3504,7 +3504,7 @@
                 throw new NullPointerException("methodMap is null");
             }
             mMethodMap = methodMap;
-            final File systemDir = userId == UserHandle.USER_OWNER
+            final File systemDir = userId == UserHandle.USER_SYSTEM
                     ? new File(Environment.getDataDirectory(), SYSTEM_PATH)
                     : Environment.getUserSystemDirectory(userId);
             final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH);
diff --git a/services/core/java/com/android/server/LockSettingsService.java b/services/core/java/com/android/server/LockSettingsService.java
index c7e0c98..da81528 100644
--- a/services/core/java/com/android/server/LockSettingsService.java
+++ b/services/core/java/com/android/server/LockSettingsService.java
@@ -145,7 +145,8 @@
         } catch (RemoteException e) {
             Slog.e(TAG, "Failure retrieving IGateKeeperService", e);
         }
-        mStorage.prefetchUser(UserHandle.USER_OWNER);
+        // TODO: maybe skip this for split system user mode.
+        mStorage.prefetchUser(UserHandle.USER_SYSTEM);
     }
 
     private void migrateOldData() {
diff --git a/services/core/java/com/android/server/LockSettingsStrongAuth.java b/services/core/java/com/android/server/LockSettingsStrongAuth.java
index c023f4a..0e4d5a7 100644
--- a/services/core/java/com/android/server/LockSettingsStrongAuth.java
+++ b/services/core/java/com/android/server/LockSettingsStrongAuth.java
@@ -132,7 +132,7 @@
     }
 
     public void requireStrongAuth(int strongAuthReason, int userId) {
-        if (userId == UserHandle.USER_ALL || userId >= UserHandle.USER_OWNER) {
+        if (userId == UserHandle.USER_ALL || userId >= UserHandle.USER_SYSTEM) {
             mHandler.obtainMessage(MSG_REQUIRE_STRONG_AUTH, strongAuthReason,
                     userId).sendToTarget();
         } else {
diff --git a/services/core/java/com/android/server/MmsServiceBroker.java b/services/core/java/com/android/server/MmsServiceBroker.java
index e0352e0..33f9234 100644
--- a/services/core/java/com/android/server/MmsServiceBroker.java
+++ b/services/core/java/com/android/server/MmsServiceBroker.java
@@ -500,7 +500,7 @@
         private Uri adjustUriForUserAndGrantPermission(Uri contentUri, String action,
                 int permission) {
             final int callingUserId = UserHandle.getCallingUserId();
-            if (callingUserId != UserHandle.USER_OWNER) {
+            if (callingUserId != UserHandle.USER_SYSTEM) {
                 contentUri = ContentProvider.maybeAddUserId(contentUri, callingUserId);
             }
             long token = Binder.clearCallingIdentity();
diff --git a/services/core/java/com/android/server/TextServicesManagerService.java b/services/core/java/com/android/server/TextServicesManagerService.java
index aace66c..fc3a322 100644
--- a/services/core/java/com/android/server/TextServicesManagerService.java
+++ b/services/core/java/com/android/server/TextServicesManagerService.java
@@ -99,7 +99,7 @@
         broadcastFilter.addAction(Intent.ACTION_USER_REMOVED);
         mContext.registerReceiver(new TextServicesBroadcastReceiver(), broadcastFilter);
 
-        int userId = UserHandle.USER_OWNER;
+        int userId = UserHandle.USER_SYSTEM;
         try {
             ActivityManagerNative.getDefault().registerUserSwitchObserver(
                     new IUserSwitchObserver.Stub() {
diff --git a/services/core/java/com/android/server/am/ProviderMap.java b/services/core/java/com/android/server/am/ProviderMap.java
index ed8b1dd..878c0e7a 100644
--- a/services/core/java/com/android/server/am/ProviderMap.java
+++ b/services/core/java/com/android/server/am/ProviderMap.java
@@ -211,7 +211,7 @@
             boolean doit, boolean evenPersistent, int userId,
             ArrayList<ContentProviderRecord> result) {
         boolean didSomething = false;
-        if (userId == UserHandle.USER_ALL || userId == UserHandle.USER_OWNER) {
+        if (userId == UserHandle.USER_ALL || userId == UserHandle.USER_SYSTEM) {
             didSomething = collectPackageProvidersLocked(packageName, filterByClasses,
                     doit, evenPersistent, mSingletonByClass, result);
         }
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 1475f2f..99ca050 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -1560,7 +1560,7 @@
         } finally {
             Binder.restoreCallingIdentity(ident);
         }
-        return UserHandle.USER_OWNER;
+        return UserHandle.USER_SYSTEM;
     }
 
     // UI update and Broadcast Intent
diff --git a/services/core/java/com/android/server/firewall/SenderPackageFilter.java b/services/core/java/com/android/server/firewall/SenderPackageFilter.java
index ec9b5de..dc3edd9 100644
--- a/services/core/java/com/android/server/firewall/SenderPackageFilter.java
+++ b/services/core/java/com/android/server/firewall/SenderPackageFilter.java
@@ -44,7 +44,9 @@
 
         int packageUid = -1;
         try {
-            packageUid = pm.getPackageUid(mPackageName, UserHandle.USER_OWNER);
+            // USER_SYSTEM here is not important. Only app id is used and getPackageUid() will
+            // return a uid whether the app is installed for a user or not.
+            packageUid = pm.getPackageUid(mPackageName, UserHandle.USER_SYSTEM);
         } catch (RemoteException ex) {
             // handled below
         }