diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 68009177cd9eb..75c92e000c4dc 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -292,7 +292,7 @@ - + diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt index 8356440714e6d..08d18575da796 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt @@ -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 + } } diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt index d14b7a7667621..d5f4a5a5d351d 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt @@ -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() } } diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskIntentResolver.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskIntentResolver.kt index 98d69910aac39..26e3f49828c75 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskIntentResolver.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskIntentResolver.kt @@ -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" } } diff --git a/packages/SystemUI/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivity.kt b/packages/SystemUI/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivity.kt index 47fe67638cd05..f203e7a51643f 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/shortcut/LaunchNoteTaskActivity.kt @@ -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 } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt index fc90c1add5e90..8440455127bd2 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt @@ -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 diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt index 538131a4dd733..010ac5bbb2d9d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt @@ -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() } diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskIntentResolverTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskIntentResolverTest.kt index dd2cc2ffc9db2..bbe60f4ba4935 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskIntentResolverTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskIntentResolverTest.kt @@ -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() diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 5285f63dcc44f..b55b6dd0eb555 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -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;