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

Commit 538b3611 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Do not synchronize if not necessary

Test: atest CtsStatsdHostTestCases:android.cts.statsd.atom.HostAtomTests#testRoleHolder
Change-Id: I60e684338e97db9aa4dd90c3a7ce318e1a9b9a72
parent bcd4bddc
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -376,7 +376,7 @@ public class RoleUserState {

            version = mVersion;
            packagesHash = mPackagesHash;
            roles = getRoleHolders();
            roles = snapshotRolesLocked();
        }

        AtomicFile atomicFile = new AtomicFile(getFile(mUserId), "roles-" + mUserId);
@@ -541,7 +541,7 @@ public class RoleUserState {

            version = mVersion;
            packagesHash = mPackagesHash;
            roles = getRoleHolders();
            roles = snapshotRolesLocked();
        }

        long fieldToken = dumpOutputStream.start(fieldName, fieldId);
@@ -578,6 +578,12 @@ public class RoleUserState {
    @NonNull
    public ArrayMap<String, ArraySet<String>> getRoleHolders() {
        synchronized (mLock) {
            return snapshotRolesLocked();
        }
    }

    @GuardedBy("mLock")
    private ArrayMap<String, ArraySet<String>> snapshotRolesLocked() {
        ArrayMap<String, ArraySet<String>> roles = new ArrayMap<>();
        for (int i = 0, size = CollectionUtils.size(mRoles); i < size; ++i) {
            String roleName = mRoles.keyAt(i);
@@ -588,7 +594,6 @@ public class RoleUserState {
        }
        return roles;
    }
    }

    /**
     * Destroy this user state and delete the corresponding file. Any pending writes to the file