Add JobService to delete obsolete anomaly data

Bug: 72385333
Test: RunSettingsRoboTests
Change-Id: I73e16b9785fe0e832acc9e4256c8f9fd1333721e
This commit is contained in:
jackqdyulei
2018-02-16 10:06:08 -08:00
parent 10b7c0c39d
commit 338ae2fd71
7 changed files with 159 additions and 3 deletions

View File

@@ -0,0 +1,63 @@
/*
* 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.fuelgauge.batterytip;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.robolectric.RuntimeEnvironment.application;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowJobScheduler;
import java.util.List;
import java.util.concurrent.TimeUnit;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AnomalyCleanUpJobServiceTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void testScheduleCleanUp() {
AnomalyCleanUpJobService.scheduleCleanUp(application);
ShadowJobScheduler shadowJobScheduler = Shadows.shadowOf(
application.getSystemService(JobScheduler.class));
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
assertEquals(1, pendingJobs.size());
JobInfo pendingJob = pendingJobs.get(0);
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_clean_up);
assertThat(pendingJob.getMinLatencyMillis()).isEqualTo(TimeUnit.DAYS.toMillis(1));
assertThat(pendingJob.isRequireDeviceIdle()).isTrue();
}
}

View File

@@ -49,7 +49,8 @@ public class BatteryTipPolicyTest {
+ ",reduced_battery_enabled=true"
+ ",reduced_battery_percent=30"
+ ",low_battery_enabled=false"
+ ",low_battery_hour=10";
+ ",low_battery_hour=10"
+ ",data_history_retain_hour=24";
private Context mContext;
@Before
@@ -76,6 +77,7 @@ public class BatteryTipPolicyTest {
assertThat(batteryTipPolicy.reducedBatteryPercent).isEqualTo(30);
assertThat(batteryTipPolicy.lowBatteryEnabled).isFalse();
assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(10);
assertThat(batteryTipPolicy.dataHistoryRetainHour).isEqualTo(24);
}
@Test
@@ -97,6 +99,7 @@ public class BatteryTipPolicyTest {
assertThat(batteryTipPolicy.reducedBatteryPercent).isEqualTo(50);
assertThat(batteryTipPolicy.lowBatteryEnabled).isFalse();
assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(16);
assertThat(batteryTipPolicy.dataHistoryRetainHour).isEqualTo(72);
}
}