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

Commit 4fb77faa authored by Zimuzo Ezeozue's avatar Zimuzo Ezeozue Committed by Automerger Merge Worker
Browse files

Merge "Reduce demo user FUSE volume mount timeout" into rvc-dev am: 0df699ae...

Merge "Reduce demo user FUSE volume mount timeout" into rvc-dev am: 0df699ae am: 53c4fc32 am: c94d92c0

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12217292

Change-Id: I573dd9b87635ea36a85c04776bca71e33302686b
parents 56e54711 c94d92c0
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ import android.os.ParcelFileDescriptor;
import android.os.ParcelableException;
import android.os.ParcelableException;
import android.os.RemoteCallback;
import android.os.RemoteCallback;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManagerInternal;
import android.os.storage.StorageManagerInternal;
import android.os.storage.StorageManagerInternal;
import android.os.storage.StorageVolume;
import android.os.storage.StorageVolume;
import android.service.storage.ExternalStorageService;
import android.service.storage.ExternalStorageService;
@@ -62,19 +63,25 @@ import java.util.concurrent.TimeoutException;
public final class StorageUserConnection {
public final class StorageUserConnection {
    private static final String TAG = "StorageUserConnection";
    private static final String TAG = "StorageUserConnection";


    public static final int REMOTE_TIMEOUT_SECONDS = 20;
    private static final int DEFAULT_REMOTE_TIMEOUT_SECONDS = 20;
    // TODO(b/161702661): Workaround for demo user to have shorter timeout.
    // This allows the DevicePolicyManagerService#enableSystemApp call to succeed without ANR.
    private static final int DEMO_USER_REMOTE_TIMEOUT_SECONDS = 5;


    private final Object mLock = new Object();
    private final Object mLock = new Object();
    private final Context mContext;
    private final Context mContext;
    private final int mUserId;
    private final int mUserId;
    private final StorageSessionController mSessionController;
    private final StorageSessionController mSessionController;
    private final ActiveConnection mActiveConnection = new ActiveConnection();
    private final ActiveConnection mActiveConnection = new ActiveConnection();
    private final boolean mIsDemoUser;
    @GuardedBy("mLock") private final Map<String, Session> mSessions = new HashMap<>();
    @GuardedBy("mLock") private final Map<String, Session> mSessions = new HashMap<>();


    public StorageUserConnection(Context context, int userId, StorageSessionController controller) {
    public StorageUserConnection(Context context, int userId, StorageSessionController controller) {
        mContext = Objects.requireNonNull(context);
        mContext = Objects.requireNonNull(context);
        mUserId = Preconditions.checkArgumentNonnegative(userId);
        mUserId = Preconditions.checkArgumentNonnegative(userId);
        mSessionController = controller;
        mSessionController = controller;
        mIsDemoUser = LocalServices.getService(UserManagerInternal.class)
                .getUserInfo(userId).isDemo();
    }
    }


    /**
    /**
@@ -200,7 +207,8 @@ public final class StorageUserConnection {


    private void waitForLatch(CountDownLatch latch, String reason) throws TimeoutException {
    private void waitForLatch(CountDownLatch latch, String reason) throws TimeoutException {
        try {
        try {
            if (!latch.await(REMOTE_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
            if (!latch.await(mIsDemoUser ? DEMO_USER_REMOTE_TIMEOUT_SECONDS
                            : DEFAULT_REMOTE_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
                // TODO(b/140025078): Call ActivityManager ANR API?
                // TODO(b/140025078): Call ActivityManager ANR API?
                Slog.wtf(TAG, "Failed to bind to the ExternalStorageService for user " + mUserId);
                Slog.wtf(TAG, "Failed to bind to the ExternalStorageService for user " + mUserId);
                throw new TimeoutException("Latch wait for " + reason + " elapsed");
                throw new TimeoutException("Latch wait for " + reason + " elapsed");