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

Commit 9f09bb4e authored by Evan Severson's avatar Evan Severson Committed by Android (Google) Code Review
Browse files

Merge changes from topic "hardware_sensor_privacy_apis"

* changes:
  Update cameraservice to use new sensor privacy api
  Update audiopolicy service to use new sensor privacy api
parents 2a2f5554 d0b69924
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -1587,14 +1587,6 @@ void AudioPolicyService::SensorPrivacyPolicy::registerSelf() {
    spm.addSensorPrivacyListener(this);
}

void AudioPolicyService::SensorPrivacyPolicy::registerSelfForMicrophoneOnly(int userId) {
    SensorPrivacyManager spm;
    mSensorPrivacyEnabled = spm.isIndividualSensorPrivacyEnabled(userId,
            SensorPrivacyManager::INDIVIDUAL_SENSOR_MICROPHONE);
    spm.addIndividualSensorPrivacyListener(userId,
            SensorPrivacyManager::INDIVIDUAL_SENSOR_MICROPHONE, this);
}

void AudioPolicyService::SensorPrivacyPolicy::unregisterSelf() {
    SensorPrivacyManager spm;
    spm.removeSensorPrivacyListener(this);
@@ -1604,7 +1596,8 @@ bool AudioPolicyService::SensorPrivacyPolicy::isSensorPrivacyEnabled() {
    return mSensorPrivacyEnabled;
}

binder::Status AudioPolicyService::SensorPrivacyPolicy::onSensorPrivacyChanged(bool enabled) {
binder::Status AudioPolicyService::SensorPrivacyPolicy::onSensorPrivacyChanged(
    int toggleType __unused, int sensor __unused, bool enabled) {
    mSensorPrivacyEnabled = enabled;
    sp<AudioPolicyService> service = mService.promote();
    if (service != nullptr) {
+2 −2
Original line number Diff line number Diff line
@@ -488,12 +488,12 @@ private:
                    : mService(service) {}

            void registerSelf();
            void registerSelfForMicrophoneOnly(int userId);
            void unregisterSelf();

            bool isSensorPrivacyEnabled();

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

        private:
            wp<AudioPolicyService> mService;
+13 −11
Original line number Diff line number Diff line
@@ -1895,7 +1895,7 @@ Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8&

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

bool CameraService::SensorPrivacyPolicy::isCameraPrivacyEnabled(userid_t userId) {
bool CameraService::SensorPrivacyPolicy::isCameraPrivacyEnabled() {
    if (!hasCameraPrivacyFeature()) {
        return false;
    }
    return mSpm.isIndividualSensorPrivacyEnabled(userId,
        SensorPrivacyManager::INDIVIDUAL_SENSOR_CAMERA);
    return mSpm.isToggleSensorPrivacyEnabled(SensorPrivacyManager::TOGGLE_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);
        mSensorPrivacyEnabled = enabled;
        mSensorPrivacyEnabled = mSpm.isToggleSensorPrivacyEnabled(SensorPrivacyManager::TOGGLE_SENSOR_CAMERA);
    }
    // if sensor privacy is enabled then block all clients from accessing the camera
    if (enabled) {
@@ -3930,7 +3928,11 @@ void CameraService::SensorPrivacyPolicy::binderDied(const wp<IBinder>& /*who*/)
}

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 Diff line number Diff line
@@ -739,9 +739,10 @@ private:
            void unregisterSelf();

            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
            virtual void binderDied(const wp<IBinder> &who);