Remove references to BatteryStatsHelper from PowerUsageBase
Bug: 180630447 Bug: 173745486 Test: make RunSettingsRoboTests Test: male RunSettingsGoogleRoboTests Change-Id: Ifed69c4fdd741f75b0b962f9d3200f0ed533358f
This commit is contained in:
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.fuelgauge;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.UserManager;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
|
||||||
import com.android.settingslib.utils.AsyncLoaderCompat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loader to get new {@link BatteryStatsHelper} in the background
|
|
||||||
*/
|
|
||||||
public class BatteryStatsHelperLoader extends AsyncLoaderCompat<BatteryStatsHelper> {
|
|
||||||
@VisibleForTesting
|
|
||||||
UserManager mUserManager;
|
|
||||||
@VisibleForTesting
|
|
||||||
BatteryUtils mBatteryUtils;
|
|
||||||
|
|
||||||
public BatteryStatsHelperLoader(Context context) {
|
|
||||||
super(context);
|
|
||||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
|
||||||
mBatteryUtils = BatteryUtils.getInstance(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BatteryStatsHelper loadInBackground() {
|
|
||||||
Context context = getContext();
|
|
||||||
final BatteryStatsHelper statsHelper = new BatteryStatsHelper(context,
|
|
||||||
true /* collectBatteryBroadcast */);
|
|
||||||
mBatteryUtils.initBatteryStatsHelper(statsHelper, null /* bundle */, mUserManager);
|
|
||||||
|
|
||||||
return statsHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDiscardResult(BatteryStatsHelper result) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -29,7 +29,6 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
import androidx.loader.app.LoaderManager;
|
import androidx.loader.app.LoaderManager;
|
||||||
import androidx.loader.content.Loader;
|
import androidx.loader.content.Loader;
|
||||||
|
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,10 +43,8 @@ public abstract class PowerUsageBase extends DashboardFragment {
|
|||||||
private static final String KEY_REFRESH_TYPE = "refresh_type";
|
private static final String KEY_REFRESH_TYPE = "refresh_type";
|
||||||
private static final String KEY_INCLUDE_HISTORY = "include_history";
|
private static final String KEY_INCLUDE_HISTORY = "include_history";
|
||||||
|
|
||||||
private static final int LOADER_BATTERY_STATS_HELPER = 0;
|
|
||||||
private static final int LOADER_BATTERY_USAGE_STATS = 1;
|
private static final int LOADER_BATTERY_USAGE_STATS = 1;
|
||||||
|
|
||||||
protected BatteryStatsHelper mStatsHelper;
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
BatteryUsageStats mBatteryUsageStats;
|
BatteryUsageStats mBatteryUsageStats;
|
||||||
|
|
||||||
@@ -55,12 +52,6 @@ public abstract class PowerUsageBase extends DashboardFragment {
|
|||||||
private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
||||||
protected boolean mIsBatteryPresent = true;
|
protected boolean mIsBatteryPresent = true;
|
||||||
|
|
||||||
// TODO(b/180630447): switch to BatteryUsageStatsLoader and remove all references to
|
|
||||||
// BatteryStatsHelper and BatterySipper
|
|
||||||
@VisibleForTesting
|
|
||||||
final BatteryStatsHelperLoaderCallbacks mBatteryStatsHelperLoaderCallbacks =
|
|
||||||
new BatteryStatsHelperLoaderCallbacks();
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final BatteryUsageStatsLoaderCallbacks mBatteryUsageStatsLoaderCallbacks =
|
final BatteryUsageStatsLoaderCallbacks mBatteryUsageStatsLoaderCallbacks =
|
||||||
new BatteryUsageStatsLoaderCallbacks();
|
new BatteryUsageStatsLoaderCallbacks();
|
||||||
@@ -69,13 +60,11 @@ public abstract class PowerUsageBase extends DashboardFragment {
|
|||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
mUm = (UserManager) activity.getSystemService(Context.USER_SERVICE);
|
mUm = (UserManager) activity.getSystemService(Context.USER_SERVICE);
|
||||||
mStatsHelper = new BatteryStatsHelper(activity, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
mStatsHelper.create(icicle);
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
|
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
|
||||||
@@ -103,18 +92,11 @@ public abstract class PowerUsageBase extends DashboardFragment {
|
|||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putInt(KEY_REFRESH_TYPE, refreshType);
|
bundle.putInt(KEY_REFRESH_TYPE, refreshType);
|
||||||
bundle.putBoolean(KEY_INCLUDE_HISTORY, isBatteryHistoryNeeded());
|
bundle.putBoolean(KEY_INCLUDE_HISTORY, isBatteryHistoryNeeded());
|
||||||
getLoaderManager().restartLoader(LOADER_BATTERY_STATS_HELPER, bundle,
|
|
||||||
mBatteryStatsHelperLoaderCallbacks);
|
|
||||||
getLoaderManager().restartLoader(LOADER_BATTERY_USAGE_STATS, bundle,
|
getLoaderManager().restartLoader(LOADER_BATTERY_USAGE_STATS, bundle,
|
||||||
mBatteryUsageStatsLoaderCallbacks);
|
mBatteryUsageStatsLoaderCallbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLoadFinished(@BatteryUpdateType int refreshType) {
|
private void onLoadFinished(@BatteryUpdateType int refreshType) {
|
||||||
// Wait for both loaders to finish before proceeding.
|
|
||||||
if (mStatsHelper == null || mBatteryUsageStats == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshUi(refreshType);
|
refreshUi(refreshType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,28 +109,6 @@ public abstract class PowerUsageBase extends DashboardFragment {
|
|||||||
BatteryUtils.logRuntime(TAG, "updatePreference", startTime);
|
BatteryUtils.logRuntime(TAG, "updatePreference", startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class BatteryStatsHelperLoaderCallbacks
|
|
||||||
implements LoaderManager.LoaderCallbacks<BatteryStatsHelper> {
|
|
||||||
private int mRefreshType;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Loader<BatteryStatsHelper> onCreateLoader(int id, Bundle args) {
|
|
||||||
mRefreshType = args.getInt(KEY_REFRESH_TYPE);
|
|
||||||
return new BatteryStatsHelperLoader(getContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadFinished(Loader<BatteryStatsHelper> loader,
|
|
||||||
BatteryStatsHelper batteryHelper) {
|
|
||||||
mStatsHelper = batteryHelper;
|
|
||||||
PowerUsageBase.this.onLoadFinished(mRefreshType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoaderReset(Loader<BatteryStatsHelper> loader) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class BatteryUsageStatsLoaderCallbacks
|
private class BatteryUsageStatsLoaderCallbacks
|
||||||
implements LoaderManager.LoaderCallbacks<BatteryUsageStats> {
|
implements LoaderManager.LoaderCallbacks<BatteryUsageStats> {
|
||||||
private int mRefreshType;
|
private int mRefreshType;
|
||||||
|
@@ -120,7 +120,6 @@ public class AvatarViewMixinTest {
|
|||||||
@Test
|
@Test
|
||||||
@Config(qualifiers = "mcc999",
|
@Config(qualifiers = "mcc999",
|
||||||
shadows = {
|
shadows = {
|
||||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
|
||||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
||||||
})
|
})
|
||||||
public void onStart_useMockAvatarViewMixin_shouldBeExecuted() {
|
public void onStart_useMockAvatarViewMixin_shouldBeExecuted() {
|
||||||
|
@@ -78,7 +78,6 @@ public class BatteryBroadcastReceiverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
|
||||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
||||||
})
|
})
|
||||||
public void testOnReceive_batteryLevelChanged_dataUpdated() {
|
public void testOnReceive_batteryLevelChanged_dataUpdated() {
|
||||||
@@ -93,7 +92,6 @@ public class BatteryBroadcastReceiverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
|
||||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
||||||
})
|
})
|
||||||
public void testOnReceive_batteryHealthChanged_dataUpdated() {
|
public void testOnReceive_batteryHealthChanged_dataUpdated() {
|
||||||
@@ -108,7 +106,6 @@ public class BatteryBroadcastReceiverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
|
||||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
||||||
})
|
})
|
||||||
public void onReceive_batteryNotPresent_shouldShowHelpMessage() {
|
public void onReceive_batteryNotPresent_shouldShowHelpMessage() {
|
||||||
@@ -121,7 +118,6 @@ public class BatteryBroadcastReceiverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
|
||||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
||||||
})
|
})
|
||||||
public void testOnReceive_powerSaveModeChanged_listenerInvoked() {
|
public void testOnReceive_powerSaveModeChanged_listenerInvoked() {
|
||||||
@@ -133,7 +129,6 @@ public class BatteryBroadcastReceiverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
|
||||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
||||||
})
|
})
|
||||||
public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
|
public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
|
||||||
@@ -154,7 +149,6 @@ public class BatteryBroadcastReceiverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
|
||||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
||||||
})
|
})
|
||||||
public void testRegister_updateBatteryStatus() {
|
public void testRegister_updateBatteryStatus() {
|
||||||
|
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.fuelgauge;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class BatteryStatsHelperLoaderTest {
|
|
||||||
@Mock
|
|
||||||
private BatteryUtils mBatteryUtils;
|
|
||||||
@Mock
|
|
||||||
private ConnectivityManager mConnectivityManager;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private BatteryStatsHelperLoader mBatteryStatsHelperLoader;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
|
||||||
doReturn(mConnectivityManager).when(mContext).getSystemService(
|
|
||||||
Context.CONNECTIVITY_SERVICE);
|
|
||||||
|
|
||||||
mBatteryStatsHelperLoader = spy(new BatteryStatsHelperLoader(mContext));
|
|
||||||
mBatteryStatsHelperLoader.mBatteryUtils = mBatteryUtils;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLoadInBackground_loadWithoutBundle() {
|
|
||||||
when(mBatteryStatsHelperLoader.getContext()).thenReturn(mContext);
|
|
||||||
mBatteryStatsHelperLoader.loadInBackground();
|
|
||||||
|
|
||||||
verify(mBatteryUtils).initBatteryStatsHelper(any(), eq(null), any());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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.fuelgauge;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.BatteryStatsManager;
|
||||||
|
import android.os.BatteryUsageStats;
|
||||||
|
import android.os.BatteryUsageStatsQuery;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class BatteryUsageStatsLoaderTest {
|
||||||
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private BatteryStatsManager mBatteryStatsManager;
|
||||||
|
@Mock
|
||||||
|
private BatteryUsageStats mBatteryUsageStats;
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<BatteryUsageStatsQuery> mUsageStatsQueryCaptor;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
doReturn(mBatteryStatsManager).when(mContext).getSystemService(
|
||||||
|
Context.BATTERY_STATS_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadInBackground_loadWithoutHistory() {
|
||||||
|
BatteryUsageStatsLoader loader = new BatteryUsageStatsLoader(
|
||||||
|
mContext, /* includeBatteryHistory */ false);
|
||||||
|
|
||||||
|
when(mBatteryStatsManager.getBatteryUsageStats(mUsageStatsQueryCaptor.capture()))
|
||||||
|
.thenReturn(mBatteryUsageStats);
|
||||||
|
|
||||||
|
loader.loadInBackground();
|
||||||
|
|
||||||
|
final int queryFlags = mUsageStatsQueryCaptor.getValue().getFlags();
|
||||||
|
assertThat(queryFlags
|
||||||
|
& BatteryUsageStatsQuery.FLAG_BATTERY_USAGE_STATS_INCLUDE_HISTORY).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadInBackground_loadWithHistory() {
|
||||||
|
BatteryUsageStatsLoader loader = new BatteryUsageStatsLoader(
|
||||||
|
mContext, /* includeBatteryHistory */ true);
|
||||||
|
|
||||||
|
when(mBatteryStatsManager.getBatteryUsageStats(mUsageStatsQueryCaptor.capture()))
|
||||||
|
.thenReturn(mBatteryUsageStats);
|
||||||
|
|
||||||
|
loader.loadInBackground();
|
||||||
|
|
||||||
|
final int queryFlags = mUsageStatsQueryCaptor.getValue().getFlags();
|
||||||
|
assertThat(queryFlags
|
||||||
|
& BatteryUsageStatsQuery.FLAG_BATTERY_USAGE_STATS_INCLUDE_HISTORY).isNotEqualTo(0);
|
||||||
|
}
|
||||||
|
}
|
@@ -27,7 +27,6 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
import androidx.loader.app.LoaderManager;
|
import androidx.loader.app.LoaderManager;
|
||||||
|
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
|
||||||
import com.android.settings.testutils.shadow.ShadowDashboardFragment;
|
import com.android.settings.testutils.shadow.ShadowDashboardFragment;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
@@ -45,8 +44,6 @@ import java.util.List;
|
|||||||
@Config(shadows = ShadowDashboardFragment.class)
|
@Config(shadows = ShadowDashboardFragment.class)
|
||||||
public class PowerUsageBaseTest {
|
public class PowerUsageBaseTest {
|
||||||
|
|
||||||
@Mock
|
|
||||||
private BatteryStatsHelper mBatteryStatsHelper;
|
|
||||||
@Mock
|
@Mock
|
||||||
private LoaderManager mLoaderManager;
|
private LoaderManager mLoaderManager;
|
||||||
private TestFragment mFragment;
|
private TestFragment mFragment;
|
||||||
@@ -56,7 +53,6 @@ public class PowerUsageBaseTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mFragment = spy(new TestFragment());
|
mFragment = spy(new TestFragment());
|
||||||
mFragment.setBatteryStatsHelper(mBatteryStatsHelper);
|
|
||||||
doReturn(mLoaderManager).when(mFragment).getLoaderManager();
|
doReturn(mLoaderManager).when(mFragment).getLoaderManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,9 +94,5 @@ public class PowerUsageBaseTest {
|
|||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBatteryStatsHelper(BatteryStatsHelper batteryStatsHelper) {
|
|
||||||
mStatsHelper = batteryStatsHelper;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
@@ -40,8 +39,6 @@ import android.provider.Settings;
|
|||||||
import androidx.loader.app.LoaderManager;
|
import androidx.loader.app.LoaderManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.internal.os.BatterySipper;
|
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
|
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
|
||||||
@@ -54,7 +51,6 @@ import org.junit.Before;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
@@ -62,35 +58,19 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
// TODO: Improve this test class so that it starts up the real activity and fragment.
|
// TODO: Improve this test class so that it starts up the real activity and fragment.
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class PowerUsageSummaryTest {
|
public class PowerUsageSummaryTest {
|
||||||
|
|
||||||
private static final int UID = 123;
|
|
||||||
private static final int POWER_MAH = 100;
|
|
||||||
private static final long TIME_SINCE_LAST_FULL_CHARGE_MS = 120 * 60 * 1000;
|
private static final long TIME_SINCE_LAST_FULL_CHARGE_MS = 120 * 60 * 1000;
|
||||||
private static final long TIME_SINCE_LAST_FULL_CHARGE_US =
|
|
||||||
TIME_SINCE_LAST_FULL_CHARGE_MS * 1000;
|
|
||||||
private static final long USAGE_TIME_MS = 65 * 60 * 1000;
|
|
||||||
private static final double TOTAL_POWER = 200;
|
|
||||||
private static Intent sAdditionalBatteryInfoIntent;
|
private static Intent sAdditionalBatteryInfoIntent;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
sAdditionalBatteryInfoIntent = new Intent("com.example.app.ADDITIONAL_BATTERY_INFO");
|
sAdditionalBatteryInfoIntent = new Intent("com.example.app.ADDITIONAL_BATTERY_INFO");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mock
|
|
||||||
private BatterySipper mNormalBatterySipper;
|
|
||||||
@Mock
|
|
||||||
private BatterySipper mScreenBatterySipper;
|
|
||||||
@Mock
|
|
||||||
private BatterySipper mCellBatterySipper;
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private BatteryStatsHelper mBatteryHelper;
|
|
||||||
@Mock
|
@Mock
|
||||||
private SettingsActivity mSettingsActivity;
|
private SettingsActivity mSettingsActivity;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -104,7 +84,6 @@ public class PowerUsageSummaryTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
|
||||||
private List<BatterySipper> mUsageList;
|
|
||||||
private Context mRealContext;
|
private Context mRealContext;
|
||||||
private TestFragment mFragment;
|
private TestFragment mFragment;
|
||||||
private FakeFeatureFactory mFeatureFactory;
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
@@ -123,27 +102,6 @@ public class PowerUsageSummaryTest {
|
|||||||
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
|
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
|
||||||
when(mFeatureFactory.powerUsageFeatureProvider.getAdditionalBatteryInfoIntent())
|
when(mFeatureFactory.powerUsageFeatureProvider.getAdditionalBatteryInfoIntent())
|
||||||
.thenReturn(sAdditionalBatteryInfoIntent);
|
.thenReturn(sAdditionalBatteryInfoIntent);
|
||||||
when(mBatteryHelper.getTotalPower()).thenReturn(TOTAL_POWER);
|
|
||||||
when(mBatteryHelper.getStats().computeBatteryRealtime(anyLong(), anyInt()))
|
|
||||||
.thenReturn(TIME_SINCE_LAST_FULL_CHARGE_US);
|
|
||||||
|
|
||||||
when(mNormalBatterySipper.getUid()).thenReturn(UID);
|
|
||||||
mNormalBatterySipper.totalPowerMah = POWER_MAH;
|
|
||||||
mNormalBatterySipper.drainType = BatterySipper.DrainType.APP;
|
|
||||||
|
|
||||||
mCellBatterySipper.drainType = BatterySipper.DrainType.CELL;
|
|
||||||
mCellBatterySipper.totalPowerMah = POWER_MAH;
|
|
||||||
|
|
||||||
mScreenBatterySipper.drainType = BatterySipper.DrainType.SCREEN;
|
|
||||||
mScreenBatterySipper.usageTimeMs = USAGE_TIME_MS;
|
|
||||||
|
|
||||||
mUsageList = new ArrayList<>();
|
|
||||||
mUsageList.add(mNormalBatterySipper);
|
|
||||||
mUsageList.add(mScreenBatterySipper);
|
|
||||||
mUsageList.add(mCellBatterySipper);
|
|
||||||
|
|
||||||
mFragment.mStatsHelper = mBatteryHelper;
|
|
||||||
when(mBatteryHelper.getUsageList()).thenReturn(mUsageList);
|
|
||||||
mFragment.mBatteryUtils = spy(new BatteryUtils(mRealContext));
|
mFragment.mBatteryUtils = spy(new BatteryUtils(mRealContext));
|
||||||
ReflectionHelpers.setField(mFragment, "mVisibilityLoggerMixin", mVisibilityLoggerMixin);
|
ReflectionHelpers.setField(mFragment, "mVisibilityLoggerMixin", mVisibilityLoggerMixin);
|
||||||
ReflectionHelpers.setField(mFragment, "mBatteryBroadcastReceiver",
|
ReflectionHelpers.setField(mFragment, "mBatteryBroadcastReceiver",
|
||||||
|
@@ -68,7 +68,6 @@ public class SettingsHomepageActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
|
||||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
||||||
})
|
})
|
||||||
public void onStart_isNotDebuggable_shouldHideSystemOverlay() {
|
public void onStart_isNotDebuggable_shouldHideSystemOverlay() {
|
||||||
@@ -88,7 +87,6 @@ public class SettingsHomepageActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
|
||||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class,
|
BatteryFixSliceTest.ShadowBatteryTipLoader.class,
|
||||||
})
|
})
|
||||||
public void onStop_isNotDebuggable_shouldRemoveHideSystemOverlay() {
|
public void onStop_isNotDebuggable_shouldRemoveHideSystemOverlay() {
|
||||||
|
@@ -30,9 +30,7 @@ import androidx.slice.SliceMetadata;
|
|||||||
import androidx.slice.SliceProvider;
|
import androidx.slice.SliceProvider;
|
||||||
import androidx.slice.widget.SliceLiveData;
|
import androidx.slice.widget.SliceLiveData;
|
||||||
|
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
|
|
||||||
import com.android.settings.fuelgauge.BatteryUsageStatsLoader;
|
import com.android.settings.fuelgauge.BatteryUsageStatsLoader;
|
||||||
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
||||||
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
|
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
|
||||||
@@ -137,15 +135,6 @@ public class BatteryFixSliceTest {
|
|||||||
assertThat(ShadowEarlyWarningTip.isIconTintColorIdCalled()).isTrue();
|
assertThat(ShadowEarlyWarningTip.isIconTintColorIdCalled()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Implements(BatteryStatsHelperLoader.class)
|
|
||||||
public static class ShadowBatteryStatsHelperLoader {
|
|
||||||
|
|
||||||
@Implementation
|
|
||||||
protected BatteryStatsHelper loadInBackground() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Implements(BatteryUsageStatsLoader.class)
|
@Implements(BatteryUsageStatsLoader.class)
|
||||||
public static class ShadowBatteryUsageStatsLoader {
|
public static class ShadowBatteryUsageStatsLoader {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user