Add control for the anomaly detection
Bug: 36924669 Test: RunSettingsRoboTests Change-Id: Id71b1324f567e7aa9b51dc25247fff9151d4e108
This commit is contained in:
@@ -92,7 +92,6 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
private static final String KEY_BATTERY_HEADER = "battery_header";
|
||||
private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 10;
|
||||
private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
|
||||
private static final int ANOMALY_LOADER = 1;
|
||||
|
||||
private static final String KEY_SCREEN_USAGE = "screen_usage";
|
||||
private static final String KEY_TIME_SINCE_LAST_FULL_CHARGE = "last_full_charge";
|
||||
@@ -101,6 +100,8 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
private static final String KEY_SCREEN_TIMEOUT = "screen_timeout_battery";
|
||||
private static final String KEY_BATTERY_SAVER_SUMMARY = "battery_saver_summary";
|
||||
|
||||
@VisibleForTesting
|
||||
static final int ANOMALY_LOADER = 1;
|
||||
private static final int MENU_STATS_TYPE = Menu.FIRST;
|
||||
@VisibleForTesting
|
||||
static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3;
|
||||
@@ -446,7 +447,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
return;
|
||||
}
|
||||
|
||||
getLoaderManager().initLoader(ANOMALY_LOADER, null, mAnomalyLoaderCallbacks);
|
||||
initAnomalyDetectionIfPossible();
|
||||
|
||||
final long elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000;
|
||||
Intent batteryBroadcast = context.registerReceiver(null,
|
||||
@@ -576,6 +577,13 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
BatteryEntry.startRequestQueue();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void initAnomalyDetectionIfPossible() {
|
||||
if (mPowerFeatureProvider.isAnomalyDetectionEnabled()) {
|
||||
getLoaderManager().initLoader(ANOMALY_LOADER, Bundle.EMPTY, mAnomalyLoaderCallbacks);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BatterySipper findBatterySipperByType(List<BatterySipper> usageList, DrainType type) {
|
||||
for (int i = 0, size = usageList.size(); i < size; i++) {
|
||||
|
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.app.LoaderManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.os.Process;
|
||||
import android.text.TextUtils;
|
||||
@@ -142,6 +144,8 @@ public class PowerUsageSummaryTest {
|
||||
private PowerManager mPowerManager;
|
||||
@Mock
|
||||
private SettingsActivity mSettingsActivity;
|
||||
@Mock
|
||||
private LoaderManager mLoaderManager;
|
||||
|
||||
private List<BatterySipper> mUsageList;
|
||||
private Context mRealContext;
|
||||
@@ -486,6 +490,18 @@ public class PowerUsageSummaryTest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInitAnomalyDetectionIfPossible_detectionEnabled_init() {
|
||||
when(mFeatureFactory.powerUsageFeatureProvider.isAnomalyDetectionEnabled()).thenReturn(
|
||||
true);
|
||||
doReturn(mLoaderManager).when(mFragment).getLoaderManager();
|
||||
|
||||
mFragment.initAnomalyDetectionIfPossible();
|
||||
|
||||
verify(mLoaderManager).initLoader(eq(PowerUsageSummary.ANOMALY_LOADER), eq(Bundle.EMPTY),
|
||||
any());
|
||||
}
|
||||
|
||||
public static class TestFragment extends PowerUsageSummary {
|
||||
|
||||
private Context mContext;
|
||||
|
Reference in New Issue
Block a user