Fix policy transparency for camera disabled policy

Bug: 273494642
Test: atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testSetCameraDisabledLogged
Change-Id: I7046a545765439e31b88fe6c6949135b92f82cdd
This commit is contained in:
Kholoud Mohamed
2023-04-24 12:07:33 +00:00
parent c7fc36a82c
commit 282eb18103

View File

@@ -16219,17 +16219,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
deviceOwner.second);
return result;
}
} else if (DevicePolicyManager.POLICY_DISABLE_CAMERA.equals(restriction)
|| DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE.equals(restriction)) {
} else if (DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE.equals(restriction)) {
synchronized (getLockObject()) {
final DevicePolicyData policy = getUserData(userId);
final int N = policy.mAdminList.size();
for (int i = 0; i < N; i++) {
final ActiveAdmin admin = policy.mAdminList.get(i);
if ((admin.disableCamera &&
DevicePolicyManager.POLICY_DISABLE_CAMERA.equals(restriction))
|| (admin.disableScreenCapture && DevicePolicyManager
.POLICY_DISABLE_SCREEN_CAPTURE.equals(restriction))) {
if (admin.disableScreenCapture) {
result = new Bundle();
result.putInt(Intent.EXTRA_USER_ID, userId);
result.putParcelable(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
@@ -16237,17 +16233,44 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
return result;
}
}
// For the camera, a device owner on a different user can disable it globally,
// so we need an additional check.
if (result == null
&& DevicePolicyManager.POLICY_DISABLE_CAMERA.equals(restriction)) {
final ActiveAdmin admin = getDeviceOwnerAdminLocked();
if (admin != null && admin.disableCamera) {
result = new Bundle();
result.putInt(Intent.EXTRA_USER_ID, mOwners.getDeviceOwnerUserId());
result.putParcelable(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
admin.info.getComponent());
return result;
}
} else if (DevicePolicyManager.POLICY_DISABLE_CAMERA.equals(restriction)) {
if (isPolicyEngineForFinanceFlagEnabled()) {
PolicyDefinition<Boolean> policyDefinition =
PolicyDefinition.getPolicyDefinitionForUserRestriction(
UserManager.DISALLOW_CAMERA);
Boolean value = mDevicePolicyEngine.getResolvedPolicy(policyDefinition, userId);
if (value != null && value) {
result = new Bundle();
result.putInt(Intent.EXTRA_USER_ID, userId);
return result;
}
} else {
synchronized (getLockObject()) {
final DevicePolicyData policy = getUserData(userId);
final int N = policy.mAdminList.size();
for (int i = 0; i < N; i++) {
final ActiveAdmin admin = policy.mAdminList.get(i);
if (admin.disableCamera) {
result = new Bundle();
result.putInt(Intent.EXTRA_USER_ID, userId);
result.putParcelable(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
admin.info.getComponent());
return result;
}
}
// For the camera, a device owner on a different user can disable it globally,
// so we need an additional check.
if (result == null
&& DevicePolicyManager.POLICY_DISABLE_CAMERA.equals(restriction)) {
final ActiveAdmin admin = getDeviceOwnerAdminLocked();
if (admin != null && admin.disableCamera) {
result = new Bundle();
result.putInt(Intent.EXTRA_USER_ID, mOwners.getDeviceOwnerUserId());
result.putParcelable(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
admin.info.getComponent());
return result;
}
}
}
}