Move the default configs in AppBatteryTracker into resources
..so it could be overlaid by different device configs. Bug: 200326767 Bug: 203105544 Test: atest FrameworksMockingServicesTests:BackgroundRestrictionTest Change-Id: Iffa7ff2b7fb8f14f1a54359d72d936c721d27904
This commit is contained in:
@@ -5687,4 +5687,75 @@
|
||||
-->
|
||||
<string-array name="config_dockExtconStateMapping">
|
||||
</string-array>
|
||||
|
||||
<!-- Whether or not the monitoring on the apps' background battery drain is enabled -->
|
||||
<bool name="config_bg_current_drain_monitor_enabled">true</bool>
|
||||
|
||||
<!-- The threshold of the background current drain (in percentage) to the restricted
|
||||
standby bucket.
|
||||
-->
|
||||
<array name="config_bg_current_drain_threshold_to_restricted_bucket">
|
||||
<item>2.0</item> <!-- regular device -->
|
||||
<item>4.0</item> <!-- low ram device -->
|
||||
</array>
|
||||
|
||||
<!-- The threshold of the background current drain (in percentage) to the background
|
||||
restricted level.
|
||||
-->
|
||||
<array name="config_bg_current_drain_threshold_to_bg_restricted">
|
||||
<item>4.0</item> <!-- regular device -->
|
||||
<item>8.0</item> <!-- low ram device -->
|
||||
</array>
|
||||
|
||||
<!-- The background current drain monitoring window size. -->
|
||||
<integer name="config_bg_current_drain_window">86400</integer>
|
||||
|
||||
<!-- The types of battery drain we're checking on each app; if the sum of the battery drain
|
||||
exceeds the threshold, it'll be moved to restricted standby bucket. The value must be
|
||||
one of or combination of the definitions in AppBatteryPolicy.
|
||||
-->
|
||||
<integer name="config_bg_current_drain_types_to_restricted_bucket">4</integer>
|
||||
|
||||
<!-- The types of battery drain we're checking on each app; if the sum of the battery drain
|
||||
exceeds the threshold, it'll be moved to background restricted level. The value must be
|
||||
one of or combination of the definitions in AppBatteryPolicy.
|
||||
-->
|
||||
<integer name="config_bg_current_drain_types_to_bg_restricted">12</integer>
|
||||
|
||||
<!-- The power usage components we're monitoring. Must one of the definition in BatteryConsumer.
|
||||
-->
|
||||
<integer name="config_bg_current_drain_power_components">-1</integer>
|
||||
|
||||
<!-- Whether or not enable the different threshold based on the durations of
|
||||
certain event type.
|
||||
-->
|
||||
<bool name="config_bg_current_drain_event_duration_based_threshold_enabled">false</bool>
|
||||
|
||||
<!-- The threshold of the background current drain (in percentage) to the restricted
|
||||
standby bucket for legitimate case with higher background current drain.
|
||||
-->
|
||||
<array name="config_bg_current_drain_high_threshold_to_restricted_bucket">
|
||||
<item>30.0</item> <!-- regular device -->
|
||||
<item>60.0</item> <!-- low ram device -->
|
||||
</array>
|
||||
|
||||
<!-- The threshold of the background current drain (in percentage) to the background
|
||||
restricted level for legitimate case with higher background current drain.
|
||||
-->
|
||||
<array name="config_bg_current_drain_high_threshold_to_bg_restricted">
|
||||
<item>20.0</item> <!-- regular device -->
|
||||
<item>40.0</item> <!-- low ram device -->
|
||||
</array>
|
||||
|
||||
<!-- The threshold of minimal time of hosting a foreground service with type "mediaPlayback"
|
||||
or a media session, over the given window, so it'd subject towards the higher background
|
||||
current drain threshold.
|
||||
-->
|
||||
<integer name="config_bg_current_drain_media_playback_min_duration">1800</integer>
|
||||
|
||||
<!-- The threshold of minimal time of hosting a foreground service with type "location"
|
||||
over the given window, so it'd subject towards the higher background
|
||||
current drain threshold.
|
||||
-->
|
||||
<integer name="config_bg_current_drain_location_min_duration">1800</integer>
|
||||
</resources>
|
||||
|
||||
@@ -4730,4 +4730,17 @@
|
||||
<java-symbol type="integer" name="config_lowPowerStandbyNonInteractiveTimeout" />
|
||||
|
||||
<java-symbol type="color" name="camera_privacy_light"/>
|
||||
|
||||
<java-symbol type="bool" name="config_bg_current_drain_monitor_enabled" />
|
||||
<java-symbol type="array" name="config_bg_current_drain_threshold_to_restricted_bucket" />
|
||||
<java-symbol type="array" name="config_bg_current_drain_threshold_to_bg_restricted" />
|
||||
<java-symbol type="integer" name="config_bg_current_drain_window" />
|
||||
<java-symbol type="integer" name="config_bg_current_drain_types_to_restricted_bucket" />
|
||||
<java-symbol type="integer" name="config_bg_current_drain_types_to_bg_restricted" />
|
||||
<java-symbol type="integer" name="config_bg_current_drain_power_components" />
|
||||
<java-symbol type="bool" name="config_bg_current_drain_event_duration_based_threshold_enabled" />
|
||||
<java-symbol type="array" name="config_bg_current_drain_high_threshold_to_restricted_bucket" />
|
||||
<java-symbol type="array" name="config_bg_current_drain_high_threshold_to_bg_restricted" />
|
||||
<java-symbol type="integer" name="config_bg_current_drain_media_playback_min_duration" />
|
||||
<java-symbol type="integer" name="config_bg_current_drain_location_min_duration" />
|
||||
</resources>
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.os.SystemClock;
|
||||
import android.util.Pair;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.server.am.AppBatteryExemptionTracker.AppBatteryExemptionPolicy;
|
||||
import com.android.server.am.AppBatteryExemptionTracker.UidBatteryStates;
|
||||
@@ -454,7 +455,8 @@ final class AppBatteryExemptionTracker
|
||||
super(injector, tracker,
|
||||
KEY_BG_BATTERY_EXEMPTION_ENABLED, DEFAULT_BG_BATTERY_EXEMPTION_ENABLED,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_WINDOW,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_WINDOW_MS);
|
||||
tracker.mContext.getResources()
|
||||
.getInteger(R.integer.config_bg_current_drain_window));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,6 @@ import static android.util.TimeUtils.formatTime;
|
||||
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
|
||||
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
|
||||
import static com.android.server.am.AppRestrictionController.DEVICE_CONFIG_SUBNAMESPACE_PREFIX;
|
||||
import static com.android.server.am.BaseAppStateTracker.ONE_DAY;
|
||||
import static com.android.server.am.BaseAppStateTracker.ONE_MINUTE;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
@@ -47,6 +46,8 @@ import android.annotation.UserIdInt;
|
||||
import android.app.ActivityManager.RestrictionLevel;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.BatteryConsumer;
|
||||
import android.os.BatteryConsumer.Dimensions;
|
||||
import android.os.BatteryStatsInternal;
|
||||
@@ -64,6 +65,7 @@ import android.util.SparseArray;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.util.TimeUtils;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
@@ -1024,71 +1026,59 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
|
||||
static final String KEY_BG_CURRENT_DRAIN_POWER_COMPONENTS =
|
||||
DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "current_drain_power_components";
|
||||
|
||||
/**
|
||||
* Default value to {@link #mTrackerEnabled}.
|
||||
*/
|
||||
static final boolean DEFAULT_BG_CURRENT_DRAIN_MONITOR_ENABLED = true;
|
||||
|
||||
/**
|
||||
* Default value to the {@link #INDEX_REGULAR_CURRENT_DRAIN_THRESHOLD} of
|
||||
* the {@link #mBgCurrentDrainRestrictedBucketThreshold}.
|
||||
*/
|
||||
static final float DEFAULT_BG_CURRENT_DRAIN_RESTRICTED_BUCKET_THRESHOLD =
|
||||
isLowRamDeviceStatic() ? 4.0f : 2.0f;
|
||||
final float mDefaultBgCurrentDrainRestrictedBucket;
|
||||
|
||||
/**
|
||||
* Default value to the {@link #INDEX_REGULAR_CURRENT_DRAIN_THRESHOLD} of
|
||||
* the {@link #mBgCurrentDrainBgRestrictedThreshold}.
|
||||
*/
|
||||
static final float DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_THRESHOLD =
|
||||
isLowRamDeviceStatic() ? 8.0f : 4.0f;
|
||||
final float mDefaultBgCurrentDrainBgRestrictedThreshold;
|
||||
|
||||
/**
|
||||
* Default value to {@link #mBgCurrentDrainWindowMs}.
|
||||
*/
|
||||
static final long DEFAULT_BG_CURRENT_DRAIN_WINDOW_MS = ONE_DAY;
|
||||
final long mDefaultBgCurrentDrainWindowMs;
|
||||
|
||||
/**
|
||||
* Default value to the {@link #INDEX_HIGH_CURRENT_DRAIN_THRESHOLD} of
|
||||
* the {@link #mBgCurrentDrainRestrictedBucketThreshold}.
|
||||
*/
|
||||
static final float DEFAULT_BG_CURRENT_DRAIN_RESTRICTED_BUCKET_HIGH_THRESHOLD =
|
||||
isLowRamDeviceStatic() ? 60.0f : 30.0f;
|
||||
final float mDefaultBgCurrentDrainRestrictedBucketHighThreshold;
|
||||
|
||||
/**
|
||||
* Default value to the {@link #INDEX_HIGH_CURRENT_DRAIN_THRESHOLD} of
|
||||
* the {@link #mBgCurrentDrainBgRestrictedThreshold}.
|
||||
*/
|
||||
static final float DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_HIGH_THRESHOLD =
|
||||
isLowRamDeviceStatic() ? 60.0f : 30.0f;
|
||||
final float mDefaultBgCurrentDrainBgRestrictedHighThreshold;
|
||||
|
||||
/**
|
||||
* Default value to {@link #mBgCurrentDrainMediaPlaybackMinDuration}.
|
||||
*/
|
||||
static final long DEFAULT_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION = 30 * ONE_MINUTE;
|
||||
final long mDefaultBgCurrentDrainMediaPlaybackMinDuration;
|
||||
|
||||
/**
|
||||
* Default value to {@link #mBgCurrentDrainLocationMinDuration}.
|
||||
*/
|
||||
static final long DEFAULT_BG_CURRENT_DRAIN_LOCATION_MIN_DURATION = 30 * ONE_MINUTE;
|
||||
final long mDefaultBgCurrentDrainLocationMinDuration;
|
||||
|
||||
/**
|
||||
* Default value to {@link #mBgCurrentDrainEventDurationBasedThresholdEnabled}.
|
||||
*/
|
||||
static final boolean DEFAULT_BG_CURRENT_DRAIN_EVENT_DURATION_BASED_THRESHOLD_ENABLED =
|
||||
false;
|
||||
final boolean mDefaultBgCurrentDrainEventDurationBasedThresholdEnabled;
|
||||
|
||||
/**
|
||||
* Default value to {@link #mBgCurrentDrainRestrictedBucketTypes}.
|
||||
*/
|
||||
static final int DEFAULT_BG_CURRENT_DRAIN_TYPES_TO_RESTRICTED_BUCKET =
|
||||
BATTERY_USAGE_TYPE_BACKGROUND;
|
||||
final int mDefaultCurrentDrainTypesToRestrictedBucket;
|
||||
|
||||
/**
|
||||
* Default value to {@link #mBgCurrentDrainBgRestrictedTypes}.
|
||||
*/
|
||||
static final int DEFAULT_BG_CURRENT_DRAIN_TYPES_TO_BG_RESTRICTED =
|
||||
BATTERY_USAGE_TYPE_BACKGROUND | BATTERY_USAGE_TYPE_FOREGROUND_SERVICE;
|
||||
final int mDefaultBgCurrentDrainTypesToBgRestricted;
|
||||
|
||||
/**
|
||||
* Default value to {@link #mBgCurrentDrainPowerComponents}.
|
||||
@@ -1096,6 +1086,8 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
|
||||
@BatteryConsumer.PowerComponent
|
||||
static final int DEFAULT_BG_CURRENT_DRAIN_POWER_COMPONENTS = POWER_COMPONENT_ANY;
|
||||
|
||||
final int mDefaultBgCurrentDrainPowerComponent;
|
||||
|
||||
/**
|
||||
* The index to {@link #mBgCurrentDrainRestrictedBucketThreshold}
|
||||
* and {@link #mBgCurrentDrainBgRestrictedThreshold}.
|
||||
@@ -1107,36 +1099,28 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
|
||||
* @see #KEY_BG_CURRENT_DRAIN_THRESHOLD_TO_RESTRICTED_BUCKET.
|
||||
* @see #KEY_BG_CURRENT_DRAIN_HIGH_THRESHOLD_TO_RESTRICTED_BUCKET.
|
||||
*/
|
||||
volatile float[] mBgCurrentDrainRestrictedBucketThreshold = {
|
||||
DEFAULT_BG_CURRENT_DRAIN_RESTRICTED_BUCKET_THRESHOLD,
|
||||
DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_HIGH_THRESHOLD,
|
||||
};
|
||||
volatile float[] mBgCurrentDrainRestrictedBucketThreshold = new float[2];
|
||||
|
||||
/**
|
||||
* @see #KEY_BG_CURRENT_DRAIN_THRESHOLD_TO_BG_RESTRICTED.
|
||||
* @see #KEY_BG_CURRENT_DRAIN_HIGH_THRESHOLD_TO_BG_RESTRICTED.
|
||||
*/
|
||||
volatile float[] mBgCurrentDrainBgRestrictedThreshold = {
|
||||
DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_THRESHOLD,
|
||||
DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_HIGH_THRESHOLD,
|
||||
};
|
||||
volatile float[] mBgCurrentDrainBgRestrictedThreshold = new float[2];
|
||||
|
||||
/**
|
||||
* @see #KEY_BG_CURRENT_DRAIN_WINDOW.
|
||||
*/
|
||||
volatile long mBgCurrentDrainWindowMs = DEFAULT_BG_CURRENT_DRAIN_WINDOW_MS;
|
||||
volatile long mBgCurrentDrainWindowMs;
|
||||
|
||||
/**
|
||||
* @see #KEY_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION.
|
||||
*/
|
||||
volatile long mBgCurrentDrainMediaPlaybackMinDuration =
|
||||
DEFAULT_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION;
|
||||
volatile long mBgCurrentDrainMediaPlaybackMinDuration;
|
||||
|
||||
/**
|
||||
* @see #KEY_BG_CURRENT_DRAIN_LOCATION_MIN_DURATION.
|
||||
*/
|
||||
volatile long mBgCurrentDrainLocationMinDuration =
|
||||
DEFAULT_BG_CURRENT_DRAIN_LOCATION_MIN_DURATION;
|
||||
volatile long mBgCurrentDrainLocationMinDuration;
|
||||
|
||||
/**
|
||||
* @see #KEY_BG_CURRENT_DRAIN_EVENT_DURATION_BASED_THRESHOLD_ENABLED.
|
||||
@@ -1183,8 +1167,62 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
|
||||
|
||||
AppBatteryPolicy(@NonNull Injector injector, @NonNull AppBatteryTracker tracker) {
|
||||
super(injector, tracker, KEY_BG_CURRENT_DRAIN_MONITOR_ENABLED,
|
||||
DEFAULT_BG_CURRENT_DRAIN_MONITOR_ENABLED);
|
||||
tracker.mContext.getResources()
|
||||
.getBoolean(R.bool.config_bg_current_drain_monitor_enabled));
|
||||
mLock = tracker.mLock;
|
||||
final Resources resources = tracker.mContext.getResources();
|
||||
float[] val = getFloatArray(resources.obtainTypedArray(
|
||||
R.array.config_bg_current_drain_threshold_to_restricted_bucket));
|
||||
mDefaultBgCurrentDrainRestrictedBucket =
|
||||
isLowRamDeviceStatic() ? val[1] : val[0];
|
||||
val = getFloatArray(resources.obtainTypedArray(
|
||||
R.array.config_bg_current_drain_threshold_to_bg_restricted));
|
||||
mDefaultBgCurrentDrainBgRestrictedThreshold =
|
||||
isLowRamDeviceStatic() ? val[1] : val[0];
|
||||
mDefaultBgCurrentDrainWindowMs = resources.getInteger(
|
||||
R.integer.config_bg_current_drain_window);
|
||||
val = getFloatArray(resources.obtainTypedArray(
|
||||
R.array.config_bg_current_drain_high_threshold_to_restricted_bucket));
|
||||
mDefaultBgCurrentDrainRestrictedBucketHighThreshold =
|
||||
isLowRamDeviceStatic() ? val[1] : val[0];
|
||||
val = getFloatArray(resources.obtainTypedArray(
|
||||
R.array.config_bg_current_drain_high_threshold_to_bg_restricted));
|
||||
mDefaultBgCurrentDrainBgRestrictedHighThreshold =
|
||||
isLowRamDeviceStatic() ? val[1] : val[0];
|
||||
mDefaultBgCurrentDrainMediaPlaybackMinDuration = resources.getInteger(
|
||||
R.integer.config_bg_current_drain_media_playback_min_duration);
|
||||
mDefaultBgCurrentDrainLocationMinDuration = resources.getInteger(
|
||||
R.integer.config_bg_current_drain_location_min_duration);
|
||||
mDefaultBgCurrentDrainEventDurationBasedThresholdEnabled = resources.getBoolean(
|
||||
R.bool.config_bg_current_drain_event_duration_based_threshold_enabled);
|
||||
mDefaultCurrentDrainTypesToRestrictedBucket = resources.getInteger(
|
||||
R.integer.config_bg_current_drain_types_to_restricted_bucket);
|
||||
mDefaultBgCurrentDrainTypesToBgRestricted = resources.getInteger(
|
||||
R.integer.config_bg_current_drain_types_to_bg_restricted);
|
||||
mDefaultBgCurrentDrainPowerComponent = resources.getInteger(
|
||||
R.integer.config_bg_current_drain_power_components);
|
||||
mBgCurrentDrainRestrictedBucketThreshold[0] =
|
||||
mDefaultBgCurrentDrainRestrictedBucket;
|
||||
mBgCurrentDrainRestrictedBucketThreshold[1] =
|
||||
mDefaultBgCurrentDrainRestrictedBucketHighThreshold;
|
||||
mBgCurrentDrainBgRestrictedThreshold[0] =
|
||||
mDefaultBgCurrentDrainBgRestrictedThreshold;
|
||||
mBgCurrentDrainBgRestrictedThreshold[1] =
|
||||
mDefaultBgCurrentDrainBgRestrictedHighThreshold;
|
||||
mBgCurrentDrainWindowMs = mDefaultBgCurrentDrainWindowMs;
|
||||
mBgCurrentDrainMediaPlaybackMinDuration =
|
||||
mDefaultBgCurrentDrainMediaPlaybackMinDuration;
|
||||
mBgCurrentDrainLocationMinDuration = mDefaultBgCurrentDrainLocationMinDuration;
|
||||
}
|
||||
|
||||
static float[] getFloatArray(TypedArray array) {
|
||||
int length = array.length();
|
||||
float[] floatArray = new float[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
floatArray[i] = array.getFloat(i, Float.NaN);
|
||||
}
|
||||
array.recycle();
|
||||
return floatArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1234,31 +1272,31 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
|
||||
mBgCurrentDrainRestrictedBucketThreshold[INDEX_REGULAR_CURRENT_DRAIN_THRESHOLD] =
|
||||
DeviceConfig.getFloat(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_THRESHOLD_TO_RESTRICTED_BUCKET,
|
||||
DEFAULT_BG_CURRENT_DRAIN_RESTRICTED_BUCKET_THRESHOLD);
|
||||
mDefaultBgCurrentDrainRestrictedBucket);
|
||||
mBgCurrentDrainRestrictedBucketThreshold[INDEX_HIGH_CURRENT_DRAIN_THRESHOLD] =
|
||||
DeviceConfig.getFloat(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_HIGH_THRESHOLD_TO_RESTRICTED_BUCKET,
|
||||
DEFAULT_BG_CURRENT_DRAIN_RESTRICTED_BUCKET_HIGH_THRESHOLD);
|
||||
mDefaultBgCurrentDrainRestrictedBucketHighThreshold);
|
||||
mBgCurrentDrainBgRestrictedThreshold[INDEX_REGULAR_CURRENT_DRAIN_THRESHOLD] =
|
||||
DeviceConfig.getFloat(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_THRESHOLD_TO_BG_RESTRICTED,
|
||||
DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_THRESHOLD);
|
||||
mDefaultBgCurrentDrainBgRestrictedThreshold);
|
||||
mBgCurrentDrainBgRestrictedThreshold[INDEX_HIGH_CURRENT_DRAIN_THRESHOLD] =
|
||||
DeviceConfig.getFloat(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_HIGH_THRESHOLD_TO_BG_RESTRICTED,
|
||||
DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_HIGH_THRESHOLD);
|
||||
mDefaultBgCurrentDrainBgRestrictedHighThreshold);
|
||||
mBgCurrentDrainRestrictedBucketTypes =
|
||||
DeviceConfig.getInt(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_TYPES_TO_RESTRICTED_BUCKET,
|
||||
DEFAULT_BG_CURRENT_DRAIN_TYPES_TO_RESTRICTED_BUCKET);
|
||||
mDefaultCurrentDrainTypesToRestrictedBucket);
|
||||
mBgCurrentDrainBgRestrictedTypes =
|
||||
DeviceConfig.getInt(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_TYPES_TO_BG_RESTRICTED,
|
||||
DEFAULT_BG_CURRENT_DRAIN_TYPES_TO_BG_RESTRICTED);
|
||||
mDefaultBgCurrentDrainTypesToBgRestricted);
|
||||
mBgCurrentDrainPowerComponents =
|
||||
DeviceConfig.getInt(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_POWER_COMPONENTS,
|
||||
DEFAULT_BG_CURRENT_DRAIN_POWER_COMPONENTS);
|
||||
mDefaultBgCurrentDrainPowerComponent);
|
||||
if (mBgCurrentDrainPowerComponents == DEFAULT_BG_CURRENT_DRAIN_POWER_COMPONENTS) {
|
||||
mBatteryDimensions = BatteryUsage.BATT_DIMENS;
|
||||
} else {
|
||||
@@ -1273,28 +1311,28 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
|
||||
mBgCurrentDrainWindowMs = DeviceConfig.getLong(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_WINDOW,
|
||||
DEFAULT_BG_CURRENT_DRAIN_WINDOW_MS);
|
||||
mDefaultBgCurrentDrainWindowMs);
|
||||
}
|
||||
|
||||
private void updateCurrentDrainMediaPlaybackMinDuration() {
|
||||
mBgCurrentDrainMediaPlaybackMinDuration = DeviceConfig.getLong(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION,
|
||||
DEFAULT_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION);
|
||||
mDefaultBgCurrentDrainMediaPlaybackMinDuration);
|
||||
}
|
||||
|
||||
private void updateCurrentDrainLocationMinDuration() {
|
||||
mBgCurrentDrainLocationMinDuration = DeviceConfig.getLong(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_LOCATION_MIN_DURATION,
|
||||
DEFAULT_BG_CURRENT_DRAIN_LOCATION_MIN_DURATION);
|
||||
mDefaultBgCurrentDrainLocationMinDuration);
|
||||
}
|
||||
|
||||
private void updateCurrentDrainEventDurationBasedThresholdEnabled() {
|
||||
mBgCurrentDrainEventDurationBasedThresholdEnabled = DeviceConfig.getBoolean(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_BG_CURRENT_DRAIN_EVENT_DURATION_BASED_THRESHOLD_ENABLED,
|
||||
DEFAULT_BG_CURRENT_DRAIN_EVENT_DURATION_BASED_THRESHOLD_ENABLED);
|
||||
mDefaultBgCurrentDrainEventDurationBasedThresholdEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import static android.app.ActivityManager.RESTRICTION_LEVEL_ADAPTIVE_BUCKET;
|
||||
import static android.app.ActivityManager.RESTRICTION_LEVEL_BACKGROUND_RESTRICTED;
|
||||
import static android.app.ActivityManager.RESTRICTION_LEVEL_EXEMPTED;
|
||||
import static android.app.ActivityManager.RESTRICTION_LEVEL_RESTRICTED_BUCKET;
|
||||
import static android.app.ActivityManager.isLowRamDeviceStatic;
|
||||
import static android.app.usage.UsageStatsManager.REASON_MAIN_FORCED_BY_SYSTEM;
|
||||
import static android.app.usage.UsageStatsManager.REASON_MAIN_FORCED_BY_USER;
|
||||
import static android.app.usage.UsageStatsManager.REASON_MAIN_USAGE;
|
||||
@@ -46,6 +47,7 @@ import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE;
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
|
||||
import static com.android.internal.notification.SystemNotificationChannels.ABUSIVE_BACKGROUND_APPS;
|
||||
import static com.android.server.am.AppBatteryTracker.AppBatteryPolicy.getFloatArray;
|
||||
import static com.android.server.am.AppBatteryTracker.BatteryUsage.BATTERY_USAGE_INDEX_BACKGROUND;
|
||||
import static com.android.server.am.AppBatteryTracker.BatteryUsage.BATTERY_USAGE_INDEX_FOREGROUND;
|
||||
import static com.android.server.am.AppBatteryTracker.BatteryUsage.BATTERY_USAGE_INDEX_FOREGROUND_SERVICE;
|
||||
@@ -108,6 +110,7 @@ import android.util.Pair;
|
||||
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.server.AppStateTracker;
|
||||
import com.android.server.DeviceIdleInternal;
|
||||
import com.android.server.am.AppBatteryExemptionTracker.AppBatteryExemptionPolicy;
|
||||
@@ -554,28 +557,34 @@ public final class BackgroundRestrictionTest {
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_MONITOR_ENABLED,
|
||||
DeviceConfig::getBoolean,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_MONITOR_ENABLED);
|
||||
mContext.getResources().getBoolean(
|
||||
R.bool.config_bg_current_drain_monitor_enabled));
|
||||
bgCurrentDrainMonitor.set(true);
|
||||
|
||||
bgCurrentDrainWindow = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_WINDOW,
|
||||
DeviceConfig::getLong,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_WINDOW_MS);
|
||||
(long) mContext.getResources().getInteger(
|
||||
R.integer.config_bg_current_drain_window));
|
||||
bgCurrentDrainWindow.set(windowMs);
|
||||
|
||||
bgCurrentDrainRestrictedBucketThreshold = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_THRESHOLD_TO_RESTRICTED_BUCKET,
|
||||
DeviceConfig::getFloat,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_RESTRICTED_BUCKET_THRESHOLD);
|
||||
getFloatArray(mContext.getResources().obtainTypedArray(
|
||||
R.array.config_bg_current_drain_threshold_to_restricted_bucket))[
|
||||
isLowRamDeviceStatic() ? 1 : 0]);
|
||||
bgCurrentDrainRestrictedBucketThreshold.set(restrictBucketThreshold);
|
||||
|
||||
bgCurrentDrainBgRestrictedThreshold = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_THRESHOLD_TO_BG_RESTRICTED,
|
||||
DeviceConfig::getFloat,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_THRESHOLD);
|
||||
getFloatArray(mContext.getResources().obtainTypedArray(
|
||||
R.array.config_bg_current_drain_threshold_to_bg_restricted))[
|
||||
isLowRamDeviceStatic() ? 1 : 0]);
|
||||
bgCurrentDrainBgRestrictedThreshold.set(bgRestrictedThreshold);
|
||||
|
||||
mCurrentTimeMillis = 10_000L;
|
||||
@@ -1282,64 +1291,76 @@ public final class BackgroundRestrictionTest {
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_MONITOR_ENABLED,
|
||||
DeviceConfig::getBoolean,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_MONITOR_ENABLED);
|
||||
mContext.getResources().getBoolean(
|
||||
R.bool.config_bg_current_drain_monitor_enabled));
|
||||
bgCurrentDrainMonitor.set(true);
|
||||
|
||||
bgCurrentDrainWindow = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_WINDOW,
|
||||
DeviceConfig::getLong,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_WINDOW_MS);
|
||||
(long) mContext.getResources().getInteger(
|
||||
R.integer.config_bg_current_drain_window));
|
||||
bgCurrentDrainWindow.set(windowMs);
|
||||
|
||||
bgCurrentDrainRestrictedBucketThreshold = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_THRESHOLD_TO_RESTRICTED_BUCKET,
|
||||
DeviceConfig::getFloat,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_RESTRICTED_BUCKET_THRESHOLD);
|
||||
getFloatArray(mContext.getResources().obtainTypedArray(
|
||||
R.array.config_bg_current_drain_threshold_to_restricted_bucket))[
|
||||
isLowRamDeviceStatic() ? 1 : 0]);
|
||||
bgCurrentDrainRestrictedBucketThreshold.set(restrictBucketThreshold);
|
||||
|
||||
bgCurrentDrainBgRestrictedThreshold = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_THRESHOLD_TO_BG_RESTRICTED,
|
||||
DeviceConfig::getFloat,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_THRESHOLD);
|
||||
getFloatArray(mContext.getResources().obtainTypedArray(
|
||||
R.array.config_bg_current_drain_threshold_to_bg_restricted))[
|
||||
isLowRamDeviceStatic() ? 1 : 0]);
|
||||
bgCurrentDrainBgRestrictedThreshold.set(bgRestrictedThreshold);
|
||||
|
||||
bgCurrentDrainRestrictedBucketHighThreshold = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_HIGH_THRESHOLD_TO_RESTRICTED_BUCKET,
|
||||
DeviceConfig::getFloat,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_RESTRICTED_BUCKET_HIGH_THRESHOLD);
|
||||
getFloatArray(mContext.getResources().obtainTypedArray(
|
||||
R.array.config_bg_current_drain_high_threshold_to_restricted_bucket))[
|
||||
isLowRamDeviceStatic() ? 1 : 0]);
|
||||
bgCurrentDrainRestrictedBucketHighThreshold.set(restrictBucketHighThreshold);
|
||||
|
||||
bgCurrentDrainBgRestrictedHighThreshold = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_HIGH_THRESHOLD_TO_BG_RESTRICTED,
|
||||
DeviceConfig::getFloat,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_BG_RESTRICTED_HIGH_THRESHOLD);
|
||||
getFloatArray(mContext.getResources().obtainTypedArray(
|
||||
R.array.config_bg_current_drain_high_threshold_to_bg_restricted))[
|
||||
isLowRamDeviceStatic() ? 1 : 0]);
|
||||
bgCurrentDrainBgRestrictedHighThreshold.set(bgRestrictedHighThreshold);
|
||||
|
||||
bgMediaPlaybackMinDurationThreshold = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION,
|
||||
DeviceConfig::getLong,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION);
|
||||
(long) mContext.getResources().getInteger(
|
||||
R.integer.config_bg_current_drain_media_playback_min_duration));
|
||||
bgMediaPlaybackMinDurationThreshold.set(bgMediaPlaybackMinDuration);
|
||||
|
||||
bgLocationMinDurationThreshold = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_LOCATION_MIN_DURATION,
|
||||
DeviceConfig::getLong,
|
||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_LOCATION_MIN_DURATION);
|
||||
(long) mContext.getResources().getInteger(
|
||||
R.integer.config_bg_current_drain_location_min_duration));
|
||||
bgLocationMinDurationThreshold.set(bgLocationMinDuration);
|
||||
|
||||
bgCurrentDrainEventDurationBasedThresholdEnabled = new DeviceConfigSession<>(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_EVENT_DURATION_BASED_THRESHOLD_ENABLED,
|
||||
DeviceConfig::getBoolean,
|
||||
AppBatteryPolicy
|
||||
.DEFAULT_BG_CURRENT_DRAIN_EVENT_DURATION_BASED_THRESHOLD_ENABLED);
|
||||
mContext.getResources().getBoolean(
|
||||
R.bool.config_bg_current_drain_event_duration_based_threshold_enabled));
|
||||
bgCurrentDrainEventDurationBasedThresholdEnabled.set(true);
|
||||
|
||||
bgBatteryExemptionEnabled = new DeviceConfigSession<>(
|
||||
|
||||
Reference in New Issue
Block a user