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 device pulsing.
44      */
isPulsing()45     boolean isPulsing();
46 
47     /**
48      * Adds a state listener
49      */
addCallback(StateListener listener)50     void addCallback(StateListener listener);
51 
52     /**
53      * Removes callback from listeners
54      */
removeCallback(StateListener listener)55     void removeCallback(StateListener listener);
56 
57     /**
58      * Get amount of doze
59      */
getDozeAmount()60     float getDozeAmount();
61 
62     /**
63      * Listener for StatusBarState updates
64      */
65     @ProvidesInterface(version = StateListener.VERSION)
66     public interface StateListener {
67         int VERSION = 1;
68 
69         /**
70          * Callback before the new state is applied, for those who need to preempt the change.
71          */
onStatePreChange(int oldState, int newState)72         default void onStatePreChange(int oldState, int newState) {
73         }
74 
75         /**
76          * Callback after all listeners have had a chance to update based on the state change
77          */
onStatePostChange()78         default void onStatePostChange() {
79         }
80 
81         /**
82          * Required callback. Get the new state and do what you will with it. Keep in mind that
83          * other listeners are typically unordered and don't rely on your work being done before
84          * other peers.
85          *
86          * Only called if the state is actually different.
87          */
onStateChanged(int newState)88         default void onStateChanged(int newState) {
89         }
90 
91         /**
92          * Callback to be notified when Dozing changes. Dozing is stored separately from state.
93          */
onDozingChanged(boolean isDozing)94         default void onDozingChanged(boolean isDozing) {}
95 
96         /**
97          * Callback to be notified when the doze amount changes. Useful for animations.
98          * Note: this will be called for each animation frame. Please be careful to avoid
99          * performance regressions.
100          */
onDozeAmountChanged(float linear, float eased)101         default void onDozeAmountChanged(float linear, float eased) {}
102 
103         /**
104          * Callback to be notified when the fullscreen or immersive state changes.
105          *
106          * @param isFullscreen if any of the system bar is hidden by the focused window.
107          * @param isImmersive if the navigation bar can stay hidden when the display gets tapped.
108          */
onFullscreenStateChanged(boolean isFullscreen, boolean isImmersive)109         default void onFullscreenStateChanged(boolean isFullscreen, boolean isImmersive) {}
110 
111         /**
112          * Callback to be notified when the pulsing state changes
113          */
onPulsingChanged(boolean pulsing)114         default void onPulsingChanged(boolean pulsing) {}
115     }
116 }
117