Merge ab/7061308 into stage.
Bug: 180401296 Merged-In: I35fe00aeeb112d5d9971985619e3ec5095dcdb7b Change-Id: I07d008e38827280c9e9c6b7fa31393309f9de8a3
This commit is contained in:
@@ -20,7 +20,9 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -38,15 +40,18 @@ import java.lang.annotation.RetentionPolicy;
|
||||
* 1. Battery level(e.g. 100%->99%)
|
||||
* 2. Battery status(e.g. plugged->unplugged)
|
||||
* 3. Battery saver(e.g. off->on)
|
||||
* 4. Battery health(e.g. good->overheat)
|
||||
*/
|
||||
public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "BatteryBroadcastRcvr";
|
||||
/**
|
||||
* Callback when the following has been changed:
|
||||
*
|
||||
* Battery level(e.g. 100%->99%)
|
||||
* Battery status(e.g. plugged->unplugged)
|
||||
* Battery saver(e.g. off->on)
|
||||
* Battery health(e.g. good->overheat)
|
||||
*/
|
||||
public interface OnBatteryChangedListener {
|
||||
void onBatteryChanged(@BatteryUpdateType int type);
|
||||
@@ -56,18 +61,24 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
@IntDef({BatteryUpdateType.MANUAL,
|
||||
BatteryUpdateType.BATTERY_LEVEL,
|
||||
BatteryUpdateType.BATTERY_SAVER,
|
||||
BatteryUpdateType.BATTERY_STATUS})
|
||||
BatteryUpdateType.BATTERY_STATUS,
|
||||
BatteryUpdateType.BATTERY_HEALTH,
|
||||
BatteryUpdateType.BATTERY_NOT_PRESENT})
|
||||
public @interface BatteryUpdateType {
|
||||
int MANUAL = 0;
|
||||
int BATTERY_LEVEL = 1;
|
||||
int BATTERY_SAVER = 2;
|
||||
int BATTERY_STATUS = 3;
|
||||
int BATTERY_HEALTH = 4;
|
||||
int BATTERY_NOT_PRESENT = 5;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String mBatteryLevel;
|
||||
@VisibleForTesting
|
||||
String mBatteryStatus;
|
||||
@VisibleForTesting
|
||||
int mBatteryHealth;
|
||||
private OnBatteryChangedListener mBatteryListener;
|
||||
private Context mContext;
|
||||
|
||||
@@ -101,10 +112,16 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
if (intent != null && mBatteryListener != null) {
|
||||
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
|
||||
final String batteryLevel = Utils.getBatteryPercentage(intent);
|
||||
final String batteryStatus = Utils.getBatteryStatus(
|
||||
mContext, intent);
|
||||
if (forceUpdate) {
|
||||
final String batteryStatus = Utils.getBatteryStatus(mContext, intent);
|
||||
final int batteryHealth = intent.getIntExtra(
|
||||
BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN);
|
||||
if (!Utils.isBatteryPresent(intent)) {
|
||||
Log.w(TAG, "Problem reading the battery meter.");
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_NOT_PRESENT);
|
||||
} else if (forceUpdate) {
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.MANUAL);
|
||||
} else if (batteryHealth != mBatteryHealth) {
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_HEALTH);
|
||||
} else if(!batteryLevel.equals(mBatteryLevel)) {
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_LEVEL);
|
||||
} else if (!batteryStatus.equals(mBatteryStatus)) {
|
||||
@@ -112,6 +129,7 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
}
|
||||
mBatteryLevel = batteryLevel;
|
||||
mBatteryStatus = batteryStatus;
|
||||
mBatteryHealth = batteryHealth;
|
||||
} else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(intent.getAction())) {
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_SAVER);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,10 @@ import android.icu.text.NumberFormat;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.PowerManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -35,7 +39,9 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.utils.AnnotationSpan;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
@@ -49,6 +55,7 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
||||
implements PreferenceControllerMixin, LifecycleObserver, OnStart {
|
||||
@VisibleForTesting
|
||||
static final String KEY_BATTERY_HEADER = "battery_header";
|
||||
private static final String ANNOTATION_URL = "url";
|
||||
|
||||
@VisibleForTesting
|
||||
BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
||||
@@ -94,7 +101,11 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
||||
mBatteryPercentText = mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
||||
mSummary1 = mBatteryLayoutPref.findViewById(R.id.summary1);
|
||||
|
||||
quickUpdateHeaderPreference();
|
||||
if (com.android.settings.Utils.isBatteryPresent(mContext)) {
|
||||
quickUpdateHeaderPreference();
|
||||
} else {
|
||||
showHelpMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,7 +124,9 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
||||
public void updateHeaderPreference(BatteryInfo info) {
|
||||
mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel));
|
||||
if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) {
|
||||
if (info.remainingLabel == null) {
|
||||
if (BatteryUtils.isBatteryDefenderOn(info)) {
|
||||
mSummary1.setText(null);
|
||||
} else if (info.remainingLabel == null) {
|
||||
mSummary1.setText(info.statusLabel);
|
||||
} else {
|
||||
mSummary1.setText(info.remainingLabel);
|
||||
@@ -146,6 +159,32 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
||||
mBatteryPercentText.setText(formatBatteryPercentageText(batteryLevel));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void showHelpMessage() {
|
||||
final LinearLayout batteryInfoLayout =
|
||||
mBatteryLayoutPref.findViewById(R.id.battery_info_layout);
|
||||
// Remove battery meter icon
|
||||
mBatteryMeterView.setVisibility(View.GONE);
|
||||
// Update the width of battery info layout
|
||||
final ViewGroup.LayoutParams params = batteryInfoLayout.getLayoutParams();
|
||||
params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
batteryInfoLayout.setLayoutParams(params);
|
||||
mBatteryPercentText.setText(mContext.getText(R.string.unknown));
|
||||
// Add linkable text for learn more
|
||||
final Intent helpIntent = HelpUtils.getHelpIntent(mContext,
|
||||
mContext.getString(R.string.help_url_battery_missing),
|
||||
mContext.getClass().getName());
|
||||
final AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan
|
||||
.LinkInfo(mContext, ANNOTATION_URL, helpIntent);
|
||||
if (linkInfo.isActionable()) {
|
||||
mSummary1.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
mSummary1.setText(AnnotationSpan
|
||||
.linkify(mContext.getText(R.string.battery_missing_help_message), linkInfo));
|
||||
} else {
|
||||
mSummary1.setText(mContext.getText(R.string.battery_missing_message));
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence formatBatteryPercentageText(int batteryLevel) {
|
||||
return TextUtils.expandTemplate(mContext.getText(R.string.battery_header_title_alternate),
|
||||
NumberFormat.getIntegerInstance().format(batteryLevel));
|
||||
|
||||
@@ -45,6 +45,7 @@ public class BatteryInfo {
|
||||
public CharSequence remainingLabel;
|
||||
public int batteryLevel;
|
||||
public boolean discharging = true;
|
||||
public boolean isOverheated;
|
||||
public long remainingTimeUs = 0;
|
||||
public long averageTimeToDischarge = EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN;
|
||||
public String batteryPercentString;
|
||||
@@ -232,6 +233,9 @@ public class BatteryInfo {
|
||||
info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
|
||||
info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
|
||||
info.averageTimeToDischarge = estimate.getAverageDischargeTime();
|
||||
info.isOverheated = batteryBroadcast.getIntExtra(
|
||||
BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN)
|
||||
== BatteryManager.BATTERY_HEALTH_OVERHEAT;
|
||||
|
||||
info.statusLabel = Utils.getBatteryStatus(context, batteryBroadcast);
|
||||
if (!info.mCharging) {
|
||||
@@ -251,7 +255,12 @@ public class BatteryInfo {
|
||||
BatteryManager.BATTERY_STATUS_UNKNOWN);
|
||||
info.discharging = false;
|
||||
info.suggestionLabel = null;
|
||||
if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
|
||||
if (info.isOverheated && status != BatteryManager.BATTERY_STATUS_FULL) {
|
||||
info.remainingLabel = null;
|
||||
int chargingLimitedResId = R.string.power_charging_limited;
|
||||
info.chargeLabel =
|
||||
context.getString(chargingLimitedResId, info.batteryPercentString);
|
||||
} else if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
|
||||
info.remainingTimeUs = chargeTime;
|
||||
CharSequence timeString = StringUtil.formatElapsedTime(context,
|
||||
PowerUtil.convertUsToMs(info.remainingTimeUs), false /* withSeconds */);
|
||||
|
||||
@@ -19,8 +19,6 @@ package com.android.settings.fuelgauge;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@@ -52,14 +50,12 @@ public class BatteryMeterView extends ImageView {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
final int frameColor = context.getColor(R.color.meter_background_color);
|
||||
mAccentColorFilter = new PorterDuffColorFilter(
|
||||
Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent),
|
||||
PorterDuff.Mode.SRC);
|
||||
mErrorColorFilter = new PorterDuffColorFilter(
|
||||
context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);
|
||||
mForegroundColorFilter =new PorterDuffColorFilter(
|
||||
Utils.getColorAttrDefaultColor(context, android.R.attr.colorForeground),
|
||||
PorterDuff.Mode.SRC);
|
||||
mAccentColorFilter = Utils.getAlphaInvariantColorFilterForColor(
|
||||
Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent));
|
||||
mErrorColorFilter = Utils.getAlphaInvariantColorFilterForColor(
|
||||
context.getColor(R.color.battery_icon_color_error));
|
||||
mForegroundColorFilter = Utils.getAlphaInvariantColorFilterForColor(
|
||||
Utils.getColorAttrDefaultColor(context, android.R.attr.colorForeground));
|
||||
mDrawable = new BatteryMeterDrawable(context, frameColor);
|
||||
mDrawable.setColorFilter(mAccentColorFilter);
|
||||
setImageDrawable(mDrawable);
|
||||
|
||||
@@ -403,6 +403,13 @@ public class BatteryUtils {
|
||||
Log.d(tag, message + ": " + (System.currentTimeMillis() - startTime) + "ms");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if battery is overheated and charging.
|
||||
*/
|
||||
public static boolean isBatteryDefenderOn(BatteryInfo batteryInfo) {
|
||||
return batteryInfo.isOverheated && !batteryInfo.discharging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find package uid from package name
|
||||
*
|
||||
|
||||
@@ -44,6 +44,7 @@ public abstract class PowerUsageBase extends DashboardFragment {
|
||||
protected BatteryStatsHelper mStatsHelper;
|
||||
protected UserManager mUm;
|
||||
private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
||||
protected boolean mIsBatteryPresent = true;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
@@ -60,6 +61,9 @@ public abstract class PowerUsageBase extends DashboardFragment {
|
||||
|
||||
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
|
||||
mBatteryBroadcastReceiver.setBatteryChangedListener(type -> {
|
||||
if (type == BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_NOT_PRESENT) {
|
||||
mIsBatteryPresent = false;
|
||||
}
|
||||
restartBatteryStatsLoader(type);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ import com.android.settingslib.widget.LayoutPreference;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Displays a list of apps and subsystems that consume power, ordered by how much power was
|
||||
* consumed since the last time it was unplugged.
|
||||
* Displays a list of apps and subsystems that consume power, ordered by how much power was consumed
|
||||
* since the last time it was unplugged.
|
||||
*/
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class PowerUsageSummary extends PowerUsageBase implements OnLongClickListener,
|
||||
@@ -220,7 +220,9 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
KEY_TIME_SINCE_LAST_FULL_CHARGE);
|
||||
mBatteryUtils = BatteryUtils.getInstance(getContext());
|
||||
|
||||
restartBatteryInfoLoader();
|
||||
if (Utils.isBatteryPresent(getContext())) {
|
||||
restartBatteryInfoLoader();
|
||||
}
|
||||
mBatteryTipPreferenceController.restoreInstanceState(icicle);
|
||||
updateBatteryTipFlag(icicle);
|
||||
}
|
||||
@@ -287,6 +289,10 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
// Skip refreshing UI if battery is not present.
|
||||
if (!mIsBatteryPresent) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip BatteryTipLoader if device is rotated or only battery level change
|
||||
if (mNeedUpdateBatteryTip
|
||||
@@ -295,7 +301,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
} else {
|
||||
mNeedUpdateBatteryTip = true;
|
||||
}
|
||||
|
||||
// reload BatteryInfo and updateUI
|
||||
restartBatteryInfoLoader();
|
||||
updateLastFullChargePreference();
|
||||
@@ -354,6 +359,10 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
if (getContext() == null) {
|
||||
return;
|
||||
}
|
||||
// Skip restartBatteryInfoLoader if battery is not present.
|
||||
if (!mIsBatteryPresent) {
|
||||
return;
|
||||
}
|
||||
getLoaderManager().restartLoader(BATTERY_INFO_LOADER, Bundle.EMPTY,
|
||||
mBatteryInfoLoaderCallbacks);
|
||||
if (mPowerFeatureProvider.isEstimateDebugEnabled()) {
|
||||
@@ -378,7 +387,10 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
@Override
|
||||
protected void restartBatteryStatsLoader(@BatteryUpdateType int refreshType) {
|
||||
super.restartBatteryStatsLoader(refreshType);
|
||||
mBatteryHeaderPreferenceController.quickUpdateHeaderPreference();
|
||||
// Update battery header if battery is present.
|
||||
if (mIsBatteryPresent) {
|
||||
mBatteryHeaderPreferenceController.quickUpdateHeaderPreference();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -392,7 +404,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
restartBatteryTipLoader();
|
||||
}
|
||||
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.power_usage_summary);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@@ -30,6 +31,8 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
public class TopLevelBatteryPreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mIsBatteryPresent = true;
|
||||
private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
||||
private Preference mPreference;
|
||||
private BatteryInfo mBatteryInfo;
|
||||
@@ -38,6 +41,9 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
|
||||
super(context, preferenceKey);
|
||||
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
|
||||
mBatteryBroadcastReceiver.setBatteryChangedListener(type -> {
|
||||
if (type == BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_NOT_PRESENT) {
|
||||
mIsBatteryPresent = false;
|
||||
}
|
||||
BatteryInfo.getBatteryInfo(mContext, info -> {
|
||||
mBatteryInfo = info;
|
||||
updateState(mPreference);
|
||||
@@ -69,6 +75,10 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
// Display help message if battery is not present.
|
||||
if (!mIsBatteryPresent) {
|
||||
return mContext.getText(R.string.battery_missing_message);
|
||||
}
|
||||
return getDashboardLabel(mContext, mBatteryInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import androidx.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.BatteryDefenderDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.EarlyWarningDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
|
||||
@@ -72,6 +73,7 @@ public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
|
||||
batteryInfo.discharging).detect());
|
||||
tips.add(new SmartBatteryDetector(policy, context.getContentResolver()).detect());
|
||||
tips.add(new EarlyWarningDetector(policy, context).detect());
|
||||
tips.add(new BatteryDefenderDetector(batteryInfo).detect());
|
||||
tips.add(new SummaryDetector(policy, batteryInfo.averageTimeToDischarge).detect());
|
||||
// Disable this feature now since it introduces false positive cases. We will try to improve
|
||||
// it in the future.
|
||||
|
||||
@@ -29,6 +29,7 @@ import androidx.annotation.NonNull;
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.fuelgauge.batterytip.actions.BatteryDefenderAction;
|
||||
import com.android.settings.fuelgauge.batterytip.actions.BatterySaverAction;
|
||||
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
|
||||
import com.android.settings.fuelgauge.batterytip.actions.OpenBatterySaverAction;
|
||||
@@ -111,6 +112,8 @@ public class BatteryTipUtils {
|
||||
}
|
||||
case BatteryTip.TipType.REMOVE_APP_RESTRICTION:
|
||||
return new UnrestrictAppAction(settingsActivity, (UnrestrictAppTip) batteryTip);
|
||||
case BatteryTip.TipType.BATTERY_DEFENDER:
|
||||
return new BatteryDefenderAction(settingsActivity);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.actions;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
|
||||
/**
|
||||
* Action to open the Support Center article
|
||||
*/
|
||||
public class BatteryDefenderAction extends BatteryTipAction {
|
||||
private SettingsActivity mSettingsActivity;
|
||||
|
||||
public BatteryDefenderAction(SettingsActivity settingsActivity) {
|
||||
super(settingsActivity.getApplicationContext());
|
||||
mSettingsActivity = settingsActivity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the action when user clicks positive button
|
||||
*/
|
||||
@Override
|
||||
public void handlePositiveAction(int metricsKey) {
|
||||
final Intent intent = HelpUtils.getHelpIntent(
|
||||
mContext,
|
||||
mContext.getString(R.string.help_url_battery_defender),
|
||||
getClass().getName());
|
||||
if (intent != null) {
|
||||
mSettingsActivity.startActivityForResult(intent, 0);
|
||||
}
|
||||
// TODO(b/173985153): Add logging enums for Battery Defender.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.BatteryInfo;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
|
||||
/**
|
||||
* Detect whether the battery is overheated
|
||||
*/
|
||||
public class BatteryDefenderDetector implements BatteryTipDetector {
|
||||
private BatteryInfo mBatteryInfo;
|
||||
|
||||
public BatteryDefenderDetector(BatteryInfo batteryInfo) {
|
||||
mBatteryInfo = batteryInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
final int state =
|
||||
BatteryUtils.isBatteryDefenderOn(mBatteryInfo)
|
||||
? BatteryTip.StateType.NEW
|
||||
: BatteryTip.StateType.INVISIBLE;
|
||||
return new BatteryDefenderTip(state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.content.Context;
|
||||
import android.os.Parcel;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
/**
|
||||
* Tip to show current battery is overheated
|
||||
*/
|
||||
public class BatteryDefenderTip extends BatteryTip {
|
||||
|
||||
public BatteryDefenderTip(@StateType int state) {
|
||||
super(TipType.BATTERY_DEFENDER, state, false /* showDialog */);
|
||||
}
|
||||
|
||||
private BatteryDefenderTip(Parcel in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle(Context context) {
|
||||
return context.getString(R.string.battery_tip_limited_temporarily_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary(Context context) {
|
||||
return context.getString(R.string.battery_tip_limited_temporarily_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconId() {
|
||||
return R.drawable.ic_battery_status_good_24dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(BatteryTip tip) {
|
||||
mState = tip.mState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
|
||||
// TODO(b/173985153): Add logging enums for Battery Defender.
|
||||
}
|
||||
|
||||
public static final Creator CREATOR = new Creator() {
|
||||
public BatteryTip createFromParcel(Parcel in) {
|
||||
return new BatteryDefenderTip(in);
|
||||
}
|
||||
|
||||
public BatteryTip[] newArray(int size) {
|
||||
return new BatteryDefenderTip[size];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.fuelgauge.batterytip.tips;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.SparseIntArray;
|
||||
@@ -58,7 +57,8 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
TipType.APP_RESTRICTION,
|
||||
TipType.REDUCED_BATTERY,
|
||||
TipType.LOW_BATTERY,
|
||||
TipType.REMOVE_APP_RESTRICTION})
|
||||
TipType.REMOVE_APP_RESTRICTION,
|
||||
TipType.BATTERY_DEFENDER})
|
||||
public @interface TipType {
|
||||
int SMART_BATTERY_MANAGER = 0;
|
||||
int APP_RESTRICTION = 1;
|
||||
@@ -68,20 +68,22 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
int LOW_BATTERY = 5;
|
||||
int SUMMARY = 6;
|
||||
int REMOVE_APP_RESTRICTION = 7;
|
||||
int BATTERY_DEFENDER = 8;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static final SparseIntArray TIP_ORDER;
|
||||
static {
|
||||
TIP_ORDER = new SparseIntArray();
|
||||
TIP_ORDER.append(TipType.APP_RESTRICTION, 0);
|
||||
TIP_ORDER.append(TipType.BATTERY_SAVER, 1);
|
||||
TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 2);
|
||||
TIP_ORDER.append(TipType.LOW_BATTERY, 3);
|
||||
TIP_ORDER.append(TipType.SUMMARY, 4);
|
||||
TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 5);
|
||||
TIP_ORDER.append(TipType.REDUCED_BATTERY, 6);
|
||||
TIP_ORDER.append(TipType.REMOVE_APP_RESTRICTION, 7);
|
||||
TIP_ORDER.append(TipType.BATTERY_DEFENDER, 0);
|
||||
TIP_ORDER.append(TipType.APP_RESTRICTION, 1);
|
||||
TIP_ORDER.append(TipType.BATTERY_SAVER, 2);
|
||||
TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 3);
|
||||
TIP_ORDER.append(TipType.LOW_BATTERY, 4);
|
||||
TIP_ORDER.append(TipType.SUMMARY, 5);
|
||||
TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 6);
|
||||
TIP_ORDER.append(TipType.REDUCED_BATTERY, 7);
|
||||
TIP_ORDER.append(TipType.REMOVE_APP_RESTRICTION, 8);
|
||||
}
|
||||
|
||||
private static final String KEY_PREFIX = "key_battery_tip";
|
||||
|
||||
Reference in New Issue
Block a user