Add BatteryStatusFeatureProvider
This allows the battery header status line to be overridden.
Bug: 150239363
Test: implemented provider and changed status line text
Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Change-Id: I05bedbee641f087de5ee1b25a00724ce2de51f87
Merged-In: I05bedbee641f087de5ee1b25a00724ce2de51f87
diff --git a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
index bfa43d1..468d8c5 100644
--- a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
@@ -34,6 +34,7 @@
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.widget.EntityHeaderController;
import com.android.settingslib.Utils;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -50,6 +51,8 @@
static final String KEY_BATTERY_HEADER = "battery_header";
@VisibleForTesting
+ BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
+ @VisibleForTesting
BatteryMeterView mBatteryMeterView;
@VisibleForTesting
TextView mBatteryPercentText;
@@ -66,6 +69,8 @@
public BatteryHeaderPreferenceController(Context context, String key) {
super(context, key);
mPowerManager = context.getSystemService(PowerManager.class);
+ mBatteryStatusFeatureProvider = FeatureFactory.getFactory(context)
+ .getBatteryStatusFeatureProvider(context);
}
public void setActivity(Activity activity) {
@@ -107,10 +112,12 @@
public void updateHeaderPreference(BatteryInfo info) {
mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel));
- if (info.remainingLabel == null) {
- mSummary1.setText(info.statusLabel);
- } else {
- mSummary1.setText(info.remainingLabel);
+ if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) {
+ if (info.remainingLabel == null) {
+ mSummary1.setText(info.statusLabel);
+ } else {
+ mSummary1.setText(info.remainingLabel);
+ }
}
mBatteryMeterView.setBatteryLevel(info.batteryLevel);
@@ -118,6 +125,13 @@
mBatteryMeterView.setPowerSave(mPowerManager.isPowerSaveMode());
}
+ /**
+ * Callback which receives text for the summary line.
+ */
+ public void updateBatteryStatus(String statusLabel) {
+ mSummary1.setText(statusLabel);
+ }
+
public void quickUpdateHeaderPreference() {
Intent batteryBroadcast = mContext.registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
diff --git a/src/com/android/settings/fuelgauge/BatteryStatusFeatureProvider.java b/src/com/android/settings/fuelgauge/BatteryStatusFeatureProvider.java
new file mode 100644
index 0000000..c3fc247
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryStatusFeatureProvider.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * Feature Provider used to retrieve battery status
+ */
+public interface BatteryStatusFeatureProvider {
+
+ /**
+ * Trigger a battery status update; return false if built-in status should be used.
+ */
+ boolean triggerBatteryStatusUpdate(
+ BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info);
+}
diff --git a/src/com/android/settings/fuelgauge/BatteryStatusFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/BatteryStatusFeatureProviderImpl.java
new file mode 100644
index 0000000..47d376d
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryStatusFeatureProviderImpl.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import android.content.Context;
+
+/**
+ * Used to override battery status string in Battery Header.
+ */
+public class BatteryStatusFeatureProviderImpl implements BatteryStatusFeatureProvider {
+
+ protected Context mContext;
+
+ public BatteryStatusFeatureProviderImpl(Context context) {
+ mContext = context.getApplicationContext();
+ }
+
+ @Override
+ public boolean triggerBatteryStatusUpdate(
+ BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info) {
+ return false;
+ }
+}
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index afbce09..b9aa68a 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -31,6 +31,7 @@
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
+import com.android.settings.fuelgauge.BatteryStatusFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.gestures.AssistGestureFeatureProvider;
import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider;
@@ -103,6 +104,12 @@
public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context);
+ /**
+ * Retrieve implementation for Battery Status feature.
+ */
+ public abstract BatteryStatusFeatureProvider getBatteryStatusFeatureProvider(
+ Context context);
+
public abstract DashboardFeatureProvider getDashboardFeatureProvider(Context context);
public abstract DockUpdaterFeatureProvider getDockUpdaterFeatureProvider();
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index 29beb5b..d4d396f 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -42,6 +42,8 @@
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl;
+import com.android.settings.fuelgauge.BatteryStatusFeatureProvider;
+import com.android.settings.fuelgauge.BatteryStatusFeatureProviderImpl;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProviderImpl;
import com.android.settings.gestures.AssistGestureFeatureProvider;
@@ -78,6 +80,7 @@
private SecurityFeatureProvider mSecurityFeatureProvider;
private SuggestionFeatureProvider mSuggestionFeatureProvider;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
+ private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
private AssistGestureFeatureProvider mAssistGestureFeatureProvider;
private UserFeatureProvider mUserFeatureProvider;
private SlicesFeatureProvider mSlicesFeatureProvider;
@@ -111,6 +114,15 @@
}
@Override
+ public BatteryStatusFeatureProvider getBatteryStatusFeatureProvider(Context context) {
+ if (mBatteryStatusFeatureProvider == null) {
+ mBatteryStatusFeatureProvider = new BatteryStatusFeatureProviderImpl(
+ context.getApplicationContext());
+ }
+ return mBatteryStatusFeatureProvider;
+ }
+
+ @Override
public DashboardFeatureProvider getDashboardFeatureProvider(Context context) {
if (mDashboardFeatureProvider == null) {
mDashboardFeatureProvider = new DashboardFeatureProviderImpl(
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
index b6c4fb7..2c68269 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -29,6 +29,7 @@
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
+import com.android.settings.fuelgauge.BatteryStatusFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.gestures.AssistGestureFeatureProvider;
import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider;
@@ -54,6 +55,7 @@
public final SupportFeatureProvider supportFeatureProvider;
public final MetricsFeatureProvider metricsFeatureProvider;
+ public final BatteryStatusFeatureProvider batteryStatusFeatureProvider;
public final PowerUsageFeatureProvider powerUsageFeatureProvider;
public final DashboardFeatureProvider dashboardFeatureProvider;
public final DockUpdaterFeatureProvider dockUpdaterFeatureProvider;
@@ -98,6 +100,7 @@
public FakeFeatureFactory() {
supportFeatureProvider = mock(SupportFeatureProvider.class);
metricsFeatureProvider = mock(MetricsFeatureProvider.class);
+ batteryStatusFeatureProvider = mock(BatteryStatusFeatureProvider.class);
powerUsageFeatureProvider = mock(PowerUsageFeatureProvider.class);
dashboardFeatureProvider = mock(DashboardFeatureProvider.class);
dockUpdaterFeatureProvider = mock(DockUpdaterFeatureProvider.class);
@@ -135,6 +138,11 @@
}
@Override
+ public BatteryStatusFeatureProvider getBatteryStatusFeatureProvider(Context context) {
+ return batteryStatusFeatureProvider;
+ }
+
+ @Override
public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) {
return powerUsageFeatureProvider;
}