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

Commit 42d97911 authored by dimorinny's avatar dimorinny
Browse files

Get rid of unnecessary grant file locking that may potentially affect AM...

Get rid of unnecessary grant file locking that may potentially affect AM performance. Even though this file is accessed from separate threads, there is no space for race condition here because it is read in the very early stages of system boot but writes may only happen in 10 seconds after communication.

Bug: 149370983
Test: locally by flashing device and check basic functionality and atest UriGrantsManagerServiceTest
Change-Id: I3737646cbc0333b0dcbdc89fb8e165b0c2432018
parent 4e59b196
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -117,7 +117,6 @@ public class UriGrantsManagerService extends IUriGrantsManager.Stub {
    PackageManagerInternal mPmInternal;

    /** File storing persisted {@link #mGrantedUriPermissions}. */
    @GuardedBy("mLock")
    private final AtomicFile mGrantFile;

    /** XML constants used in {@link #mGrantFile} */
@@ -1299,15 +1298,14 @@ public class UriGrantsManagerService extends IUriGrantsManager.Stub {
        return false;
    }

    @GuardedBy("mLock")
    private void writeGrantedUriPermissionsLocked() {
    private void writeGrantedUriPermissions() {
        if (DEBUG) Slog.v(TAG, "writeGrantedUriPermissions()");

        final long startTime = SystemClock.uptimeMillis();

        // Snapshot permissions so we can persist without lock
        ArrayList<UriPermission.Snapshot> persist = Lists.newArrayList();
        synchronized (this) {
        synchronized (mLock) {
            final int size = mGrantedUriPermissions.size();
            for (int i = 0; i < size; i++) {
                final ArrayMap<GrantUri, UriPermission> perms = mGrantedUriPermissions.valueAt(i);
@@ -1360,9 +1358,7 @@ public class UriGrantsManagerService extends IUriGrantsManager.Stub {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case PERSIST_URI_GRANTS_MSG: {
                    synchronized (mLock) {
                        writeGrantedUriPermissionsLocked();
                    }
                    writeGrantedUriPermissions();
                    break;
                }
            }