Merge "Handle Stylus Key Events in System UI" into tm-qpr-dev

This commit is contained in:
Marcello Galhardo
2023-01-12 13:22:30 +00:00
committed by Android (Google) Code Review
9 changed files with 34 additions and 33 deletions

View File

@@ -292,7 +292,7 @@
<queries> <queries>
<intent> <intent>
<action android:name="android.intent.action.NOTES" /> <action android:name="android.intent.action.CREATE_NOTE" />
</intent> </intent>
</queries> </queries>

View File

@@ -104,4 +104,9 @@ constructor(
PackageManager.DONT_KILL_APP, PackageManager.DONT_KILL_APP,
) )
} }
companion object {
// TODO(b/254604589): Use final KeyEvent.KEYCODE_* instead.
const val NOTE_TASK_KEY_EVENT = 311
}
} }

View File

@@ -16,7 +16,6 @@
package com.android.systemui.notetask package com.android.systemui.notetask
import android.view.KeyEvent
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import com.android.systemui.statusbar.CommandQueue import com.android.systemui.statusbar.CommandQueue
import com.android.wm.shell.bubbles.Bubbles import com.android.wm.shell.bubbles.Bubbles
@@ -37,7 +36,7 @@ constructor(
val callbacks = val callbacks =
object : CommandQueue.Callbacks { object : CommandQueue.Callbacks {
override fun handleSystemKey(keyCode: Int) { override fun handleSystemKey(keyCode: Int) {
if (keyCode == KeyEvent.KEYCODE_VIDEO_APP_1) { if (keyCode == NoteTaskController.NOTE_TASK_KEY_EVENT) {
noteTaskController.showNoteTask() noteTaskController.showNoteTask()
} }
} }

View File

@@ -21,12 +21,12 @@ import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.pm.PackageManager.ResolveInfoFlags import android.content.pm.PackageManager.ResolveInfoFlags
import com.android.systemui.notetask.NoteTaskIntentResolver.Companion.NOTES_ACTION import com.android.systemui.notetask.NoteTaskIntentResolver.Companion.ACTION_CREATE_NOTE
import javax.inject.Inject import javax.inject.Inject
/** /**
* Class responsible to query all apps and find one that can handle the [NOTES_ACTION]. If found, an * Class responsible to query all apps and find one that can handle the [ACTION_CREATE_NOTE]. If
* [Intent] ready for be launched will be returned. Otherwise, returns null. * found, an [Intent] ready for be launched will be returned. Otherwise, returns null.
* *
* TODO(b/248274123): should be revisited once the notes role is implemented. * TODO(b/248274123): should be revisited once the notes role is implemented.
*/ */
@@ -37,15 +37,16 @@ constructor(
) { ) {
fun resolveIntent(): Intent? { fun resolveIntent(): Intent? {
val intent = Intent(NOTES_ACTION) val intent = Intent(ACTION_CREATE_NOTE)
val flags = ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()) val flags = ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong())
val infoList = packageManager.queryIntentActivities(intent, flags) val infoList = packageManager.queryIntentActivities(intent, flags)
for (info in infoList) { for (info in infoList) {
val packageName = info.serviceInfo.applicationInfo.packageName ?: continue val packageName = info.activityInfo.applicationInfo.packageName ?: continue
val activityName = resolveActivityNameForNotesAction(packageName) ?: continue val activityName = resolveActivityNameForNotesAction(packageName) ?: continue
return Intent(NOTES_ACTION) return Intent(ACTION_CREATE_NOTE)
.setPackage(packageName)
.setComponent(ComponentName(packageName, activityName)) .setComponent(ComponentName(packageName, activityName))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
} }
@@ -54,7 +55,7 @@ constructor(
} }
private fun resolveActivityNameForNotesAction(packageName: String): String? { private fun resolveActivityNameForNotesAction(packageName: String): String? {
val intent = Intent(NOTES_ACTION).setPackage(packageName) val intent = Intent(ACTION_CREATE_NOTE).setPackage(packageName)
val flags = ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()) val flags = ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong())
val resolveInfo = packageManager.resolveActivity(intent, flags) val resolveInfo = packageManager.resolveActivity(intent, flags)
@@ -69,8 +70,8 @@ constructor(
} }
companion object { companion object {
// TODO(b/254606432): Use Intent.ACTION_NOTES and Intent.ACTION_NOTES_LOCKED instead. // TODO(b/254606432): Use Intent.ACTION_CREATE_NOTE instead.
const val NOTES_ACTION = "android.intent.action.NOTES" const val ACTION_CREATE_NOTE = "android.intent.action.CREATE_NOTE"
} }
} }

View File

@@ -45,8 +45,8 @@ constructor(
fun newIntent(context: Context): Intent { fun newIntent(context: Context): Intent {
return Intent(context, LaunchNoteTaskActivity::class.java).apply { return Intent(context, LaunchNoteTaskActivity::class.java).apply {
// Intent's action must be set in shortcuts, or an exception will be thrown. // Intent's action must be set in shortcuts, or an exception will be thrown.
// TODO(b/254606432): Use Intent.ACTION_NOTES instead. // TODO(b/254606432): Use Intent.ACTION_CREATE_NOTE instead.
action = NoteTaskIntentResolver.NOTES_ACTION action = NoteTaskIntentResolver.ACTION_CREATE_NOTE
} }
} }
} }

View File

