Make broadcast response window duration configurable.

Bug: 206518114
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: Ifc6792e969304967af7019483fdd1ec242bd2a83
This commit is contained in:
Sudheer Shanka
2022-01-27 09:51:53 +00:00
parent 2d888c547a
commit cc59c25bd1
5 changed files with 43 additions and 4 deletions

View File

@@ -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();
}

View File

@@ -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)

View File

@@ -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"}
]
},
{

View File

@@ -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);

View File

@@ -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() {