1 /* 2 * Copyright (C) 2019 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.plugins.statusbar; 18 19 import com.android.systemui.plugins.annotations.DependsOn; 20 import com.android.systemui.plugins.annotations.ProvidesInterface; 21 22 23 /** 24 * Sends updates to {@link StateListener}s about changes to the status bar state and dozing state 25 */ 26 @ProvidesInterface(version = StatusBarStateController.VERSION) 27 @DependsOn(target = StatusBarStateController.StateListener.class) 28 public interface StatusBarStateController { 29 int VERSION = 1; 30 31 /** 32 * Current status bar state 33 */ getState()34 int getState(); 35 36 /** 37 * Is device dozing. Dozing is when the screen is in AOD or asleep given that 38 * {@link com.android.systemui.doze.DozeService} is configured. 39 */ isDozing()40 boolean isDozing(); 41 42 /** 43 * Is the status bar panel expanded. 44 */ isExpanded()45 boolean isExpanded(); 46 47 /** 48 * Is device pulsing. 49 */ isPulsing()50 boolean isPulsing(); 51 52 /** 53 * Adds a state listener 54 */ addCallback(StateListener listener)55 void addCallback(StateListener listener); 56 57 /** 58 * Removes callback from listeners 59 */ removeCallback(StateListener listener)60 void removeCallback(StateListener listener); 61 62 /** 63 * Get amount of doze 64 */ getDozeAmount()65 float getDozeAmount(); 66 67 /** 68 * Listener for StatusBarState updates 69 */ 70 @ProvidesInterface(version = StateListener.VERSION) 71 public interface StateListener { 72 int VERSION = 1; 73 74 /** 75 * Callback before the new state is applied, for those who need to preempt the change. 76 */ onStatePreChange(int oldState, int newState)77 default void onStatePreChange(int oldState, int newState) { 78 } 79 80 /** 81 * Callback after all listeners have had a chance to update based on the state change 82 */ onStatePostChange()83 default void onStatePostChange() { 84 } 85 86 /** 87 * Required callback. Get the new state and do what you will with it. Keep in mind that 88 * other listeners are typically unordered and don't rely on your work being done before 89 * other peers. 90 * 91 * Only called if the state is actually different. 92 */ onStateChanged(int newState)93 default void onStateChanged(int newState) { 94 } 95 96 /** 97 * Callback to be notified when Dozing changes. Dozing is stored separately from state. 98 */ onDozingChanged(boolean isDozing)99 default void onDozingChanged(boolean isDozing) {} 100 101 /** 102 * Callback to be notified when the doze amount changes. Useful for animations. 103 * Note: this will be called for each animation frame. Please be careful to avoid 104 * performance regressions. 105 */ onDozeAmountChanged(float linear, float eased)106 default void onDozeAmountChanged(float linear, float eased) {} 107 108 /** 109 * Callback to be notified when the fullscreen or immersive state changes. 110 * 111 * @param isFullscreen if any of the system bar is hidden by the focused window. 112 * @param isImmersive if the navigation bar can stay hidden when the display gets tapped. 113 */ onFullscreenStateChanged(boolean isFullscreen, boolean isImmersive)114 default void onFullscreenStateChanged(boolean isFullscreen, boolean isImmersive) {} 115 116 /** 117 * Callback to be notified when the pulsing state changes 118 */ onPulsingChanged(boolean pulsing)119 default void onPulsingChanged(boolean pulsing) {} 120 121 /** 122 * Callback to be notified when the expanded state of the status bar changes 123 */ onExpandedChanged(boolean isExpanded)124 default void onExpandedChanged(boolean isExpanded) {} 125 } 126 } 127