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