update the whitelist for anomaly detection
Add "allow-in-power-save-except-idle" to whitelist. Also ignore all the system uids Bug: 74241534 Test: RunSettingsRoboTests Change-Id: I593e558168db339f6f38c7f78ab4fd63f99b16ab
This commit is contained in:
@@ -31,8 +31,9 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.StatsDimensionsValue;
|
||||
import android.os.SystemPropertiesProto;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
@@ -122,7 +123,8 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
final boolean smartBatteryOn = Settings.Global.getInt(contentResolver,
|
||||
Settings.Global.APP_STANDBY_ENABLED, ON) == ON;
|
||||
final String packageName = batteryUtils.getPackageName(uid);
|
||||
if (!powerWhitelistBackend.isSysWhitelisted(packageName)) {
|
||||
if (!powerWhitelistBackend.isSysWhitelistedExceptIdle(packageName)
|
||||
&& !isSystemUid(uid)) {
|
||||
if (anomalyType == StatsManagerConfig.AnomalyType.EXCESSIVE_BG) {
|
||||
// TODO(b/72385333): check battery percentage draining in batterystats
|
||||
if (batteryUtils.isLegacyApp(packageName) && batteryUtils.isAppHeavilyUsed(
|
||||
@@ -156,7 +158,7 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
* 3. Bluetooth anomaly: 3:{1:{1:{1:10140|}|}|}
|
||||
*/
|
||||
@VisibleForTesting
|
||||
final int extractUidFromStatsDimensionsValue(StatsDimensionsValue statsDimensionsValue) {
|
||||
int extractUidFromStatsDimensionsValue(StatsDimensionsValue statsDimensionsValue) {
|
||||
//TODO(b/73172999): Add robo test for this method
|
||||
if (statsDimensionsValue == null) {
|
||||
return UID_NULL;
|
||||
@@ -178,4 +180,9 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
|
||||
return UID_NULL;
|
||||
}
|
||||
|
||||
private boolean isSystemUid(int uid) {
|
||||
final int appUid = UserHandle.getAppId(uid);
|
||||
return appUid >= Process.ROOT_UID && appUid < Process.FIRST_APPLICATION_UID;
|
||||
}
|
||||
}
|
||||
|
@@ -18,11 +18,13 @@ package com.android.settings.fuelgauge.batterytip;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
@@ -32,6 +34,7 @@ import android.app.job.JobScheduler;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.StatsDimensionsValue;
|
||||
import android.os.UserManager;
|
||||
|
||||
@@ -84,7 +87,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
mBundle = new Bundle();
|
||||
mBundle.putParcelable(StatsManager.EXTRA_STATS_DIMENSIONS_VALUE, mStatsDimensionsValue);
|
||||
|
||||
mAnomalyDetectionJobService = new AnomalyDetectionJobService();
|
||||
mAnomalyDetectionJobService = spy(new AnomalyDetectionJobService());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,6 +98,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
Shadows.shadowOf(application.getSystemService(JobScheduler.class));
|
||||
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
|
||||
assertThat(pendingJobs).hasSize(1);
|
||||
|
||||
JobInfo pendingJob = pendingJobs.get(0);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_detection);
|
||||
assertThat(pendingJob.getMaxExecutionDelayMillis())
|
||||
@@ -114,10 +118,25 @@ public class AnomalyDetectionJobServiceTest {
|
||||
anyInt(), anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveAnomalyToDatabase_systemUid_doNotSave() {
|
||||
doReturn(Process.SYSTEM_UID).when(
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mBatteryStatsHelper, mUserManager,
|
||||
mBatteryDatabaseManager, mBatteryUtils, mPolicy, mPowerWhitelistBackend,
|
||||
mContext.getContentResolver(), mBundle);
|
||||
|
||||
verify(mBatteryDatabaseManager, never()).insertAnomaly(anyInt(), anyString(), anyInt(),
|
||||
anyInt(), anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveAnomalyToDatabase_normalApp_save() {
|
||||
doReturn(SYSTEM_PACKAGE).when(mBatteryUtils).getPackageName(anyInt());
|
||||
doReturn(false).when(mPowerWhitelistBackend).isSysWhitelisted(SYSTEM_PACKAGE);
|
||||
doReturn(Process.FIRST_APPLICATION_UID).when(
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mBatteryStatsHelper, mUserManager,
|
||||
mBatteryDatabaseManager, mBatteryUtils, mPolicy, mPowerWhitelistBackend,
|
||||
|
Reference in New Issue
Block a user