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

Commit abdefbe6 authored by Kiran Ramachandra's avatar Kiran Ramachandra Committed by Android (Google) Code Review
Browse files

Merge "Fix deadlock between UriPermission and UriPermissionOwner" into main

parents e2084a0c c297d8b7
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -208,16 +208,22 @@ final class UriPermission {
                persistedModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
            }
            globalModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
            ArraySet<UriPermissionOwner> readOwnersCopy = null;
            synchronized (this) {
                if (mReadOwners != null && includingOwners) {
                    ownedModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
                    for (UriPermissionOwner r : mReadOwners) {
                    // Keeping a copy to remove the permission outside of UriPermission lock to
                    // prevent Deadlock
                    readOwnersCopy = new ArraySet<>(mReadOwners);
                    mReadOwners = null;
                }
            }
            if (readOwnersCopy != null) {
                for (UriPermissionOwner r : readOwnersCopy) {
                    if (r != null) {
                        r.removeReadPermission(this);
                    }
                }
                    mReadOwners = null;
                }
            }
        }
        if ((modeFlags & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) {
@@ -226,16 +232,22 @@ final class UriPermission {
                persistedModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
            }
            globalModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
            ArraySet<UriPermissionOwner> writeOwnersCopy = null;
            synchronized (this) {
                if (mWriteOwners != null && includingOwners) {
                    ownedModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
                    for (UriPermissionOwner r : mWriteOwners) {
                    // Keeping a copy to remove the permission outside of UriPermission lock to
                    // prevent Deadlock
                    writeOwnersCopy = new ArraySet<>(mWriteOwners);
                    mWriteOwners = null;
                }
            }
            if (writeOwnersCopy != null) {
                for (UriPermissionOwner r : writeOwnersCopy) {
                    if (r != null) {
                        r.removeWritePermission(this);
                    }
                }
                    mWriteOwners = null;
                }
            }
        }