Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb90c955 authored by Lei Yu's avatar Lei Yu
Browse files

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
parent 4e25277f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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 {
+4 −0
Original line number Diff line number Diff line
@@ -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);
+7 −4
Original line number Diff line number Diff line
@@ -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(