diff options
| author | 2025-01-28 14:17:54 +0000 | |
|---|---|---|
| committer | 2025-01-30 13:11:46 +0000 | |
| commit | f17eac3030a3bf2f28dde7728c4119896f234d62 (patch) | |
| tree | 4ada20118dd946b6ffe1eec0a2e65bd263b29843 | |
| parent | 79d02565b25b9fdc9142bcf475b1b328736bb806 (diff) | |
Stop disabling supervision when the supervision app is not the PO.
Now there's a switch in Settings that is capable of turning on supervision independently from PO.
Bug: 381428475
Test: atest SupervisionServiceTest
Flag: android.app.supervision.flags.enable_sync_with_dpm
Change-Id: I2a427cde8a81c19b28948b4e6b4c24c76a0eaf12
| -rw-r--r-- | services/supervision/java/com/android/server/supervision/SupervisionService.java | 17 | ||||
| -rw-r--r-- | services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt | 14 |
2 files changed, 22 insertions, 9 deletions
diff --git a/services/supervision/java/com/android/server/supervision/SupervisionService.java b/services/supervision/java/com/android/server/supervision/SupervisionService.java index ea85710eab44..a96c477c78d2 100644 --- a/services/supervision/java/com/android/server/supervision/SupervisionService.java +++ b/services/supervision/java/com/android/server/supervision/SupervisionService.java @@ -177,23 +177,24 @@ public class SupervisionService extends ISupervisionManager.Stub { } } - /** Ensures that supervision is enabled when the supervision app is the profile owner. */ + /** + * Ensures that supervision is enabled when the supervision app is the profile owner. + * + * <p>The state syncing with the DevicePolicyManager can only enable supervision and never + * disable. Supervision can only be disabled explicitly via calls to the + * {@link #setSupervisionEnabledForUser} method. + */ private void syncStateWithDevicePolicyManager(@UserIdInt int userId) { final DevicePolicyManagerInternal dpmInternal = mInjector.getDpmInternal(); final ComponentName po = dpmInternal != null ? dpmInternal.getProfileOwnerAsUser(userId) : null; if (po != null && po.getPackageName().equals(getSystemSupervisionPackage())) { - setSupervisionEnabledForUserInternal(userId, true, po.getPackageName()); + setSupervisionEnabledForUserInternal(userId, true, getSystemSupervisionPackage()); } else if (po != null && po.equals(getSupervisionProfileOwnerComponent())) { // TODO(b/392071637): Consider not enabling supervision in case profile owner is given // to the legacy supervision profile owner component. setSupervisionEnabledForUserInternal(userId, true, po.getPackageName()); - } else { - // TODO(b/381428475): Avoid disabling supervision when the app is not the profile owner. - // This might only be possible after introducing specific and public APIs to enable - // and disable supervision. - setSupervisionEnabledForUserInternal(userId, false, /* supervisionAppPackage= */ null); } } @@ -279,7 +280,7 @@ public class SupervisionService extends ISupervisionManager.Stub { } @VisibleForTesting - @SuppressLint("MissingPermission") // not needed for a service + @SuppressLint("MissingPermission") // not needed for a system service void registerProfileOwnerListener() { IntentFilter poIntentFilter = new IntentFilter(); poIntentFilter.addAction(DevicePolicyManager.ACTION_PROFILE_OWNER_CHANGED); diff --git a/services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt b/services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt index b150b1495042..da022780ea75 100644 --- a/services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt +++ b/services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt @@ -161,6 +161,18 @@ class SupervisionServiceTest { @Test @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SYNC_WITH_DPM) + fun profileOwnerChanged_supervisionAppIsNotProfileOwner_doesNotDisableSupervision() { + service.mInternal.setSupervisionEnabledForUser(USER_ID, true) + whenever(mockDpmInternal.getProfileOwnerAsUser(USER_ID)) + .thenReturn(ComponentName("other.package", "MainActivity")) + + broadcastProfileOwnerChanged(USER_ID) + + assertThat(service.isSupervisionEnabledForUser(USER_ID)).isTrue() + } + + @Test + @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SYNC_WITH_DPM) fun profileOwnerChanged_supervisionAppIsNotProfileOwner_doesNotEnableSupervision() { whenever(mockDpmInternal.getProfileOwnerAsUser(USER_ID)) .thenReturn(ComponentName("other.package", "MainActivity")) @@ -258,7 +270,7 @@ class SupervisionServiceTest { private companion object { const val USER_ID = 100 - val APP_UID = USER_ID * UserHandle.PER_USER_RANGE + const val APP_UID = USER_ID * UserHandle.PER_USER_RANGE } } |