FileContentProvider.java 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  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. package com.owncloud.android.providers;
  23. import android.accounts.Account;
  24. import android.accounts.AccountManager;
  25. import android.content.ContentProvider;
  26. import android.content.ContentProviderOperation;
  27. import android.content.ContentProviderResult;
  28. import android.content.ContentUris;
  29. import android.content.ContentValues;
  30. import android.content.Context;
  31. import android.content.OperationApplicationException;
  32. import android.content.UriMatcher;
  33. import android.database.Cursor;
  34. import android.database.SQLException;
  35. import android.database.sqlite.SQLiteDatabase;
  36. import android.database.sqlite.SQLiteOpenHelper;
  37. import android.database.sqlite.SQLiteQueryBuilder;
  38. import android.net.Uri;
  39. import android.text.TextUtils;
  40. import com.owncloud.android.MainApp;
  41. import com.owncloud.android.R;
  42. import com.owncloud.android.datamodel.OCFile;
  43. import com.owncloud.android.db.PreferenceManager;
  44. import com.owncloud.android.db.ProviderMeta;
  45. import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
  46. import com.owncloud.android.lib.common.accounts.AccountUtils;
  47. import com.owncloud.android.lib.common.utils.Log_OC;
  48. import com.owncloud.android.lib.resources.shares.ShareType;
  49. import com.owncloud.android.ui.activity.FileDisplayActivity;
  50. import com.owncloud.android.utils.FileStorageUtils;
  51. import com.owncloud.android.utils.MimeType;
  52. import java.io.File;
  53. import java.util.ArrayList;
  54. import java.util.Locale;
  55. /**
  56. * The ContentProvider for the ownCloud App.
  57. */
  58. @SuppressWarnings("PMD.AvoidDuplicateLiterals")
  59. public class FileContentProvider extends ContentProvider {
  60. private DataBaseHelper mDbHelper;
  61. private static final int SINGLE_FILE = 1;
  62. private static final int DIRECTORY = 2;
  63. private static final int ROOT_DIRECTORY = 3;
  64. private static final int SHARES = 4;
  65. private static final int CAPABILITIES = 5;
  66. private static final int UPLOADS = 6;
  67. private static final int SYNCED_FOLDERS = 7;
  68. private static final int EXTERNAL_LINKS = 8;
  69. private static final int ARBITRARY_DATA = 9;
  70. private static final int VIRTUAL = 10;
  71. private static final int FILESYSTEM = 11;
  72. private static final String TAG = FileContentProvider.class.getSimpleName();
  73. private UriMatcher mUriMatcher;
  74. // todo avoid string concatenation and use string formatting instead later.
  75. private static final String ERROR = "ERROR ";
  76. private static final String SQL = "SQL";
  77. private static final String INTEGER = " INTEGER, ";
  78. private static final String TEXT = " TEXT, ";
  79. private static final String ALTER_TABLE = "ALTER TABLE ";
  80. private static final String ADD_COLUMN = " ADD COLUMN ";
  81. private static final String UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";
  82. @Override
  83. public int delete(Uri uri, String where, String[] whereArgs) {
  84. //Log_OC.d(TAG, "Deleting " + uri + " at provider " + this);
  85. int count = 0;
  86. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  87. db.beginTransaction();
  88. try {
  89. count = delete(db, uri, where, whereArgs);
  90. db.setTransactionSuccessful();
  91. } finally {
  92. db.endTransaction();
  93. }
  94. getContext().getContentResolver().notifyChange(uri, null);
  95. return count;
  96. }
  97. private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) {
  98. int count = 0;
  99. switch (mUriMatcher.match(uri)) {
  100. case SINGLE_FILE:
  101. Cursor c = query(db, uri, null, where, whereArgs, null);
  102. String remoteId = "";
  103. try {
  104. if (c != null && c.moveToFirst()) {
  105. remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
  106. //ThumbnailsCacheManager.removeFileFromCache(remoteId);
  107. }
  108. Log_OC.d(TAG, "Removing FILE " + remoteId);
  109. count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
  110. ProviderTableMeta._ID
  111. + "="
  112. + uri.getPathSegments().get(1)
  113. + (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""),
  114. whereArgs);
  115. } catch (Exception e) {
  116. Log_OC.d(TAG, "DB-Error removing file!", e);
  117. } finally {
  118. if (c != null) {
  119. c.close();
  120. }
  121. }
  122. break;
  123. case DIRECTORY:
  124. // deletion of folder is recursive
  125. /*
  126. Uri folderUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, Long.parseLong(uri.getPathSegments().get(1)));
  127. Cursor folder = query(db, folderUri, null, null, null, null);
  128. String folderName = "(unknown)";
  129. if (folder != null && folder.moveToFirst()) {
  130. folderName = folder.getString(folder.getColumnIndex(ProviderTableMeta.FILE_PATH));
  131. }
  132. */
  133. Cursor children = query(uri, null, null, null, null);
  134. if (children != null && children.moveToFirst()) {
  135. long childId;
  136. boolean isDir;
  137. while (!children.isAfterLast()) {
  138. childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
  139. isDir = MimeType.DIRECTORY.equals(children.getString(
  140. children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
  141. ));
  142. //remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH));
  143. if (isDir) {
  144. count += delete(
  145. db,
  146. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
  147. null,
  148. null
  149. );
  150. } else {
  151. count += delete(
  152. db,
  153. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
  154. null,
  155. null
  156. );
  157. }
  158. children.moveToNext();
  159. }
  160. children.close();
  161. } /*else {
  162. Log_OC.d(TAG, "No child to remove in DIRECTORY " + folderName);
  163. }
  164. Log_OC.d(TAG, "Removing DIRECTORY " + folderName + " (or maybe not) ");
  165. */
  166. count += db.delete(ProviderTableMeta.FILE_TABLE_NAME,
  167. ProviderTableMeta._ID
  168. + "="
  169. + uri.getPathSegments().get(1)
  170. + (!TextUtils.isEmpty(where) ? " AND (" + where
  171. + ")" : ""), whereArgs);
  172. /* Just for log
  173. if (folder != null) {
  174. folder.close();
  175. }*/
  176. break;
  177. case ROOT_DIRECTORY:
  178. //Log_OC.d(TAG, "Removing ROOT!");
  179. count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs);
  180. break;
  181. case SHARES:
  182. count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs);
  183. break;
  184. case CAPABILITIES:
  185. count = db.delete(ProviderTableMeta.CAPABILITIES_TABLE_NAME, where, whereArgs);
  186. break;
  187. case UPLOADS:
  188. count = db.delete(ProviderTableMeta.UPLOADS_TABLE_NAME, where, whereArgs);
  189. break;
  190. case SYNCED_FOLDERS:
  191. count = db.delete(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, where, whereArgs);
  192. break;
  193. case EXTERNAL_LINKS:
  194. count = db.delete(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, where, whereArgs);
  195. break;
  196. case ARBITRARY_DATA:
  197. count = db.delete(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, where, whereArgs);
  198. break;
  199. case VIRTUAL:
  200. count = db.delete(ProviderTableMeta.VIRTUAL_TABLE_NAME, where, whereArgs);
  201. break;
  202. case FILESYSTEM:
  203. count = db.delete(ProviderTableMeta.FILESYSTEM_TABLE_NAME, where, whereArgs);
  204. break;
  205. default:
  206. //Log_OC.e(TAG, "Unknown uri " + uri);
  207. throw new IllegalArgumentException("Unknown uri: " + uri.toString());
  208. }
  209. return count;
  210. }
  211. @Override
  212. public String getType(Uri uri) {
  213. switch (mUriMatcher.match(uri)) {
  214. case ROOT_DIRECTORY:
  215. return ProviderTableMeta.CONTENT_TYPE;
  216. case SINGLE_FILE:
  217. return ProviderTableMeta.CONTENT_TYPE_ITEM;
  218. default:
  219. throw new IllegalArgumentException("Unknown Uri id."
  220. + uri.toString());
  221. }
  222. }
  223. @Override
  224. public Uri insert(Uri uri, ContentValues values) {
  225. Uri newUri = null;
  226. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  227. db.beginTransaction();
  228. try {
  229. newUri = insert(db, uri, values);
  230. db.setTransactionSuccessful();
  231. } finally {
  232. db.endTransaction();
  233. }
  234. getContext().getContentResolver().notifyChange(newUri, null);
  235. return newUri;
  236. }
  237. private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) {
  238. switch (mUriMatcher.match(uri)) {
  239. case ROOT_DIRECTORY:
  240. case SINGLE_FILE:
  241. String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
  242. String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
  243. String[] projection = new String[]{
  244. ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH,
  245. ProviderTableMeta.FILE_ACCOUNT_OWNER
  246. };
  247. String where = ProviderTableMeta.FILE_PATH + "=? AND " +
  248. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
  249. String[] whereArgs = new String[]{remotePath, accountName};
  250. Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
  251. // ugly patch; serious refactorization is needed to reduce work in
  252. // FileDataStorageManager and bring it to FileContentProvider
  253. if (doubleCheck == null || !doubleCheck.moveToFirst()) {
  254. if (doubleCheck != null) {
  255. doubleCheck.close();
  256. }
  257. long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
  258. if (rowId > 0) {
  259. return ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
  260. } else {
  261. throw new SQLException(ERROR + uri);
  262. }
  263. } else {
  264. // file is already inserted; race condition, let's avoid a duplicated entry
  265. Uri insertedFileUri = ContentUris.withAppendedId(
  266. ProviderTableMeta.CONTENT_URI_FILE,
  267. doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID))
  268. );
  269. doubleCheck.close();
  270. return insertedFileUri;
  271. }
  272. case SHARES:
  273. Uri insertedShareUri = null;
  274. long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
  275. if (rowId > 0) {
  276. insertedShareUri =
  277. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId);
  278. } else {
  279. throw new SQLException(ERROR + uri);
  280. }
  281. updateFilesTableAccordingToShareInsertion(db, values);
  282. return insertedShareUri;
  283. case CAPABILITIES:
  284. Uri insertedCapUri = null;
  285. long id = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, null, values);
  286. if (id > 0) {
  287. insertedCapUri =
  288. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_CAPABILITIES, id);
  289. } else {
  290. throw new SQLException(ERROR + uri);
  291. }
  292. return insertedCapUri;
  293. case UPLOADS:
  294. Uri insertedUploadUri = null;
  295. long uploadId = db.insert(ProviderTableMeta.UPLOADS_TABLE_NAME, null, values);
  296. if (uploadId > 0) {
  297. insertedUploadUri =
  298. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_UPLOADS, uploadId);
  299. } else {
  300. throw new SQLException(ERROR + uri);
  301. }
  302. return insertedUploadUri;
  303. case SYNCED_FOLDERS:
  304. Uri insertedSyncedFolderUri = null;
  305. long syncedFolderId = db.insert(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, null, values);
  306. if (syncedFolderId > 0) {
  307. insertedSyncedFolderUri =
  308. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS, syncedFolderId);
  309. } else {
  310. throw new SQLException("ERROR " + uri);
  311. }
  312. return insertedSyncedFolderUri;
  313. case EXTERNAL_LINKS:
  314. Uri insertedExternalLinkUri = null;
  315. long externalLinkId = db.insert(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, null, values);
  316. if (externalLinkId > 0) {
  317. insertedExternalLinkUri =
  318. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_EXTERNAL_LINKS, externalLinkId);
  319. } else {
  320. throw new SQLException("ERROR " + uri);
  321. }
  322. return insertedExternalLinkUri;
  323. case ARBITRARY_DATA:
  324. Uri insertedArbitraryDataUri = null;
  325. long arbitraryDataId = db.insert(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, null, values);
  326. if (arbitraryDataId > 0) {
  327. insertedArbitraryDataUri =
  328. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, arbitraryDataId);
  329. } else {
  330. throw new SQLException("ERROR " + uri);
  331. }
  332. return insertedArbitraryDataUri;
  333. case VIRTUAL:
  334. Uri insertedVirtualUri;
  335. long virtualId = db.insert(ProviderTableMeta.VIRTUAL_TABLE_NAME, null, values);
  336. if (virtualId > 0) {
  337. insertedVirtualUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_VIRTUAL, virtualId);
  338. } else {
  339. throw new SQLException("ERROR " + uri);
  340. }
  341. return insertedVirtualUri;
  342. case FILESYSTEM:
  343. Uri insertedFilesystemUri = null;
  344. long filesystedId = db.insert(ProviderTableMeta.FILESYSTEM_TABLE_NAME, null, values);
  345. if (filesystedId > 0) {
  346. insertedFilesystemUri =
  347. ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILESYSTEM, filesystedId);
  348. } else {
  349. throw new SQLException("ERROR " + uri);
  350. }
  351. return insertedFilesystemUri;
  352. default:
  353. throw new IllegalArgumentException("Unknown uri id: " + uri);
  354. }
  355. }
  356. private void updateFilesTableAccordingToShareInsertion(
  357. SQLiteDatabase db, ContentValues newShare
  358. ) {
  359. ContentValues fileValues = new ContentValues();
  360. int newShareType = newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE);
  361. if (newShareType == ShareType.PUBLIC_LINK.getValue()) {
  362. fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1);
  363. } else if (
  364. newShareType == ShareType.USER.getValue() ||
  365. newShareType == ShareType.GROUP.getValue() ||
  366. newShareType == ShareType.EMAIL.getValue() ||
  367. newShareType == ShareType.FEDERATED.getValue()) {
  368. fileValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, 1);
  369. }
  370. String where = ProviderTableMeta.FILE_PATH + "=? AND " +
  371. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
  372. String[] whereArgs = new String[]{
  373. newShare.getAsString(ProviderTableMeta.OCSHARES_PATH),
  374. newShare.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)
  375. };
  376. db.update(ProviderTableMeta.FILE_TABLE_NAME, fileValues, where, whereArgs);
  377. }
  378. @Override
  379. public boolean onCreate() {
  380. mDbHelper = new DataBaseHelper(getContext());
  381. String authority = getContext().getResources().getString(R.string.authority);
  382. mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  383. mUriMatcher.addURI(authority, null, ROOT_DIRECTORY);
  384. mUriMatcher.addURI(authority, "file/", SINGLE_FILE);
  385. mUriMatcher.addURI(authority, "file/#", SINGLE_FILE);
  386. mUriMatcher.addURI(authority, "dir/", DIRECTORY);
  387. mUriMatcher.addURI(authority, "dir/#", DIRECTORY);
  388. mUriMatcher.addURI(authority, "shares/", SHARES);
  389. mUriMatcher.addURI(authority, "shares/#", SHARES);
  390. mUriMatcher.addURI(authority, "capabilities/", CAPABILITIES);
  391. mUriMatcher.addURI(authority, "capabilities/#", CAPABILITIES);
  392. mUriMatcher.addURI(authority, "uploads/", UPLOADS);
  393. mUriMatcher.addURI(authority, "uploads/#", UPLOADS);
  394. mUriMatcher.addURI(authority, "synced_folders", SYNCED_FOLDERS);
  395. mUriMatcher.addURI(authority, "external_links", EXTERNAL_LINKS);
  396. mUriMatcher.addURI(authority, "arbitrary_data", ARBITRARY_DATA);
  397. mUriMatcher.addURI(authority, "virtual", VIRTUAL);
  398. mUriMatcher.addURI(authority, "filesystem", FILESYSTEM);
  399. return true;
  400. }
  401. @Override
  402. public Cursor query(
  403. Uri uri,
  404. String[] projection,
  405. String selection,
  406. String[] selectionArgs,
  407. String sortOrder
  408. ) {
  409. Cursor result = null;
  410. SQLiteDatabase db = mDbHelper.getReadableDatabase();
  411. db.beginTransaction();
  412. try {
  413. result = query(db, uri, projection, selection, selectionArgs, sortOrder);
  414. db.setTransactionSuccessful();
  415. } finally {
  416. db.endTransaction();
  417. }
  418. return result;
  419. }
  420. private Cursor query(
  421. SQLiteDatabase db,
  422. Uri uri,
  423. String[] projection,
  424. String selection,
  425. String[] selectionArgs,
  426. String sortOrder
  427. ) {
  428. SQLiteQueryBuilder sqlQuery = new SQLiteQueryBuilder();
  429. sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME);
  430. switch (mUriMatcher.match(uri)) {
  431. case ROOT_DIRECTORY:
  432. break;
  433. case DIRECTORY:
  434. String folderId = uri.getPathSegments().get(1);
  435. sqlQuery.appendWhere(ProviderTableMeta.FILE_PARENT + "="
  436. + folderId);
  437. break;
  438. case SINGLE_FILE:
  439. if (uri.getPathSegments().size() > 1) {
  440. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  441. + uri.getPathSegments().get(1));
  442. }
  443. break;
  444. case SHARES:
  445. sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME);
  446. if (uri.getPathSegments().size() > 1) {
  447. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  448. + uri.getPathSegments().get(1));
  449. }
  450. break;
  451. case CAPABILITIES:
  452. sqlQuery.setTables(ProviderTableMeta.CAPABILITIES_TABLE_NAME);
  453. if (uri.getPathSegments().size() > 1) {
  454. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  455. + uri.getPathSegments().get(1));
  456. }
  457. break;
  458. case UPLOADS:
  459. sqlQuery.setTables(ProviderTableMeta.UPLOADS_TABLE_NAME);
  460. if (uri.getPathSegments().size() > 1) {
  461. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  462. + uri.getPathSegments().get(1));
  463. }
  464. break;
  465. case SYNCED_FOLDERS:
  466. sqlQuery.setTables(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME);
  467. if (uri.getPathSegments().size() > 1) {
  468. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  469. + uri.getPathSegments().get(1));
  470. }
  471. break;
  472. case EXTERNAL_LINKS:
  473. sqlQuery.setTables(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME);
  474. if (uri.getPathSegments().size() > 1) {
  475. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  476. + uri.getPathSegments().get(1));
  477. }
  478. break;
  479. case ARBITRARY_DATA:
  480. sqlQuery.setTables(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME);
  481. if (uri.getPathSegments().size() > 1) {
  482. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  483. + uri.getPathSegments().get(1));
  484. }
  485. break;
  486. case VIRTUAL:
  487. sqlQuery.setTables(ProviderTableMeta.VIRTUAL_TABLE_NAME);
  488. if (uri.getPathSegments().size() > 1) {
  489. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  490. }
  491. break;
  492. case FILESYSTEM:
  493. sqlQuery.setTables(ProviderTableMeta.FILESYSTEM_TABLE_NAME);
  494. if (uri.getPathSegments().size() > 1) {
  495. sqlQuery.appendWhere(ProviderTableMeta._ID + "="
  496. + uri.getPathSegments().get(1));
  497. }
  498. break;
  499. default:
  500. throw new IllegalArgumentException("Unknown uri id: " + uri);
  501. }
  502. String order;
  503. if (TextUtils.isEmpty(sortOrder)) {
  504. switch (mUriMatcher.match(uri)) {
  505. case SHARES:
  506. order = ProviderTableMeta.OCSHARES_DEFAULT_SORT_ORDER;
  507. break;
  508. case CAPABILITIES:
  509. order = ProviderTableMeta.CAPABILITIES_DEFAULT_SORT_ORDER;
  510. break;
  511. case UPLOADS:
  512. order = ProviderTableMeta.UPLOADS_DEFAULT_SORT_ORDER;
  513. break;
  514. case SYNCED_FOLDERS:
  515. order = ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH;
  516. break;
  517. case EXTERNAL_LINKS:
  518. order = ProviderTableMeta.EXTERNAL_LINKS_NAME;
  519. break;
  520. case ARBITRARY_DATA:
  521. order = ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID;
  522. break;
  523. case VIRTUAL:
  524. order = ProviderTableMeta.VIRTUAL_TYPE;
  525. break;
  526. default: // Files
  527. order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
  528. break;
  529. case FILESYSTEM:
  530. order = ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH;
  531. break;
  532. }
  533. } else {
  534. order = sortOrder;
  535. }
  536. // DB case_sensitive
  537. db.execSQL("PRAGMA case_sensitive_like = true");
  538. Cursor c = sqlQuery.query(db, projection, selection, selectionArgs, null, null, order);
  539. c.setNotificationUri(getContext().getContentResolver(), uri);
  540. return c;
  541. }
  542. @Override
  543. public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
  544. int count = 0;
  545. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  546. db.beginTransaction();
  547. try {
  548. count = update(db, uri, values, selection, selectionArgs);
  549. db.setTransactionSuccessful();
  550. } finally {
  551. db.endTransaction();
  552. }
  553. getContext().getContentResolver().notifyChange(uri, null);
  554. return count;
  555. }
  556. private int update(
  557. SQLiteDatabase db,
  558. Uri uri,
  559. ContentValues values,
  560. String selection,
  561. String[] selectionArgs
  562. ) {
  563. switch (mUriMatcher.match(uri)) {
  564. case DIRECTORY:
  565. return 0; //updateFolderSize(db, selectionArgs[0]);
  566. case SHARES:
  567. return db.update(ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs);
  568. case CAPABILITIES:
  569. return db.update(ProviderTableMeta.CAPABILITIES_TABLE_NAME, values, selection, selectionArgs);
  570. case UPLOADS:
  571. int ret = db.update(ProviderTableMeta.UPLOADS_TABLE_NAME, values, selection, selectionArgs);
  572. return ret;
  573. case SYNCED_FOLDERS:
  574. return db.update(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, values, selection, selectionArgs);
  575. case ARBITRARY_DATA:
  576. return db.update(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, values, selection, selectionArgs);
  577. case FILESYSTEM:
  578. return db.update(ProviderTableMeta.FILESYSTEM_TABLE_NAME, values, selection, selectionArgs);
  579. default:
  580. return db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs);
  581. }
  582. }
  583. @Override
  584. public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
  585. throws OperationApplicationException {
  586. Log_OC.d("FileContentProvider", "applying batch in provider " + this +
  587. " (temporary: " + isTemporary() + ")");
  588. ContentProviderResult[] results = new ContentProviderResult[operations.size()];
  589. int i = 0;
  590. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  591. db.beginTransaction(); // it's supposed that transactions can be nested
  592. try {
  593. for (ContentProviderOperation operation : operations) {
  594. results[i] = operation.apply(this, results, i);
  595. i++;
  596. }
  597. db.setTransactionSuccessful();
  598. } finally {
  599. db.endTransaction();
  600. }
  601. Log_OC.d("FileContentProvider", "applied batch in provider " + this);
  602. return results;
  603. }
  604. class DataBaseHelper extends SQLiteOpenHelper {
  605. public DataBaseHelper(Context context) {
  606. super(context, ProviderMeta.DB_NAME, null, ProviderMeta.DB_VERSION);
  607. }
  608. @Override
  609. public void onCreate(SQLiteDatabase db) {
  610. // files table
  611. Log_OC.i(SQL, "Entering in onCreate");
  612. createFilesTable(db);
  613. // Create ocshares table
  614. createOCSharesTable(db);
  615. // Create capabilities table
  616. createCapabilitiesTable(db);
  617. // Create uploads table
  618. createUploadsTable(db);
  619. // Create synced folders table
  620. createSyncedFoldersTable(db);
  621. // Create external links table
  622. createExternalLinksTable(db);
  623. // Create arbitrary data table
  624. createArbitraryData(db);
  625. // Create virtual table
  626. createVirtualTable(db);
  627. // Create filesystem table
  628. createFileSystemTable(db);
  629. PreferenceManager.getDefaultSharedPreferences(getContext()).edit()
  630. .putBoolean(FileDisplayActivity.KEY_SHOW_ACCOUNT_WARNING, false).apply();
  631. }
  632. @Override
  633. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  634. Log_OC.i(SQL, "Entering in onUpgrade");
  635. boolean upgraded = false;
  636. if (oldVersion == 1 && newVersion >= 2) {
  637. Log_OC.i(SQL, "Entering in the #2 ADD in onUpgrade");
  638. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  639. ADD_COLUMN + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER " +
  640. " DEFAULT 0");
  641. upgraded = true;
  642. }
  643. if (oldVersion < 3 && newVersion >= 3) {
  644. Log_OC.i(SQL, "Entering in the #3 ADD in onUpgrade");
  645. db.beginTransaction();
  646. try {
  647. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  648. ADD_COLUMN + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA +
  649. " INTEGER " + " DEFAULT 0");
  650. // assume there are not local changes pending to upload
  651. db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
  652. " SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = "
  653. + System.currentTimeMillis() +
  654. " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
  655. upgraded = true;
  656. db.setTransactionSuccessful();
  657. } finally {
  658. db.endTransaction();
  659. }
  660. }
  661. if (oldVersion < 4 && newVersion >= 4) {
  662. Log_OC.i(SQL, "Entering in the #4 ADD in onUpgrade");
  663. db.beginTransaction();
  664. try {
  665. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  666. ADD_COLUMN + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA +
  667. " INTEGER " + " DEFAULT 0");
  668. db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
  669. " SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " +
  670. ProviderTableMeta.FILE_MODIFIED +
  671. " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
  672. upgraded = true;
  673. db.setTransactionSuccessful();
  674. } finally {
  675. db.endTransaction();
  676. }
  677. }
  678. if (!upgraded) {
  679. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  680. }
  681. if (oldVersion < 5 && newVersion >= 5) {
  682. Log_OC.i(SQL, "Entering in the #5 ADD in onUpgrade");
  683. db.beginTransaction();
  684. try {
  685. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  686. ADD_COLUMN + ProviderTableMeta.FILE_ETAG + " TEXT " +
  687. " DEFAULT NULL");
  688. upgraded = true;
  689. db.setTransactionSuccessful();
  690. } finally {
  691. db.endTransaction();
  692. }
  693. }
  694. if (!upgraded) {
  695. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  696. }
  697. if (oldVersion < 6 && newVersion >= 6) {
  698. Log_OC.i(SQL, "Entering in the #6 ADD in onUpgrade");
  699. db.beginTransaction();
  700. try {
  701. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  702. ADD_COLUMN + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER " +
  703. " DEFAULT 0");
  704. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  705. ADD_COLUMN + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT " +
  706. " DEFAULT NULL");
  707. // Create table ocshares
  708. createOCSharesTable(db);
  709. upgraded = true;
  710. db.setTransactionSuccessful();
  711. } finally {
  712. db.endTransaction();
  713. }
  714. }
  715. if (!upgraded) {
  716. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  717. }
  718. if (oldVersion < 7 && newVersion >= 7) {
  719. Log_OC.i(SQL, "Entering in the #7 ADD in onUpgrade");
  720. db.beginTransaction();
  721. try {
  722. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  723. ADD_COLUMN + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
  724. " DEFAULT NULL");
  725. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  726. ADD_COLUMN + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " +
  727. " DEFAULT NULL");
  728. upgraded = true;
  729. db.setTransactionSuccessful();
  730. } finally {
  731. db.endTransaction();
  732. }
  733. }
  734. if (!upgraded) {
  735. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  736. }
  737. if (oldVersion < 8 && newVersion >= 8) {
  738. Log_OC.i(SQL, "Entering in the #8 ADD in onUpgrade");
  739. db.beginTransaction();
  740. try {
  741. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  742. ADD_COLUMN + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER " +
  743. " DEFAULT 0");
  744. upgraded = true;
  745. db.setTransactionSuccessful();
  746. } finally {
  747. db.endTransaction();
  748. }
  749. }
  750. if (!upgraded) {
  751. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  752. }
  753. if (oldVersion < 9 && newVersion >= 9) {
  754. Log_OC.i(SQL, "Entering in the #9 ADD in onUpgrade");
  755. db.beginTransaction();
  756. try {
  757. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  758. ADD_COLUMN + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER " +
  759. " DEFAULT 0");
  760. upgraded = true;
  761. db.setTransactionSuccessful();
  762. } finally {
  763. db.endTransaction();
  764. }
  765. }
  766. if (!upgraded) {
  767. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  768. }
  769. if (oldVersion < 10 && newVersion >= 10) {
  770. Log_OC.i(SQL, "Entering in the #10 ADD in onUpgrade");
  771. updateAccountName(db);
  772. upgraded = true;
  773. }
  774. if (!upgraded) {
  775. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  776. }
  777. if (oldVersion < 11 && newVersion >= 11) {
  778. Log_OC.i(SQL, "Entering in the #11 ADD in onUpgrade");
  779. db.beginTransaction();
  780. try {
  781. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  782. ADD_COLUMN + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT " +
  783. " DEFAULT NULL");
  784. upgraded = true;
  785. db.setTransactionSuccessful();
  786. } finally {
  787. db.endTransaction();
  788. }
  789. }
  790. if (!upgraded) {
  791. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  792. }
  793. if (oldVersion < 12 && newVersion >= 12) {
  794. Log_OC.i(SQL, "Entering in the #12 ADD in onUpgrade");
  795. db.beginTransaction();
  796. try {
  797. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  798. ADD_COLUMN + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER " +
  799. " DEFAULT 0");
  800. upgraded = true;
  801. db.setTransactionSuccessful();
  802. } finally {
  803. db.endTransaction();
  804. }
  805. }
  806. if (!upgraded) {
  807. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  808. }
  809. if (oldVersion < 13 && newVersion >= 13) {
  810. Log_OC.i(SQL, "Entering in the #13 ADD in onUpgrade");
  811. db.beginTransaction();
  812. try {
  813. // Create capabilities table
  814. createCapabilitiesTable(db);
  815. upgraded = true;
  816. db.setTransactionSuccessful();
  817. } finally {
  818. db.endTransaction();
  819. }
  820. }
  821. if (oldVersion < 14 && newVersion >= 14) {
  822. Log_OC.i(SQL, "Entering in the #14 ADD in onUpgrade");
  823. db.beginTransaction();
  824. try {
  825. // drop old instant_upload table
  826. db.execSQL("DROP TABLE IF EXISTS " + "instant_upload" + ";");
  827. // Create uploads table
  828. createUploadsTable(db);
  829. upgraded = true;
  830. db.setTransactionSuccessful();
  831. } finally {
  832. db.endTransaction();
  833. }
  834. }
  835. if (oldVersion < 15 && newVersion >= 15) {
  836. Log_OC.i(SQL, "Entering in the #15 ADD in onUpgrade");
  837. db.beginTransaction();
  838. try {
  839. // drop old capabilities table
  840. db.execSQL("DROP TABLE IF EXISTS " + "capabilities" + ";");
  841. // Create uploads table
  842. createCapabilitiesTable(db);
  843. upgraded = true;
  844. db.setTransactionSuccessful();
  845. } finally {
  846. db.endTransaction();
  847. }
  848. }
  849. if (oldVersion < 16 && newVersion >= 16) {
  850. Log_OC.i(SQL, "Entering in the #16 ADD synced folders table");
  851. db.beginTransaction();
  852. try {
  853. // Create synced folders table
  854. createSyncedFoldersTable(db);
  855. upgraded = true;
  856. db.setTransactionSuccessful();
  857. } finally {
  858. db.endTransaction();
  859. }
  860. }
  861. if (!upgraded) {
  862. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  863. }
  864. if (oldVersion < 17 && newVersion >= 17) {
  865. Log_OC.i(SQL, "Entering in the #17 ADD in onUpgrade");
  866. db.beginTransaction();
  867. try {
  868. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  869. ADD_COLUMN + ProviderTableMeta.FILE_FAVORITE +
  870. " INTEGER " + " DEFAULT 0");
  871. upgraded = true;
  872. db.setTransactionSuccessful();
  873. } finally {
  874. db.endTransaction();
  875. }
  876. }
  877. if (!upgraded) {
  878. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  879. }
  880. if (oldVersion < 18 && newVersion >= 18) {
  881. Log_OC.i(SQL, "Entering in the #18 Adding external link column to capabilities");
  882. db.beginTransaction();
  883. try {
  884. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  885. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS +
  886. " INTEGER " + " DEFAULT -1");
  887. upgraded = true;
  888. db.setTransactionSuccessful();
  889. } finally {
  890. db.endTransaction();
  891. }
  892. }
  893. if (!upgraded) {
  894. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  895. }
  896. if (oldVersion < 19 && newVersion >= 19) {
  897. Log_OC.i(SQL, "Entering in the #19 Adding external link column to capabilities");
  898. db.beginTransaction();
  899. try {
  900. createExternalLinksTable(db);
  901. upgraded = true;
  902. db.setTransactionSuccessful();
  903. } finally {
  904. db.endTransaction();
  905. }
  906. }
  907. if (!upgraded) {
  908. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  909. }
  910. if (oldVersion < 20 && newVersion >= 20) {
  911. Log_OC.i(SQL, "Entering in the #20 Adding arbitrary data table");
  912. db.beginTransaction();
  913. try {
  914. createArbitraryData(db);
  915. upgraded = true;
  916. db.setTransactionSuccessful();
  917. } finally {
  918. db.endTransaction();
  919. }
  920. }
  921. if (!upgraded) {
  922. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  923. }
  924. if (oldVersion < 21 && newVersion >= 21) {
  925. Log_OC.i(SQL, "Entering in the #21 Adding virtual table");
  926. db.beginTransaction();
  927. try {
  928. createVirtualTable(db);
  929. upgraded = true;
  930. db.setTransactionSuccessful();
  931. } finally {
  932. db.endTransaction();
  933. }
  934. }
  935. if (!upgraded) {
  936. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  937. }
  938. if (oldVersion < 22 && newVersion >= 22) {
  939. Log_OC.i(SQL, "Entering in the #22 Adding user theming to capabilities table");
  940. db.beginTransaction();
  941. try {
  942. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  943. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
  944. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  945. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
  946. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  947. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
  948. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  949. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
  950. upgraded = true;
  951. db.setTransactionSuccessful();
  952. } finally {
  953. db.endTransaction();
  954. }
  955. }
  956. if (!upgraded) {
  957. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  958. }
  959. if (oldVersion < 23 && newVersion >= 23) {
  960. Log_OC.i(SQL, "Entering in the #23 adding type column for synced folders, Create filesystem table");
  961. db.beginTransaction();
  962. try {
  963. // add type column default being CUSTOM (0)
  964. if (!checkIfColumnExists(db, ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME,
  965. ProviderTableMeta.SYNCED_FOLDER_TYPE)) {
  966. Log_OC.i(SQL, "Add type column and default value 0 (CUSTOM) to synced_folders table");
  967. db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
  968. ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_TYPE +
  969. " INTEGER " + " DEFAULT 0");
  970. } else {
  971. Log_OC.i(SQL, "Type column of synced_folders table already exists");
  972. }
  973. if (!checkIfColumnExists(db, ProviderTableMeta.UPLOADS_TABLE_NAME,
  974. ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)) {
  975. Log_OC.i(SQL, "Add charging and wifi columns to uploads");
  976. db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
  977. ADD_COLUMN + ProviderTableMeta.UPLOADS_IS_WIFI_ONLY +
  978. " INTEGER " + " DEFAULT 0");
  979. } else {
  980. Log_OC.i(SQL, "Wifi column of uploads table already exists");
  981. }
  982. if (!checkIfColumnExists(db, ProviderTableMeta.UPLOADS_TABLE_NAME,
  983. ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY)) {
  984. db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
  985. ADD_COLUMN + ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY +
  986. " INTEGER " + " DEFAULT 0");
  987. } else {
  988. Log_OC.i(SQL, "Charging column of uploads table already exists");
  989. }
  990. // create Filesystem table
  991. Log_OC.i(SQL, "Create filesystem table");
  992. createFileSystemTable(db);
  993. upgraded = true;
  994. db.setTransactionSuccessful();
  995. } catch (Throwable t) {
  996. Log_OC.e(TAG, "ERROR!", t);
  997. } finally {
  998. db.endTransaction();
  999. }
  1000. if (!upgraded) {
  1001. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1002. }
  1003. if (oldVersion < 24 && newVersion >= 24) {
  1004. Log_OC.i(SQL, "Entering in the #24 Re-adding user theming to capabilities table");
  1005. db.beginTransaction();
  1006. try {
  1007. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1008. ProviderTableMeta.CAPABILITIES_SERVER_NAME)) {
  1009. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1010. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
  1011. }
  1012. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1013. ProviderTableMeta.CAPABILITIES_SERVER_COLOR)) {
  1014. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1015. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
  1016. }
  1017. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1018. ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL)) {
  1019. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1020. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
  1021. }
  1022. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1023. ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN)) {
  1024. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1025. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
  1026. }
  1027. upgraded = true;
  1028. db.setTransactionSuccessful();
  1029. } finally {
  1030. db.endTransaction();
  1031. }
  1032. }
  1033. if (!upgraded) {
  1034. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1035. }
  1036. }
  1037. }
  1038. }
  1039. private boolean checkIfColumnExists(SQLiteDatabase database, String table, String column) {
  1040. Cursor cursor = database.rawQuery("SELECT * FROM " + table + " LIMIT 0", null);
  1041. boolean exists = cursor.getColumnIndex(column) != -1;
  1042. cursor.close();
  1043. return exists;
  1044. }
  1045. private void createFilesTable(SQLiteDatabase db) {
  1046. db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "("
  1047. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  1048. + ProviderTableMeta.FILE_NAME + TEXT
  1049. + ProviderTableMeta.FILE_PATH + TEXT
  1050. + ProviderTableMeta.FILE_PARENT + INTEGER
  1051. + ProviderTableMeta.FILE_CREATION + INTEGER
  1052. + ProviderTableMeta.FILE_MODIFIED + INTEGER
  1053. + ProviderTableMeta.FILE_CONTENT_TYPE + TEXT
  1054. + ProviderTableMeta.FILE_CONTENT_LENGTH + INTEGER
  1055. + ProviderTableMeta.FILE_STORAGE_PATH + TEXT
  1056. + ProviderTableMeta.FILE_ACCOUNT_OWNER + TEXT
  1057. + ProviderTableMeta.FILE_LAST_SYNC_DATE + INTEGER
  1058. + ProviderTableMeta.FILE_KEEP_IN_SYNC + INTEGER
  1059. + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + INTEGER
  1060. + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + INTEGER
  1061. + ProviderTableMeta.FILE_ETAG + TEXT
  1062. + ProviderTableMeta.FILE_SHARED_VIA_LINK + INTEGER
  1063. + ProviderTableMeta.FILE_PUBLIC_LINK + TEXT
  1064. + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
  1065. + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null,"
  1066. + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + INTEGER //boolean
  1067. + ProviderTableMeta.FILE_IS_DOWNLOADING + INTEGER //boolean
  1068. + ProviderTableMeta.FILE_FAVORITE + INTEGER // boolean
  1069. + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + TEXT
  1070. + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER);"
  1071. );
  1072. }
  1073. private void createOCSharesTable(SQLiteDatabase db) {
  1074. // Create ocshares table
  1075. db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
  1076. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  1077. + ProviderTableMeta.OCSHARES_FILE_SOURCE + INTEGER
  1078. + ProviderTableMeta.OCSHARES_ITEM_SOURCE + INTEGER
  1079. + ProviderTableMeta.OCSHARES_SHARE_TYPE + INTEGER
  1080. + ProviderTableMeta.OCSHARES_SHARE_WITH + TEXT
  1081. + ProviderTableMeta.OCSHARES_PATH + TEXT
  1082. + ProviderTableMeta.OCSHARES_PERMISSIONS + INTEGER
  1083. + ProviderTableMeta.OCSHARES_SHARED_DATE + INTEGER
  1084. + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + INTEGER
  1085. + ProviderTableMeta.OCSHARES_TOKEN + TEXT
  1086. + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + TEXT
  1087. + ProviderTableMeta.OCSHARES_IS_DIRECTORY + INTEGER // boolean
  1088. + ProviderTableMeta.OCSHARES_USER_ID + INTEGER
  1089. + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + INTEGER
  1090. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );");
  1091. }
  1092. private void createCapabilitiesTable(SQLiteDatabase db) {
  1093. // Create capabilities table
  1094. db.execSQL("CREATE TABLE " + ProviderTableMeta.CAPABILITIES_TABLE_NAME + "("
  1095. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  1096. + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + TEXT
  1097. + ProviderTableMeta.CAPABILITIES_VERSION_MAYOR + INTEGER
  1098. + ProviderTableMeta.CAPABILITIES_VERSION_MINOR + INTEGER
  1099. + ProviderTableMeta.CAPABILITIES_VERSION_MICRO + INTEGER
  1100. + ProviderTableMeta.CAPABILITIES_VERSION_STRING + TEXT
  1101. + ProviderTableMeta.CAPABILITIES_VERSION_EDITION + TEXT
  1102. + ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL + INTEGER
  1103. + ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED + INTEGER // boolean
  1104. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED + INTEGER // boolean
  1105. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED + INTEGER // boolean
  1106. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED + INTEGER // boolean
  1107. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS + INTEGER
  1108. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED + INTEGER // boolean
  1109. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL + INTEGER // boolean
  1110. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD + INTEGER // boolean
  1111. + ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL + INTEGER // boolean
  1112. + ProviderTableMeta.CAPABILITIES_SHARING_RESHARING + INTEGER // boolean
  1113. + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING + INTEGER // boolean
  1114. + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING + INTEGER // boolean
  1115. + ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING + INTEGER // boolean
  1116. + ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + INTEGER // boolean
  1117. + ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + INTEGER // boolean
  1118. + ProviderTableMeta.CAPABILITIES_FILES_DROP + INTEGER // boolean
  1119. + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS + INTEGER // boolean
  1120. + ProviderTableMeta.CAPABILITIES_SERVER_NAME + TEXT
  1121. + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + TEXT
  1122. + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + TEXT
  1123. + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT );");
  1124. }
  1125. private void createUploadsTable(SQLiteDatabase db) {
  1126. // Create uploads table
  1127. db.execSQL("CREATE TABLE " + ProviderTableMeta.UPLOADS_TABLE_NAME + "("
  1128. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  1129. + ProviderTableMeta.UPLOADS_LOCAL_PATH + TEXT
  1130. + ProviderTableMeta.UPLOADS_REMOTE_PATH + TEXT
  1131. + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + TEXT
  1132. + ProviderTableMeta.UPLOADS_FILE_SIZE + " LONG, "
  1133. + ProviderTableMeta.UPLOADS_STATUS + INTEGER // UploadStatus
  1134. + ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + INTEGER // Upload LocalBehaviour
  1135. + ProviderTableMeta.UPLOADS_UPLOAD_TIME + INTEGER
  1136. + ProviderTableMeta.UPLOADS_FORCE_OVERWRITE + INTEGER // boolean
  1137. + ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + INTEGER // boolean
  1138. + ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + INTEGER
  1139. + ProviderTableMeta.UPLOADS_LAST_RESULT + INTEGER // Upload LastResult
  1140. + ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + INTEGER // boolean
  1141. + ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + INTEGER // boolean
  1142. + ProviderTableMeta.UPLOADS_CREATED_BY + " INTEGER );" // Upload createdBy
  1143. );
  1144. /* before:
  1145. // PRIMARY KEY should always imply NOT NULL. Unfortunately, due to a
  1146. // bug in some early versions, this is not the case in SQLite.
  1147. //db.execSQL("CREATE TABLE " + TABLE_UPLOAD + " (" + " path TEXT PRIMARY KEY NOT NULL UNIQUE,"
  1148. // + " uploadStatus INTEGER NOT NULL, uploadObject TEXT NOT NULL);");
  1149. // uploadStatus is used to easy filtering, it has precedence over
  1150. // uploadObject.getUploadStatus()
  1151. */
  1152. }
  1153. private void createSyncedFoldersTable(SQLiteDatabase db) {
  1154. db.execSQL("CREATE TABLE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + "("
  1155. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  1156. + ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " TEXT, " // local path
  1157. + ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH + " TEXT, " // remote path
  1158. + ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY + " INTEGER, " // wifi_only
  1159. + ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY + " INTEGER, " // charging only
  1160. + ProviderTableMeta.SYNCED_FOLDER_ENABLED + " INTEGER, " // enabled
  1161. + ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
  1162. + ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " TEXT, " // account
  1163. + ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION + " INTEGER, " // upload action
  1164. + ProviderTableMeta.SYNCED_FOLDER_TYPE + " INTEGER );" // type
  1165. );
  1166. }
  1167. private void createExternalLinksTable(SQLiteDatabase db) {
  1168. db.execSQL("CREATE TABLE " + ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME + "("
  1169. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  1170. + ProviderTableMeta.EXTERNAL_LINKS_ICON_URL + " TEXT, " // icon url
  1171. + ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE + " TEXT, " // language
  1172. + ProviderTableMeta.EXTERNAL_LINKS_TYPE + " INTEGER, " // type
  1173. + ProviderTableMeta.EXTERNAL_LINKS_NAME + " TEXT, " // name
  1174. + ProviderTableMeta.EXTERNAL_LINKS_URL + " TEXT );" // url
  1175. );
  1176. }
  1177. private void createArbitraryData(SQLiteDatabase db) {
  1178. db.execSQL("CREATE TABLE " + ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME + "("
  1179. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  1180. + ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " TEXT, " // cloud id (account name + FQDN)
  1181. + ProviderTableMeta.ARBITRARY_DATA_KEY + " TEXT, " // key
  1182. + ProviderTableMeta.ARBITRARY_DATA_VALUE + " TEXT );" // value
  1183. );
  1184. }
  1185. private void createVirtualTable(SQLiteDatabase db) {
  1186. db.execSQL("CREATE TABLE " + ProviderTableMeta.VIRTUAL_TABLE_NAME + "("
  1187. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  1188. + ProviderTableMeta.VIRTUAL_TYPE + " TEXT, " // type
  1189. + ProviderTableMeta.VIRTUAL_OCFILE_ID + " INTEGER )" // file id
  1190. );
  1191. }
  1192. private void createFileSystemTable(SQLiteDatabase db) {
  1193. db.execSQL("CREATE TABLE IF NOT EXISTS " + ProviderTableMeta.FILESYSTEM_TABLE_NAME + "("
  1194. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  1195. + ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " TEXT, "
  1196. + ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER + " INTEGER, "
  1197. + ProviderTableMeta.FILESYSTEM_FILE_FOUND_RECENTLY + " LONG, "
  1198. + ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD + " INTEGER, "
  1199. + ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " STRING, "
  1200. + ProviderTableMeta.FILESYSTEM_FILE_MODIFIED + " LONG );"
  1201. );
  1202. }
  1203. /**
  1204. * Version 10 of database does not modify its scheme. It coincides with the upgrade of the ownCloud account names
  1205. * structure to include in it the path to the server instance. Updating the account names and path to local files
  1206. * in the files table is a must to keep the existing account working and the database clean.
  1207. *
  1208. * See {@link com.owncloud.android.authentication.AccountUtils#updateAccountVersion(android.content.Context)}
  1209. *
  1210. * @param db Database where table of files is included.
  1211. */
  1212. private void updateAccountName(SQLiteDatabase db) {
  1213. Log_OC.d(SQL, "THREAD: " + Thread.currentThread().getName());
  1214. AccountManager ama = AccountManager.get(getContext());
  1215. try {
  1216. // get accounts from AccountManager ; we can't be sure if accounts in it are updated or not although
  1217. // we know the update was previously done in {link @FileActivity#onCreate} because the changes through
  1218. // AccountManager are not synchronous
  1219. Account[] accounts = AccountManager.get(getContext()).getAccountsByType(
  1220. MainApp.getAccountType());
  1221. String serverUrl;
  1222. String username;
  1223. String oldAccountName;
  1224. String newAccountName;
  1225. for (Account account : accounts) {
  1226. // build both old and new account name
  1227. serverUrl = ama.getUserData(account, AccountUtils.Constants.KEY_OC_BASE_URL);
  1228. username = AccountUtils.getUsernameForAccount(account);
  1229. oldAccountName = AccountUtils.buildAccountNameOld(Uri.parse(serverUrl), username);
  1230. newAccountName = AccountUtils.buildAccountName(Uri.parse(serverUrl), username);
  1231. // update values in database
  1232. db.beginTransaction();
  1233. try {
  1234. ContentValues cv = new ContentValues();
  1235. cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, newAccountName);
  1236. int num = db.update(ProviderTableMeta.FILE_TABLE_NAME,
  1237. cv,
  1238. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
  1239. new String[]{oldAccountName});
  1240. Log_OC.d(SQL, "Updated account in database: old name == " + oldAccountName +
  1241. ", new name == " + newAccountName + " (" + num + " rows updated )");
  1242. // update path for downloaded files
  1243. updateDownloadedFiles(db, newAccountName, oldAccountName);
  1244. db.setTransactionSuccessful();
  1245. } catch (SQLException e) {
  1246. Log_OC.e(TAG, "SQL Exception upgrading account names or paths in database", e);
  1247. } finally {
  1248. db.endTransaction();
  1249. }
  1250. }
  1251. } catch (Exception e) {
  1252. Log_OC.e(TAG, "Exception upgrading account names or paths in database", e);
  1253. }
  1254. }
  1255. /**
  1256. * Rename the local ownCloud folder of one account to match the a rename of the account itself. Updates the
  1257. * table of files in database so that the paths to the local files keep being the same.
  1258. *
  1259. * @param db Database where table of files is included.
  1260. * @param newAccountName New name for the target OC account.
  1261. * @param oldAccountName Old name of the target OC account.
  1262. */
  1263. private void updateDownloadedFiles(SQLiteDatabase db, String newAccountName,
  1264. String oldAccountName) {
  1265. String whereClause = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  1266. ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL";
  1267. Cursor c = db.query(ProviderTableMeta.FILE_TABLE_NAME,
  1268. null,
  1269. whereClause,
  1270. new String[]{newAccountName},
  1271. null, null, null);
  1272. try {
  1273. if (c.moveToFirst()) {
  1274. // create storage path
  1275. String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
  1276. String newAccountPath = FileStorageUtils.getSavePath(newAccountName);
  1277. // move files
  1278. File oldAccountFolder = new File(oldAccountPath);
  1279. File newAccountFolder = new File(newAccountPath);
  1280. oldAccountFolder.renameTo(newAccountFolder);
  1281. // update database
  1282. do {
  1283. // Update database
  1284. String oldPath = c.getString(
  1285. c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
  1286. OCFile file = new OCFile(
  1287. c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH)));
  1288. String newPath = FileStorageUtils.getDefaultSavePathFor(newAccountName, file);
  1289. ContentValues cv = new ContentValues();
  1290. cv.put(ProviderTableMeta.FILE_STORAGE_PATH, newPath);
  1291. db.update(ProviderTableMeta.FILE_TABLE_NAME,
  1292. cv,
  1293. ProviderTableMeta.FILE_STORAGE_PATH + "=?",
  1294. new String[]{oldPath});
  1295. Log_OC.v(SQL, "Updated path of downloaded file: old file name == " + oldPath +
  1296. ", new file name == " + newPath);
  1297. } while (c.moveToNext());
  1298. }
  1299. } finally {
  1300. c.close();
  1301. }
  1302. }
  1303. }