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

Commit e7745b12 authored by Lei Yu's avatar Lei Yu Committed by Android (Google) Code Review
Browse files

Merge "Add early warning tip and detector"

parents de64baeb 62d6a9dc
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2018 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:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#0F9D58"
        android:pathData="M13,7h-2v2h2L13,7zM13,11h-2v6h2v-6zM17,1.01L7,1c-1.1,0 -2,0.9 -2,2v18c0,
        1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,3c0,-1.1 -0.9,-1.99 -2,-1.99zM17,19L7,19L7,5h10v14z"/>
</vector>
+8 −0
Original line number Diff line number Diff line
@@ -4813,6 +4813,14 @@
    <string name="battery_tip_smart_battery_title">Turn on smart battery manager</string>
    <!-- Summary for the smart battery tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_smart_battery_summary">Turn on to optimize battery usage</string>
    <!-- Title for the early heads up tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_early_heads_up_title">Turn on Low Battery Mode</string>
    <!-- Summary for the early hedas up tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_early_heads_up_summary">Extend your battery life</string>
    <!-- Title when early heads up is solved [CHAR LIMIT=NONE] -->
    <string name="battery_tip_early_heads_up_done_title">Low Battery Mode is on</string>
    <!-- Summary when early heads up is solved [CHAR LIMIT=NONE] -->
    <string name="battery_tip_early_heads_up_done_summary">Some features are limited</string>
    <!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
    <string name="battery_tip_high_usage_title" product="default">Phone used heavily</string>
    <!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
+5 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.detectors.BatteryTipDetector;
import com.android.settings.fuelgauge.batterytip.detectors.EarlyWarningDetector;
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
import com.android.settings.fuelgauge.batterytip.detectors.SmartBatteryDetector;
@@ -64,13 +65,15 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
        final List<BatteryTip> tips = new ArrayList<>();
        final BatteryTipPolicy policy = new BatteryTipPolicy(getContext());
        final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG);
        final Context context = getContext();
        mVisibleTips = 0;

        addBatteryTipFromDetector(tips, new LowBatteryDetector(policy, batteryInfo));
        addBatteryTipFromDetector(tips,
                new HighUsageDetector(getContext(), policy, mBatteryStatsHelper));
                new HighUsageDetector(context, policy, mBatteryStatsHelper));
        addBatteryTipFromDetector(tips,
                new SmartBatteryDetector(policy, getContext().getContentResolver()));
                new SmartBatteryDetector(policy, context.getContentResolver()));
        addBatteryTipFromDetector(tips, new EarlyWarningDetector(policy, context));
        // Add summary detector at last since it need other detectors to update the mVisibleTips
        addBatteryTipFromDetector(tips, new SummaryDetector(policy, mVisibleTips));

+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.fuelgauge.batterytip;
import android.app.Fragment;

import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.batterytip.actions.BatterySaverAction;
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
import com.android.settings.fuelgauge.batterytip.actions.SmartBatteryAction;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
@@ -40,6 +41,8 @@ public class BatteryTipUtils {
        switch (batteryTip.getType()) {
            case BatteryTip.TipType.SMART_BATTERY_MANAGER:
                return new SmartBatteryAction(settingsActivity, fragment);
            case BatteryTip.TipType.BATTERY_SAVER:
                return new BatterySaverAction(settingsActivity.getApplicationContext());
            default:
                return null;
        }
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

package com.android.settings.fuelgauge.batterytip.actions;

import android.content.Context;
import android.os.PowerManager;

public class BatterySaverAction extends BatteryTipAction {
    private PowerManager mPowerManager;

    public BatterySaverAction(Context context) {
        super(context);
        mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    }

    /**
     * Handle the action when user clicks positive button
     */
    @Override
    public void handlePositiveAction() {
        mPowerManager.setPowerSaveMode(true);
    }
}
Loading