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 
21 import com.android.systemui.Dumpable;
22 import com.android.systemui.demomode.DemoMode;
23 import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback;
24 
25 import java.io.FileDescriptor;
26 import java.io.PrintWriter;
27 
28 public interface BatteryController extends DemoMode, Dumpable,
29         CallbackController<BatteryStateChangeCallback> {
30     /**
31      * Prints the current state of the {@link BatteryController} to the given {@link PrintWriter}.
32      */
dump(FileDescriptor fd, PrintWriter pw, String[] args)33     void dump(FileDescriptor fd, PrintWriter pw, String[] args);
34 
35     /**
36      * Sets if the current device is in power save mode.
37      */
setPowerSaveMode(boolean powerSave)38     void setPowerSaveMode(boolean powerSave);
39 
40     /**
41      * Returns {@code true} if the device is currently plugged in.
42      */
isPluggedIn()43     boolean isPluggedIn();
44 
45     /**
46      * Returns {@code true} if the device is currently plugged in via wireless charger.
47      */
isPluggedInWireless()48     default boolean isPluggedInWireless() {
49         return false;
50     }
51 
52     /**
53      * Returns {@code true} if the device is currently in power save mode.
54      */
isPowerSave()55     boolean isPowerSave();
56 
57     /**
58      * Returns {@code true} if AOD was disabled by power saving policies.
59      */
isAodPowerSave()60     boolean isAodPowerSave();
61 
62     /**
63      * Initializes the class.
64      */
init()65     default void init() { }
66 
67     /**
68      * Returns {@code true} if the device is currently in wireless charging mode.
69      */
isWirelessCharging()70     default boolean isWirelessCharging() { return false; }
71 
72     /**
73      * Returns {@code true} if reverse is supported.
74      */
isReverseSupported()75     default boolean isReverseSupported() { return false; }
76 
77     /**
78      * Returns {@code true} if reverse is on.
79      */
isReverseOn()80     default boolean isReverseOn() { return false; }
81 
82     /**
83      * Set reverse state.
84      * @param isReverse true if turn on reverse, false otherwise
85      */
setReverseState(boolean isReverse)86     default void setReverseState(boolean isReverse) {}
87 
88     /**
89      * Returns {@code true} if extreme battery saver is on.
90      */
isExtremeSaverOn()91     default boolean isExtremeSaverOn() {
92         return false;
93     }
94 
95     /**
96      * A listener that will be notified whenever a change in battery level or power save mode has
97      * occurred.
98      */
99     interface BatteryStateChangeCallback {
100 
onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging)101         default void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
102         }
103 
onPowerSaveChanged(boolean isPowerSave)104         default void onPowerSaveChanged(boolean isPowerSave) {
105         }
106 
onBatteryUnknownStateChanged(boolean isUnknown)107         default void onBatteryUnknownStateChanged(boolean isUnknown) {
108         }
109 
onReverseChanged(boolean isReverse, int level, String name)110         default void onReverseChanged(boolean isReverse, int level, String name) {
111         }
112 
onExtremeBatterySaverChanged(boolean isExtreme)113         default void onExtremeBatterySaverChanged(boolean isExtreme) {
114         }
115 
onWirelessChargingChanged(boolean isWirlessCharging)116         default void onWirelessChargingChanged(boolean isWirlessCharging) {
117         }
118     }
119 
120     /**
121      * If available, get the estimated battery time remaining as a string.
122      *
123      * @param completion A lambda that will be called with the result of fetching the estimate. The
124      * first time this method is called may need to be dispatched to a background thread. The
125      * completion is called on the main thread
126      */
getEstimatedTimeRemainingString(EstimateFetchCompletion completion)127     default void getEstimatedTimeRemainingString(EstimateFetchCompletion completion) {}
128 
129     /**
130      * Callback called when the estimated time remaining text is fetched.
131      */
132     public interface EstimateFetchCompletion {
133 
134         /**
135          * The callback
136          * @param estimate the estimate
137          */
onBatteryRemainingEstimateRetrieved(@ullable String estimate)138         void onBatteryRemainingEstimateRetrieved(@Nullable String estimate);
139     }
140 }
141