Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d11d9ce authored by Zhenwei Chen's avatar Zhenwei Chen
Browse files

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: default avatarZhenwei Chen <zhenwec@google.com>
parent 41ce8772
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="vector"
    android:width="16dp"
    android:height="16dp"
    android:viewportWidth="16"
    android:viewportHeight="16">
    <path
        android:name="path_1"
        android:pathData="M 11.739 14.409 C 11.572 14.576 11.346 14.67 11.11 14.67 L 4.89 14.67 C 4.654 14.67 4.428 14.576 4.261 14.409 C 4.094 14.242 4 14.016 4 13.78 L 4 3.55 C 4 3.316 4.092 3.091 4.257 2.924 C 4.422 2.758 4.646 2.663 4.88 2.66 L 6.33 2.66 L 6.33 1.33 L 9.66 1.33 L 9.66 2.66 L 11.11 2.66 C 11.227 2.66 11.343 2.683 11.451 2.728 C 11.559 2.773 11.657 2.838 11.739 2.921 C 11.822 3.003 11.887 3.102 11.932 3.209 C 11.977 3.317 12 3.433 12 3.55 L 12 13.78 C 12 14.016 11.906 14.242 11.739 14.409 Z M 6 9 L 8.67 4 L 8.67 7.67 L 10 7.67 L 7.33 12.67 L 7.33 9 L 6 9 Z"
        android:fillColor="#ffffff"
        android:strokeWidth="1"
        android:fillType="evenOdd"/>
</vector>
 No newline at end of file
+30 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="vector"
    android:width="16dp"
    android:height="16dp"
    android:viewportWidth="16"
    android:viewportHeight="16">
    <path
        android:name="path"
        android:pathData="M 11.739 14.409 C 11.572 14.576 11.346 14.67 11.11 14.67 L 4.89 14.67 C 4.654 14.67 4.428 14.576 4.261 14.409 C 4.094 14.242 4 14.016 4 13.78 L 4 3.55 C 4 3.316 4.092 3.091 4.257 2.924 C 4.422 2.758 4.646 2.663 4.88 2.66 L 6.33 2.66 L 6.33 1.33 L 9.66 1.33 L 9.66 2.66 L 11.11 2.66 C 11.227 2.66 11.343 2.683 11.451 2.728 C 11.559 2.773 11.657 2.838 11.739 2.921 C 11.822 3.003 11.887 3.102 11.932 3.209 C 11.977 3.317 12 3.433 12 3.55 L 12 13.78 C 12 14.016 11.906 14.242 11.739 14.409 Z M 6 9 L 8.67 4 L 8.67 7.67 L 10 7.67 L 7.33 12.67 L 7.33 9 L 6 9 Z"
        android:fillColor="#000000"
        android:strokeWidth="1"
        android:fillType="evenOdd"/>
</vector>
 No newline at end of file
+12 −2
Original line number Diff line number Diff line
@@ -4682,8 +4682,18 @@
    <string name="battery_tip_limited_temporarily_title">Charging is paused</string>
    <!-- Summary for the battery limited temporarily tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_limited_temporarily_summary">Protecting battery to extend battery lifespan</string>
    <!-- Summary for the battery limited temporarily extra tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_limited_temporarily_extra_summary"><xliff:g id="percent" example="10%">%1$s</xliff:g></string>
    <!-- Title for the battery dock defender future bypass tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_dock_defender_future_bypass_title">Charging to <xliff:g id="percent" example="10%">%1$s</xliff:g> to protect the battery</string>
    <!-- Summary for the battery dock defender future bypass tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_dock_defender_future_bypass_summary">When your tablet is docked, charging will be paused at <xliff:g id="percent" example="10%">%1$s</xliff:g> to extend battery lifespan</string>
    <!-- Title for the battery dock defender active tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_dock_defender_active_title">Charging paused to protect battery</string>
    <!-- Summary for the battery dock defender active tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_dock_defender_active_summary">When your tablet is docked, charging is paused at <xliff:g id="percent" example="10%">%1$s</xliff:g> to extend battery lifespan</string>
    <!-- Title for the battery dock defender temporarily bypassed tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_dock_defender_temporarily_bypassed_title">Charging to full</string>
    <!-- Summary for the battery dock defender temporarily bypassed tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_dock_defender_temporarily_bypassed_summary">To protect your battery, charging will be paused at <xliff:g id="percent" example="10%">%1$s</xliff:g> the next time your tablet is docked</string>
    <!-- Content description for the battery limited temporarily tip secondary button [CHAR LIMIT=NONE] -->
    <string name="battery_tip_limited_temporarily_sec_button_content_description">Learn more about charging is paused</string>
    <!-- Text of battery limited temporarily tip resume charge button. [CHAR LIMIT=NONE] -->
