Skip to content
Snippets Groups Projects
Commit 4ee08d17 authored by Kholoud Mohamed's avatar Kholoud Mohamed
Browse files

Introduce a new headless-user-mode attribute

Bug: 338588825
Test: manual
Test: btest a.d.c.CreateAndManageUserTest
Test: btest android.devicepolicy.cts.ProvisioningTest
Change-Id: Ic0a5edfcbee88b0f89464282ba7e7af97abb2611
parent d25af2f1
No related branches found
No related tags found
No related merge requests found
......@@ -1030,11 +1030,19 @@ aconfig_declarations {
name: "device_policy_aconfig_flags",
package: "android.app.admin.flags",
container: "system",
exportable: true,
srcs: [
"core/java/android/app/admin/flags/flags.aconfig",
],
}
java_aconfig_library {
name: "device_policy_exported_aconfig_flags_lib",
aconfig_declarations: "device_policy_aconfig_flags",
defaults: ["framework-minus-apex-aconfig-java-defaults"],
mode: "exported",
}
java_aconfig_library {
name: "device_policy_aconfig_flags_lib",
aconfig_declarations: "device_policy_aconfig_flags",
......
......@@ -21,6 +21,7 @@ import static android.app.admin.flags.Flags.FLAG_HEADLESS_DEVICE_OWNER_SINGLE_US
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.app.admin.flags.Flags;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.Context;
......@@ -176,6 +177,10 @@ public final class DeviceAdminInfo implements Parcelable {
* provisioned into "affiliated" mode when on a Headless System User Mode device.
*
* <p>This mode adds a Profile Owner to all users other than the user the Device Owner is on.
*
* <p>Starting from Android version {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM},
* DPCs should set the value of attribute "headless-device-owner-mode" inside the
* "headless-system-user" tag as "affiliated".
*/
public static final int HEADLESS_DEVICE_OWNER_MODE_AFFILIATED = 1;
......@@ -185,6 +190,10 @@ public final class DeviceAdminInfo implements Parcelable {
*
* <p>This mode only allows a single secondary user on the device blocking the creation of
* additional secondary users.
*
* <p>Starting from Android version {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM},
* DPCs should set the value of attribute "headless-device-owner-mode" inside the
* "headless-system-user" tag as "single_user".
*/
@FlaggedApi(FLAG_HEADLESS_DEVICE_OWNER_SINGLE_USER_ENABLED)
public static final int HEADLESS_DEVICE_OWNER_MODE_SINGLE_USER = 2;
......@@ -383,17 +392,30 @@ public final class DeviceAdminInfo implements Parcelable {
}
mSupportsTransferOwnership = true;
} else if (tagName.equals("headless-system-user")) {
String deviceOwnerModeStringValue =
parser.getAttributeValue(null, "device-owner-mode");
String deviceOwnerModeStringValue = null;
if (Flags.headlessSingleUserCompatibilityFix()) {
deviceOwnerModeStringValue = parser.getAttributeValue(
null, "headless-device-owner-mode");
}
if (deviceOwnerModeStringValue == null) {
deviceOwnerModeStringValue =
parser.getAttributeValue(null, "device-owner-mode");
}
if (deviceOwnerModeStringValue.equalsIgnoreCase("unsupported")) {
if ("unsupported".equalsIgnoreCase(deviceOwnerModeStringValue)) {
mHeadlessDeviceOwnerMode = HEADLESS_DEVICE_OWNER_MODE_UNSUPPORTED;
} else if (deviceOwnerModeStringValue.equalsIgnoreCase("affiliated")) {
} else if ("affiliated".equalsIgnoreCase(deviceOwnerModeStringValue)) {
mHeadlessDeviceOwnerMode = HEADLESS_DEVICE_OWNER_MODE_AFFILIATED;
} else if (deviceOwnerModeStringValue.equalsIgnoreCase("single_user")) {
} else if ("single_user".equalsIgnoreCase(deviceOwnerModeStringValue)) {
mHeadlessDeviceOwnerMode = HEADLESS_DEVICE_OWNER_MODE_SINGLE_USER;
} else {
throw new XmlPullParserException("headless-system-user mode must be valid");
if (Flags.headlessSingleUserCompatibilityFix()) {
Log.e(TAG, "Unknown headless-system-user mode: "
+ deviceOwnerModeStringValue);
} else {
throw new XmlPullParserException(
"headless-system-user mode must be valid");
}
}
}
}
......
......@@ -303,3 +303,24 @@ flag {
purpose: PURPOSE_BUGFIX
}
}
flag {
name: "headless_single_user_compatibility_fix"
namespace: "enterprise"
description: "Fix for compatibility issue introduced from using single_user mode on pre-Android V builds"
bug: "338050276"
is_exported: true
metadata {
purpose: PURPOSE_BUGFIX
}
}
flag {
name: "headless_single_min_target_sdk"
namespace: "enterprise"
description: "Only allow DPCs targeting Android V to provision into single user mode"
bug: "338588825"
metadata {
purpose: PURPOSE_BUGFIX
}
}
......@@ -21610,9 +21610,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
== HEADLESS_DEVICE_OWNER_MODE_SINGLE_USER;
}
 
if (Flags.headlessSingleUserFixes() && mInjector.userManagerIsHeadlessSystemUserMode()
&& isSingleUserMode && !mInjector.isChangeEnabled(
PROVISION_SINGLE_USER_MODE, deviceAdmin.getPackageName(), caller.getUserId())) {
if (Flags.headlessSingleMinTargetSdk()
&& mInjector.userManagerIsHeadlessSystemUserMode()
&& isSingleUserMode
&& !mInjector.isChangeEnabled(
PROVISION_SINGLE_USER_MODE, deviceAdmin.getPackageName(),
caller.getUserId())) {
throw new IllegalStateException("Device admin is not targeting Android V.");
}
 
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment