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.statusbar;
18 
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
20 
21 import android.annotation.IntDef;
22 import android.view.View;
23 
24 import com.android.systemui.CoreStartable;
25 import com.android.systemui.plugins.statusbar.StatusBarStateController;
26 import com.android.systemui.statusbar.phone.CentralSurfaces;
27 
28 import java.lang.annotation.Retention;
29 
30 /**
31  * Sends updates to {@link StateListener}s about changes to the status bar state and dozing state
32  */
33 public interface SysuiStatusBarStateController extends StatusBarStateController, CoreStartable {
34 
35     // TODO: b/115739177 (remove this explicit ordering if we can)
36     @Retention(SOURCE)
37     @IntDef({RANK_STATUS_BAR, RANK_STATUS_BAR_WINDOW_CONTROLLER, RANK_STACK_SCROLLER, RANK_SHELF})
38     @interface SbStateListenerRank {}
39     // This is the set of known dependencies when updating StatusBarState
40     int RANK_STATUS_BAR = 0;
41     int RANK_STATUS_BAR_WINDOW_CONTROLLER = 1;
42     int RANK_STACK_SCROLLER = 2;
43     int RANK_SHELF = 3;
44 
45     /**
46      * Add a listener and a rank based on the priority of this message
47      * @param listener the listener
48      * @param rank the order in which you'd like to be called. Ranked listeners will be
49      * notified before unranked, and we will sort ranked listeners from low to high
50      *
51      * @deprecated This method exists only to solve latent inter-dependencies from refactoring
52      * StatusBarState out of CentralSurfaces.java. Any new listeners should be built not to need
53      * ranking (i.e., they are non-dependent on the order of operations of StatusBarState
54      * listeners).
55      */
56     @Deprecated
addCallback(StateListener listener, int rank)57     void addCallback(StateListener listener, int rank);
58 
59     /**
60      * Update the status bar state
61      * @param state see {@link StatusBarState} for valid options
62      * @return {@code true} if the state changed, else {@code false}
63      */
setState(int state)64     default boolean setState(int state) {
65         return setState(state, false /* force */);
66     }
67 
68     /**
69      * Update the status bar state
70      * @param state see {@link StatusBarState} for valid options
71      * @param force whether to set the state even if it's the same as the current state. This will
72      *              dispatch the state to all StatusBarStateListeners, ensuring that all listening
73      *              components are reset to this state.
74      * @return {@code true} if the state was changed or set forcefully
75      */
setState(int state, boolean force)76     boolean setState(int state, boolean force);
77 
78     /**
79      * Provides a hint that the status bar has started to transition to another
80      * {@link StatusBarState}. This suggests that a matching call to setState() with the same value
81      * will happen in the near future, although that may not happen if the animation is canceled,
82      * etc.
83      */
setUpcomingState(int state)84     void setUpcomingState(int state);
85 
86     /**
87      * If the status bar is in the process of transitioning to a new state, returns that state.
88      * Otherwise, returns the current state.
89      */
getCurrentOrUpcomingState()90     int getCurrentOrUpcomingState();
91 
92     /**
93      * Update the dozing state from {@link CentralSurfaces}'s perspective
94      * @param isDozing well, are we dozing?
95      * @return {@code true} if the state changed, else {@code false}
96      */
setIsDozing(boolean isDozing)97     boolean setIsDozing(boolean isDozing);
98 
99     /**
100      * Update the dreaming state from {@link CentralSurfaces}'s perspective
101      * @param isDreaming whether we are dreaming
102      * @return {@code true} if the state changed, else {@code false}
103      */
setIsDreaming(boolean isDreaming)104     boolean setIsDreaming(boolean isDreaming);
105 
106     /**
107      * Changes the current doze amount, also starts the
108      * {@link com.android.internal.jank.InteractionJankMonitor InteractionJankMonitor} as possible.
109      *
110      * @param view An attached view, which will be used by InteractionJankMonitor.
111      * @param dozeAmount New doze/dark amount.
112      * @param animated If change should be animated or not. This will cancel current animations.
113      */
setAndInstrumentDozeAmount(View view, float dozeAmount, boolean animated)114     void setAndInstrumentDozeAmount(View view, float dozeAmount, boolean animated);
115 
116     /**
117      * Sets whether to leave status bar open when hiding keyguard
118      */
setLeaveOpenOnKeyguardHide(boolean leaveOpen)119     void setLeaveOpenOnKeyguardHide(boolean leaveOpen);
120 
121     /**
122      * Whether to leave status bar open when hiding keyguard
123      */
leaveOpenOnKeyguardHide()124     boolean leaveOpenOnKeyguardHide();
125 
126     /**
127      * Interpolated doze amount
128      */
getInterpolatedDozeAmount()129     float getInterpolatedDozeAmount();
130 
131     /**
132      * Whether status bar is going to full shade
133      */
goingToFullShade()134     boolean goingToFullShade();
135 
136     /**
137      * Whether the previous state of the status bar was the shade locked
138      */
fromShadeLocked()139     boolean fromShadeLocked();
140 
141     /**
142      * Set keyguard requested
143      */
setKeyguardRequested(boolean keyguardRequested)144     void setKeyguardRequested(boolean keyguardRequested);
145 
146     /**
147      * Is keyguard requested
148      */
isKeyguardRequested()149     boolean isKeyguardRequested();
150 
151     /**
152      * Set pulsing
153      */
setPulsing(boolean visibility)154     void setPulsing(boolean visibility);
155 
156     /**
157      * Listener with rankings SbStateListenerRank that have dependencies so must be updated
158      * in a certain order
159      */
160     class RankedListener {
161         final StateListener mListener;
162         final int mRank;
163 
RankedListener(StateListener l, int r)164         RankedListener(StateListener l, int r) {
165             mListener = l;
166             mRank = r;
167         }
168     }
169 }
170