1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.datamodel
;
22 import java
.util
.ArrayList
;
23 import java
.util
.Collection
;
24 import java
.util
.Collections
;
25 import java
.util
.Iterator
;
26 import java
.util
.Vector
;
28 import com
.owncloud
.android
.MainApp
;
29 import com
.owncloud
.android
.db
.ProviderMeta
.ProviderTableMeta
;
30 import com
.owncloud
.android
.utils
.FileStorageUtils
;
31 import com
.owncloud
.android
.utils
.Log_OC
;
34 import android
.accounts
.Account
;
35 import android
.content
.ContentProviderClient
;
36 import android
.content
.ContentProviderOperation
;
37 import android
.content
.ContentProviderResult
;
38 import android
.content
.ContentResolver
;
39 import android
.content
.ContentUris
;
40 import android
.content
.ContentValues
;
41 import android
.content
.OperationApplicationException
;
42 import android
.database
.Cursor
;
43 import android
.net
.Uri
;
44 import android
.os
.RemoteException
;
46 public class FileDataStorageManager
{
48 public static final int ROOT_PARENT_ID
= 0;
50 private ContentResolver mContentResolver
;
51 private ContentProviderClient mContentProviderClient
;
52 private Account mAccount
;
54 private static String TAG
= FileDataStorageManager
.class.getSimpleName();
57 public FileDataStorageManager(Account account
, ContentResolver cr
) {
58 mContentProviderClient
= null
;
59 mContentResolver
= cr
;
63 public FileDataStorageManager(Account account
, ContentProviderClient cp
) {
64 mContentProviderClient
= cp
;
65 mContentResolver
= null
;
70 public void setAccount(Account account
) {
74 public Account
getAccount() {
78 public void setContentResolver(ContentResolver cr
) {
79 mContentResolver
= cr
;
82 public ContentResolver
getContentResolver() {
83 return mContentResolver
;
86 public void setContentProviderClient(ContentProviderClient cp
) {
87 mContentProviderClient
= cp
;
90 public ContentProviderClient
getContentProviderClient() {
91 return mContentProviderClient
;
95 public OCFile
getFileByPath(String path
) {
96 Cursor c
= getCursorForValue(ProviderTableMeta
.FILE_PATH
, path
);
98 if (c
.moveToFirst()) {
99 file
= createFileInstance(c
);
102 if (file
== null
&& OCFile
.ROOT_PATH
.equals(path
)) {
103 return createRootDir(); // root should always exist
109 public OCFile
getFileById(long id
) {
110 Cursor c
= getCursorForValue(ProviderTableMeta
._ID
, String
.valueOf(id
));
112 if (c
.moveToFirst()) {
113 file
= createFileInstance(c
);
119 public OCFile
getFileByLocalPath(String path
) {
120 Cursor c
= getCursorForValue(ProviderTableMeta
.FILE_STORAGE_PATH
, path
);
122 if (c
.moveToFirst()) {
123 file
= createFileInstance(c
);
129 public boolean fileExists(long id
) {
130 return fileExists(ProviderTableMeta
._ID
, String
.valueOf(id
));
133 public boolean fileExists(String path
) {
134 return fileExists(ProviderTableMeta
.FILE_PATH
, path
);
138 public Vector
<OCFile
> getFolderContent(OCFile f
) {
139 if (f
!= null
&& f
.isFolder() && f
.getFileId() != -1) {
140 return getFolderContent(f
.getFileId());
143 return new Vector
<OCFile
>();
148 public Vector
<OCFile
> getFolderImages(OCFile folder
) {
149 Vector
<OCFile
> ret
= new Vector
<OCFile
>();
150 if (folder
!= null
) {
151 // TODO better implementation, filtering in the access to database (if possible) instead of here
152 Vector
<OCFile
> tmp
= getFolderContent(folder
);
153 OCFile current
= null
;
154 for (int i
=0; i
<tmp
.size(); i
++) {
155 current
= tmp
.get(i
);
156 if (current
.isImage()) {
165 public boolean saveFile(OCFile file
) {
166 boolean overriden
= false
;
167 ContentValues cv
= new ContentValues();
168 cv
.put(ProviderTableMeta
.FILE_MODIFIED
, file
.getModificationTimestamp());
169 cv
.put(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
, file
.getModificationTimestampAtLastSyncForData());
170 cv
.put(ProviderTableMeta
.FILE_CREATION
, file
.getCreationTimestamp());
171 cv
.put(ProviderTableMeta
.FILE_CONTENT_LENGTH
, file
.getFileLength());
172 cv
.put(ProviderTableMeta
.FILE_CONTENT_TYPE
, file
.getMimetype());
173 cv
.put(ProviderTableMeta
.FILE_NAME
, file
.getFileName());
174 //if (file.getParentId() != DataStorageManager.ROOT_PARENT_ID)
175 cv
.put(ProviderTableMeta
.FILE_PARENT
, file
.getParentId());
176 cv
.put(ProviderTableMeta
.FILE_PATH
, file
.getRemotePath());
177 if (!file
.isFolder())
178 cv
.put(ProviderTableMeta
.FILE_STORAGE_PATH
, file
.getStoragePath());
179 cv
.put(ProviderTableMeta
.FILE_ACCOUNT_OWNER
, mAccount
.name
);
180 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE
, file
.getLastSyncDateForProperties());
181 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
, file
.getLastSyncDateForData());
182 cv
.put(ProviderTableMeta
.FILE_KEEP_IN_SYNC
, file
.keepInSync() ?
1 : 0);
183 cv
.put(ProviderTableMeta
.FILE_ETAG
, file
.getEtag());
185 boolean sameRemotePath
= fileExists(file
.getRemotePath());
186 if (sameRemotePath
||
187 fileExists(file
.getFileId()) ) { // for renamed files; no more delete and create
189 OCFile oldFile
= null
;
190 if (sameRemotePath
) {
191 oldFile
= getFileByPath(file
.getRemotePath());
192 file
.setFileId(oldFile
.getFileId());
194 oldFile
= getFileById(file
.getFileId());
198 if (getContentResolver() != null
) {
199 getContentResolver().update(ProviderTableMeta
.CONTENT_URI
, cv
,
200 ProviderTableMeta
._ID
+ "=?",
201 new String
[] { String
.valueOf(file
.getFileId()) });
204 getContentProviderClient().update(ProviderTableMeta
.CONTENT_URI
,
205 cv
, ProviderTableMeta
._ID
+ "=?",
206 new String
[] { String
.valueOf(file
.getFileId()) });
207 } catch (RemoteException e
) {
209 "Fail to insert insert file to database "
214 Uri result_uri
= null
;
215 if (getContentResolver() != null
) {
216 result_uri
= getContentResolver().insert(
217 ProviderTableMeta
.CONTENT_URI_FILE
, cv
);
220 result_uri
= getContentProviderClient().insert(
221 ProviderTableMeta
.CONTENT_URI_FILE
, cv
);
222 } catch (RemoteException e
) {
224 "Fail to insert insert file to database "
228 if (result_uri
!= null
) {
229 long new_id
= Long
.parseLong(result_uri
.getPathSegments()
231 file
.setFileId(new_id
);
235 if (file
.isFolder()) {
236 updateFolderSize(file
.getFileId());
238 updateFolderSize(file
.getParentId());
246 * Inserts or updates the list of files contained in a given folder.
248 * CALLER IS THE RESPONSIBLE FOR GRANTING RIGHT UPDATE OF INFORMATION, NOT THIS METHOD.
249 * HERE ONLY DATA CONSISTENCY SHOULD BE GRANTED
253 * @param removeNotUpdated
255 public void saveFolder(OCFile folder
, Collection
<OCFile
> updatedFiles
, Collection
<OCFile
> filesToRemove
) {
257 Log_OC
.d(TAG
, "Saving folder " + folder
.getRemotePath() + " with " + updatedFiles
.size() + " children and " + filesToRemove
.size() + " files to remove");
259 ArrayList
<ContentProviderOperation
> operations
= new ArrayList
<ContentProviderOperation
>(updatedFiles
.size());
261 // prepare operations to insert or update files to save in the given folder
262 for (OCFile file
: updatedFiles
) {
263 ContentValues cv
= new ContentValues();
264 cv
.put(ProviderTableMeta
.FILE_MODIFIED
, file
.getModificationTimestamp());
265 cv
.put(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
, file
.getModificationTimestampAtLastSyncForData());
266 cv
.put(ProviderTableMeta
.FILE_CREATION
, file
.getCreationTimestamp());
267 cv
.put(ProviderTableMeta
.FILE_CONTENT_LENGTH
, file
.getFileLength());
268 cv
.put(ProviderTableMeta
.FILE_CONTENT_TYPE
, file
.getMimetype());
269 cv
.put(ProviderTableMeta
.FILE_NAME
, file
.getFileName());
270 //cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
271 cv
.put(ProviderTableMeta
.FILE_PARENT
, folder
.getFileId());
272 cv
.put(ProviderTableMeta
.FILE_PATH
, file
.getRemotePath());
273 if (!file
.isFolder()) {
274 cv
.put(ProviderTableMeta
.FILE_STORAGE_PATH
, file
.getStoragePath());
276 cv
.put(ProviderTableMeta
.FILE_ACCOUNT_OWNER
, mAccount
.name
);
277 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE
, file
.getLastSyncDateForProperties());
278 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
, file
.getLastSyncDateForData());
279 cv
.put(ProviderTableMeta
.FILE_KEEP_IN_SYNC
, file
.keepInSync() ?
1 : 0);
280 cv
.put(ProviderTableMeta
.FILE_ETAG
, file
.getEtag());
282 boolean existsByPath
= fileExists(file
.getRemotePath());
283 if (existsByPath
|| fileExists(file
.getFileId())) {
284 // updating an existing file
285 operations
.add(ContentProviderOperation
.newUpdate(ProviderTableMeta
.CONTENT_URI
).
287 withSelection( ProviderTableMeta
._ID
+ "=?",
288 new String
[] { String
.valueOf(file
.getFileId()) })
293 operations
.add(ContentProviderOperation
.newInsert(ProviderTableMeta
.CONTENT_URI
).withValues(cv
).build());
297 // prepare operations to remove files in the given folder
298 String where
= ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?" + " AND " + ProviderTableMeta
.FILE_PATH
+ "=?";
299 String
[] whereArgs
= null
;
300 for (OCFile file
: filesToRemove
) {
301 if (file
.getParentId() == folder
.getFileId()) {
302 whereArgs
= new String
[]{mAccount
.name
, file
.getRemotePath()};
303 //Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, "" + file.getFileId());
304 if (file
.isFolder()) {
305 operations
.add(ContentProviderOperation
306 .newDelete(ContentUris
.withAppendedId(ProviderTableMeta
.CONTENT_URI_DIR
, file
.getFileId())).withSelection(where
, whereArgs
)
308 // TODO remove local folder
310 operations
.add(ContentProviderOperation
311 .newDelete(ContentUris
.withAppendedId(ProviderTableMeta
.CONTENT_URI_FILE
, file
.getFileId())).withSelection(where
, whereArgs
)
314 new File(file
.getStoragePath()).delete();
315 // TODO move the deletion of local contents after success of deletions
321 // update metadata of folder
322 ContentValues cv
= new ContentValues();
323 cv
.put(ProviderTableMeta
.FILE_MODIFIED
, folder
.getModificationTimestamp());
324 cv
.put(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
, folder
.getModificationTimestampAtLastSyncForData());
325 cv
.put(ProviderTableMeta
.FILE_CREATION
, folder
.getCreationTimestamp());
326 cv
.put(ProviderTableMeta
.FILE_CONTENT_LENGTH
, 0); // FileContentProvider calculates the right size
327 cv
.put(ProviderTableMeta
.FILE_CONTENT_TYPE
, folder
.getMimetype());
328 cv
.put(ProviderTableMeta
.FILE_NAME
, folder
.getFileName());
329 cv
.put(ProviderTableMeta
.FILE_PARENT
, folder
.getParentId());
330 cv
.put(ProviderTableMeta
.FILE_PATH
, folder
.getRemotePath());
331 cv
.put(ProviderTableMeta
.FILE_ACCOUNT_OWNER
, mAccount
.name
);
332 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE
, folder
.getLastSyncDateForProperties());
333 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
, folder
.getLastSyncDateForData());
334 cv
.put(ProviderTableMeta
.FILE_KEEP_IN_SYNC
, folder
.keepInSync() ?
1 : 0);
335 cv
.put(ProviderTableMeta
.FILE_ETAG
, folder
.getEtag());
336 operations
.add(ContentProviderOperation
.newUpdate(ProviderTableMeta
.CONTENT_URI
).
338 withSelection( ProviderTableMeta
._ID
+ "=?",
339 new String
[] { String
.valueOf(folder
.getFileId()) })
342 // apply operations in batch
343 ContentProviderResult
[] results
= null
;
344 Log_OC
.d(TAG
, "Sending " + operations
.size() + " operations to FileContentProvider");
346 if (getContentResolver() != null
) {
347 results
= getContentResolver().applyBatch(MainApp
.getAuthority(), operations
);
350 results
= getContentProviderClient().applyBatch(operations
);
353 } catch (OperationApplicationException e
) {
354 Log_OC
.e(TAG
, "Exception in batch of operations " + e
.getMessage());
356 } catch (RemoteException e
) {
357 Log_OC
.e(TAG
, "Exception in batch of operations " + e
.getMessage());
360 // update new id in file objects for insertions
361 if (results
!= null
) {
363 Iterator
<OCFile
> filesIt
= updatedFiles
.iterator();
365 for (int i
=0; i
<results
.length
; i
++) {
366 if (filesIt
.hasNext()) {
367 file
= filesIt
.next();
371 if (results
[i
].uri
!= null
) {
372 newId
= Long
.parseLong(results
[i
].uri
.getPathSegments().get(1));
373 //updatedFiles.get(i).setFileId(newId);
375 file
.setFileId(newId
);
381 updateFolderSize(folder
.getFileId());
390 private void updateFolderSize(long id
) {
391 if (id
> FileDataStorageManager
.ROOT_PARENT_ID
) {
392 Log_OC
.d(TAG
, "Updating size of " + id
);
393 if (getContentResolver() != null
) {
394 getContentResolver().update(ProviderTableMeta
.CONTENT_URI_DIR
,
395 new ContentValues(), // won't be used, but cannot be null; crashes in KLP
396 ProviderTableMeta
._ID
+ "=?",
397 new String
[] { String
.valueOf(id
) });
400 getContentProviderClient().update(ProviderTableMeta
.CONTENT_URI_DIR
,
401 new ContentValues(), // won't be used, but cannot be null; crashes in KLP
402 ProviderTableMeta
._ID
+ "=?",
403 new String
[] { String
.valueOf(id
) });
405 } catch (RemoteException e
) {
406 Log_OC
.e(TAG
, "Exception in update of folder size through compatibility patch " + e
.getMessage());
410 Log_OC
.e(TAG
, "not updating size for folder " + id
);
415 public void removeFile(OCFile file
, boolean removeDBData
, boolean removeLocalCopy
) {
417 if (file
.isFolder()) {
418 removeFolder(file
, removeDBData
, removeLocalCopy
);
422 //Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
423 Uri file_uri
= ContentUris
.withAppendedId(ProviderTableMeta
.CONTENT_URI_FILE
, file
.getFileId());
424 String where
= ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?" + " AND " + ProviderTableMeta
.FILE_PATH
+ "=?";
425 String
[] whereArgs
= new String
[]{mAccount
.name
, file
.getRemotePath()};
426 if (getContentProviderClient() != null
) {
428 getContentProviderClient().delete(file_uri
, where
, whereArgs
);
429 } catch (RemoteException e
) {
433 getContentResolver().delete(file_uri
, where
, whereArgs
);
435 updateFolderSize(file
.getParentId());
437 if (removeLocalCopy
&& file
.isDown() && file
.getStoragePath() != null
) {
438 boolean success
= new File(file
.getStoragePath()).delete();
439 if (!removeDBData
&& success
) {
440 // maybe unnecessary, but should be checked TODO remove if unnecessary
441 file
.setStoragePath(null
);
450 public void removeFolder(OCFile folder
, boolean removeDBData
, boolean removeLocalContent
) {
451 if (folder
!= null
&& folder
.isFolder()) {
452 if (removeDBData
&& folder
.getFileId() != -1) {
453 removeFolderInDb(folder
);
455 if (removeLocalContent
) {
456 File localFolder
= new File(FileStorageUtils
.getDefaultSavePathFor(mAccount
.name
, folder
));
457 removeLocalFolder(localFolder
);
462 private void removeFolderInDb(OCFile folder
) {
463 Uri folder_uri
= Uri
.withAppendedPath(ProviderTableMeta
.CONTENT_URI_DIR
, ""+ folder
.getFileId()); // URI for recursive deletion
464 String where
= ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?" + " AND " + ProviderTableMeta
.FILE_PATH
+ "=?";
465 String
[] whereArgs
= new String
[]{mAccount
.name
, folder
.getRemotePath()};
466 if (getContentProviderClient() != null
) {
468 getContentProviderClient().delete(folder_uri
, where
, whereArgs
);
469 } catch (RemoteException e
) {
473 getContentResolver().delete(folder_uri
, where
, whereArgs
);
475 updateFolderSize(folder
.getParentId());
478 private void removeLocalFolder(File folder
) {
479 if (folder
.exists()) {
480 File
[] files
= folder
.listFiles();
482 for (File file
: files
) {
483 if (file
.isDirectory()) {
484 removeLocalFolder(file
);
495 * Updates database for a folder that was moved to a different location.
497 * TODO explore better (faster) implementations
498 * TODO throw exceptions up !
500 public void moveFolder(OCFile folder
, String newPath
) {
501 // TODO check newPath
503 if (folder
!= null
&& folder
.isFolder() && folder
.fileExists() && !OCFile
.ROOT_PATH
.equals(folder
.getFileName())) {
504 /// 1. get all the descendants of 'dir' in a single QUERY (including 'dir')
506 if (getContentProviderClient() != null
) {
508 c
= getContentProviderClient().query(ProviderTableMeta
.CONTENT_URI
,
510 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=? AND " + ProviderTableMeta
.FILE_PATH
+ " LIKE ? ",
511 new String
[] { mAccount
.name
, folder
.getRemotePath() + "%" }, ProviderTableMeta
.FILE_PATH
+ " ASC ");
512 } catch (RemoteException e
) {
513 Log_OC
.e(TAG
, e
.getMessage());
516 c
= getContentResolver().query(ProviderTableMeta
.CONTENT_URI
,
518 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=? AND " + ProviderTableMeta
.FILE_PATH
+ " LIKE ? ",
519 new String
[] { mAccount
.name
, folder
.getRemotePath() + "%" }, ProviderTableMeta
.FILE_PATH
+ " ASC ");
522 /// 2. prepare a batch of update operations to change all the descendants
523 ArrayList
<ContentProviderOperation
> operations
= new ArrayList
<ContentProviderOperation
>(c
.getCount());
524 int lengthOfOldPath
= folder
.getRemotePath().length();
525 String defaultSavePath
= FileStorageUtils
.getSavePath(mAccount
.name
);
526 int lengthOfOldStoragePath
= defaultSavePath
.length() + lengthOfOldPath
;
527 if (c
.moveToFirst()) {
529 ContentValues cv
= new ContentValues(); // don't take the constructor out of the loop and clear the object
530 OCFile child
= createFileInstance(c
);
531 cv
.put(ProviderTableMeta
.FILE_PATH
, newPath
+ child
.getRemotePath().substring(lengthOfOldPath
));
532 if (child
.getStoragePath() != null
&& child
.getStoragePath().startsWith(defaultSavePath
)) {
533 cv
.put(ProviderTableMeta
.FILE_STORAGE_PATH
, defaultSavePath
+ newPath
+ child
.getStoragePath().substring(lengthOfOldStoragePath
));
535 operations
.add(ContentProviderOperation
.newUpdate(ProviderTableMeta
.CONTENT_URI
).
537 withSelection( ProviderTableMeta
._ID
+ "=?",
538 new String
[] { String
.valueOf(child
.getFileId()) })
540 } while (c
.moveToNext());
544 /// 3. apply updates in batch
546 if (getContentResolver() != null
) {
547 getContentResolver().applyBatch(MainApp
.getAuthority(), operations
);
550 getContentProviderClient().applyBatch(operations
);
553 } catch (OperationApplicationException e
) {
554 Log_OC
.e(TAG
, "Fail to update descendants of " + folder
.getFileId() + " in database", e
);
556 } catch (RemoteException e
) {
557 Log_OC
.e(TAG
, "Fail to update desendants of " + folder
.getFileId() + " in database", e
);
564 private Vector
<OCFile
> getFolderContent(long parentId
) {
566 Vector
<OCFile
> ret
= new Vector
<OCFile
>();
568 Uri req_uri
= Uri
.withAppendedPath(
569 ProviderTableMeta
.CONTENT_URI_DIR
,
570 String
.valueOf(parentId
));
573 if (getContentProviderClient() != null
) {
575 c
= getContentProviderClient().query(req_uri
, null
,
576 ProviderTableMeta
.FILE_PARENT
+ "=?" ,
577 new String
[] { String
.valueOf(parentId
)}, null
);
578 } catch (RemoteException e
) {
579 Log_OC
.e(TAG
, e
.getMessage());
583 c
= getContentResolver().query(req_uri
, null
,
584 ProviderTableMeta
.FILE_PARENT
+ "=?" ,
585 new String
[] { String
.valueOf(parentId
)}, null
);
588 if (c
.moveToFirst()) {
590 OCFile child
= createFileInstance(c
);
592 } while (c
.moveToNext());
597 Collections
.sort(ret
);
603 private OCFile
createRootDir() {
604 OCFile file
= new OCFile(OCFile
.ROOT_PATH
);
605 file
.setMimetype("DIR");
606 file
.setParentId(FileDataStorageManager
.ROOT_PARENT_ID
);
611 private boolean fileExists(String cmp_key
, String value
) {
613 if (getContentResolver() != null
) {
614 c
= getContentResolver()
615 .query(ProviderTableMeta
.CONTENT_URI
,
618 + ProviderTableMeta
.FILE_ACCOUNT_OWNER
620 new String
[] { value
, mAccount
.name
}, null
);
623 c
= getContentProviderClient().query(
624 ProviderTableMeta
.CONTENT_URI
,
627 + ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?",
628 new String
[] { value
, mAccount
.name
}, null
);
629 } catch (RemoteException e
) {
631 "Couldn't determine file existance, assuming non existance: "
636 boolean retval
= c
.moveToFirst();
641 private Cursor
getCursorForValue(String key
, String value
) {
643 if (getContentResolver() != null
) {
644 c
= getContentResolver()
645 .query(ProviderTableMeta
.CONTENT_URI
,
648 + ProviderTableMeta
.FILE_ACCOUNT_OWNER
650 new String
[] { value
, mAccount
.name
}, null
);
653 c
= getContentProviderClient().query(
654 ProviderTableMeta
.CONTENT_URI
,
656 key
+ "=? AND " + ProviderTableMeta
.FILE_ACCOUNT_OWNER
657 + "=?", new String
[] { value
, mAccount
.name
},
659 } catch (RemoteException e
) {
660 Log_OC
.e(TAG
, "Could not get file details: " + e
.getMessage());
667 private OCFile
createFileInstance(Cursor c
) {
670 file
= new OCFile(c
.getString(c
671 .getColumnIndex(ProviderTableMeta
.FILE_PATH
)));
672 file
.setFileId(c
.getLong(c
.getColumnIndex(ProviderTableMeta
._ID
)));
673 file
.setParentId(c
.getLong(c
674 .getColumnIndex(ProviderTableMeta
.FILE_PARENT
)));
675 file
.setMimetype(c
.getString(c
676 .getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
)));
677 if (!file
.isFolder()) {
678 file
.setStoragePath(c
.getString(c
679 .getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
)));
680 if (file
.getStoragePath() == null
) {
681 // try to find existing file and bind it with current account; - with the current update of SynchronizeFolderOperation, this won't be necessary anymore after a full synchronization of the account
682 File f
= new File(FileStorageUtils
.getDefaultSavePathFor(mAccount
.name
, file
));
684 file
.setStoragePath(f
.getAbsolutePath());
685 file
.setLastSyncDateForData(f
.lastModified());
689 file
.setFileLength(c
.getLong(c
690 .getColumnIndex(ProviderTableMeta
.FILE_CONTENT_LENGTH
)));
691 file
.setCreationTimestamp(c
.getLong(c
692 .getColumnIndex(ProviderTableMeta
.FILE_CREATION
)));
693 file
.setModificationTimestamp(c
.getLong(c
694 .getColumnIndex(ProviderTableMeta
.FILE_MODIFIED
)));
695 file
.setModificationTimestampAtLastSyncForData(c
.getLong(c
696 .getColumnIndex(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
)));
697 file
.setLastSyncDateForProperties(c
.getLong(c
698 .getColumnIndex(ProviderTableMeta
.FILE_LAST_SYNC_DATE
)));
699 file
.setLastSyncDateForData(c
.getLong(c
.
700 getColumnIndex(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
)));
701 file
.setKeepInSync(c
.getInt(
702 c
.getColumnIndex(ProviderTableMeta
.FILE_KEEP_IN_SYNC
)) == 1 ? true
: false
);
703 file
.setEtag(c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_ETAG
)));