diff options
author | 2024-01-09 22:01:10 -0800 | |
---|---|---|
committer | 2024-01-31 16:07:18 -0800 | |
commit | d5660e3ce79a054834411dced896de31ce7475b1 (patch) | |
tree | 859ef80ba429f72b35cca8d8c1da767ea8c7ea53 | |
parent | b0990e3fd6dc327f28b7198ae4883d11d5dcf1be (diff) |
Implement camera privacy allowlist.
This feature enables the user to access the camera for certain
driver assistance applications regardless of the device-wide global
camera privacy toggle in order to preserve user safety and meet
safety regulations.
Flag: ACONFIG com.android.internal.camera.flags.privacy_allowlist DEVELOPMENT
Bug: 300986585
Test: Build and test using kitchensink.
Change-Id: Ia566e1c28c9dee559007bbbcf84b78d15fa3edde
7 files changed, 91 insertions, 3 deletions
diff --git a/libs/sensorprivacy/Android.bp b/libs/sensorprivacy/Android.bp index 00514c4417..1e7e70775a 100644 --- a/libs/sensorprivacy/Android.bp +++ b/libs/sensorprivacy/Android.bp @@ -57,6 +57,7 @@ cc_library_shared { filegroup { name: "libsensorprivacy_aidl", srcs: [ + "aidl/android/hardware/CameraPrivacyAllowlistEntry.aidl", "aidl/android/hardware/ISensorPrivacyListener.aidl", "aidl/android/hardware/ISensorPrivacyManager.aidl", ], diff --git a/libs/sensorprivacy/SensorPrivacyManager.cpp b/libs/sensorprivacy/SensorPrivacyManager.cpp index 57c74ee565..fe9378616d 100644 --- a/libs/sensorprivacy/SensorPrivacyManager.cpp +++ b/libs/sensorprivacy/SensorPrivacyManager.cpp @@ -108,7 +108,7 @@ bool SensorPrivacyManager::isSensorPrivacyEnabled() bool SensorPrivacyManager::isToggleSensorPrivacyEnabled(int sensor) { - sp<hardware::ISensorPrivacyManager> service = getService(); + sp<hardware::ISensorPrivacyManager> service = getService(); if (service != nullptr) { bool result; service->isCombinedToggleSensorPrivacyEnabled(sensor, &result); @@ -143,6 +143,39 @@ status_t SensorPrivacyManager::isToggleSensorPrivacyEnabled(int toggleType, int return UNKNOWN_ERROR; } +int SensorPrivacyManager::getToggleSensorPrivacyState(int toggleType, int sensor) +{ + sp<hardware::ISensorPrivacyManager> service = getService(); + if (service != nullptr) { + int result; + service->getToggleSensorPrivacyState(toggleType, sensor, &result); + return result; + } + // if the SensorPrivacyManager is not available then assume sensor privacy is disabled + return DISABLED; +} + +std::vector<hardware::CameraPrivacyAllowlistEntry> + SensorPrivacyManager::getCameraPrivacyAllowlist(){ + sp<hardware::ISensorPrivacyManager> service = getService(); + std::vector<hardware::CameraPrivacyAllowlistEntry> result; + if (service != nullptr) { + service->getCameraPrivacyAllowlist(&result); + return result; + } + return result; +} + +bool SensorPrivacyManager::isCameraPrivacyEnabled(String16 packageName){ + sp<hardware::ISensorPrivacyManager> service = getService(); + if (service != nullptr) { + bool result; + service->isCameraPrivacyEnabled(packageName, &result); + return result; + } + return false; +} + status_t SensorPrivacyManager::linkToDeath(const sp<IBinder::DeathRecipient>& recipient) { sp<hardware::ISensorPrivacyManager> service = getService(); diff --git a/libs/sensorprivacy/aidl/android/hardware/CameraPrivacyAllowlistEntry.aidl b/libs/sensorprivacy/aidl/android/hardware/CameraPrivacyAllowlistEntry.aidl new file mode 100644 index 0000000000..03e153704b --- /dev/null +++ b/libs/sensorprivacy/aidl/android/hardware/CameraPrivacyAllowlistEntry.aidl @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2024, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware; + +parcelable CameraPrivacyAllowlistEntry { + String packageName; + boolean isMandatory; +} diff --git a/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyListener.aidl b/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyListener.aidl index eccd54c3eb..694af00a87 100644 --- a/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyListener.aidl +++ b/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyListener.aidl @@ -21,4 +21,5 @@ package android.hardware; */ oneway interface ISensorPrivacyListener { void onSensorPrivacyChanged(int toggleType, int sensor, boolean enabled); + void onSensorPrivacyStateChanged(int toggleType, int sensor, int state); } diff --git a/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyManager.aidl b/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyManager.aidl index 49a1e1ea05..b6bd39e557 100644 --- a/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyManager.aidl +++ b/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyManager.aidl @@ -16,6 +16,7 @@ package android.hardware; +import android.hardware.CameraPrivacyAllowlistEntry; import android.hardware.ISensorPrivacyListener; /** @hide */ @@ -41,4 +42,15 @@ interface ISensorPrivacyManager { void setToggleSensorPrivacy(int userId, int source, int sensor, boolean enable); void setToggleSensorPrivacyForProfileGroup(int userId, int source, int sensor, boolean enable); + + List<CameraPrivacyAllowlistEntry> getCameraPrivacyAllowlist(); + + int getToggleSensorPrivacyState(int toggleType, int sensor); + + void setToggleSensorPrivacyState(int userId, int source, int sensor, int state); + + void setToggleSensorPrivacyStateForProfileGroup(int userId, int source, int sensor, int state); + + boolean isCameraPrivacyEnabled(String packageName); + } diff --git a/libs/sensorprivacy/include/sensorprivacy/SensorPrivacyManager.h b/libs/sensorprivacy/include/sensorprivacy/SensorPrivacyManager.h index fc5fdf7900..9e97e166be 100644 --- a/libs/sensorprivacy/include/sensorprivacy/SensorPrivacyManager.h +++ b/libs/sensorprivacy/include/sensorprivacy/SensorPrivacyManager.h @@ -32,12 +32,22 @@ class SensorPrivacyManager public: enum { TOGGLE_SENSOR_MICROPHONE = 1, - TOGGLE_SENSOR_CAMERA = 2 + TOGGLE_SENSOR_CAMERA = 2, + TOGGLE_SENSOR_UNKNOWN = -1 }; enum { TOGGLE_TYPE_SOFTWARE = 1, - TOGGLE_TYPE_HARDWARE = 2 + TOGGLE_TYPE_HARDWARE = 2, + TOGGLE_TYPE_UNKNOWN = -1 + }; + + enum { + ENABLED = 1, + DISABLED = 2, + AUTOMOTIVE_DRIVER_ASSISTANCE_HELPFUL_APPS = 3, + AUTOMOTIVE_DRIVER_ASSISTANCE_REQUIRED_APPS = 4, + AUTOMOTIVE_DRIVER_ASSISTANCE_APPS = 5 }; SensorPrivacyManager(); @@ -51,6 +61,9 @@ public: bool isToggleSensorPrivacyEnabled(int sensor); bool isToggleSensorPrivacyEnabled(int toggleType, int sensor); status_t isToggleSensorPrivacyEnabled(int toggleType, int sensor, bool &result); + int getToggleSensorPrivacyState(int toggleType, int sensor); + std::vector<hardware::CameraPrivacyAllowlistEntry> getCameraPrivacyAllowlist(); + bool isCameraPrivacyEnabled(String16 packageName); status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient); status_t unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient); diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h index ad10e7a7bd..118d9281fc 100644 --- a/services/sensorservice/SensorService.h +++ b/services/sensorservice/SensorService.h @@ -340,6 +340,12 @@ private: binder::Status onSensorPrivacyChanged(int toggleType, int sensor, bool enabled); + // This callback is used for additional automotive-specific states for sensor privacy + // such as AUTO_DRIVER_ASSISTANCE_APPS. The newly defined states will only be valid + // for camera privacy on automotive devices. onSensorPrivacyChanged() will still be + // invoked whenever the enabled status of a toggle changes. + binder::Status onSensorPrivacyStateChanged(int, int, int) {return binder::Status::ok();} + protected: std::atomic_bool mSensorPrivacyEnabled; wp<SensorService> mService; |