Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 203243ae authored by Xiaohui Chen's avatar Xiaohui Chen
Browse files

sys user split: fix primary flag bug.

When the end user first login as Guest, and the device rebooted during
the session (Guest user not removed), then the first user created
afterwards would not be correctly marked as primary.  We need to
explicitly looks through all current users to be able to tell for
sure.

Bug: 19913735
Change-Id: Iab1160c17c8dfdc054fd5dd136435fe2711dfa0c
parent 28e73139
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.IStopUserCallback;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -1262,12 +1263,15 @@ public class UserManagerService extends IUserManager.Stub {
                        return null;
                    }
                    // In split system user mode, we assign the first human user the primary flag.
                    // And if the only system user is not admin, we also assign the admin flag to
                    // primary user.
                    // And if there is no device owner, we also assign the admin flag to primary
                    // user.
                    if (UserManager.isSplitSystemUser()
                            && !isGuest && !isManagedProfile && mUsers.size() == 1) {
                            && !isGuest && !isManagedProfile && getPrimaryUser() == null) {
                        flags |= UserInfo.FLAG_PRIMARY;
                        if (!mUsers.get(UserHandle.USER_SYSTEM).isAdmin()) {
                        DevicePolicyManager devicePolicyManager = (DevicePolicyManager)
                                mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
                        if (devicePolicyManager == null
                                || devicePolicyManager.getDeviceOwner() == null) {
                            flags |= UserInfo.FLAG_ADMIN;
                        }
                    }