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

Commit c0f74809 authored by Guojing Yuan's avatar Guojing Yuan Committed by Android (Google) Code Review
Browse files

Merge "[CDM perm sync] Remove SystemDataTransferRequest when disassociate"

parents 00d3e2d1 ad263802
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);