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

Commit 6821cae1 authored by Adam Bookatz's avatar Adam Bookatz
Browse files

Fix VirtualDeviceManagerService startUser crash

Service crashed on certain secondary user startups because the system
server was being denied permission within the system server.

Test: on headless user 0 mode device, start a secondary user and ensure
that the service doesn't crash on startup
Test: atest CreateUsersNoAppCrashesTest (with ag/16771988)
Bug: 217246676

Change-Id: I98ba584553ca0cc0b03fc9196c841645faca1ddc
parent d707ebcd
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -35,10 +35,10 @@ import static com.android.internal.util.function.pooled.PooledLambda.obtainRunna
import static com.android.server.companion.AssociationStore.CHANGE_TYPE_UPDATED_ADDRESS_UNCHANGED;
import static com.android.server.companion.PermissionsUtils.checkCallerCanManageAssociationsForPackage;
import static com.android.server.companion.PermissionsUtils.checkCallerCanManageCompanionDevice;
import static com.android.server.companion.PermissionsUtils.enforceCallerCanInteractWithUserId;
import static com.android.server.companion.PermissionsUtils.enforceCallerCanManageAssociationsForPackage;
import static com.android.server.companion.PermissionsUtils.enforceCallerCanManageCompanionDevice;
import static com.android.server.companion.PermissionsUtils.enforceCallerIsSystemOr;
import static com.android.server.companion.PermissionsUtils.enforceCallerIsSystemOrCanInteractWithUserId;
import static com.android.server.companion.RolesUtils.addRoleHolderForAssociation;
import static com.android.server.companion.RolesUtils.removeRoleHolderForAssociation;

@@ -459,7 +459,7 @@ public class CompanionDeviceManagerService extends SystemService

        @Override
        public List<AssociationInfo> getAllAssociationsForUser(int userId) throws RemoteException {
            enforceCallerCanInteractWithUserId(getContext(), userId);
            enforceCallerIsSystemOrCanInteractWithUserId(getContext(), userId);
            enforceCallerCanManageCompanionDevice(getContext(), "getAllAssociationsForUser");

            return mAssociationStore.getAssociationsForUser(userId);
@@ -468,7 +468,7 @@ public class CompanionDeviceManagerService extends SystemService
        @Override
        public void addOnAssociationsChangedListener(IOnAssociationsChangedListener listener,
                int userId) {
            enforceCallerCanInteractWithUserId(getContext(), userId);
            enforceCallerIsSystemOrCanInteractWithUserId(getContext(), userId);
            enforceCallerCanManageCompanionDevice(getContext(),
                    "addOnAssociationsChangedListener");

@@ -478,7 +478,7 @@ public class CompanionDeviceManagerService extends SystemService
        @Override
        public void removeOnAssociationsChangedListener(IOnAssociationsChangedListener listener,
                int userId) {
            enforceCallerCanInteractWithUserId(getContext(), userId);
            enforceCallerIsSystemOrCanInteractWithUserId(getContext(), userId);
            enforceCallerCanManageCompanionDevice(
                    getContext(), "removeOnAssociationsChangedListener");

+6 −0
Original line number Diff line number Diff line
@@ -112,6 +112,12 @@ final class PermissionsUtils {
        context.enforceCallingPermission(INTERACT_ACROSS_USERS, null);
    }

    static void enforceCallerIsSystemOrCanInteractWithUserId(@NonNull Context context, int userId) {
        if (getCallingUid() == SYSTEM_UID) return;

        enforceCallerCanInteractWithUserId(context, userId);
    }

    static boolean checkCallerIsSystemOr(@UserIdInt int userId, @NonNull String packageName) {
        final int callingUid = getCallingUid();
        if (callingUid == SYSTEM_UID) return true;