Add info string to advanced battery usage page
This CL adds an FYI string under the battery graph to let users know that their current estimate is coming from the enhanced estimate provider when it is enabled. Test: Robotests Bug: 38399654 Change-Id: If5cd622ef0251a5a483cef870fc2261369e14845
This commit is contained in:
@@ -43,4 +43,11 @@
|
|||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
settings:textColor="?android:attr/textColorSecondary" />
|
settings:textColor="?android:attr/textColorSecondary" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/bottom_summary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -21,6 +21,7 @@ import android.support.annotation.VisibleForTesting;
|
|||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceViewHolder;
|
import android.support.v7.preference.PreferenceViewHolder;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
import com.android.internal.os.BatteryStatsHelper;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -32,6 +33,10 @@ import com.android.settings.graph.UsageView;
|
|||||||
*/
|
*/
|
||||||
public class BatteryHistoryPreference extends Preference {
|
public class BatteryHistoryPreference extends Preference {
|
||||||
|
|
||||||
|
private CharSequence mSummary;
|
||||||
|
private TextView mSummaryView;
|
||||||
|
private boolean hideSummary;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
BatteryInfo mBatteryInfo;
|
BatteryInfo mBatteryInfo;
|
||||||
|
|
||||||
@@ -48,6 +53,20 @@ public class BatteryHistoryPreference extends Preference {
|
|||||||
}, batteryStats.getStats(), false);
|
}, batteryStats.getStats(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBottomSummary(CharSequence text) {
|
||||||
|
mSummary = text;
|
||||||
|
if (mSummaryView != null) {
|
||||||
|
mSummaryView.setText(mSummary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideBottomSummary() {
|
||||||
|
if (mSummaryView != null) {
|
||||||
|
mSummaryView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
hideSummary = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||||
super.onBindViewHolder(view);
|
super.onBindViewHolder(view);
|
||||||
@@ -56,6 +75,13 @@ public class BatteryHistoryPreference extends Preference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
((TextView) view.findViewById(R.id.charge)).setText(mBatteryInfo.batteryPercentString);
|
((TextView) view.findViewById(R.id.charge)).setText(mBatteryInfo.batteryPercentString);
|
||||||
|
mSummaryView = (TextView) view.findViewById(R.id.bottom_summary);
|
||||||
|
if (mSummary != null) {
|
||||||
|
mSummaryView.setText(mSummary);
|
||||||
|
}
|
||||||
|
if (hideSummary) {
|
||||||
|
mSummaryView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
UsageView usageView = (UsageView) view.findViewById(R.id.battery_usage);
|
UsageView usageView = (UsageView) view.findViewById(R.id.battery_usage);
|
||||||
usageView.findViewById(R.id.label_group).setAlpha(.7f);
|
usageView.findViewById(R.id.label_group).setAlpha(.7f);
|
||||||
mBatteryInfo.bindHistory(usageView);
|
mBatteryInfo.bindHistory(usageView);
|
||||||
|
@@ -69,9 +69,9 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
|||||||
UsageType.UNACCOUNTED,
|
UsageType.UNACCOUNTED,
|
||||||
UsageType.OVERCOUNTED};
|
UsageType.OVERCOUNTED};
|
||||||
|
|
||||||
|
@VisibleForTesting BatteryHistoryPreference mHistPref;
|
||||||
|
@VisibleForTesting PreferenceGroup mUsageListGroup;
|
||||||
private BatteryUtils mBatteryUtils;
|
private BatteryUtils mBatteryUtils;
|
||||||
private BatteryHistoryPreference mHistPref;
|
|
||||||
private PreferenceGroup mUsageListGroup;
|
|
||||||
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
@@ -170,6 +170,14 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
|||||||
}
|
}
|
||||||
updatePreference(mHistPref);
|
updatePreference(mHistPref);
|
||||||
refreshPowerUsageDataList(mStatsHelper, mUsageListGroup);
|
refreshPowerUsageDataList(mStatsHelper, mUsageListGroup);
|
||||||
|
|
||||||
|
if (mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(context)) {
|
||||||
|
mHistPref.setBottomSummary(
|
||||||
|
mPowerUsageFeatureProvider.getAdvancedUsageScreenInfoString());
|
||||||
|
} else {
|
||||||
|
mHistPref.hideBottomSummary();
|
||||||
|
}
|
||||||
|
|
||||||
BatteryEntry.startRequestQueue();
|
BatteryEntry.startRequestQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -113,4 +113,10 @@ public interface PowerUsageFeatureProvider {
|
|||||||
* @return A string containing the estimate and a label indicating it is a normal estimate
|
* @return A string containing the estimate and a label indicating it is a normal estimate
|
||||||
*/
|
*/
|
||||||
String getOldEstimateDebugString(String timeRemaining);
|
String getOldEstimateDebugString(String timeRemaining);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the string to show in the advanced usage battery page when enhanced estimates are
|
||||||
|
* enabled. This string notifies users that the estimate is using enhanced prediction.
|
||||||
|
*/
|
||||||
|
String getAdvancedUsageScreenInfoString();
|
||||||
}
|
}
|
||||||
|
@@ -132,4 +132,9 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
|||||||
public String getOldEstimateDebugString(String timeRemaining) {
|
public String getOldEstimateDebugString(String timeRemaining) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAdvancedUsageScreenInfoString() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.fuelgauge;
|
package com.android.settings.fuelgauge;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.nullable;
|
import static org.mockito.ArgumentMatchers.nullable;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -49,6 +50,7 @@ import org.robolectric.annotation.Config;
|
|||||||
SettingsShadowResources.SettingsShadowTheme.class
|
SettingsShadowResources.SettingsShadowTheme.class
|
||||||
})
|
})
|
||||||
public class BatteryHistoryPreferenceTest {
|
public class BatteryHistoryPreferenceTest {
|
||||||
|
public static final String TEST_STRING = "test";
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceViewHolder mViewHolder;
|
private PreferenceViewHolder mViewHolder;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -86,4 +88,24 @@ public class BatteryHistoryPreferenceTest {
|
|||||||
verify(mTextView).setText(nullable(String.class));
|
verify(mTextView).setText(nullable(String.class));
|
||||||
verify(mBatteryInfo).bindHistory(mUsageView);
|
verify(mBatteryInfo).bindHistory(mUsageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetBottomSummary_updatesBottomSummaryTextIfSet() {
|
||||||
|
mBatteryHistoryPreference.setBottomSummary(TEST_STRING);
|
||||||
|
mBatteryHistoryPreference.onBindViewHolder(mViewHolder);
|
||||||
|
|
||||||
|
TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
|
||||||
|
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
|
assertThat(view.getText()).isEqualTo(TEST_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetBottomSummary_leavesBottomSummaryTextBlankIfNotSet() {
|
||||||
|
mBatteryHistoryPreference.hideBottomSummary();
|
||||||
|
mBatteryHistoryPreference.onBindViewHolder(mViewHolder);
|
||||||
|
|
||||||
|
TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
|
||||||
|
assertThat(view.getVisibility()).isEqualTo(View.GONE);
|
||||||
|
assertThat(view.getText()).isEqualTo("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,9 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -81,6 +83,10 @@ public class PowerUsageAdvancedTest {
|
|||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
@Mock
|
@Mock
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
|
@Mock
|
||||||
|
private BatteryHistoryPreference mHistPref;
|
||||||
|
@Mock
|
||||||
|
private PreferenceGroup mUsageListGroup;
|
||||||
private PowerUsageAdvanced mPowerUsageAdvanced;
|
private PowerUsageAdvanced mPowerUsageAdvanced;
|
||||||
private PowerUsageData mPowerUsageData;
|
private PowerUsageData mPowerUsageData;
|
||||||
private Context mShadowContext;
|
private Context mShadowContext;
|
||||||
@@ -352,4 +358,26 @@ public class PowerUsageAdvancedTest {
|
|||||||
assertThat(mPowerUsageAdvanced.calculateHiddenPower(powerUsageDataList)).isWithin(
|
assertThat(mPowerUsageAdvanced.calculateHiddenPower(powerUsageDataList)).isWithin(
|
||||||
PRECISION).of(unaccountedPower);
|
PRECISION).of(unaccountedPower);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRefreshUi_addsSubtextWhenAppropriate() {
|
||||||
|
// Mock out all the battery stuff
|
||||||
|
mPowerUsageAdvanced.mHistPref = mHistPref;
|
||||||
|
mPowerUsageAdvanced.mStatsHelper = mBatteryStatsHelper;
|
||||||
|
doReturn(new ArrayList<PowerUsageData>())
|
||||||
|
.when(mPowerUsageAdvanced).parsePowerUsageData(any());
|
||||||
|
doReturn("").when(mPowerUsageAdvanced).getString(anyInt());
|
||||||
|
mPowerUsageAdvanced.mUsageListGroup = mUsageListGroup;
|
||||||
|
|
||||||
|
// refresh the ui and check that text was not updated when enhanced prediction disabled
|
||||||
|
when(mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(any()))
|
||||||
|
.thenReturn(false);
|
||||||
|
mPowerUsageAdvanced.refreshUi();
|
||||||
|
verify(mHistPref, never()).setBottomSummary(any());
|
||||||
|
|
||||||
|
// refresh the ui and check that text was updated when enhanced prediction enabled
|
||||||
|
when(mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(any())).thenReturn(true);
|
||||||
|
mPowerUsageAdvanced.refreshUi();
|
||||||
|
verify(mHistPref, atLeastOnce()).setBottomSummary(any());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user