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

Commit 3799607f authored by vaibsinghal's avatar vaibsinghal Committed by Vaibhav Singhal
Browse files

Synchronize read/write operations in AppFunctionAgentAllowlistStorage.

Add a lock to synchronize the `readPreviousValidAllowlist` and `writeCurrentAllowlist` methods, ensuring thread-safe access to the allowlist file.

Flag: EXEMPT Added only lock
Test: atest FrameworksAppFunctionsTests
Bug: 416661798
Change-Id: I15338ab9d8da31d1c1bc1eef240848619d3e4157
parent 669f519c
Loading
Loading
Loading
Loading
+26 −21
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ public final class AppFunctionAgentAllowlistStorage {
    private static final String TAG = "AppFunctionAgentAllowlistStorage";

    @NonNull private final AtomicFile mAtomicFile;
    @NonNull private final Object mAllowlistStorageLock = new Object();

    /**
     * Creates an instance that manages the allowlist at the specified file path.
@@ -57,6 +58,7 @@ public final class AppFunctionAgentAllowlistStorage {
    @WorkerThread
    @Nullable
    public List<SignedPackage> readPreviousValidAllowlist() {
        synchronized (mAllowlistStorageLock) {
            if (!mAtomicFile.exists()) {
                Slog.d(TAG, "Allowlist file does not exist.");
                return null;
@@ -72,6 +74,7 @@ public final class AppFunctionAgentAllowlistStorage {
                return null;
            }
        }
    }

    /**
     * Writes the given allowlist string to persistent storage atomically.
@@ -82,6 +85,7 @@ public final class AppFunctionAgentAllowlistStorage {
     */
    @WorkerThread
    public void writeCurrentAllowlist(@NonNull String allowlistString) {
        synchronized (mAllowlistStorageLock) {
            FileOutputStream fos = null;
            try {
                fos = mAtomicFile.startWrite();
@@ -95,3 +99,4 @@ public final class AppFunctionAgentAllowlistStorage {
            }
        }
    }
}