Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f4afd6bf authored by Xin Guan's avatar Xin Guan
Browse files

Enforce INTERACT_ACROSS_USERS_FULL for cross-user event reports.

Bug: 296061232
Test: CtsUsageStatsTestCases:android.app.usage.cts.UsageStatsTest
Change-Id: I5031f9fc45c4518acdeb69e073b6625f789a01b9
parent aa03774d
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -2278,6 +2278,12 @@ public class UsageStatsService extends SystemService implements
                        "Only the system or holders of the REPORT_USAGE_STATS"
                            + " permission are allowed to call reportUserInteraction");
                }
                if (userId != UserHandle.getCallingUserId()) {
                    // Cross-user event reporting.
                    getContext().enforceCallingPermission(
                            Manifest.permission.INTERACT_ACROSS_USERS_FULL,
                            "Caller doesn't have INTERACT_ACROSS_USERS_FULL permission");
                }
            } else {
                if (!isCallingUidSystem()) {
                    throw new SecurityException("Only system is allowed to call"
@@ -2287,7 +2293,8 @@ public class UsageStatsService extends SystemService implements

            // Verify if this package exists before reporting an event for it.
            if (mPackageManagerInternal.getPackageUid(packageName, 0, userId) < 0) {
                throw new IllegalArgumentException("Package " + packageName + "not exist!");
                throw new IllegalArgumentException("Package " + packageName
                        + " does not exist!");
            }

            final Event event = new Event(USER_INTERACTION, SystemClock.elapsedRealtime());