1 /* 2 * Copyright (C) 2023 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.keyguard.ui.view.layout 18 19 import androidx.core.text.isDigitsOnly 20 import com.android.systemui.CoreStartable 21 import com.android.systemui.keyguard.data.repository.KeyguardBlueprintRepository 22 import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor 23 import com.android.systemui.statusbar.commandline.Command 24 import com.android.systemui.statusbar.commandline.CommandRegistry 25 import java.io.PrintWriter 26 import javax.inject.Inject 27 28 /** Uses $ adb shell cmd statusbar blueprint <BlueprintId> */ 29 class KeyguardBlueprintCommandListener 30 @Inject 31 constructor( 32 private val commandRegistry: CommandRegistry, 33 private val keyguardBlueprintRepository: KeyguardBlueprintRepository, 34 private val keyguardBlueprintInteractor: KeyguardBlueprintInteractor, 35 ) : CoreStartable { 36 private val layoutCommand = KeyguardLayoutManagerCommand() 37 startnull38 override fun start() { 39 commandRegistry.registerCommand(COMMAND) { layoutCommand } 40 } 41 42 internal inner class KeyguardLayoutManagerCommand : Command { executenull43 override fun execute(pw: PrintWriter, args: List<String>) { 44 val arg = args.getOrNull(0) 45 if (arg == null || arg.lowercase() == "help") { 46 help(pw) 47 return 48 } 49 50 when { 51 arg.isDigitsOnly() -> pw.println("Invalid argument! Use string ids.") 52 keyguardBlueprintInteractor.transitionOrRefreshBlueprint(arg) -> 53 pw.println("Transition succeeded!") 54 else -> { 55 pw.println("Invalid argument! To see available blueprint ids, run:") 56 pw.println("$ adb shell cmd statusbar blueprint help") 57 } 58 } 59 } 60 helpnull61 override fun help(pw: PrintWriter) { 62 pw.println("Usage: $ adb shell cmd statusbar blueprint <blueprintId>") 63 pw.println("Existing Blueprint Ids: ") 64 keyguardBlueprintRepository.printBlueprints(pw) 65 } 66 } 67 68 companion object { 69 internal const val COMMAND = "blueprint" 70 } 71 } 72