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

Commit 1eb87176 authored by Guojing Yuan's avatar Guojing Yuan
Browse files

[CDM] Perm Sync toggle fixes

Bug: 290063372
Fix: 300388336

Test: m
Change-Id: Ia1dd9c913f2fa5bc64c9806b515e93265371814e
parent a9e0b680
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -887,6 +887,11 @@ public class CompanionDeviceManagerService extends SystemService {

        @Override
        public PermissionSyncRequest getPermissionSyncRequest(int associationId) {
            // TODO: temporary fix, will remove soon
            AssociationInfo association = mAssociationStore.getAssociationById(associationId);
            if (association == null) {
                return null;
            }
            getAssociationWithCallerChecks(associationId);
            return mSystemDataTransferProcessor.getPermissionSyncRequest(associationId);
        }
+39 −18
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ public class SystemDataTransferProcessor {
            @UserIdInt int userId, int associationId) {
        if (PackageUtils.isPackageAllowlisted(mContext, mPackageManager, packageName)) {
            Slog.i(LOG_TAG, "User consent Intent should be skipped. Returning null.");
            // Auto enable perm sync for the whitelisted packages, but don't override user decision
            // Auto enable perm sync for the allowlisted packages, but don't override user decision
            PermissionSyncRequest request = getPermissionSyncRequest(associationId);
            if (request == null) {
                PermissionSyncRequest newRequest = new PermissionSyncRequest(associationId);
@@ -224,20 +224,30 @@ public class SystemDataTransferProcessor {
     * Enable perm sync for the association
     */
    public void enablePermissionsSync(int associationId) {
        final long callingIdentityToken = Binder.clearCallingIdentity();
        try {
            int userId = mAssociationStore.getAssociationById(associationId).getUserId();
            PermissionSyncRequest request = new PermissionSyncRequest(associationId);
            request.setUserConsented(true);
            mSystemDataTransferRequestStore.writeRequest(userId, request);
        } finally {
            Binder.restoreCallingIdentity(callingIdentityToken);
        }
    }

    /**
     * Disable perm sync for the association
     */
    public void disablePermissionsSync(int associationId) {
        final long callingIdentityToken = Binder.clearCallingIdentity();
        try {
            int userId = mAssociationStore.getAssociationById(associationId).getUserId();
            PermissionSyncRequest request = new PermissionSyncRequest(associationId);
            request.setUserConsented(false);
            mSystemDataTransferRequestStore.writeRequest(userId, request);
        } finally {
            Binder.restoreCallingIdentity(callingIdentityToken);
        }
    }

    /**
@@ -245,23 +255,34 @@ public class SystemDataTransferProcessor {
     */
    @Nullable
    public PermissionSyncRequest getPermissionSyncRequest(int associationId) {
        final long callingIdentityToken = Binder.clearCallingIdentity();
        try {
            int userId = mAssociationStore.getAssociationById(associationId).getUserId();
            List<SystemDataTransferRequest> requests =
                mSystemDataTransferRequestStore.readRequestsByAssociationId(userId, associationId);
                    mSystemDataTransferRequestStore.readRequestsByAssociationId(userId,
                            associationId);
            for (SystemDataTransferRequest request : requests) {
                if (request instanceof PermissionSyncRequest) {
                    return (PermissionSyncRequest) request;
                }
            }
            return null;
        } finally {
            Binder.restoreCallingIdentity(callingIdentityToken);
        }
    }

    /**
     * Remove perm sync request for the association.
     */
    public void removePermissionSyncRequest(int associationId) {
        final long callingIdentityToken = Binder.clearCallingIdentity();
        try {
            int userId = mAssociationStore.getAssociationById(associationId).getUserId();
            mSystemDataTransferRequestStore.removeRequestsByAssociationId(userId, associationId);
        } finally {
            Binder.restoreCallingIdentity(callingIdentityToken);
        }
    }

    private void onReceivePermissionRestore(byte[] message) {