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

Commit daaf1728 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Enhance battery settings limit charge tip" into sc-qpr1-dev

parents cd2016c7 083ace54
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6158,6 +6158,12 @@
    <string name="battery_tip_limited_temporarily_title">Charging temporarily limited</string>
    <!-- Summary for the battery limited temporarily tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_limited_temporarily_summary">To preserve your battery. Learn more.</string>
    <!-- Text of battery limited temporarily tip resume charge button. [CHAR LIMIT=NONE] -->
    <string name="battery_tip_limited_temporarily_dialog_resume_charge">Resume charging</string>
    <!-- Message of battery limited temporarily tip. [CHAR LIMIT=NONE] -->
    <string name="battery_tip_limited_temporarily_dialog_msg" product="default">In certain conditions, like high temperatures and long charging periods, charging may be limited to <xliff:g id="percent" example="50%">%1$s</xliff:g> to help preserve battery health.\n\nWhen those conditions end, your phone will automatically charge normally.</string>
    <!-- Message of battery limited temporarily tip. [CHAR LIMIT=NONE] -->
    <string name="battery_tip_limited_temporarily_dialog_msg" product="tablet">In certain conditions, like high temperatures and long charging periods, charging may be limited to <xliff:g id="percent" example="50%">%1$s</xliff:g> to help preserve battery health.\n\nWhen those conditions end, your tablet will automatically charge normally.</string>
    <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
    <string name="battery_tip_dialog_message" product="default">Because you’ve used your phone more than usual, your battery may run out sooner than it normally would.\n\nApps using most battery:</string>
    <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
    android:title="@string/smart_battery_manager_title"
    settings:keywords="@string/keywords_battery_adaptive_preferences">

    <com.android.settingslib.widget.IllustrationPreferencee
    <com.android.settingslib.widget.IllustrationPreference
        android:key="auto_awesome_battery"
        settings:lottie_rawRes="@raw/auto_awesome_battery_lottie" />

+5 −0
Original line number Diff line number Diff line
@@ -138,6 +138,11 @@ public interface PowerUsageFeatureProvider {
     */
    boolean isChartGraphSlotsEnabled(Context context);

    /**
     * Gets a intent for one time bypass charge limited to resume charging.
     */
    Intent getResumeChargeIntent();

    /**
     * Returns battery history data with corresponding timestamp key.
     */
+5 −0
Original line number Diff line number Diff line
@@ -165,6 +165,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
        return false;
    }

    @Override
    public Intent getResumeChargeIntent() {
        return null;
    }

    @Override
    public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
        return null;
+34 −0
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.view.LayoutInflater;

@@ -40,6 +43,7 @@ import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;

import java.text.NumberFormat;
import java.util.List;

/**
@@ -50,6 +54,7 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme

    private static final String ARG_BATTERY_TIP = "battery_tip";
    private static final String ARG_METRICS_KEY = "metrics_key";
    private static final double CHARGE_LIMIT_LEVEL = 0.8f;

    @VisibleForTesting
    BatteryTip mBatteryTip;
@@ -138,6 +143,28 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
                        .setPositiveButton(R.string.battery_tip_unrestrict_app_dialog_ok, this)
                        .setNegativeButton(R.string.battery_tip_unrestrict_app_dialog_cancel, null)
                        .create();
            case BatteryTip.TipType.BATTERY_DEFENDER:
                mMetricsFeatureProvider.action(context,
                        SettingsEnums.ACTION_TIP_BATTERY_DEFENDER, mMetricsKey);
                final String percentage =
                        NumberFormat.getPercentInstance().format(CHARGE_LIMIT_LEVEL);
                final String message = context.getString(
                        R.string.battery_tip_limited_temporarily_dialog_msg, percentage);
                final boolean isPluggedIn = isPluggedIn();
                final AlertDialog.Builder dialogBuilder =
                        new AlertDialog.Builder(context)
                                .setTitle(R.string.battery_tip_limited_temporarily_title)
                                .setMessage(message);
                if (isPluggedIn) {
                    dialogBuilder
                            .setPositiveButton(
                                    R.string.battery_tip_limited_temporarily_dialog_resume_charge,
                                    this)
                            .setNegativeButton(R.string.okay, null);
                } else {
                    dialogBuilder.setPositiveButton(R.string.okay, null);
                }
                return dialogBuilder.create();
            default:
                throw new IllegalArgumentException("unknown type " + mBatteryTip.getType());
        }
@@ -163,4 +190,11 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
        lsn.onBatteryTipHandled(mBatteryTip);
    }

    private boolean isPluggedIn() {
        final Intent batteryIntent = getContext().registerReceiver(null /* receiver */,
                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        return batteryIntent != null && batteryIntent.getIntExtra(
                BatteryManager.EXTRA_PLUGGED, 0) != 0;
    }

}
Loading