return task.createCursor(mResolver, columnNames);
}
- synchronized void clearCache(int deviceId) {
+ synchronized void clearTasks(int deviceId) {
mTaskList.clearTaskForDevice(deviceId);
}
- synchronized void clearCache() {
+ synchronized void clearCompletedTasks() {
mTaskList.clearCompletedTask();
}
+ synchronized void clearTask(Identifier parentIdentifier) {
+ mTaskList.clearTask(parentIdentifier);
+ }
+
private class BackgroundLoaderThread extends Thread {
@Override
public void run() {
}
}
}
+
+ void clearTask(Identifier parentIdentifier) {
+ for (int i = 0; i < size(); i++) {
+ final LoaderTask task = get(i);
+ if (task.mIdentifier.mDeviceId == parentIdentifier.mDeviceId &&
+ task.mIdentifier.mObjectHandle == parentIdentifier.mObjectHandle) {
+ remove(i);
+ return;
+ }
+ }
+ }
}
private static class LoaderTask {
case "r":
return mPipeManager.readDocument(mMtpManager, identifier);
case "w":
+ // TODO: Clear the parent document loader task (if exists) and call notify
+ // when writing is completed.
return mPipeManager.writeDocument(getContext(), mMtpManager, identifier);
default:
// TODO: Add support for seekable files.
final int parentHandle =
mMtpManager.getParent(identifier.mDeviceId, identifier.mObjectHandle);
mMtpManager.deleteDocument(identifier.mDeviceId, identifier.mObjectHandle);
- notifyChildDocumentsChange(new Identifier(
- identifier.mDeviceId, identifier.mStorageId, parentHandle).toDocumentId());
+ final Identifier parentIdentifier = new Identifier(
+ identifier.mDeviceId, identifier.mStorageId, parentHandle);
+ mDocumentLoader.clearTask(parentIdentifier);
+ notifyChildDocumentsChange(parentIdentifier.toDocumentId());
} catch (IOException error) {
throw new FileNotFoundException(error.getMessage());
}
@Override
public void onTrimMemory(int level) {
- mDocumentLoader.clearCache();
+ mDocumentLoader.clearCompletedTasks();
}
@Override
.setFormat(CursorHelper.mimeTypeToFormatType(mimeType))
.setName(displayName)
.build(), pipe[1]);
- final String documentId = new Identifier(parentId.mDeviceId, parentId.mStorageId,
+ final String documentId = new Identifier(parentId.mDeviceId, parentId.mStorageId,
objectHandle).toDocumentId();
+ mDocumentLoader.clearTask(parentId);
notifyChildDocumentsChange(parentDocumentId);
return documentId;
} catch (IOException error) {
void closeDevice(int deviceId) throws IOException {
mMtpManager.closeDevice(deviceId);
- mDocumentLoader.clearCache(deviceId);
+ mDocumentLoader.clearTasks(deviceId);
mRootScanner.scanNow();
}
for (int deviceId : mMtpManager.getOpenedDeviceIds()) {
try {
mMtpManager.closeDevice(deviceId);
- mDocumentLoader.clearCache(deviceId);
+ mDocumentLoader.clearTasks(deviceId);
closed = true;
} catch (IOException d) {
Log.d(TAG, "Failed to close the MTP device: " + deviceId);