Merge "Fix enhanced estimate discharge text showing while charging" into oc-dr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4d3b534325
@@ -35,8 +35,9 @@ public class BatteryHistoryPreference extends Preference {
|
|||||||
|
|
||||||
private CharSequence mSummary;
|
private CharSequence mSummary;
|
||||||
private TextView mSummaryView;
|
private TextView mSummaryView;
|
||||||
private boolean hideSummary;
|
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean hideSummary;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
BatteryInfo mBatteryInfo;
|
BatteryInfo mBatteryInfo;
|
||||||
|
|
||||||
@@ -56,8 +57,10 @@ public class BatteryHistoryPreference extends Preference {
|
|||||||
public void setBottomSummary(CharSequence text) {
|
public void setBottomSummary(CharSequence text) {
|
||||||
mSummary = text;
|
mSummary = text;
|
||||||
if (mSummaryView != null) {
|
if (mSummaryView != null) {
|
||||||
|
mSummaryView.setVisibility(View.VISIBLE);
|
||||||
mSummaryView.setText(mSummary);
|
mSummaryView.setText(mSummary);
|
||||||
}
|
}
|
||||||
|
hideSummary = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideBottomSummary() {
|
public void hideBottomSummary() {
|
||||||
|
@@ -15,7 +15,10 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.BatteryManager;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -171,7 +174,11 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
|||||||
updatePreference(mHistPref);
|
updatePreference(mHistPref);
|
||||||
refreshPowerUsageDataList(mStatsHelper, mUsageListGroup);
|
refreshPowerUsageDataList(mStatsHelper, mUsageListGroup);
|
||||||
|
|
||||||
if (mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(context)) {
|
Intent batteryIntent =
|
||||||
|
context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
|
final boolean plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) != 0;
|
||||||
|
|
||||||
|
if (mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(context) && !plugged) {
|
||||||
mHistPref.setBottomSummary(
|
mHistPref.setBottomSummary(
|
||||||
mPowerUsageFeatureProvider.getAdvancedUsageScreenInfoString());
|
mPowerUsageFeatureProvider.getAdvancedUsageScreenInfoString());
|
||||||
} else {
|
} else {
|
||||||
|
@@ -97,6 +97,7 @@ public class BatteryHistoryPreferenceTest {
|
|||||||
TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
|
TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
|
||||||
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
|
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
assertThat(view.getText()).isEqualTo(TEST_STRING);
|
assertThat(view.getText()).isEqualTo(TEST_STRING);
|
||||||
|
assertThat(mBatteryHistoryPreference.hideSummary).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -107,5 +108,6 @@ public class BatteryHistoryPreferenceTest {
|
|||||||
TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
|
TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
|
||||||
assertThat(view.getVisibility()).isEqualTo(View.GONE);
|
assertThat(view.getVisibility()).isEqualTo(View.GONE);
|
||||||
assertThat(view.getText()).isEqualTo("");
|
assertThat(view.getText()).isEqualTo("");
|
||||||
|
assertThat(mBatteryHistoryPreference.hideSummary).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import android.os.BatteryManager;
|
|||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
import com.android.internal.os.BatteryStatsHelper;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.BatteryTestUtils;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -64,12 +65,7 @@ public class BatteryInfoLoaderTest {
|
|||||||
.setupForTest(mContext)
|
.setupForTest(mContext)
|
||||||
.getPowerUsageFeatureProvider(mContext);
|
.getPowerUsageFeatureProvider(mContext);
|
||||||
|
|
||||||
mDisChargingBatteryBroadcast = new Intent();
|
mDisChargingBatteryBroadcast = BatteryTestUtils.getDischargingIntent();
|
||||||
mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_PLUGGED, 0);
|
|
||||||
mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 0);
|
|
||||||
mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_SCALE, 100);
|
|
||||||
mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_STATUS,
|
|
||||||
BatteryManager.BATTERY_STATUS_FULL);
|
|
||||||
|
|
||||||
doReturn(mContext).when(mContext).getApplicationContext();
|
doReturn(mContext).when(mContext).getApplicationContext();
|
||||||
when(mStats.computeBatteryTimeRemaining(anyLong())).thenReturn(TEST_TIME_REMAINING);
|
when(mStats.computeBatteryTimeRemaining(anyLong())).thenReturn(TEST_TIME_REMAINING);
|
||||||
|
@@ -39,6 +39,7 @@ import android.util.SparseIntArray;
|
|||||||
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.graph.UsageView;
|
import com.android.settings.graph.UsageView;
|
||||||
|
import com.android.settings.testutils.BatteryTestUtils;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
@@ -63,6 +64,7 @@ public class BatteryInfoTest {
|
|||||||
private static final String STATUS_FULL = "Full";
|
private static final String STATUS_FULL = "Full";
|
||||||
private static final String STATUS_CHARGING_NO_TIME = "50% - charging";
|
private static final String STATUS_CHARGING_NO_TIME = "50% - charging";
|
||||||
private static final String STATUS_CHARGING_TIME = "50% - 0m until fully charged";
|
private static final String STATUS_CHARGING_TIME = "50% - 0m until fully charged";
|
||||||
|
private static final String STATUS_NOT_CHARGING = "Not charging";
|
||||||
private static final int PLUGGED_IN = 1;
|
private static final int PLUGGED_IN = 1;
|
||||||
private static final long REMAINING_TIME_NULL = -1;
|
private static final long REMAINING_TIME_NULL = -1;
|
||||||
private static final long REMAINING_TIME = 2;
|
private static final long REMAINING_TIME = 2;
|
||||||
@@ -87,20 +89,9 @@ public class BatteryInfoTest {
|
|||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
|
mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
|
||||||
|
|
||||||
mDisChargingBatteryBroadcast = new Intent();
|
mDisChargingBatteryBroadcast = BatteryTestUtils.getDischargingIntent();
|
||||||
mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_PLUGGED, 0);
|
|
||||||
mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 0);
|
|
||||||
mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_SCALE, 100);
|
|
||||||
mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_STATUS,
|
|
||||||
BatteryManager.BATTERY_STATUS_FULL);
|
|
||||||
|
|
||||||
mChargingBatteryBroadcast = new Intent();
|
mChargingBatteryBroadcast = BatteryTestUtils.getChargingIntent();
|
||||||
mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_PLUGGED,
|
|
||||||
BatteryManager.BATTERY_PLUGGED_AC);
|
|
||||||
mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 50);
|
|
||||||
mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_SCALE, 100);
|
|
||||||
mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_STATUS,
|
|
||||||
BatteryManager.BATTERY_STATUS_UNKNOWN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -110,7 +101,7 @@ public class BatteryInfoTest {
|
|||||||
mDisChargingBatteryBroadcast, mBatteryStats, SystemClock.elapsedRealtime() * 1000,
|
mDisChargingBatteryBroadcast, mBatteryStats, SystemClock.elapsedRealtime() * 1000,
|
||||||
true /* shortString */);
|
true /* shortString */);
|
||||||
|
|
||||||
assertThat(info.statusLabel).isEqualTo(STATUS_FULL);
|
assertThat(info.statusLabel).isEqualTo(STATUS_NOT_CHARGING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -20,6 +20,7 @@ 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.Matchers.isNull;
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
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.never;
|
||||||
@@ -28,16 +29,19 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v7.preference.PreferenceCategory;
|
import android.support.v7.preference.PreferenceCategory;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
import com.android.internal.os.BatterySipper;
|
import com.android.internal.os.BatterySipper;
|
||||||
import com.android.internal.os.BatterySipper.DrainType;
|
import com.android.internal.os.BatterySipper.DrainType;
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
import com.android.internal.os.BatteryStatsHelper;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.testutils.BatteryTestUtils;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
@@ -90,11 +94,12 @@ public class PowerUsageAdvancedTest {
|
|||||||
private PowerUsageAdvanced mPowerUsageAdvanced;
|
private PowerUsageAdvanced mPowerUsageAdvanced;
|
||||||
private PowerUsageData mPowerUsageData;
|
private PowerUsageData mPowerUsageData;
|
||||||
private Context mShadowContext;
|
private Context mShadowContext;
|
||||||
|
private Intent mDischargingBatteryIntent;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mShadowContext = RuntimeEnvironment.application;
|
mShadowContext = spy(RuntimeEnvironment.application);
|
||||||
mPowerUsageAdvanced = spy(new PowerUsageAdvanced());
|
mPowerUsageAdvanced = spy(new PowerUsageAdvanced());
|
||||||
|
|
||||||
List<BatterySipper> batterySippers = new ArrayList<>();
|
List<BatterySipper> batterySippers = new ArrayList<>();
|
||||||
@@ -107,6 +112,8 @@ public class PowerUsageAdvancedTest {
|
|||||||
batterySippers.add(new BatterySipper(DrainType.WIFI, new FakeUid(FAKE_UID_1),
|
batterySippers.add(new BatterySipper(DrainType.WIFI, new FakeUid(FAKE_UID_1),
|
||||||
TYPE_WIFI_USAGE));
|
TYPE_WIFI_USAGE));
|
||||||
|
|
||||||
|
mDischargingBatteryIntent = BatteryTestUtils.getDischargingIntent();
|
||||||
|
doReturn(mDischargingBatteryIntent).when(mShadowContext).registerReceiver(any(), any());
|
||||||
when(mBatteryStatsHelper.getStats().getDischargeAmount(anyInt())).thenReturn(
|
when(mBatteryStatsHelper.getStats().getDischargeAmount(anyInt())).thenReturn(
|
||||||
DISCHARGE_AMOUNT);
|
DISCHARGE_AMOUNT);
|
||||||
when(mBatteryStatsHelper.getUsageList()).thenReturn(batterySippers);
|
when(mBatteryStatsHelper.getUsageList()).thenReturn(batterySippers);
|
||||||
|
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.testutils;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.BatteryManager;
|
||||||
|
|
||||||
|
public class BatteryTestUtils {
|
||||||
|
|
||||||
|
public static Intent getChargingIntent() {
|
||||||
|
return getCustomBatteryIntent(
|
||||||
|
BatteryManager.BATTERY_PLUGGED_AC,
|
||||||
|
50 /* level */,
|
||||||
|
100 /* scale */,
|
||||||
|
BatteryManager.BATTERY_STATUS_CHARGING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Intent getDischargingIntent() {
|
||||||
|
return getCustomBatteryIntent(
|
||||||
|
0 /* plugged */,
|
||||||
|
10 /* level */,
|
||||||
|
100 /* scale */,
|
||||||
|
BatteryManager.BATTERY_STATUS_DISCHARGING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged);
|
||||||
|
intent.putExtra(BatteryManager.EXTRA_LEVEL, level);
|
||||||
|
intent.putExtra(BatteryManager.EXTRA_SCALE, scale);
|
||||||
|
intent.putExtra(BatteryManager.EXTRA_STATUS, status);
|
||||||
|
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user