Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +2 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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. Loading Loading @@ -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 { Loading Loading @@ -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 { Loading packages/MtpDocumentsProvider/src/com/android/mtp/RootScanner.java +12 −4 Original line number Diff line number Diff line Loading @@ -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 { /** Loading Loading @@ -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. Loading Loading @@ -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. Loading packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -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); Loading packages/MtpDocumentsProvider/tests/src/com/android/mtp/PipeManagerTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +2 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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. Loading Loading @@ -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 { Loading Loading @@ -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 { Loading
packages/MtpDocumentsProvider/src/com/android/mtp/RootScanner.java +12 −4 Original line number Diff line number Diff line Loading @@ -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 { /** Loading Loading @@ -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. Loading Loading @@ -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. Loading
packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -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); Loading
packages/MtpDocumentsProvider/tests/src/com/android/mtp/PipeManagerTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading