summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Varun Shah <varunshah@google.com> 2023-04-22 00:50:26 +0000
committer Varun Shah <varunshah@google.com> 2023-04-22 00:50:26 +0000
commitb0fc48e369d6c965a22bdf6a50f5dcc06391773b (patch)
tree85fcdc9fc04e6def5c89e2aba33f40f317893578
parent03a4257306ea2b691d3cf57a7c2bbb66dc5fd55c (diff)
Ensure only valid events are reported.
When CHOOSER_ACTION events are reported via reportChooserSelection, make sure the parameters are not null and the package passed is also a valid, installed package. Bug: 229633537 Bug: 253403242 Test: atest UsageStatsTest Change-Id: I92089f75c94a4e1e4e40afc70f4488c49d178f96
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsService.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index a98429ad4902..ef1359449b9b 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -2539,10 +2539,20 @@ public class UsageStatsService extends SystemService implements
}
@Override
- public void reportChooserSelection(String packageName, int userId, String contentType,
- String[] annotations, String action) {
+ public void reportChooserSelection(@NonNull String packageName, int userId,
+ @NonNull String contentType, String[] annotations, @NonNull String action) {
if (packageName == null) {
- Slog.w(TAG, "Event report user selecting a null package");
+ throw new IllegalArgumentException("Package selection must not be null.");
+ }
+ if (contentType == null) {
+ throw new IllegalArgumentException("Content type for selection must not be null.");
+ }
+ if (action == null) {
+ throw new IllegalArgumentException("Selection action must not be null.");
+ }
+ // 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");
return;
}