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

Commit aa0fa384 authored by Daichi Hirono's avatar Daichi Hirono Committed by Android (Google) Code Review
Browse files

Merge "Regard timeout as an error in the MtpDocumentsProvider test." into nyc-dev

parents 32d1a1a9 acb0e27b
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import android.provider.DocumentsContract.Root;
import android.provider.DocumentsContract;
import android.provider.DocumentsProvider;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log;

import com.android.internal.annotations.GuardedBy;
@@ -48,6 +47,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * DocumentsProvider for MTP devices.
@@ -426,7 +426,7 @@ public class MtpDocumentsProvider extends DocumentsProvider {
                    closeDeviceInternal(id);
                }
                mRootScanner.pause();
            } catch (InterruptedException|IOException e) {
            } catch (InterruptedException | IOException | TimeoutException e) {
                // It should fail unit tests by throwing runtime exception.
                throw new RuntimeException(e);
            } finally {
@@ -464,9 +464,6 @@ public class MtpDocumentsProvider extends DocumentsProvider {
        getDeviceToolkit(deviceId).close();
        mDeviceToolkits.remove(deviceId);
        mMtpManager.closeDevice(deviceId);
        if (mDeviceToolkits.size() == 0) {
            mRootScanner.pause();
        }
    }

    private DeviceToolkit getDeviceToolkit(int deviceId) throws FileNotFoundException {
+12 −4
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

final class RootScanner {
    /**
@@ -95,16 +96,20 @@ final class RootScanner {
     * Stops background thread and wait for its termination.
     * @throws InterruptedException
     */
    synchronized void pause() throws InterruptedException {
    synchronized void pause() throws InterruptedException, TimeoutException {
        if (mExecutor == null) {
            return;
        }
        mExecutor.shutdownNow();
        try {
            if (!mExecutor.awaitTermination(AWAIT_TERMINATION_TIMEOUT, TimeUnit.MILLISECONDS)) {
            Log.e(MtpDocumentsProvider.TAG, "Failed to terminate RootScanner's background thread.");
                throw new TimeoutException(
                        "Timeout for terminating RootScanner's background thread.");
            }
        } finally {
            mExecutor = null;
        }
    }

    /**
     * Runnable to scan roots and update the database information.
@@ -173,6 +178,9 @@ final class RootScanner {
                }
                mFirstScanCompleted.countDown();
                pollingCount++;
                if (devices.length == 0) {
                    break;
                }
                try {
                    // Use SHORT_POLLING_PERIOD for the first SHORT_POLLING_TIMES because it is
                    // more likely to add new root just after the device is added.
+0 −2
Original line number Diff line number Diff line
@@ -262,11 +262,9 @@ public class MtpDocumentsProviderTest extends AndroidTestCase {
                null));
        {
            mProvider.openDevice(0);
            mProvider.resumeRootScanner();
            mResolver.waitForNotification(ROOTS_URI, 1);

            mProvider.openDevice(1);
            mProvider.resumeRootScanner();
            mResolver.waitForNotification(ROOTS_URI, 2);

            final Cursor cursor = mProvider.queryRoots(null);
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public class PipeManagerTest extends AndroidTestCase {
    @Override
    protected void tearDown() throws Exception {
        assertTrue(mPipeManager.close());
        mDatabase.close();
    }

    public void testReadDocument_basic() throws Exception {