我们如果需要做类似禁用相机的功能,也是可以参考该部分的代码流程逻辑。
这一功能涉及到的相关代码,如下图所示。
CameraService.cpp
--------- CameraService.cppSet camera muting behaviorbool isCameraPrivacyEnabled =mSensorPrivacyPolicy->isCameraPrivacyEnabled(multiuser_get_user_id(clientUid));if (client->supportsCameraMute()) {client->setCameraMute(mOverrideCameraMuteMode || isCameraPrivacyEnabled);} else if (isCameraPrivacyEnabled) {// no camera mute supported, but privacy is on! => disconnectALOGI("Camera mute not supported for package: %s, camera id: %s",String8(client->getPackageName()).string(), cameraId.string());// Do not hold mServiceLock while disconnecting clients, but// retain the condition blocking other clients from connecting// in mServiceLockWrapper if held.mServiceLock.unlock();// Clear caller identity temporarily so client disconnect PID// checks work correctlyint64_t token = CameraThreadState::clearCallingIdentity();// Note AppOp to trigger the "Unblock" dialogclient->noteAppOp();client->disconnect();CameraThreadState::restoreCallingIdentity(token);// Reacquire mServiceLockmServiceLock.lock();return STATUS_ERROR_FMT(ERROR_DISABLED,"Camera \"%s\" disabled due to camera mute", cameraId.string());}
bool isCameraPrivacyEnabled =mSensorPrivacyPolicy->isCameraPrivacyEnabled(multiuser_get_user_id(clientUid));if (isCameraPrivacyEnabled) {// no camera mute supported, but privacy is on! => disconnectALOGI("Camera mute not supported for package: %s, camera id: %s",String8(client->getPackageName()).string(), cameraId.string());bool CameraService::SensorPrivacyPolicy::isCameraPrivacyEnabled(userid_t userId) {if (!hasCameraPrivacyFeature()) {return false;}return mSpm.isIndividualSensorPrivacyEnabled(userId,SensorPrivacyManager::INDIVIDUAL_SENSOR_CAMERA);}----- SensorPrivacyService.javaisIndividualSensorPrivacyEnabled()
评论 (0)