Ensure valid parameters for CHOOSER_ACTION events.

Bug: 253403242
Test: atest UsageStatsTest
Change-Id: Id356794f8fdfe077ae223c83a4df9b9185e497b3
This commit is contained in:
Varun Shah
2023-05-16 01:39:06 +00:00
parent 2d3fbc4973
commit e2551bcecb

View File

@@ -2540,10 +2540,15 @@ public class UsageStatsService extends SystemService implements
@Override
public void reportChooserSelection(@NonNull String packageName, int userId,
String contentType, String[] annotations, String action) {
@NonNull String contentType, String[] annotations, @NonNull String action) {
if (packageName == null) {
throw new IllegalArgumentException("Package selection must not be null.");
}
// A valid contentType and action must be provided for chooser selection events.
if (contentType == null || contentType.isBlank()
|| action == null || action.isBlank()) {
return;
}
// Verify if this package exists before reporting an event for it.
if (mPackageManagerInternal.getPackageUid(packageName, 0, userId) < 0) {
Slog.w(TAG, "Event report user selecting an invalid package");