Clean up the legacy anomaly detection mechanism in the Settings

Clean up the legacy anomaly detection mechanism in the Settings, which is implemented in the 2017-2018. The will be replaced by the new anomaly detection mechanism.

Bug: n/a
Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge"
Change-Id: I12ee6c8b3cbdb5073e4d46f18b90f8de228be8a8
This commit is contained in:
ykhung
2024-01-16 14:48:03 +08:00
parent fe684cb602
commit 9ccd8d8da2
4 changed files with 2 additions and 195 deletions

View File

@@ -40,20 +40,16 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.BatteryConsumer;
import android.os.BatteryStats;
import android.os.BatteryStatsManager;
import android.os.BatteryUsageStats;
import android.os.Build;
import android.os.Process;
import android.os.SystemClock;
import com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper;
import com.android.settings.fuelgauge.batterytip.AnomalyInfo;
import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowThreadUtils;
@@ -70,9 +66,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
public class BatteryUtilsTest {
@@ -122,7 +115,6 @@ public class BatteryUtilsTest {
@Mock private ApplicationInfo mLowApplicationInfo;
@Mock private PowerAllowlistBackend mPowerAllowlistBackend;
@Mock private BatteryDatabaseManager mBatteryDatabaseManager;
private AnomalyInfo mAnomalyInfo;
private BatteryUtils mBatteryUtils;
private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mProvider;
@@ -169,7 +161,6 @@ public class BatteryUtilsTest {
doReturn(0L)
.when(mBatteryUtils)
.getForegroundServiceTotalTimeUs(any(BatteryStats.Uid.class), anyLong());
mAnomalyInfo = new AnomalyInfo(INFO_WAKELOCK);
BatteryDatabaseManager.setUpForTest(mBatteryDatabaseManager);
ShadowThreadUtils.setIsMainThread(true);
@@ -390,79 +381,6 @@ public class BatteryUtilsTest {
assertThat(mBatteryUtils.isForceAppStandbyEnabled(UID, PACKAGE_NAME)).isFalse();
}
@Test
public void testShouldHideAnomaly_systemAppWithLauncher_returnTrue() {
final List<ResolveInfo> resolveInfos = new ArrayList<>();
final ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = new ActivityInfo();
resolveInfo.activityInfo.packageName = HIGH_SDK_PACKAGE;
doReturn(resolveInfos).when(mPackageManager).queryIntentActivities(any(), anyInt());
doReturn(new String[] {HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
mHighApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID, mAnomalyInfo))
.isTrue();
}
@Test
public void testShouldHideAnomaly_systemAppWithoutLauncher_returnTrue() {
doReturn(new ArrayList<>()).when(mPackageManager).queryIntentActivities(any(), anyInt());
doReturn(new String[] {HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
mHighApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID, mAnomalyInfo))
.isTrue();
}
@Test
public void testShouldHideAnomaly_systemUid_returnTrue() {
final int systemUid = Process.ROOT_UID;
doReturn(new String[] {HIGH_SDK_PACKAGE})
.when(mPackageManager)
.getPackagesForUid(systemUid);
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, systemUid, mAnomalyInfo))
.isTrue();
}
@Test
public void testShouldHideAnomaly_AppInDozeList_returnTrue() {
doReturn(new String[] {HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
doReturn(true)
.when(mPowerAllowlistBackend)
.isAllowlisted(new String[] {HIGH_SDK_PACKAGE}, UID);
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID, mAnomalyInfo))
.isTrue();
}
@Test
public void testShouldHideAnomaly_normalApp_returnFalse() {
doReturn(new String[] {HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID, mAnomalyInfo))
.isFalse();
}
@Test
public void testShouldHideAnomaly_excessivePriorOApp_returnFalse() {
doReturn(new String[] {LOW_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
mAnomalyInfo = new AnomalyInfo(INFO_EXCESSIVE);
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID, mAnomalyInfo))
.isFalse();
}
@Test
public void testShouldHideAnomaly_excessiveOApp_returnTrue() {
doReturn(new String[] {HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
mAnomalyInfo = new AnomalyInfo(INFO_EXCESSIVE);
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID, mAnomalyInfo))
.isTrue();
}
@Test
public void clearForceAppStandby_appRestricted_clearAndReturnTrue() {
when(mBatteryUtils.getPackageUid(HIGH_SDK_PACKAGE)).thenReturn(UID);

View File

@@ -74,6 +74,7 @@ import com.android.settingslib.search.SearchIndexableRaw;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.AdditionalMatchers;
@@ -709,6 +710,7 @@ public class UserSettingsTest {
verify(mUserManager).getAliveUsers();
}
@Ignore
@Test
public void updateUserList_userIconMissing_shouldLoadIcon() {
UserInfo currentUser = getAdminUser(true);