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