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

Commit 28dac743 authored by Valentin Iftime's avatar Valentin Iftime
Browse files

Set HW toggle states

Propagate HW toggle state from InputManagerService to SensorPrivacyManager.
Enable devices with 2-way (on/off) or 3-way hardware switches (on/mic-only/off)
 to control the microphone and camera privacy toggles state and behavior.

Devices map the hardware toggles GPIO to SW_MUTE_DEVICE
 and SW_CAMERA_LENS_COVER codes, which are handled by InputFlinger -> InputManagerService.

Test: atest SensorPrivacyServiceMockingTest , Manual
Bug: 191745272
Change-Id: If968a2c2292ab73808e7d5735f156515a6d62e03
parent 92e6edf5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -61,4 +61,9 @@ public abstract class SensorPrivacyManagerInternal {
     */
    public abstract void addSensorPrivacyListenerForAllUsers(int sensor,
            OnUserSensorPrivacyChangedListener listener);

    /**
     *  Set the HW toggle sensor value based on HW switch states, called from InputManagerService
     */
    public abstract void setPhysicalToggleSensorPrivacy(int userId, int sensor, boolean enable);
}
+6 −0
Original line number Diff line number Diff line
@@ -49,6 +49,12 @@
        com.android.systemui/com.android.systemui.sensorprivacy.television.TvUnblockSensorActivity
    </string>

    <!-- Component name of the activity used to inform a user about a sensory being blocked because
     of hardware privacy switches. -->
    <string name="config_sensorUseStartedActivity_hwToggle" translatable="false">
        com.android.systemui/com.android.systemui.sensorprivacy.television.TvUnblockSensorActivity
    </string>

    <!-- Component name of the activity that shows the request for access to a usb device. -->
    <string name="config_usbPermissionActivity" translatable="false">
        com.android.systemui/com.android.systemui.usb.tv.TvUsbPermissionActivity
+7 −0
Original line number Diff line number Diff line
@@ -2902,6 +2902,11 @@
    <string name="config_sensorUseStartedActivity" translatable="false"
            >com.android.systemui/com.android.systemui.sensorprivacy.SensorUseStartedActivity</string>

    <!-- Component name of the activity used to inform a user about a sensory being blocked because
     of hardware privacy switches. -->
    <string name="config_sensorUseStartedActivity_hwToggle" translatable="false"
            >com.android.systemui/com.android.systemui.sensorprivacy.SensorUseStartedActivity</string>

    <!-- Component name of the activity used to ask a user to confirm system language change after
         receiving <Set Menu Language> CEC message. -->
    <string name="config_hdmiCecSetMenuLanguageActivity"
@@ -5478,6 +5483,8 @@
    <bool name="config_supportsHardwareMicToggle">false</bool>
    <!-- Whether this device is supporting the hardware camera toggle -->
    <bool name="config_supportsHardwareCamToggle">false</bool>
    <!-- Whether a camera intent is launched when the lens cover is toggled -->
    <bool name="config_launchCameraOnCameraLensCoverToggle">true</bool>

    <!-- List containing the allowed install sources for accessibility service. -->
    <string-array name="config_accessibility_allowed_install_source" translatable="false"/>
+2 −0
Original line number Diff line number Diff line
@@ -375,6 +375,7 @@
  <java-symbol type="string" name="config_usbConfirmActivity" />
  <java-symbol type="string" name="config_usbResolverActivity" />
  <java-symbol type="string" name="config_sensorUseStartedActivity" />
  <java-symbol type="string" name="config_sensorUseStartedActivity_hwToggle" />
  <java-symbol type="string" name="config_hdmiCecSetMenuLanguageActivity" />
  <java-symbol type="integer" name="config_minNumVisibleRecentTasks_lowRam" />
  <java-symbol type="integer" name="config_maxNumVisibleRecentTasks_lowRam" />
@@ -4648,6 +4649,7 @@
  <java-symbol type="bool" name="config_supportsCamToggle" />
  <java-symbol type="bool" name="config_supportsHardwareMicToggle" />
  <java-symbol type="bool" name="config_supportsHardwareCamToggle" />
  <java-symbol type="bool" name="config_launchCameraOnCameraLensCoverToggle" />

  <java-symbol type="dimen" name="starting_surface_icon_size" />
  <java-symbol type="dimen" name="starting_surface_default_icon_size" />
+29 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.database.ContentObserver;
import android.graphics.PointF;
import android.hardware.SensorPrivacyManager;
import android.hardware.SensorPrivacyManager.Sensors;
import android.hardware.SensorPrivacyManagerInternal;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayViewport;
import android.hardware.input.IInputDevicesChangedListener;
@@ -550,6 +553,19 @@ public class InputManagerService extends IInputManager.Stub
            }
        }

        // Set the HW mic toggle switch state
        final int micMuteState = getSwitchState(-1 /* deviceId */, InputDevice.SOURCE_ANY,
                SW_MUTE_DEVICE);
        if (micMuteState != InputManager.SWITCH_STATE_UNKNOWN) {
            setSensorPrivacy(Sensors.MICROPHONE, micMuteState != InputManager.SWITCH_STATE_OFF);
        }
        // Set the HW camera toggle switch state
        final int cameraMuteState = getSwitchState(-1 /* deviceId */, InputDevice.SOURCE_ANY,
                SW_CAMERA_LENS_COVER);
        if (cameraMuteState != InputManager.SWITCH_STATE_UNKNOWN) {
            setSensorPrivacy(Sensors.CAMERA, cameraMuteState != InputManager.SWITCH_STATE_OFF);
        }

        IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
@@ -2816,6 +2832,8 @@ public class InputManagerService extends IInputManager.Stub
        if ((switchMask & SW_CAMERA_LENS_COVER_BIT) != 0) {
            final boolean lensCovered = ((switchValues & SW_CAMERA_LENS_COVER_BIT) != 0);
            mWindowManagerCallbacks.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered);
            // Use SW_CAMERA_LENS_COVER code for camera privacy toggles
            setSensorPrivacy(Sensors.CAMERA, lensCovered);
        }

        if (mUseDevInputEventForAudioJack && (switchMask & SW_JACK_BITS) != 0) {
@@ -2836,7 +2854,18 @@ public class InputManagerService extends IInputManager.Stub
            final boolean micMute = ((switchValues & SW_MUTE_DEVICE_BIT) != 0);
            AudioManager audioManager = mContext.getSystemService(AudioManager.class);
            audioManager.setMicrophoneMuteFromSwitch(micMute);

            setSensorPrivacy(Sensors.MICROPHONE, micMute);
        }
    }

    // Set the sensor privacy state based on the hardware toggles switch states
    private void setSensorPrivacy(@SensorPrivacyManager.Sensors.Sensor int sensor,
            boolean enablePrivacy) {
        final SensorPrivacyManagerInternal sensorPrivacyManagerInternal =
                LocalServices.getService(SensorPrivacyManagerInternal.class);
        sensorPrivacyManagerInternal.setPhysicalToggleSensorPrivacy(UserHandle.USER_CURRENT, sensor,
                enablePrivacy);
    }

    // Native callback.
Loading