Add dock defender battery tips
1. Remove the dock defender v1 code 2. Add dock defender battery tips and update corresponding list item string Bug:256523472 Test: Unit test passed and manual test on device Change-Id: Ib6c09df056744142f42f5e2a13252b58e54c7534 Signed-off-by: Zhenwei Chen <zhenwec@google.com>
This commit is contained in:
@@ -33,6 +33,7 @@ import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UidBatteryConsumer;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -76,6 +77,11 @@ public class BatteryUtils {
|
||||
/** Special UID for aggregated other users. */
|
||||
public static final long UID_OTHER_USERS = Long.MIN_VALUE;
|
||||
|
||||
/** Flag to check if the dock defender mode has been temporarily bypassed */
|
||||
public static final String SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS = "dock_defender_bypass";
|
||||
|
||||
public static final String BYPASS_DOCK_DEFENDER_ACTION = "battery.dock.defender.bypass";
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({StatusType.SCREEN_USAGE,
|
||||
StatusType.FOREGROUND,
|
||||
@@ -89,6 +95,18 @@ public class BatteryUtils {
|
||||
int ALL = 3;
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({DockDefenderMode.FUTURE_BYPASS,
|
||||
DockDefenderMode.ACTIVE,
|
||||
DockDefenderMode.TEMPORARILY_BYPASSED,
|
||||
DockDefenderMode.DISABLED})
|
||||
public @interface DockDefenderMode {
|
||||
int FUTURE_BYPASS = 0;
|
||||
int ACTIVE = 1;
|
||||
int TEMPORARILY_BYPASSED = 2;
|
||||
int DISABLED = 3;
|
||||
}
|
||||
|
||||
private static final String TAG = "BatteryUtils";
|
||||
|
||||
private static BatteryUtils sInstance;
|
||||
@@ -592,4 +610,21 @@ public class BatteryUtils {
|
||||
? -1 /*invalid battery level*/
|
||||
: Math.round((level / (float) scale) * 100f);
|
||||
}
|
||||
|
||||
/** Gets the current dock defender mode */
|
||||
public static int getCurrentDockDefenderMode(Context context, BatteryInfo batteryInfo) {
|
||||
if (batteryInfo.pluggedStatus == BatteryManager.BATTERY_PLUGGED_DOCK) {
|
||||
if (Settings.Global.getInt(context.getContentResolver(),
|
||||
SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0) == 1) {
|
||||
return DockDefenderMode.TEMPORARILY_BYPASSED;
|
||||
} else if (batteryInfo.isOverheated && FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context)
|
||||
.isExtraDefend()) {
|
||||
return DockDefenderMode.ACTIVE;
|
||||
} else if (!batteryInfo.isOverheated) {
|
||||
return DockDefenderMode.FUTURE_BYPASS;
|
||||
}
|
||||
}
|
||||
return DockDefenderMode.DISABLED;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user