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

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

Merge "Let sysUI call PeopleService#getLastInteraction"

parents 22ef6c7e 8fbe29a0
Loading
Loading
Loading
Loading
+20 −3
Original line number Original line Diff line number Diff line
@@ -94,12 +94,29 @@ public class PeopleService extends SystemService {
     * @throws SecurityException if the caller is not system or root
     * @throws SecurityException if the caller is not system or root
     */
     */
    private static void enforceSystemOrRoot(String message) {
    private static void enforceSystemOrRoot(String message) {
        int uid = Binder.getCallingUid();
        if (!isSystemOrRoot()) {
        if (!UserHandle.isSameApp(uid, Process.SYSTEM_UID) && uid != Process.ROOT_UID) {
            throw new SecurityException("Only system may " + message);
            throw new SecurityException("Only system may " + message);
        }
        }
    }
    }


    private static boolean isSystemOrRoot() {
        final int uid = Binder.getCallingUid();
        return UserHandle.isSameApp(uid, Process.SYSTEM_UID) || uid == Process.ROOT_UID;
    }


    /**
     * Enforces that only the system, root UID or SystemUI can make certain calls.
     *
     * @param message used as message if SecurityException is thrown
     * @throws SecurityException if the caller is not system or root
     */
    private static void enforceSystemRootOrSystemUI(Context context, String message) {
        if (isSystemOrRoot()) return;
        context.enforceCallingPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
                message);
    }

    private final class BinderService extends IPeopleManager.Stub {
    private final class BinderService extends IPeopleManager.Stub {


        @Override
        @Override
@@ -126,7 +143,7 @@ public class PeopleService extends SystemService {


        @Override
        @Override
        public long getLastInteraction(String packageName, int userId, String shortcutId) {
        public long getLastInteraction(String packageName, int userId, String shortcutId) {
            enforceSystemOrRoot("get last interaction");
            enforceSystemRootOrSystemUI(getContext(), "get last interaction");
            return mDataManager.getLastInteraction(packageName, userId, shortcutId);
            return mDataManager.getLastInteraction(packageName, userId, shortcutId);
        }
        }
    }
    }