Merge "Added restriction for switching to Headless SYSTEM user."

This commit is contained in:
Nikhil Kumar
2023-02-09 11:30:12 +00:00
committed by Android (Google) Code Review
5 changed files with 20 additions and 9 deletions

View File

@@ -919,7 +919,7 @@ package android.content.pm {
method public boolean isQuietModeEnabled();
method public boolean isRestricted();
method public boolean supportsSwitchTo();
method public boolean supportsSwitchToByUser();
method @Deprecated public boolean supportsSwitchToByUser();
method public void writeToParcel(android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.UserInfo> CREATOR;
field public static final int FLAG_ADMIN = 2; // 0x2

View File

@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;
@@ -418,16 +419,25 @@ public class UserInfo implements Parcelable {
// Don't support switching to pre-created users until they become "real" users.
return false;
}
return !isProfile();
return isFull() || canSwitchToHeadlessSystemUser();
}
/**
* @return true if user is of type {@link UserManager#USER_TYPE_SYSTEM_HEADLESS} and
* {@link com.android.internal.R.bool.config_canSwitchToHeadlessSystemUser} is true.
*/
private boolean canSwitchToHeadlessSystemUser() {
return UserManager.USER_TYPE_SYSTEM_HEADLESS.equals(userType) && Resources.getSystem()
.getBoolean(com.android.internal.R.bool.config_canSwitchToHeadlessSystemUser);
}
/**
* @return true if this user can be switched to by end user through UI.
* @deprecated Use {@link UserInfo#supportsSwitchTo} instead.
*/
@Deprecated
public boolean supportsSwitchToByUser() {
// Hide the system user when it does not represent a human user.
boolean hideSystemUser = UserManager.isHeadlessSystemUserMode();
return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo();
return supportsSwitchTo();
}
// TODO(b/142482943): Make this logic more specific and customizable. (canHaveProfile(userType))

View File

@@ -2781,6 +2781,10 @@
it can't be deleted or downgraded to non-admin status. -->
<bool name="config_isMainUserPermanentAdmin">false</bool>
<!-- Whether switch to headless system user is allowed. If allowed,
headless system user can run in the foreground even though it is not a full user. -->
<bool name="config_canSwitchToHeadlessSystemUser">false</bool>
<!-- Whether UI for multi user should be shown -->
<bool name="config_enableMultiUserUI">false</bool>

View File

@@ -355,6 +355,7 @@
<java-symbol type="bool" name="config_speed_up_audio_on_mt_calls" />
<java-symbol type="bool" name="config_useFixedVolume" />
<java-symbol type="bool" name="config_isMainUserPermanentAdmin"/>
<java-symbol type="bool" name="config_canSwitchToHeadlessSystemUser"/>
<java-symbol type="bool" name="config_enableMultiUserUI"/>
<java-symbol type="bool" name="config_enableMultipleAdmins"/>
<java-symbol type="bool" name="config_enableNewAutoSelectNetworkUI"/>

View File

@@ -1986,10 +1986,6 @@ class UserController implements Handler.Callback {
Slogf.w(TAG, "Cannot switch to User #" + targetUserId + ": not supported");
return false;
}
if (targetUserInfo.isProfile()) {
Slogf.w(TAG, "Cannot switch to User #" + targetUserId + ": not a full user");
return false;
}
if (FactoryResetter.isFactoryResetting()) {
Slogf.w(TAG, "Cannot switch to User #" + targetUserId + ": factory reset in progress");
return false;