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