summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yvonne Jiang <yvonnejiang@google.com> 2021-02-18 05:50:15 -0800
committer Yvonne Jiang <yvonnejiang@google.com> 2021-03-18 00:16:34 +0000
commitf0bdeb325f6f4032c7e04066cd0117f74a0c85cb (patch)
tree166ca9d474ccc38b604b0ecfd9770ececdc0542c
parent53863bbcbf9192eb5c93839d75f2f267936d9aae (diff)
Add new DevicePolicyConstant for indicating that the testOnly admin should be used as the supervision component.
We were always using the testOnly admin previously, but this shouldn't apply for all test cases, thus making it conditional now. Short term fix until general test solution to override xml resources (which is how the designated supervision component is set) is implemented (b/182994391). Bug: 176212263 Test: atest FrameworksServicesTests:DevicePolicyManagerTest Test: atest -c 'CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.MixedProfileOwnerTest' Change-Id: I81506362ea681ca01d98d1713220110977f0fee1
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyConstants.java15
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java14
2 files changed, 24 insertions, 5 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyConstants.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyConstants.java
index 464d6f5ea835..37983349be2f 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyConstants.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyConstants.java
@@ -48,6 +48,11 @@ public class DevicePolicyConstants {
private static final String BATTERY_THRESHOLD_CHARGING_KEY =
"battery_threshold_charging";
+ // TODO(b/182994391): Replace with more generic solution to override the supervision
+ // component.
+ private static final String USE_TEST_ADMIN_AS_SUPERVISION_COMPONENT_KEY =
+ "use_test_admin_as_supervision_component";
+
/**
* The back-off before re-connecting, when a service binding died, due to the owner
* crashing repeatedly.
@@ -79,6 +84,12 @@ public class DevicePolicyConstants {
*/
public final int BATTERY_THRESHOLD_CHARGING;
+ /**
+ * Whether to default to considering the current DO/PO as the supervision component
+ * if they are a testOnly admin.
+ */
+ public final boolean USE_TEST_ADMIN_AS_SUPERVISION_COMPONENT;
+
private DevicePolicyConstants(String settings) {
@@ -110,6 +121,9 @@ public class DevicePolicyConstants {
int batteryThresholdCharging = parser.getInt(
BATTERY_THRESHOLD_CHARGING_KEY, 20);
+ boolean useTestAdminAsSupervisionComponent = parser.getBoolean(
+ USE_TEST_ADMIN_AS_SUPERVISION_COMPONENT_KEY, false);
+
// Set minimum: 5 seconds.
dasDiedServiceReconnectBackoffSec = Math.max(5, dasDiedServiceReconnectBackoffSec);
@@ -128,6 +142,7 @@ public class DevicePolicyConstants {
dasDiedServiceStableConnectionThresholdSec;
BATTERY_THRESHOLD_NOT_CHARGING = batteryThresholdNotCharging;
BATTERY_THRESHOLD_CHARGING = batteryThresholdCharging;
+ USE_TEST_ADMIN_AS_SUPERVISION_COMPONENT = useTestAdminAsSupervisionComponent;
}
public static DevicePolicyConstants loadFromString(String settings) {
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 7260732bbcb6..bbcb538d381a 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -8689,11 +8689,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
final ComponentName doComponent = mOwners.getDeviceOwnerComponent();
final ComponentName poComponent =
mOwners.getProfileOwnerComponent(userHandle.getIdentifier());
- // Return test only admin by default.
- if (isAdminTestOnlyLocked(doComponent, userHandle.getIdentifier())) {
- return doComponent;
- } else if (isAdminTestOnlyLocked(poComponent, userHandle.getIdentifier())) {
- return poComponent;
+ // Return test only admin if configured to do so.
+ // TODO(b/182994391): Replace with more generic solution to override the supervision
+ // component.
+ if (mConstants.USE_TEST_ADMIN_AS_SUPERVISION_COMPONENT) {
+ if (isAdminTestOnlyLocked(doComponent, userHandle.getIdentifier())) {
+ return doComponent;
+ } else if (isAdminTestOnlyLocked(poComponent, userHandle.getIdentifier())) {
+ return poComponent;
+ }
}
final String supervisor = mContext.getResources().getString(
com.android.internal.R.string.config_defaultSupervisionProfileOwnerComponent);