Clean up useless battery tips and detectors
Bug: 263193978 Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge.batterytip" Change-Id: Idfe03eee5acee33126f1805ef45ccc4a9fc7e7a8
This commit is contained in:
@@ -30,7 +30,6 @@ import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
|
||||
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.settingslib.fuelgauge.EstimateKt;
|
||||
import com.android.settingslib.utils.AsyncLoaderCompat;
|
||||
|
||||
@@ -45,8 +44,6 @@ import java.util.List;
|
||||
public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
|
||||
private static final String TAG = "BatteryTipLoader";
|
||||
|
||||
private static final boolean USE_FAKE_DATA = false;
|
||||
|
||||
private BatteryUsageStats mBatteryUsageStats;
|
||||
@VisibleForTesting
|
||||
BatteryUtils mBatteryUtils;
|
||||
@@ -59,9 +56,6 @@ public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
|
||||
|
||||
@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(TAG);
|
||||
@@ -81,14 +75,4 @@ public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
|
||||
@Override
|
||||
protected void onDiscardResult(List<BatteryTip> result) {
|
||||
}
|
||||
|
||||
private List<BatteryTip> getFakeData() {
|
||||
final List<BatteryTip> tips = new ArrayList<>();
|
||||
tips.add(new SummaryTip(BatteryTip.StateType.NEW,
|
||||
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
|
||||
tips.add(new LowBatteryTip(BatteryTip.StateType.NEW, false /* powerSaveModeOn */));
|
||||
|
||||
return tips;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* 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.detectors;
|
||||
|
||||
import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper;
|
||||
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipUtils;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.AppLabelPredicate;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.AppRestrictionPredicate;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Detector whether to show summary tip. This detector should be executed as the last
|
||||
* {@link BatteryTipDetector} since it need the most up-to-date {@code visibleTips}
|
||||
*/
|
||||
public class RestrictAppDetector implements BatteryTipDetector {
|
||||
@VisibleForTesting
|
||||
static final boolean USE_FAKE_DATA = false;
|
||||
private BatteryTipPolicy mPolicy;
|
||||
@VisibleForTesting
|
||||
BatteryDatabaseManager mBatteryDatabaseManager;
|
||||
private Context mContext;
|
||||
|
||||
private AppRestrictionPredicate mAppRestrictionPredicate;
|
||||
private AppLabelPredicate mAppLabelPredicate;
|
||||
|
||||
public RestrictAppDetector(Context context, BatteryTipPolicy policy) {
|
||||
mContext = context;
|
||||
mPolicy = policy;
|
||||
mBatteryDatabaseManager = BatteryDatabaseManager.getInstance(context);
|
||||
mAppRestrictionPredicate = AppRestrictionPredicate.getInstance(context);
|
||||
mAppLabelPredicate = AppLabelPredicate.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
if (USE_FAKE_DATA) {
|
||||
return getFakeData();
|
||||
}
|
||||
if (mPolicy.appRestrictionEnabled) {
|
||||
final long oneDayBeforeMs = System.currentTimeMillis()
|
||||
- TimeUnit.HOURS.toMillis(mPolicy.appRestrictionActiveHour);
|
||||
final List<AppInfo> highUsageApps = BatteryTipUtils.detectAnomalies(mContext,
|
||||
oneDayBeforeMs);
|
||||
if (!highUsageApps.isEmpty()) {
|
||||
// If there are new anomalies, show them
|
||||
return new RestrictAppTip(BatteryTip.StateType.NEW, highUsageApps);
|
||||
} else {
|
||||
// Otherwise, show auto-handled one if it exists
|
||||
final List<AppInfo> autoHandledApps = mBatteryDatabaseManager.queryAllAnomalies(
|
||||
oneDayBeforeMs, AnomalyDatabaseHelper.State.AUTO_HANDLED);
|
||||
// Remove it if it doesn't have label or unrestricted
|
||||
autoHandledApps.removeIf(mAppLabelPredicate.or(mAppRestrictionPredicate.negate()));
|
||||
return new RestrictAppTip(autoHandledApps.isEmpty() ? BatteryTip.StateType.INVISIBLE
|
||||
: BatteryTip.StateType.HANDLED, autoHandledApps);
|
||||
}
|
||||
} else {
|
||||
return new RestrictAppTip(BatteryTip.StateType.INVISIBLE, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
private BatteryTip getFakeData() {
|
||||
final List<AppInfo> highUsageApps = new ArrayList<>();
|
||||
highUsageApps.add(new AppInfo.Builder()
|
||||
.setPackageName(SETTINGS_PACKAGE_NAME)
|
||||
.build());
|
||||
return new RestrictAppTip(BatteryTip.StateType.NEW, highUsageApps);
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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.detectors;
|
||||
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||
|
||||
/**
|
||||
* Detector whether to show summary tip. This detector should be executed as the last
|
||||
* {@link BatteryTipDetector} since it need the most up-to-date {@code visibleTips}
|
||||
*/
|
||||
public class SummaryDetector implements BatteryTipDetector {
|
||||
private BatteryTipPolicy mPolicy;
|
||||
private long mAverageTimeMs;
|
||||
|
||||
public SummaryDetector(BatteryTipPolicy policy, long averageTimeMs) {
|
||||
mPolicy = policy;
|
||||
mAverageTimeMs = averageTimeMs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
// Show it if there is no other tips shown
|
||||
final int state = mPolicy.summaryEnabled
|
||||
? BatteryTip.StateType.NEW
|
||||
: BatteryTip.StateType.INVISIBLE;
|
||||
return new SummaryTip(state, mAverageTimeMs);
|
||||
}
|
||||
}
|
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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.tips;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
/**
|
||||
* Tip to show general summary about battery life
|
||||
*/
|
||||
public class SummaryTip extends BatteryTip {
|
||||
private long mAverageTimeMs;
|
||||
|
||||
public SummaryTip(@StateType int state, long averageTimeMs) {
|
||||
super(TipType.SUMMARY, state, true /* showDialog */);
|
||||
mAverageTimeMs = averageTimeMs;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
SummaryTip(Parcel in) {
|
||||
super(in);
|
||||
mAverageTimeMs = in.readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle(Context context) {
|
||||
return context.getString(R.string.battery_tip_summary_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary(Context context) {
|
||||
return context.getString(R.string.battery_tip_summary_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconId() {
|
||||
return R.drawable.ic_battery_status_good_24dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconTintColorId() {
|
||||
return R.color.battery_good_color_light;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(BatteryTip tip) {
|
||||
mState = tip.mState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeLong(mAverageTimeMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
|
||||
metricsFeatureProvider.action(context, SettingsEnums.ACTION_SUMMARY_TIP,
|
||||
mState);
|
||||
}
|
||||
|
||||
public long getAverageTimeMs() {
|
||||
return mAverageTimeMs;
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
|
||||
public BatteryTip createFromParcel(Parcel in) {
|
||||
return new SummaryTip(in);
|
||||
}
|
||||
|
||||
public BatteryTip[] newArray(int size) {
|
||||
return new SummaryTip[size];
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user