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

Commit 885928f7 authored by Felipe Leme's avatar Felipe Leme
Browse files

Allow visible background users on default display.

This scenario will be used on automotive builds that only support
passengers (for example, when a 2nd instance of Android runs on the
back seat of a car).

Test: atest UserVisibilityMediatorMUPANDTest UserVisibilityMediatorMUMDTest UserVisibilityMediatorSUSDTest # unit
Test: atest UserVisibilityVisibleBackgroundUsersOnDefaultDisplayTest # CTS
Test: m update-api
Test: adb shell stop && \
  adb shell setprop fw.visible_bg_users true && \
  adb shell setprop fw.visible_bg_users_on_default_display true && \
  adb shell start && sleep 30 &&
  adb shell cmd user is-visible-background-users-on-default-display-supported &&
  adb shell am start-user --display 0 10

Fixes: 261538232

Change-Id: I043b0677351999182a73ed938b2da38c955d5433
parent 83c4c5da
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2067,6 +2067,7 @@ package android.os {
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public java.util.List<android.content.pm.UserInfo> getUsers(boolean, boolean, boolean);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public boolean hasBaseUserRestriction(@NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public boolean isUserTypeEnabled(@NonNull String);
    method public boolean isVisibleBackgroundUsersOnDefaultDisplaySupported();
    method public boolean isVisibleBackgroundUsersSupported();
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public android.content.pm.UserInfo preCreateUser(@NonNull String) throws android.os.UserManager.UserOperationException;
  }
+23 −0
Original line number Diff line number Diff line
@@ -2975,6 +2975,29 @@ public class UserManager {
        return isVisibleBackgroundUsersEnabled();
    }

    /**
     * @hide
     */
    public static boolean isVisibleBackgroundUsersOnDefaultDisplayEnabled() {
        return SystemProperties.getBoolean("fw.visible_bg_users_on_default_display",
                Resources.getSystem()
                        .getBoolean(R.bool.config_multiuserVisibleBackgroundUsersOnDefaultDisplay));
    }

    /**
     * Returns whether the device allows (full) users to be started in background visible in the
     * {@link android.view.Display#DEFAULT_DISPLAY default display}.
     *
     * @return {@code false} for most devices, except passenger-only automotive build (i.e., when
     * Android runs in a separate system in the back seat to manage the passenger displays).
     *
     * @hide
     */
    @TestApi
    public boolean isVisibleBackgroundUsersOnDefaultDisplaySupported() {
        return isVisibleBackgroundUsersOnDefaultDisplayEnabled();
    }

    /**
     * Checks if the user is visible at the moment.
     *
+5 −0
Original line number Diff line number Diff line
@@ -2735,6 +2735,11 @@
         Should be false for most devices, except automotive vehicle with passenger displays. -->
    <bool name="config_multiuserVisibleBackgroundUsers">false</bool>

    <!-- Whether the device allows users to start in background visible on the default display.
         Should be false for most devices, except passenger-only automotive build (i.e., when
         Android runs in a separate system in the back seat to manage the passenger displays) -->
    <bool name="config_multiuserVisibleBackgroundUsersOnDefaultDisplay">false</bool>

    <!-- Whether to automatically switch to the designated Dock User (the user chosen for
         displaying dreams, etc.) after a timeout when the device is docked.  -->
    <bool name="config_enableTimeoutToDockUserWhenDocked">false</bool>
+1 −0
Original line number Diff line number Diff line
@@ -473,6 +473,7 @@
  <java-symbol type="integer" name="config_multiuserMaxRunningUsers" />
  <java-symbol type="bool" name="config_multiuserDelayUserDataLocking" />
  <java-symbol type="bool" name="config_multiuserVisibleBackgroundUsers" />
  <java-symbol type="bool" name="config_multiuserVisibleBackgroundUsersOnDefaultDisplay" />
  <java-symbol type="bool" name="config_enableTimeoutToDockUserWhenDocked" />
  <java-symbol type="integer" name="config_userTypePackageWhitelistMode"/>
  <java-symbol type="xml" name="config_user_types" />
+15 −8
Original line number Diff line number Diff line
@@ -18974,14 +18974,20 @@ public class ActivityManagerService extends IActivityManager.Stub
                return null;
            }
            // Starts with all displays but DEFAULT_DISPLAY
            int[] displayIds = new int[allDisplays.length - 1];
            boolean allowOnDefaultDisplay = UserManager
                    .isVisibleBackgroundUsersOnDefaultDisplayEnabled();
            int displaysSize = allDisplays.length;
            if (!allowOnDefaultDisplay) {
                displaysSize--;
            }
            int[] displayIds = new int[displaysSize];
            // TODO(b/247592632): check for other properties like isSecure or proper display type
            int numberValidDisplays = 0;
            for (Display display : allDisplays) {
                int displayId = display.getDisplayId();
                if (display.isValid() && displayId != Display.DEFAULT_DISPLAY) {
                // TODO(b/247592632): check other properties like isSecure or proper display type
                if (display.isValid()
                        && (allowOnDefaultDisplay || displayId != Display.DEFAULT_DISPLAY)) {
                    displayIds[numberValidDisplays++] = displayId;
                }
            }
@@ -18993,14 +18999,15 @@ public class ActivityManagerService extends IActivityManager.Stub
                // STOPSHIP: if not removed, it should at least be unit tested
                String testingProp = "fw.display_ids_for_starting_users_for_testing_purposes";
                int displayId = SystemProperties.getInt(testingProp, Display.DEFAULT_DISPLAY);
                if (displayId != Display.DEFAULT_DISPLAY && displayId > 0) {
                    Slogf.w(TAG, "getSecondaryDisplayIdsForStartingBackgroundUsers(): no valid "
                if (allowOnDefaultDisplay && displayId == Display.DEFAULT_DISPLAY
                        || displayId > 0) {
                    Slogf.w(TAG, "getDisplayIdsForStartingVisibleBackgroundUsers(): no valid "
                            + "display found, but returning %d as set by property %s", displayId,
                            testingProp);
                    return new int[] { displayId };
                }
                Slogf.e(TAG, "getDisplayIdsForStartingBackgroundUsers(): no valid display on %s",
                        Arrays.toString(allDisplays));
                Slogf.e(TAG, "getDisplayIdsForStartingVisibleBackgroundUsers(): no valid display"
                        + " on %s", Arrays.toString(allDisplays));
                return null;
            }
Loading