Get anomalyType and autoRestriction from config
Now the westworld config provides COOKIES to store private info for each alert(anomaly). So we could use it to store: 1. AnomalyType: what is the type of anomaly 2. AutoRestriction: whether to auto restrict this anomaly Bug: 74567790 Test: RunSettingsRoboTests Change-Id: I15f5e225a4cb1f2da3fe109e56e5222816d179cc
This commit is contained in:
@@ -22,6 +22,7 @@ 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.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -41,6 +42,8 @@ import android.os.UserManager;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
|
||||
@@ -60,6 +63,10 @@ import java.util.concurrent.TimeUnit;
|
||||
public class AnomalyDetectionJobServiceTest {
|
||||
private static final int UID = 123;
|
||||
private static final String SYSTEM_PACKAGE = "com.android.system";
|
||||
private static final String SUBSCRIBER_COOKIES_AUTO_RESTRICTION =
|
||||
"anomaly_type=6,auto_restriction=true";
|
||||
private static final String SUBSCRIBER_COOKIES_NOT_AUTO_RESTRICTION =
|
||||
"anomaly_type=6,auto_restriction=false";
|
||||
@Mock
|
||||
private BatteryStatsHelper mBatteryStatsHelper;
|
||||
@Mock
|
||||
@@ -76,6 +83,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
private BatteryTipPolicy mPolicy;
|
||||
private Bundle mBundle;
|
||||
private AnomalyDetectionJobService mAnomalyDetectionJobService;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
@@ -86,6 +94,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
mPolicy = new BatteryTipPolicy(mContext);
|
||||
mBundle = new Bundle();
|
||||
mBundle.putParcelable(StatsManager.EXTRA_STATS_DIMENSIONS_VALUE, mStatsDimensionsValue);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
mAnomalyDetectionJobService = spy(new AnomalyDetectionJobService());
|
||||
}
|
||||
@@ -112,7 +121,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mBatteryStatsHelper, mUserManager,
|
||||
mBatteryDatabaseManager, mBatteryUtils, mPolicy, mPowerWhitelistBackend,
|
||||
mContext.getContentResolver(), mBundle);
|
||||
mContext.getContentResolver(), mFeatureFactory.powerUsageFeatureProvider, mBundle);
|
||||
|
||||
verify(mBatteryDatabaseManager, never()).insertAnomaly(anyInt(), anyString(), anyInt(),
|
||||
anyInt(), anyLong());
|
||||
@@ -125,14 +134,16 @@ public class AnomalyDetectionJobServiceTest {
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mBatteryStatsHelper, mUserManager,
|
||||
mBatteryDatabaseManager, mBatteryUtils, mPolicy, mPowerWhitelistBackend,
|
||||
mContext.getContentResolver(), mBundle);
|
||||
mContext.getContentResolver(), mFeatureFactory.powerUsageFeatureProvider, mBundle);
|
||||
|
||||
verify(mBatteryDatabaseManager, never()).insertAnomaly(anyInt(), anyString(), anyInt(),
|
||||
anyInt(), anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveAnomalyToDatabase_normalApp_save() {
|
||||
public void testSaveAnomalyToDatabase_normalAppWithAutoRestriction_save() {
|
||||
mBundle.putStringArray(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES,
|
||||
new String[]{SUBSCRIBER_COOKIES_AUTO_RESTRICTION});
|
||||
doReturn(SYSTEM_PACKAGE).when(mBatteryUtils).getPackageName(anyInt());
|
||||
doReturn(false).when(mPowerWhitelistBackend).isSysWhitelisted(SYSTEM_PACKAGE);
|
||||
doReturn(Process.FIRST_APPLICATION_UID).when(
|
||||
@@ -140,9 +151,27 @@ public class AnomalyDetectionJobServiceTest {
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mBatteryStatsHelper, mUserManager,
|
||||
mBatteryDatabaseManager, mBatteryUtils, mPolicy, mPowerWhitelistBackend,
|
||||
mContext.getContentResolver(), mBundle);
|
||||
mContext.getContentResolver(), mFeatureFactory.powerUsageFeatureProvider, mBundle);
|
||||
|
||||
verify(mBatteryDatabaseManager).insertAnomaly(anyInt(), anyString(), anyInt(), anyInt(),
|
||||
anyLong());
|
||||
verify(mBatteryDatabaseManager).insertAnomaly(anyInt(), anyString(), eq(6),
|
||||
eq(AnomalyDatabaseHelper.State.AUTO_HANDLED), anyLong());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSaveAnomalyToDatabase_normalAppWithoutAutoRestriction_save() {
|
||||
mBundle.putStringArray(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES,
|
||||
new String[]{SUBSCRIBER_COOKIES_NOT_AUTO_RESTRICTION});
|
||||
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,
|
||||
mContext.getContentResolver(), mFeatureFactory.powerUsageFeatureProvider, mBundle);
|
||||
|
||||
verify(mBatteryDatabaseManager).insertAnomaly(anyInt(), anyString(), eq(6),
|
||||
eq(AnomalyDatabaseHelper.State.NEW), anyLong());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user