1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.notetask 18 19 import android.app.KeyguardManager 20 import androidx.annotation.VisibleForTesting 21 import com.android.systemui.statusbar.CommandQueue 22 import com.android.systemui.util.kotlin.getOrNull 23 import com.android.wm.shell.bubbles.Bubbles 24 import java.util.Optional 25 import javax.inject.Inject 26 27 /** Class responsible to "glue" all note task dependencies. */ 28 internal class NoteTaskInitializer 29 @Inject 30 constructor( 31 private val optionalBubbles: Optional<Bubbles>, 32 private val noteTaskController: NoteTaskController, 33 private val commandQueue: CommandQueue, 34 @NoteTaskEnabledKey private val isEnabled: Boolean, 35 private val optionalKeyguardManager: Optional<KeyguardManager>, 36 ) { 37 38 @VisibleForTesting 39 val callbacks = 40 object : CommandQueue.Callbacks { handleSystemKeynull41 override fun handleSystemKey(keyCode: Int) { 42 if (keyCode == NoteTaskController.NOTE_TASK_KEY_EVENT) { 43 showNoteTask() 44 } 45 } 46 } 47 showNoteTasknull48 private fun showNoteTask() { 49 val uiEvent = 50 if (optionalKeyguardManager.isKeyguardLocked) { 51 NoteTaskController.ShowNoteTaskUiEvent.NOTE_OPENED_VIA_STYLUS_TAIL_BUTTON_LOCKED 52 } else { 53 NoteTaskController.ShowNoteTaskUiEvent.NOTE_OPENED_VIA_STYLUS_TAIL_BUTTON 54 } 55 noteTaskController.showNoteTask(uiEvent = uiEvent) 56 } 57 initializenull58 fun initialize() { 59 if (isEnabled && optionalBubbles.isPresent) { 60 commandQueue.addCallback(callbacks) 61 } 62 noteTaskController.setNoteTaskShortcutEnabled(isEnabled) 63 } 64 } 65 66 private val Optional<KeyguardManager>.isKeyguardLocked: Boolean 67 // If there's no KeyguardManager, assume that the keyguard is not locked. 68 get() = getOrNull()?.isKeyguardLocked ?: false 69