Added restriction for switching to Headless SYSTEM user.
On HSUM(HeadlessSystemUserMode) user 0 will not be a Full user and is not going to run in foreground. Added restrictions to prevent switching to non-full user which will eventually restrict switching to user 0 in headless. In some form factors we do need to switch to headless SYSTEM user even when its not FULL like in AUTO, added overlay property to allow switching to non-full SYSTEM user in case the property is enabled. Refactor and Deprecated UserInfo.supportsSwitchToByUser by UserInfo.supportsSwitchTo after adding the restrictions to prevent switch to non-full users. Removed redundant userInfo.isProfile check from UserController.switchUser. Test: m , atest ActivityManagerTest -c Bug: 262402637 Change-Id: I871e6721ce6745d5a9e3009162e3d6ac8a284908
This commit is contained in:
@@ -923,7 +923,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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -2774,6 +2774,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>
|
||||
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
@@ -1984,10 +1984,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;
|
||||
|
||||
Reference in New Issue
Block a user