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