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

Commit e7ead1ba authored by Eric Jeong's avatar Eric Jeong
Browse files

Add isHeadlessSystemUserMode() to UserManager

- isHeadlessSystemUserMode() returns whether the device is running with
headless system user (go/multi-user-headless-user0)
- RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER is replaced by
isHeadlessSystemUserMode()

Bug: 137755681
Test: Bluetooth service and Network policy manager should work fine with
headless system user. A profile user should be created with headless
system user.

Change-Id: Ic48d98426f7a5ea47dde2008ae51f78855f622e6
parent 03af85af
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ import android.os.Parcelable;
import android.os.UserHandle;
import android.os.UserManager;

import com.android.internal.os.RoSystemProperties;

/**
 * Per-user information.
 * @hide
@@ -233,9 +231,7 @@ public class UserInfo implements Parcelable {
        if (isManagedProfile() || isGuest() || isRestricted()) {
            return false;
        }
        boolean splitOrHeadlessSystemUser = UserManager.isSplitSystemUser()
                || RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER;
        if (splitOrHeadlessSystemUser) {
        if (UserManager.isSplitSystemUser() || UserManager.isHeadlessSystemUserMode()) {
            return id != UserHandle.USER_SYSTEM;
        } else {
            return id == UserHandle.USER_SYSTEM;
+10 −0
Original line number Diff line number Diff line
@@ -1282,6 +1282,16 @@ public class UserManager {
                .getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
    }

    /**
     * @hide
     * @return Whether the device is running in a headless system user mode. It means the headless
     * user (system user) runs system services and system UI, but is not associated with any real
     * person. Secondary users can be created to be associated with real person.
     */
    public static boolean isHeadlessSystemUserMode() {
        return RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER;
    }

    /**
     * @deprecated use {@link #getUserSwitchability()} instead.
     *
+2 −3
Original line number Diff line number Diff line
@@ -18,8 +18,7 @@ package com.android.server;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;

import com.android.internal.os.RoSystemProperties;
import android.os.UserManager;

class BluetoothService extends SystemService {
    private BluetoothManagerService mBluetoothManagerService;
@@ -47,7 +46,7 @@ class BluetoothService extends SystemService {
            publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE,
                    mBluetoothManagerService);
        } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY &&
                !RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER) {
                !UserManager.isHeadlessSystemUserMode()) {
            initialize();
        }
    }
+4 −9
Original line number Diff line number Diff line
@@ -217,7 +217,6 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.os.RoSystemProperties;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ConcurrentUtils;
@@ -1354,7 +1353,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {

                final Intent viewIntent = buildViewDataUsageIntent(res, policy.template);
                // TODO: Resolve to single code path.
                if (isHeadlessSystemUserBuild()) {
                if (UserManager.isHeadlessSystemUserMode()) {
                    builder.setContentIntent(PendingIntent.getActivityAsUser(
                            mContext, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT,
                            /* options= */ null, UserHandle.CURRENT));
@@ -1382,7 +1381,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {

                final Intent intent = buildNetworkOverLimitIntent(res, policy.template);
                // TODO: Resolve to single code path.
                if (isHeadlessSystemUserBuild()) {
                if (UserManager.isHeadlessSystemUserMode()) {
                    builder.setContentIntent(PendingIntent.getActivityAsUser(
                            mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT,
                            /* options= */ null, UserHandle.CURRENT));
@@ -1413,7 +1412,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {

                final Intent intent = buildViewDataUsageIntent(res, policy.template);
                // TODO: Resolve to single code path.
                if (isHeadlessSystemUserBuild()) {
                if (UserManager.isHeadlessSystemUserMode()) {
                    builder.setContentIntent(PendingIntent.getActivityAsUser(
                            mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT,
                            /* options= */ null, UserHandle.CURRENT));
@@ -1440,7 +1439,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {

                final Intent viewIntent = buildViewDataUsageIntent(res, policy.template);
                // TODO: Resolve to single code path.
                if (isHeadlessSystemUserBuild()) {
                if (UserManager.isHeadlessSystemUserMode()) {
                    builder.setContentIntent(PendingIntent.getActivityAsUser(
                            mContext, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT,
                            /* options= */ null, UserHandle.CURRENT));
@@ -5301,10 +5300,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
        return (bundle != null) ? bundle.getBoolean(key, defaultValue) : defaultValue;
    }

    private static boolean isHeadlessSystemUserBuild() {
        return RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER;
    }

    private class NotificationId {
        private final String mTag;
        private final int mId;