@@ -24,7 +24,7 @@ import android.os.UserManager
import android.test.suitebuilder.annotation.SmallTest import android.test.suitebuilder.annotation.SmallTest
import androidx.test.runner.AndroidJUnit4 import androidx.test.runner.AndroidJUnit4
import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase
import com.android.systemui.notetask.NoteTaskIntentResolver.Companion.NOTES_ACTION import com.android.systemui.notetask.NoteTaskIntentResolver.Companion.ACTION_CREATE_NOTE
import com.android.systemui.notetask.shortcut.CreateNoteTaskShortcutActivity import com.android.systemui.notetask.shortcut.CreateNoteTaskShortcutActivity
import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.mockito.eq import com.android.systemui.util.mockito.eq
@@ -50,7 +50,7 @@ import org.mockito.MockitoAnnotations
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
internal class NoteTaskControllerTest : SysuiTestCase() { internal class NoteTaskControllerTest : SysuiTestCase() {
private val notesIntent = Intent(NOTES_ACTION) private val notesIntent = Intent(ACTION_CREATE_NOTE)
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var packageManager: PackageManager @Mock lateinit var packageManager: PackageManager

View File

@@ -106,7 +106,9 @@ internal class NoteTaskInitializerTest : SysuiTestCase() {
// region handleSystemKey // region handleSystemKey
@Test @Test
fun handleSystemKey_receiveValidSystemKey_shouldShowNoteTask() { fun handleSystemKey_receiveValidSystemKey_shouldShowNoteTask() {
createNoteTaskInitializer().callbacks.handleSystemKey(KeyEvent.KEYCODE_VIDEO_APP_1) createNoteTaskInitializer()
.callbacks
.handleSystemKey(NoteTaskController.NOTE_TASK_KEY_EVENT)
verify(noteTaskController).showNoteTask() verify(noteTaskController).showNoteTask()
} }

View File

@@ -23,11 +23,10 @@ import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.pm.PackageManager.ResolveInfoFlags import android.content.pm.PackageManager.ResolveInfoFlags
import android.content.pm.ResolveInfo import android.content.pm.ResolveInfo
import android.content.pm.ServiceInfo
import android.test.suitebuilder.annotation.SmallTest import android.test.suitebuilder.annotation.SmallTest
import androidx.test.runner.AndroidJUnit4 import androidx.test.runner.AndroidJUnit4
import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase
import com.android.systemui.notetask.NoteTaskIntentResolver.Companion.NOTES_ACTION import com.android.systemui.notetask.NoteTaskIntentResolver.Companion.ACTION_CREATE_NOTE
import com.android.systemui.util.mockito.whenever import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import org.junit.Before import org.junit.Before
@@ -58,19 +57,13 @@ internal class NoteTaskIntentResolverTest : SysuiTestCase() {
} }
private fun createResolveInfo( private fun createResolveInfo(
packageName: String = "PackageName", activityInfo: ActivityInfo? = createActivityInfo(),
activityInfo: ActivityInfo? = null,
): ResolveInfo { ): ResolveInfo {
return ResolveInfo().apply { return ResolveInfo().apply { this.activityInfo = activityInfo }
serviceInfo =
ServiceInfo().apply {
applicationInfo = ApplicationInfo().apply { this.packageName = packageName }
}
this.activityInfo = activityInfo
}
} }
private fun createActivityInfo( private fun createActivityInfo(
packageName: String = "PackageName",
name: String? = "ActivityName", name: String? = "ActivityName",
exported: Boolean = true, exported: Boolean = true,
enabled: Boolean = true, enabled: Boolean = true,
@@ -87,6 +80,7 @@ internal class NoteTaskIntentResolverTest : SysuiTestCase() {
if (turnScreenOn) { if (turnScreenOn) {
flags = flags or ActivityInfo.FLAG_TURN_SCREEN_ON flags = flags or ActivityInfo.FLAG_TURN_SCREEN_ON
} }
this.applicationInfo = ApplicationInfo().apply { this.packageName = packageName }
} }
} }
@@ -107,7 +101,8 @@ internal class NoteTaskIntentResolverTest : SysuiTestCase() {
val actual = resolver.resolveIntent() val actual = resolver.resolveIntent()
val expected = val expected =
Intent(NOTES_ACTION) Intent(ACTION_CREATE_NOTE)
.setPackage("PackageName")
.setComponent(ComponentName("PackageName", "ActivityName")) .setComponent(ComponentName("PackageName", "ActivityName"))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// Compares the string representation of both intents, as they are different instances. // Compares the string representation of both intents, as they are different instances.
@@ -204,7 +199,9 @@ internal class NoteTaskIntentResolverTest : SysuiTestCase() {
@Test @Test
fun resolveIntent_packageNameIsBlank_shouldReturnNull() { fun resolveIntent_packageNameIsBlank_shouldReturnNull() {
givenQueryIntentActivities { listOf(createResolveInfo(packageName = "")) } givenQueryIntentActivities {
listOf(createResolveInfo(createActivityInfo(packageName = "")))
}
val actual = resolver.resolveIntent() val actual = resolver.resolveIntent()

View File

@@ -4129,9 +4129,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
case KeyEvent.KEYCODE_DEMO_APP_2: case KeyEvent.KEYCODE_DEMO_APP_2:
case KeyEvent.KEYCODE_DEMO_APP_3: case KeyEvent.KEYCODE_DEMO_APP_3:
case KeyEvent.KEYCODE_DEMO_APP_4: { case KeyEvent.KEYCODE_DEMO_APP_4: {
// TODO(b/254604589): Dispatch KeyEvent to System UI.
sendSystemKeyToStatusBarAsync(keyCode);
// Just drop if keys are not intercepted for direct key. // Just drop if keys are not intercepted for direct key.
result &= ~ACTION_PASS_TO_USER; result &= ~ACTION_PASS_TO_USER;
break; break;