Merge "Delete DockDefenderTip and Detector" into main
This commit is contained in:
@@ -35,5 +35,5 @@ public interface BatterySettingsFeatureProvider {
|
||||
boolean isBatteryInfoEnabled(Context context);
|
||||
|
||||
/** A way to add more battery tip detectors. */
|
||||
void addBatteryTipDetector(Context context, List<BatteryTip> tips);
|
||||
void addBatteryTipDetector(Context context, List<BatteryTip> tips, BatteryInfo batteryInfo);
|
||||
}
|
||||
|
||||
@@ -41,5 +41,6 @@ public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatur
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBatteryTipDetector(Context context, List<BatteryTip> tips) {}
|
||||
public void addBatteryTipDetector(
|
||||
Context context, List<BatteryTip> tips, BatteryInfo batteryInfo) {}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import androidx.annotation.VisibleForTesting;
|
||||
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.DockDefenderDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.IncompatibleChargerDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
|
||||
@@ -66,11 +65,10 @@ public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
|
||||
tips.add(new LowBatteryDetector(context, policy, batteryInfo, isPowerSaveMode).detect());
|
||||
tips.add(new HighUsageDetector(context, policy, mBatteryUsageStats, batteryInfo).detect());
|
||||
tips.add(new BatteryDefenderDetector(batteryInfo, context).detect());
|
||||
tips.add(new DockDefenderDetector(batteryInfo, context).detect());
|
||||
tips.add(new IncompatibleChargerDetector(context).detect());
|
||||
FeatureFactory.getFeatureFactory()
|
||||
.getBatterySettingsFeatureProvider()
|
||||
.addBatteryTipDetector(context, tips);
|
||||
.addBatteryTipDetector(context, tips, batteryInfo);
|
||||
Collections.sort(tips);
|
||||
return tips;
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 android.content.Context;
|
||||
|
||||
import com.android.settings.fuelgauge.BatteryInfo;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.DockDefenderTip;
|
||||
|
||||
/** Detect whether the dock defender mode is enabled. */
|
||||
public class DockDefenderDetector implements BatteryTipDetector {
|
||||
private final BatteryInfo mBatteryInfo;
|
||||
private final Context mContext;
|
||||
|
||||
public DockDefenderDetector(BatteryInfo batteryInfo, Context context) {
|
||||
mBatteryInfo = batteryInfo;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
int mode = BatteryUtils.getCurrentDockDefenderMode(mContext, mBatteryInfo);
|
||||
return new DockDefenderTip(
|
||||
mode != BatteryUtils.DockDefenderMode.DISABLED
|
||||
? BatteryTip.StateType.NEW
|
||||
: BatteryTip.StateType.INVISIBLE,
|
||||
mode);
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.fuelgauge.BatteryUtils.DockDefenderMode;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
/** Tip to show dock defender status */
|
||||
public class DockDefenderTip extends BatteryTip {
|
||||
private static final String TAG = "DockDefenderTip";
|
||||
private int mMode;
|
||||
|
||||
public DockDefenderTip(@StateType int state, @DockDefenderMode int mode) {
|
||||
super(TipType.DOCK_DEFENDER, state, false);
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
private DockDefenderTip(Parcel in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public int getMode() {
|
||||
return mMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle(Context context) {
|
||||
switch (mMode) {
|
||||
case DockDefenderMode.FUTURE_BYPASS:
|
||||
return context.getString(R.string.battery_tip_dock_defender_future_bypass_title);
|
||||
case DockDefenderMode.ACTIVE:
|
||||
return context.getString(R.string.battery_tip_dock_defender_active_title);
|
||||
case DockDefenderMode.TEMPORARILY_BYPASSED:
|
||||
return context.getString(
|
||||
R.string.battery_tip_dock_defender_temporarily_bypassed_title);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary(Context context) {
|
||||
switch (mMode) {
|
||||
case DockDefenderMode.FUTURE_BYPASS:
|
||||
return context.getString(R.string.battery_tip_dock_defender_future_bypass_summary);
|
||||
case DockDefenderMode.ACTIVE:
|
||||
return context.getString(R.string.battery_tip_dock_defender_active_summary);
|
||||
case DockDefenderMode.TEMPORARILY_BYPASSED:
|
||||
return context.getString(
|
||||
R.string.battery_tip_dock_defender_temporarily_bypassed_summary);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconId() {
|
||||
return mMode == DockDefenderMode.ACTIVE
|
||||
? R.drawable.ic_battery_status_protected_24dp
|
||||
: R.drawable.ic_battery_dock_defender_untriggered_24dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(BatteryTip tip) {
|
||||
mState = tip.mState;
|
||||
if (tip instanceof DockDefenderTip) {
|
||||
mMode = ((DockDefenderTip) tip).mMode;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
|
||||
metricsFeatureProvider.action(context, SettingsEnums.ACTION_DOCK_DEFENDER_TIP, mState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreference(Preference preference) {
|
||||
super.updatePreference(preference);
|
||||
final Context context = preference.getContext();
|
||||
|
||||
CardPreference cardPreference = castToCardPreferenceSafely(preference);
|
||||
if (cardPreference == null) {
|
||||
Log.e(TAG, "cast Preference to CardPreference failed");
|
||||
return;
|
||||
}
|
||||
|
||||
cardPreference.setSelectable(false);
|
||||
switch (mMode) {
|
||||
case DockDefenderMode.FUTURE_BYPASS:
|
||||
case DockDefenderMode.ACTIVE:
|
||||
cardPreference.setPrimaryButtonText(
|
||||
context.getString(R.string.battery_tip_charge_to_full_button));
|
||||
cardPreference.setPrimaryButtonClickListener(
|
||||
unused -> {
|
||||
resumeCharging(context);
|
||||
mMode = DockDefenderMode.TEMPORARILY_BYPASSED;
|
||||
context.sendBroadcast(
|
||||
new Intent()
|
||||
.setAction(BatteryUtils.BYPASS_DOCK_DEFENDER_ACTION)
|
||||
.setPackage(context.getPackageName())
|
||||
.addFlags(
|
||||
Intent.FLAG_RECEIVER_REGISTERED_ONLY
|
||||
| Intent.FLAG_RECEIVER_FOREGROUND));
|
||||
updatePreference(preference);
|
||||
});
|
||||
cardPreference.setPrimaryButtonVisible(true);
|
||||
break;
|
||||
case DockDefenderMode.TEMPORARILY_BYPASSED:
|
||||
cardPreference.setPrimaryButtonVisible(false);
|
||||
break;
|
||||
default:
|
||||
cardPreference.setVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
cardPreference.setSecondaryButtonText(context.getString(R.string.learn_more));
|
||||
cardPreference.setSecondaryButtonClickListener(
|
||||
button ->
|
||||
button.startActivityForResult(
|
||||
HelpUtils.getHelpIntent(
|
||||
context,
|
||||
context.getString(R.string.help_url_dock_defender),
|
||||
/* backupContext */ ""), /* requestCode */
|
||||
0));
|
||||
cardPreference.setSecondaryButtonVisible(true);
|
||||
cardPreference.setSecondaryButtonContentDescription(
|
||||
context.getString(
|
||||
R.string.battery_tip_limited_temporarily_sec_button_content_description));
|
||||
}
|
||||
|
||||
private void resumeCharging(Context context) {
|
||||
final Intent intent =
|
||||
FeatureFactory.getFeatureFactory()
|
||||
.getPowerUsageFeatureProvider()
|
||||
.getResumeChargeIntent(true);
|
||||
if (intent != null) {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
Log.i(TAG, "send resume charging broadcast intent=" + intent);
|
||||
}
|
||||
|
||||
public static final Creator CREATOR =
|
||||
new Creator() {
|
||||
public BatteryTip createFromParcel(Parcel in) {
|
||||
return new DockDefenderTip(in);
|
||||
}
|
||||
|
||||
public BatteryTip[] newArray(int size) {
|
||||
return new DockDefenderTip[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user