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

Commit 4440fc60 authored by Adam Bookatz's avatar Adam Bookatz Committed by Automerger Merge Worker
Browse files

Merge "Unify multiuser switcher enabled setting" into rvc-dev am: 203a17d9

Change-Id: If70ef74c9dcaf1071324cf093aeec1db7196786b
parents f074b5fb 203a17d9
Loading
Loading
Loading
Loading
+34 −12
Original line number Diff line number Diff line
@@ -4102,12 +4102,25 @@ public class UserManager {
    }

    /**
     * Returns true if the user switcher should be shown, this will be if device supports multi-user
     * and there are at least 2 users available that are not managed profiles.
     * @hide
     * Returns true if the user switcher should be shown.
     * I.e., returns whether the user switcher is enabled and there is something actionable to show.
     *
     * @return true if user switcher should be shown.
     * @hide
     */
    public boolean isUserSwitcherEnabled() {
        return isUserSwitcherEnabled(false);
    }

    /**
     * Returns true if the user switcher should be shown.
     *
     * @param showEvenIfNotActionable value to return if the feature is enabled but there is nothing
     *                                actionable for the user to do anyway
     * @return true if user switcher should be shown.
     * @hide
     */
    public boolean isUserSwitcherEnabled(boolean showEvenIfNotActionable) {
        if (!supportsMultipleUsers()) {
            return false;
        }
@@ -4118,13 +4131,24 @@ public class UserManager {
        if (isDeviceInDemoMode(mContext)) {
            return false;
        }
        // If user disabled this feature, don't show switcher
        final boolean userSwitcherEnabled = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.USER_SWITCHER_ENABLED, 1) != 0;
        if (!userSwitcherEnabled) {
        // Check the Settings.Global.USER_SWITCHER_ENABLED that the user can toggle on/off.
        final boolean userSwitcherSettingOn = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.USER_SWITCHER_ENABLED,
                Resources.getSystem().getBoolean(R.bool.config_showUserSwitcherByDefault) ? 1 : 0)
                != 0;
        if (!userSwitcherSettingOn) {
            return false;
        }
        List<UserInfo> users = getUsers(true);

        // The feature is enabled. But is it worth showing?
        return showEvenIfNotActionable
                || areThereUsersToWhichToSwitch() // There are switchable users.
                || !hasUserRestriction(UserManager.DISALLOW_ADD_USER); // New users can be added.
    }

    /** Returns whether there are any users (other than the current user) to which to switch. */
    private boolean areThereUsersToWhichToSwitch() {
        final List<UserInfo> users = getUsers(true);
        if (users == null) {
            return false;
        }
@@ -4134,9 +4158,7 @@ public class UserManager {
                ++switchableUserCount;
            }
        }
        final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
                .getGuestUserDisabled(null);
        return switchableUserCount > 1 || guestEnabled;
        return switchableUserCount > 1;
    }

    /**
+3 −0
Original line number Diff line number Diff line
@@ -48,5 +48,8 @@

    <!-- Set to true to enable the user switcher on the keyguard. -->
    <bool name="config_keyguardUserSwitcher">true</bool>

    <!-- If true, show multiuser switcher by default unless the user specifically disables it. -->
    <bool name="config_showUserSwitcherByDefault">true</bool>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -4444,6 +4444,9 @@
    <!-- Set to true to enable the user switcher on the keyguard. -->
    <bool name="config_keyguardUserSwitcher">false</bool>

    <!-- If true, show multiuser switcher by default unless the user specifically disables it. -->
    <bool name="config_showUserSwitcherByDefault">false</bool>

    <!-- Set to true to make assistant show in front of the dream/screensaver. -->
    <bool name="config_assistantOnTopOfDream">false</bool>

+3 −0
Original line number Diff line number Diff line
@@ -4007,6 +4007,9 @@
  <!-- Set to true to enable the user switcher on the keyguard. -->
  <java-symbol type="bool" name="config_keyguardUserSwitcher" />

  <!-- If true, show multiuser switcher by default unless the user specifically disables it. -->
  <java-symbol type="bool" name="config_showUserSwitcherByDefault" />

  <!-- Set to true to make assistant show in front of the dream/screensaver. -->
  <java-symbol type="bool" name="config_assistantOnTopOfDream"/>

+3 −29
Original line number Diff line number Diff line
@@ -18,10 +18,8 @@ package com.android.systemui.statusbar.phone;

import static com.android.systemui.DejankUtils.whitelistIpcs;

import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.os.UserManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
@@ -97,33 +95,9 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
    }

    public boolean isMultiUserEnabled() {
        // Short-circuiting from UserManager. Needs to be extracted because of SystemUI boolean flag
        // qs_show_user_switcher_for_single_user

        // TODO(b/138661450) Move IPC calls to background
        return whitelistIpcs(() -> {
            // The default in UserManager is to show the switcher. We want to not show it unless the
            // user explicitly requests it in Settings
            final boolean userSwitcherEnabled = Settings.Global.getInt(
                    mContext.getContentResolver(),
                    Settings.Global.USER_SWITCHER_ENABLED, 0) != 0;

            if (!userSwitcherEnabled
                    || !UserManager.supportsMultipleUsers()
                    || UserManager.isDeviceInDemoMode(mContext)
                    || mUserManager.hasUserRestriction(UserManager.DISALLOW_USER_SWITCH)) {
                return false;
            }

            final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
                    .getGuestUserDisabled(null);
            return mUserSwitcherController.getSwitchableUserCount() > 1
                    // If we cannot add guests even if they are enabled, do not show
                    || (guestEnabled && !mUserManager.hasUserRestriction(
                    UserManager.DISALLOW_ADD_USER))
                    || mContext.getResources().getBoolean(
                    R.bool.qs_show_user_switcher_for_single_user);
        });
        return whitelistIpcs(() -> mUserManager.isUserSwitcherEnabled(
                mContext.getResources().getBoolean(R.bool.qs_show_user_switcher_for_single_user)));
    }

    private void registerListener() {
@@ -175,7 +149,7 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
    private void refreshContentDescription() {
        String currentUser = null;
        // TODO(b/138661450)
        if (whitelistIpcs(mUserManager::isUserSwitcherEnabled)
        if (whitelistIpcs(() -> mUserManager.isUserSwitcherEnabled())
                && mUserSwitcherController != null) {
            currentUser = mUserSwitcherController.getCurrentUserName(mContext);
        }
Loading