Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.documentsui.services; |
| 18 | |
| 19 | import static android.os.SystemClock.elapsedRealtime; |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 20 | import static android.provider.DocumentsContract.buildChildDocumentsUri; |
| 21 | import static android.provider.DocumentsContract.buildDocumentUri; |
| 22 | import static android.provider.DocumentsContract.getDocumentId; |
| 23 | import static android.provider.DocumentsContract.isChildDocument; |
Tomasz Mikolajewski | 748ea8c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 24 | import static com.android.documentsui.OperationDialogFragment.DIALOG_TYPE_CONVERTED; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 25 | import static com.android.documentsui.Shared.DEBUG; |
| 26 | import static com.android.documentsui.model.DocumentInfo.getCursorLong; |
| 27 | import static com.android.documentsui.model.DocumentInfo.getCursorString; |
Tomasz Mikolajewski | 748ea8c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 28 | import static com.android.documentsui.services.FileOperationService.EXTRA_DIALOG_TYPE; |
| 29 | import static com.android.documentsui.services.FileOperationService.EXTRA_OPERATION; |
| 30 | import static com.android.documentsui.services.FileOperationService.EXTRA_SRC_LIST; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 31 | import static com.android.documentsui.services.FileOperationService.OPERATION_COPY; |
| 32 | import static com.google.common.base.Preconditions.checkArgument; |
| 33 | |
| 34 | import android.annotation.StringRes; |
| 35 | import android.app.Notification; |
| 36 | import android.app.Notification.Builder; |
Tomasz Mikolajewski | 748ea8c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 37 | import android.app.PendingIntent; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 38 | import android.content.ContentProviderClient; |
| 39 | import android.content.Context; |
Tomasz Mikolajewski | 748ea8c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 40 | import android.content.Intent; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 41 | import android.content.res.AssetFileDescriptor; |
| 42 | import android.database.Cursor; |
| 43 | import android.net.Uri; |
| 44 | import android.os.CancellationSignal; |
| 45 | import android.os.ParcelFileDescriptor; |
| 46 | import android.os.RemoteException; |
| 47 | import android.provider.DocumentsContract; |
| 48 | import android.provider.DocumentsContract.Document; |
| 49 | import android.text.format.DateUtils; |
| 50 | import android.util.Log; |
| 51 | import android.webkit.MimeTypeMap; |
| 52 | |
Ben Kwa | d5b2af1 | 2016-01-28 16:39:57 -0800 | [diff] [blame] | 53 | import com.android.documentsui.Metrics; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 54 | import com.android.documentsui.R; |
| 55 | import com.android.documentsui.model.DocumentInfo; |
| 56 | import com.android.documentsui.model.DocumentStack; |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 57 | import com.android.documentsui.services.FileOperationService.OpType; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 58 | |
| 59 | import libcore.io.IoUtils; |
| 60 | |
| 61 | import java.io.FileNotFoundException; |
| 62 | import java.io.IOException; |
| 63 | import java.io.InputStream; |
| 64 | import java.io.OutputStream; |
| 65 | import java.text.NumberFormat; |
Tomasz Mikolajewski | 748ea8c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 66 | import java.util.ArrayList; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 67 | import java.util.List; |
| 68 | |
| 69 | class CopyJob extends Job { |
| 70 | private static final String TAG = "CopyJob"; |
| 71 | private static final int PROGRESS_INTERVAL_MILLIS = 1000; |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 72 | final List<DocumentInfo> mSrcs; |
Tomasz Mikolajewski | 748ea8c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 73 | final ArrayList<DocumentInfo> convertedFiles = new ArrayList<>(); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 74 | |
| 75 | private long mStartTime = -1; |
| 76 | private long mBatchSize; |
| 77 | private long mBytesCopied; |
| 78 | private long mLastNotificationTime; |
| 79 | // Speed estimation |
| 80 | private long mBytesCopiedSample; |
| 81 | private long mSampleTime; |
| 82 | private long mSpeed; |
| 83 | private long mRemainingTime; |
| 84 | |
| 85 | /** |
| 86 | * Copies files to a destination identified by {@code destination}. |
| 87 | * @see @link {@link Job} constructor for most param descriptions. |
| 88 | * |
| 89 | * @param srcs List of files to be copied. |
| 90 | */ |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 91 | CopyJob(Context service, Context appContext, Listener listener, |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 92 | String id, DocumentStack stack, List<DocumentInfo> srcs) { |
| 93 | super(service, appContext, listener, OPERATION_COPY, id, stack); |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 94 | |
| 95 | checkArgument(!srcs.isEmpty()); |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 96 | this.mSrcs = srcs; |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @see @link {@link Job} constructor for most param descriptions. |
| 101 | * |
| 102 | * @param srcs List of files to be copied. |
| 103 | */ |
| 104 | CopyJob(Context service, Context appContext, Listener listener, |
| 105 | @OpType int opType, String id, DocumentStack destination, List<DocumentInfo> srcs) { |
| 106 | super(service, appContext, listener, opType, id, destination); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 107 | |
| 108 | checkArgument(!srcs.isEmpty()); |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 109 | this.mSrcs = srcs; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | Builder createProgressBuilder() { |
| 114 | return super.createProgressBuilder( |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 115 | service.getString(R.string.copy_notification_title), |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 116 | R.drawable.ic_menu_copy, |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 117 | service.getString(android.R.string.cancel), |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 118 | R.drawable.ic_cab_cancel); |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public Notification getSetupNotification() { |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 123 | return getSetupNotification(service.getString(R.string.copy_preparing)); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | public boolean shouldUpdateProgress() { |
| 127 | // Wait a while between updates :) |
| 128 | return elapsedRealtime() - mLastNotificationTime > PROGRESS_INTERVAL_MILLIS; |
| 129 | } |
| 130 | |
| 131 | Notification getProgressNotification(@StringRes int msgId) { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 132 | if (mBatchSize >= 0) { |
| 133 | double completed = (double) this.mBytesCopied / mBatchSize; |
| 134 | mProgressBuilder.setProgress(100, (int) (completed * 100), false); |
| 135 | mProgressBuilder.setContentInfo( |
| 136 | NumberFormat.getPercentInstance().format(completed)); |
| 137 | } else { |
| 138 | // If the total file size failed to compute on some files, then show |
| 139 | // an indeterminate spinner. CopyJob would most likely fail on those |
| 140 | // files while copying, but would continue with another files. |
| 141 | // Also, if the total size is 0 bytes, show an indeterminate spinner. |
| 142 | mProgressBuilder.setProgress(0, 0, true); |
| 143 | } |
| 144 | |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 145 | if (mRemainingTime > 0) { |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 146 | mProgressBuilder.setContentText(service.getString(msgId, |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 147 | DateUtils.formatDuration(mRemainingTime))); |
| 148 | } else { |
| 149 | mProgressBuilder.setContentText(null); |
| 150 | } |
| 151 | |
| 152 | // Remember when we last returned progress so we can provide an answer |
| 153 | // in shouldUpdateProgress. |
| 154 | mLastNotificationTime = elapsedRealtime(); |
| 155 | return mProgressBuilder.build(); |
| 156 | } |
| 157 | |
| 158 | public Notification getProgressNotification() { |
| 159 | return getProgressNotification(R.string.copy_remaining); |
| 160 | } |
| 161 | |
| 162 | void onBytesCopied(long numBytes) { |
| 163 | this.mBytesCopied += numBytes; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Generates an estimate of the remaining time in the copy. |
| 168 | */ |
| 169 | void updateRemainingTimeEstimate() { |
| 170 | long elapsedTime = elapsedRealtime() - mStartTime; |
| 171 | |
| 172 | final long sampleDuration = elapsedTime - mSampleTime; |
| 173 | final long sampleSpeed = ((mBytesCopied - mBytesCopiedSample) * 1000) / sampleDuration; |
| 174 | if (mSpeed == 0) { |
| 175 | mSpeed = sampleSpeed; |
| 176 | } else { |
| 177 | mSpeed = ((3 * mSpeed) + sampleSpeed) / 4; |
| 178 | } |
| 179 | |
| 180 | if (mSampleTime > 0 && mSpeed > 0) { |
| 181 | mRemainingTime = ((mBatchSize - mBytesCopied) * 1000) / mSpeed; |
| 182 | } else { |
| 183 | mRemainingTime = 0; |
| 184 | } |
| 185 | |
| 186 | mSampleTime = elapsedTime; |
| 187 | mBytesCopiedSample = mBytesCopied; |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | Notification getFailureNotification() { |
| 192 | return getFailureNotification( |
| 193 | R.plurals.copy_error_notification_title, R.drawable.ic_menu_copy); |
| 194 | } |
| 195 | |
| 196 | @Override |
Tomasz Mikolajewski | 748ea8c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 197 | Notification getWarningNotification() { |
Tomasz Mikolajewski | cd27015 | 2016-02-01 12:01:14 +0900 | [diff] [blame] | 198 | final Intent navigateIntent = buildNavigateIntent(INTENT_TAG_WARNING); |
Tomasz Mikolajewski | 748ea8c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 199 | navigateIntent.putExtra(EXTRA_DIALOG_TYPE, DIALOG_TYPE_CONVERTED); |
| 200 | navigateIntent.putExtra(EXTRA_OPERATION, operationType); |
| 201 | |
| 202 | navigateIntent.putParcelableArrayListExtra(EXTRA_SRC_LIST, convertedFiles); |
| 203 | |
| 204 | // TODO: Consider adding a dialog on tapping the notification with a list of |
| 205 | // converted files. |
| 206 | final Notification.Builder warningBuilder = new Notification.Builder(service) |
| 207 | .setContentTitle(service.getResources().getString( |
| 208 | R.string.notification_copy_files_converted_title)) |
| 209 | .setContentText(service.getString( |
| 210 | R.string.notification_touch_for_details)) |
| 211 | .setContentIntent(PendingIntent.getActivity(appContext, 0, navigateIntent, |
| 212 | PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT)) |
| 213 | .setCategory(Notification.CATEGORY_ERROR) |
| 214 | .setSmallIcon(R.drawable.ic_menu_copy) |
| 215 | .setAutoCancel(true); |
| 216 | return warningBuilder.build(); |
| 217 | } |
| 218 | |
| 219 | @Override |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 220 | void start() { |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 221 | mStartTime = elapsedRealtime(); |
| 222 | |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 223 | try { |
| 224 | mBatchSize = calculateSize(mSrcs); |
| 225 | } catch (ResourceException e) { |
| 226 | Log.w(TAG, "Failed to calculate total size. Copying without progress."); |
| 227 | mBatchSize = -1; |
| 228 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 229 | |
| 230 | DocumentInfo srcInfo; |
Ben Kwa | d5b2af1 | 2016-01-28 16:39:57 -0800 | [diff] [blame] | 231 | DocumentInfo dstInfo = stack.peek(); |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 232 | for (int i = 0; i < mSrcs.size() && !isCanceled(); ++i) { |
| 233 | srcInfo = mSrcs.get(i); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 234 | |
| 235 | // Guard unsupported recursive operation. |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 236 | try { |
| 237 | if (dstInfo.equals(srcInfo) || isDescendentOf(srcInfo, dstInfo)) { |
| 238 | throw new ResourceException("Cannot copy to itself recursively."); |
| 239 | } |
| 240 | } catch (ResourceException e) { |
| 241 | Log.e(TAG, e.toString()); |
| 242 | onFileFailed(srcInfo); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 243 | continue; |
| 244 | } |
| 245 | |
| 246 | if (DEBUG) Log.d(TAG, |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 247 | "Copying " + srcInfo.displayName + " (" + srcInfo.derivedUri + ")" |
| 248 | + " to " + dstInfo.displayName + " (" + dstInfo.derivedUri + ")"); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 249 | |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 250 | try { |
| 251 | processDocument(srcInfo, null, dstInfo); |
| 252 | } catch (ResourceException e) { |
| 253 | Log.e(TAG, e.toString()); |
| 254 | onFileFailed(srcInfo); |
| 255 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 256 | } |
Ben Kwa | d5b2af1 | 2016-01-28 16:39:57 -0800 | [diff] [blame] | 257 | Metrics.logFileOperation(service, operationType, mSrcs, dstInfo); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Tomasz Mikolajewski | 748ea8c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 260 | @Override |
| 261 | boolean hasWarnings() { |
| 262 | return !convertedFiles.isEmpty(); |
| 263 | } |
| 264 | |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 265 | /** |
| 266 | * Logs progress on the current copy operation. Displays/Updates the progress notification. |
| 267 | * |
| 268 | * @param bytesCopied |
| 269 | */ |
| 270 | private void makeCopyProgress(long bytesCopied) { |
| 271 | onBytesCopied(bytesCopied); |
| 272 | if (shouldUpdateProgress()) { |
| 273 | updateRemainingTimeEstimate(); |
| 274 | listener.onProgress(this); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Copies a the given document to the given location. |
| 280 | * |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 281 | * @param src DocumentInfos for the documents to copy. |
Tomasz Mikolajewski | b8436af | 2016-01-25 16:20:15 +0900 | [diff] [blame] | 282 | * @param srcParent DocumentInfo for the parent of the document to process. |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 283 | * @param dstDirInfo The destination directory. |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 284 | * @throws ResourceException |
Tomasz Mikolajewski | b8436af | 2016-01-25 16:20:15 +0900 | [diff] [blame] | 285 | * |
| 286 | * TODO: Stop passing srcParent, as it's not used for copy, but for move only. |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 287 | */ |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 288 | void processDocument(DocumentInfo src, DocumentInfo srcParent, |
| 289 | DocumentInfo dstDirInfo) throws ResourceException { |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 290 | |
| 291 | // TODO: When optimized copy kicks in, we'll not making any progress updates. |
| 292 | // For now. Local storage isn't using optimized copy. |
| 293 | |
Tomasz Mikolajewski | 6704808 | 2016-01-21 10:00:33 +0900 | [diff] [blame] | 294 | // When copying within the same provider, try to use optimized copying. |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 295 | // If not supported, then fallback to byte-by-byte copy/move. |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 296 | if (src.authority.equals(dstDirInfo.authority)) { |
| 297 | if ((src.flags & Document.FLAG_SUPPORTS_COPY) != 0) { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 298 | try { |
| 299 | if (DocumentsContract.copyDocument(getClient(src), src.derivedUri, |
| 300 | dstDirInfo.derivedUri) == null) { |
| 301 | throw new ResourceException("Provider side copy failed for document %s.", |
| 302 | src.derivedUri); |
| 303 | } |
| 304 | } catch (ResourceException e) { |
| 305 | throw e; |
| 306 | } catch (RemoteException | RuntimeException e) { |
| 307 | throw new ResourceException( |
| 308 | "Provider side copy failed for document %s due to an exception.", |
| 309 | src.derivedUri, e); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 310 | } |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 311 | return; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | // If we couldn't do an optimized copy...we fall back to vanilla byte copy. |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 316 | byteCopyDocument(src, dstDirInfo); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 319 | void byteCopyDocument(DocumentInfo src, DocumentInfo dest) throws ResourceException { |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 320 | final String dstMimeType; |
| 321 | final String dstDisplayName; |
| 322 | |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 323 | if (DEBUG) Log.d(TAG, "Doing byte copy of document: " + src); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 324 | // If the file is virtual, but can be converted to another format, then try to copy it |
| 325 | // as such format. Also, append an extension for the target mime type (if known). |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 326 | if (src.isVirtualDocument()) { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 327 | String[] streamTypes = null; |
| 328 | try { |
| 329 | streamTypes = getContentResolver().getStreamTypes(src.derivedUri, "*/*"); |
| 330 | } catch (RuntimeException e) { |
| 331 | throw new ResourceException( |
| 332 | "Failed to obtain streamable types for %s due to an exception.", |
| 333 | src.derivedUri, e); |
| 334 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 335 | if (streamTypes != null && streamTypes.length > 0) { |
| 336 | dstMimeType = streamTypes[0]; |
| 337 | final String extension = MimeTypeMap.getSingleton(). |
| 338 | getExtensionFromMimeType(dstMimeType); |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 339 | dstDisplayName = src.displayName + |
| 340 | (extension != null ? "." + extension : src.displayName); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 341 | } else { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 342 | throw new ResourceException("Cannot copy virtual file %s. No streamable formats " |
| 343 | + "available.", src.derivedUri); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 344 | } |
| 345 | } else { |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 346 | dstMimeType = src.mimeType; |
| 347 | dstDisplayName = src.displayName; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | // Create the target document (either a file or a directory), then copy recursively the |
| 351 | // contents (bytes or children). |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 352 | Uri dstUri = null; |
| 353 | try { |
| 354 | dstUri = DocumentsContract.createDocument( |
| 355 | getClient(dest), dest.derivedUri, dstMimeType, dstDisplayName); |
| 356 | } catch (RemoteException | RuntimeException e) { |
| 357 | throw new ResourceException( |
| 358 | "Couldn't create destination document " + dstDisplayName + " in directory %s " |
| 359 | + "due to an exception.", dest.derivedUri, e); |
| 360 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 361 | if (dstUri == null) { |
| 362 | // If this is a directory, the entire subdir will not be copied over. |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 363 | throw new ResourceException( |
| 364 | "Couldn't create destination document " + dstDisplayName + " in directory %s.", |
| 365 | dest.derivedUri); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | DocumentInfo dstInfo = null; |
| 369 | try { |
| 370 | dstInfo = DocumentInfo.fromUri(getContentResolver(), dstUri); |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 371 | } catch (FileNotFoundException | RuntimeException e) { |
| 372 | throw new ResourceException("Could not load DocumentInfo for newly created file %s.", |
| 373 | dstUri); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 376 | if (Document.MIME_TYPE_DIR.equals(src.mimeType)) { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 377 | copyDirectoryHelper(src, dstInfo); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 378 | } else { |
Tomasz Mikolajewski | db87543 | 2016-02-23 15:12:54 +0900 | [diff] [blame] | 379 | copyFileHelper(src, dstInfo, dest, dstMimeType); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 380 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Handles recursion into a directory and copying its contents. Note that in linux terms, this |
| 385 | * does the equivalent of "cp src/* dst", not "cp -r src dst". |
| 386 | * |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 387 | * @param srcDir Info of the directory to copy from. The routine will copy the directory's |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 388 | * contents, not the directory itself. |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 389 | * @param destDir Info of the directory to copy to. Must be created beforehand. |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 390 | * @throws ResourceException |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 391 | */ |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 392 | private void copyDirectoryHelper(DocumentInfo srcDir, DocumentInfo destDir) |
| 393 | throws ResourceException { |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 394 | // Recurse into directories. Copy children into the new subdirectory. |
| 395 | final String queryColumns[] = new String[] { |
| 396 | Document.COLUMN_DISPLAY_NAME, |
| 397 | Document.COLUMN_DOCUMENT_ID, |
| 398 | Document.COLUMN_MIME_TYPE, |
| 399 | Document.COLUMN_SIZE, |
| 400 | Document.COLUMN_FLAGS |
| 401 | }; |
| 402 | Cursor cursor = null; |
| 403 | boolean success = true; |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 404 | // Iterate over srcs in the directory; copy to the destination directory. |
| 405 | final Uri queryUri = buildChildDocumentsUri(srcDir.authority, srcDir.documentId); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 406 | try { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 407 | try { |
| 408 | cursor = getClient(srcDir).query(queryUri, queryColumns, null, null, null); |
| 409 | } catch (RemoteException | RuntimeException e) { |
| 410 | throw new ResourceException("Failed to query children of %s due to an exception.", |
| 411 | srcDir.derivedUri, e); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 412 | } |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 413 | |
| 414 | DocumentInfo src; |
| 415 | while (cursor.moveToNext() && !isCanceled()) { |
| 416 | try { |
| 417 | src = DocumentInfo.fromCursor(cursor, srcDir.authority); |
| 418 | processDocument(src, srcDir, destDir); |
| 419 | } catch (RuntimeException e) { |
| 420 | Log.e(TAG, "Failed to recursively process a file %s due to an exception." |
| 421 | .format(srcDir.derivedUri.toString()), e); |
| 422 | success = false; |
| 423 | } |
| 424 | } |
| 425 | } catch (RuntimeException e) { |
| 426 | Log.e(TAG, "Failed to copy a file %s to %s. " |
| 427 | .format(srcDir.derivedUri.toString(), destDir.derivedUri.toString()), e); |
| 428 | success = false; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 429 | } finally { |
| 430 | IoUtils.closeQuietly(cursor); |
| 431 | } |
| 432 | |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 433 | if (!success) { |
| 434 | throw new RuntimeException("Some files failed to copy during a recursive " |
| 435 | + "directory copy."); |
| 436 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Handles copying a single file. |
| 441 | * |
Tomasz Mikolajewski | db87543 | 2016-02-23 15:12:54 +0900 | [diff] [blame] | 442 | * @param src Info of the file to copy from. |
| 443 | * @param dest Info of the *file* to copy to. Must be created beforehand. |
| 444 | * @param destParent Info of the parent of the destination. |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 445 | * @param mimeType Mime type for the target. Can be different than source for virtual files. |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 446 | * @throws ResourceException |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 447 | */ |
Tomasz Mikolajewski | db87543 | 2016-02-23 15:12:54 +0900 | [diff] [blame] | 448 | private void copyFileHelper(DocumentInfo src, DocumentInfo dest, DocumentInfo destParent, |
| 449 | String mimeType) throws ResourceException { |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 450 | CancellationSignal canceller = new CancellationSignal(); |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 451 | AssetFileDescriptor srcFileAsAsset = null; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 452 | ParcelFileDescriptor srcFile = null; |
| 453 | ParcelFileDescriptor dstFile = null; |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 454 | InputStream in = null; |
| 455 | OutputStream out = null; |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 456 | boolean success = false; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 457 | |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 458 | try { |
| 459 | // If the file is virtual, but can be converted to another format, then try to copy it |
| 460 | // as such format. |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 461 | if (src.isVirtualDocument()) { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 462 | try { |
| 463 | srcFileAsAsset = getClient(src).openTypedAssetFileDescriptor( |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 464 | src.derivedUri, mimeType, null, canceller); |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 465 | } catch (FileNotFoundException | RemoteException | RuntimeException e) { |
| 466 | throw new ResourceException("Failed to open a file as asset for %s due to an " |
| 467 | + "exception.", src.derivedUri, e); |
| 468 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 469 | srcFile = srcFileAsAsset.getParcelFileDescriptor(); |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 470 | try { |
| 471 | in = new AssetFileDescriptor.AutoCloseInputStream(srcFileAsAsset); |
| 472 | } catch (IOException e) { |
| 473 | throw new ResourceException("Failed to open a file input stream for %s due " |
| 474 | + "an exception.", src.derivedUri, e); |
| 475 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 476 | } else { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 477 | try { |
| 478 | srcFile = getClient(src).openFile(src.derivedUri, "r", canceller); |
| 479 | } catch (FileNotFoundException | RemoteException | RuntimeException e) { |
| 480 | throw new ResourceException( |
| 481 | "Failed to open a file for %s due to an exception.", src.derivedUri, e); |
| 482 | } |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 483 | in = new ParcelFileDescriptor.AutoCloseInputStream(srcFile); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 484 | } |
| 485 | |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 486 | try { |
| 487 | dstFile = getClient(dest).openFile(dest.derivedUri, "w", canceller); |
| 488 | } catch (FileNotFoundException | RemoteException | RuntimeException e) { |
| 489 | throw new ResourceException("Failed to open the destination file %s for writing " |
| 490 | + "due to an exception.", dest.derivedUri, e); |
| 491 | } |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 492 | out = new ParcelFileDescriptor.AutoCloseOutputStream(dstFile); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 493 | |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 494 | byte[] buffer = new byte[32 * 1024]; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 495 | int len; |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 496 | try { |
| 497 | while ((len = in.read(buffer)) != -1) { |
| 498 | if (isCanceled()) { |
| 499 | throw new ResourceException("Canceled copy mid-copy of %s", |
| 500 | src.derivedUri); |
| 501 | } |
| 502 | out.write(buffer, 0, len); |
| 503 | makeCopyProgress(len); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 504 | } |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 505 | |
| 506 | srcFile.checkError(); |
| 507 | } catch (IOException e) { |
| 508 | throw new ResourceException( |
| 509 | "Failed to copy bytes from %s to %s due to an IO exception.", |
| 510 | src.derivedUri, dest.derivedUri, e); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 513 | if (src.isVirtualDocument()) { |
| 514 | convertedFiles.add(src); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 515 | } |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 516 | |
| 517 | success = true; |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 518 | } finally { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 519 | if (!success) { |
| 520 | if (dstFile != null) { |
| 521 | try { |
| 522 | dstFile.closeWithError("Error copying bytes."); |
| 523 | } catch (IOException closeError) { |
| 524 | Log.w(TAG, "Error closing destination.", closeError); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | if (DEBUG) Log.d(TAG, "Cleaning up failed operation leftovers."); |
| 529 | canceller.cancel(); |
| 530 | try { |
Tomasz Mikolajewski | db87543 | 2016-02-23 15:12:54 +0900 | [diff] [blame] | 531 | deleteDocument(dest, destParent); |
| 532 | } catch (ResourceException e) { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 533 | Log.w(TAG, "Failed to cleanup after copy error: " + src.derivedUri, e); |
| 534 | } |
| 535 | } |
| 536 | |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 537 | // This also ensures the file descriptors are closed. |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 538 | IoUtils.closeQuietly(in); |
| 539 | IoUtils.closeQuietly(out); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 540 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
| 544 | * Calculates the cumulative size of all the documents in the list. Directories are recursed |
| 545 | * into and totaled up. |
| 546 | * |
| 547 | * @param srcs |
| 548 | * @return Size in bytes. |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 549 | * @throws ResourceException |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 550 | */ |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 551 | private long calculateSize(List<DocumentInfo> srcs) throws ResourceException { |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 552 | long result = 0; |
| 553 | |
| 554 | for (DocumentInfo src : srcs) { |
| 555 | if (src.isDirectory()) { |
| 556 | // Directories need to be recursed into. |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 557 | try { |
| 558 | result += calculateFileSizesRecursively(getClient(src), src.derivedUri); |
| 559 | } catch (RemoteException e) { |
| 560 | throw new ResourceException("Failed to obtain the client for %s.", |
| 561 | src.derivedUri); |
| 562 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 563 | } else { |
| 564 | result += src.size; |
| 565 | } |
| 566 | } |
| 567 | return result; |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Calculates (recursively) the cumulative size of all the files under the given directory. |
| 572 | * |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 573 | * @throws ResourceException |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 574 | */ |
| 575 | private static long calculateFileSizesRecursively( |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 576 | ContentProviderClient client, Uri uri) throws ResourceException { |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 577 | final String authority = uri.getAuthority(); |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 578 | final Uri queryUri = buildChildDocumentsUri(authority, getDocumentId(uri)); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 579 | final String queryColumns[] = new String[] { |
| 580 | Document.COLUMN_DOCUMENT_ID, |
| 581 | Document.COLUMN_MIME_TYPE, |
| 582 | Document.COLUMN_SIZE |
| 583 | }; |
| 584 | |
| 585 | long result = 0; |
| 586 | Cursor cursor = null; |
| 587 | try { |
| 588 | cursor = client.query(queryUri, queryColumns, null, null, null); |
| 589 | while (cursor.moveToNext()) { |
| 590 | if (Document.MIME_TYPE_DIR.equals( |
| 591 | getCursorString(cursor, Document.COLUMN_MIME_TYPE))) { |
| 592 | // Recurse into directories. |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 593 | final Uri dirUri = buildDocumentUri(authority, |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 594 | getCursorString(cursor, Document.COLUMN_DOCUMENT_ID)); |
| 595 | result += calculateFileSizesRecursively(client, dirUri); |
| 596 | } else { |
| 597 | // This may return -1 if the size isn't defined. Ignore those cases. |
| 598 | long size = getCursorLong(cursor, Document.COLUMN_SIZE); |
| 599 | result += size > 0 ? size : 0; |
| 600 | } |
| 601 | } |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 602 | } catch (RemoteException | RuntimeException e) { |
| 603 | throw new ResourceException( |
| 604 | "Failed to calculate size for %s due to an exception.", uri, e); |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 605 | } finally { |
| 606 | IoUtils.closeQuietly(cursor); |
| 607 | } |
| 608 | |
| 609 | return result; |
| 610 | } |
| 611 | |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 612 | /** |
| 613 | * Returns true if {@code doc} is a descendant of {@code parentDoc}. |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 614 | * @throws ResourceException |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 615 | */ |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 616 | boolean isDescendentOf(DocumentInfo doc, DocumentInfo parent) |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 617 | throws ResourceException { |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 618 | if (parent.isDirectory() && doc.authority.equals(parent.authority)) { |
Tomasz Mikolajewski | 0fa97e8 | 2016-02-18 16:45:44 +0900 | [diff] [blame] | 619 | try { |
| 620 | return isChildDocument(getClient(doc), doc.derivedUri, parent.derivedUri); |
| 621 | } catch (RemoteException | RuntimeException e) { |
| 622 | throw new ResourceException( |
| 623 | "Failed to check if %s is a child of %s due to an exception.", |
| 624 | doc.derivedUri, parent.derivedUri, e); |
| 625 | } |
Steve McKay | 14e827a | 2016-01-06 18:32:13 -0800 | [diff] [blame] | 626 | } |
| 627 | return false; |
| 628 | } |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 629 | |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 630 | @Override |
| 631 | public String toString() { |
| 632 | return new StringBuilder() |
| 633 | .append("CopyJob") |
| 634 | .append("{") |
| 635 | .append("id=" + id) |
Tomasz Mikolajewski | b8436af | 2016-01-25 16:20:15 +0900 | [diff] [blame] | 636 | .append(", srcs=" + mSrcs) |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 637 | .append(", destination=" + stack) |
| 638 | .append("}") |
| 639 | .toString(); |
| 640 | } |
Steve McKay | ecbf3c5 | 2016-01-13 17:17:39 -0800 | [diff] [blame] | 641 | } |