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 * Is device dreaming. This method is more inclusive than 54 * {@link android.service.dreams.IDreamManager.isDreaming}, as it will return true during the 55 * dream's wake-up phase. 56 */ isDreaming()57 boolean isDreaming(); 58 59 /** 60 * Adds a state listener 61 */ addCallback(StateListener listener)62 void addCallback(StateListener listener); 63 64 /** 65 * Removes callback from listeners 66 */ removeCallback(StateListener listener)67 void removeCallback(StateListener listener); 68 69 /** 70 * Get amount of doze 71 */ getDozeAmount()72 float getDozeAmount(); 73 74 /** 75 * Listener for StatusBarState updates 76 */ 77 @ProvidesInterface(version = StateListener.VERSION) 78 public interface StateListener { 79 int VERSION = 1; 80 81 /** 82 * Callback before the new state is applied, for those who need to preempt the change. 83 */ onStatePreChange(int oldState, int newState)84 default void onStatePreChange(int oldState, int newState) { 85 } 86 87 /** 88 * Callback after all listeners have had a chance to update based on the state change 89 */ onStatePostChange()90 default void onStatePostChange() { 91 } 92 93 /** 94 * Required callback. Get the new state and do what you will with it. Keep in mind that 95 * other listeners are typically unordered and don't rely on your work being done before 96 * other peers. 97 * 98 * Only called if the state is actually different. 99 */ onStateChanged(int newState)100 default void onStateChanged(int newState) { 101 } 102 103 /** 104 * Callback to be notified about upcoming state changes. Typically, is immediately followed 105 * by #onStateChanged, unless there was an intentional delay in updating the state changed. 106 */ onUpcomingStateChanged(int upcomingState)107 default void onUpcomingStateChanged(int upcomingState) {} 108 109 /** 110 * Callback to be notified when Dozing changes. Dozing is stored separately from state. 111 */ onDozingChanged(boolean isDozing)112 default void onDozingChanged(boolean isDozing) {} 113 114 /** 115 * Callback to be notified when Dreaming changes. Dreaming is stored separately from state. 116 */ onDreamingChanged(boolean isDreaming)117 default void onDreamingChanged(boolean isDreaming) {} 118 119 /** 120 * Callback to be notified when the doze amount changes. Useful for animations. 121 * Note: this will be called for each animation frame. Please be careful to avoid 122 * performance regressions. 123 */ onDozeAmountChanged(float linear, float eased)124 default void onDozeAmountChanged(float linear, float eased) {} 125 126 /** 127 * Callback to be notified when the fullscreen or immersive state changes. 128 * 129 * @param isFullscreen if any of the system bar is hidden by the focused window. 130 */ onFullscreenStateChanged(boolean isFullscreen)131 default void onFullscreenStateChanged(boolean isFullscreen) {} 132 133 /** 134 * Callback to be notified when the pulsing state changes 135 */ onPulsingChanged(boolean pulsing)136 default void onPulsingChanged(boolean pulsing) {} 137 138 /** 139 * Callback to be notified when the expanded state of the status bar changes 140 */ onExpandedChanged(boolean isExpanded)141 default void onExpandedChanged(boolean isExpanded) {} 142 } 143 } 144