Merge "Make broadcast response window duration configurable."
This commit is contained in:
committed by
Android (Google) Code Review
commit
6c03192f3d
@@ -216,4 +216,11 @@ public interface AppStandbyInternal {
|
||||
void dumpState(String[] args, PrintWriter pw);
|
||||
|
||||
boolean isAppIdleEnabled();
|
||||
|
||||
/**
|
||||
* Returns the duration (in millis) for the window where events occurring will be
|
||||
* considered as broadcast response, starting from the point when an app receives
|
||||
* a broadcast.
|
||||
*/
|
||||
long getBroadcastResponseWindowDurationMs();
|
||||
}
|
||||
|
||||
@@ -347,6 +347,14 @@ public class AppStandbyController
|
||||
*/
|
||||
boolean mLinkCrossProfileApps =
|
||||
ConstantsObserver.DEFAULT_CROSS_PROFILE_APPS_SHARE_STANDBY_BUCKETS;
|
||||
|
||||
/**
|
||||
* Duration (in millis) for the window where events occurring will be considered as
|
||||
* broadcast response, starting from the point when an app receives a broadcast.
|
||||
*/
|
||||
volatile long mBroadcastResponseWindowDurationMillis =
|
||||
ConstantsObserver.DEFAULT_BROADCAST_RESPONSE_WINDOW_DURATION_MS;
|
||||
|
||||
/**
|
||||
* Whether we should allow apps into the
|
||||
* {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED} bucket or not.
|
||||
@@ -1774,6 +1782,10 @@ public class AppStandbyController
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBroadcastResponseWindowDurationMs() {
|
||||
return mBroadcastResponseWindowDurationMillis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushToDisk() {
|
||||
@@ -2042,6 +2054,10 @@ public class AppStandbyController
|
||||
TimeUtils.formatDuration(mSystemUpdateUsageTimeoutMillis, pw);
|
||||
pw.println();
|
||||
|
||||
pw.print(" mBroadcastResponseWindowDurationMillis=");
|
||||
TimeUtils.formatDuration(mBroadcastResponseWindowDurationMillis, pw);
|
||||
pw.println();
|
||||
|
||||
pw.println();
|
||||
pw.print("mAppIdleEnabled="); pw.print(mAppIdleEnabled);
|
||||
pw.print(" mAllowRestrictedBucket=");
|
||||
@@ -2473,6 +2489,8 @@ public class AppStandbyController
|
||||
KEY_PREFIX_ELAPSED_TIME_THRESHOLD + "rare",
|
||||
KEY_PREFIX_ELAPSED_TIME_THRESHOLD + "restricted"
|
||||
};
|
||||
private static final String KEY_BROADCAST_RESPONSE_WINDOW_DURATION_MS =
|
||||
"broadcast_response_window_timeout_ms";
|
||||
public static final long DEFAULT_CHECK_IDLE_INTERVAL_MS =
|
||||
COMPRESS_TIME ? ONE_MINUTE : 4 * ONE_HOUR;
|
||||
public static final long DEFAULT_STRONG_USAGE_TIMEOUT =
|
||||
@@ -2502,6 +2520,8 @@ public class AppStandbyController
|
||||
public static final long DEFAULT_AUTO_RESTRICTED_BUCKET_DELAY_MS =
|
||||
COMPRESS_TIME ? ONE_MINUTE : ONE_DAY;
|
||||
public static final boolean DEFAULT_CROSS_PROFILE_APPS_SHARE_STANDBY_BUCKETS = true;
|
||||
public static final long DEFAULT_BROADCAST_RESPONSE_WINDOW_DURATION_MS =
|
||||
2 * ONE_MINUTE;
|
||||
|
||||
ConstantsObserver(Handler handler) {
|
||||
super(handler);
|
||||
@@ -2619,6 +2639,11 @@ public class AppStandbyController
|
||||
KEY_UNEXEMPTED_SYNC_SCHEDULED_HOLD_DURATION,
|
||||
DEFAULT_UNEXEMPTED_SYNC_SCHEDULED_TIMEOUT);
|
||||
break;
|
||||
case KEY_BROADCAST_RESPONSE_WINDOW_DURATION_MS:
|
||||
mBroadcastResponseWindowDurationMillis = properties.getLong(
|
||||
KEY_BROADCAST_RESPONSE_WINDOW_DURATION_MS,
|
||||
DEFAULT_BROADCAST_RESPONSE_WINDOW_DURATION_MS);
|
||||
break;
|
||||
default:
|
||||
if (!timeThresholdsUpdated
|
||||
&& (name.startsWith(KEY_PREFIX_SCREEN_TIME_THRESHOLD)
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
"options": [
|
||||
{"include-filter": "android.app.usage.cts.UsageStatsTest"},
|
||||
{"exclude-annotation": "android.platform.test.annotations.FlakyTest"},
|
||||
{"exclude-annotation": "androidx.test.filters.FlakyTest"}
|
||||
{"exclude-annotation": "androidx.test.filters.FlakyTest"},
|
||||
{"exclude-annotation": "androidx.test.filters.MediumTest"},
|
||||
{"exclude-annotation": "androidx.test.filters.LargeTest"}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -69,6 +69,12 @@ class BroadcastResponseStatsTracker {
|
||||
private SparseArray<SparseArray<UserBroadcastResponseStats>> mUserResponseStats =
|
||||
new SparseArray<>();
|
||||
|
||||
private AppStandbyInternal mAppStandby;
|
||||
|
||||
BroadcastResponseStatsTracker(@NonNull AppStandbyInternal appStandby) {
|
||||
mAppStandby = appStandby;
|
||||
}
|
||||
|
||||
// TODO (206518114): Move all callbacks handling to a handler thread.
|
||||
void reportBroadcastDispatchEvent(int sourceUid, @NonNull String targetPackage,
|
||||
UserHandle targetUser, long idForResponseEvent,
|
||||
@@ -132,8 +138,7 @@ class BroadcastResponseStatsTracker {
|
||||
if (dispatchTimestampMs >= timestampMs) {
|
||||
continue;
|
||||
}
|
||||
// TODO (206518114): Make the constant configurable.
|
||||
if (elapsedDurationMs <= 2 * 60 * 1000) {
|
||||
if (elapsedDurationMs <= mAppStandby.getBroadcastResponseWindowDurationMs()) {
|
||||
final BroadcastEvent broadcastEvent = broadcastEvents.valueAt(i);
|
||||
final BroadcastResponseStats responseStats =
|
||||
getBroadcastResponseStats(broadcastEvent);
|
||||
|
||||
@@ -281,7 +281,7 @@ public class UsageStatsService extends SystemService implements
|
||||
mHandler = new H(BackgroundThread.get().getLooper());
|
||||
|
||||
mAppStandby = mInjector.getAppStandbyController(getContext());
|
||||
mResponseStatsTracker = new BroadcastResponseStatsTracker();
|
||||
mResponseStatsTracker = new BroadcastResponseStatsTracker(mAppStandby);
|
||||
|
||||
mAppTimeLimit = new AppTimeLimitController(getContext(),
|
||||
new AppTimeLimitController.TimeLimitCallbackListener() {
|
||||
|
||||
Reference in New Issue
Block a user