Android 系统设置,“隐私”中关闭相机权限

Android系统设置中,"隐私"里面,有一项是 关于"摄像头使用权限",如果关闭了,则所有的app都没法正常去打开相机。

我们如果需要做类似禁用相机的功能,也是可以参考该部分的代码流程逻辑。

这一功能涉及到的相关代码,如下图所示。

CameraService.cpp

php 复制代码
--------- 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! => disconnect            ALOGI("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 correctly            int64_t token = CameraThreadState::clearCallingIdentity();            // Note AppOp to trigger the "Unblock" dialog            client->noteAppOp();            client->disconnect();            CameraThreadState::restoreCallingIdentity(token);            // Reacquire mServiceLock            mServiceLock.lock();            return STATUS_ERROR_FMT(ERROR_DISABLED,                    "Camera \"%s\" disabled due to camera mute", cameraId.string());        }
php 复制代码
bool isCameraPrivacyEnabled =                mSensorPrivacyPolicy->isCameraPrivacyEnabled(multiuser_get_user_id(clientUid));
if (isCameraPrivacyEnabled) {        // no camera mute supported, but privacy is on! => disconnect        ALOGI("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.java        isIndividualSensorPrivacyEnabled()

《小驰行动派的知识星球》



推荐阅读:

关于博主

采用v4l2loopback来实现 虚拟Camera

Camera基础及一些基本概念

Android Camera 学习路线 | 个人推荐

Android Camera开发系列(干货满满)

Camera Hal|如何学习一个新平台

一篇文章带你了解Android 最新Camera框架

学习完Camera入门课程视频,可以去找工作了?