Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0bdeb32 authored by Yvonne Jiang's avatar Yvonne Jiang
Browse files

Add new DevicePolicyConstant for indicating that the testOnly admin should be...

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
parent 53863bbc
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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) {
+9 −5
Original line number Diff line number Diff line
@@ -8689,12 +8689,16 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            final ComponentName doComponent = mOwners.getDeviceOwnerComponent();
            final ComponentName poComponent =
                    mOwners.getProfileOwnerComponent(userHandle.getIdentifier());
            // Return test only admin by default.
            // 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);
            if (supervisor == null) {