From b5fe24b7346d2daa18a1c52af4872dd00f6cae27 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Thu, 9 Jan 2025 10:50:51 -0500 Subject: Add debug command to set device postured state This allows us to verify postured behavior and force the state without actually physically posturing the device. Bug: 383208131 Test: adb shell cmd statusbar device-postured true and verified dreams were triggered. Flag: EXEMPT adding debug command Change-Id: Id8c049ec53e1c5aef2ccfaaff224d11c11ad9782 --- .../communal/DevicePosturingCommandListener.kt | 66 ++++++++++++++++++++++ .../communal/dagger/CommunalStartableModule.kt | 6 ++ 2 files changed, 72 insertions(+) create mode 100644 packages/SystemUI/src/com/android/systemui/communal/DevicePosturingCommandListener.kt diff --git a/packages/SystemUI/src/com/android/systemui/communal/DevicePosturingCommandListener.kt b/packages/SystemUI/src/com/android/systemui/communal/DevicePosturingCommandListener.kt new file mode 100644 index 000000000000..c7b7050340a0 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/communal/DevicePosturingCommandListener.kt @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2025 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.communal + +import android.annotation.SuppressLint +import android.app.DreamManager +import com.android.systemui.CoreStartable +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.statusbar.commandline.Command +import com.android.systemui.statusbar.commandline.CommandRegistry +import java.io.PrintWriter +import javax.inject.Inject + +@SysUISingleton +class DevicePosturingCommandListener +@Inject +constructor(private val commandRegistry: CommandRegistry, private val dreamManager: DreamManager) : + CoreStartable { + private val command = DevicePosturingCommand() + + override fun start() { + commandRegistry.registerCommand(COMMAND_ROOT) { command } + } + + internal inner class DevicePosturingCommand : Command { + @SuppressLint("MissingPermission") + override fun execute(pw: PrintWriter, args: List) { + val arg = args.getOrNull(0) + if (arg == null || arg.lowercase() == "help") { + help(pw) + return + } + + when (arg.lowercase()) { + "true" -> dreamManager.setDevicePostured(true) + "false" -> dreamManager.setDevicePostured(false) + else -> { + pw.println("Invalid argument!") + help(pw) + } + } + } + + override fun help(pw: PrintWriter) { + pw.println("Usage: $ adb shell cmd statusbar device-postured ") + } + } + + private companion object { + const val COMMAND_ROOT = "device-postured" + } +} diff --git a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalStartableModule.kt b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalStartableModule.kt index 2d19b026489c..e3443227685f 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalStartableModule.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalStartableModule.kt @@ -22,6 +22,7 @@ import com.android.systemui.communal.CommunalDreamStartable import com.android.systemui.communal.CommunalMetricsStartable import com.android.systemui.communal.CommunalOngoingContentStartable import com.android.systemui.communal.CommunalSceneStartable +import com.android.systemui.communal.DevicePosturingCommandListener import com.android.systemui.communal.log.CommunalLoggerStartable import com.android.systemui.communal.widgets.CommunalAppWidgetHostStartable import com.android.systemui.dagger.qualifiers.PerUser @@ -67,4 +68,9 @@ interface CommunalStartableModule { @IntoMap @ClassKey(CommunalMetricsStartable::class) fun bindCommunalMetricsStartable(impl: CommunalMetricsStartable): CoreStartable + + @Binds + @IntoMap + @ClassKey(DevicePosturingCommandListener::class) + fun bindDevicePosturingCommandListener(impl: DevicePosturingCommandListener): CoreStartable } -- cgit v1.2.3-59-g8ed1b