FileContentProvider.java 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author Bartek Przybylski
  5. * @author David A. Velasco
  6. * @author masensio
  7. * Copyright (C) 2011 Bartek Przybylski
  8. * Copyright (C) 2016 ownCloud Inc.
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. package com.owncloud.android.providers;
  24. import android.accounts.Account;
  25. import android.accounts.AccountManager;
  26. import android.content.ContentProvider;
  27. import android.content.ContentProviderOperation;
  28. import android.content.ContentProviderResult;
  29. import android.content.ContentUris;
  30. import android.content.ContentValues;
  31. import android.content.Context;
  32. import android.content.OperationApplicationException;
  33. import android.content.UriMatcher;
  34. import android.database.Cursor;
  35. import android.database.SQLException;
  36. import android.database.sqlite.SQLiteDatabase;
  37. import android.database.sqlite.SQLiteOpenHelper;
  38. import android.database.sqlite.SQLiteQueryBuilder;
  39. import android.net.Uri;
  40. import android.text.TextUtils;
  41. import com.owncloud.android.MainApp;
  42. import com.owncloud.android.R;
  43. import com.owncloud.android.datamodel.OCFile;
  44. import com.owncloud.android.datamodel.UploadsStorageManager;
  45. import com.owncloud.android.db.ProviderMeta;
  46. import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
  47. import com.owncloud.android.lib.common.accounts.AccountUtils;
  48. import com.owncloud.android.lib.common.utils.Log_OC;
  49. import com.owncloud.android.lib.resources.shares.ShareType;
  50. import com.owncloud.android.utils.FileStorageUtils;
  51. import java.io.File;
  52. import java.util.ArrayList;
  53. /**
  54. * The ContentProvider for the ownCloud App.
  55. */
  56. public class FileContentProvider extends ContentProvider {
  57. private DataBaseHelper mDbHelper;
  58. private static final int SINGLE_FILE = 1;
  59. private static final int DIRECTORY = 2;
  60. private static final int ROOT_DIRECTORY = 3;
  61. private static final int SHARES = 4;
  62. private static final int CAPABILITIES = 5;
  63. private static final int UPLOADS = 6;
  64. private static final String TAG = FileContentProvider.class.getSimpleName();
  65. private final String MAX_SUCCESSFUL_UPLOADS = "30";
  66. private UriMatcher mUriMatcher;
  67. @Override
  68. public int delete(Uri uri, String where, String[] whereArgs) {
  69. //Log_OC.d(TAG, "Deleting " + uri + " at provider " + this);
  70. int count = 0;
  71. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  72. db.beginTransaction();
  73. try {
  74. count = delete(db, uri, where, whereArgs);
  75. db.setTransactionSuccessful();
  76. } finally {
  77. db.endTransaction();
  78. }
  79. getContext().getContentResolver().notifyChange(uri, null);
  80. return count;
  81. }
  82. private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) {
  83. int count = 0;
  84. switch (mUriMatcher.match(uri)) {
  85. case SINGLE_FILE:
  86. Cursor c = query(db, uri, null, where, whereArgs, null);
  87. String remoteId = "";
  88. if (c != null && c.moveToFirst()) {
  89. remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
  90. //ThumbnailsCacheManager.removeFileFromCache(remoteId);
  91. c.close();
  92. }
  93. Log_OC.d(TAG, "Removing FILE " + remoteId);
  94. count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
  95. ProviderTableMeta._ID
  96. + "="
  97. + uri.getPathSegments().get(1)
  98. + (!TextUtils.isEmpty(where) ? " AND (" + where
  99. + ")" : ""), whereArgs);
  100. break;
  101. case DIRECTORY:
  102. // deletion of folder is recursive
  103. /*
  104. Uri folderUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, Long.parseLong(uri.getPathSegments().get(1)));
  105. Cursor folder = query(db, folderUri, null, null, null, null);
  106. String folderName = "(unknown)";
  107. if (folder != null && folder.moveToFirst()) {
  108. folderName = folder.getString(folder.getColumnIndex(ProviderTableMeta.FILE_PATH));
  109. }
  110. */
  111. Cursor children = query(uri, null, null, null, null);
  112. if (children != null && children.moveToFirst()) {
  113. long childId;
  114. boolean isDir;
  115. while (!children.isAfterLast()) {
  116. childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
  117. isDir = "DIR".equals(children.getString(
  118. children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
  119. ));
  120. //remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH));
  121. if (isDir) {
  122. count += delete(
  123. db,
  124. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
  125. null,
  126. null
  127. );
  128. } else {
  129. count += delete(
  130. db,
  131. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
  132. null,
  133. null
  134. );
  135. }
  136. children.moveToNext();
  137. }
  138. children.close();
  139. } /*else {
  140. Log_OC.d(TAG, "No child to remove in DIRECTORY " + folderName);
  141. }
  142. Log_OC.d(TAG, "Removing DIRECTORY " + folderName + " (or maybe not) ");
  143. */
  144. count += db.delete(ProviderTableMeta.FILE_TABLE_NAME,
  145. ProviderTableMeta._ID
  146. + "="
  147. + uri.getPathSegments().get(1)
  148. + (!TextUtils.isEmpty(where) ? " AND (" + where
  149. + ")" : ""), whereArgs);
  150. /* Just for log
  151. if (folder != null) {
  152. folder.close();
  153. }*/
  154. break;
  155. case ROOT_DIRECTORY:
  156. //Log_OC.d(TAG, "Removing ROOT!");
  157. count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs);
  158. break;
  159. case SHARES:
  160. count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs);
  161. break;
  162. case CAPABILITIES:
  163. count = db.delete(ProviderTableMeta.CAPABILITIES_TABLE_NAME, where, whereArgs);
  164. break;
  165. case UPLOADS:
  166. count = db.delete(ProviderTableMeta.UPLOADS_TABLE_NAME, where, whereArgs);
  167. break;
  168. default:
  169. //Log_OC.e(TAG, "Unknown uri " + uri);
  170. throw new IllegalArgumentException("Unknown uri: " + uri.toString());
  171. }
  172. return count;
  173. }
  174. @Override
  175. public String getType(Uri uri) {
  176. switch (mUriMatcher.match(uri)) {
  177. case ROOT_DIRECTORY:
  178. return ProviderTableMeta.CONTENT_TYPE;
  179. case SINGLE_FILE:
  180. return ProviderTableMeta.CONTENT_TYPE_ITEM;
  181. default:
  182. throw new IllegalArgumentException("Unknown Uri id."
  183. + uri.toString());
  184. }
  185. }
  186. @Override
  187. public Uri insert(Uri uri, ContentValues values) {
  188. Uri newUri = null;
  189. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  190. db.beginTransaction();
  191. try {
  192. newUri = insert(db, uri, values);
  193. db.setTransactionSuccessful();
  194. } finally {
  195. db.endTransaction();
  196. }
  197. getContext().getContentResolver().notifyChange(newUri, null);
  198. return newUri;
  199. }
  200. private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) {
  201. switch (mUriMatcher.match(uri)){
  202. case ROOT_DIRECTORY:
  203. case SINGLE_FILE:
  204. String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
  205. String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
  206. String[] projection = new String[] {
  207. ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH,
  208. ProviderTableMeta.FILE_ACCOUNT_OWNER
  209. };
  210. String where = ProviderTableMeta.FILE_PATH + "=? AND " +
  211. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
  212. String[] whereArgs = new String[] {remotePath, accountName};
  213. Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
  214. // ugly patch; serious refactorization is needed to reduce work in
  215. // FileDataStorageManager and bring it to FileContentProvider
  216. if (doubleCheck == null || !doubleCheck.moveToFirst()) {
  217. if (doubleCheck != null) {
  218. doubleCheck.close();
  219. }
  220. long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
  221. if (rowId > 0) {
  222. return ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
  223. } else {
  224. throw new SQLException("ERROR " + uri);
  225. }
  226. } else {
  227. // file is already inserted; race condition, let's avoid a duplicated entry
  228. Uri insertedFileUri = ContentUris.withAppendedId(
  229. ProviderTableMeta.CONTENT_URI_FILE,
  230. doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID))
  231. );
  232. doubleCheck.close();
  233. return insertedFileUri;
  234. }
  235. case SHARES:
  236. Uri insertedShareUri = null;
  237. long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
  238. if (rowId >0) {
  239. insertedShareUri =
  240. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId);
  241. } else {
  242. throw new SQLException("ERROR " + uri);
  243. }
  244. updateFilesTableAccordingToShareInsertion(db, values);
  245. return insertedShareUri;
  246. case CAPABILITIES:
  247. Uri insertedCapUri = null;
  248. long id = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, null, values);
  249. if (id >0) {
  250. insertedCapUri =
  251. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_CAPABILITIES, id);
  252. } else {
  253. throw new SQLException("ERROR " + uri);
  254. }
  255. return insertedCapUri;
  256. case UPLOADS:
  257. Uri insertedUploadUri = null;
  258. long uploadId = db.insert(ProviderTableMeta.UPLOADS_TABLE_NAME, null, values);
  259. if (uploadId >0) {
  260. insertedUploadUri =
  261. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_UPLOADS, uploadId);
  262. trimSuccessfulUploads(db);
  263. } else {
  264. throw new SQLException("ERROR " + uri);
  265. }
  266. return insertedUploadUri;
  267. default:
  268. throw new IllegalArgumentException("Unknown uri id: " + uri);
  269. }
  270. }
  271. private void updateFilesTableAccordingToShareInsertion(
  272. SQLiteDatabase db, ContentValues newShare
  273. ) {
  274. ContentValues fileValues = new ContentValues();
  275. int newShareType = newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE);
  276. if (newShareType == ShareType.PUBLIC_LINK.getValue()) {
  277. fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1);
  278. } else if (
  279. newShareType == ShareType.USER.getValue() ||
  280. newShareType == ShareType.GROUP.getValue() ||
  281. newShareType == ShareType.FEDERATED.getValue() ) {
  282. fileValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, 1);
  283. }
  284. String where = ProviderTableMeta.FILE_PATH + "=? AND " +
  285. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
  286. String[] whereArgs = new String[] {
  287. newShare.getAsString(ProviderTableMeta.OCSHARES_PATH),
  288. newShare.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)
  289. };
  290. db.update(ProviderTableMeta.FILE_TABLE_NAME, fileValues, where, whereArgs);
  291. }
  292. @Override
  293. public boolean onCreate() {
  294. mDbHelper = new DataBaseHelper(getContext());
  295. String authority = getContext().getResources().getString(R.string.authority);
  296. mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  297. mUriMatcher.addURI(authority, null, ROOT_DIRECTORY);
  298. mUriMatcher.addURI(authority, "file/", SINGLE_FILE);
  299. mUriMatcher.addURI(authority, "file/#", SINGLE_FILE);
  300. mUriMatcher.addURI(authority, "dir/", DIRECTORY);
  301. mUriMatcher.addURI(authority, "dir/#", DIRECTORY);
  302. mUriMatcher.addURI(authority, "shares/", SHARES);
  303. mUriMatcher.addURI(authority, "shares/#", SHARES);
  304. mUriMatcher.addURI(authority, "capabilities/", CAPABILITIES);
  305. mUriMatcher.addURI(authority, "capabilities/#", CAPABILITIES);
  306. mUriMatcher.addURI(authority, "uploads/", UPLOADS);
  307. mUriMatcher.addURI(authority, "uploads/#", UPLOADS);
  308. return true;
  309. }
  310. @Override
  311. public Cursor query(
  312. Uri uri,
  313. String[] projection,
  314. String selection,
  315. String[] selectionArgs,
  316. String sortOrder
  317. ) {
  318. Cursor result = null;
  319. SQLiteDatabase db = mDbHelper.getReadableDatabase();
  320. db.beginTransaction();
  321. try {
  322. result = query(db, uri, projection, selection, selectionArgs, sortOrder);
  323. db.setTransactionSuccessful();
  324. } finally {
  325. db.endTransaction();
  326. }
  327. return result;
  328. }
  329. private Cursor query(
  330. SQLiteDatabase db,
  331. Uri uri,
  332. String[] projection,
  333. String selection,
  334. String[] selectionArgs,
  335. String sortOrder
  336. ) {
  337. SQLiteQueryBuilder sqlQuery = new SQLiteQueryBuilder();
  338. sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME);
  339. switch (mUriMatcher.match(uri)) {
  340. case ROOT_DIRECTORY:
  341. break;
  342. case DIRECTORY:
  343. String folderId = uri.getPathSegments().get(1);
  344. sqlQuery.appendWhere(ProviderTableMeta.FILE_PARENT + "="
  345. + folderId);
  346. break;
  347. case SINGLE_FILE:
  348. if (uri.getPathSegments().size() > 1) {
  349. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  350. + uri.getPathSegments().get(1));
  351. }
  352. break;
  353. case SHARES:
  354. sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME);
  355. if (uri.getPathSegments().size() > 1) {
  356. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  357. + uri.getPathSegments().get(1));
  358. }
  359. break;
  360. case CAPABILITIES:
  361. sqlQuery.setTables(ProviderTableMeta.CAPABILITIES_TABLE_NAME);
  362. if (uri.getPathSegments().size() > 1) {
  363. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  364. + uri.getPathSegments().get(1));
  365. }
  366. break;
  367. case UPLOADS:
  368. sqlQuery.setTables(ProviderTableMeta.UPLOADS_TABLE_NAME);
  369. if (uri.getPathSegments().size() > 1) {
  370. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  371. + uri.getPathSegments().get(1));
  372. }
  373. break;
  374. default:
  375. throw new IllegalArgumentException("Unknown uri id: " + uri);
  376. }
  377. String order;
  378. if (TextUtils.isEmpty(sortOrder)) {
  379. switch (mUriMatcher.match(uri)) {
  380. case SHARES:
  381. order = ProviderTableMeta.OCSHARES_DEFAULT_SORT_ORDER;
  382. break;
  383. case CAPABILITIES:
  384. order = ProviderTableMeta.CAPABILITIES_DEFAULT_SORT_ORDER;
  385. break;
  386. case UPLOADS:
  387. order = ProviderTableMeta.UPLOADS_DEFAULT_SORT_ORDER;
  388. break;
  389. default: // Files
  390. order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
  391. break;
  392. }
  393. } else {
  394. order = sortOrder;
  395. }
  396. // DB case_sensitive
  397. db.execSQL("PRAGMA case_sensitive_like = true");
  398. Cursor c = sqlQuery.query(db, projection, selection, selectionArgs, null, null, order);
  399. c.setNotificationUri(getContext().getContentResolver(), uri);
  400. return c;
  401. }
  402. @Override
  403. public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
  404. int count = 0;
  405. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  406. db.beginTransaction();
  407. try {
  408. count = update(db, uri, values, selection, selectionArgs);
  409. db.setTransactionSuccessful();
  410. } finally {
  411. db.endTransaction();
  412. }
  413. getContext().getContentResolver().notifyChange(uri, null);
  414. return count;
  415. }
  416. private int update(
  417. SQLiteDatabase db,
  418. Uri uri,
  419. ContentValues values,
  420. String selection,
  421. String[] selectionArgs
  422. ) {
  423. switch (mUriMatcher.match(uri)) {
  424. case DIRECTORY:
  425. return 0; //updateFolderSize(db, selectionArgs[0]);
  426. case SHARES:
  427. return db.update(
  428. ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs
  429. );
  430. case CAPABILITIES:
  431. return db.update(
  432. ProviderTableMeta.CAPABILITIES_TABLE_NAME, values, selection, selectionArgs
  433. );
  434. case UPLOADS:
  435. int ret = db.update(
  436. ProviderTableMeta.UPLOADS_TABLE_NAME, values, selection, selectionArgs
  437. );
  438. trimSuccessfulUploads(db);
  439. return ret;
  440. default:
  441. return db.update(
  442. ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs
  443. );
  444. }
  445. }
  446. @Override
  447. public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations)
  448. throws OperationApplicationException {
  449. Log_OC.d("FileContentProvider", "applying batch in provider " + this +
  450. " (temporary: " + isTemporary() + ")" );
  451. ContentProviderResult[] results = new ContentProviderResult[operations.size()];
  452. int i=0;
  453. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  454. db.beginTransaction(); // it's supposed that transactions can be nested
  455. try {
  456. for (ContentProviderOperation operation : operations) {
  457. results[i] = operation.apply(this, results, i);
  458. i++;
  459. }
  460. db.setTransactionSuccessful();
  461. } finally {
  462. db.endTransaction();
  463. }
  464. Log_OC.d("FileContentProvider", "applied batch in provider " + this);
  465. return results;
  466. }
  467. class DataBaseHelper extends SQLiteOpenHelper {
  468. public DataBaseHelper(Context context) {
  469. super(context, ProviderMeta.DB_NAME, null, ProviderMeta.DB_VERSION);
  470. }
  471. @Override
  472. public void onCreate(SQLiteDatabase db) {
  473. // files table
  474. Log_OC.i("SQL", "Entering in onCreate");
  475. createFilesTable(db);
  476. // Create ocshares table
  477. createOCSharesTable(db);
  478. // Create capabilities table
  479. createCapabilitiesTable(db);
  480. // Create uploads table
  481. createUploadsTable(db);
  482. }
  483. @Override
  484. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  485. Log_OC.i("SQL", "Entering in onUpgrade");
  486. boolean upgraded = false;
  487. if (oldVersion == 1 && newVersion >= 2) {
  488. Log_OC.i("SQL", "Entering in the #1 ADD in onUpgrade");
  489. db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  490. " ADD COLUMN " + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER " +
  491. " DEFAULT 0");
  492. upgraded = true;
  493. }
  494. if (oldVersion < 3 && newVersion >= 3) {
  495. Log_OC.i("SQL", "Entering in the #2 ADD in onUpgrade");
  496. db.beginTransaction();
  497. try {
  498. db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  499. " ADD COLUMN " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA +
  500. " INTEGER " + " DEFAULT 0");
  501. // assume there are not local changes pending to upload
  502. db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
  503. " SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = "
  504. + System.currentTimeMillis() +
  505. " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
  506. upgraded = true;
  507. db.setTransactionSuccessful();
  508. } finally {
  509. db.endTransaction();
  510. }
  511. }
  512. if (oldVersion < 4 && newVersion >= 4) {
  513. Log_OC.i("SQL", "Entering in the #3 ADD in onUpgrade");
  514. db.beginTransaction();
  515. try {
  516. db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  517. " ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA +
  518. " INTEGER " + " DEFAULT 0");
  519. db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
  520. " SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " +
  521. ProviderTableMeta.FILE_MODIFIED +
  522. " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
  523. upgraded = true;
  524. db.setTransactionSuccessful();
  525. } finally {
  526. db.endTransaction();
  527. }
  528. }
  529. if (!upgraded)
  530. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  531. ", newVersion == " + newVersion);
  532. if (oldVersion < 5 && newVersion >= 5) {
  533. Log_OC.i("SQL", "Entering in the #4 ADD in onUpgrade");
  534. db.beginTransaction();
  535. try {
  536. db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  537. " ADD COLUMN " + ProviderTableMeta.FILE_ETAG + " TEXT " +
  538. " DEFAULT NULL");
  539. upgraded = true;
  540. db.setTransactionSuccessful();
  541. } finally {
  542. db.endTransaction();
  543. }
  544. }
  545. if (!upgraded)
  546. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  547. ", newVersion == " + newVersion);
  548. if (oldVersion < 6 && newVersion >= 6) {
  549. Log_OC.i("SQL", "Entering in the #5 ADD in onUpgrade");
  550. db.beginTransaction();
  551. try {
  552. db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  553. " ADD COLUMN " + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER " +
  554. " DEFAULT 0");
  555. db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  556. " ADD COLUMN " + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT " +
  557. " DEFAULT NULL");
  558. // Create table ocshares
  559. createOCSharesTable(db);
  560. upgraded = true;
  561. db.setTransactionSuccessful();
  562. } finally {
  563. db.endTransaction();
  564. }
  565. }
  566. if (!upgraded)
  567. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  568. ", newVersion == " + newVersion);
  569. if (oldVersion < 7 && newVersion >= 7) {
  570. Log_OC.i("SQL", "Entering in the #7 ADD in onUpgrade");
  571. db.beginTransaction();
  572. try {
  573. db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  574. " ADD COLUMN " + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
  575. " DEFAULT NULL");
  576. db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  577. " ADD COLUMN " + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " +
  578. " DEFAULT NULL");
  579. upgraded = true;
  580. db.setTransactionSuccessful();
  581. } finally {
  582. db.endTransaction();
  583. }
  584. }
  585. if (!upgraded)
  586. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  587. ", newVersion == " + newVersion);
  588. if (oldVersion < 8 && newVersion >= 8) {
  589. Log_OC.i("SQL", "Entering in the #8 ADD in onUpgrade");
  590. db.beginTransaction();
  591. try {
  592. db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  593. " ADD COLUMN " + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER " +
  594. " DEFAULT 0");
  595. upgraded = true;
  596. db.setTransactionSuccessful();
  597. } finally {
  598. db.endTransaction();
  599. }
  600. }
  601. if (!upgraded)
  602. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  603. ", newVersion == " + newVersion);
  604. if (oldVersion < 9 && newVersion >= 9) {
  605. Log_OC.i("SQL", "Entering in the #9 ADD in onUpgrade");
  606. db.beginTransaction();
  607. try {
  608. db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  609. " ADD COLUMN " + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER " +
  610. " DEFAULT 0");
  611. upgraded = true;
  612. db.setTransactionSuccessful();
  613. } finally {
  614. db.endTransaction();
  615. }
  616. }
  617. if (!upgraded)
  618. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  619. ", newVersion == " + newVersion);
  620. if (oldVersion < 10 && newVersion >= 10) {
  621. Log_OC.i("SQL", "Entering in the #10 ADD in onUpgrade");
  622. updateAccountName(db);
  623. upgraded = true;
  624. }
  625. if (!upgraded)
  626. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  627. ", newVersion == " + newVersion);
  628. if (oldVersion < 11 && newVersion >= 11) {
  629. Log_OC.i("SQL", "Entering in the #11 ADD in onUpgrade");
  630. db.beginTransaction();
  631. try {
  632. db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  633. " ADD COLUMN " + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT " +
  634. " DEFAULT NULL");
  635. upgraded = true;
  636. db.setTransactionSuccessful();
  637. } finally {
  638. db.endTransaction();
  639. }
  640. }
  641. if (!upgraded)
  642. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  643. ", newVersion == " + newVersion);
  644. if (oldVersion < 12 && newVersion >= 12) {
  645. Log_OC.i("SQL", "Entering in the #12 ADD in onUpgrade");
  646. db.beginTransaction();
  647. try {
  648. db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
  649. " ADD COLUMN " + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER " +
  650. " DEFAULT 0");
  651. upgraded = true;
  652. db.setTransactionSuccessful();
  653. } finally {
  654. db.endTransaction();
  655. }
  656. }
  657. if (!upgraded)
  658. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  659. ", newVersion == " + newVersion);
  660. if (oldVersion < 13 && newVersion >= 13) {
  661. Log_OC.i("SQL", "Entering in the #13 ADD in onUpgrade");
  662. db.beginTransaction();
  663. try {
  664. // Create capabilities table
  665. createCapabilitiesTable(db);
  666. upgraded = true;
  667. db.setTransactionSuccessful();
  668. } finally {
  669. db.endTransaction();
  670. }
  671. }
  672. if (oldVersion < 14 && newVersion >= 14) {
  673. Log_OC.i("SQL", "Entering in the #14 ADD in onUpgrade");
  674. db.beginTransaction();
  675. try {
  676. // drop old instant_upload table
  677. db.execSQL("DROP TABLE IF EXISTS " + "instant_upload" + ";");
  678. // Create uploads table
  679. createUploadsTable(db);
  680. upgraded = true;
  681. db.setTransactionSuccessful();
  682. } finally {
  683. db.endTransaction();
  684. }
  685. }
  686. if (!upgraded)
  687. Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
  688. ", newVersion == " + newVersion);
  689. }
  690. }
  691. private void createFilesTable(SQLiteDatabase db){
  692. db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "("
  693. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  694. + ProviderTableMeta.FILE_NAME + " TEXT, "
  695. + ProviderTableMeta.FILE_PATH + " TEXT, "
  696. + ProviderTableMeta.FILE_PARENT + " INTEGER, "
  697. + ProviderTableMeta.FILE_CREATION + " INTEGER, "
  698. + ProviderTableMeta.FILE_MODIFIED + " INTEGER, "
  699. + ProviderTableMeta.FILE_CONTENT_TYPE + " TEXT, "
  700. + ProviderTableMeta.FILE_CONTENT_LENGTH + " INTEGER, "
  701. + ProviderTableMeta.FILE_STORAGE_PATH + " TEXT, "
  702. + ProviderTableMeta.FILE_ACCOUNT_OWNER + " TEXT, "
  703. + ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, "
  704. + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, "
  705. + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, "
  706. + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, "
  707. + ProviderTableMeta.FILE_ETAG + " TEXT, "
  708. + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER, "
  709. + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, "
  710. + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
  711. + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null,"
  712. + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER," //boolean
  713. + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER," //boolean
  714. + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT,"
  715. + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER);"
  716. );
  717. }
  718. private void createOCSharesTable(SQLiteDatabase db) {
  719. // Create ocshares table
  720. db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
  721. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  722. + ProviderTableMeta.OCSHARES_FILE_SOURCE + " INTEGER, "
  723. + ProviderTableMeta.OCSHARES_ITEM_SOURCE + " INTEGER, "
  724. + ProviderTableMeta.OCSHARES_SHARE_TYPE + " INTEGER, "
  725. + ProviderTableMeta.OCSHARES_SHARE_WITH + " TEXT, "
  726. + ProviderTableMeta.OCSHARES_PATH + " TEXT, "
  727. + ProviderTableMeta.OCSHARES_PERMISSIONS+ " INTEGER, "
  728. + ProviderTableMeta.OCSHARES_SHARED_DATE + " INTEGER, "
  729. + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + " INTEGER, "
  730. + ProviderTableMeta.OCSHARES_TOKEN + " TEXT, "
  731. + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, "
  732. + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, " // boolean
  733. + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, "
  734. + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER,"
  735. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" );
  736. }
  737. private void createCapabilitiesTable(SQLiteDatabase db){
  738. // Create capabilities table
  739. db.execSQL("CREATE TABLE " + ProviderTableMeta.CAPABILITIES_TABLE_NAME + "("
  740. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  741. + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + " TEXT, "
  742. + ProviderTableMeta.CAPABILITIES_VERSION_MAYOR + " INTEGER, "
  743. + ProviderTableMeta.CAPABILITIES_VERSION_MINOR + " INTEGER, "
  744. + ProviderTableMeta.CAPABILITIES_VERSION_MICRO + " INTEGER, "
  745. + ProviderTableMeta.CAPABILITIES_VERSION_STRING + " TEXT, "
  746. + ProviderTableMeta.CAPABILITIES_VERSION_EDITION + " TEXT, "
  747. + ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL + " INTEGER, "
  748. + ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED + " INTEGER, " // boolean
  749. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED + " INTEGER, " // boolean
  750. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED + " INTEGER, " // boolean
  751. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED + " INTEGER, " // boolean
  752. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS + " INTEGER, "
  753. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED + " INTEGER, " // boolean
  754. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL + " INTEGER, " // boolean
  755. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD + " INTEGER, " // boolean
  756. + ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL + " INTEGER, " // boolean
  757. + ProviderTableMeta.CAPABILITIES_SHARING_RESHARING + " INTEGER, " // boolean
  758. + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING + " INTEGER, " // boolean
  759. + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING + " INTEGER, " // boolean
  760. + ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING + " INTEGER, " // boolean
  761. + ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + " INTEGER, " // boolean
  762. + ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + " INTEGER );" ); // boolean
  763. }
  764. private void createUploadsTable(SQLiteDatabase db){
  765. // Create uploads table
  766. db.execSQL("CREATE TABLE " + ProviderTableMeta.UPLOADS_TABLE_NAME + "("
  767. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  768. + ProviderTableMeta.UPLOADS_LOCAL_PATH + " TEXT, "
  769. + ProviderTableMeta.UPLOADS_REMOTE_PATH + " TEXT, "
  770. + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + " TEXT, "
  771. + ProviderTableMeta.UPLOADS_FILE_SIZE + " LONG, "
  772. + ProviderTableMeta.UPLOADS_STATUS + " INTEGER, " // UploadStatus
  773. + ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + " INTEGER, " // Upload LocalBehaviour
  774. + ProviderTableMeta.UPLOADS_UPLOAD_TIME + " INTEGER, "
  775. + ProviderTableMeta.UPLOADS_FORCE_OVERWRITE + " INTEGER, " // boolean
  776. + ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + " INTEGER, " // boolean
  777. + ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + " INTEGER, "
  778. + ProviderTableMeta.UPLOADS_LAST_RESULT + " INTEGER, " // Upload LastResult
  779. + ProviderTableMeta.UPLOADS_CREATED_BY + " INTEGER );" // Upload createdBy
  780. );
  781. /* before:
  782. // PRIMARY KEY should always imply NOT NULL. Unfortunately, due to a
  783. // bug in some early versions, this is not the case in SQLite.
  784. //db.execSQL("CREATE TABLE " + TABLE_UPLOAD + " (" + " path TEXT PRIMARY KEY NOT NULL UNIQUE,"
  785. // + " uploadStatus INTEGER NOT NULL, uploadObject TEXT NOT NULL);");
  786. // uploadStatus is used to easy filtering, it has precedence over
  787. // uploadObject.getUploadStatus()
  788. */
  789. }
  790. /**
  791. * Version 10 of database does not modify its scheme. It coincides with the upgrade of the ownCloud account names
  792. * structure to include in it the path to the server instance. Updating the account names and path to local files
  793. * in the files table is a must to keep the existing account working and the database clean.
  794. *
  795. * See {@link com.owncloud.android.authentication.AccountUtils#updateAccountVersion(android.content.Context)}
  796. *
  797. * @param db Database where table of files is included.
  798. */
  799. private void updateAccountName(SQLiteDatabase db){
  800. Log_OC.d("SQL", "THREAD: " + Thread.currentThread().getName());
  801. AccountManager ama = AccountManager.get(getContext());
  802. try {
  803. // get accounts from AccountManager ; we can't be sure if accounts in it are updated or not although
  804. // we know the update was previously done in {link @FileActivity#onCreate} because the changes through
  805. // AccountManager are not synchronous
  806. Account[] accounts = AccountManager.get(getContext()).getAccountsByType(
  807. MainApp.getAccountType());
  808. String serverUrl, username, oldAccountName, newAccountName;
  809. for (Account account : accounts) {
  810. // build both old and new account name
  811. serverUrl = ama.getUserData(account, AccountUtils.Constants.KEY_OC_BASE_URL);
  812. username = AccountUtils.getUsernameForAccount(account);
  813. oldAccountName = AccountUtils.buildAccountNameOld(Uri.parse(serverUrl), username);
  814. newAccountName = AccountUtils.buildAccountName(Uri.parse(serverUrl), username);
  815. // update values in database
  816. db.beginTransaction();
  817. try {
  818. ContentValues cv = new ContentValues();
  819. cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, newAccountName);
  820. int num = db.update(ProviderTableMeta.FILE_TABLE_NAME,
  821. cv,
  822. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
  823. new String[]{oldAccountName});
  824. Log_OC.d("SQL", "Updated account in database: old name == " + oldAccountName +
  825. ", new name == " + newAccountName + " (" + num + " rows updated )");
  826. // update path for downloaded files
  827. updateDownloadedFiles(db, newAccountName, oldAccountName);
  828. db.setTransactionSuccessful();
  829. } catch (SQLException e) {
  830. Log_OC.e(TAG, "SQL Exception upgrading account names or paths in database", e);
  831. } finally {
  832. db.endTransaction();
  833. }
  834. }
  835. } catch (Exception e) {
  836. Log_OC.e(TAG, "Exception upgrading account names or paths in database", e);
  837. }
  838. }
  839. /**
  840. * Rename the local ownCloud folder of one account to match the a rename of the account itself. Updates the
  841. * table of files in database so that the paths to the local files keep being the same.
  842. *
  843. * @param db Database where table of files is included.
  844. * @param newAccountName New name for the target OC account.
  845. * @param oldAccountName Old name of the target OC account.
  846. */
  847. private void updateDownloadedFiles(SQLiteDatabase db, String newAccountName,
  848. String oldAccountName) {
  849. String whereClause = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  850. ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL";
  851. Cursor c = db.query(ProviderTableMeta.FILE_TABLE_NAME,
  852. null,
  853. whereClause,
  854. new String[]{newAccountName},
  855. null, null, null);
  856. try {
  857. if (c.moveToFirst()) {
  858. // create storage path
  859. String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
  860. String newAccountPath = FileStorageUtils.getSavePath(newAccountName);
  861. // move files
  862. File oldAccountFolder = new File(oldAccountPath);
  863. File newAccountFolder = new File(newAccountPath);
  864. oldAccountFolder.renameTo(newAccountFolder);
  865. // update database
  866. do {
  867. // Update database
  868. String oldPath = c.getString(
  869. c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
  870. OCFile file = new OCFile(
  871. c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH)));
  872. String newPath = FileStorageUtils.getDefaultSavePathFor(newAccountName, file);
  873. ContentValues cv = new ContentValues();
  874. cv.put(ProviderTableMeta.FILE_STORAGE_PATH, newPath);
  875. db.update(ProviderTableMeta.FILE_TABLE_NAME,
  876. cv,
  877. ProviderTableMeta.FILE_STORAGE_PATH + "=?",
  878. new String[]{oldPath});
  879. Log_OC.v("SQL", "Updated path of downloaded file: old file name == " + oldPath +
  880. ", new file name == " + newPath);
  881. } while (c.moveToNext());
  882. }
  883. } finally {
  884. c.close();
  885. }
  886. }
  887. /**
  888. * Grants that total count of successful uploads stored is not greater than MAX_SUCCESSFUL_UPLOADS.
  889. *
  890. * Removes older uploads if needed.
  891. */
  892. private void trimSuccessfulUploads(SQLiteDatabase db) {
  893. Cursor c = null;
  894. try {
  895. c = db.rawQuery(
  896. "delete from " + ProviderTableMeta.UPLOADS_TABLE_NAME +
  897. " where " + ProviderTableMeta.UPLOADS_STATUS + " == "
  898. + UploadsStorageManager.UploadStatus.UPLOAD_SUCCEEDED.getValue() +
  899. " and " + ProviderTableMeta._ID +
  900. " not in (select " + ProviderTableMeta._ID +
  901. " from " + ProviderTableMeta.UPLOADS_TABLE_NAME +
  902. " where " + ProviderTableMeta.UPLOADS_STATUS + " == "
  903. + UploadsStorageManager.UploadStatus.UPLOAD_SUCCEEDED.getValue() +
  904. " order by " + ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP +
  905. " desc limit " + MAX_SUCCESSFUL_UPLOADS +
  906. ")",
  907. null
  908. );
  909. c.moveToFirst(); // do something with the cursor, or deletion doesn't happen; true story
  910. } catch (Exception e) {
  911. Log_OC.e(
  912. TAG,
  913. "Something wrong trimming successful uploads, database could grow more than expected",
  914. e
  915. );
  916. } finally {
  917. if (c!= null) {
  918. c.close();
  919. }
  920. }
  921. }
  922. }