Revert "Add adaptive charging to the top level settings menu"
Revert submission 12989357-fix_ac_menu Reason for revert: Bug: 176473169 Reverted Changes: I6fc50a5ae:Add adaptive charging to the top level settings me... I8f600287c:Add adaptive charging to the top level settings me... Change-Id: I2928a96112bb8d2beeb071f231af6595edead4fa
This commit is contained in:
@@ -52,8 +52,7 @@ import com.android.settingslib.widget.LayoutPreference;
|
|||||||
* Controller that update the battery header view
|
* Controller that update the battery header view
|
||||||
*/
|
*/
|
||||||
public class BatteryHeaderPreferenceController extends BasePreferenceController
|
public class BatteryHeaderPreferenceController extends BasePreferenceController
|
||||||
implements PreferenceControllerMixin, LifecycleObserver, OnStart,
|
implements PreferenceControllerMixin, LifecycleObserver, OnStart {
|
||||||
BatteryPreferenceController {
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String KEY_BATTERY_HEADER = "battery_header";
|
static final String KEY_BATTERY_HEADER = "battery_header";
|
||||||
private static final String ANNOTATION_URL = "url";
|
private static final String ANNOTATION_URL = "url";
|
||||||
@@ -122,20 +121,16 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
|||||||
.styleActionBar(mActivity);
|
.styleActionBar(mActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence generateLabel(BatteryInfo info) {
|
|
||||||
if (BatteryUtils.isBatteryDefenderOn(info)) {
|
|
||||||
return null;
|
|
||||||
} else if (info.remainingLabel == null) {
|
|
||||||
return info.statusLabel;
|
|
||||||
} else {
|
|
||||||
return info.remainingLabel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateHeaderPreference(BatteryInfo info) {
|
public void updateHeaderPreference(BatteryInfo info) {
|
||||||
mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel));
|
mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel));
|
||||||
if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) {
|
if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) {
|
||||||
mSummary1.setText(generateLabel(info));
|
if (BatteryUtils.isBatteryDefenderOn(info)) {
|
||||||
|
mSummary1.setText(null);
|
||||||
|
} else if (info.remainingLabel == null) {
|
||||||
|
mSummary1.setText(info.statusLabel);
|
||||||
|
} else {
|
||||||
|
mSummary1.setText(info.remainingLabel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mBatteryMeterView.setBatteryLevel(info.batteryLevel);
|
mBatteryMeterView.setBatteryLevel(info.batteryLevel);
|
||||||
@@ -146,8 +141,8 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
|||||||
/**
|
/**
|
||||||
* Callback which receives text for the summary line.
|
* Callback which receives text for the summary line.
|
||||||
*/
|
*/
|
||||||
public void updateBatteryStatus(String label, BatteryInfo info) {
|
public void updateBatteryStatus(String statusLabel) {
|
||||||
mSummary1.setText(label != null ? label : generateLabel(info));
|
mSummary1.setText(statusLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void quickUpdateHeaderPreference() {
|
public void quickUpdateHeaderPreference() {
|
||||||
|
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common interface for a preference controller that updates battery status
|
|
||||||
*/
|
|
||||||
public interface BatteryPreferenceController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the label for the preference controller. If the label is null, the
|
|
||||||
* implementation should revert back to the original label based on the
|
|
||||||
* battery info.
|
|
||||||
*/
|
|
||||||
void updateBatteryStatus(String label, BatteryInfo info);
|
|
||||||
}
|
|
@@ -25,5 +25,5 @@ public interface BatteryStatusFeatureProvider {
|
|||||||
* Trigger a battery status update; return false if built-in status should be used.
|
* Trigger a battery status update; return false if built-in status should be used.
|
||||||
*/
|
*/
|
||||||
boolean triggerBatteryStatusUpdate(
|
boolean triggerBatteryStatusUpdate(
|
||||||
BatteryPreferenceController controller, BatteryInfo info);
|
BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info);
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@ public class BatteryStatusFeatureProviderImpl implements BatteryStatusFeaturePro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean triggerBatteryStatusUpdate(
|
public boolean triggerBatteryStatusUpdate(
|
||||||
BatteryPreferenceController controller, BatteryInfo info) {
|
BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,21 +26,18 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.FeatureFlags;
|
import com.android.settings.core.FeatureFlags;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
|
||||||
public class TopLevelBatteryPreferenceController extends BasePreferenceController implements
|
public class TopLevelBatteryPreferenceController extends BasePreferenceController implements
|
||||||
LifecycleObserver, OnStart, OnStop, BatteryPreferenceController {
|
LifecycleObserver, OnStart, OnStop {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected boolean mIsBatteryPresent = true;
|
boolean mIsBatteryPresent = true;
|
||||||
private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
private BatteryInfo mBatteryInfo;
|
private BatteryInfo mBatteryInfo;
|
||||||
private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
|
||||||
private String mBatteryStatusLabel;
|
|
||||||
|
|
||||||
public TopLevelBatteryPreferenceController(Context context, String preferenceKey) {
|
public TopLevelBatteryPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
@@ -54,9 +51,6 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
|
|||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}, true /* shortString */);
|
}, true /* shortString */);
|
||||||
});
|
});
|
||||||
|
|
||||||
mBatteryStatusFeatureProvider = FeatureFactory.getFactory(context)
|
|
||||||
.getBatteryStatusFeatureProvider(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -94,42 +88,20 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
|
|||||||
return getDashboardLabel(mContext, mBatteryInfo);
|
return getDashboardLabel(mContext, mBatteryInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CharSequence getDashboardLabel(Context context, BatteryInfo info) {
|
static CharSequence getDashboardLabel(Context context, BatteryInfo info) {
|
||||||
if (info == null || context == null) {
|
if (info == null || context == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharSequence label;
|
CharSequence label;
|
||||||
if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)
|
|
||||||
|| mBatteryStatusLabel == null) {
|
|
||||||
label = generateLabel(info);
|
|
||||||
} else {
|
|
||||||
label = mBatteryStatusLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CharSequence generateLabel(BatteryInfo info) {
|
|
||||||
if (!info.discharging && info.chargeLabel != null) {
|
if (!info.discharging && info.chargeLabel != null) {
|
||||||
return info.chargeLabel;
|
label = info.chargeLabel;
|
||||||
} else if (info.remainingLabel == null) {
|
} else if (info.remainingLabel == null) {
|
||||||
return info.batteryPercentString;
|
label = info.batteryPercentString;
|
||||||
} else {
|
} else {
|
||||||
return mContext.getString(R.string.power_remaining_settings_home_page,
|
label = context.getString(R.string.power_remaining_settings_home_page,
|
||||||
info.batteryPercentString,
|
info.batteryPercentString,
|
||||||
info.remainingLabel);
|
info.remainingLabel);
|
||||||
}
|
}
|
||||||
}
|
return label;
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback which receives text for the label.
|
|
||||||
*/
|
|
||||||
public void updateBatteryStatus(String label, BatteryInfo info) {
|
|
||||||
mBatteryStatusLabel = (label != null) ? label : generateLabel(info).toString();
|
|
||||||
|
|
||||||
if (mPreference != null) {
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||||
|
import static com.android.settings.fuelgauge.TopLevelBatteryPreferenceController.getDashboardLabel;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -68,16 +69,14 @@ public class TopLevelBatteryPreferenceControllerTest {
|
|||||||
public void getDashboardLabel_returnsCorrectLabel() {
|
public void getDashboardLabel_returnsCorrectLabel() {
|
||||||
BatteryInfo info = new BatteryInfo();
|
BatteryInfo info = new BatteryInfo();
|
||||||
info.batteryPercentString = "3%";
|
info.batteryPercentString = "3%";
|
||||||
assertThat(mController.getDashboardLabel(mContext, info))
|
assertThat(getDashboardLabel(mContext, info)).isEqualTo(info.batteryPercentString);
|
||||||
.isEqualTo(info.batteryPercentString);
|
|
||||||
|
|
||||||
info.remainingLabel = "Phone will shut down soon";
|
info.remainingLabel = "Phone will shut down soon";
|
||||||
assertThat(mController.getDashboardLabel(mContext, info))
|
assertThat(getDashboardLabel(mContext, info)).isEqualTo("3% - Phone will shut down soon");
|
||||||
.isEqualTo("3% - Phone will shut down soon");
|
|
||||||
|
|
||||||
info.discharging = false;
|
info.discharging = false;
|
||||||
info.chargeLabel = "5% - charging";
|
info.chargeLabel = "5% - charging";
|
||||||
assertThat(mController.getDashboardLabel(mContext, info)).isEqualTo("5% - charging");
|
assertThat(getDashboardLabel(mContext, info)).isEqualTo("5% - charging");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user