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 * Sends updates to {@link StateListener}s about changes to the status bar state and dozing state 24 */ 25 @ProvidesInterface(version = StatusBarStateController.VERSION) 26 @DependsOn(target = StatusBarStateController.StateListener.class) 27 public interface StatusBarStateController { 28 int VERSION = 1; 29 30 /** 31 * Current status bar state 32 */ getState()33 int getState(); 34 35 /** 36 * Is device dozing. Dozing is when the screen is in AOD or asleep given that 37 * {@link com.android.systemui.doze.DozeService} is configured. 38 */ isDozing()39 boolean isDozing(); 40 41 /** 42 * Is the status bar panel expanded. 43 */ isExpanded()44 boolean isExpanded(); 45 46 /** 47 * Is device pulsing. 48 */ isPulsing()49 boolean isPulsing(); 50 51 /** 52 * Is device dreaming. This method is more inclusive than 53 * {@link android.service.dreams.IDreamManager.isDreaming}, as it will return true during the 54 * dream's wake-up phase. 55 */ isDreaming()56 boolean isDreaming(); 57 58 /** 59 * Adds a state listener 60 */ addCallback(StateListener listener)61 void addCallback(StateListener listener); 62 63 /** 64 * Removes callback from listeners 65 */ removeCallback(StateListener listener)66 void removeCallback(StateListener listener); 67 68 /** 69 * Get amount of doze 70 */ getDozeAmount()71 float getDozeAmount(); 72 73 /** 74 * Listener for StatusBarState updates 75 */ 76 @ProvidesInterface(version = StateListener.VERSION) 77 public interface StateListener { 78 int VERSION = 1; 79 80 /** 81 * Callback before the new state is applied, for those who need to preempt the change. 82 */ onStatePreChange(int oldState, int newState)83 default void onStatePreChange(int oldState, int newState) { 84 } 85 86 /** 87 * Callback after all listeners have had a chance to update based on the state change 88 */ onStatePostChange()89 default void onStatePostChange() { 90 } 91 92 /** 93 * Required callback. Get the new state and do what you will with it. Keep in mind that 94 * other listeners are typically unordered and don't rely on your work being done before 95 * other peers. 96 * 97 * Only called if the state is actually different. 98 */ onStateChanged(int newState)99 default void onStateChanged(int newState) { 100 } 101 102 /** 103 * Callback to be notified about upcoming state changes. Typically, is immediately followed 104 * by #onStateChanged, unless there was an intentional delay in updating the state changed. 105 */ onUpcomingStateChanged(int upcomingState)106 default void onUpcomingStateChanged(int upcomingState) {} 107 108 /** 109 * Callback to be notified when Dozing changes. Dozing is stored separately from state. 110 */ onDozingChanged(boolean isDozing)111 default void onDozingChanged(boolean isDozing) {} 112 113 /** 114 * Callback to be notified when Dreaming changes. Dreaming is stored separately from state. 115 */ onDreamingChanged(boolean isDreaming)116 default void onDreamingChanged(boolean isDreaming) {} 117 118 /** 119 * Callback to be notified when the doze amount changes. Useful for animations. 120 * Note: this will be called for each animation frame. Please be careful to avoid 121 * performance regressions. 122 */ onDozeAmountChanged(float linear, float eased)123 default void onDozeAmountChanged(float linear, float eased) {} 124 125 /** 126 * Callback to be notified when the pulsing state changes 127 */ onPulsingChanged(boolean pulsing)128 default void onPulsingChanged(boolean pulsing) {} 129 130 /** 131 * Callback to be notified when the expanded state of the status bar changes 132 */ onExpandedChanged(boolean isExpanded)133 default void onExpandedChanged(boolean isExpanded) {} 134 } 135 } 136