Loading packages/MtpDocumentsProvider/src/com/android/mtp/DocumentLoader.java +4 −3 Original line number Original line Diff line number Diff line Loading @@ -196,9 +196,10 @@ class DocumentLoader implements AutoCloseable { } } task.loadObjectInfoList(NUM_LOADING_ENTRIES); task.loadObjectInfoList(NUM_LOADING_ENTRIES); final boolean shouldNotify = final boolean shouldNotify = task.mLastNotified.getTime() < task.getState() != LoaderTask.STATE_CANCELLED && (task.mLastNotified.getTime() < new Date().getTime() - NOTIFY_PERIOD_MS || new Date().getTime() - NOTIFY_PERIOD_MS || task.getState() != LoaderTask.STATE_LOADING; task.getState() != LoaderTask.STATE_LOADING); if (shouldNotify) { if (shouldNotify) { task.notify(mResolver); task.notify(mResolver); } } Loading packages/MtpDocumentsProvider/tests/src/com/android/mtp/DocumentLoaderTest.java +11 −6 Original line number Original line Diff line number Diff line Loading @@ -143,9 +143,9 @@ public class DocumentLoaderTest extends AndroidTestCase { } } } } public void testCancelTask() throws IOException, InterruptedException { public void testCancelTask() throws IOException, InterruptedException, TimeoutException { setUpDocument(mManager, setUpDocument(mManager, DocumentLoader.NUM_INITIAL_ENTRIES + DocumentLoader.NUM_LOADING_ENTRIES + 1); DocumentLoader.NUM_INITIAL_ENTRIES + 1); // Block the first iteration in the background thread. // Block the first iteration in the background thread. mManager.blockDocument( mManager.blockDocument( Loading @@ -155,19 +155,24 @@ public class DocumentLoaderTest extends AndroidTestCase { MtpDocumentsProvider.DEFAULT_DOCUMENT_PROJECTION, mParentIdentifier)) { MtpDocumentsProvider.DEFAULT_DOCUMENT_PROJECTION, mParentIdentifier)) { assertTrue(cursor.getExtras().getBoolean(DocumentsContract.EXTRA_LOADING)); assertTrue(cursor.getExtras().getBoolean(DocumentsContract.EXTRA_LOADING)); } } Thread.sleep(DocumentLoader.NOTIFY_PERIOD_MS); final Uri uri = DocumentsContract.buildChildDocumentsUri( MtpDocumentsProvider.AUTHORITY, mParentIdentifier.mDocumentId); assertEquals(0, mResolver.getChangeCount(uri)); // Clear task while the first iteration is being blocked. // Clear task while the first iteration is being blocked. mLoader.cancelTask(mParentIdentifier); mManager.unblockDocument( mManager.unblockDocument( 0, DocumentLoader.NUM_INITIAL_ENTRIES + 1); 0, DocumentLoader.NUM_INITIAL_ENTRIES + 1); mLoader.cancelTask(mParentIdentifier); Thread.sleep(DocumentLoader.NOTIFY_PERIOD_MS); assertEquals(0, mResolver.getChangeCount(uri)); Thread.sleep(DocumentLoader.NOTIFY_PERIOD_MS * 2); // Check if it's OK to query invalidated task. // Check if it's OK to query invalidated task. try (final Cursor cursor = mLoader.queryChildDocuments( try (final Cursor cursor = mLoader.queryChildDocuments( MtpDocumentsProvider.DEFAULT_DOCUMENT_PROJECTION, mParentIdentifier)) { MtpDocumentsProvider.DEFAULT_DOCUMENT_PROJECTION, mParentIdentifier)) { assertTrue(cursor.getExtras().getBoolean(DocumentsContract.EXTRA_LOADING)); } } mResolver.waitForNotification(uri, 1); } } private void setUpLoader() { private void setUpLoader() { Loading Loading
packages/MtpDocumentsProvider/src/com/android/mtp/DocumentLoader.java +4 −3 Original line number Original line Diff line number Diff line Loading @@ -196,9 +196,10 @@ class DocumentLoader implements AutoCloseable { } } task.loadObjectInfoList(NUM_LOADING_ENTRIES); task.loadObjectInfoList(NUM_LOADING_ENTRIES); final boolean shouldNotify = final boolean shouldNotify = task.mLastNotified.getTime() < task.getState() != LoaderTask.STATE_CANCELLED && (task.mLastNotified.getTime() < new Date().getTime() - NOTIFY_PERIOD_MS || new Date().getTime() - NOTIFY_PERIOD_MS || task.getState() != LoaderTask.STATE_LOADING; task.getState() != LoaderTask.STATE_LOADING); if (shouldNotify) { if (shouldNotify) { task.notify(mResolver); task.notify(mResolver); } } Loading
packages/MtpDocumentsProvider/tests/src/com/android/mtp/DocumentLoaderTest.java +11 −6 Original line number Original line Diff line number Diff line Loading @@ -143,9 +143,9 @@ public class DocumentLoaderTest extends AndroidTestCase { } } } } public void testCancelTask() throws IOException, InterruptedException { public void testCancelTask() throws IOException, InterruptedException, TimeoutException { setUpDocument(mManager, setUpDocument(mManager, DocumentLoader.NUM_INITIAL_ENTRIES + DocumentLoader.NUM_LOADING_ENTRIES + 1); DocumentLoader.NUM_INITIAL_ENTRIES + 1); // Block the first iteration in the background thread. // Block the first iteration in the background thread. mManager.blockDocument( mManager.blockDocument( Loading @@ -155,19 +155,24 @@ public class DocumentLoaderTest extends AndroidTestCase { MtpDocumentsProvider.DEFAULT_DOCUMENT_PROJECTION, mParentIdentifier)) { MtpDocumentsProvider.DEFAULT_DOCUMENT_PROJECTION, mParentIdentifier)) { assertTrue(cursor.getExtras().getBoolean(DocumentsContract.EXTRA_LOADING)); assertTrue(cursor.getExtras().getBoolean(DocumentsContract.EXTRA_LOADING)); } } Thread.sleep(DocumentLoader.NOTIFY_PERIOD_MS); final Uri uri = DocumentsContract.buildChildDocumentsUri( MtpDocumentsProvider.AUTHORITY, mParentIdentifier.mDocumentId); assertEquals(0, mResolver.getChangeCount(uri)); // Clear task while the first iteration is being blocked. // Clear task while the first iteration is being blocked. mLoader.cancelTask(mParentIdentifier); mManager.unblockDocument( mManager.unblockDocument( 0, DocumentLoader.NUM_INITIAL_ENTRIES + 1); 0, DocumentLoader.NUM_INITIAL_ENTRIES + 1); mLoader.cancelTask(mParentIdentifier); Thread.sleep(DocumentLoader.NOTIFY_PERIOD_MS); assertEquals(0, mResolver.getChangeCount(uri)); Thread.sleep(DocumentLoader.NOTIFY_PERIOD_MS * 2); // Check if it's OK to query invalidated task. // Check if it's OK to query invalidated task. try (final Cursor cursor = mLoader.queryChildDocuments( try (final Cursor cursor = mLoader.queryChildDocuments( MtpDocumentsProvider.DEFAULT_DOCUMENT_PROJECTION, mParentIdentifier)) { MtpDocumentsProvider.DEFAULT_DOCUMENT_PROJECTION, mParentIdentifier)) { assertTrue(cursor.getExtras().getBoolean(DocumentsContract.EXTRA_LOADING)); } } mResolver.waitForNotification(uri, 1); } } private void setUpLoader() { private void setUpLoader() { Loading