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
This commit is contained in:
Zim
2021-03-04 18:05:57 +00:00
committed by Zimuzo Ezeozue
parent 88c5179965
commit 827a95e153

View File

@@ -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) {
mUidsBlockedOnIo.remove(uid);
int ioBlockedCounter = mUidsBlockedOnIo.get(uid, 0);
if (ioBlockedCounter == 0) {
mUidsBlockedOnIo.remove(uid);
} else {
mUidsBlockedOnIo.put(uid, --ioBlockedCounter);
}
}
}