Merge "Transition BatteryInfo and BatteryUtils to BatteryUsageStats API" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
38e0dae439
@@ -19,23 +19,23 @@ package com.android.settings.fuelgauge;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.BatteryStatsManager;
|
||||
import android.os.BatteryUsageStats;
|
||||
import android.os.BatteryUsageStatsQuery;
|
||||
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.settings.testutils.BatteryTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@@ -46,10 +46,10 @@ public class BatteryInfoLoaderTest {
|
||||
|
||||
private static final long TEST_TIME_REMAINING = 1000L;
|
||||
|
||||
@Mock (answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private BatteryStatsHelper mHelper;
|
||||
@Mock (answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private BatteryStats mStats;
|
||||
@Mock
|
||||
private BatteryStatsManager mBatteryStatsManager;
|
||||
@Mock
|
||||
private BatteryUsageStats mBatteryUsageStats;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -60,8 +60,11 @@ public class BatteryInfoLoaderTest {
|
||||
FakeFeatureFactory.setupForTest().getPowerUsageFeatureProvider(mContext);
|
||||
|
||||
doReturn(mContext).when(mContext).getApplicationContext();
|
||||
when(mStats.computeBatteryTimeRemaining(anyLong())).thenReturn(TEST_TIME_REMAINING);
|
||||
doReturn(mStats).when(mHelper).getStats();
|
||||
when(mContext.getSystemService(eq(Context.BATTERY_STATS_SERVICE)))
|
||||
.thenReturn(mBatteryStatsManager);
|
||||
when(mBatteryUsageStats.getBatteryTimeRemainingMs()).thenReturn(TEST_TIME_REMAINING);
|
||||
when(mBatteryStatsManager.getBatteryUsageStats(any(BatteryUsageStatsQuery.class)))
|
||||
.thenReturn(mBatteryUsageStats);
|
||||
|
||||
final Intent dischargingBatteryBroadcast = BatteryTestUtils.getDischargingIntent();
|
||||
doReturn(dischargingBatteryBroadcast).when(mContext).registerReceiver(any(), any());
|
||||
@@ -69,8 +72,8 @@ public class BatteryInfoLoaderTest {
|
||||
|
||||
@Test
|
||||
public void test_loadInBackground_dischargingOldEstimate_dischargingLabelNotNull() {
|
||||
BatteryInfoLoader loader = new BatteryInfoLoader(mContext, mHelper);
|
||||
loader.batteryUtils = new BatteryUtils(mContext);
|
||||
BatteryInfoLoader loader = new BatteryInfoLoader(mContext);
|
||||
loader.mBatteryUtils = new BatteryUtils(mContext);
|
||||
|
||||
BatteryInfo info = loader.loadInBackground();
|
||||
|
||||
|
@@ -34,9 +34,11 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.BatteryUsageStats;
|
||||
import android.os.SystemClock;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.android.internal.os.BatteryStatsHistoryIterator;
|
||||
import com.android.settings.testutils.BatteryTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.widget.UsageView;
|
||||
@@ -46,7 +48,6 @@ import com.android.settingslib.fuelgauge.Estimate;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@@ -83,9 +84,8 @@ public class BatteryInfoTest {
|
||||
private Intent mChargingBatteryBroadcast;
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private BatteryStats mBatteryStats;
|
||||
@Mock
|
||||
private BatteryUsageStats mBatteryUsageStats;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -100,9 +100,10 @@ public class BatteryInfoTest {
|
||||
|
||||
@Test
|
||||
public void testGetBatteryInfo_hasStatusLabel() {
|
||||
doReturn(REMAINING_TIME_NULL).when(mBatteryStats).computeBatteryTimeRemaining(anyLong());
|
||||
doReturn(REMAINING_TIME_NULL).when(mBatteryUsageStats).getBatteryTimeRemainingMs();
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext,
|
||||
mDisChargingBatteryBroadcast, mBatteryStats, SystemClock.elapsedRealtime() * 1000,
|
||||
mDisChargingBatteryBroadcast, mBatteryUsageStats,
|
||||
SystemClock.elapsedRealtime() * 1000,
|
||||
true /* shortString */);
|
||||
|
||||
assertThat(info.statusLabel).isEqualTo(STATUS_NOT_CHARGING);
|
||||
@@ -110,28 +111,28 @@ public class BatteryInfoTest {
|
||||
|
||||
@Test
|
||||
public void testGetBatteryInfo_doNotShowChargingMethod_hasRemainingTime() {
|
||||
doReturn(REMAINING_TIME).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
|
||||
doReturn(REMAINING_TIME).when(mBatteryUsageStats).getChargeTimeRemainingMs();
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext, mChargingBatteryBroadcast,
|
||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */);
|
||||
mBatteryUsageStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */);
|
||||
|
||||
assertThat(info.chargeLabel.toString()).isEqualTo(STATUS_CHARGING_TIME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBatteryInfo_doNotShowChargingMethod_noRemainingTime() {
|
||||
doReturn(REMAINING_TIME_NULL).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
|
||||
doReturn(REMAINING_TIME_NULL).when(mBatteryUsageStats).getChargeTimeRemainingMs();
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext, mChargingBatteryBroadcast,
|
||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */);
|
||||
mBatteryUsageStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */);
|
||||
|
||||
assertThat(info.chargeLabel.toString()).isEqualTo(STATUS_CHARGING_NO_TIME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBatteryInfo_pluggedInUsingShortString_usesCorrectData() {
|
||||
doReturn(TEST_CHARGE_TIME_REMAINING).when(mBatteryStats).computeChargeTimeRemaining(
|
||||
anyLong());
|
||||
doReturn(TEST_CHARGE_TIME_REMAINING / 1000)
|
||||
.when(mBatteryUsageStats).getChargeTimeRemainingMs();
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext, mChargingBatteryBroadcast,
|
||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, true /* shortString */);
|
||||
mBatteryUsageStats, SystemClock.elapsedRealtime() * 1000, true /* shortString */);
|
||||
|
||||
assertThat(info.discharging).isEqualTo(false);
|
||||
assertThat(info.chargeLabel.toString()).isEqualTo("50% - 1 min until charged");
|
||||
@@ -143,10 +144,10 @@ public class BatteryInfoTest {
|
||||
true /* isBasedOnUsage */,
|
||||
1000 /* averageDischargeTime */);
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
false /* shortString */);
|
||||
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
true /* shortString */);
|
||||
|
||||
// We only add special mention for the long string
|
||||
@@ -163,10 +164,10 @@ public class BatteryInfoTest {
|
||||
true /* isBasedOnUsage */,
|
||||
1000 /* averageDischargeTime */);
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
false /* shortString */);
|
||||
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
true /* shortString */);
|
||||
|
||||
// These should be identical in either case
|
||||
@@ -183,7 +184,7 @@ public class BatteryInfoTest {
|
||||
true /* isBasedOnUsage */,
|
||||
1000 /* averageDischargeTime */);
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
false /* shortString */);
|
||||
|
||||
assertThat(info.suggestionLabel).doesNotContain(BATTERY_RUN_OUT_PREFIX);
|
||||
@@ -196,7 +197,7 @@ public class BatteryInfoTest {
|
||||
true /* isBasedOnUsage */,
|
||||
1000 /* averageDischargeTime */);
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
false /* shortString */);
|
||||
|
||||
// Check that strings are showing less than 15 minutes remaining regardless of exact time.
|
||||
@@ -211,10 +212,10 @@ public class BatteryInfoTest {
|
||||
@Test
|
||||
public void testGetBatteryInfo_basedOnUsageFalse_usesDefaultString() {
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
false /* shortString */);
|
||||
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
true /* shortString */);
|
||||
|
||||
assertThat(info.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
|
||||
@@ -223,12 +224,11 @@ public class BatteryInfoTest {
|
||||
|
||||
@Test
|
||||
public void testGetBatteryInfo_charging_usesChargeTime() {
|
||||
doReturn(TEST_CHARGE_TIME_REMAINING)
|
||||
.when(mBatteryStats)
|
||||
.computeChargeTimeRemaining(anyLong());
|
||||
doReturn(TEST_CHARGE_TIME_REMAINING / 1000)
|
||||
.when(mBatteryUsageStats).getChargeTimeRemainingMs();
|
||||
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
|
||||
mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
false /* shortString */);
|
||||
assertThat(info.remainingTimeUs).isEqualTo(TEST_CHARGE_TIME_REMAINING);
|
||||
assertThat(info.remainingLabel.toString())
|
||||
@@ -240,7 +240,7 @@ public class BatteryInfoTest {
|
||||
mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 100);
|
||||
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
|
||||
mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
false /* shortString */);
|
||||
|
||||
assertThat(info.chargeLabel).isEqualTo("100%");
|
||||
@@ -249,13 +249,13 @@ public class BatteryInfoTest {
|
||||
@Test
|
||||
public void testGetBatteryInfo_chargingWithOverheated_updateChargeLabel() {
|
||||
doReturn(TEST_CHARGE_TIME_REMAINING)
|
||||
.when(mBatteryStats)
|
||||
.computeChargeTimeRemaining(anyLong());
|
||||
.when(mBatteryUsageStats)
|
||||
.getChargeTimeRemainingMs();
|
||||
mChargingBatteryBroadcast
|
||||
.putExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_OVERHEAT);
|
||||
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
|
||||
mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||
false /* shortString */);
|
||||
|
||||
assertThat(info.isOverheated).isTrue();
|
||||
@@ -264,28 +264,29 @@ public class BatteryInfoTest {
|
||||
|
||||
// Make our battery stats return a sequence of battery events.
|
||||
private void mockBatteryStatsHistory() {
|
||||
// Mock out new data every time start...Locked is called.
|
||||
// Mock out new data every time iterateBatteryStatsHistory is called.
|
||||
doAnswer(invocation -> {
|
||||
doAnswer(new Answer() {
|
||||
private int count = 0;
|
||||
private long[] times = {1000, 1500, 2000};
|
||||
private byte[] levels = {99, 98, 97};
|
||||
BatteryStatsHistoryIterator iterator = mock(BatteryStatsHistoryIterator.class);
|
||||
doAnswer(new Answer<Boolean>() {
|
||||
private int mCount = 0;
|
||||
private final long[] mTimes = {1000, 1500, 2000};
|
||||
private final byte[] mLevels = {99, 98, 97};
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (count == times.length) {
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (mCount == mTimes.length) {
|
||||
return false;
|
||||
}
|
||||
BatteryStats.HistoryItem record = invocation.getArgument(0);
|
||||
record.cmd = BatteryStats.HistoryItem.CMD_UPDATE;
|
||||
record.time = times[count];
|
||||
record.batteryLevel = levels[count];
|
||||
count++;
|
||||
record.time = mTimes[mCount];
|
||||
record.batteryLevel = mLevels[mCount];
|
||||
mCount++;
|
||||
return true;
|
||||
}
|
||||
}).when(mBatteryStats).getNextHistoryLocked(any(BatteryStats.HistoryItem.class));
|
||||
return true;
|
||||
}).when(mBatteryStats).startIteratingHistoryLocked();
|
||||
}).when(iterator).next(any(BatteryStats.HistoryItem.class));
|
||||
return iterator;
|
||||
}).when(mBatteryUsageStats).iterateBatteryStatsHistory();
|
||||
}
|
||||
|
||||
private void assertOnlyHistory(BatteryInfo info) {
|
||||
@@ -337,9 +338,9 @@ public class BatteryInfoTest {
|
||||
|
||||
private BatteryInfo getBatteryInfo(boolean charging, boolean enhanced, boolean estimate) {
|
||||
if (charging && estimate) {
|
||||
doReturn(1000L).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
|
||||
doReturn(1000L).when(mBatteryUsageStats).getChargeTimeRemainingMs();
|
||||
} else {
|
||||
doReturn(0L).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
|
||||
doReturn(0L).when(mBatteryUsageStats).getChargeTimeRemainingMs();
|
||||
}
|
||||
Estimate batteryEstimate = new Estimate(
|
||||
estimate ? 1000 : 0,
|
||||
@@ -347,7 +348,7 @@ public class BatteryInfoTest {
|
||||
1000 /* averageDischargeTime */);
|
||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext,
|
||||
charging ? mChargingBatteryBroadcast : mDisChargingBatteryBroadcast,
|
||||
mBatteryStats, batteryEstimate, SystemClock.elapsedRealtime() * 1000, false);
|
||||
mBatteryUsageStats, batteryEstimate, SystemClock.elapsedRealtime() * 1000, false);
|
||||
doReturn(enhanced).when(mFeatureFactory.powerUsageFeatureProvider)
|
||||
.isEnhancedBatteryPredictionEnabled(mContext);
|
||||
return info;
|
||||
|
@@ -48,6 +48,7 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.BatteryStatsManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
@@ -157,6 +158,8 @@ public class BatteryUtilsTest {
|
||||
private ApplicationInfo mApplicationInfo;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private BatteryStatsHelper mBatteryStatsHelper;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private BatteryStatsManager mBatteryStatsManager;
|
||||
@Mock
|
||||
private ApplicationInfo mHighApplicationInfo;
|
||||
@Mock
|
||||
@@ -228,6 +231,8 @@ public class BatteryUtilsTest {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
doReturn(mAppOpsManager).when(mContext).getSystemService(Context.APP_OPS_SERVICE);
|
||||
doReturn(mBatteryStatsManager).when(mContext)
|
||||
.getSystemService(Context.BATTERY_STATS_SERVICE);
|
||||
mBatteryUtils = spy(new BatteryUtils(mContext));
|
||||
mBatteryUtils.mPowerUsageFeatureProvider = mProvider;
|
||||
doReturn(0L).when(mBatteryUtils)
|
||||
@@ -741,7 +746,7 @@ public class BatteryUtilsTest {
|
||||
any(IntentFilter.class))).thenReturn(new Intent());
|
||||
|
||||
//Should not crash
|
||||
assertThat(mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG)).isNotNull();
|
||||
assertThat(mBatteryUtils.getBatteryInfo(TAG)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -74,6 +74,11 @@ public class PowerUsageBaseTest {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isBatteryHistoryNeeded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshUi(int refreshType) {
|
||||
// Do nothing
|
||||
|
@@ -77,7 +77,7 @@ public class BatteryTipLoaderTest {
|
||||
doReturn(mContext).when(mContext).getApplicationContext();
|
||||
doReturn(mPowerManager).when(mContext).getSystemService(Context.POWER_SERVICE);
|
||||
doReturn(mIntent).when(mContext).registerReceiver(any(), any());
|
||||
doReturn(mBatteryInfo).when(mBatteryUtils).getBatteryInfo(any(), any());
|
||||
doReturn(mBatteryInfo).when(mBatteryUtils).getBatteryInfo(any());
|
||||
mBatteryTipLoader = new BatteryTipLoader(mContext, mBatteryStatsHelper);
|
||||
mBatteryTipLoader.mBatteryUtils = mBatteryUtils;
|
||||
}
|
||||
|
@@ -18,7 +18,9 @@ package com.android.settings.fuelgauge.batterytip.detectors;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -26,8 +28,11 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.BatteryStats;
|
||||
import android.text.format.DateUtils;
|
||||
import android.os.BatteryStatsManager;
|
||||
import android.os.BatteryUsageStats;
|
||||
import android.os.BatteryUsageStatsQuery;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
@@ -53,6 +58,8 @@ import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class HighUsageDetectorTest {
|
||||
private static final String TAG = "HighUsageDetectorTest";
|
||||
|
||||
private static final int UID_HIGH = 123;
|
||||
private static final int UID_LOW = 345;
|
||||
private static final double POWER_HIGH = 20000;
|
||||
@@ -68,6 +75,10 @@ public class HighUsageDetectorTest {
|
||||
private BatterySipper mSystemBatterySipper;
|
||||
@Mock
|
||||
private HighUsageDataParser mDataParser;
|
||||
@Mock
|
||||
private BatteryUsageStats mBatteryUsageStats;
|
||||
@Mock
|
||||
private BatteryStatsManager mBatteryStatsManager;
|
||||
|
||||
private AppInfo mHighAppInfo;
|
||||
private AppInfo mLowAppInfo;
|
||||
@@ -80,11 +91,19 @@ public class HighUsageDetectorTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mPolicy = spy(new BatteryTipPolicy(mContext));
|
||||
mBatteryUtils = spy(BatteryUtils.getInstance(mContext));
|
||||
mBatteryUtils = spy(new BatteryUtils(mContext));
|
||||
|
||||
when(mContext.getSystemService(eq(Context.BATTERY_STATS_SERVICE)))
|
||||
.thenReturn(mBatteryStatsManager);
|
||||
when(mBatteryStatsManager.getBatteryUsageStats(any(BatteryUsageStatsQuery.class)))
|
||||
.thenReturn(mBatteryUsageStats);
|
||||
|
||||
mContext.sendStickyBroadcast(new Intent(Intent.ACTION_BATTERY_CHANGED));
|
||||
|
||||
mHighUsageDetector = spy(new HighUsageDetector(mContext, mPolicy, mBatteryStatsHelper,
|
||||
true /* mDischarging */));
|
||||
mBatteryUtils.getBatteryInfo(TAG)));
|
||||
mHighUsageDetector.mBatteryUtils = mBatteryUtils;
|
||||
mHighUsageDetector.mDataParser = mDataParser;
|
||||
doNothing().when(mHighUsageDetector).parseBatteryData();
|
||||
|
Reference in New Issue
Block a user