Merge "Reduce the calling times for isExtraDefend" into tm-qpr-dev
This commit is contained in:
@@ -31,7 +31,6 @@ import com.android.settings.fuelgauge.batterytip.detectors.SmartBatteryDetector;
|
||||
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.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.fuelgauge.EstimateKt;
|
||||
import com.android.settingslib.utils.AsyncLoaderCompat;
|
||||
|
||||
@@ -67,16 +66,14 @@ public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
|
||||
final BatteryTipPolicy policy = new BatteryTipPolicy(getContext());
|
||||
final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(TAG);
|
||||
final Context context = getContext();
|
||||
final boolean extraDefend = FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context)
|
||||
.isExtraDefend();
|
||||
|
||||
tips.add(new LowBatteryDetector(context, policy, batteryInfo).detect());
|
||||
tips.add(new HighUsageDetector(context, policy, mBatteryUsageStats, batteryInfo).detect());
|
||||
tips.add(new SmartBatteryDetector(
|
||||
context, policy, batteryInfo, context.getContentResolver()).detect());
|
||||
tips.add(new EarlyWarningDetector(policy, context).detect());
|
||||
tips.add(new BatteryDefenderDetector(batteryInfo, extraDefend).detect());
|
||||
tips.add(new BatteryDefenderDetector(
|
||||
batteryInfo, context.getApplicationContext()).detect());
|
||||
Collections.sort(tips);
|
||||
return tips;
|
||||
}
|
||||
|
@@ -16,28 +16,33 @@
|
||||
|
||||
package com.android.settings.fuelgauge.batterytip.detectors;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.fuelgauge.BatteryInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* Detect whether the battery is overheated
|
||||
*/
|
||||
public class BatteryDefenderDetector implements BatteryTipDetector {
|
||||
private final BatteryInfo mBatteryInfo;
|
||||
private final boolean mExtraDefend;
|
||||
private final Context mContext;
|
||||
|
||||
public BatteryDefenderDetector(BatteryInfo batteryInfo, boolean extraDefend) {
|
||||
public BatteryDefenderDetector(BatteryInfo batteryInfo, Context context) {
|
||||
mBatteryInfo = batteryInfo;
|
||||
mExtraDefend = extraDefend;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
final int state =
|
||||
mBatteryInfo.isOverheated
|
||||
? BatteryTip.StateType.NEW
|
||||
: BatteryTip.StateType.INVISIBLE;
|
||||
return new BatteryDefenderTip(state, mExtraDefend);
|
||||
if (mBatteryInfo.isOverheated) {
|
||||
final boolean extraDefend = FeatureFactory.getFactory(mContext)
|
||||
.getPowerUsageFeatureProvider(mContext)
|
||||
.isExtraDefend();
|
||||
return new BatteryDefenderTip(BatteryTip.StateType.NEW, extraDefend);
|
||||
}
|
||||
return new BatteryDefenderTip(BatteryTip.StateType.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,8 @@ package com.android.settings.fuelgauge.batterytip.detectors;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.fuelgauge.BatteryInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
|
||||
@@ -42,7 +44,7 @@ public class BatteryDefenderDetectorTest {
|
||||
mBatteryInfo.discharging = false;
|
||||
|
||||
mBatteryDefenderDetector = new BatteryDefenderDetector(
|
||||
mBatteryInfo, /* extraDefend= */ false);
|
||||
mBatteryInfo, ApplicationProvider.getApplicationContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user