This tip was punted however we need to bring it back to P. It happens when battery level is low or remaining time is less than 3 hour. The suggestion is to turn on battery saver. 1. Extend tip from EarlyWarningTip since it has most common logic 2. Update the detector to align it to battery saver notifcation in systemui. 3. Update tip order to surface low battery tip. Follow CL will: 1. Hook up the low battery threshold to server side 2. Add test stub for this tip, so we could trigger it by adb. Change-Id: I14f9696a549393bf980e31838fb86afd5d9efbc7 Bug: 76113067 Test: RunSettingsRoboTests
97 lines
3.8 KiB
Java
97 lines
3.8 KiB
Java
/*
|
|
* Copyright (C) 2017 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;
|
|
|
|
import android.content.Context;
|
|
import android.support.annotation.VisibleForTesting;
|
|
|
|
import com.android.internal.os.BatteryStatsHelper;
|
|
import com.android.settings.fuelgauge.BatteryInfo;
|
|
import com.android.settings.fuelgauge.BatteryUtils;
|
|
import com.android.settings.fuelgauge.Estimate;
|
|
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;
|
|
import com.android.settings.fuelgauge.batterytip.detectors.RestrictAppDetector;
|
|
import com.android.settings.fuelgauge.batterytip.detectors.SummaryDetector;
|
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
|
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
|
|
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
|
import com.android.settingslib.utils.AsyncLoader;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Loader to compute and return a battery tip list. It will always return a full length list even
|
|
* though some tips may have state {@code BaseBatteryTip.StateType.INVISIBLE}.
|
|
*/
|
|
public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
|
|
private static final String TAG = "BatteryTipLoader";
|
|
|
|
private static final boolean USE_FAKE_DATA = false;
|
|
|
|
private BatteryStatsHelper mBatteryStatsHelper;
|
|
@VisibleForTesting
|
|
BatteryUtils mBatteryUtils;
|
|
|
|
public BatteryTipLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
|
|
super(context);
|
|
mBatteryStatsHelper = batteryStatsHelper;
|
|
mBatteryUtils = BatteryUtils.getInstance(context);
|
|
}
|
|
|
|
@Override
|
|
public List<BatteryTip> loadInBackground() {
|
|
if (USE_FAKE_DATA) {
|
|
return getFakeData();
|
|
}
|
|
final List<BatteryTip> tips = new ArrayList<>();
|
|
final BatteryTipPolicy policy = new BatteryTipPolicy(getContext());
|
|
final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG);
|
|
final Context context = getContext();
|
|
|
|
tips.add(new LowBatteryDetector(context, policy, batteryInfo).detect());
|
|
tips.add(new HighUsageDetector(context, policy, mBatteryStatsHelper,
|
|
batteryInfo.discharging).detect());
|
|
tips.add(new SmartBatteryDetector(policy, context.getContentResolver()).detect());
|
|
tips.add(new EarlyWarningDetector(policy, context).detect());
|
|
tips.add(new SummaryDetector(policy, batteryInfo.averageTimeToDischarge).detect());
|
|
tips.add(new RestrictAppDetector(context, policy).detect());
|
|
|
|
Collections.sort(tips);
|
|
return tips;
|
|
}
|
|
|
|
@Override
|
|
protected void onDiscardResult(List<BatteryTip> result) {
|
|
}
|
|
|
|
private List<BatteryTip> getFakeData() {
|
|
final List<BatteryTip> tips = new ArrayList<>();
|
|
tips.add(new SummaryTip(BatteryTip.StateType.NEW,
|
|
Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
|
|
tips.add(new LowBatteryTip(BatteryTip.StateType.NEW, false /* powerSaveModeOn */,
|
|
"Fake data"));
|
|
|
|
return tips;
|
|
}
|
|
|
|
}
|