Provide the flexibility to add more tip detector
Bug: 309054332 Test: robotests Change-Id: I650141072b6de6c4dcdbbb853fb9997295d6e929
This commit is contained in:
@@ -18,6 +18,10 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** Feature provider for battery settings usage. */
|
/** Feature provider for battery settings usage. */
|
||||||
public interface BatterySettingsFeatureProvider {
|
public interface BatterySettingsFeatureProvider {
|
||||||
|
|
||||||
@@ -29,4 +33,7 @@ public interface BatterySettingsFeatureProvider {
|
|||||||
|
|
||||||
/** Check whether the battery information page is enabled in the About phone page */
|
/** Check whether the battery information page is enabled in the About phone page */
|
||||||
boolean isBatteryInfoEnabled(Context context);
|
boolean isBatteryInfoEnabled(Context context);
|
||||||
|
|
||||||
|
/** A way to add more battery tip detectors. */
|
||||||
|
void addBatteryTipDetector(Context context, List<BatteryTip> tips);
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,10 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** Feature provider implementation for battery settings usage. */
|
/** Feature provider implementation for battery settings usage. */
|
||||||
public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatureProvider {
|
public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatureProvider {
|
||||||
|
|
||||||
@@ -35,4 +39,7 @@ public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatur
|
|||||||
public boolean isBatteryInfoEnabled(Context context) {
|
public boolean isBatteryInfoEnabled(Context context) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addBatteryTipDetector(Context context, List<BatteryTip> tips) {}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
|
|||||||
import com.android.settings.fuelgauge.batterytip.detectors.IncompatibleChargerDetector;
|
import com.android.settings.fuelgauge.batterytip.detectors.IncompatibleChargerDetector;
|
||||||
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
|
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
|
||||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.utils.AsyncLoaderCompat;
|
import com.android.settingslib.utils.AsyncLoaderCompat;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -44,6 +45,7 @@ public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
|
|||||||
private static final String TAG = "BatteryTipLoader";
|
private static final String TAG = "BatteryTipLoader";
|
||||||
|
|
||||||
private BatteryUsageStats mBatteryUsageStats;
|
private BatteryUsageStats mBatteryUsageStats;
|
||||||
|
|
||||||
@VisibleForTesting BatteryUtils mBatteryUtils;
|
@VisibleForTesting BatteryUtils mBatteryUtils;
|
||||||
|
|
||||||
public BatteryTipLoader(Context context, BatteryUsageStats batteryUsageStats) {
|
public BatteryTipLoader(Context context, BatteryUsageStats batteryUsageStats) {
|
||||||
@@ -66,6 +68,9 @@ public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
|
|||||||
tips.add(new BatteryDefenderDetector(batteryInfo, context).detect());
|
tips.add(new BatteryDefenderDetector(batteryInfo, context).detect());
|
||||||
tips.add(new DockDefenderDetector(batteryInfo, context).detect());
|
tips.add(new DockDefenderDetector(batteryInfo, context).detect());
|
||||||
tips.add(new IncompatibleChargerDetector(context).detect());
|
tips.add(new IncompatibleChargerDetector(context).detect());
|
||||||
|
FeatureFactory.getFeatureFactory()
|
||||||
|
.getBatterySettingsFeatureProvider()
|
||||||
|
.addBatteryTipDetector(context, tips);
|
||||||
Collections.sort(tips);
|
Collections.sort(tips);
|
||||||
return tips;
|
return tips;
|
||||||
}
|
}
|
||||||
|
@@ -50,21 +50,20 @@ import java.util.List;
|
|||||||
public class BatteryTipLoaderTest {
|
public class BatteryTipLoaderTest {
|
||||||
|
|
||||||
private static final int[] TIP_ORDER = {
|
private static final int[] TIP_ORDER = {
|
||||||
BatteryTip.TipType.LOW_BATTERY,
|
BatteryTip.TipType.LOW_BATTERY,
|
||||||
BatteryTip.TipType.BATTERY_DEFENDER,
|
BatteryTip.TipType.BATTERY_DEFENDER,
|
||||||
BatteryTip.TipType.DOCK_DEFENDER,
|
BatteryTip.TipType.DOCK_DEFENDER,
|
||||||
BatteryTip.TipType.INCOMPATIBLE_CHARGER,
|
BatteryTip.TipType.INCOMPATIBLE_CHARGER,
|
||||||
BatteryTip.TipType.HIGH_DEVICE_USAGE};
|
BatteryTip.TipType.HIGH_DEVICE_USAGE
|
||||||
|
};
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private BatteryUsageStats mBatteryUsageStats;
|
private BatteryUsageStats mBatteryUsageStats;
|
||||||
@Mock
|
|
||||||
private PowerManager mPowerManager;
|
@Mock private PowerManager mPowerManager;
|
||||||
@Mock
|
@Mock private Intent mIntent;
|
||||||
private Intent mIntent;
|
@Mock private BatteryUtils mBatteryUtils;
|
||||||
@Mock
|
@Mock private BatteryInfo mBatteryInfo;
|
||||||
private BatteryUtils mBatteryUtils;
|
|
||||||
@Mock
|
|
||||||
private BatteryInfo mBatteryInfo;
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BatteryTipLoader mBatteryTipLoader;
|
private BatteryTipLoader mBatteryTipLoader;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user