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

Commit dbdd7012 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Enforce permissions check in getLastTimeAnyComponentUsed" into sc-dev

parents 3e244be4 bdac9059
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -68,5 +68,5 @@ interface IUsageStatsManager {
    void reportUserInteraction(String packageName, int userId);
    int getUsageSource();
    void forceUsageSourceSettingRead();
    long getLastTimeAnyComponentUsed(String packageName);
    long getLastTimeAnyComponentUsed(String packageName, String callingPackage);
}
+1 −1
Original line number Diff line number Diff line
@@ -1287,7 +1287,7 @@ public final class UsageStatsManager {
            android.Manifest.permission.PACKAGE_USAGE_STATS})
    public long getLastTimeAnyComponentUsed(@NonNull String packageName) {
        try {
            return mService.getLastTimeAnyComponentUsed(packageName);
            return mService.getLastTimeAnyComponentUsed(packageName, mContext.getOpPackageName());
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
+8 −1
Original line number Diff line number Diff line
@@ -2226,7 +2226,14 @@ public class UsageStatsService extends SystemService implements
        }

        @Override
        public long getLastTimeAnyComponentUsed(String packageName) {
        public long getLastTimeAnyComponentUsed(String packageName, String callingPackage) {
            if (!hasPermissions(
                    callingPackage, android.Manifest.permission.INTERACT_ACROSS_USERS)) {
                throw new SecurityException("Caller doesn't have INTERACT_ACROSS_USERS permission");
            }
            if (!hasPermission(callingPackage)) {
                throw new SecurityException("Don't have permission to query usage stats");
            }
            synchronized (mLock) {
                // Truncate the returned milliseconds to the boundary of the last day before exact
                // time for privacy reasons.