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

Commit ad263802 authored by Guojing Yuan's avatar Guojing Yuan
Browse files

[CDM perm sync] Remove SystemDataTransferRequest when disassociate

Fix: 220921569

Remove all the system data transfer requests for the association when
it's being disassociated.

Fix: 220921569

Test: Manually tested it in the CDM test app. Added unit tests.
Change-Id: I24fd4fd5639e0801e4f5df6b5616c3910b87f247
parent e0027cd2
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -870,6 +870,9 @@ public class CompanionDeviceManagerService extends SystemService {
        // Removing the association.
        mAssociationStore.removeAssociation(associationId);

        // Remove all the system data transfer requests for the association.
        mSystemDataTransferRequestStore.removeRequestsByAssociationId(userId, associationId);

        final List<AssociationInfo> otherAssociations =
                mAssociationStore.getAssociationsForPackage(userId, packageName);

+18 −1
Original line number Diff line number Diff line
@@ -81,7 +81,6 @@ public class SystemDataTransferRequestStore {

    private static final String XML_TAG_REQUESTS = "requests";
    private static final String XML_TAG_REQUEST = "request";
    private static final String XML_TAG_LIST = "list";

    private static final String XML_ATTR_ASSOCIATION_ID = "association_id";
    private static final String XML_ATTR_DATA_TYPE = "data_type";
@@ -122,6 +121,7 @@ public class SystemDataTransferRequestStore {
    }

    void writeRequest(@UserIdInt int userId, SystemDataTransferRequest request) {
        Slog.i(LOG_TAG, "Writing request=" + request + " to store.");
        ArrayList<SystemDataTransferRequest> cachedRequests;
        synchronized (mLock) {
            // Write to cache
@@ -133,6 +133,23 @@ public class SystemDataTransferRequestStore {
        mExecutor.execute(() -> writeRequestsToStore(userId, cachedRequests));
    }

    /**
     * Remove requests by association id. userId must be the one which owns the associationId.
     */
    public void removeRequestsByAssociationId(@UserIdInt int userId, int associationId) {
        Slog.i(LOG_TAG, "Removing system data transfer requests for userId=" + userId
                + ", associationId=" + associationId);
        ArrayList<SystemDataTransferRequest> cachedRequests;
        synchronized (mLock) {
            // Remove requests from cache
            cachedRequests = readRequestsFromCache(userId);
            cachedRequests.removeIf(request -> request.getAssociationId() == associationId);
            mCachedPerUser.set(userId, cachedRequests);
        }
        // Remove requests from store
        mExecutor.execute(() -> writeRequestsToStore(userId, cachedRequests));
    }

    @GuardedBy("mLock")
    private ArrayList<SystemDataTransferRequest> readRequestsFromCache(@UserIdInt int userId) {
        ArrayList<SystemDataTransferRequest> cachedRequests = mCachedPerUser.get(userId);