Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b667213f authored by Marcello Galhardo's avatar Marcello Galhardo
Browse files

Handle Stylus Key Events in System UI

Test: manual
Test: atest SystemUITests:NoteTaskIntentResolverTest
Test: atest SystemUITests:NoteTaskInitializerTest
Test: atest SystemUITests:NoteTaskControllerTest

Fixes: b/254604589

Change-Id: I2579a69ce29fad5c2655c61962a44e9189976b5b
parent b00fd1d7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -292,7 +292,7 @@

    <queries>
        <intent>
            <action android:name="android.intent.action.NOTES" />
            <action android:name="android.intent.action.CREATE_NOTE" />
        </intent>
    </queries>

+5 −0
Original line number Diff line number Diff line
@@ -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
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -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()
                }
            }
+10 −9
Original line number Diff line number Diff line
@@ -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"
    }
}

+2 −2
Original line number Diff line number Diff line
@@ -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
            }
        }
    }
Loading