Camera: Clear identity before access device policy manager

When cameraserver query device policy via CameraServiceProxy, the proxy
service uses identity of cameraserver. It causes SecurityException and
does not properly returns the actual query result.

Bug: 290329527
Test: Manual test with TestDPC
Change-Id: Ia02aab3276850c16a14b70c027bd03a17a601b8d
Merged-In: Ia02aab3276850c16a14b70c027bd03a17a601b8d
This commit is contained in:
Kwangkyu Park
2023-07-07 22:25:43 +09:00
committed by Austin Borger
parent 29a919e319
commit 090529b1c4

View File

@@ -613,16 +613,26 @@ public class CameraServiceProxy extends SystemService
@Override
public boolean isCameraDisabled(int userId) {
DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
if (dpm == null) {
Slog.e(TAG, "Failed to get the device policy manager service");
if (Binder.getCallingUid() != Process.CAMERASERVER_UID) {
Slog.e(TAG, "Calling UID: " + Binder.getCallingUid()
+ " doesn't match expected camera service UID!");
return false;
}
final long ident = Binder.clearCallingIdentity();
try {
return dpm.getCameraDisabled(null, userId);
} catch (Exception e) {
e.printStackTrace();
return false;
DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
if (dpm == null) {
Slog.e(TAG, "Failed to get the device policy manager service");
return false;
}
try {
return dpm.getCameraDisabled(null, userId);
} catch (Exception e) {
e.printStackTrace();
return false;
}
} finally {
Binder.restoreCallingIdentity(ident);
}
}
};