androidmultiple-usersandroid-multiple-users

How to check if "Multiple users" is enabled


Is there a system setting table or API I can check to see if the "Multiple users" setting is turned on in Settings -> System -> Advanced -> Multiple users?

enter image description here

Thanks!


Solution

  • After a few hours of searching, I found the answer by browsing /data/system/users/0 and looking through settings_system.xml, settings_secure.xml, and settings_global.xml. It turns out what I'm looking for is "user_switcher_enabled" in settings_global.xml.

    Here's my code:

    public static boolean isMultipleUsersEnabled(Context context) {
        try {
            int pref = Settings.Global.getInt(context.getContentResolver(), "user_switcher_enabled");
            return pref == 1 && (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || UserManager.supportsMultipleUsers());
        } catch (Settings.SettingNotFoundException e) {
            Utils.logError(TAG, "user_switcher_enabled setting not found: " + e.toString());
            return false;
        } 
    }
    

    The check for UserManager.supportsMultipleUsers() is probably not needed, but just in case the preference is somehow bogus on devices that don't actually support multiple users.

    If there's anything you want to add to this answer, please comment below.