Search in sources :

Example 41 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by omnirom.

the class BluetoothScanAnomalyDetectorTest method testDetectAnomalies_detectTargetAnomaly_detectIt.

@Test
public void testDetectAnomalies_detectTargetAnomaly_detectIt() {
    doReturn(TARGET_UID).when(mBatteryUtils).getPackageUid(TARGET_PACKAGE_NAME);
    final Anomaly targetAnomaly = createBluetoothAnomaly(TARGET_UID);
    List<Anomaly> mAnomalies = mBluetoothScanAnomalyDetector.detectAnomalies(mBatteryStatsHelper, TARGET_PACKAGE_NAME);
    assertThat(mAnomalies).containsExactly(targetAnomaly);
}
Also used : Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly) Test(org.junit.Test)

Example 42 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by omnirom.

the class PowerUsageAnomalyDetailsTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mAbnormalListGroup = spy(new PreferenceCategory(mContext));
    mAnomalyList = new ArrayList<>();
    Anomaly anomaly1 = new Anomaly.Builder().setType(Anomaly.AnomalyType.WAKE_LOCK).setPackageName(PACKAGE_NAME_1).setDisplayName(NAME_APP_1).build();
    mAnomalyList.add(anomaly1);
    Anomaly anomaly2 = new Anomaly.Builder().setType(Anomaly.AnomalyType.WAKEUP_ALARM).setPackageName(PACKAGE_NAME_2).setDisplayName(NAME_APP_2).build();
    mAnomalyList.add(anomaly2);
    Anomaly anomaly3 = new Anomaly.Builder().setType(Anomaly.AnomalyType.BLUETOOTH_SCAN).setPackageName(PACKAGE_NAME_3).setDisplayName(NAME_APP_3).build();
    mAnomalyList.add(anomaly3);
    mFragment = spy(new PowerUsageAnomalyDetails());
    mFragment.mAbnormalListGroup = mAbnormalListGroup;
    mFragment.mAnomalies = mAnomalyList;
    mFragment.mBatteryUtils = new BatteryUtils(mContext);
    mFragment.mPackageManager = mPackageManager;
    mFragment.mIconDrawableFactory = mIconDrawableFactory;
    doReturn(mPreferenceManager).when(mFragment).getPreferenceManager();
    doReturn(mContext).when(mPreferenceManager).getContext();
}
Also used : PreferenceCategory(android.support.v7.preference.PreferenceCategory) Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly) Before(org.junit.Before)

Example 43 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by DirtyUnicorns.

the class BluetoothScanAnomalyDetectorTest method testDetectAnomalies_containsAnomaly_detectIt.

@Test
public void testDetectAnomalies_containsAnomaly_detectIt() {
    doReturn(-1).when(mBatteryUtils).getPackageUid(nullable(String.class));
    final Anomaly anomaly = createBluetoothAnomaly(ANOMALY_UID);
    final Anomaly targetAnomaly = createBluetoothAnomaly(TARGET_UID);
    List<Anomaly> mAnomalies = mBluetoothScanAnomalyDetector.detectAnomalies(mBatteryStatsHelper);
    assertThat(mAnomalies).containsExactly(anomaly, targetAnomaly);
}
Also used : Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly) Test(org.junit.Test)

Example 44 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by DirtyUnicorns.

the class PowerUsageAnomalyDetails method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    if (preference instanceof AnomalyPreference) {
        AnomalyPreference anomalyPreference = (AnomalyPreference) preference;
        final Anomaly anomaly = anomalyPreference.getAnomaly();
        AnomalyDialogFragment dialogFragment = AnomalyDialogFragment.newInstance(anomaly, MetricsProto.MetricsEvent.FUELGAUGE_ANOMALY_DETAIL);
        dialogFragment.setTargetFragment(this, REQUEST_ANOMALY_ACTION);
        dialogFragment.show(getFragmentManager(), TAG);
        return true;
    }
    return super.onPreferenceTreeClick(preference);
}
Also used : AnomalyPreference(com.android.settings.fuelgauge.anomaly.AnomalyPreference) AnomalyDialogFragment(com.android.settings.fuelgauge.anomaly.AnomalyDialogFragment) Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly)

Example 45 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by DirtyUnicorns.

the class PowerUsageSummary method updateAnomalySparseArray.

@VisibleForTesting
void updateAnomalySparseArray(List<Anomaly> anomalies) {
    mAnomalySparseArray.clear();
    for (int i = 0, size = anomalies.size(); i < size; i++) {
        final Anomaly anomaly = anomalies.get(i);
        if (mAnomalySparseArray.get(anomaly.uid) == null) {
            mAnomalySparseArray.append(anomaly.uid, new ArrayList<>());
        }
        mAnomalySparseArray.get(anomaly.uid).add(anomaly);
    }
}
Also used : Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly) VisibleForTesting(android.support.annotation.VisibleForTesting)

Aggregations

Anomaly (com.android.settings.fuelgauge.anomaly.Anomaly)60 ArrayList (java.util.ArrayList)24 BatteryStats (android.os.BatteryStats)18 BatterySipper (com.android.internal.os.BatterySipper)18 Test (org.junit.Test)18 AnomalyPreference (com.android.settings.fuelgauge.anomaly.AnomalyPreference)12 Drawable (android.graphics.drawable.Drawable)6 VisibleForTesting (android.support.annotation.VisibleForTesting)6 Preference (android.support.v7.preference.Preference)6 PreferenceCategory (android.support.v7.preference.PreferenceCategory)6 AnomalyDialogFragment (com.android.settings.fuelgauge.anomaly.AnomalyDialogFragment)6 Before (org.junit.Before)6