Merge "Handle Stylus Key Events in System UI" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c05d662018
@@ -292,7 +292,7 @@
|
||||
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.NOTES" />
|
||||
<action android:name="android.intent.action.CREATE_NOTE" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
|
||||
@@ -104,4 +104,9 @@ constructor(
|
||||
PackageManager.DONT_KILL_APP,
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
// TODO(b/254604589): Use final KeyEvent.KEYCODE_* instead.
|
||||
const val NOTE_TASK_KEY_EVENT = 311
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.systemui.notetask
|
||||
|
||||
import android.view.KeyEvent
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import com.android.systemui.statusbar.CommandQueue
|
||||
import com.android.wm.shell.bubbles.Bubbles
|
||||
@@ -37,7 +36,7 @@ constructor(
|
||||
val callbacks =
|
||||
object : CommandQueue.Callbacks {
|
||||
override fun handleSystemKey(keyCode: Int) {
|
||||
if (keyCode == KeyEvent.KEYCODE_VIDEO_APP_1) {
|
||||
if (keyCode == NoteTaskController.NOTE_TASK_KEY_EVENT) {
|
||||
noteTaskController.showNoteTask()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ import android.content.Intent
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.PackageManager
|
||||
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
|
||||
|
||||
/**
|
||||
* Class responsible to query all apps and find one that can handle the [NOTES_ACTION]. If found, an
|
||||
* [Intent] ready for be launched will be returned. Otherwise, returns null.
|
||||
* Class responsible to query all apps and find one that can handle the [ACTION_CREATE_NOTE]. If
|
||||
* 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.
|
||||
*/
|
||||
@@ -37,15 +37,16 @@ constructor(
|
||||
) {
|
||||
|
||||
fun resolveIntent(): Intent? {
|
||||
val intent = Intent(NOTES_ACTION)
|
||||
val intent = Intent(ACTION_CREATE_NOTE)
|
||||
val flags = ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong())
|
||||
val infoList = packageManager.queryIntentActivities(intent, flags)
|
||||
|
||||
for (info in infoList) {
|
||||
val packageName = info.serviceInfo.applicationInfo.packageName ?: continue
|
||||
val packageName = info.activityInfo.applicationInfo.packageName ?: continue
|
||||
val activityName = resolveActivityNameForNotesAction(packageName) ?: continue
|
||||
|
||||
return Intent(NOTES_ACTION)
|
||||
return Intent(ACTION_CREATE_NOTE)
|
||||
.setPackage(packageName)
|
||||
.setComponent(ComponentName(packageName, activityName))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
@@ -54,7 +55,7 @@ constructor(
|
||||
}
|
||||
|
||||
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 resolveInfo = packageManager.resolveActivity(intent, flags)
|
||||
|
||||
@@ -69,8 +70,8 @@ constructor(
|
||||
}
|
||||
|
||||
companion object {
|
||||
// TODO(b/254606432): Use Intent.ACTION_NOTES and Intent.ACTION_NOTES_LOCKED instead.
|
||||
const val NOTES_ACTION = "android.intent.action.NOTES"
|
||||
// TODO(b/254606432): Use Intent.ACTION_CREATE_NOTE instead.
|
||||
const val ACTION_CREATE_NOTE = "android.intent.action.CREATE_NOTE"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ constructor(
|
||||
fun newIntent(context: Context): Intent {
|
||||
return Intent(context, LaunchNoteTaskActivity::class.java).apply {
|
||||
// Intent's action must be set in shortcuts, or an exception will be thrown.
|
||||
// TODO(b/254606432): Use Intent.ACTION_NOTES instead.
|
||||
action = NoteTaskIntentResolver.NOTES_ACTION
|
||||
// TODO(b/254606432): Use Intent.ACTION_CREATE_NOTE instead.
|
||||
action = NoteTaskIntentResolver.ACTION_CREATE_NOTE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import android.os.UserManager
|
||||
import android.test.suitebuilder.annotation.SmallTest
|
||||
import androidx.test.runner.AndroidJUnit4
|
||||
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.util.mockito.argumentCaptor
|
||||
import com.android.systemui.util.mockito.eq
|
||||
@@ -50,7 +50,7 @@ import org.mockito.MockitoAnnotations
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
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 packageManager: PackageManager
|
||||
|
||||
@@ -106,7 +106,9 @@ internal class NoteTaskInitializerTest : SysuiTestCase() {
|
||||
// region handleSystemKey
|
||||
@Test
|
||||
fun handleSystemKey_receiveValidSystemKey_shouldShowNoteTask() {
|
||||
createNoteTaskInitializer().callbacks.handleSystemKey(KeyEvent.KEYCODE_VIDEO_APP_1)
|
||||
createNoteTaskInitializer()
|
||||
.callbacks
|
||||
.handleSystemKey(NoteTaskController.NOTE_TASK_KEY_EVENT)
|
||||
|
||||
verify(noteTaskController).showNoteTask()
|
||||
}
|
||||
|
||||
@@ -23,11 +23,10 @@ import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.PackageManager.ResolveInfoFlags
|
||||
import android.content.pm.ResolveInfo
|
||||
import android.content.pm.ServiceInfo
|
||||
import android.test.suitebuilder.annotation.SmallTest
|
||||
import androidx.test.runner.AndroidJUnit4
|
||||
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.google.common.truth.Truth.assertThat
|
||||
import org.junit.Before
|
||||
@@ -58,19 +57,13 @@ internal class NoteTaskIntentResolverTest : SysuiTestCase() {
|
||||
}
|
||||
|
||||
private fun createResolveInfo(
|
||||
packageName: String = "PackageName",
|
||||
activityInfo: ActivityInfo? = null,
|
||||
activityInfo: ActivityInfo? = createActivityInfo(),
|
||||
): ResolveInfo {
|
||||
return ResolveInfo().apply {
|
||||
serviceInfo =
|
||||
ServiceInfo().apply {
|
||||
applicationInfo = ApplicationInfo().apply { this.packageName = packageName }
|
||||
}
|
||||
this.activityInfo = activityInfo
|
||||
}
|
||||
return ResolveInfo().apply { this.activityInfo = activityInfo }
|
||||
}
|
||||
|
||||
private fun createActivityInfo(
|
||||
packageName: String = "PackageName",
|
||||
name: String? = "ActivityName",
|
||||
exported: Boolean = true,
|
||||
enabled: Boolean = true,
|
||||
@@ -87,6 +80,7 @@ internal class NoteTaskIntentResolverTest : SysuiTestCase() {
|
||||
if (turnScreenOn) {
|
||||
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 expected =
|
||||
Intent(NOTES_ACTION)
|
||||
Intent(ACTION_CREATE_NOTE)
|
||||
.setPackage("PackageName")
|
||||
.setComponent(ComponentName("PackageName", "ActivityName"))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
// Compares the string representation of both intents, as they are different instances.
|
||||
@@ -204,7 +199,9 @@ internal class NoteTaskIntentResolverTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun resolveIntent_packageNameIsBlank_shouldReturnNull() {
|
||||
givenQueryIntentActivities { listOf(createResolveInfo(packageName = "")) }
|
||||
givenQueryIntentActivities {
|
||||
listOf(createResolveInfo(createActivityInfo(packageName = "")))
|
||||
}
|
||||
|
||||
val actual = resolver.resolveIntent()
|
||||
|
||||
|
||||
@@ -4129,9 +4129,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
case KeyEvent.KEYCODE_DEMO_APP_2:
|
||||
case KeyEvent.KEYCODE_DEMO_APP_3:
|
||||
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.
|
||||
result &= ~ACTION_PASS_TO_USER;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user