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

Commit ca881957 authored by Marcello Galhardo's avatar Marcello Galhardo Committed by Automerger Merge Worker
Browse files

Merge "Open Notes from a KeyEvent dispatch" into tm-qpr-dev am: c3c42010

parents 63d03ebf c3c42010
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -289,6 +289,12 @@
    <!-- Query all packages on device on R+ -->
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

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

    <!-- Permission to register process observer -->
    <uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER"/>

+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.systemui.log.dagger.LogModule;
import com.android.systemui.mediaprojection.appselector.MediaProjectionModule;
import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.NavigationBarComponent;
import com.android.systemui.notetask.NoteTaskModule;
import com.android.systemui.people.PeopleModule;
import com.android.systemui.plugins.BcSmartspaceDataPlugin;
import com.android.systemui.privacy.PrivacyModule;
@@ -152,6 +153,7 @@ import dagger.Provides;
            TunerModule.class,
            UserModule.class,
            UtilModule.class,
            NoteTaskModule.class,
            WalletModule.class
        },
        subcomponents = {
+3 −0
Original line number Diff line number Diff line
@@ -325,6 +325,9 @@ object Flags {
    // 1800 - shade container
    @JvmField val LEAVE_SHADE_OPEN_FOR_BUGREPORT = UnreleasedFlag(1800, true)

    // 1900 - note task
    @JvmField val NOTE_TASKS = SysPropBooleanFlag(1900, "persist.sysui.debug.note_tasks")

    // Pay no attention to the reflection behind the curtain.
    // ========================== Curtain ==========================
    // |                                                           |
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.notetask

import android.app.KeyguardManager
import android.content.Context
import android.os.UserManager
import android.view.KeyEvent
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.util.kotlin.getOrNull
import com.android.wm.shell.floating.FloatingTasks
import java.util.Optional
import javax.inject.Inject

/**
 * Entry point for creating and managing note.
 *
 * The controller decides how a note is launched based in the device state: locked or unlocked.
 *
 * Currently, we only support a single task per time.
 */
@SysUISingleton
internal class NoteTaskController
@Inject
constructor(
    private val context: Context,
    private val intentResolver: NoteTaskIntentResolver,
    private val optionalFloatingTasks: Optional<FloatingTasks>,
    private val optionalKeyguardManager: Optional<KeyguardManager>,
    private val optionalUserManager: Optional<UserManager>,
    @NoteTaskEnabledKey private val isEnabled: Boolean,
) {

    fun handleSystemKey(keyCode: Int) {
        if (!isEnabled) return

        if (keyCode == KeyEvent.KEYCODE_VIDEO_APP_1) {
            showNoteTask()
        }
    }

    private fun showNoteTask() {
        val floatingTasks = optionalFloatingTasks.getOrNull() ?: return
        val keyguardManager = optionalKeyguardManager.getOrNull() ?: return
        val userManager = optionalUserManager.getOrNull() ?: return
        val intent = intentResolver.resolveIntent() ?: return

        // TODO(b/249954038): We should handle direct boot (isUserUnlocked). For now, we do nothing.
        if (!userManager.isUserUnlocked) return

        if (keyguardManager.isKeyguardLocked) {
            context.startActivity(intent)
        } else {
            // TODO(b/254606432): Should include Intent.EXTRA_FLOATING_WINDOW_MODE parameter.
            floatingTasks.showOrSetStashed(intent)
        }
    }
}
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.notetask

import javax.inject.Qualifier

/** Key associated with a [Boolean] flag that enables or disables the note task feature. */
@Qualifier internal annotation class NoteTaskEnabledKey
Loading