Merge "adb cmd for canSwitchToHeadlessSystemUser and isMainUserPermanentAdmin" into udc-dev am: 652989c037
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21592745 Change-Id: I0a656928e6b29fb8f3c6eb8b500fc06a88bf5b71 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -114,6 +114,7 @@ import android.util.TimeUtils;
|
|||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
|
import com.android.internal.R;
|
||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.app.IAppOpsService;
|
import com.android.internal.app.IAppOpsService;
|
||||||
@@ -7369,9 +7370,19 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
* If the main user is a permanent admin user it can't be deleted
|
* If the main user is a permanent admin user it can't be deleted
|
||||||
* or downgraded to non-admin status.
|
* or downgraded to non-admin status.
|
||||||
*/
|
*/
|
||||||
private static boolean isMainUserPermanentAdmin() {
|
public boolean isMainUserPermanentAdmin() {
|
||||||
return Resources.getSystem()
|
return Resources.getSystem()
|
||||||
.getBoolean(com.android.internal.R.bool.config_isMainUserPermanentAdmin);
|
.getBoolean(R.bool.config_isMainUserPermanentAdmin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if {@link com.android.internal.R.bool#config_canSwitchToHeadlessSystemUser}
|
||||||
|
* is true. If allowed, headless system user can run in the foreground even though
|
||||||
|
* it is not a full user.
|
||||||
|
*/
|
||||||
|
public boolean canSwitchToHeadlessSystemUser() {
|
||||||
|
return Resources.getSystem()
|
||||||
|
.getBoolean(R.bool.config_canSwitchToHeadlessSystemUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,6 +150,10 @@ public class UserManagerServiceShellCommand extends ShellCommand {
|
|||||||
return runIsUserVisible();
|
return runIsUserVisible();
|
||||||
case "get-main-user":
|
case "get-main-user":
|
||||||
return runGetMainUserId();
|
return runGetMainUserId();
|
||||||
|
case "can-switch-to-headless-system-user":
|
||||||
|
return canSwitchToHeadlessSystemUser();
|
||||||
|
case "is-main-user-permanent-admin":
|
||||||
|
return isMainUserPermanentAdmin();
|
||||||
default:
|
default:
|
||||||
return handleDefaultCommands(cmd);
|
return handleDefaultCommands(cmd);
|
||||||
}
|
}
|
||||||
@@ -532,6 +536,20 @@ public class UserManagerServiceShellCommand extends ShellCommand {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int canSwitchToHeadlessSystemUser() {
|
||||||
|
PrintWriter pw = getOutPrintWriter();
|
||||||
|
boolean canSwitchToHeadlessSystemUser = mService.canSwitchToHeadlessSystemUser();
|
||||||
|
pw.println(canSwitchToHeadlessSystemUser);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int isMainUserPermanentAdmin() {
|
||||||
|
PrintWriter pw = getOutPrintWriter();
|
||||||
|
boolean isMainUserPermanentAdmin = mService.isMainUserPermanentAdmin();
|
||||||
|
pw.println(isMainUserPermanentAdmin);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link UserManager} associated with the context of the given user.
|
* Gets the {@link UserManager} associated with the context of the given user.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -121,4 +121,31 @@ public class UserManagerServiceShellCommandTest {
|
|||||||
assertEquals("Couldn't get main user.", mOutStream.toString().trim());
|
assertEquals("Couldn't get main user.", mOutStream.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCanSwitchToHeadlessSystemUser() {
|
||||||
|
doReturn(true).when(mUserManagerService).canSwitchToHeadlessSystemUser();
|
||||||
|
doReturn(mWriter).when(mCommand).getOutPrintWriter();
|
||||||
|
|
||||||
|
assertEquals(0, mCommand.exec(mBinder, in, out, err,
|
||||||
|
new String[]{"can-switch-to-headless-system-user"},
|
||||||
|
mShellCallback, mResultReceiver));
|
||||||
|
|
||||||
|
mWriter.flush();
|
||||||
|
assertEquals("true", mOutStream.toString().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsMainUserPermanentAdmin() {
|
||||||
|
doReturn(false).when(mUserManagerService).isMainUserPermanentAdmin();
|
||||||
|
doReturn(mWriter).when(mCommand).getOutPrintWriter();
|
||||||
|
|
||||||
|
assertEquals(0, mCommand.exec(mBinder, in, out, err,
|
||||||
|
new String[]{"is-main-user-permanent-admin"}, mShellCallback, mResultReceiver));
|
||||||
|
|
||||||
|
mWriter.flush();
|
||||||
|
assertEquals("false", mOutStream.toString().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user