diff options
| author | 2021-01-13 00:18:48 -0800 | |
|---|---|---|
| committer | 2021-01-14 15:23:06 -0800 | |
| commit | c63bb6c7a7fe4d6f1b9826afd8b36df9b692a31e (patch) | |
| tree | b793ebb9ce922ebcc386d9e0975e171eed2432dd | |
| parent | fa5c2e7b404673453458a724369cd6509624b54e (diff) | |
Add support for Global Mic Disable user setting
This CL adds support for responding to changes in the
Global Microphone access disable user setting in the
ContextHub service.
Bug: 174691697
Test: run the ContexthubHidlTest VTS test, verify that the setting
change is propagated all the way to the stub in the CHRE framework.
Change-Id: Idd420bd110dd9d17ac9afcb5fc8be9113aa0a055
| -rw-r--r-- | services/core/java/com/android/server/location/contexthub/ContextHubService.java | 34 | ||||
| -rw-r--r-- | services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java | 35 |
2 files changed, 69 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubService.java b/services/core/java/com/android/server/location/contexthub/ContextHubService.java index 63a42f845cee..dc1a26ae6fea 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubService.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubService.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.ContentObserver; +import android.hardware.SensorPrivacyManager; import android.hardware.contexthub.V1_0.AsyncEventType; import android.hardware.contexthub.V1_0.ContextHub; import android.hardware.contexthub.V1_0.ContextHubMsg; @@ -117,6 +118,9 @@ public class ContextHubService extends IContextHubService.Stub { // True if WiFi is available for the Context Hub private boolean mIsWifiAvailable = false; + // True if audio is disabled for the ContextHub + private boolean mIsAudioDisabled = false; + // Lock object for sendWifiSettingUpdate() private final Object mSendWifiSettingUpdateLock = new Object(); @@ -256,6 +260,21 @@ public class ContextHubService extends IContextHubService.Stub { } }, UserHandle.USER_ALL); } + + if (mContextHubWrapper.supportsMicrophoneDisableSettingNotifications()) { + sendMicrophoneDisableSettingUpdate(); + + SensorPrivacyManager.OnSensorPrivacyChangedListener listener = + new SensorPrivacyManager.OnSensorPrivacyChangedListener() { + @Override + public void onSensorPrivacyChanged(boolean enabled) { + sendMicrophoneDisableSettingUpdate(); + } + }; + SensorPrivacyManager manager = SensorPrivacyManager.getInstance(mContext); + manager.addSensorPrivacyListener( + SensorPrivacyManager.INDIVIDUAL_SENSOR_MICROPHONE, listener); + } } /** @@ -999,6 +1018,21 @@ public class ContextHubService extends IContextHubService.Stub { mContextHubWrapper.onAirplaneModeSettingChanged(enabled); } + /** + * Obtains the latest microphone disable setting value and notifies the + * Context Hub. + */ + private void sendMicrophoneDisableSettingUpdate() { + SensorPrivacyManager manager = SensorPrivacyManager.getInstance(mContext); + boolean disabled = manager.isIndividualSensorPrivacyEnabled( + SensorPrivacyManager.INDIVIDUAL_SENSOR_MICROPHONE); + if (mIsAudioDisabled != disabled) { + mIsAudioDisabled = disabled; + mContextHubWrapper.onMicrophoneDisableSettingChanged(disabled); + } + } + + private String getCallingPackageName() { return mContext.getPackageManager().getNameForUid(Binder.getCallingUid()); } diff --git a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java index 4242d72239e2..c11e289c116b 100644 --- a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java +++ b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java @@ -129,6 +129,18 @@ public abstract class IContextHubWrapper { */ public abstract void onAirplaneModeSettingChanged(boolean enabled); + /** + * @return True if this version of the Contexthub HAL supports microphone + * disable setting notifications. + */ + public abstract boolean supportsMicrophoneDisableSettingNotifications(); + + /** + * Notifies the Contexthub implementation of a microphone disable setting + * change. + */ + public abstract void onMicrophoneDisableSettingChanged(boolean enabled); + private static class ContextHubWrapperV1_0 extends IContextHubWrapper { private android.hardware.contexthub.V1_0.IContexthub mHub; @@ -152,6 +164,10 @@ public abstract class IContextHubWrapper { return false; } + public boolean supportsMicrophoneDisableSettingNotifications() { + return false; + } + public void onLocationSettingChanged(boolean enabled) { } @@ -160,6 +176,9 @@ public abstract class IContextHubWrapper { public void onAirplaneModeSettingChanged(boolean enabled) { } + + public void onMicrophoneDisableSettingChanged(boolean enabled) { + } } private static class ContextHubWrapperV1_1 extends IContextHubWrapper { @@ -185,6 +204,10 @@ public abstract class IContextHubWrapper { return false; } + public boolean supportsMicrophoneDisableSettingNotifications() { + return false; + } + public void onLocationSettingChanged(boolean enabled) { try { mHub.onSettingChanged(Setting.LOCATION, @@ -199,6 +222,9 @@ public abstract class IContextHubWrapper { public void onAirplaneModeSettingChanged(boolean enabled) { } + + public void onMicrophoneDisableSettingChanged(boolean enabled) { + } } private static class ContextHubWrapperV1_2 extends IContextHubWrapper { @@ -224,6 +250,10 @@ public abstract class IContextHubWrapper { return true; } + public boolean supportsMicrophoneDisableSettingNotifications() { + return true; + } + public void onLocationSettingChanged(boolean enabled) { sendSettingChanged(Setting.LOCATION, enabled ? SettingValue.ENABLED : SettingValue.DISABLED); @@ -239,6 +269,11 @@ public abstract class IContextHubWrapper { enabled ? SettingValue.ENABLED : SettingValue.DISABLED); } + public void onMicrophoneDisableSettingChanged(boolean enabled) { + sendSettingChanged(android.hardware.contexthub.V1_2.Setting.GLOBAL_MIC_DISABLE, + enabled ? SettingValue.ENABLED : SettingValue.DISABLED); + } + private void sendSettingChanged(byte setting, byte newValue) { try { mHub.onSettingChanged_1_2(setting, newValue); |