Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0b69924 authored by Evan Severson's avatar Evan Severson
Browse files

Update cameraservice to use new sensor privacy api

The new calls no longer require user ids since that is managed
internally in the sensor privacy service and calling services will
receive updates when the state is changed or user is changed who has a
different setting. Calling services should treat the state as a global
setting.

The new calls also add support for hardware controls. This change
ignores changes to hardware state.

Test: Build
Bug: 191745272
Change-Id: Id56c3b117f2a25bd3c1d3a232192fd6794001bfb
parent d8dc6834
Loading
Loading
Loading
Loading
+13 −11
Original line number Original line Diff line number Diff line
@@ -1890,7 +1890,7 @@ Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8&


        // Set camera muting behavior
        // Set camera muting behavior
        bool isCameraPrivacyEnabled =
        bool isCameraPrivacyEnabled =
                mSensorPrivacyPolicy->isCameraPrivacyEnabled(multiuser_get_user_id(clientUid));
                mSensorPrivacyPolicy->isCameraPrivacyEnabled();
        if (client->supportsCameraMute()) {
        if (client->supportsCameraMute()) {
            client->setCameraMute(
            client->setCameraMute(
                    mOverrideCameraMuteMode || isCameraPrivacyEnabled);
                    mOverrideCameraMuteMode || isCameraPrivacyEnabled);
@@ -3385,8 +3385,7 @@ status_t CameraService::BasicClient::handleAppOpMode(int32_t mode) {
        bool isUidActive = sCameraService->mUidPolicy->isUidActive(mClientUid,
        bool isUidActive = sCameraService->mUidPolicy->isUidActive(mClientUid,
                mClientPackageName);
                mClientPackageName);
        bool isCameraPrivacyEnabled =
        bool isCameraPrivacyEnabled =
                sCameraService->mSensorPrivacyPolicy->isCameraPrivacyEnabled(
                sCameraService->mSensorPrivacyPolicy->isCameraPrivacyEnabled();
                    multiuser_get_user_id(mClientUid));
        if (!isUidActive || !isCameraPrivacyEnabled) {
        if (!isUidActive || !isCameraPrivacyEnabled) {
            ALOGI("Camera %s: Access for \"%s\" has been restricted",
            ALOGI("Camera %s: Access for \"%s\" has been restricted",
                    mCameraIdStr.string(), String8(mClientPackageName).string());
                    mCameraIdStr.string(), String8(mClientPackageName).string());
@@ -3568,8 +3567,7 @@ void CameraService::BasicClient::opChanged(int32_t op, const String16&) {
    } else if (res == AppOpsManager::MODE_IGNORED) {
    } else if (res == AppOpsManager::MODE_IGNORED) {
        bool isUidActive = sCameraService->mUidPolicy->isUidActive(mClientUid, mClientPackageName);
        bool isUidActive = sCameraService->mUidPolicy->isUidActive(mClientUid, mClientPackageName);
        bool isCameraPrivacyEnabled =
        bool isCameraPrivacyEnabled =
                sCameraService->mSensorPrivacyPolicy->isCameraPrivacyEnabled(
                sCameraService->mSensorPrivacyPolicy->isCameraPrivacyEnabled();
                        multiuser_get_user_id(mClientUid));
        ALOGI("Camera %s: Access for \"%s\" has been restricted, isUidTrusted %d, isUidActive %d",
        ALOGI("Camera %s: Access for \"%s\" has been restricted, isUidTrusted %d, isUidActive %d",
                mCameraIdStr.string(), String8(mClientPackageName).string(),
                mCameraIdStr.string(), String8(mClientPackageName).string(),
                mUidIsTrusted, isUidActive);
                mUidIsTrusted, isUidActive);
@@ -3881,18 +3879,18 @@ bool CameraService::SensorPrivacyPolicy::isSensorPrivacyEnabled() {
    return mSensorPrivacyEnabled;
    return mSensorPrivacyEnabled;
}
}


bool CameraService::SensorPrivacyPolicy::isCameraPrivacyEnabled(userid_t userId) {
bool CameraService::SensorPrivacyPolicy::isCameraPrivacyEnabled() {
    if (!hasCameraPrivacyFeature()) {
    if (!hasCameraPrivacyFeature()) {
        return false;
        return false;
    }
    }
    return mSpm.isIndividualSensorPrivacyEnabled(userId,
    return mSpm.isToggleSensorPrivacyEnabled(SensorPrivacyManager::TOGGLE_SENSOR_CAMERA);
        SensorPrivacyManager::INDIVIDUAL_SENSOR_CAMERA);
}
}


binder::Status CameraService::SensorPrivacyPolicy::onSensorPrivacyChanged(bool enabled) {
binder::Status CameraService::SensorPrivacyPolicy::onSensorPrivacyChanged(
    int toggleType __unused, int sensor __unused, bool enabled) {
    {
    {
        Mutex::Autolock _l(mSensorPrivacyLock);
        Mutex::Autolock _l(mSensorPrivacyLock);
        mSensorPrivacyEnabled = enabled;
        mSensorPrivacyEnabled = mSpm.isToggleSensorPrivacyEnabled(SensorPrivacyManager::TOGGLE_SENSOR_CAMERA);
    }
    }
    // if sensor privacy is enabled then block all clients from accessing the camera
    // if sensor privacy is enabled then block all clients from accessing the camera
    if (enabled) {
    if (enabled) {
@@ -3911,7 +3909,11 @@ void CameraService::SensorPrivacyPolicy::binderDied(const wp<IBinder>& /*who*/)
}
}


bool CameraService::SensorPrivacyPolicy::hasCameraPrivacyFeature() {
bool CameraService::SensorPrivacyPolicy::hasCameraPrivacyFeature() {
    return mSpm.supportsSensorToggle(SensorPrivacyManager::INDIVIDUAL_SENSOR_CAMERA);
    bool supportsSoftwareToggle = mSpm.supportsSensorToggle(
            SensorPrivacyManager::TOGGLE_TYPE_SOFTWARE, SensorPrivacyManager::TOGGLE_SENSOR_CAMERA);
    bool supportsHardwareToggle = mSpm.supportsSensorToggle(
            SensorPrivacyManager::TOGGLE_TYPE_HARDWARE, SensorPrivacyManager::TOGGLE_SENSOR_CAMERA);
    return supportsSoftwareToggle || supportsHardwareToggle;
}
}


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
+3 −2
Original line number Original line Diff line number Diff line
@@ -735,9 +735,10 @@ private:
            void unregisterSelf();
            void unregisterSelf();


            bool isSensorPrivacyEnabled();
            bool isSensorPrivacyEnabled();
            bool isCameraPrivacyEnabled(userid_t userId);
            bool isCameraPrivacyEnabled();


            binder::Status onSensorPrivacyChanged(bool enabled);
            binder::Status onSensorPrivacyChanged(int toggleType, int sensor,
                                                  bool enabled);


            // IBinder::DeathRecipient implementation
            // IBinder::DeathRecipient implementation
            virtual void binderDied(const wp<IBinder> &who);
            virtual void binderDied(const wp<IBinder> &who);