FileDataStorageManager.java 91 KB

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