FileDataStorageManager.java 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * Copyright (C) 2012 Bartek Przybylski
  5. * Copyright (C) 2015 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. package com.owncloud.android.datamodel;
  21. import android.accounts.Account;
  22. import android.content.ContentProviderClient;
  23. import android.content.ContentProviderOperation;
  24. import android.content.ContentProviderResult;
  25. import android.content.ContentResolver;
  26. import android.content.ContentUris;
  27. import android.content.ContentValues;
  28. import android.content.Intent;
  29. import android.content.OperationApplicationException;
  30. import android.database.Cursor;
  31. import android.net.Uri;
  32. import android.os.RemoteException;
  33. import android.provider.MediaStore;
  34. import com.owncloud.android.MainApp;
  35. import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
  36. import com.owncloud.android.lib.common.utils.Log_OC;
  37. import com.owncloud.android.lib.resources.shares.OCShare;
  38. import com.owncloud.android.lib.resources.shares.ShareType;
  39. import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
  40. import com.owncloud.android.lib.resources.status.OCCapability;
  41. import com.owncloud.android.utils.FileStorageUtils;
  42. import java.io.File;
  43. import java.io.FileInputStream;
  44. import java.io.FileOutputStream;
  45. import java.io.IOException;
  46. import java.io.InputStream;
  47. import java.io.OutputStream;
  48. import java.util.ArrayList;
  49. import java.util.Collection;
  50. import java.util.Collections;
  51. import java.util.HashSet;
  52. import java.util.Iterator;
  53. import java.util.List;
  54. import java.util.Set;
  55. import java.util.Vector;
  56. public class FileDataStorageManager {
  57. public static final int ROOT_PARENT_ID = 0;
  58. private ContentResolver mContentResolver;
  59. private ContentProviderClient mContentProviderClient;
  60. private Account mAccount;
  61. private static String TAG = FileDataStorageManager.class.getSimpleName();
  62. public FileDataStorageManager(Account account, ContentResolver cr) {
  63. mContentProviderClient = null;
  64. mContentResolver = cr;
  65. mAccount = account;
  66. }
  67. public FileDataStorageManager(Account account, ContentProviderClient cp) {
  68. mContentProviderClient = cp;
  69. mContentResolver = null;
  70. mAccount = account;
  71. }
  72. public void setAccount(Account account) {
  73. mAccount = account;
  74. }
  75. public Account getAccount() {
  76. return mAccount;
  77. }
  78. public ContentResolver getContentResolver() {
  79. return mContentResolver;
  80. }
  81. public ContentProviderClient getContentProviderClient() {
  82. return mContentProviderClient;
  83. }
  84. public OCFile getFileByPath(String path) {
  85. Cursor c = getFileCursorForValue(ProviderTableMeta.FILE_PATH, path);
  86. OCFile file = null;
  87. if (c.moveToFirst()) {
  88. file = createFileInstance(c);
  89. }
  90. c.close();
  91. if (file == null && OCFile.ROOT_PATH.equals(path)) {
  92. return createRootDir(); // root should always exist
  93. }
  94. return file;
  95. }
  96. public OCFile getFileById(long id) {
  97. Cursor c = getFileCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
  98. OCFile file = null;
  99. if (c.moveToFirst()) {
  100. file = createFileInstance(c);
  101. }
  102. c.close();
  103. return file;
  104. }
  105. public OCFile getFileByLocalPath(String path) {
  106. Cursor c = getFileCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
  107. OCFile file = null;
  108. if (c.moveToFirst()) {
  109. file = createFileInstance(c);
  110. }
  111. c.close();
  112. return file;
  113. }
  114. public boolean fileExists(long id) {
  115. return fileExists(ProviderTableMeta._ID, String.valueOf(id));
  116. }
  117. public boolean fileExists(String path) {
  118. return fileExists(ProviderTableMeta.FILE_PATH, path);
  119. }
  120. public Vector<OCFile> getFolderContent(OCFile f/*, boolean onlyOnDevice*/) {
  121. if (f != null && f.isFolder() && f.getFileId() != -1) {
  122. // TODO Enable when "On Device" is recovered ?
  123. return getFolderContent(f.getFileId()/*, onlyOnDevice*/);
  124. } else {
  125. return new Vector<OCFile>();
  126. }
  127. }
  128. public Vector<OCFile> getFolderImages(OCFile folder/*, boolean onlyOnDevice*/) {
  129. Vector<OCFile> ret = new Vector<OCFile>();
  130. if (folder != null) {
  131. // TODO better implementation, filtering in the access to database instead of here
  132. // TODO Enable when "On Device" is recovered ?
  133. Vector<OCFile> tmp = getFolderContent(folder/*, onlyOnDevice*/);
  134. OCFile current = null;
  135. for (int i=0; i<tmp.size(); i++) {
  136. current = tmp.get(i);
  137. if (current.isImage()) {
  138. ret.add(current);
  139. }
  140. }
  141. }
  142. return ret;
  143. }
  144. public boolean saveFile(OCFile file) {
  145. boolean overriden = false;
  146. ContentValues cv = new ContentValues();
  147. cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
  148. cv.put(
  149. ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
  150. file.getModificationTimestampAtLastSyncForData()
  151. );
  152. cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
  153. cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
  154. cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
  155. cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
  156. cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
  157. cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
  158. if (!file.isFolder())
  159. cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
  160. cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
  161. cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
  162. cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
  163. cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isFavorite() ? 1 : 0);
  164. cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
  165. cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
  166. cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
  167. cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
  168. cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
  169. cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
  170. cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
  171. cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
  172. cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
  173. boolean sameRemotePath = fileExists(file.getRemotePath());
  174. if (sameRemotePath ||
  175. fileExists(file.getFileId())) { // for renamed files; no more delete and create
  176. OCFile oldFile;
  177. if (sameRemotePath) {
  178. oldFile = getFileByPath(file.getRemotePath());
  179. file.setFileId(oldFile.getFileId());
  180. } else {
  181. oldFile = getFileById(file.getFileId());
  182. }
  183. overriden = true;
  184. if (getContentResolver() != null) {
  185. getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv,
  186. ProviderTableMeta._ID + "=?",
  187. new String[]{String.valueOf(file.getFileId())});
  188. } else {
  189. try {
  190. getContentProviderClient().update(ProviderTableMeta.CONTENT_URI,
  191. cv, ProviderTableMeta._ID + "=?",
  192. new String[]{String.valueOf(file.getFileId())});
  193. } catch (RemoteException e) {
  194. Log_OC.e(TAG,
  195. "Fail to insert insert file to database "
  196. + e.getMessage());
  197. }
  198. }
  199. } else {
  200. Uri result_uri = null;
  201. if (getContentResolver() != null) {
  202. result_uri = getContentResolver().insert(
  203. ProviderTableMeta.CONTENT_URI_FILE, cv);
  204. } else {
  205. try {
  206. result_uri = getContentProviderClient().insert(
  207. ProviderTableMeta.CONTENT_URI_FILE, cv);
  208. } catch (RemoteException e) {
  209. Log_OC.e(TAG,
  210. "Fail to insert insert file to database "
  211. + e.getMessage());
  212. }
  213. }
  214. if (result_uri != null) {
  215. long new_id = Long.parseLong(result_uri.getPathSegments()
  216. .get(1));
  217. file.setFileId(new_id);
  218. }
  219. }
  220. return overriden;
  221. }
  222. /**
  223. * Inserts or updates the list of files contained in a given folder.
  224. * <p/>
  225. * CALLER IS THE RESPONSIBLE FOR GRANTING RIGHT UPDATE OF INFORMATION, NOT THIS METHOD.
  226. * HERE ONLY DATA CONSISTENCY SHOULD BE GRANTED
  227. *
  228. * @param folder
  229. * @param updatedFiles
  230. * @param filesToRemove
  231. */
  232. public void saveFolder(
  233. OCFile folder, Collection<OCFile> updatedFiles, Collection<OCFile> filesToRemove
  234. ) {
  235. Log_OC.d(TAG, "Saving folder " + folder.getRemotePath() + " with " + updatedFiles.size()
  236. + " children and " + filesToRemove.size() + " files to remove");
  237. ArrayList<ContentProviderOperation> operations =
  238. new ArrayList<ContentProviderOperation>(updatedFiles.size());
  239. // prepare operations to insert or update files to save in the given folder
  240. for (OCFile file : updatedFiles) {
  241. ContentValues cv = new ContentValues();
  242. cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
  243. cv.put(
  244. ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
  245. file.getModificationTimestampAtLastSyncForData()
  246. );
  247. cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
  248. cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
  249. cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
  250. cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
  251. //cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
  252. cv.put(ProviderTableMeta.FILE_PARENT, folder.getFileId());
  253. cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
  254. if (!file.isFolder()) {
  255. cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
  256. }
  257. cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
  258. cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
  259. cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
  260. cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isFavorite() ? 1 : 0);
  261. cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
  262. cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
  263. cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
  264. cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
  265. cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
  266. cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
  267. cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
  268. cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
  269. cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
  270. boolean existsByPath = fileExists(file.getRemotePath());
  271. if (existsByPath || fileExists(file.getFileId())) {
  272. // updating an existing file
  273. operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
  274. withValues(cv).
  275. withSelection(ProviderTableMeta._ID + "=?",
  276. new String[]{String.valueOf(file.getFileId())})
  277. .build());
  278. } else {
  279. // adding a new file
  280. operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).
  281. withValues(cv).build());
  282. }
  283. }
  284. // prepare operations to remove files in the given folder
  285. String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " +
  286. ProviderTableMeta.FILE_PATH + "=?";
  287. String [] whereArgs = null;
  288. for (OCFile file : filesToRemove) {
  289. if (file.getParentId() == folder.getFileId()) {
  290. whereArgs = new String[]{mAccount.name, file.getRemotePath()};
  291. if (file.isFolder()) {
  292. operations.add(ContentProviderOperation.newDelete(
  293. ContentUris.withAppendedId(
  294. ProviderTableMeta.CONTENT_URI_DIR, file.getFileId()
  295. )
  296. ).withSelection(where, whereArgs).build());
  297. File localFolder =
  298. new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
  299. if (localFolder.exists()) {
  300. removeLocalFolder(localFolder);
  301. }
  302. } else {
  303. operations.add(ContentProviderOperation.newDelete(
  304. ContentUris.withAppendedId(
  305. ProviderTableMeta.CONTENT_URI_FILE, file.getFileId()
  306. )
  307. ).withSelection(where, whereArgs).build());
  308. if (file.isDown()) {
  309. String path = file.getStoragePath();
  310. new File(path).delete();
  311. triggerMediaScan(path); // notify MediaScanner about removed file
  312. }
  313. }
  314. }
  315. }
  316. // update metadata of folder
  317. ContentValues cv = new ContentValues();
  318. cv.put(ProviderTableMeta.FILE_MODIFIED, folder.getModificationTimestamp());
  319. cv.put(
  320. ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
  321. folder.getModificationTimestampAtLastSyncForData()
  322. );
  323. cv.put(ProviderTableMeta.FILE_CREATION, folder.getCreationTimestamp());
  324. cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, 0);
  325. cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, folder.getMimetype());
  326. cv.put(ProviderTableMeta.FILE_NAME, folder.getFileName());
  327. cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId());
  328. cv.put(ProviderTableMeta.FILE_PATH, folder.getRemotePath());
  329. cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
  330. cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, folder.getLastSyncDateForProperties());
  331. cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData());
  332. cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, folder.isFavorite() ? 1 : 0);
  333. cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag());
  334. cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, folder.isSharedViaLink() ? 1 : 0);
  335. cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, folder.isSharedWithSharee() ? 1 : 0);
  336. cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, folder.getPublicLink());
  337. cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions());
  338. cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId());
  339. operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
  340. withValues(cv).
  341. withSelection(ProviderTableMeta._ID + "=?",
  342. new String[]{String.valueOf(folder.getFileId())})
  343. .build());
  344. // apply operations in batch
  345. ContentProviderResult[] results = null;
  346. Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
  347. try {
  348. if (getContentResolver() != null) {
  349. results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
  350. } else {
  351. results = getContentProviderClient().applyBatch(operations);
  352. }
  353. } catch (OperationApplicationException e) {
  354. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  355. } catch (RemoteException e) {
  356. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  357. }
  358. // update new id in file objects for insertions
  359. if (results != null) {
  360. long newId;
  361. Iterator<OCFile> filesIt = updatedFiles.iterator();
  362. OCFile file = null;
  363. for (int i = 0; i < results.length; i++) {
  364. if (filesIt.hasNext()) {
  365. file = filesIt.next();
  366. } else {
  367. file = null;
  368. }
  369. if (results[i].uri != null) {
  370. newId = Long.parseLong(results[i].uri.getPathSegments().get(1));
  371. //updatedFiles.get(i).setFileId(newId);
  372. if (file != null) {
  373. file.setFileId(newId);
  374. }
  375. }
  376. }
  377. }
  378. }
  379. public boolean removeFile(OCFile file, boolean removeDBData, boolean removeLocalCopy) {
  380. boolean success = true;
  381. if (file != null) {
  382. if (file.isFolder()) {
  383. success = removeFolder(file, removeDBData, removeLocalCopy);
  384. } else {
  385. if (removeDBData) {
  386. //Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE,
  387. // ""+file.getFileId());
  388. Uri file_uri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE,
  389. file.getFileId());
  390. String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " +
  391. ProviderTableMeta.FILE_PATH + "=?";
  392. String[] whereArgs = new String[]{mAccount.name, file.getRemotePath()};
  393. int deleted = 0;
  394. if (getContentProviderClient() != null) {
  395. try {
  396. deleted = getContentProviderClient().delete(file_uri, where, whereArgs);
  397. } catch (RemoteException e) {
  398. e.printStackTrace();
  399. }
  400. } else {
  401. deleted = getContentResolver().delete(file_uri, where, whereArgs);
  402. }
  403. success &= (deleted > 0);
  404. }
  405. String localPath = file.getStoragePath();
  406. if (removeLocalCopy && file.isDown() && localPath != null && success) {
  407. success = new File(localPath).delete();
  408. if (success) {
  409. deleteFileInMediaScan(localPath);
  410. }
  411. if (!removeDBData && success) {
  412. // maybe unnecessary, but should be checked TODO remove if unnecessary
  413. file.setStoragePath(null);
  414. saveFile(file);
  415. saveConflict(file, null);
  416. }
  417. }
  418. }
  419. }
  420. return success;
  421. }
  422. public boolean removeFolder(OCFile folder, boolean removeDBData, boolean removeLocalContent) {
  423. boolean success = true;
  424. if (folder != null && folder.isFolder()) {
  425. if (removeDBData && folder.getFileId() != -1) {
  426. success = removeFolderInDb(folder);
  427. }
  428. if (removeLocalContent && success) {
  429. success = removeLocalFolder(folder);
  430. }
  431. }
  432. return success;
  433. }
  434. private boolean removeFolderInDb(OCFile folder) {
  435. Uri folder_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, "" +
  436. folder.getFileId()); // URI for recursive deletion
  437. String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " +
  438. ProviderTableMeta.FILE_PATH + "=?";
  439. String [] whereArgs = new String[]{mAccount.name, folder.getRemotePath()};
  440. int deleted = 0;
  441. if (getContentProviderClient() != null) {
  442. try {
  443. deleted = getContentProviderClient().delete(folder_uri, where, whereArgs);
  444. } catch (RemoteException e) {
  445. e.printStackTrace();
  446. }
  447. } else {
  448. deleted = getContentResolver().delete(folder_uri, where, whereArgs);
  449. }
  450. return deleted > 0;
  451. }
  452. private boolean removeLocalFolder(OCFile folder) {
  453. boolean success = true;
  454. String localFolderPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, folder);
  455. File localFolder = new File(localFolderPath);
  456. if (localFolder.exists()) {
  457. // stage 1: remove the local files already registered in the files database
  458. // TODO Enable when "On Device" is recovered ?
  459. Vector<OCFile> files = getFolderContent(folder.getFileId()/*, false*/);
  460. if (files != null) {
  461. for (OCFile file : files) {
  462. if (file.isFolder()) {
  463. success &= removeLocalFolder(file);
  464. } else {
  465. if (file.isDown()) {
  466. File localFile = new File(file.getStoragePath());
  467. success &= localFile.delete();
  468. if (success) {
  469. // notify MediaScanner about removed file
  470. deleteFileInMediaScan(file.getStoragePath());
  471. file.setStoragePath(null);
  472. saveFile(file);
  473. }
  474. }
  475. }
  476. }
  477. }
  478. // stage 2: remove the folder itself and any local file inside out of sync;
  479. // for instance, after clearing the app cache or reinstalling
  480. success &= removeLocalFolder(localFolder);
  481. }
  482. return success;
  483. }
  484. private boolean removeLocalFolder(File localFolder) {
  485. boolean success = true;
  486. File[] localFiles = localFolder.listFiles();
  487. if (localFiles != null) {
  488. for (File localFile : localFiles) {
  489. if (localFile.isDirectory()) {
  490. success &= removeLocalFolder(localFile);
  491. } else {
  492. String path = localFile.getAbsolutePath();
  493. success &= localFile.delete();
  494. }
  495. }
  496. }
  497. success &= localFolder.delete();
  498. return success;
  499. }
  500. /**
  501. * Updates database and file system for a file or folder that was moved to a different location.
  502. *
  503. * TODO explore better (faster) implementations
  504. * TODO throw exceptions up !
  505. */
  506. public void moveLocalFile(OCFile file, String targetPath, String targetParentPath) {
  507. if (file != null && file.fileExists() && !OCFile.ROOT_PATH.equals(file.getFileName())) {
  508. OCFile targetParent = getFileByPath(targetParentPath);
  509. if (targetParent == null) {
  510. throw new IllegalStateException(
  511. "Parent folder of the target path does not exist!!");
  512. }
  513. /// 1. get all the descendants of the moved element in a single QUERY
  514. Cursor c = null;
  515. if (getContentProviderClient() != null) {
  516. try {
  517. c = getContentProviderClient().query(
  518. ProviderTableMeta.CONTENT_URI,
  519. null,
  520. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  521. ProviderTableMeta.FILE_PATH + " LIKE ? ",
  522. new String[]{
  523. mAccount.name,
  524. file.getRemotePath() + "%"
  525. },
  526. ProviderTableMeta.FILE_PATH + " ASC "
  527. );
  528. } catch (RemoteException e) {
  529. Log_OC.e(TAG, e.getMessage());
  530. }
  531. } else {
  532. c = getContentResolver().query(
  533. ProviderTableMeta.CONTENT_URI,
  534. null,
  535. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  536. ProviderTableMeta.FILE_PATH + " LIKE ? ",
  537. new String[]{
  538. mAccount.name,
  539. file.getRemotePath() + "%"
  540. },
  541. ProviderTableMeta.FILE_PATH + " ASC "
  542. );
  543. }
  544. /// 2. prepare a batch of update operations to change all the descendants
  545. ArrayList<ContentProviderOperation> operations =
  546. new ArrayList<ContentProviderOperation>(c.getCount());
  547. String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
  548. List<String> originalPathsToTriggerMediaScan = new ArrayList<String>();
  549. List<String> newPathsToTriggerMediaScan = new ArrayList<String>();
  550. if (c.moveToFirst()) {
  551. int lengthOfOldPath = file.getRemotePath().length();
  552. int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
  553. do {
  554. ContentValues cv = new ContentValues(); // keep construction in the loop
  555. OCFile child = createFileInstance(c);
  556. cv.put(
  557. ProviderTableMeta.FILE_PATH,
  558. targetPath + child.getRemotePath().substring(lengthOfOldPath)
  559. );
  560. if (child.getStoragePath() != null &&
  561. child.getStoragePath().startsWith(defaultSavePath)) {
  562. // update link to downloaded content - but local move is not done here!
  563. String targetLocalPath = defaultSavePath + targetPath +
  564. child.getStoragePath().substring(lengthOfOldStoragePath);
  565. cv.put(ProviderTableMeta.FILE_STORAGE_PATH, targetLocalPath);
  566. originalPathsToTriggerMediaScan.add(child.getStoragePath());
  567. newPathsToTriggerMediaScan.add(targetLocalPath);
  568. }
  569. if (child.getRemotePath().equals(file.getRemotePath())) {
  570. cv.put(
  571. ProviderTableMeta.FILE_PARENT,
  572. targetParent.getFileId()
  573. );
  574. }
  575. operations.add(
  576. ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
  577. withValues(cv).
  578. withSelection(
  579. ProviderTableMeta._ID + "=?",
  580. new String[]{String.valueOf(child.getFileId())}
  581. )
  582. .build());
  583. } while (c.moveToNext());
  584. }
  585. c.close();
  586. /// 3. apply updates in batch
  587. try {
  588. if (getContentResolver() != null) {
  589. getContentResolver().applyBatch(MainApp.getAuthority(), operations);
  590. } else {
  591. getContentProviderClient().applyBatch(operations);
  592. }
  593. } catch (Exception e) {
  594. Log_OC.e(TAG, "Fail to update " + file.getFileId() + " and descendants in database",
  595. e);
  596. }
  597. /// 4. move in local file system
  598. String originalLocalPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
  599. String targetLocalPath = defaultSavePath + targetPath;
  600. File localFile = new File(originalLocalPath);
  601. boolean renamed = false;
  602. if (localFile.exists()) {
  603. File targetFile = new File(targetLocalPath);
  604. File targetFolder = targetFile.getParentFile();
  605. if (!targetFolder.exists()) {
  606. targetFolder.mkdirs();
  607. }
  608. renamed = localFile.renameTo(targetFile);
  609. }
  610. if (renamed) {
  611. Iterator<String> it = originalPathsToTriggerMediaScan.iterator();
  612. while (it.hasNext()) {
  613. // Notify MediaScanner about removed file
  614. deleteFileInMediaScan(it.next());
  615. }
  616. it = newPathsToTriggerMediaScan.iterator();
  617. while (it.hasNext()) {
  618. // Notify MediaScanner about new file/folder
  619. triggerMediaScan(it.next());
  620. }
  621. }
  622. }
  623. }
  624. public void copyLocalFile(OCFile file, String targetPath) {
  625. if (file != null && file.fileExists() && !OCFile.ROOT_PATH.equals(file.getFileName())) {
  626. String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
  627. File localFile = new File(localPath);
  628. boolean copied = false;
  629. String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
  630. if (localFile.exists()) {
  631. File targetFile = new File(defaultSavePath + targetPath);
  632. File targetFolder = targetFile.getParentFile();
  633. if (!targetFolder.exists()) {
  634. targetFolder.mkdirs();
  635. }
  636. copied = copyFile(localFile, targetFile);
  637. }
  638. Log_OC.d(TAG, "Local file COPIED : " + copied);
  639. }
  640. }
  641. private boolean copyFile(File src, File target) {
  642. boolean ret = true;
  643. InputStream in = null;
  644. OutputStream out = null;
  645. try {
  646. in = new FileInputStream(src);
  647. out = new FileOutputStream(target);
  648. byte[] buf = new byte[1024];
  649. int len;
  650. while ((len = in.read(buf)) > 0) {
  651. out.write(buf, 0, len);
  652. }
  653. } catch (IOException ex) {
  654. ret = false;
  655. } finally {
  656. if (in != null) try {
  657. in.close();
  658. } catch (IOException e) {
  659. e.printStackTrace(System.err);
  660. }
  661. if (out != null) try {
  662. out.close();
  663. } catch (IOException e) {
  664. e.printStackTrace(System.err);
  665. }
  666. }
  667. return ret;
  668. }
  669. private Vector<OCFile> getFolderContent(long parentId/*, boolean onlyOnDevice*/) {
  670. Vector<OCFile> ret = new Vector<OCFile>();
  671. Uri req_uri = Uri.withAppendedPath(
  672. ProviderTableMeta.CONTENT_URI_DIR,
  673. String.valueOf(parentId));
  674. Cursor c = null;
  675. if (getContentProviderClient() != null) {
  676. try {
  677. c = getContentProviderClient().query(req_uri, null,
  678. ProviderTableMeta.FILE_PARENT + "=?",
  679. new String[]{String.valueOf(parentId)}, null);
  680. } catch (RemoteException e) {
  681. Log_OC.e(TAG, e.getMessage());
  682. return ret;
  683. }
  684. } else {
  685. c = getContentResolver().query(req_uri, null,
  686. ProviderTableMeta.FILE_PARENT + "=?",
  687. new String[]{String.valueOf(parentId)}, null);
  688. }
  689. if (c.moveToFirst()) {
  690. do {
  691. OCFile child = createFileInstance(c);
  692. // TODO Enable when "On Device" is recovered ?
  693. // if (child.isFolder() || !onlyOnDevice || onlyOnDevice && child.isDown()){
  694. ret.add(child);
  695. // }
  696. } while (c.moveToNext());
  697. }
  698. c.close();
  699. Collections.sort(ret);
  700. return ret;
  701. }
  702. private OCFile createRootDir() {
  703. OCFile file = new OCFile(OCFile.ROOT_PATH);
  704. file.setMimetype("DIR");
  705. file.setParentId(FileDataStorageManager.ROOT_PARENT_ID);
  706. saveFile(file);
  707. return file;
  708. }
  709. private boolean fileExists(String cmp_key, String value) {
  710. Cursor c;
  711. if (getContentResolver() != null) {
  712. c = getContentResolver()
  713. .query(ProviderTableMeta.CONTENT_URI,
  714. null,
  715. cmp_key + "=? AND "
  716. + ProviderTableMeta.FILE_ACCOUNT_OWNER
  717. + "=?",
  718. new String[]{value, mAccount.name}, null);
  719. } else {
  720. try {
  721. c = getContentProviderClient().query(
  722. ProviderTableMeta.CONTENT_URI,
  723. null,
  724. cmp_key + "=? AND "
  725. + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
  726. new String[]{value, mAccount.name}, null);
  727. } catch (RemoteException e) {
  728. Log_OC.e(TAG,
  729. "Couldn't determine file existance, assuming non existance: "
  730. + e.getMessage());
  731. return false;
  732. }
  733. }
  734. boolean retval = c.moveToFirst();
  735. c.close();
  736. return retval;
  737. }
  738. private Cursor getFileCursorForValue(String key, String value) {
  739. Cursor c = null;
  740. if (getContentResolver() != null) {
  741. c = getContentResolver()
  742. .query(ProviderTableMeta.CONTENT_URI,
  743. null,
  744. key + "=? AND "
  745. + ProviderTableMeta.FILE_ACCOUNT_OWNER
  746. + "=?",
  747. new String[]{value, mAccount.name}, null);
  748. } else {
  749. try {
  750. c = getContentProviderClient().query(
  751. ProviderTableMeta.CONTENT_URI,
  752. null,
  753. key + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER
  754. + "=?", new String[]{value, mAccount.name},
  755. null);
  756. } catch (RemoteException e) {
  757. Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
  758. c = null;
  759. }
  760. }
  761. return c;
  762. }
  763. private OCFile createFileInstance(Cursor c) {
  764. OCFile file = null;
  765. if (c != null) {
  766. file = new OCFile(c.getString(c
  767. .getColumnIndex(ProviderTableMeta.FILE_PATH)));
  768. file.setFileId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID)));
  769. file.setParentId(c.getLong(c
  770. .getColumnIndex(ProviderTableMeta.FILE_PARENT)));
  771. file.setMimetype(c.getString(c
  772. .getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)));
  773. if (!file.isFolder()) {
  774. file.setStoragePath(c.getString(c
  775. .getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
  776. if (file.getStoragePath() == null) {
  777. // try to find existing file and bind it with current account;
  778. // with the current update of SynchronizeFolderOperation, this won't be
  779. // necessary anymore after a full synchronization of the account
  780. File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
  781. if (f.exists()) {
  782. file.setStoragePath(f.getAbsolutePath());
  783. file.setLastSyncDateForData(f.lastModified());
  784. }
  785. }
  786. }
  787. file.setFileLength(c.getLong(c
  788. .getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH)));
  789. file.setCreationTimestamp(c.getLong(c
  790. .getColumnIndex(ProviderTableMeta.FILE_CREATION)));
  791. file.setModificationTimestamp(c.getLong(c
  792. .getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
  793. file.setModificationTimestampAtLastSyncForData(c.getLong(c
  794. .getColumnIndex(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
  795. file.setLastSyncDateForProperties(c.getLong(c
  796. .getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
  797. file.setLastSyncDateForData(c.getLong(c.
  798. getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)));
  799. file.setFavorite(c.getInt(
  800. c.getColumnIndex(ProviderTableMeta.FILE_KEEP_IN_SYNC)) == 1 ? true : false);
  801. file.setEtag(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG)));
  802. file.setShareViaLink(c.getInt(
  803. c.getColumnIndex(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1 ? true : false);
  804. file.setShareWithSharee(c.getInt(
  805. c.getColumnIndex(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1 ? true : false);
  806. file.setPublicLink(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK)));
  807. file.setPermissions(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS)));
  808. file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
  809. file.setNeedsUpdateThumbnail(c.getInt(
  810. c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false);
  811. file.setDownloading(c.getInt(
  812. c.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1 ? true : false);
  813. file.setEtagInConflict(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG_IN_CONFLICT)));
  814. }
  815. return file;
  816. }
  817. // Methods for Shares
  818. public boolean saveShare(OCShare share) {
  819. boolean overriden = false;
  820. ContentValues cv = new ContentValues();
  821. cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource());
  822. cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource());
  823. cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue());
  824. cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith());
  825. cv.put(ProviderTableMeta.OCSHARES_PATH, share.getPath());
  826. cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions());
  827. cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
  828. cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
  829. cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
  830. cv.put(
  831. ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
  832. share.getSharedWithDisplayName()
  833. );
  834. cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
  835. cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
  836. cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
  837. cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
  838. if (shareExistsForRemoteId(share.getRemoteId())) {// for renamed files; no more delete and create
  839. overriden = true;
  840. if (getContentResolver() != null) {
  841. getContentResolver().update(ProviderTableMeta.CONTENT_URI_SHARE, cv,
  842. ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
  843. new String[]{String.valueOf(share.getRemoteId())});
  844. } else {
  845. try {
  846. getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_SHARE,
  847. cv, ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
  848. new String[]{String.valueOf(share.getRemoteId())});
  849. } catch (RemoteException e) {
  850. Log_OC.e(TAG,
  851. "Fail to insert insert file to database "
  852. + e.getMessage());
  853. }
  854. }
  855. } else {
  856. Uri result_uri = null;
  857. if (getContentResolver() != null) {
  858. result_uri = getContentResolver().insert(
  859. ProviderTableMeta.CONTENT_URI_SHARE, cv);
  860. } else {
  861. try {
  862. result_uri = getContentProviderClient().insert(
  863. ProviderTableMeta.CONTENT_URI_SHARE, cv);
  864. } catch (RemoteException e) {
  865. Log_OC.e(TAG,
  866. "Fail to insert insert file to database "
  867. + e.getMessage());
  868. }
  869. }
  870. if (result_uri != null) {
  871. long new_id = Long.parseLong(result_uri.getPathSegments()
  872. .get(1));
  873. share.setId(new_id);
  874. }
  875. }
  876. return overriden;
  877. }
  878. /**
  879. * Retrieves an stored {@link OCShare} given its id.
  880. *
  881. * @param id Identifier.
  882. * @return Stored {@link OCShare} given its id.
  883. */
  884. public OCShare getShareById(long id) {
  885. OCShare share = null;
  886. Cursor c = getShareCursorForValue(
  887. ProviderTableMeta._ID,
  888. String.valueOf(id)
  889. );
  890. if (c != null) {
  891. if (c.moveToFirst()) {
  892. share = createShareInstance(c);
  893. }
  894. c.close();
  895. }
  896. return share;
  897. }
  898. /**
  899. * Checks the existance of an stored {@link OCShare} matching the given remote id (not to be confused with
  900. * the local id) in the current account.
  901. *
  902. * @param remoteId Remote of the share in the server.
  903. * @return 'True' if a matching {@link OCShare} is stored in the current account.
  904. */
  905. private boolean shareExistsForRemoteId(long remoteId) {
  906. return shareExistsForValue(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, String.valueOf(remoteId));
  907. }
  908. /**
  909. * Checks the existance of an stored {@link OCShare} in the current account
  910. * matching a given column and a value for that column
  911. *
  912. * @param key Name of the column to match.
  913. * @param value Value of the column to match.
  914. * @return 'True' if a matching {@link OCShare} is stored in the current account.
  915. */
  916. private boolean shareExistsForValue(String key, String value) {
  917. Cursor c = getShareCursorForValue(key, value);
  918. boolean retval = c.moveToFirst();
  919. c.close();
  920. return retval;
  921. }
  922. /**
  923. * Gets a {@link Cursor} for an stored {@link OCShare} in the current account
  924. * matching a given column and a value for that column
  925. *
  926. * @param key Name of the column to match.
  927. * @param value Value of the column to match.
  928. * @return 'True' if a matching {@link OCShare} is stored in the current account.
  929. */
  930. private Cursor getShareCursorForValue(String key, String value) {
  931. Cursor c;
  932. if (getContentResolver() != null) {
  933. c = getContentResolver()
  934. .query(ProviderTableMeta.CONTENT_URI_SHARE,
  935. null,
  936. key + "=? AND "
  937. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
  938. new String[]{value, mAccount.name},
  939. null
  940. );
  941. } else {
  942. try {
  943. c = getContentProviderClient().query(
  944. ProviderTableMeta.CONTENT_URI_SHARE,
  945. null,
  946. key + "=? AND "
  947. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
  948. new String[]{value, mAccount.name},
  949. null
  950. );
  951. } catch (RemoteException e) {
  952. Log_OC.w(TAG,
  953. "Could not get details, assuming share does not exist: "+ e.getMessage());
  954. c = null;
  955. }
  956. }
  957. return c;
  958. }
  959. /**
  960. * Get first share bound to a file with a known path and given {@link ShareType}.
  961. *
  962. * @param path Path of the file.
  963. * @param type Type of the share to get
  964. * @param shareWith Target of the share. Ignored in type is {@link ShareType#PUBLIC_LINK}
  965. * @return First {@OCShare} instance found in DB bound to the file in 'path'
  966. */
  967. public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
  968. Cursor c = null;
  969. if (shareWith == null) {
  970. shareWith = "";
  971. }
  972. String selection = ProviderTableMeta.OCSHARES_PATH + "=? AND "
  973. + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
  974. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" ;
  975. if (!ShareType.PUBLIC_LINK.equals(type)) {
  976. selection += " AND " + ProviderTableMeta.OCSHARES_SHARE_WITH + "=?";
  977. }
  978. String [] selectionArgs;
  979. if (ShareType.PUBLIC_LINK.equals(type)) {
  980. selectionArgs = new String[]{
  981. path,
  982. Integer.toString(type.getValue()),
  983. mAccount.name
  984. };
  985. } else {
  986. selectionArgs = new String[]{
  987. path,
  988. Integer.toString(type.getValue()),
  989. mAccount.name,
  990. shareWith
  991. };
  992. }
  993. if (getContentResolver() != null) {
  994. c = getContentResolver().query(
  995. ProviderTableMeta.CONTENT_URI_SHARE,
  996. null,
  997. selection, selectionArgs,
  998. null);
  999. } else {
  1000. try {
  1001. c = getContentProviderClient().query(
  1002. ProviderTableMeta.CONTENT_URI_SHARE,
  1003. null,
  1004. selection, selectionArgs,
  1005. null);
  1006. } catch (RemoteException e) {
  1007. Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
  1008. c = null;
  1009. }
  1010. }
  1011. OCShare share = null;
  1012. if (c.moveToFirst()) {
  1013. share = createShareInstance(c);
  1014. }
  1015. c.close();
  1016. return share;
  1017. }
  1018. private OCShare createShareInstance(Cursor c) {
  1019. OCShare share = null;
  1020. if (c != null) {
  1021. share = new OCShare(c.getString(c
  1022. .getColumnIndex(ProviderTableMeta.OCSHARES_PATH)));
  1023. share.setId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID)));
  1024. share.setFileSource(c.getLong(c
  1025. .getColumnIndex(ProviderTableMeta.OCSHARES_ITEM_SOURCE)));
  1026. share.setShareType(ShareType.fromValue(c.getInt(c
  1027. .getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_TYPE))));
  1028. share.setShareWith(c.getString(c
  1029. .getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_WITH)));
  1030. share.setPermissions(c.getInt(c
  1031. .getColumnIndex(ProviderTableMeta.OCSHARES_PERMISSIONS)));
  1032. share.setSharedDate(c.getLong(c
  1033. .getColumnIndex(ProviderTableMeta.OCSHARES_SHARED_DATE)));
  1034. share.setExpirationDate(c.getLong(c
  1035. .getColumnIndex(ProviderTableMeta.OCSHARES_EXPIRATION_DATE)));
  1036. share.setToken(c.getString(c
  1037. .getColumnIndex(ProviderTableMeta.OCSHARES_TOKEN)));
  1038. share.setSharedWithDisplayName(c.getString(c
  1039. .getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME)));
  1040. share.setIsFolder(c.getInt(
  1041. c.getColumnIndex(ProviderTableMeta.OCSHARES_IS_DIRECTORY)) == 1);
  1042. share.setUserId(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_USER_ID)));
  1043. share.setIdRemoteShared(c.getLong(
  1044. c.getColumnIndex(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED)));
  1045. }
  1046. return share;
  1047. }
  1048. private void resetShareFlagsInAllFiles() {
  1049. ContentValues cv = new ContentValues();
  1050. cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
  1051. cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
  1052. cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
  1053. String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
  1054. String[] whereArgs = new String[]{mAccount.name};
  1055. if (getContentResolver() != null) {
  1056. getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
  1057. } else {
  1058. try {
  1059. getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where,
  1060. whereArgs);
  1061. } catch (RemoteException e) {
  1062. Log_OC.e(TAG, "Exception in resetShareFlagsInAllFiles" + e.getMessage());
  1063. }
  1064. }
  1065. }
  1066. private void resetShareFlagsInFolder(OCFile folder) {
  1067. ContentValues cv = new ContentValues();
  1068. cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
  1069. cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
  1070. cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
  1071. String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  1072. ProviderTableMeta.FILE_PARENT + "=?";
  1073. String [] whereArgs = new String[] { mAccount.name , String.valueOf(folder.getFileId()) };
  1074. if (getContentResolver() != null) {
  1075. getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
  1076. } else {
  1077. try {
  1078. getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where,
  1079. whereArgs);
  1080. } catch (RemoteException e) {
  1081. Log_OC.e(TAG, "Exception in resetShareFlagsInFolder " + e.getMessage());
  1082. }
  1083. }
  1084. }
  1085. private void resetShareFlagInAFile(String filePath){
  1086. ContentValues cv = new ContentValues();
  1087. cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
  1088. cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
  1089. cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
  1090. String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  1091. ProviderTableMeta.FILE_PATH+ "=?";
  1092. String [] whereArgs = new String[] { mAccount.name , filePath };
  1093. if (getContentResolver() != null) {
  1094. getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
  1095. } else {
  1096. try {
  1097. getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where,
  1098. whereArgs);
  1099. } catch (RemoteException e) {
  1100. Log_OC.e(TAG, "Exception in resetShareFlagsInFolder " + e.getMessage());
  1101. }
  1102. }
  1103. }
  1104. private void cleanShares() {
  1105. String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
  1106. String[] whereArgs = new String[]{mAccount.name};
  1107. if (getContentResolver() != null) {
  1108. getContentResolver().delete(ProviderTableMeta.CONTENT_URI_SHARE, where, whereArgs);
  1109. } else {
  1110. try {
  1111. getContentProviderClient().delete(ProviderTableMeta.CONTENT_URI_SHARE, where,
  1112. whereArgs);
  1113. } catch (RemoteException e) {
  1114. Log_OC.e(TAG, "Exception in cleanShares" + e.getMessage());
  1115. }
  1116. }
  1117. }
  1118. public void saveShares(Collection<OCShare> shares) {
  1119. cleanShares();
  1120. if (shares != null) {
  1121. ArrayList<ContentProviderOperation> operations =
  1122. new ArrayList<ContentProviderOperation>(shares.size());
  1123. // prepare operations to insert or update files to save in the given folder
  1124. for (OCShare share : shares) {
  1125. ContentValues cv = new ContentValues();
  1126. cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource());
  1127. cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource());
  1128. cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue());
  1129. cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith());
  1130. cv.put(ProviderTableMeta.OCSHARES_PATH, share.getPath());
  1131. cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions());
  1132. cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
  1133. cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
  1134. cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
  1135. cv.put(
  1136. ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
  1137. share.getSharedWithDisplayName()
  1138. );
  1139. cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
  1140. cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
  1141. cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
  1142. cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
  1143. if (shareExistsForRemoteId(share.getRemoteId())) {
  1144. // updating an existing file
  1145. operations.add(
  1146. ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).
  1147. withValues(cv).
  1148. withSelection(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
  1149. new String[]{String.valueOf(share.getRemoteId())})
  1150. .build());
  1151. } else {
  1152. // adding a new file
  1153. operations.add(
  1154. ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).
  1155. withValues(cv).
  1156. build()
  1157. );
  1158. }
  1159. }
  1160. // apply operations in batch
  1161. if (operations.size() > 0) {
  1162. @SuppressWarnings("unused")
  1163. ContentProviderResult[] results = null;
  1164. Log_OC.d(TAG, "Sending " + operations.size() +
  1165. " operations to FileContentProvider");
  1166. try {
  1167. if (getContentResolver() != null) {
  1168. results = getContentResolver().applyBatch(MainApp.getAuthority(),
  1169. operations);
  1170. } else {
  1171. results = getContentProviderClient().applyBatch(operations);
  1172. }
  1173. } catch (OperationApplicationException e) {
  1174. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  1175. } catch (RemoteException e) {
  1176. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  1177. }
  1178. }
  1179. }
  1180. }
  1181. public void updateSharedFiles(Collection<OCFile> sharedFiles) {
  1182. resetShareFlagsInAllFiles();
  1183. if (sharedFiles != null) {
  1184. ArrayList<ContentProviderOperation> operations =
  1185. new ArrayList<ContentProviderOperation>(sharedFiles.size());
  1186. // prepare operations to insert or update files to save in the given folder
  1187. for (OCFile file : sharedFiles) {
  1188. ContentValues cv = new ContentValues();
  1189. cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
  1190. cv.put(
  1191. ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
  1192. file.getModificationTimestampAtLastSyncForData()
  1193. );
  1194. cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
  1195. cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
  1196. cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
  1197. cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
  1198. cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
  1199. cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
  1200. if (!file.isFolder()) {
  1201. cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
  1202. }
  1203. cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
  1204. cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
  1205. cv.put(
  1206. ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA,
  1207. file.getLastSyncDateForData()
  1208. );
  1209. cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isFavorite() ? 1 : 0);
  1210. cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
  1211. cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
  1212. cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
  1213. cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
  1214. cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
  1215. cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
  1216. cv.put(
  1217. ProviderTableMeta.FILE_UPDATE_THUMBNAIL,
  1218. file.needsUpdateThumbnail() ? 1 : 0
  1219. );
  1220. cv.put(
  1221. ProviderTableMeta.FILE_IS_DOWNLOADING,
  1222. file.isDownloading() ? 1 : 0
  1223. );
  1224. cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
  1225. boolean existsByPath = fileExists(file.getRemotePath());
  1226. if (existsByPath || fileExists(file.getFileId())) {
  1227. // updating an existing file
  1228. operations.add(
  1229. ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
  1230. withValues(cv).
  1231. withSelection(ProviderTableMeta._ID + "=?",
  1232. new String[]{String.valueOf(file.getFileId())})
  1233. .build());
  1234. } else {
  1235. // adding a new file
  1236. operations.add(
  1237. ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).
  1238. withValues(cv).
  1239. build()
  1240. );
  1241. }
  1242. }
  1243. // apply operations in batch
  1244. if (operations.size() > 0) {
  1245. @SuppressWarnings("unused")
  1246. ContentProviderResult[] results = null;
  1247. Log_OC.d(TAG, "Sending " + operations.size() +
  1248. " operations to FileContentProvider");
  1249. try {
  1250. if (getContentResolver() != null) {
  1251. results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
  1252. } else {
  1253. results = getContentProviderClient().applyBatch(operations);
  1254. }
  1255. } catch (OperationApplicationException e) {
  1256. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  1257. } catch (RemoteException e) {
  1258. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  1259. }
  1260. }
  1261. }
  1262. }
  1263. public void removeShare(OCShare share) {
  1264. Uri share_uri = ProviderTableMeta.CONTENT_URI_SHARE;
  1265. String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" + " AND " +
  1266. ProviderTableMeta._ID + "=?";
  1267. String [] whereArgs = new String[]{mAccount.name, Long.toString(share.getId())};
  1268. if (getContentProviderClient() != null) {
  1269. try {
  1270. getContentProviderClient().delete(share_uri, where, whereArgs);
  1271. } catch (RemoteException e) {
  1272. e.printStackTrace();
  1273. }
  1274. } else {
  1275. getContentResolver().delete(share_uri, where, whereArgs);
  1276. }
  1277. }
  1278. public void saveSharesDB(ArrayList<OCShare> shares) {
  1279. ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
  1280. // Reset flags & Remove shares for this files
  1281. String filePath = "";
  1282. for (OCShare share: shares) {
  1283. if (filePath != share.getPath()){
  1284. filePath = share.getPath();
  1285. resetShareFlagInAFile(filePath);
  1286. operations = prepareRemoveSharesInFile(filePath, operations);
  1287. }
  1288. }
  1289. // Add operations to insert shares
  1290. operations = prepareInsertShares(shares, operations);
  1291. // apply operations in batch
  1292. if (operations.size() > 0) {
  1293. Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
  1294. try {
  1295. if (getContentResolver() != null) {
  1296. getContentResolver().applyBatch(MainApp.getAuthority(), operations);
  1297. } else {
  1298. getContentProviderClient().applyBatch(operations);
  1299. }
  1300. } catch (OperationApplicationException e) {
  1301. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  1302. } catch (RemoteException e) {
  1303. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  1304. }
  1305. }
  1306. // // TODO: review if it is needed
  1307. // // Update shared files
  1308. // ArrayList<OCFile> sharedFiles = new ArrayList<OCFile>();
  1309. //
  1310. // for (OCShare share : shares) {
  1311. // // Get the path
  1312. // String path = share.getPath();
  1313. // if (share.isFolder()) {
  1314. // path = path + FileUtils.PATH_SEPARATOR;
  1315. // }
  1316. //
  1317. // // Update OCFile with data from share: ShareByLink, publicLink and
  1318. // OCFile file = getFileByPath(path);
  1319. // if (file != null) {
  1320. // if (share.getShareType().equals(ShareType.PUBLIC_LINK)) {
  1321. // file.setShareViaLink(true);
  1322. // sharedFiles.add(file);
  1323. // }
  1324. // }
  1325. // }
  1326. //
  1327. // // TODO: Review
  1328. // updateSharedFiles(sharedFiles);
  1329. }
  1330. public void removeSharesForFile(String remotePath) {
  1331. resetShareFlagInAFile(remotePath);
  1332. ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
  1333. operations = prepareRemoveSharesInFile(remotePath, operations);
  1334. // apply operations in batch
  1335. if (operations.size() > 0) {
  1336. Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
  1337. try {
  1338. if (getContentResolver() != null) {
  1339. getContentResolver().applyBatch(MainApp.getAuthority(), operations);
  1340. } else {
  1341. getContentProviderClient().applyBatch(operations);
  1342. }
  1343. } catch (OperationApplicationException e) {
  1344. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  1345. } catch (RemoteException e) {
  1346. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  1347. }
  1348. }
  1349. }
  1350. public void saveSharesInFolder(ArrayList<OCShare> shares, OCFile folder) {
  1351. resetShareFlagsInFolder(folder);
  1352. ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
  1353. operations = prepareRemoveSharesInFolder(folder, operations);
  1354. if (shares != null) {
  1355. // prepare operations to insert or update files to save in the given folder
  1356. operations = prepareInsertShares(shares, operations);
  1357. }
  1358. // apply operations in batch
  1359. if (operations.size() > 0) {
  1360. Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
  1361. try {
  1362. if (getContentResolver() != null) {
  1363. getContentResolver().applyBatch(MainApp.getAuthority(), operations);
  1364. } else {
  1365. getContentProviderClient().applyBatch(operations);
  1366. }
  1367. } catch (OperationApplicationException e) {
  1368. Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
  1369. } catch (RemoteException e) {
  1370. }
  1371. }
  1372. }
  1373. /**
  1374. * Prepare operations to insert or update files to save in the given folder
  1375. * @param shares List of shares to insert
  1376. * @param operations List of operations
  1377. * @return
  1378. */
  1379. private ArrayList<ContentProviderOperation> prepareInsertShares(
  1380. ArrayList<OCShare> shares, ArrayList<ContentProviderOperation> operations) {
  1381. if (shares != null) {
  1382. // prepare operations to insert or update files to save in the given folder
  1383. for (OCShare share : shares) {
  1384. ContentValues cv = new ContentValues();
  1385. cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource());
  1386. cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource());
  1387. cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue());
  1388. cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith());
  1389. cv.put(ProviderTableMeta.OCSHARES_PATH, share.getPath());
  1390. cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions());
  1391. cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
  1392. cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
  1393. cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
  1394. cv.put(
  1395. ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
  1396. share.getSharedWithDisplayName()
  1397. );
  1398. cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
  1399. cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
  1400. cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
  1401. cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
  1402. // adding a new share resource
  1403. operations.add(
  1404. ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).
  1405. withValues(cv).
  1406. build()
  1407. );
  1408. }
  1409. }
  1410. return operations;
  1411. }
  1412. private ArrayList<ContentProviderOperation> prepareRemoveSharesInFolder(
  1413. OCFile folder, ArrayList<ContentProviderOperation> preparedOperations) {
  1414. if (folder != null) {
  1415. String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND "
  1416. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
  1417. String [] whereArgs = new String[]{ "", mAccount.name };
  1418. // TODO Enable when "On Device" is recovered ?
  1419. Vector<OCFile> files = getFolderContent(folder /*, false*/);
  1420. for (OCFile file : files) {
  1421. whereArgs[0] = file.getRemotePath();
  1422. preparedOperations.add(
  1423. ContentProviderOperation.newDelete(ProviderTableMeta.CONTENT_URI_SHARE).
  1424. withSelection(where, whereArgs).
  1425. build()
  1426. );
  1427. }
  1428. }
  1429. return preparedOperations;
  1430. }
  1431. private ArrayList<ContentProviderOperation> prepareRemoveSharesInFile(
  1432. String filePath, ArrayList<ContentProviderOperation> preparedOperations) {
  1433. String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND "
  1434. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
  1435. String[] whereArgs = new String[]{filePath, mAccount.name};
  1436. preparedOperations.add(
  1437. ContentProviderOperation.newDelete(ProviderTableMeta.CONTENT_URI_SHARE).
  1438. withSelection(where, whereArgs).
  1439. build()
  1440. );
  1441. return preparedOperations;
  1442. }
  1443. public ArrayList<OCShare> getSharesWithForAFile(String filePath, String accountName){
  1444. // Condition
  1445. String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND "
  1446. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?"+ "AND"
  1447. + " (" + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
  1448. + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? ) ";
  1449. String [] whereArgs = new String[]{ filePath, accountName ,
  1450. Integer.toString(ShareType.USER.getValue()),
  1451. Integer.toString(ShareType.GROUP.getValue()) };
  1452. Cursor c = null;
  1453. if (getContentResolver() != null) {
  1454. c = getContentResolver().query(
  1455. ProviderTableMeta.CONTENT_URI_SHARE,
  1456. null, where, whereArgs, null);
  1457. } else {
  1458. try {
  1459. c = getContentProviderClient().query(
  1460. ProviderTableMeta.CONTENT_URI_SHARE,
  1461. null, where, whereArgs, null);
  1462. } catch (RemoteException e) {
  1463. Log_OC.e(TAG, "Could not get list of shares with: " + e.getMessage());
  1464. c = null;
  1465. }
  1466. }
  1467. ArrayList<OCShare> shares = new ArrayList<OCShare>();
  1468. OCShare share = null;
  1469. if (c.moveToFirst()) {
  1470. do {
  1471. share = createShareInstance(c);
  1472. shares.add(share);
  1473. // }
  1474. } while (c.moveToNext());
  1475. }
  1476. c.close();
  1477. return shares;
  1478. }
  1479. public static void triggerMediaScan(String path) {
  1480. if (path != null) {
  1481. Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
  1482. intent.setData(Uri.fromFile(new File(path)));
  1483. MainApp.getAppContext().sendBroadcast(intent);
  1484. }
  1485. }
  1486. public void deleteFileInMediaScan(String path) {
  1487. String mimetypeString = FileStorageUtils.getMimeTypeFromName(path);
  1488. ContentResolver contentResolver = getContentResolver();
  1489. if (contentResolver != null) {
  1490. if (mimetypeString.startsWith("image/")) {
  1491. // Images
  1492. contentResolver.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
  1493. MediaStore.Images.Media.DATA + "=?", new String[]{path});
  1494. } else if (mimetypeString.startsWith("audio/")) {
  1495. // Audio
  1496. contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
  1497. MediaStore.Audio.Media.DATA + "=?", new String[]{path});
  1498. } else if (mimetypeString.startsWith("video/")) {
  1499. // Video
  1500. contentResolver.delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
  1501. MediaStore.Video.Media.DATA + "=?", new String[]{path});
  1502. }
  1503. } else {
  1504. ContentProviderClient contentProviderClient = getContentProviderClient();
  1505. try {
  1506. if (mimetypeString.startsWith("image/")) {
  1507. // Images
  1508. contentProviderClient.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
  1509. MediaStore.Images.Media.DATA + "=?", new String[]{path});
  1510. } else if (mimetypeString.startsWith("audio/")) {
  1511. // Audio
  1512. contentProviderClient.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
  1513. MediaStore.Audio.Media.DATA + "=?", new String[]{path});
  1514. } else if (mimetypeString.startsWith("video/")) {
  1515. // Video
  1516. contentProviderClient.delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
  1517. MediaStore.Video.Media.DATA + "=?", new String[]{path});
  1518. }
  1519. } catch (RemoteException e) {
  1520. Log_OC.e(TAG, "Exception deleting media file in MediaStore " + e.getMessage());
  1521. }
  1522. }
  1523. }
  1524. public void saveConflict(OCFile file, String etagInConflict) {
  1525. if (!file.isDown()) {
  1526. etagInConflict = null;
  1527. }
  1528. ContentValues cv = new ContentValues();
  1529. cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, etagInConflict);
  1530. int updated = 0;
  1531. if (getContentResolver() != null) {
  1532. updated = getContentResolver().update(
  1533. ProviderTableMeta.CONTENT_URI_FILE,
  1534. cv,
  1535. ProviderTableMeta._ID + "=?",
  1536. new String[] { String.valueOf(file.getFileId())}
  1537. );
  1538. } else {
  1539. try {
  1540. updated = getContentProviderClient().update(
  1541. ProviderTableMeta.CONTENT_URI_FILE,
  1542. cv,
  1543. ProviderTableMeta._ID + "=?",
  1544. new String[]{String.valueOf(file.getFileId())}
  1545. );
  1546. } catch (RemoteException e) {
  1547. Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage());
  1548. }
  1549. }
  1550. Log_OC.d(TAG, "Number of files updated with CONFLICT: " + updated);
  1551. if (updated > 0) {
  1552. if (etagInConflict != null) {
  1553. /// set conflict in all ancestor folders
  1554. long parentId = file.getParentId();
  1555. Set<String> ancestorIds = new HashSet<String>();
  1556. while (parentId != FileDataStorageManager.ROOT_PARENT_ID) {
  1557. ancestorIds.add(Long.toString(parentId));
  1558. parentId = getFileById(parentId).getParentId();
  1559. }
  1560. if (ancestorIds.size() > 0) {
  1561. StringBuffer whereBuffer = new StringBuffer();
  1562. whereBuffer.append(ProviderTableMeta._ID).append(" IN (");
  1563. for (int i = 0; i < ancestorIds.size() - 1; i++) {
  1564. whereBuffer.append("?,");
  1565. }
  1566. whereBuffer.append("?");
  1567. whereBuffer.append(")");
  1568. if (getContentResolver() != null) {
  1569. updated = getContentResolver().update(
  1570. ProviderTableMeta.CONTENT_URI_FILE,
  1571. cv,
  1572. whereBuffer.toString(),
  1573. ancestorIds.toArray(new String[]{})
  1574. );
  1575. } else {
  1576. try {
  1577. updated = getContentProviderClient().update(
  1578. ProviderTableMeta.CONTENT_URI_FILE,
  1579. cv,
  1580. whereBuffer.toString(),
  1581. ancestorIds.toArray(new String[]{})
  1582. );
  1583. } catch (RemoteException e) {
  1584. Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage());
  1585. }
  1586. }
  1587. } // else file is ROOT folder, no parent to set in conflict
  1588. } else {
  1589. /// update conflict in ancestor folders
  1590. // (not directly unset; maybe there are more conflicts below them)
  1591. String parentPath = file.getRemotePath();
  1592. if (parentPath.endsWith(OCFile.PATH_SEPARATOR)) {
  1593. parentPath = parentPath.substring(0, parentPath.length() - 1);
  1594. }
  1595. parentPath = parentPath.substring(0, parentPath.lastIndexOf(OCFile.PATH_SEPARATOR) + 1);
  1596. Log_OC.d(TAG, "checking parents to remove conflict; STARTING with " + parentPath);
  1597. while (parentPath.length() > 0) {
  1598. String whereForDescencentsInConflict =
  1599. ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " IS NOT NULL AND " +
  1600. ProviderTableMeta.FILE_CONTENT_TYPE + " != 'DIR' AND " +
  1601. ProviderTableMeta.FILE_ACCOUNT_OWNER + " = ? AND " +
  1602. ProviderTableMeta.FILE_PATH + " LIKE ?";
  1603. Cursor descendentsInConflict = null;
  1604. if (getContentResolver() != null) {
  1605. descendentsInConflict = getContentResolver().query(
  1606. ProviderTableMeta.CONTENT_URI_FILE,
  1607. new String[]{ProviderTableMeta._ID},
  1608. whereForDescencentsInConflict,
  1609. new String[]{mAccount.name, parentPath + "%"},
  1610. null
  1611. );
  1612. } else {
  1613. try {
  1614. descendentsInConflict = getContentProviderClient().query(
  1615. ProviderTableMeta.CONTENT_URI_FILE,
  1616. new String[]{ProviderTableMeta._ID},
  1617. whereForDescencentsInConflict,
  1618. new String[]{mAccount.name, parentPath + "%"},
  1619. null
  1620. );
  1621. } catch (RemoteException e) {
  1622. Log_OC.e(TAG, "Failed querying for descendents in conflict " + e.getMessage());
  1623. }
  1624. }
  1625. if (descendentsInConflict == null || descendentsInConflict.getCount() == 0) {
  1626. Log_OC.d(TAG, "NO MORE conflicts in " + parentPath);
  1627. if (getContentResolver() != null) {
  1628. updated = getContentResolver().update(
  1629. ProviderTableMeta.CONTENT_URI_FILE,
  1630. cv,
  1631. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  1632. ProviderTableMeta.FILE_PATH + "=?",
  1633. new String[]{mAccount.name, parentPath}
  1634. );
  1635. } else {
  1636. try {
  1637. updated = getContentProviderClient().update(
  1638. ProviderTableMeta.CONTENT_URI_FILE,
  1639. cv,
  1640. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  1641. ProviderTableMeta.FILE_PATH + "=?"
  1642. , new String[]{mAccount.name, parentPath}
  1643. );
  1644. } catch (RemoteException e) {
  1645. Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage());
  1646. }
  1647. }
  1648. } else {
  1649. Log_OC.d(TAG, "STILL " + descendentsInConflict.getCount() + " in " + parentPath);
  1650. }
  1651. if (descendentsInConflict != null) {
  1652. descendentsInConflict.close();
  1653. }
  1654. parentPath = parentPath.substring(0, parentPath.length() - 1); // trim last /
  1655. parentPath = parentPath.substring(0, parentPath.lastIndexOf(OCFile.PATH_SEPARATOR) + 1);
  1656. Log_OC.d(TAG, "checking parents to remove conflict; NEXT " + parentPath);
  1657. }
  1658. }
  1659. }
  1660. }
  1661. public OCCapability saveCapabilities(OCCapability capability){
  1662. // Prepare capabilities data
  1663. ContentValues cv = new ContentValues();
  1664. cv.put(ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME, mAccount.name);
  1665. cv.put(ProviderTableMeta.CAPABILITIES_VERSION_MAYOR, capability.getVersionMayor());
  1666. cv.put(ProviderTableMeta.CAPABILITIES_VERSION_MINOR, capability.getVersionMinor());
  1667. cv.put(ProviderTableMeta.CAPABILITIES_VERSION_MICRO, capability.getVersionMicro());
  1668. cv.put(ProviderTableMeta.CAPABILITIES_VERSION_STRING, capability.getVersionString());
  1669. cv.put(ProviderTableMeta.CAPABILITIES_VERSION_EDITION, capability.getVersionEdition());
  1670. cv.put(ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL, capability.getCorePollinterval());
  1671. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED, capability.getFilesSharingApiEnabled().getValue());
  1672. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED,
  1673. capability.getFilesSharingPublicEnabled().getValue());
  1674. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED,
  1675. capability.getFilesSharingPublicPasswordEnforced().getValue());
  1676. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED,
  1677. capability.getFilesSharingPublicExpireDateEnabled().getValue());
  1678. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS,
  1679. capability.getFilesSharingPublicExpireDateDays());
  1680. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED,
  1681. capability.getFilesSharingPublicExpireDateEnforced().getValue());
  1682. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL,
  1683. capability.getFilesSharingPublicSendMail().getValue());
  1684. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD,
  1685. capability.getFilesSharingPublicUpload().getValue());
  1686. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL,
  1687. capability.getFilesSharingUserSendMail().getValue());
  1688. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_RESHARING, capability.getFilesSharingResharing().getValue());
  1689. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING,
  1690. capability.getFilesSharingFederationOutgoing().getValue());
  1691. cv.put(ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING,
  1692. capability.getFilesSharingFederationIncoming().getValue());
  1693. cv.put(ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING, capability.getFilesBigFileChuncking().getValue());
  1694. cv.put(ProviderTableMeta.CAPABILITIES_FILES_UNDELETE, capability.getFilesUndelete().getValue());
  1695. cv.put(ProviderTableMeta.CAPABILITIES_FILES_VERSIONING, capability.getFilesVersioning().getValue());
  1696. if (capabilityExists(mAccount.name)) {
  1697. if (getContentResolver() != null) {
  1698. getContentResolver().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES, cv,
  1699. ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?",
  1700. new String[]{mAccount.name});
  1701. } else {
  1702. try {
  1703. getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES,
  1704. cv, ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?",
  1705. new String[]{mAccount.name});
  1706. } catch (RemoteException e) {
  1707. Log_OC.e(TAG,
  1708. "Fail to insert insert file to database "
  1709. + e.getMessage());
  1710. }
  1711. }
  1712. } else {
  1713. Uri result_uri = null;
  1714. if (getContentResolver() != null) {
  1715. result_uri = getContentResolver().insert(
  1716. ProviderTableMeta.CONTENT_URI_CAPABILITIES, cv);
  1717. } else {
  1718. try {
  1719. result_uri = getContentProviderClient().insert(
  1720. ProviderTableMeta.CONTENT_URI_CAPABILITIES, cv);
  1721. } catch (RemoteException e) {
  1722. Log_OC.e(TAG,
  1723. "Fail to insert insert capability to database "
  1724. + e.getMessage());
  1725. }
  1726. }
  1727. if (result_uri != null) {
  1728. long new_id = Long.parseLong(result_uri.getPathSegments()
  1729. .get(1));
  1730. capability.setId(new_id);
  1731. capability.setAccountName(mAccount.name);
  1732. }
  1733. }
  1734. return capability;
  1735. }
  1736. private boolean capabilityExists(String accountName) {
  1737. Cursor c = getCapabilityCursorForAccount(accountName);
  1738. boolean exists = false;
  1739. if (c != null) {
  1740. exists = c.moveToFirst();
  1741. c.close();
  1742. }
  1743. return exists;
  1744. }
  1745. private Cursor getCapabilityCursorForAccount(String accountName){
  1746. Cursor c = null;
  1747. if (getContentResolver() != null) {
  1748. c = getContentResolver()
  1749. .query(ProviderTableMeta.CONTENT_URI_CAPABILITIES,
  1750. null,
  1751. ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=? ",
  1752. new String[]{accountName}, null);
  1753. } else {
  1754. try {
  1755. c = getContentProviderClient().query(
  1756. ProviderTableMeta.CONTENT_URI_CAPABILITIES,
  1757. null,
  1758. ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=? ",
  1759. new String[]{accountName}, null);
  1760. } catch (RemoteException e) {
  1761. Log_OC.e(TAG,
  1762. "Couldn't determine capability existance, assuming non existance: "
  1763. + e.getMessage());
  1764. }
  1765. }
  1766. return c;
  1767. }
  1768. public OCCapability getCapability(String accountName){
  1769. OCCapability capability = null;
  1770. Cursor c = getCapabilityCursorForAccount(accountName);
  1771. if (c.moveToFirst()) {
  1772. capability = createCapabilityInstance(c);
  1773. } else {
  1774. capability = new OCCapability(); // return default with all UNKNOWN
  1775. }
  1776. c.close();
  1777. return capability;
  1778. }
  1779. private OCCapability createCapabilityInstance(Cursor c) {
  1780. OCCapability capability = null;
  1781. if (c != null) {
  1782. capability = new OCCapability();
  1783. capability.setId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID)));
  1784. capability.setAccountName(c.getString(c
  1785. .getColumnIndex(ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME)));
  1786. capability.setVersionMayor(c.getInt(c
  1787. .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_MAYOR)));
  1788. capability.setVersionMinor(c.getInt(c
  1789. .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_MINOR)));
  1790. capability.setVersionMicro(c.getInt(c
  1791. .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_MICRO)));
  1792. capability.setVersionString(c.getString(c
  1793. .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_STRING)));
  1794. capability.setVersionEdition(c.getString(c
  1795. .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_EDITION)));
  1796. capability.setCorePollinterval(c.getInt(c
  1797. .getColumnIndex(ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL)));
  1798. capability.setFilesSharingApiEnabled(CapabilityBooleanType.fromValue(c.getInt(c
  1799. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED))));
  1800. capability.setFilesSharingPublicEnabled(CapabilityBooleanType.fromValue(c.getInt(c
  1801. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED))));
  1802. capability.setFilesSharingPublicPasswordEnforced(CapabilityBooleanType.fromValue(c.getInt(c
  1803. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED))));
  1804. capability.setFilesSharingPublicExpireDateEnabled(CapabilityBooleanType.fromValue(c.getInt(c
  1805. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED))));
  1806. capability.setFilesSharingPublicExpireDateDays(c.getInt(c
  1807. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS)));
  1808. capability.setFilesSharingPublicExpireDateEnforced(CapabilityBooleanType.fromValue(c.getInt(c
  1809. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED))));
  1810. capability.setFilesSharingPublicSendMail(CapabilityBooleanType.fromValue(c.getInt(c
  1811. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL))));
  1812. capability.setFilesSharingPublicUpload(CapabilityBooleanType.fromValue(c.getInt(c
  1813. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD))));
  1814. capability.setFilesSharingUserSendMail(CapabilityBooleanType.fromValue(c.getInt(c
  1815. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL))));
  1816. capability.setFilesSharingResharing(CapabilityBooleanType.fromValue(c.getInt(c
  1817. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_RESHARING))));
  1818. capability.setFilesSharingFederationOutgoing(CapabilityBooleanType.fromValue(c.getInt(c
  1819. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING))));
  1820. capability.setFilesSharingFederationIncoming(CapabilityBooleanType.fromValue(c.getInt(c
  1821. .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING))));
  1822. capability.setFilesBigFileChuncking(CapabilityBooleanType.fromValue(c.getInt(c
  1823. .getColumnIndex(ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING))));
  1824. capability.setFilesUndelete(CapabilityBooleanType.fromValue(c.getInt(c
  1825. .getColumnIndex(ProviderTableMeta.CAPABILITIES_FILES_UNDELETE))));
  1826. capability.setFilesVersioning(CapabilityBooleanType.fromValue(c.getInt(c
  1827. .getColumnIndex(ProviderTableMeta.CAPABILITIES_FILES_VERSIONING))));
  1828. }
  1829. return capability;
  1830. }
  1831. }