Loading packages/SystemUI/plugin/src/com/android/systemui/plugins/log/TableLogBufferBase.kt 0 → 100644 +58 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.plugins.log /** * Base interface for a logger that logs changes in table format. * * This is a plugin interface for classes outside of SystemUI core. */ interface TableLogBufferBase { /** * Logs a String? change. * * For Java overloading. */ fun logChange(prefix: String, columnName: String, value: String?) { logChange(prefix, columnName, value, isInitial = false) } /** Logs a String? change. */ fun logChange(prefix: String, columnName: String, value: String?, isInitial: Boolean) /** * Logs a Boolean change. * * For Java overloading. */ fun logChange(prefix: String, columnName: String, value: Boolean) { logChange(prefix, columnName, value, isInitial = false) } /** Logs a Boolean change. */ fun logChange(prefix: String, columnName: String, value: Boolean, isInitial: Boolean) /** * Logs an Int? change. * * For Java overloading. */ fun logChange(prefix: String, columnName: String, value: Int?) { logChange(prefix, columnName, value, isInitial = false) } /** Logs an Int? change. */ fun logChange(prefix: String, columnName: String, value: Int?, isInitial: Boolean) } packages/SystemUI/shared/src/com/android/systemui/shared/condition/Condition.java +17 −0 Original line number Diff line number Diff line Loading @@ -234,9 +234,26 @@ public abstract class Condition { } protected final String getTag() { if (isOverridingCondition()) { return mTag + "[OVRD]"; } return mTag; } /** * Returns the state of the condition. * - "Invalid", condition hasn't been set / not monitored * - "True", condition has been met * - "False", condition has not been met */ protected final String getState() { if (!isConditionSet()) { return "Invalid"; } return isConditionMet() ? "True" : "False"; } /** * Creates a new condition which will only be true when both this condition and all the provided * conditions are true. Loading packages/SystemUI/shared/src/com/android/systemui/shared/condition/Monitor.java +14 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.util.Log; import androidx.annotation.NonNull; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.plugins.log.TableLogBufferBase; import java.util.ArrayList; import java.util.Collections; Loading @@ -41,6 +42,7 @@ public class Monitor { private final String mTag = getClass().getSimpleName(); private final Executor mExecutor; private final Set<Condition> mPreconditions; private final TableLogBufferBase mLogBuffer; private final HashMap<Condition, ArraySet<Subscription.Token>> mConditions = new HashMap<>(); private final HashMap<Subscription.Token, SubscriptionState> mSubscriptions = new HashMap<>(); Loading Loading @@ -160,11 +162,23 @@ public class Monitor { * Main constructor, allowing specifying preconditions. */ public Monitor(Executor executor, Set<Condition> preconditions) { this(executor, preconditions, null); } /** * Main constructor, allowing specifying preconditions and a log buffer for logging. */ public Monitor(Executor executor, Set<Condition> preconditions, TableLogBufferBase logBuffer) { mExecutor = executor; mPreconditions = preconditions; mLogBuffer = logBuffer; } private void updateConditionMetState(Condition condition) { if (mLogBuffer != null) { mLogBuffer.logChange(/* prefix= */ "", condition.getTag(), condition.getState()); } final ArraySet<Subscription.Token> subscriptions = mConditions.get(condition); // It's possible the condition was removed between the time the callback occurred and Loading packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +4 −2 Original line number Diff line number Diff line Loading @@ -55,6 +55,8 @@ import com.android.systemui.flags.FlagsModule; import com.android.systemui.keyboard.KeyboardModule; import com.android.systemui.keyguard.data.BouncerViewModule; import com.android.systemui.log.dagger.LogModule; import com.android.systemui.log.dagger.MonitorLog; import com.android.systemui.log.table.TableLogBuffer; import com.android.systemui.mediaprojection.appselector.MediaProjectionModule; import com.android.systemui.model.SysUiState; import com.android.systemui.motiontool.MotionToolModule; Loading Loading @@ -250,8 +252,8 @@ public abstract class SystemUIModule { @Provides @SystemUser static Monitor provideSystemUserMonitor(@Main Executor executor, SystemProcessCondition systemProcessCondition) { return new Monitor(executor, Collections.singleton(systemProcessCondition)); SystemProcessCondition systemProcessCondition, @MonitorLog TableLogBuffer logBuffer) { return new Monitor(executor, Collections.singleton(systemProcessCondition), logBuffer); } @BindsOptionalOf Loading packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +8 −0 Original line number Diff line number Diff line Loading @@ -421,6 +421,14 @@ public class LogModule { return factory.create("BouncerLog", 250); } /** Provides a table logging buffer for the Monitor. */ @Provides @SysUISingleton @MonitorLog public static TableLogBuffer provideMonitorTableLogBuffer(TableLogBufferFactory factory) { return factory.create("MonitorLog", 250); } /** * Provides a {@link LogBuffer} for Udfps logs. */ Loading Loading
packages/SystemUI/plugin/src/com/android/systemui/plugins/log/TableLogBufferBase.kt 0 → 100644 +58 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.plugins.log /** * Base interface for a logger that logs changes in table format. * * This is a plugin interface for classes outside of SystemUI core. */ interface TableLogBufferBase { /** * Logs a String? change. * * For Java overloading. */ fun logChange(prefix: String, columnName: String, value: String?) { logChange(prefix, columnName, value, isInitial = false) } /** Logs a String? change. */ fun logChange(prefix: String, columnName: String, value: String?, isInitial: Boolean) /** * Logs a Boolean change. * * For Java overloading. */ fun logChange(prefix: String, columnName: String, value: Boolean) { logChange(prefix, columnName, value, isInitial = false) } /** Logs a Boolean change. */ fun logChange(prefix: String, columnName: String, value: Boolean, isInitial: Boolean) /** * Logs an Int? change. * * For Java overloading. */ fun logChange(prefix: String, columnName: String, value: Int?) { logChange(prefix, columnName, value, isInitial = false) } /** Logs an Int? change. */ fun logChange(prefix: String, columnName: String, value: Int?, isInitial: Boolean) }
packages/SystemUI/shared/src/com/android/systemui/shared/condition/Condition.java +17 −0 Original line number Diff line number Diff line Loading @@ -234,9 +234,26 @@ public abstract class Condition { } protected final String getTag() { if (isOverridingCondition()) { return mTag + "[OVRD]"; } return mTag; } /** * Returns the state of the condition. * - "Invalid", condition hasn't been set / not monitored * - "True", condition has been met * - "False", condition has not been met */ protected final String getState() { if (!isConditionSet()) { return "Invalid"; } return isConditionMet() ? "True" : "False"; } /** * Creates a new condition which will only be true when both this condition and all the provided * conditions are true. Loading
packages/SystemUI/shared/src/com/android/systemui/shared/condition/Monitor.java +14 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.util.Log; import androidx.annotation.NonNull; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.plugins.log.TableLogBufferBase; import java.util.ArrayList; import java.util.Collections; Loading @@ -41,6 +42,7 @@ public class Monitor { private final String mTag = getClass().getSimpleName(); private final Executor mExecutor; private final Set<Condition> mPreconditions; private final TableLogBufferBase mLogBuffer; private final HashMap<Condition, ArraySet<Subscription.Token>> mConditions = new HashMap<>(); private final HashMap<Subscription.Token, SubscriptionState> mSubscriptions = new HashMap<>(); Loading Loading @@ -160,11 +162,23 @@ public class Monitor { * Main constructor, allowing specifying preconditions. */ public Monitor(Executor executor, Set<Condition> preconditions) { this(executor, preconditions, null); } /** * Main constructor, allowing specifying preconditions and a log buffer for logging. */ public Monitor(Executor executor, Set<Condition> preconditions, TableLogBufferBase logBuffer) { mExecutor = executor; mPreconditions = preconditions; mLogBuffer = logBuffer; } private void updateConditionMetState(Condition condition) { if (mLogBuffer != null) { mLogBuffer.logChange(/* prefix= */ "", condition.getTag(), condition.getState()); } final ArraySet<Subscription.Token> subscriptions = mConditions.get(condition); // It's possible the condition was removed between the time the callback occurred and Loading
packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +4 −2 Original line number Diff line number Diff line Loading @@ -55,6 +55,8 @@ import com.android.systemui.flags.FlagsModule; import com.android.systemui.keyboard.KeyboardModule; import com.android.systemui.keyguard.data.BouncerViewModule; import com.android.systemui.log.dagger.LogModule; import com.android.systemui.log.dagger.MonitorLog; import com.android.systemui.log.table.TableLogBuffer; import com.android.systemui.mediaprojection.appselector.MediaProjectionModule; import com.android.systemui.model.SysUiState; import com.android.systemui.motiontool.MotionToolModule; Loading Loading @@ -250,8 +252,8 @@ public abstract class SystemUIModule { @Provides @SystemUser static Monitor provideSystemUserMonitor(@Main Executor executor, SystemProcessCondition systemProcessCondition) { return new Monitor(executor, Collections.singleton(systemProcessCondition)); SystemProcessCondition systemProcessCondition, @MonitorLog TableLogBuffer logBuffer) { return new Monitor(executor, Collections.singleton(systemProcessCondition), logBuffer); } @BindsOptionalOf Loading
packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +8 −0 Original line number Diff line number Diff line Loading @@ -421,6 +421,14 @@ public class LogModule { return factory.create("BouncerLog", 250); } /** Provides a table logging buffer for the Monitor. */ @Provides @SysUISingleton @MonitorLog public static TableLogBuffer provideMonitorTableLogBuffer(TableLogBufferFactory factory) { return factory.create("MonitorLog", 250); } /** * Provides a {@link LogBuffer} for Udfps logs. */ Loading