Add BatteryTipDetector and LowBatteryTip stuffs.
This cl adds the infra of BatteryTipDetector and use LowBatteryTip as an example(tip model + detector). Also add SummaryTipDetector and related tests Bug: 70570352 Test: RunSettingsRoboTests Change-Id: Icf1349b6ede9eb7ee5ed69b39ee3a2661ac660fa
This commit is contained in:
@@ -17,13 +17,21 @@
|
||||
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.batterytip.detectors.BatteryTipDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -36,18 +44,31 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
|
||||
private static final boolean USE_FAKE_DATA = false;
|
||||
|
||||
private BatteryStatsHelper mBatteryStatsHelper;
|
||||
private BatteryUtils mBatteryUtils;
|
||||
@VisibleForTesting
|
||||
int mVisibleTips;
|
||||
|
||||
public BatteryTipLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
|
||||
super(context);
|
||||
mBatteryStatsHelper = batteryStatsHelper;
|
||||
mBatteryUtils = BatteryUtils.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BatteryTip> loadInBackground() {
|
||||
List<BatteryTip> tips = new ArrayList<>();
|
||||
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);
|
||||
mVisibleTips = 0;
|
||||
|
||||
//TODO(b/70570352): add battery tip detectors
|
||||
tips.add(new SummaryTip(BatteryTip.StateType.NEW));
|
||||
addBatteryTipFromDetector(tips, new LowBatteryDetector(policy, batteryInfo));
|
||||
// Add summary detector at last since it need other detectors to update the mVisibleTips
|
||||
addBatteryTipFromDetector(tips, new SummaryDetector(policy, mVisibleTips));
|
||||
|
||||
Collections.sort(tips);
|
||||
return tips;
|
||||
}
|
||||
|
||||
@@ -55,4 +76,20 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
|
||||
protected void onDiscardResult(List<BatteryTip> result) {
|
||||
}
|
||||
|
||||
private List<BatteryTip> getFakeData() {
|
||||
final List<BatteryTip> tips = new ArrayList<>();
|
||||
tips.add(new SummaryTip(BatteryTip.StateType.NEW));
|
||||
tips.add(new LowBatteryTip(BatteryTip.StateType.NEW));
|
||||
|
||||
return tips;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addBatteryTipFromDetector(final List<BatteryTip> tips,
|
||||
final BatteryTipDetector detector) {
|
||||
final BatteryTip batteryTip = detector.detect();
|
||||
mVisibleTips += batteryTip.isVisible() ? 1 : 0;
|
||||
tips.add(batteryTip);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user