Merge changes Icf6fafe9,I35eb3f0c,Ieec0c486,I8accb164 into pi-dev
* changes:
Set color of update line to red if update is older than six hours.
In Data Usage screen, Below the data bar, Add “X days left” field.
In Data Usage screen, add over-limit state.
Change text layout of data usage string.
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
index 83a79bc..5d0e71d 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
@@ -31,8 +31,9 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.os.Process;
import android.os.StatsDimensionsValue;
-import android.os.SystemPropertiesProto;
+import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
@@ -122,7 +123,8 @@
final boolean smartBatteryOn = Settings.Global.getInt(contentResolver,
Settings.Global.APP_STANDBY_ENABLED, ON) == ON;
final String packageName = batteryUtils.getPackageName(uid);
- if (!powerWhitelistBackend.isSysWhitelisted(packageName)) {
+ if (!powerWhitelistBackend.isSysWhitelistedExceptIdle(packageName)
+ && !isSystemUid(uid)) {
if (anomalyType == StatsManagerConfig.AnomalyType.EXCESSIVE_BG) {
// TODO(b/72385333): check battery percentage draining in batterystats
if (batteryUtils.isLegacyApp(packageName) && batteryUtils.isAppHeavilyUsed(
@@ -156,7 +158,7 @@
* 3. Bluetooth anomaly: 3:{1:{1:{1:10140|}|}|}
*/
@VisibleForTesting
- final int extractUidFromStatsDimensionsValue(StatsDimensionsValue statsDimensionsValue) {
+ int extractUidFromStatsDimensionsValue(StatsDimensionsValue statsDimensionsValue) {
//TODO(b/73172999): Add robo test for this method
if (statsDimensionsValue == null) {
return UID_NULL;
@@ -178,4 +180,9 @@
return UID_NULL;
}
+
+ private boolean isSystemUid(int uid) {
+ final int appUid = UserHandle.getAppId(uid);
+ return appUid >= Process.ROOT_UID && appUid < Process.FIRST_APPLICATION_UID;
+ }
}
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index 68c9731..ddda5d8 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -34,10 +34,10 @@
import java.util.Map;
import java.util.WeakHashMap;
-import androidx.app.slice.Slice;
-import androidx.app.slice.SliceProvider;
-import androidx.app.slice.builders.SliceAction;
-import androidx.app.slice.builders.ListBuilder;
+import androidx.slice.Slice;
+import androidx.slice.SliceProvider;
+import androidx.slice.builders.SliceAction;
+import androidx.slice.builders.ListBuilder;
/**
* A {@link SliceProvider} for Settings to enabled inline results in system apps.
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index e90ea8e..a1f27d1 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -35,10 +35,10 @@
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settingslib.core.AbstractPreferenceController;
-import androidx.app.slice.Slice;
-import androidx.app.slice.builders.SliceAction;
-import androidx.app.slice.builders.ListBuilder;
-import androidx.app.slice.builders.ListBuilder.RowBuilder;
+import androidx.slice.Slice;
+import androidx.slice.builders.SliceAction;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.ListBuilder.RowBuilder;
/**
* Utility class to build Slices objects and Preference Controllers based on the Database managed
diff --git a/src/com/android/settings/slices/SlicesDatabaseAccessor.java b/src/com/android/settings/slices/SlicesDatabaseAccessor.java
index 4fca63a..acd296b 100644
--- a/src/com/android/settings/slices/SlicesDatabaseAccessor.java
+++ b/src/com/android/settings/slices/SlicesDatabaseAccessor.java
@@ -28,7 +28,7 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.slices.SlicesDatabaseHelper.IndexColumns;
-import androidx.app.slice.Slice;
+import androidx.slice.Slice;
/**
* Class used to map a {@link Uri} from {@link SettingsSliceProvider} to a Slice.
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
index aa3d5a8..499ab9d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
@@ -18,11 +18,13 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.robolectric.RuntimeEnvironment.application;
@@ -32,6 +34,7 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.os.Process;
import android.os.StatsDimensionsValue;
import android.os.UserManager;
@@ -84,7 +87,7 @@
mBundle = new Bundle();
mBundle.putParcelable(StatsManager.EXTRA_STATS_DIMENSIONS_VALUE, mStatsDimensionsValue);
- mAnomalyDetectionJobService = new AnomalyDetectionJobService();
+ mAnomalyDetectionJobService = spy(new AnomalyDetectionJobService());
}
@Test
@@ -92,13 +95,14 @@
AnomalyDetectionJobService.scheduleAnomalyDetection(application, new Intent());
ShadowJobScheduler shadowJobScheduler =
- Shadows.shadowOf(application.getSystemService(JobScheduler.class));
+ Shadows.shadowOf(application.getSystemService(JobScheduler.class));
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
assertThat(pendingJobs).hasSize(1);
+
JobInfo pendingJob = pendingJobs.get(0);
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_detection);
assertThat(pendingJob.getMaxExecutionDelayMillis())
- .isEqualTo(TimeUnit.MINUTES.toMillis(30));
+ .isEqualTo(TimeUnit.MINUTES.toMillis(30));
}
@Test
@@ -115,9 +119,24 @@
}
@Test
+ public void testSaveAnomalyToDatabase_systemUid_doNotSave() {
+ doReturn(Process.SYSTEM_UID).when(
+ mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
+
+ mAnomalyDetectionJobService.saveAnomalyToDatabase(mBatteryStatsHelper, mUserManager,
+ mBatteryDatabaseManager, mBatteryUtils, mPolicy, mPowerWhitelistBackend,
+ mContext.getContentResolver(), mBundle);
+
+ verify(mBatteryDatabaseManager, never()).insertAnomaly(anyInt(), anyString(), anyInt(),
+ anyInt(), anyLong());
+ }
+
+ @Test
public void testSaveAnomalyToDatabase_normalApp_save() {
doReturn(SYSTEM_PACKAGE).when(mBatteryUtils).getPackageName(anyInt());
doReturn(false).when(mPowerWhitelistBackend).isSysWhitelisted(SYSTEM_PACKAGE);
+ doReturn(Process.FIRST_APPLICATION_UID).when(
+ mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
mAnomalyDetectionJobService.saveAnomalyToDatabase(mBatteryStatsHelper, mUserManager,
mBatteryDatabaseManager, mBatteryUtils, mPolicy, mPowerWhitelistBackend,
diff --git a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
index 9edae7e..8ddd48a 100644
--- a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
@@ -39,7 +39,7 @@
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
-import androidx.app.slice.Slice;
+import androidx.slice.Slice;
import java.util.HashMap;
diff --git a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
index 0fcce5f..39b381d 100644
--- a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
@@ -35,7 +35,7 @@
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
-import androidx.app.slice.Slice;
+import androidx.slice.Slice;
@RunWith(SettingsRobolectricTestRunner.class)
public class SliceBuilderUtilsTest {