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

Commit 827a95e1 authored by Zim's avatar Zim Committed by Zimuzo Ezeozue
Browse files

Implement AppIoBlocked counter per uid

This allows us track AppIoBlocked status correctly for a uid with
several threads concurrently blocked on IO.

This would have been cleaner to track per tid of uid, but
unfortunately, we don't know the calling tid via binder

Test: Manual
Bug: 170486601
Change-Id: I4df5cb2e99726739059d962915c7488df98a0f05
parent 88c51799
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -42,8 +42,8 @@ import android.os.storage.StorageManagerInternal;
import android.os.storage.StorageVolume;
import android.service.storage.ExternalStorageService;
import android.service.storage.IExternalStorageService;
import android.util.ArraySet;
import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
@@ -76,8 +76,8 @@ public final class StorageUserConnection {
    private final StorageSessionController mSessionController;
    private final StorageManagerInternal mSmInternal;
    private final ActiveConnection mActiveConnection = new ActiveConnection();
    @GuardedBy("mLock") private final Map<String, Session> mSessions = new HashMap<>();
    @GuardedBy("mLock") private final Set<Integer> mUidsBlockedOnIo = new ArraySet<>();
    @GuardedBy("mSessionsLock") private final Map<String, Session> mSessions = new HashMap<>();
    @GuardedBy("mSessionsLock") private final SparseArray<Integer> mUidsBlockedOnIo = new SparseArray<>();
    private final HandlerThread mHandlerThread;

    public StorageUserConnection(Context context, int userId, StorageSessionController controller) {
@@ -249,7 +249,8 @@ public final class StorageUserConnection {
    public void notifyAppIoBlocked(String volumeUuid, int uid, int tid,
            @StorageManager.AppIoBlockedReason int reason) {
        synchronized (mSessionsLock) {
            mUidsBlockedOnIo.add(uid);
            int ioBlockedCounter = mUidsBlockedOnIo.get(uid, 0);
            mUidsBlockedOnIo.put(uid, ++ioBlockedCounter);
        }
    }

@@ -262,7 +263,12 @@ public final class StorageUserConnection {
    public void notifyAppIoResumed(String volumeUuid, int uid, int tid,
            @StorageManager.AppIoBlockedReason int reason) {
        synchronized (mSessionsLock) {
            int ioBlockedCounter = mUidsBlockedOnIo.get(uid, 0);
            if (ioBlockedCounter == 0) {
                mUidsBlockedOnIo.remove(uid);
            } else {
                mUidsBlockedOnIo.put(uid, --ioBlockedCounter);
            }
        }
    }