diff options
3 files changed, 75 insertions, 0 deletions
diff --git a/core/java/android/hardware/lights/Light.java b/core/java/android/hardware/lights/Light.java index 163f9fa83fe2..38f34e961ec0 100644 --- a/core/java/android/hardware/lights/Light.java +++ b/core/java/android/hardware/lights/Light.java @@ -71,6 +71,12 @@ public final class Light implements Parcelable { public static final int LIGHT_TYPE_KEYBOARD_MIC_MUTE = 10004; /** + * Type for keyboard volume mute light. + * @hide + */ + public static final int LIGHT_TYPE_KEYBOARD_VOLUME_MUTE = 10005; + + /** * Capability for lights that could adjust its LED brightness. If the capability is not present * the LED can only be turned either on or off. */ @@ -99,6 +105,7 @@ public final class Light implements Parcelable { LIGHT_TYPE_PLAYER_ID, LIGHT_TYPE_KEYBOARD_BACKLIGHT, LIGHT_TYPE_KEYBOARD_MIC_MUTE, + LIGHT_TYPE_KEYBOARD_VOLUME_MUTE, }) public @interface LightType {} diff --git a/services/core/java/com/android/server/input/KeyboardLedController.java b/services/core/java/com/android/server/input/KeyboardLedController.java index 5c404a2ae6e7..a2940d54fe4d 100644 --- a/services/core/java/com/android/server/input/KeyboardLedController.java +++ b/services/core/java/com/android/server/input/KeyboardLedController.java @@ -46,11 +46,13 @@ public final class KeyboardLedController implements InputManager.InputDeviceList private static final String TAG = KeyboardLedController.class.getSimpleName(); private static final int MSG_UPDATE_EXISTING_DEVICES = 1; private static final int MSG_UPDATE_MIC_MUTE_LED_STATE = 2; + private static final int MSG_UPDATE_AUDIO_MUTE_LED_STATE = 3; private final Context mContext; private final Handler mHandler; private final NativeInputManagerService mNative; private final SparseArray<InputDevice> mKeyboardsWithMicMuteLed = new SparseArray<>(); + private final SparseArray<InputDevice> mKeyboardsWithVolumeMuteLed = new SparseArray<>(); @NonNull private InputManager mInputManager; @NonNull @@ -66,6 +68,17 @@ public final class KeyboardLedController implements InputManager.InputDeviceList } }; + private BroadcastReceiver mVolumeMuteIntentReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); + if (streamType == AudioManager.USE_DEFAULT_STREAM_TYPE) { + Message msg = Message.obtain(mHandler, MSG_UPDATE_AUDIO_MUTE_LED_STATE); + mHandler.sendMessage(msg); + } + } + }; + KeyboardLedController(Context context, Looper looper, NativeInputManagerService nativeService) { mContext = context; @@ -83,6 +96,9 @@ public final class KeyboardLedController implements InputManager.InputDeviceList case MSG_UPDATE_MIC_MUTE_LED_STATE: updateMicMuteLedState(); return true; + case MSG_UPDATE_AUDIO_MUTE_LED_STATE: + updateVolumeMuteLedState(); + return true; } return false; } @@ -105,6 +121,21 @@ public final class KeyboardLedController implements InputManager.InputDeviceList } } + private void updateVolumeMuteLedState() { + int color = mAudioManager.isStreamMute(AudioManager.USE_DEFAULT_STREAM_TYPE) + ? Color.WHITE : Color.TRANSPARENT; + for (int i = 0; i < mKeyboardsWithVolumeMuteLed.size(); i++) { + InputDevice device = mKeyboardsWithVolumeMuteLed.valueAt(i); + if (device != null) { + int deviceId = device.getId(); + Light light = getKeyboardVolumeMuteLight(device); + if (light != null) { + mNative.setLightColor(deviceId, light.getId(), color); + } + } + } + } + private Light getKeyboardMicMuteLight(InputDevice device) { for (Light light : device.getLightsManager().getLights()) { if (light.getType() == Light.LIGHT_TYPE_KEYBOARD_MIC_MUTE @@ -115,6 +146,16 @@ public final class KeyboardLedController implements InputManager.InputDeviceList return null; } + private Light getKeyboardVolumeMuteLight(InputDevice device) { + for (Light light : device.getLightsManager().getLights()) { + if (light.getType() == Light.LIGHT_TYPE_KEYBOARD_VOLUME_MUTE + && light.hasBrightnessControl()) { + return light; + } + } + return null; + } + /** Called when the system is ready for us to start third-party code. */ public void systemRunning() { mSensorPrivacyManager = Objects.requireNonNull( @@ -131,6 +172,12 @@ public final class KeyboardLedController implements InputManager.InputDeviceList new IntentFilter(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED), null, mHandler); + mContext.registerReceiverAsUser( + mVolumeMuteIntentReceiver, + UserHandle.ALL, + new IntentFilter(AudioManager.STREAM_MUTE_CHANGED_ACTION), + null, + mHandler); } @Override @@ -141,6 +188,7 @@ public final class KeyboardLedController implements InputManager.InputDeviceList @Override public void onInputDeviceRemoved(int deviceId) { mKeyboardsWithMicMuteLed.remove(deviceId); + mKeyboardsWithVolumeMuteLed.remove(deviceId); } @Override @@ -154,6 +202,11 @@ public final class KeyboardLedController implements InputManager.InputDeviceList Message msg = Message.obtain(mHandler, MSG_UPDATE_MIC_MUTE_LED_STATE); mHandler.sendMessage(msg); } + if (getKeyboardVolumeMuteLight(inputDevice) != null) { + mKeyboardsWithVolumeMuteLed.put(deviceId, inputDevice); + Message msg = Message.obtain(mHandler, MSG_UPDATE_AUDIO_MUTE_LED_STATE); + mHandler.sendMessage(msg); + } } /** Dump the diagnostic information */ @@ -167,5 +220,14 @@ public final class KeyboardLedController implements InputManager.InputDeviceList + getKeyboardMicMuteLight(inputDevice).toString()); } ipw.decreaseIndent(); + ipw.println(TAG + ": " + mKeyboardsWithVolumeMuteLed.size() + + " keyboard volume mute lights"); + ipw.increaseIndent(); + for (int i = 0; i < mKeyboardsWithVolumeMuteLed.size(); i++) { + InputDevice inputDevice = mKeyboardsWithVolumeMuteLed.valueAt(i); + ipw.println(i + " " + inputDevice.getName() + ": " + + getKeyboardVolumeMuteLight(inputDevice).toString()); + } + ipw.decreaseIndent(); } } diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index e4ac8261afab..e38337540ad9 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -210,6 +210,7 @@ static struct { jfieldID lightTypePlayerId; jfieldID lightTypeKeyboardBacklight; jfieldID lightTypeKeyboardMicMute; + jfieldID lightTypeKeyboardVolumeMute; jfieldID lightCapabilityBrightness; jfieldID lightCapabilityColorRgb; } gLightClassInfo; @@ -2630,6 +2631,9 @@ static jobject nativeGetLights(JNIEnv* env, jobject nativeImplObj, jint deviceId } else if (lightInfo.type == InputDeviceLightType::KEYBOARD_MIC_MUTE) { jTypeId = env->GetStaticIntField(gLightClassInfo.clazz, gLightClassInfo.lightTypeKeyboardMicMute); + } else if (lightInfo.type == InputDeviceLightType::KEYBOARD_VOLUME_MUTE) { + jTypeId = env->GetStaticIntField(gLightClassInfo.clazz, + gLightClassInfo.lightTypeKeyboardVolumeMute); } else { ALOGW("Unknown light type %s", ftl::enum_string(lightInfo.type).c_str()); continue; @@ -3420,6 +3424,8 @@ int register_android_server_InputManager(JNIEnv* env) { env->GetStaticFieldID(gLightClassInfo.clazz, "LIGHT_TYPE_KEYBOARD_BACKLIGHT", "I"); gLightClassInfo.lightTypeKeyboardMicMute = env->GetStaticFieldID(gLightClassInfo.clazz, "LIGHT_TYPE_KEYBOARD_MIC_MUTE", "I"); + gLightClassInfo.lightTypeKeyboardVolumeMute = + env->GetStaticFieldID(gLightClassInfo.clazz, "LIGHT_TYPE_KEYBOARD_VOLUME_MUTE", "I"); gLightClassInfo.lightCapabilityBrightness = env->GetStaticFieldID(gLightClassInfo.clazz, "LIGHT_CAPABILITY_BRIGHTNESS", "I"); gLightClassInfo.lightCapabilityColorRgb = |