• 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 
21 import com.android.systemui.DemoMode;
22 import com.android.systemui.Dumpable;
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 in power save mode.
42      */
isPowerSave()43     boolean isPowerSave();
44 
45     /**
46      * Returns {@code true} if AOD was disabled by power saving policies.
47      */
isAodPowerSave()48     default boolean isAodPowerSave() {
49         return isPowerSave();
50     }
51 
52     /**
53      * A listener that will be notified whenever a change in battery level or power save mode has
54      * occurred.
55      */
56     interface BatteryStateChangeCallback {
57 
onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging)58         default void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
59         }
60 
onPowerSaveChanged(boolean isPowerSave)61         default void onPowerSaveChanged(boolean isPowerSave) {
62         }
63     }
64 
65     /**
66      * If available, get the estimated battery time remaining as a string.
67      *
68      * @param completion A lambda that will be called with the result of fetching the estimate. The
69      * first time this method is called may need to be dispatched to a background thread. The
70      * completion is called on the main thread
71      */
getEstimatedTimeRemainingString(EstimateFetchCompletion completion)72     default void getEstimatedTimeRemainingString(EstimateFetchCompletion completion) {}
73 
74     /**
75      * Callback called when the estimated time remaining text is fetched.
76      */
77     public interface EstimateFetchCompletion {
78 
79         /**
80          * The callback
81          * @param estimate the estimate
82          */
onBatteryRemainingEstimateRetrieved(@ullable String estimate)83         void onBatteryRemainingEstimateRetrieved(@Nullable String estimate);
84     }
85 }
86