Loading services/usage/java/com/android/server/usage/UsageStatsService.java +24 −15 Original line number Diff line number Diff line Loading @@ -2127,14 +2127,12 @@ public class UsageStatsService extends SystemService implements } private boolean canReportUsageStats() { final boolean isSystem = isCallingUidSystem(); if (!Flags.reportUsageStatsPermission()) { // If the flag is disabled, do no check for the new permission and instead return // true only if the calling uid is system since System UID can always report stats. return isSystem; } return isSystem || getContext().checkCallingPermission(Manifest.permission.REPORT_USAGE_STATS) if (isCallingUidSystem()) { // System UID can always report UsageStats return true; } return getContext().checkCallingPermission(Manifest.permission.REPORT_USAGE_STATS) == PackageManager.PERMISSION_GRANTED; } Loading Loading @@ -2627,10 +2625,13 @@ public class UsageStatsService extends SystemService implements return; } if (Flags.reportUsageStatsPermission()) { if (!canReportUsageStats()) { throw new SecurityException("Only the system or holders of the REPORT_USAGE_STATS" throw new SecurityException( "Only the system or holders of the REPORT_USAGE_STATS" + " permission are allowed to call reportChooserSelection"); } } // Verify if this package exists before reporting an event for it. if (mPackageManagerInternal.getPackageUid(packageName, 0, userId) < 0) { Loading @@ -2649,10 +2650,18 @@ public class UsageStatsService extends SystemService implements @Override public void reportUserInteraction(String packageName, int userId) { Objects.requireNonNull(packageName); if (Flags.reportUsageStatsPermission()) { if (!canReportUsageStats()) { throw new SecurityException("Only the system or holders of the REPORT_USAGE_STATS" throw new SecurityException( "Only the system or holders of the REPORT_USAGE_STATS" + " permission are allowed to call reportUserInteraction"); } } else { if (!isCallingUidSystem()) { throw new SecurityException("Only system is allowed to call" + " reportUserInteraction"); } } final Event event = new Event(USER_INTERACTION, SystemClock.elapsedRealtime()); event.mPackage = packageName; Loading Loading
services/usage/java/com/android/server/usage/UsageStatsService.java +24 −15 Original line number Diff line number Diff line Loading @@ -2127,14 +2127,12 @@ public class UsageStatsService extends SystemService implements } private boolean canReportUsageStats() { final boolean isSystem = isCallingUidSystem(); if (!Flags.reportUsageStatsPermission()) { // If the flag is disabled, do no check for the new permission and instead return // true only if the calling uid is system since System UID can always report stats. return isSystem; } return isSystem || getContext().checkCallingPermission(Manifest.permission.REPORT_USAGE_STATS) if (isCallingUidSystem()) { // System UID can always report UsageStats return true; } return getContext().checkCallingPermission(Manifest.permission.REPORT_USAGE_STATS) == PackageManager.PERMISSION_GRANTED; } Loading Loading @@ -2627,10 +2625,13 @@ public class UsageStatsService extends SystemService implements return; } if (Flags.reportUsageStatsPermission()) { if (!canReportUsageStats()) { throw new SecurityException("Only the system or holders of the REPORT_USAGE_STATS" throw new SecurityException( "Only the system or holders of the REPORT_USAGE_STATS" + " permission are allowed to call reportChooserSelection"); } } // Verify if this package exists before reporting an event for it. if (mPackageManagerInternal.getPackageUid(packageName, 0, userId) < 0) { Loading @@ -2649,10 +2650,18 @@ public class UsageStatsService extends SystemService implements @Override public void reportUserInteraction(String packageName, int userId) { Objects.requireNonNull(packageName); if (Flags.reportUsageStatsPermission()) { if (!canReportUsageStats()) { throw new SecurityException("Only the system or holders of the REPORT_USAGE_STATS" throw new SecurityException( "Only the system or holders of the REPORT_USAGE_STATS" + " permission are allowed to call reportUserInteraction"); } } else { if (!isCallingUidSystem()) { throw new SecurityException("Only system is allowed to call" + " reportUserInteraction"); } } final Event event = new Event(USER_INTERACTION, SystemClock.elapsedRealtime()); event.mPackage = packageName; Loading