Don't drop log about excessive O anomaly.
Before this CL, we will drop log for excessive bg anomaly that target O or higher. This CL doesn't drop it however merge it to ACTION_ANOMALY_IGNORED Bug: 79944380 Test: RunSettingsRoboTests Change-Id: I46d0bdb1191d8843ba373e59afb1b0ba16057661
This commit is contained in:
@@ -45,6 +45,8 @@ import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
import com.android.settings.fuelgauge.batterytip.AnomalyInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.StatsManagerConfig;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
@@ -511,10 +513,25 @@ public class BatteryUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPreOApp(final String[] packageNames) {
|
||||
if (ArrayUtils.isEmpty(packageNames)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String packageName : packageNames) {
|
||||
if (isPreOApp(packageName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if we should hide anomaly app represented by {@code uid}
|
||||
*/
|
||||
public boolean shouldHideAnomaly(PowerWhitelistBackend powerWhitelistBackend, int uid) {
|
||||
public boolean shouldHideAnomaly(PowerWhitelistBackend powerWhitelistBackend, int uid,
|
||||
AnomalyInfo anomalyInfo) {
|
||||
final String[] packageNames = mPackageManager.getPackagesForUid(uid);
|
||||
if (ArrayUtils.isEmpty(packageNames)) {
|
||||
// Don't show it if app has been uninstalled
|
||||
@@ -522,7 +539,13 @@ public class BatteryUtils {
|
||||
}
|
||||
|
||||
return isSystemUid(uid) || powerWhitelistBackend.isWhitelisted(packageNames)
|
||||
|| (isSystemApp(mPackageManager, packageNames) && !hasLauncherEntry(packageNames));
|
||||
|| (isSystemApp(mPackageManager, packageNames) && !hasLauncherEntry(packageNames))
|
||||
|| (isExcessiveBackgroundAnomaly(anomalyInfo) && !isPreOApp(packageNames));
|
||||
}
|
||||
|
||||
private boolean isExcessiveBackgroundAnomaly(AnomalyInfo anomalyInfo) {
|
||||
return anomalyInfo.anomalyType
|
||||
== StatsManagerConfig.AnomalyType.EXCESSIVE_BACKGROUND_SERVICE;
|
||||
}
|
||||
|
||||
private boolean isSystemUid(int uid) {
|
||||
|
@@ -155,44 +155,36 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
final String packageName = batteryUtils.getPackageName(uid);
|
||||
final long versionCode = batteryUtils.getAppLongVersionCode(packageName);
|
||||
|
||||
final boolean anomalyDetected;
|
||||
if (isExcessiveBackgroundAnomaly(anomalyInfo)) {
|
||||
anomalyDetected = batteryUtils.isPreOApp(packageName);
|
||||
if (batteryUtils.shouldHideAnomaly(powerWhitelistBackend, uid, anomalyInfo)) {
|
||||
metricsFeatureProvider.action(context,
|
||||
MetricsProto.MetricsEvent.ACTION_ANOMALY_IGNORED,
|
||||
packageName,
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT,
|
||||
anomalyInfo.anomalyType),
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_APP_VERSION_CODE,
|
||||
versionCode));
|
||||
} else {
|
||||
anomalyDetected = true;
|
||||
if (autoFeatureOn && anomalyInfo.autoRestriction) {
|
||||
// Auto restrict this app
|
||||
batteryUtils.setForceAppStandby(uid, packageName,
|
||||
AppOpsManager.MODE_IGNORED);
|
||||
databaseManager.insertAnomaly(uid, packageName, anomalyInfo.anomalyType,
|
||||
AnomalyDatabaseHelper.State.AUTO_HANDLED,
|
||||
timeMs);
|
||||
} else {
|
||||
databaseManager.insertAnomaly(uid, packageName, anomalyInfo.anomalyType,
|
||||
AnomalyDatabaseHelper.State.NEW,
|
||||
timeMs);
|
||||
}
|
||||
metricsFeatureProvider.action(context,
|
||||
MetricsProto.MetricsEvent.ACTION_ANOMALY_TRIGGERED,
|
||||
packageName,
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_ANOMALY_TYPE,
|
||||
anomalyInfo.anomalyType),
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_APP_VERSION_CODE,
|
||||
versionCode));
|
||||
}
|
||||
|
||||
if (anomalyDetected) {
|
||||
if (batteryUtils.shouldHideAnomaly(powerWhitelistBackend, uid)) {
|
||||
metricsFeatureProvider.action(context,
|
||||
MetricsProto.MetricsEvent.ACTION_ANOMALY_IGNORED,
|
||||
packageName,
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT,
|
||||
anomalyInfo.anomalyType),
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_APP_VERSION_CODE,
|
||||
versionCode));
|
||||
} else {
|
||||
if (autoFeatureOn && anomalyInfo.autoRestriction) {
|
||||
// Auto restrict this app
|
||||
batteryUtils.setForceAppStandby(uid, packageName,
|
||||
AppOpsManager.MODE_IGNORED);
|
||||
databaseManager.insertAnomaly(uid, packageName, anomalyInfo.anomalyType,
|
||||
AnomalyDatabaseHelper.State.AUTO_HANDLED,
|
||||
timeMs);
|
||||
} else {
|
||||
databaseManager.insertAnomaly(uid, packageName, anomalyInfo.anomalyType,
|
||||
AnomalyDatabaseHelper.State.NEW,
|
||||
timeMs);
|
||||
}
|
||||
metricsFeatureProvider.action(context,
|
||||
MetricsProto.MetricsEvent.ACTION_ANOMALY_TRIGGERED,
|
||||
packageName,
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_ANOMALY_TYPE,
|
||||
anomalyInfo.anomalyType),
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_APP_VERSION_CODE,
|
||||
versionCode));
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException | IndexOutOfBoundsException e) {
|
||||
Log.e(TAG, "Parse stats dimensions value error.", e);
|
||||
}
|
||||
@@ -229,11 +221,6 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
return UID_NULL;
|
||||
}
|
||||
|
||||
private boolean isExcessiveBackgroundAnomaly(AnomalyInfo anomalyInfo) {
|
||||
return anomalyInfo.anomalyType
|
||||
== StatsManagerConfig.AnomalyType.EXCESSIVE_BACKGROUND_SERVICE;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
JobWorkItem dequeueWork(JobParameters parameters) {
|
||||
synchronized (mLock) {
|
||||
|
Reference in New Issue
Block a user