Init BatteryUtils in constructor

In this case we won't have the NPE.

Bug: 63526637
Test: RunSettingsRoboTests
Change-Id: I20375e535ba07deddacf74052f31476e0cb28e56
This commit is contained in:
jackqdyulei
2017-07-10 11:00:05 -07:00
parent 8dc795d64b
commit 116fec5b25
2 changed files with 8 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ public class BackgroundCheckAction extends AnomalyAction {
super(context); super(context);
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_BACKGROUND_CHECK; mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_BACKGROUND_CHECK;
mBatteryUtils = BatteryUtils.getInstance(context);
} }
@Override @Override

View File

@@ -94,4 +94,11 @@ public class BackgroundCheckActionTest {
assertThat(mBackgroundCheckAction.isActionActive(mAnomaly)).isFalse(); assertThat(mBackgroundCheckAction.isActionActive(mAnomaly)).isFalse();
} }
@Test
public void testConstructor_batteryUtilsNotNull() {
mBackgroundCheckAction = new BackgroundCheckAction(mContext);
assertThat(mBackgroundCheckAction.mBatteryUtils).isNotNull();
}
} }