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
This commit is contained in:
Kwangkyu Park
2023-07-07 22:25:43 +09:00
parent 9c30117b0b
commit cf72d72cf7

View File

@@ -595,16 +595,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);
}
}
};