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