Loading packages/SystemUI/AndroidManifest.xml +2 −0 Original line number Diff line number Diff line Loading @@ -341,6 +341,8 @@ <uses-permission android:name="android.permission.SET_UNRESTRICTED_KEEP_CLEAR_AREAS" /> <uses-permission android:name="android.permission.MONITOR_KEYBOARD_BACKLIGHT" /> <protected-broadcast android:name="com.android.settingslib.action.REGISTER_SLICE_RECEIVER" /> <protected-broadcast android:name="com.android.settingslib.action.UNREGISTER_SLICE_RECEIVER" /> <protected-broadcast android:name="com.android.settings.flashlight.action.FLASHLIGHT_CHANGED" /> Loading packages/SystemUI/src/com/android/systemui/keyboard/data/repository/KeyboardRepository.kt +24 −8 Original line number Diff line number Diff line Loading @@ -18,15 +18,19 @@ package com.android.systemui.keyboard.data.repository import android.hardware.input.InputManager import android.hardware.input.InputManager.KeyboardBacklightListener import android.hardware.input.KeyboardBacklightState import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.keyboard.data.model.BacklightModel import java.util.concurrent.Executor import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted Loading @@ -51,24 +55,22 @@ constructor( private val connectedDeviceIds: Flow<Set<Int>> = conflatedCallbackFlow { fun send(element: Set<Int>) = trySendWithFailureLogging(element, TAG) var connectedKeyboards = inputManager.inputDeviceIds.toSet() val listener = object : InputManager.InputDeviceListener { override fun onInputDeviceAdded(deviceId: Int) { connectedKeyboards = connectedKeyboards + deviceId send(connectedKeyboards) sendWithLogging(connectedKeyboards) } override fun onInputDeviceChanged(deviceId: Int) = Unit override fun onInputDeviceRemoved(deviceId: Int) { connectedKeyboards = connectedKeyboards - deviceId send(connectedKeyboards) sendWithLogging(connectedKeyboards) } } send(connectedKeyboards) sendWithLogging(connectedKeyboards) inputManager.registerInputDeviceListener(listener, /* handler= */ null) awaitClose { inputManager.unregisterInputDeviceListener(listener) } } Loading @@ -78,6 +80,16 @@ constructor( replay = 1, ) private val backlightStateListener: Flow<KeyboardBacklightState> = conflatedCallbackFlow { val listener = KeyboardBacklightListener { _, state, isTriggeredByKeyPress -> if (isTriggeredByKeyPress) { sendWithLogging(state) } } inputManager.registerKeyboardBacklightListener(Executor(Runnable::run), listener) awaitClose { inputManager.unregisterKeyboardBacklightListener(listener) } } override val keyboardConnected: Flow<Boolean> = connectedDeviceIds .map { it.any { deviceId -> isPhysicalFullKeyboard(deviceId) } } Loading @@ -85,8 +97,12 @@ constructor( .flowOn(backgroundDispatcher) override val backlight: Flow<BacklightModel> = conflatedCallbackFlow { // TODO(b/268645734) register BacklightListener backlightStateListener .map { BacklightModel(it.brightnessLevel, it.maxBrightnessLevel) } .flowOn(backgroundDispatcher) private fun <T> SendChannel<T>.sendWithLogging(element: T) { trySendWithFailureLogging(element, TAG) } private fun isPhysicalFullKeyboard(deviceId: Int): Boolean { Loading Loading
packages/SystemUI/AndroidManifest.xml +2 −0 Original line number Diff line number Diff line Loading @@ -341,6 +341,8 @@ <uses-permission android:name="android.permission.SET_UNRESTRICTED_KEEP_CLEAR_AREAS" /> <uses-permission android:name="android.permission.MONITOR_KEYBOARD_BACKLIGHT" /> <protected-broadcast android:name="com.android.settingslib.action.REGISTER_SLICE_RECEIVER" /> <protected-broadcast android:name="com.android.settingslib.action.UNREGISTER_SLICE_RECEIVER" /> <protected-broadcast android:name="com.android.settings.flashlight.action.FLASHLIGHT_CHANGED" /> Loading
packages/SystemUI/src/com/android/systemui/keyboard/data/repository/KeyboardRepository.kt +24 −8 Original line number Diff line number Diff line Loading @@ -18,15 +18,19 @@ package com.android.systemui.keyboard.data.repository import android.hardware.input.InputManager import android.hardware.input.InputManager.KeyboardBacklightListener import android.hardware.input.KeyboardBacklightState import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.keyboard.data.model.BacklightModel import java.util.concurrent.Executor import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted Loading @@ -51,24 +55,22 @@ constructor( private val connectedDeviceIds: Flow<Set<Int>> = conflatedCallbackFlow { fun send(element: Set<Int>) = trySendWithFailureLogging(element, TAG) var connectedKeyboards = inputManager.inputDeviceIds.toSet() val listener = object : InputManager.InputDeviceListener { override fun onInputDeviceAdded(deviceId: Int) { connectedKeyboards = connectedKeyboards + deviceId send(connectedKeyboards) sendWithLogging(connectedKeyboards) } override fun onInputDeviceChanged(deviceId: Int) = Unit override fun onInputDeviceRemoved(deviceId: Int) { connectedKeyboards = connectedKeyboards - deviceId send(connectedKeyboards) sendWithLogging(connectedKeyboards) } } send(connectedKeyboards) sendWithLogging(connectedKeyboards) inputManager.registerInputDeviceListener(listener, /* handler= */ null) awaitClose { inputManager.unregisterInputDeviceListener(listener) } } Loading @@ -78,6 +80,16 @@ constructor( replay = 1, ) private val backlightStateListener: Flow<KeyboardBacklightState> = conflatedCallbackFlow { val listener = KeyboardBacklightListener { _, state, isTriggeredByKeyPress -> if (isTriggeredByKeyPress) { sendWithLogging(state) } } inputManager.registerKeyboardBacklightListener(Executor(Runnable::run), listener) awaitClose { inputManager.unregisterKeyboardBacklightListener(listener) } } override val keyboardConnected: Flow<Boolean> = connectedDeviceIds .map { it.any { deviceId -> isPhysicalFullKeyboard(deviceId) } } Loading @@ -85,8 +97,12 @@ constructor( .flowOn(backgroundDispatcher) override val backlight: Flow<BacklightModel> = conflatedCallbackFlow { // TODO(b/268645734) register BacklightListener backlightStateListener .map { BacklightModel(it.brightnessLevel, it.maxBrightnessLevel) } .flowOn(backgroundDispatcher) private fun <T> SendChannel<T>.sendWithLogging(element: T) { trySendWithFailureLogging(element, TAG) } private fun isPhysicalFullKeyboard(deviceId: Int): Boolean { Loading