+3 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
        final IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
        intentFilter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
        intentFilter.addAction(BatteryUtils.BYPASS_DOCK_DEFENDER_ACTION);

        final Intent intent = mContext.registerReceiver(this, intentFilter);
        updateBatteryStatus(intent, true /* forceUpdate */);
@@ -132,6 +133,8 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
                mBatteryHealth = batteryHealth;
            } else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(intent.getAction())) {
                mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_SAVER);
            } else if (BatteryUtils.BYPASS_DOCK_DEFENDER_ACTION.equals(intent.getAction())) {
                mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_STATUS);
            }
        }
    }
+29 −13
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import com.android.settingslib.fuelgauge.EstimateKt;
import com.android.settingslib.utils.PowerUtil;
import com.android.settingslib.utils.StringUtil;

import java.text.NumberFormat;

public class BatteryInfo {
    private static final String TAG = "BatteryInfo";

@@ -49,6 +51,7 @@ public class BatteryInfo {
    public CharSequence remainingLabel;
    public int batteryLevel;
    public int batteryStatus;
    public int pluggedStatus;
    public boolean discharging = true;
    public boolean isOverheated;
    public long remainingTimeUs = 0;
@@ -253,7 +256,8 @@ public class BatteryInfo {
        info.mBatteryUsageStats = batteryUsageStats;
        info.batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
        info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
        info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
        info.pluggedStatus = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
        info.mCharging = info.pluggedStatus != 0;
        info.averageTimeToDischarge = estimate.getAverageDischargeTime();
        info.isOverheated = batteryBroadcast.getIntExtra(
                BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN)
@@ -280,25 +284,37 @@ public class BatteryInfo {
                BatteryManager.BATTERY_STATUS_UNKNOWN);
        info.discharging = false;
        info.suggestionLabel = null;
        if (info.isOverheated && status != BatteryManager.BATTERY_STATUS_FULL) {
        int dockDefenderMode = BatteryUtils.getCurrentDockDefenderMode(context, info);
        if ((info.isOverheated && status != BatteryManager.BATTERY_STATUS_FULL
                && dockDefenderMode == BatteryUtils.DockDefenderMode.DISABLED)
                || dockDefenderMode == BatteryUtils.DockDefenderMode.ACTIVE) {
            // Battery defender active, battery charging paused
            info.remainingLabel = null;
            int chargingLimitedResId = R.string.power_charging_limited;
            info.chargeLabel =
                context.getString(chargingLimitedResId, info.batteryPercentString);
        } else if (chargeTimeMs > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
            info.chargeLabel = context.getString(chargingLimitedResId, info.batteryPercentString);
        } else if ((chargeTimeMs > 0 && status != BatteryManager.BATTERY_STATUS_FULL
                && dockDefenderMode == BatteryUtils.DockDefenderMode.DISABLED)
                || dockDefenderMode == BatteryUtils.DockDefenderMode.TEMPORARILY_BYPASSED) {
            // Battery is charging to full
            info.remainingTimeUs = PowerUtil.convertMsToUs(chargeTimeMs);
            final CharSequence timeString = StringUtil.formatElapsedTime(
                    context,
                    PowerUtil.convertUsToMs(info.remainingTimeUs),
                    false /* withSeconds */,
            final CharSequence timeString = StringUtil.formatElapsedTime(context,
                    (double) PowerUtil.convertUsToMs(info.remainingTimeUs), false /* withSeconds */,
                    true /* collapseTimeUnit */);
            int resId = R.string.power_charging_duration;
            info.remainingLabel = context.getString(
                    R.string.power_remaining_charging_duration_only, timeString);
            info.remainingLabel = context.getString(R.string.power_remaining_charging_duration_only,
                    timeString);
            info.chargeLabel = context.getString(resId, info.batteryPercentString, timeString);
        } else if (dockDefenderMode == BatteryUtils.DockDefenderMode.FUTURE_BYPASS) {
            // Dock defender will be triggered in the future, charging will be paused at 90%.
            final int extraValue = context.getResources().getInteger(
                    R.integer.config_battery_extra_tip_value);
            final String extraPercentage = NumberFormat.getPercentInstance().format(
                    extraValue * 0.01f);
            info.chargeLabel = context.getString(R.string.power_charging_future_paused,
                    info.batteryPercentString, extraPercentage);
        } else {
            final String chargeStatusLabel =
                    Utils.getBatteryStatus(context, batteryBroadcast, compactStatus);
            final String chargeStatusLabel = Utils.getBatteryStatus(context, batteryBroadcast,
                    compactStatus);
            info.remainingLabel = null;
            info.chargeLabel = info.batteryLevel == 100 ? info.batteryPercentString :
                    resources.getString(R.string.power_charging, info.batteryPercentString,
Loading