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

Commit 8fbe29a0 authored by Beverly's avatar Beverly
Browse files

Let sysUI call PeopleService#getLastInteraction

Test: manual
Bug: 169412531
Change-Id: Iac329d2c92048932ec468d7eb4d37c5c51e3e7c5
parent 9bca9776
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -94,12 +94,29 @@ public class PeopleService extends SystemService {
     * @throws SecurityException if the caller is not system or root
     */
    private static void enforceSystemOrRoot(String message) {
        int uid = Binder.getCallingUid();
        if (!UserHandle.isSameApp(uid, Process.SYSTEM_UID) && uid != Process.ROOT_UID) {
        if (!isSystemOrRoot()) {
            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 {

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

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