Remove BatteryFixSlice as it's not used

The BatteryFixSlice hasn't been used for a while, and it's introducing
memory leaks due to a design change at the framework's end. Hence,
remove it.

Bug: 245385410
Test: robotests
Change-Id: I517cab71a32613d5cb5fcd3beb991a24926a2902
Merged-In: I517cab71a32613d5cb5fcd3beb991a24926a2902
(cherry picked from commit e3fcf1f082)
This commit is contained in:
Yi-Ling Chuang
2022-11-04 10:03:25 +08:00
committed by Yanting Yang
parent 1d04eb6eb7
commit 2f80e073d0
9 changed files with 3 additions and 519 deletions

View File

@@ -41,7 +41,6 @@ import android.os.Bundle;
import android.widget.ImageView;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Before;
@@ -95,7 +94,6 @@ public class AvatarViewMixinTest {
}
@Test
@Config(shadows = BatteryFixSliceTest.ShadowBatteryTipLoader.class)
public void onStart_useMockAvatarViewMixin_shouldBeExecuted() {
final AvatarViewMixin mockAvatar = spy(new AvatarViewMixin(mActivity, mImageView));

View File

@@ -33,7 +33,6 @@ import android.os.BatteryManager;
import android.os.PowerManager;
import com.android.settings.Utils;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
import org.junit.Before;
import org.junit.Test;
@@ -42,7 +41,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
public class BatteryBroadcastReceiverTest {
@@ -77,9 +75,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void testOnReceive_batteryLevelChanged_dataUpdated() {
mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
@@ -91,9 +86,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void testOnReceive_batteryHealthChanged_dataUpdated() {
mChargingIntent
.putExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_OVERHEAT);
@@ -105,9 +97,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void onReceive_batteryNotPresent_shouldShowHelpMessage() {
mChargingIntent.putExtra(BatteryManager.EXTRA_PRESENT, false);
@@ -117,9 +106,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void testOnReceive_powerSaveModeChanged_listenerInvoked() {
mBatteryBroadcastReceiver.onReceive(mContext,
new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
@@ -128,9 +114,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent);
final String batteryStatus =
@@ -148,9 +131,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void testRegister_updateBatteryStatus() {
doReturn(mChargingIntent).when(mContext).registerReceiver(any(), any());

View File

@@ -39,7 +39,6 @@ import androidx.fragment.app.Fragment;
import com.android.settings.R;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
import com.android.settings.testutils.shadow.ShadowActivityEmbeddingUtils;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
@@ -151,9 +150,6 @@ public class SettingsHomepageActivityTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void onStart_isNotDebuggable_shouldHideSystemOverlay() {
ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);
@@ -170,9 +166,6 @@ public class SettingsHomepageActivityTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryTipLoader.class,
})
public void onStop_isNotDebuggable_shouldRemoveHideSystemOverlay() {
ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);

View File

@@ -135,7 +135,7 @@ public class ContextualCardManagerTest {
final List<String> actualCards = mManager.mSavedCards.stream().collect(Collectors.toList());
final List<String> expectedCards = Arrays.asList("test_low_storage", "test_flashlight",
"test_dark_theme", "test_gesture", "test_battery");
"test_dark_theme", "test_gesture", "test_face_enroll");
assertThat(actualCards).containsExactlyElementsIn(expectedCards);
}
@@ -695,9 +695,9 @@ public class ContextualCardManagerTest {
.setViewType(VIEW_TYPE_FULL_WIDTH)
.build());
cards.add(new ContextualCard.Builder()
.setName("test_battery")
.setName("test_face_enroll")
.setCardType(ContextualCard.CardType.SLICE)
.setSliceUri(CustomSliceRegistry.BATTERY_FIX_SLICE_URI)
.setSliceUri(CustomSliceRegistry.FACE_ENROLL_SLICE_URI)
.setViewType(VIEW_TYPE_FULL_WIDTH)
.build());
return cards;

View File

@@ -1,207 +0,0 @@
/*
* Copyright (C) 2018 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.homepage.contextualcards.slices;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.Uri;
import android.os.BatteryUsageStats;
import androidx.slice.Slice;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip;
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader;
import com.android.settings.slices.SliceBackgroundWorker;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryUsageStatsLoader.class,
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public class BatteryFixSliceTest {
private Context mContext;
private BatteryFixSlice mSlice;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mSlice = new BatteryFixSlice(mContext);
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
}
@After
public void tearDown() {
ShadowBatteryTipLoader.reset();
ShadowSliceBackgroundWorker.reset();
ShadowEarlyWarningTip.reset();
}
@Test
public void refreshBatteryTips_hasImportantTip_shouldReturnTrue() {
final List<BatteryTip> tips = new ArrayList<>();
tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false));
tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.refreshBatteryTips(mContext);
assertThat(BatteryFixSlice.isBatteryTipAvailableFromCache(mContext)).isTrue();
}
@Test
public void getSlice_unimportantSlice_shouldSkip() {
final List<BatteryTip> tips = new ArrayList<>();
final List<AppInfo> appList = new ArrayList<>();
appList.add(new AppInfo.Builder()
.setPackageName("com.android.settings")
.setScreenOnTimeMs(10000L)
.build());
tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false));
tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false));
tips.add(new HighUsageTip(1000L, appList));
ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.refreshBatteryTips(mContext);
final Slice slice = mSlice.getSlice();
assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).isTrue();
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowEarlyWarningTip.class,
BatteryFixSliceTest.ShadowSliceBackgroundWorker.class
})
public void getSlice_hasImportantTip_shouldTintIcon() {
final List<BatteryTip> tips = new ArrayList<>();
tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
// Create fake cache data
ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.refreshBatteryTips(mContext);
// Create fake background worker data
BatteryFixSlice.BatteryTipWorker batteryTipWorker = mock(
BatteryFixSlice.BatteryTipWorker.class);
when(batteryTipWorker.getResults()).thenReturn(tips);
ShadowSliceBackgroundWorker.setBatteryTipWorkerWorker(batteryTipWorker);
final Slice slice = mSlice.getSlice();
assertThat(ShadowEarlyWarningTip.isIconTintColorIdCalled()).isTrue();
}
@Implements(BatteryUsageStatsLoader.class)
public static class ShadowBatteryUsageStatsLoader {
@Implementation
protected BatteryUsageStats loadInBackground() {
return null;
}
}
@Implements(BatteryTipLoader.class)
public static class ShadowBatteryTipLoader {
private static List<BatteryTip> sBatteryTips = new ArrayList<>();
@Resetter
public static void reset() {
sBatteryTips = new ArrayList<>();
}
@Implementation
protected List<BatteryTip> loadInBackground() {
return sBatteryTips;
}
private static void setBatteryTips(List<BatteryTip> tips) {
sBatteryTips = tips;
}
}
@Implements(SliceBackgroundWorker.class)
public static class ShadowSliceBackgroundWorker {
private static BatteryFixSlice.BatteryTipWorker sBatteryTipWorkerWorker;
@Resetter
public static void reset() {
sBatteryTipWorkerWorker = null;
}
@Implementation
protected static <T extends SliceBackgroundWorker> T getInstance(Uri uri) {
return (T) sBatteryTipWorkerWorker;
}
public static void setBatteryTipWorkerWorker(BatteryFixSlice.BatteryTipWorker worker) {
sBatteryTipWorkerWorker = worker;
}
}
@Implements(EarlyWarningTip.class)
public static class ShadowEarlyWarningTip {
private static boolean mIsGetIconTintColorIdCalled;
@Resetter
public static void reset() {
mIsGetIconTintColorIdCalled = false;
}
@Implementation
protected int getIconTintColorId() {
mIsGetIconTintColorIdCalled = true;
return R.color.battery_bad_color_light;
}
public static boolean isIconTintColorIdCalled() {
return mIsGetIconTintColorIdCalled;
}
}
}