Loading packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt +1 −7 Original line number Original line Diff line number Diff line Loading @@ -65,12 +65,6 @@ constructor( * [NoteTaskController], ensure custom actions can be triggered (i.e., keyboard shortcut). * [NoteTaskController], ensure custom actions can be triggered (i.e., keyboard shortcut). */ */ private fun initializeHandleSystemKey() { private fun initializeHandleSystemKey() { val callbacks = object : CommandQueue.Callbacks { override fun handleSystemKey(key: KeyEvent) { key.toNoteTaskEntryPointOrNull()?.let(controller::showNoteTask) } } commandQueue.addCallback(callbacks) commandQueue.addCallback(callbacks) } } Loading Loading @@ -142,7 +136,7 @@ constructor( */ */ private fun KeyEvent.toNoteTaskEntryPointOrNull(): NoteTaskEntryPoint? = private fun KeyEvent.toNoteTaskEntryPointOrNull(): NoteTaskEntryPoint? = when { when { keyCode == KEYCODE_STYLUS_BUTTON_TAIL -> TAIL_BUTTON keyCode == KEYCODE_STYLUS_BUTTON_TAIL && action == KeyEvent.ACTION_UP -> TAIL_BUTTON keyCode == KEYCODE_N && isMetaPressed && isCtrlPressed -> KEYBOARD_SHORTCUT keyCode == KEYCODE_N && isMetaPressed && isCtrlPressed -> KEYBOARD_SHORTCUT else -> null else -> null } } packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt +60 −28 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,8 @@ import android.os.UserManager import android.testing.AndroidTestingRunner import android.testing.AndroidTestingRunner import android.view.KeyEvent import android.view.KeyEvent import android.view.KeyEvent.ACTION_DOWN import android.view.KeyEvent.ACTION_DOWN import android.view.KeyEvent.ACTION_UP import android.view.KeyEvent.KEYCODE_N import android.view.KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL import android.view.KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest import com.android.keyguard.KeyguardUpdateMonitor import com.android.keyguard.KeyguardUpdateMonitor Loading @@ -30,7 +32,6 @@ import com.android.systemui.settings.FakeUserTracker import com.android.systemui.statusbar.CommandQueue import com.android.systemui.statusbar.CommandQueue import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.eq import com.android.systemui.util.mockito.eq import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.util.mockito.whenever Loading @@ -43,7 +44,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.Before import org.junit.Before import org.junit.Test import org.junit.Test import org.junit.runner.RunWith import org.junit.runner.RunWith import org.mockito.ArgumentCaptor import org.mockito.Mock import org.mockito.Mock import org.mockito.Mockito.never import org.mockito.Mockito.never import org.mockito.Mockito.times import org.mockito.Mockito.times Loading @@ -66,6 +66,7 @@ internal class NoteTaskInitializerTest : SysuiTestCase() { private val executor = FakeExecutor(FakeSystemClock()) private val executor = FakeExecutor(FakeSystemClock()) private val userTracker = FakeUserTracker() private val userTracker = FakeUserTracker() private val handlerCallbacks = mutableListOf<Runnable>() @Before @Before fun setUp() { fun setUp() { Loading @@ -88,6 +89,14 @@ internal class NoteTaskInitializerTest : SysuiTestCase() { backgroundExecutor = executor, backgroundExecutor = executor, ) ) private fun createKeyEvent( action: Int, code: Int, downTime: Long = 0L, eventTime: Long = 0L, metaState: Int = 0 ): KeyEvent = KeyEvent(downTime, eventTime, action, code, 0 /*repeat*/, metaState) @Test @Test fun initialize_withUserUnlocked() { fun initialize_withUserUnlocked() { whenever(keyguardMonitor.isUserUnlocked(userTracker.userId)).thenReturn(true) whenever(keyguardMonitor.isUserUnlocked(userTracker.userId)).thenReturn(true) Loading Loading @@ -147,7 +156,12 @@ internal class NoteTaskInitializerTest : SysuiTestCase() { @Test @Test fun initialize_handleSystemKey() { fun initialize_handleSystemKey() { val expectedKeyEvent = KeyEvent(ACTION_DOWN, KEYCODE_STYLUS_BUTTON_TAIL) val expectedKeyEvent = createKeyEvent( ACTION_DOWN, KEYCODE_N, metaState = KeyEvent.META_META_ON or KeyEvent.META_CTRL_ON ) val underTest = createUnderTest(isEnabled = true, bubbles = bubbles) val underTest = createUnderTest(isEnabled = true, bubbles = bubbles) underTest.initialize() underTest.initialize() val callback = withArgCaptor { verify(commandQueue).addCallback(capture()) } val callback = withArgCaptor { verify(commandQueue).addCallback(capture()) } Loading Loading @@ -203,4 +217,22 @@ internal class NoteTaskInitializerTest : SysuiTestCase() { verify(controller, times(2)).updateNoteTaskForCurrentUserAndManagedProfiles() verify(controller, times(2)).updateNoteTaskForCurrentUserAndManagedProfiles() } } @Test fun tailButtonGestureDetection_singlePress_shouldShowNoteTaskOnUp() { val underTest = createUnderTest(isEnabled = true, bubbles = bubbles) underTest.initialize() val callback = withArgCaptor { verify(commandQueue).addCallback(capture()) } callback.handleSystemKey( createKeyEvent(ACTION_DOWN, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 0, eventTime = 0) ) verify(controller, never()).showNoteTask(any()) callback.handleSystemKey( createKeyEvent(ACTION_UP, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 0, eventTime = 50) ) verify(controller).showNoteTask(any()) } } } services/core/java/com/android/server/policy/PhoneWindowManager.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -4773,7 +4773,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { case KeyEvent.KEYCODE_STYLUS_BUTTON_SECONDARY: case KeyEvent.KEYCODE_STYLUS_BUTTON_SECONDARY: case KeyEvent.KEYCODE_STYLUS_BUTTON_TERTIARY: case KeyEvent.KEYCODE_STYLUS_BUTTON_TERTIARY: case KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL: { case KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL: { if (down && mStylusButtonsEnabled) { if (mStylusButtonsEnabled) { sendSystemKeyToStatusBarAsync(event); sendSystemKeyToStatusBarAsync(event); } } result &= ~ACTION_PASS_TO_USER; result &= ~ACTION_PASS_TO_USER; Loading Loading
packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt +1 −7 Original line number Original line Diff line number Diff line Loading @@ -65,12 +65,6 @@ constructor( * [NoteTaskController], ensure custom actions can be triggered (i.e., keyboard shortcut). * [NoteTaskController], ensure custom actions can be triggered (i.e., keyboard shortcut). */ */ private fun initializeHandleSystemKey() { private fun initializeHandleSystemKey() { val callbacks = object : CommandQueue.Callbacks { override fun handleSystemKey(key: KeyEvent) { key.toNoteTaskEntryPointOrNull()?.let(controller::showNoteTask) } } commandQueue.addCallback(callbacks) commandQueue.addCallback(callbacks) } } Loading Loading @@ -142,7 +136,7 @@ constructor( */ */ private fun KeyEvent.toNoteTaskEntryPointOrNull(): NoteTaskEntryPoint? = private fun KeyEvent.toNoteTaskEntryPointOrNull(): NoteTaskEntryPoint? = when { when { keyCode == KEYCODE_STYLUS_BUTTON_TAIL -> TAIL_BUTTON keyCode == KEYCODE_STYLUS_BUTTON_TAIL && action == KeyEvent.ACTION_UP -> TAIL_BUTTON keyCode == KEYCODE_N && isMetaPressed && isCtrlPressed -> KEYBOARD_SHORTCUT keyCode == KEYCODE_N && isMetaPressed && isCtrlPressed -> KEYBOARD_SHORTCUT else -> null else -> null } }
packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt +60 −28 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,8 @@ import android.os.UserManager import android.testing.AndroidTestingRunner import android.testing.AndroidTestingRunner import android.view.KeyEvent import android.view.KeyEvent import android.view.KeyEvent.ACTION_DOWN import android.view.KeyEvent.ACTION_DOWN import android.view.KeyEvent.ACTION_UP import android.view.KeyEvent.KEYCODE_N import android.view.KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL import android.view.KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest import com.android.keyguard.KeyguardUpdateMonitor import com.android.keyguard.KeyguardUpdateMonitor Loading @@ -30,7 +32,6 @@ import com.android.systemui.settings.FakeUserTracker import com.android.systemui.statusbar.CommandQueue import com.android.systemui.statusbar.CommandQueue import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.eq import com.android.systemui.util.mockito.eq import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.util.mockito.whenever Loading @@ -43,7 +44,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.Before import org.junit.Before import org.junit.Test import org.junit.Test import org.junit.runner.RunWith import org.junit.runner.RunWith import org.mockito.ArgumentCaptor import org.mockito.Mock import org.mockito.Mock import org.mockito.Mockito.never import org.mockito.Mockito.never import org.mockito.Mockito.times import org.mockito.Mockito.times Loading @@ -66,6 +66,7 @@ internal class NoteTaskInitializerTest : SysuiTestCase() { private val executor = FakeExecutor(FakeSystemClock()) private val executor = FakeExecutor(FakeSystemClock()) private val userTracker = FakeUserTracker() private val userTracker = FakeUserTracker() private val handlerCallbacks = mutableListOf<Runnable>() @Before @Before fun setUp() { fun setUp() { Loading @@ -88,6 +89,14 @@ internal class NoteTaskInitializerTest : SysuiTestCase() { backgroundExecutor = executor, backgroundExecutor = executor, ) ) private fun createKeyEvent( action: Int, code: Int, downTime: Long = 0L, eventTime: Long = 0L, metaState: Int = 0 ): KeyEvent = KeyEvent(downTime, eventTime, action, code, 0 /*repeat*/, metaState) @Test @Test fun initialize_withUserUnlocked() { fun initialize_withUserUnlocked() { whenever(keyguardMonitor.isUserUnlocked(userTracker.userId)).thenReturn(true) whenever(keyguardMonitor.isUserUnlocked(userTracker.userId)).thenReturn(true) Loading Loading @@ -147,7 +156,12 @@ internal class NoteTaskInitializerTest : SysuiTestCase() { @Test @Test fun initialize_handleSystemKey() { fun initialize_handleSystemKey() { val expectedKeyEvent = KeyEvent(ACTION_DOWN, KEYCODE_STYLUS_BUTTON_TAIL) val expectedKeyEvent = createKeyEvent( ACTION_DOWN, KEYCODE_N, metaState = KeyEvent.META_META_ON or KeyEvent.META_CTRL_ON ) val underTest = createUnderTest(isEnabled = true, bubbles = bubbles) val underTest = createUnderTest(isEnabled = true, bubbles = bubbles) underTest.initialize() underTest.initialize() val callback = withArgCaptor { verify(commandQueue).addCallback(capture()) } val callback = withArgCaptor { verify(commandQueue).addCallback(capture()) } Loading Loading @@ -203,4 +217,22 @@ internal class NoteTaskInitializerTest : SysuiTestCase() { verify(controller, times(2)).updateNoteTaskForCurrentUserAndManagedProfiles() verify(controller, times(2)).updateNoteTaskForCurrentUserAndManagedProfiles() } } @Test fun tailButtonGestureDetection_singlePress_shouldShowNoteTaskOnUp() { val underTest = createUnderTest(isEnabled = true, bubbles = bubbles) underTest.initialize() val callback = withArgCaptor { verify(commandQueue).addCallback(capture()) } callback.handleSystemKey( createKeyEvent(ACTION_DOWN, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 0, eventTime = 0) ) verify(controller, never()).showNoteTask(any()) callback.handleSystemKey( createKeyEvent(ACTION_UP, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 0, eventTime = 50) ) verify(controller).showNoteTask(any()) } } }
services/core/java/com/android/server/policy/PhoneWindowManager.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -4773,7 +4773,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { case KeyEvent.KEYCODE_STYLUS_BUTTON_SECONDARY: case KeyEvent.KEYCODE_STYLUS_BUTTON_SECONDARY: case KeyEvent.KEYCODE_STYLUS_BUTTON_TERTIARY: case KeyEvent.KEYCODE_STYLUS_BUTTON_TERTIARY: case KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL: { case KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL: { if (down && mStylusButtonsEnabled) { if (mStylusButtonsEnabled) { sendSystemKeyToStatusBarAsync(event); sendSystemKeyToStatusBarAsync(event); } } result &= ~ACTION_PASS_TO_USER; result &= ~ACTION_PASS_TO_USER; Loading