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

Commit 705e7fa0 authored by Varun Shah's avatar Varun Shah Committed by Android (Google) Code Review
Browse files

Merge "Update new permission logic to use flagging." into main

parents 62b214df b47fc471
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -314,7 +314,7 @@ package android {
    field public static final String REMOVE_DRM_CERTIFICATES = "android.permission.REMOVE_DRM_CERTIFICATES";
    field public static final String REMOVE_TASKS = "android.permission.REMOVE_TASKS";
    field public static final String RENOUNCE_PERMISSIONS = "android.permission.RENOUNCE_PERMISSIONS";
    field public static final String REPORT_USAGE_STATS = "android.permission.REPORT_USAGE_STATS";
    field @FlaggedApi("backstage_power.report_usage_stats_permission") public static final String REPORT_USAGE_STATS = "android.permission.REPORT_USAGE_STATS";
    field @Deprecated public static final String REQUEST_NETWORK_SCORES = "android.permission.REQUEST_NETWORK_SCORES";
    field public static final String REQUEST_NOTIFICATION_ASSISTANT_SERVICE = "android.permission.REQUEST_NOTIFICATION_ASSISTANT_SERVICE";
    field public static final String RESET_PASSWORD = "android.permission.RESET_PASSWORD";
+6 −0
Original line number Diff line number Diff line
@@ -7,3 +7,9 @@ flag {
    bug: "296061232"
}

flag {
    name: "report_usage_stats_permission"
    namespace: "backstage_power"
    description: "Feature flag for the new REPORT_USAGE_STATS permission."
    bug: "296056771"
}
+3 −1
Original line number Diff line number Diff line
@@ -6122,7 +6122,9 @@
        android:protectionLevel="signature|privileged|development|appop|retailDemo" />
    <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />

    <!-- @SystemApi @hide Allows trusted system components to report events to UsageStatsManager -->
    <!-- @SystemApi @hide
         @FlaggedApi("backstage_power.report_usage_stats_permission")
         Allows trusted system components to report events to UsageStatsManager -->
    <permission android:name="android.permission.REPORT_USAGE_STATS"
                android:protectionLevel="signature|module" />

+10 −6
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.app.usage.AppStandbyInfo;
import android.app.usage.BroadcastResponseStatsList;
import android.app.usage.ConfigurationStats;
import android.app.usage.EventStats;
import android.app.usage.Flags;
import android.app.usage.IUsageStatsManager;
import android.app.usage.UsageEvents;
import android.app.usage.UsageEvents.Event;
@@ -2124,11 +2125,14 @@ public class UsageStatsService extends SystemService implements
        }

        private boolean canReportUsageStats() {
            if (isCallingUidSystem()) {
                return true; // System UID can always report UsageStats
            }

            return getContext().checkCallingPermission(Manifest.permission.REPORT_USAGE_STATS)
            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)
                        == PackageManager.PERMISSION_GRANTED;
        }