Get anomaly info from StringArrayList

Statsd populates the anomaly info in StringArrayList, not StringArray. So
in settings we should use the correct API to get the data.

Bug: 77141809
Test: RunSettingsRoboTests
Change-Id: I56fc096106b5c040422fd7f5bb8cb4be7fe71d9d
This commit is contained in:
Lei Yu
2018-03-27 16:10:54 -07:00
parent 4e25277f60
commit bb90c955df
3 changed files with 14 additions and 6 deletions

View File

@@ -51,6 +51,7 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -126,10 +127,10 @@ public class AnomalyDetectionJobService extends JobService {
bundle.getParcelable(StatsManager.EXTRA_STATS_DIMENSIONS_VALUE);
final long timeMs = bundle.getLong(AnomalyDetectionReceiver.KEY_ANOMALY_TIMESTAMP,
System.currentTimeMillis());
final String[] cookies = bundle.getStringArray(
final ArrayList<String> cookies = bundle.getStringArrayList(
StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES);
final AnomalyInfo anomalyInfo = new AnomalyInfo(
!ArrayUtils.isEmpty(cookies) ? cookies[0] : "");
!ArrayUtils.isEmpty(cookies) ? cookies.get(0) : "");
Log.i(TAG, "Extra stats value: " + intentDimsValue.toString());
try {

View File

@@ -17,17 +17,21 @@
package com.android.settings.fuelgauge.batterytip;
import android.util.KeyValueListParser;
import android.util.Log;
/**
* Model class to parse and store anomaly info from westworld
*/
public class AnomalyInfo {
private static final String TAG = "AnomalyInfo";
private static final String KEY_ANOMALY_TYPE = "anomaly_type";
private static final String KEY_AUTO_RESTRICTION = "auto_restriction";
public final Integer anomalyType;
public final boolean autoRestriction;
public AnomalyInfo(String info) {
Log.i(TAG, "anomalyInfo: " + info);
KeyValueListParser parser = new KeyValueListParser(',');
parser.setString(info);
anomalyType = parser.getInt(KEY_ANOMALY_TYPE, -1);

View File

@@ -58,6 +58,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.shadows.ShadowJobScheduler;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -149,8 +150,9 @@ public class AnomalyDetectionJobServiceTest {
@Test
public void testSaveAnomalyToDatabase_normalAppWithAutoRestriction_save() {
mBundle.putStringArray(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES,
new String[]{SUBSCRIBER_COOKIES_AUTO_RESTRICTION});
final ArrayList<String> cookies = new ArrayList<>();
cookies.add(SUBSCRIBER_COOKIES_AUTO_RESTRICTION);
mBundle.putStringArrayList(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES, cookies);
doReturn(SYSTEM_PACKAGE).when(mBatteryUtils).getPackageName(anyInt());
doReturn(false).when(mPowerWhitelistBackend).isSysWhitelisted(SYSTEM_PACKAGE);
doReturn(Process.FIRST_APPLICATION_UID).when(
@@ -173,8 +175,9 @@ public class AnomalyDetectionJobServiceTest {
@Test
public void testSaveAnomalyToDatabase_normalAppWithoutAutoRestriction_save() {
mBundle.putStringArray(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES,
new String[]{SUBSCRIBER_COOKIES_NOT_AUTO_RESTRICTION});
final ArrayList<String> cookies = new ArrayList<>();
cookies.add(SUBSCRIBER_COOKIES_NOT_AUTO_RESTRICTION);
mBundle.putStringArrayList(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES, cookies);
doReturn(SYSTEM_PACKAGE).when(mBatteryUtils).getPackageName(anyInt());
doReturn(false).when(mPowerWhitelistBackend).isSysWhitelisted(SYSTEM_PACKAGE);
doReturn(Process.FIRST_APPLICATION_UID).when(