• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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.policy;
18 
19 import android.annotation.Nullable;
20 import android.view.View;
21 
22 import com.android.systemui.demomode.DemoMode;
23 import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback;
24 
25 import java.io.PrintWriter;
26 import java.lang.ref.WeakReference;
27 
28 /**
29  * Controller for battery related information, including the charge level, power save mode,
30  * and time remaining information
31  */
32 public interface BatteryController extends DemoMode,
33         CallbackController<BatteryStateChangeCallback> {
34     /**
35      * Prints the current state of the {@link BatteryController} to the given {@link PrintWriter}.
36      */
dump(PrintWriter pw, String[] args)37     void dump(PrintWriter pw, String[] args);
38 
39     /**
40      * Sets if the current device is in power save mode.
41      */
setPowerSaveMode(boolean powerSave)42     default void setPowerSaveMode(boolean powerSave) {
43         setPowerSaveMode(powerSave, null);
44     }
45 
46     /**
47      * Sets if the current device is in power save mode.
48      *
49      * Can pass the view that triggered the request.
50      */
setPowerSaveMode(boolean powerSave, @Nullable View view)51     void setPowerSaveMode(boolean powerSave, @Nullable View view);
52 
53     /**
54      * Gets a reference to the last view used when called {@link #setPowerSaveMode}.
55      */
56     @Nullable
getLastPowerSaverStartView()57     default WeakReference<View> getLastPowerSaverStartView() {
58         return null;
59     }
60 
61     /**
62      * Clears the last view used when called {@link #setPowerSaveMode}.
63      *
64      * Immediately after calling this, a call to {@link #getLastPowerSaverStartView()} should return
65      * {@code null}.
66      */
clearLastPowerSaverStartView()67     default void clearLastPowerSaverStartView() {}
68 
69     /**
70      * Returns {@code true} if the device is currently plugged in.
71      */
isPluggedIn()72     boolean isPluggedIn();
73 
74     /**
75      * Returns {@code true} if the device is currently plugged in via wireless charger.
76      */
isPluggedInWireless()77     default boolean isPluggedInWireless() {
78         return false;
79     }
80 
81     /**
82      * Returns {@code true} if the device is currently in power save mode.
83      */
isPowerSave()84     boolean isPowerSave();
85 
86     /**
87      * Returns {@code true} if AOD was disabled by power saving policies.
88      */
isAodPowerSave()89     boolean isAodPowerSave();
90 
91     /**
92      * Initializes the class.
93      */
init()94     default void init() { }
95 
96     /**
97      * Returns {@code true} if the device is currently in wireless charging mode.
98      */
isWirelessCharging()99     default boolean isWirelessCharging() { return false; }
100 
101     /**
102      * Returns {@code true} if reverse is supported.
103      */
isReverseSupported()104     default boolean isReverseSupported() { return false; }
105 
106     /**
107      * Returns {@code true} if reverse is on.
108      */
isReverseOn()109     default boolean isReverseOn() { return false; }
110 
111     /**
112      * Set reverse state.
113      * @param isReverse true if turn on reverse, false otherwise
114      */
setReverseState(boolean isReverse)115     default void setReverseState(boolean isReverse) {}
116 
117     /**
118      * Returns {@code true} if extreme battery saver is on.
119      */
isExtremeSaverOn()120     default boolean isExtremeSaverOn() {
121         return false;
122     }
123 
124     /**
125      * Returns {@code true} if the charging source is
126      * {@link android.os.BatteryManager#BATTERY_PLUGGED_DOCK}.
127      *
128      * <P>Note that charging from dock is not considered as wireless charging. In other words,
129      * {@link BatteryController#isWirelessCharging()} and this are mutually exclusive.
130      */
isChargingSourceDock()131     default boolean isChargingSourceDock() {
132         return false;
133     }
134 
135     /**
136      * A listener that will be notified whenever a change in battery level or power save mode has
137      * occurred.
138      */
139     interface BatteryStateChangeCallback {
140 
onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging)141         default void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
142         }
143 
onPowerSaveChanged(boolean isPowerSave)144         default void onPowerSaveChanged(boolean isPowerSave) {
145         }
146 
onBatteryUnknownStateChanged(boolean isUnknown)147         default void onBatteryUnknownStateChanged(boolean isUnknown) {
148         }
149 
onReverseChanged(boolean isReverse, int level, String name)150         default void onReverseChanged(boolean isReverse, int level, String name) {
151         }
152 
onExtremeBatterySaverChanged(boolean isExtreme)153         default void onExtremeBatterySaverChanged(boolean isExtreme) {
154         }
155 
onWirelessChargingChanged(boolean isWirlessCharging)156         default void onWirelessChargingChanged(boolean isWirlessCharging) {
157         }
158 
onIsOverheatedChanged(boolean isOverheated)159         default void onIsOverheatedChanged(boolean isOverheated) {
160         }
161     }
162 
163     /**
164      * If available, get the estimated battery time remaining as a string.
165      *
166      * @param completion A lambda that will be called with the result of fetching the estimate. The
167      * first time this method is called may need to be dispatched to a background thread. The
168      * completion is called on the main thread
169      */
getEstimatedTimeRemainingString(EstimateFetchCompletion completion)170     default void getEstimatedTimeRemainingString(EstimateFetchCompletion completion) {}
171 
172     /**
173      * Callback called when the estimated time remaining text is fetched.
174      */
175     public interface EstimateFetchCompletion {
176 
177         /**
178          * The callback
179          * @param estimate the estimate
180          */
onBatteryRemainingEstimateRetrieved(@ullable String estimate)181         void onBatteryRemainingEstimateRetrieved(@Nullable String estimate);
182     }
183 }
184