Merge "Fix a bug in AnomalyDetectionJobService" into pi-dev
This commit is contained in:
@@ -46,8 +46,6 @@ import android.app.job.JobWorkItem;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.Process;
|
||||
import android.os.StatsDimensionsValue;
|
||||
import android.os.UserManager;
|
||||
@@ -57,11 +55,11 @@ import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settings.testutils.shadow.ShadowPowerWhitelistBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -80,7 +78,7 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowConnectivityManager.class)
|
||||
@Config(shadows = {ShadowConnectivityManager.class, ShadowPowerWhitelistBackend.class})
|
||||
public class AnomalyDetectionJobServiceTest {
|
||||
private static final int UID = 12345;
|
||||
private static final String SYSTEM_PACKAGE = "com.android.system";
|
||||
@@ -91,8 +89,6 @@ public class AnomalyDetectionJobServiceTest {
|
||||
private static final int ANOMALY_TYPE = 6;
|
||||
private static final long VERSION_CODE = 15;
|
||||
@Mock
|
||||
private BatteryStatsHelper mBatteryStatsHelper;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private BatteryDatabaseManager mBatteryDatabaseManager;
|
||||
@@ -150,7 +146,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
doReturn(UID).when(mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
doReturn(true).when(mPowerWhitelistBackend).isWhitelisted(any(String[].class));
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider,
|
||||
@@ -171,7 +167,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
doReturn(true).when(mBatteryUtils).shouldHideAnomaly(any(), anyInt());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider,
|
||||
@@ -191,7 +187,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
doReturn(Process.SYSTEM_UID).when(
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
|
||||
@@ -206,7 +202,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
doReturn(AnomalyDetectionJobService.UID_NULL).when(
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
|
||||
@@ -226,7 +222,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
doReturn(Process.FIRST_APPLICATION_UID).when(
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
|
||||
@@ -251,7 +247,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
doReturn(Process.FIRST_APPLICATION_UID).when(
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
|
||||
@@ -316,4 +312,12 @@ public class AnomalyDetectionJobServiceTest {
|
||||
// Should not crash even job is stopped
|
||||
mAnomalyDetectionJobService.completeWork(mJobParameters, mJobWorkItem);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restartWorkAfterBeenStopped_jobStarted() {
|
||||
mAnomalyDetectionJobService.onStopJob(mJobParameters);
|
||||
mAnomalyDetectionJobService.onStartJob(mJobParameters);
|
||||
|
||||
assertThat(mAnomalyDetectionJobService.mIsJobCanceled).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@Implements(PowerWhitelistBackend.class)
|
||||
public class ShadowPowerWhitelistBackend {
|
||||
public void __constructor__() {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user