Add system app check for anomaly detection.

In this CL, don't blame system app in anomaly detection and also
add log for it.

Following CL will update it to also check whether this system app
has launch entry.

Bug: 77477987
Test: RunSettingsRoboTests
Change-Id: I97490b32bc42ec2f8e03ec2d82f7c8bf89f9c66f
This commit is contained in:
Lei Yu
2018-04-10 10:54:33 -07:00
parent eaccf907e7
commit 6c4c7ba0fe
4 changed files with 113 additions and 20 deletions

View File

@@ -30,6 +30,7 @@ import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Process;
@@ -145,21 +146,24 @@ public class AnomalyDetectionJobService extends JobService {
: Settings.Global.getInt(contentResolver,
Settings.Global.APP_AUTO_RESTRICTION_ENABLED, ON) == ON;
final String packageName = batteryUtils.getPackageName(uid);
if (uid != UID_NULL && !isSystemUid(uid)
&& !powerWhitelistBackend.isSysWhitelistedExceptIdle(
packageManager.getPackagesForUid(uid))) {
boolean anomalyDetected = true;
if (anomalyInfo.anomalyType
== StatsManagerConfig.AnomalyType.EXCESSIVE_BACKGROUND_SERVICE) {
if (!batteryUtils.isPreOApp(packageName)
|| !batteryUtils.isAppHeavilyUsed(batteryStatsHelper, userManager, uid,
policy.excessiveBgDrainPercentage)) {
// Don't report if it is not legacy app or haven't used much battery
anomalyDetected = false;
}
}
if (anomalyDetected) {
final boolean anomalyDetected;
if (isExcessiveBackgroundAnomaly(anomalyInfo)) {
anomalyDetected = batteryUtils.isPreOApp(packageName)
&& batteryUtils.isAppHeavilyUsed(batteryStatsHelper, userManager, uid,
policy.excessiveBgDrainPercentage);
} else {
anomalyDetected = true;
}
if (anomalyDetected) {
if (batteryUtils.shouldHideAnomaly(powerWhitelistBackend, uid)) {
metricsFeatureProvider.action(context,
MetricsProto.MetricsEvent.ACTION_ANOMALY_IGNORED,
packageName,
Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT,
anomalyInfo.anomalyType));
} else {
if (autoFeatureOn && anomalyInfo.autoRestriction) {
// Auto restrict this app
batteryUtils.setForceAppStandby(uid, packageName,
@@ -215,8 +219,8 @@ public class AnomalyDetectionJobService extends JobService {
return UID_NULL;
}
private boolean isSystemUid(int uid) {
final int appUid = UserHandle.getAppId(uid);
return appUid >= Process.ROOT_UID && appUid < Process.FIRST_APPLICATION_UID;
private boolean isExcessiveBackgroundAnomaly(AnomalyInfo anomalyInfo) {
return anomalyInfo.anomalyType
== StatsManagerConfig.AnomalyType.EXCESSIVE_BACKGROUND_SERVICE;
}
}