Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +8 −2 Original line number Diff line number Diff line Loading @@ -440,7 +440,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { if (DEBUG) { Log.d(TAG, "Close device " + deviceId); } getDeviceToolkit(deviceId).mDocumentLoader.close(); getDeviceToolkit(deviceId).close(); mDeviceToolkits.remove(deviceId); mMtpManager.closeDevice(deviceId); if (mDeviceToolkits.size() == 0) { Loading Loading @@ -496,7 +496,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { return cursor; } private static class DeviceToolkit { private static class DeviceToolkit implements AutoCloseable { public final PipeManager mPipeManager; public final DocumentLoader mDocumentLoader; public final MtpDeviceRecord mDeviceRecord; Loading @@ -509,6 +509,12 @@ public class MtpDocumentsProvider extends DocumentsProvider { mDocumentLoader = new DocumentLoader(record, manager, resolver, database); mDeviceRecord = record; } @Override public void close() throws InterruptedException { mPipeManager.close(); mDocumentLoader.close(); } } private class AppFuseCallback implements AppFuse.Callback { Loading packages/MtpDocumentsProvider/src/com/android/mtp/PipeManager.java +9 −2 Original line number Diff line number Diff line Loading @@ -26,8 +26,14 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; class PipeManager { /** * Milliseconds we wait for background thread when pausing. */ private final static long AWAIT_TERMINATION_TIMEOUT = 2000; final ExecutorService mExecutor; final MtpDatabase mDatabase; Loading Loading @@ -203,7 +209,8 @@ class PipeManager { } } void close() { mExecutor.shutdown(); boolean close() throws InterruptedException { mExecutor.shutdownNow(); return mExecutor.awaitTermination(AWAIT_TERMINATION_TIMEOUT, TimeUnit.MILLISECONDS); } } packages/MtpDocumentsProvider/tests/src/com/android/mtp/PipeManagerTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,11 @@ public class PipeManagerTest extends AndroidTestCase { mPipeManager = new PipeManager(mDatabase, mExecutor); } @Override protected void tearDown() throws Exception { assertTrue(mPipeManager.close()); } public void testReadDocument_basic() throws Exception { mtpManager.setImportFileBytes(0, 1, HELLO_BYTES); final ParcelFileDescriptor descriptor = mPipeManager.readDocument( Loading Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +8 −2 Original line number Diff line number Diff line Loading @@ -440,7 +440,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { if (DEBUG) { Log.d(TAG, "Close device " + deviceId); } getDeviceToolkit(deviceId).mDocumentLoader.close(); getDeviceToolkit(deviceId).close(); mDeviceToolkits.remove(deviceId); mMtpManager.closeDevice(deviceId); if (mDeviceToolkits.size() == 0) { Loading Loading @@ -496,7 +496,7 @@ public class MtpDocumentsProvider extends DocumentsProvider { return cursor; } private static class DeviceToolkit { private static class DeviceToolkit implements AutoCloseable { public final PipeManager mPipeManager; public final DocumentLoader mDocumentLoader; public final MtpDeviceRecord mDeviceRecord; Loading @@ -509,6 +509,12 @@ public class MtpDocumentsProvider extends DocumentsProvider { mDocumentLoader = new DocumentLoader(record, manager, resolver, database); mDeviceRecord = record; } @Override public void close() throws InterruptedException { mPipeManager.close(); mDocumentLoader.close(); } } private class AppFuseCallback implements AppFuse.Callback { Loading
packages/MtpDocumentsProvider/src/com/android/mtp/PipeManager.java +9 −2 Original line number Diff line number Diff line Loading @@ -26,8 +26,14 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; class PipeManager { /** * Milliseconds we wait for background thread when pausing. */ private final static long AWAIT_TERMINATION_TIMEOUT = 2000; final ExecutorService mExecutor; final MtpDatabase mDatabase; Loading Loading @@ -203,7 +209,8 @@ class PipeManager { } } void close() { mExecutor.shutdown(); boolean close() throws InterruptedException { mExecutor.shutdownNow(); return mExecutor.awaitTermination(AWAIT_TERMINATION_TIMEOUT, TimeUnit.MILLISECONDS); } }
packages/MtpDocumentsProvider/tests/src/com/android/mtp/PipeManagerTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,11 @@ public class PipeManagerTest extends AndroidTestCase { mPipeManager = new PipeManager(mDatabase, mExecutor); } @Override protected void tearDown() throws Exception { assertTrue(mPipeManager.close()); } public void testReadDocument_basic() throws Exception { mtpManager.setImportFileBytes(0, 1, HELLO_BYTES); final ParcelFileDescriptor descriptor = mPipeManager.readDocument( Loading