diff options
author | 2019-08-29 06:35:49 +0000 | |
---|---|---|
committer | 2019-08-29 06:35:49 +0000 | |
commit | 7b1ba41ec0137956a33c05fe7f2e187c5c3f2183 (patch) | |
tree | 19338e3676a13be5365e72faedd440bc6c1c1e2e | |
parent | f1c49b8dcd404a879b4de53e1098a3ee0e26bf8c (diff) | |
parent | a7322ac16ff6e2feb7f1899a27572289841c352c (diff) |
Merge "Fix progress bar when optimized copy or optimized move"
-rw-r--r-- | src/com/android/documentsui/services/CopyJob.java | 33 | ||||
-rw-r--r-- | src/com/android/documentsui/services/MoveJob.java | 4 |
2 files changed, 27 insertions, 10 deletions
diff --git a/src/com/android/documentsui/services/CopyJob.java b/src/com/android/documentsui/services/CopyJob.java index 5502e0a5a..196e970ca 100644 --- a/src/com/android/documentsui/services/CopyJob.java +++ b/src/com/android/documentsui/services/CopyJob.java @@ -59,9 +59,13 @@ import android.system.ErrnoException; import android.system.Int64Ref; import android.system.Os; import android.system.OsConstants; +import android.util.ArrayMap; import android.util.Log; import android.webkit.MimeTypeMap; +import androidx.annotation.StringRes; +import androidx.annotation.VisibleForTesting; + import com.android.documentsui.DocumentsApplication; import com.android.documentsui.MetricConsts; import com.android.documentsui.Metrics; @@ -82,13 +86,11 @@ import java.io.InputStream; import java.io.SyncFailedException; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; import java.util.function.LongSupplier; -import androidx.annotation.StringRes; -import androidx.annotation.VisibleForTesting; - class CopyJob extends ResolvedResourcesJob { private static final String TAG = "CopyJob"; @@ -100,6 +102,7 @@ class CopyJob extends ResolvedResourcesJob { private final Handler mHandler = new Handler(Looper.getMainLooper()); private final Messenger mMessenger; + private final Map<String, Long> mDirSizeMap = new ArrayMap<>(); private CopyJobProgressTracker mProgressTracker; @@ -307,6 +310,22 @@ class CopyJob extends ResolvedResourcesJob { } /** + * Logs progress when optimized copy. + * + * @param doc the doc current copy. + */ + protected void makeOptimizedCopyProgress(DocumentInfo doc) { + long bytes; + if (doc.isDirectory()) { + Long byteObject = mDirSizeMap.get(doc.documentId); + bytes = byteObject == null ? 0 : byteObject.longValue(); + } else { + bytes = doc.size; + } + makeCopyProgress(bytes); + } + + /** * Copies a the given document to the given location. * * @param src DocumentInfos for the documents to copy. @@ -318,8 +337,6 @@ class CopyJob extends ResolvedResourcesJob { */ void processDocument(DocumentInfo src, DocumentInfo srcParent, DocumentInfo dstDirInfo) throws ResourceException { - - // TODO: When optimized copy kicks in, we'll not making any progress updates. // For now. Local storage isn't using optimized copy. // When copying within the same provider, try to use optimized copying. @@ -330,6 +347,7 @@ class CopyJob extends ResolvedResourcesJob { if (DocumentsContract.copyDocument(wrap(getClient(src)), src.derivedUri, dstDirInfo.derivedUri) != null) { Metrics.logFileOperated(operationType, MetricConsts.OPMODE_PROVIDER); + makeOptimizedCopyProgress(src); return; } } catch (FileNotFoundException | RemoteException | RuntimeException e) { @@ -657,8 +675,9 @@ class CopyJob extends ResolvedResourcesJob { if (src.isDirectory()) { // Directories need to be recursed into. try { - bytesRequired += - calculateFileSizesRecursively(getClient(src), src.derivedUri); + long size = calculateFileSizesRecursively(getClient(src), src.derivedUri); + bytesRequired += size; + mDirSizeMap.put(src.documentId, size); } catch (RemoteException e) { Log.w(TAG, "Failed to obtain the client for " + src.derivedUri, e); return new IndeterminateProgressTracker(bytesRequired); diff --git a/src/com/android/documentsui/services/MoveJob.java b/src/com/android/documentsui/services/MoveJob.java index faccedb51..cc1601bfe 100644 --- a/src/com/android/documentsui/services/MoveJob.java +++ b/src/com/android/documentsui/services/MoveJob.java @@ -141,9 +141,6 @@ final class MoveJob extends CopyJob { void processDocument(DocumentInfo src, DocumentInfo srcParent, DocumentInfo dest) throws ResourceException { - - // TODO: When optimized move kicks in, we're not making any progress updates. FIX IT! - // When moving within the same provider, try to use optimized moving. // If not supported, then fallback to byte-by-byte copy/move. if (src.authority.equals(dest.authority) && (srcParent != null || mSrcParent != null)) { @@ -153,6 +150,7 @@ final class MoveJob extends CopyJob { srcParent != null ? srcParent.derivedUri : mSrcParent.derivedUri, dest.derivedUri) != null) { Metrics.logFileOperated(operationType, MetricConsts.OPMODE_PROVIDER); + makeOptimizedCopyProgress(src); return; } } catch (FileNotFoundException | RemoteException | RuntimeException e) { |