FileContentProvider.java 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  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.SQLiteException;
  37. import android.database.sqlite.SQLiteOpenHelper;
  38. import android.database.sqlite.SQLiteQueryBuilder;
  39. import android.net.Uri;
  40. import android.os.Binder;
  41. import android.text.TextUtils;
  42. import com.owncloud.android.MainApp;
  43. import com.owncloud.android.R;
  44. import com.owncloud.android.datamodel.OCFile;
  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 com.owncloud.android.utils.MimeType;
  52. import java.io.File;
  53. import java.util.ArrayList;
  54. import java.util.HashMap;
  55. import java.util.Locale;
  56. import androidx.annotation.NonNull;
  57. /**
  58. * The ContentProvider for the ownCloud App.
  59. */
  60. @SuppressWarnings("PMD.AvoidDuplicateLiterals")
  61. public class FileContentProvider extends ContentProvider {
  62. private static final int SINGLE_FILE = 1;
  63. private static final int DIRECTORY = 2;
  64. private static final int ROOT_DIRECTORY = 3;
  65. private static final int SHARES = 4;
  66. private static final int CAPABILITIES = 5;
  67. private static final int UPLOADS = 6;
  68. private static final int SYNCED_FOLDERS = 7;
  69. private static final int EXTERNAL_LINKS = 8;
  70. private static final int ARBITRARY_DATA = 9;
  71. private static final int VIRTUAL = 10;
  72. private static final int FILESYSTEM = 11;
  73. private static final String TAG = FileContentProvider.class.getSimpleName();
  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 REMOVE_COLUMN = " REMOVE COLUMN ";
  82. private static final String UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";
  83. private static final int SINGLE_PATH_SEGMENT = 1;
  84. public static final int ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION = 20;
  85. private DataBaseHelper mDbHelper;
  86. private Context mContext;
  87. private UriMatcher mUriMatcher;
  88. @Override
  89. public int delete(@NonNull Uri uri, String where, String[] whereArgs) {
  90. if (isCallerNotAllowed(uri)) {
  91. return -1;
  92. }
  93. int count;
  94. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  95. db.beginTransaction();
  96. try {
  97. count = delete(db, uri, where, whereArgs);
  98. db.setTransactionSuccessful();
  99. } finally {
  100. db.endTransaction();
  101. }
  102. mContext.getContentResolver().notifyChange(uri, null);
  103. return count;
  104. }
  105. private int delete(SQLiteDatabase db, Uri uri, String where, String... whereArgs) {
  106. if (isCallerNotAllowed(uri)) {
  107. return -1;
  108. }
  109. int count;
  110. switch (mUriMatcher.match(uri)) {
  111. case SINGLE_FILE:
  112. count = deleteSingleFile(db, uri, where, whereArgs);
  113. break;
  114. case DIRECTORY:
  115. count = deleteDirectory(db, uri, where, whereArgs);
  116. break;
  117. case ROOT_DIRECTORY:
  118. count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs);
  119. break;
  120. case SHARES:
  121. count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs);
  122. break;
  123. case CAPABILITIES:
  124. count = db.delete(ProviderTableMeta.CAPABILITIES_TABLE_NAME, where, whereArgs);
  125. break;
  126. case UPLOADS:
  127. count = db.delete(ProviderTableMeta.UPLOADS_TABLE_NAME, where, whereArgs);
  128. break;
  129. case SYNCED_FOLDERS:
  130. count = db.delete(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, where, whereArgs);
  131. break;
  132. case EXTERNAL_LINKS:
  133. count = db.delete(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, where, whereArgs);
  134. break;
  135. case ARBITRARY_DATA:
  136. count = db.delete(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, where, whereArgs);
  137. break;
  138. case VIRTUAL:
  139. count = db.delete(ProviderTableMeta.VIRTUAL_TABLE_NAME, where, whereArgs);
  140. break;
  141. case FILESYSTEM:
  142. count = db.delete(ProviderTableMeta.FILESYSTEM_TABLE_NAME, where, whereArgs);
  143. break;
  144. default:
  145. throw new IllegalArgumentException(String.format(Locale.US, "Unknown uri: %s", uri.toString()));
  146. }
  147. return count;
  148. }
  149. private int deleteDirectory(SQLiteDatabase db, Uri uri, String where, String... whereArgs) {
  150. int count = 0;
  151. Cursor children = query(uri, null, null, null, null);
  152. if (children != null) {
  153. if (children.moveToFirst()) {
  154. long childId;
  155. boolean isDir;
  156. while (!children.isAfterLast()) {
  157. childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
  158. isDir = MimeType.DIRECTORY.equals(children.getString(
  159. children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
  160. ));
  161. if (isDir) {
  162. count += delete(db, ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
  163. null, (String[]) null);
  164. } else {
  165. count += delete(db, ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
  166. null, (String[]) null);
  167. }
  168. children.moveToNext();
  169. }
  170. }
  171. children.close();
  172. }
  173. count += db.delete(ProviderTableMeta.FILE_TABLE_NAME,
  174. ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1)
  175. + (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""), whereArgs);
  176. return count;
  177. }
  178. private int deleteSingleFile(SQLiteDatabase db, Uri uri, String where, String... whereArgs) {
  179. int count = 0;
  180. Cursor c = query(db, uri, null, where, whereArgs, null);
  181. String remoteId = "";
  182. try {
  183. if (c != null && c.moveToFirst()) {
  184. remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
  185. }
  186. Log_OC.d(TAG, "Removing FILE " + remoteId);
  187. count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
  188. ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1)
  189. + (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""), whereArgs);
  190. } catch (Exception e) {
  191. Log_OC.d(TAG, "DB-Error removing file!", e);
  192. } finally {
  193. if (c != null) {
  194. c.close();
  195. }
  196. }
  197. return count;
  198. }
  199. @Override
  200. public String getType(@NonNull Uri uri) {
  201. switch (mUriMatcher.match(uri)) {
  202. case ROOT_DIRECTORY:
  203. return ProviderTableMeta.CONTENT_TYPE;
  204. case SINGLE_FILE:
  205. return ProviderTableMeta.CONTENT_TYPE_ITEM;
  206. default:
  207. throw new IllegalArgumentException(String.format(Locale.US, "Unknown Uri id: %s", uri));
  208. }
  209. }
  210. @Override
  211. public Uri insert(@NonNull Uri uri, ContentValues values) {
  212. if (isCallerNotAllowed(uri)) {
  213. return null;
  214. }
  215. Uri newUri;
  216. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  217. db.beginTransaction();
  218. try {
  219. newUri = insert(db, uri, values);
  220. db.setTransactionSuccessful();
  221. } finally {
  222. db.endTransaction();
  223. }
  224. mContext.getContentResolver().notifyChange(newUri, null);
  225. return newUri;
  226. }
  227. private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) {
  228. switch (mUriMatcher.match(uri)) {
  229. case ROOT_DIRECTORY:
  230. case SINGLE_FILE:
  231. String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
  232. String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
  233. String[] projection = new String[]{
  234. ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH,
  235. ProviderTableMeta.FILE_ACCOUNT_OWNER
  236. };
  237. String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
  238. String[] whereArgs = new String[]{remotePath, accountName};
  239. Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
  240. // ugly patch; serious refactorization is needed to reduce work in
  241. // FileDataStorageManager and bring it to FileContentProvider
  242. if (doubleCheck == null || !doubleCheck.moveToFirst()) {
  243. if (doubleCheck != null) {
  244. doubleCheck.close();
  245. }
  246. long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
  247. if (rowId > 0) {
  248. return ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
  249. } else {
  250. throw new SQLException(ERROR + uri);
  251. }
  252. } else {
  253. // file is already inserted; race condition, let's avoid a duplicated entry
  254. Uri insertedFileUri = ContentUris.withAppendedId(
  255. ProviderTableMeta.CONTENT_URI_FILE,
  256. doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID))
  257. );
  258. doubleCheck.close();
  259. return insertedFileUri;
  260. }
  261. case SHARES:
  262. Uri insertedShareUri;
  263. long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
  264. if (rowId > 0) {
  265. insertedShareUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId);
  266. } else {
  267. throw new SQLException(ERROR + uri);
  268. }
  269. updateFilesTableAccordingToShareInsertion(db, values);
  270. return insertedShareUri;
  271. case CAPABILITIES:
  272. Uri insertedCapUri;
  273. long id = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, null, values);
  274. if (id > 0) {
  275. insertedCapUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_CAPABILITIES, id);
  276. } else {
  277. throw new SQLException(ERROR + uri);
  278. }
  279. return insertedCapUri;
  280. case UPLOADS:
  281. Uri insertedUploadUri;
  282. long uploadId = db.insert(ProviderTableMeta.UPLOADS_TABLE_NAME, null, values);
  283. if (uploadId > 0) {
  284. insertedUploadUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_UPLOADS, uploadId);
  285. } else {
  286. throw new SQLException(ERROR + uri);
  287. }
  288. return insertedUploadUri;
  289. case SYNCED_FOLDERS:
  290. Uri insertedSyncedFolderUri;
  291. long syncedFolderId = db.insert(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, null, values);
  292. if (syncedFolderId > 0) {
  293. insertedSyncedFolderUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
  294. syncedFolderId);
  295. } else {
  296. throw new SQLException("ERROR " + uri);
  297. }
  298. return insertedSyncedFolderUri;
  299. case EXTERNAL_LINKS:
  300. Uri insertedExternalLinkUri;
  301. long externalLinkId = db.insert(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, null, values);
  302. if (externalLinkId > 0) {
  303. insertedExternalLinkUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_EXTERNAL_LINKS,
  304. externalLinkId);
  305. } else {
  306. throw new SQLException("ERROR " + uri);
  307. }
  308. return insertedExternalLinkUri;
  309. case ARBITRARY_DATA:
  310. Uri insertedArbitraryDataUri;
  311. long arbitraryDataId = db.insert(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, null, values);
  312. if (arbitraryDataId > 0) {
  313. insertedArbitraryDataUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA,
  314. arbitraryDataId);
  315. } else {
  316. throw new SQLException("ERROR " + uri);
  317. }
  318. return insertedArbitraryDataUri;
  319. case VIRTUAL:
  320. Uri insertedVirtualUri;
  321. long virtualId = db.insert(ProviderTableMeta.VIRTUAL_TABLE_NAME, null, values);
  322. if (virtualId > 0) {
  323. insertedVirtualUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_VIRTUAL, virtualId);
  324. } else {
  325. throw new SQLException("ERROR " + uri);
  326. }
  327. return insertedVirtualUri;
  328. case FILESYSTEM:
  329. Uri insertedFilesystemUri;
  330. long filesystemId = db.insert(ProviderTableMeta.FILESYSTEM_TABLE_NAME, null, values);
  331. if (filesystemId > 0) {
  332. insertedFilesystemUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILESYSTEM,
  333. filesystemId);
  334. } else {
  335. throw new SQLException("ERROR " + uri);
  336. }
  337. return insertedFilesystemUri;
  338. default:
  339. throw new IllegalArgumentException("Unknown uri id: " + uri);
  340. }
  341. }
  342. private void updateFilesTableAccordingToShareInsertion(SQLiteDatabase db, ContentValues newShare) {
  343. ContentValues fileValues = new ContentValues();
  344. ShareType newShareType = ShareType.fromValue(newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE));
  345. switch (newShareType) {
  346. case PUBLIC_LINK:
  347. fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1);
  348. break;
  349. case USER:
  350. case GROUP:
  351. case EMAIL:
  352. case FEDERATED:
  353. case ROOM:
  354. fileValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, 1);
  355. break;
  356. default:
  357. // everything should be handled
  358. }
  359. String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
  360. String[] whereArgs = new String[]{
  361. newShare.getAsString(ProviderTableMeta.OCSHARES_PATH),
  362. newShare.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)
  363. };
  364. db.update(ProviderTableMeta.FILE_TABLE_NAME, fileValues, where, whereArgs);
  365. }
  366. @Override
  367. public boolean onCreate() {
  368. mDbHelper = new DataBaseHelper(getContext());
  369. mContext = getContext();
  370. if (mContext == null) {
  371. return false;
  372. }
  373. String authority = mContext.getResources().getString(R.string.authority);
  374. mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  375. mUriMatcher.addURI(authority, null, ROOT_DIRECTORY);
  376. mUriMatcher.addURI(authority, "file/", SINGLE_FILE);
  377. mUriMatcher.addURI(authority, "file/#", SINGLE_FILE);
  378. mUriMatcher.addURI(authority, "dir/", DIRECTORY);
  379. mUriMatcher.addURI(authority, "dir/#", DIRECTORY);
  380. mUriMatcher.addURI(authority, "shares/", SHARES);
  381. mUriMatcher.addURI(authority, "shares/#", SHARES);
  382. mUriMatcher.addURI(authority, "capabilities/", CAPABILITIES);
  383. mUriMatcher.addURI(authority, "capabilities/#", CAPABILITIES);
  384. mUriMatcher.addURI(authority, "uploads/", UPLOADS);
  385. mUriMatcher.addURI(authority, "uploads/#", UPLOADS);
  386. mUriMatcher.addURI(authority, "synced_folders", SYNCED_FOLDERS);
  387. mUriMatcher.addURI(authority, "external_links", EXTERNAL_LINKS);
  388. mUriMatcher.addURI(authority, "arbitrary_data", ARBITRARY_DATA);
  389. mUriMatcher.addURI(authority, "virtual", VIRTUAL);
  390. mUriMatcher.addURI(authority, "filesystem", FILESYSTEM);
  391. return true;
  392. }
  393. @Override
  394. public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
  395. String sortOrder) {
  396. // skip check for files as they need to be queried to get access via document provider
  397. switch (mUriMatcher.match(uri)) {
  398. case ROOT_DIRECTORY:
  399. case SINGLE_FILE:
  400. case DIRECTORY:
  401. break;
  402. default:
  403. if (isCallerNotAllowed(uri)) {
  404. return null;
  405. }
  406. }
  407. Cursor result;
  408. SQLiteDatabase db = mDbHelper.getReadableDatabase();
  409. db.beginTransaction();
  410. try {
  411. result = query(db, uri, projection, selection, selectionArgs, sortOrder);
  412. db.setTransactionSuccessful();
  413. } finally {
  414. db.endTransaction();
  415. }
  416. return result;
  417. }
  418. private Cursor query(SQLiteDatabase db, Uri uri, String[] projectionArray, String selection, String[] selectionArgs,
  419. String sortOrder) {
  420. SQLiteQueryBuilder sqlQuery = new SQLiteQueryBuilder();
  421. sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME);
  422. switch (mUriMatcher.match(uri)) {
  423. case ROOT_DIRECTORY:
  424. break;
  425. case DIRECTORY:
  426. sqlQuery.appendWhere(ProviderTableMeta.FILE_PARENT + "=" + uri.getPathSegments().get(1));
  427. break;
  428. case SINGLE_FILE:
  429. if (uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
  430. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  431. }
  432. break;
  433. case SHARES:
  434. sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME);
  435. if (uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
  436. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  437. }
  438. break;
  439. case CAPABILITIES:
  440. sqlQuery.setTables(ProviderTableMeta.CAPABILITIES_TABLE_NAME);
  441. if (uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
  442. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  443. }
  444. break;
  445. case UPLOADS:
  446. sqlQuery.setTables(ProviderTableMeta.UPLOADS_TABLE_NAME);
  447. if (uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
  448. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  449. }
  450. break;
  451. case SYNCED_FOLDERS:
  452. sqlQuery.setTables(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME);
  453. if (uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
  454. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  455. }
  456. break;
  457. case EXTERNAL_LINKS:
  458. sqlQuery.setTables(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME);
  459. if (uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
  460. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  461. }
  462. break;
  463. case ARBITRARY_DATA:
  464. sqlQuery.setTables(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME);
  465. if (uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
  466. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  467. }
  468. break;
  469. case VIRTUAL:
  470. sqlQuery.setTables(ProviderTableMeta.VIRTUAL_TABLE_NAME);
  471. if (uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
  472. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  473. }
  474. break;
  475. case FILESYSTEM:
  476. sqlQuery.setTables(ProviderTableMeta.FILESYSTEM_TABLE_NAME);
  477. if (uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
  478. sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
  479. }
  480. break;
  481. default:
  482. throw new IllegalArgumentException("Unknown uri id: " + uri);
  483. }
  484. String order;
  485. if (TextUtils.isEmpty(sortOrder)) {
  486. switch (mUriMatcher.match(uri)) {
  487. case SHARES:
  488. order = ProviderTableMeta.OCSHARES_DEFAULT_SORT_ORDER;
  489. break;
  490. case CAPABILITIES:
  491. order = ProviderTableMeta.CAPABILITIES_DEFAULT_SORT_ORDER;
  492. break;
  493. case UPLOADS:
  494. order = ProviderTableMeta.UPLOADS_DEFAULT_SORT_ORDER;
  495. break;
  496. case SYNCED_FOLDERS:
  497. order = ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH;
  498. break;
  499. case EXTERNAL_LINKS:
  500. order = ProviderTableMeta.EXTERNAL_LINKS_NAME;
  501. break;
  502. case ARBITRARY_DATA:
  503. order = ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID;
  504. break;
  505. case VIRTUAL:
  506. order = ProviderTableMeta.VIRTUAL_TYPE;
  507. break;
  508. default: // Files
  509. order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
  510. break;
  511. case FILESYSTEM:
  512. order = ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH;
  513. break;
  514. }
  515. } else {
  516. order = sortOrder;
  517. }
  518. // DB case_sensitive
  519. db.execSQL("PRAGMA case_sensitive_like = true");
  520. // only file list is accessible via content provider, so only this has to be protected with projectionMap
  521. if (mUriMatcher.match(uri) == ROOT_DIRECTORY && projectionArray != null) {
  522. HashMap<String, String> projectionMap = new HashMap<>();
  523. for (String projection : ProviderTableMeta.FILE_ALL_COLUMNS) {
  524. projectionMap.put(projection, projection);
  525. }
  526. sqlQuery.setProjectionMap(projectionMap);
  527. }
  528. // if both are null, let them pass to query
  529. if (selectionArgs == null && selection != null) {
  530. selectionArgs = new String[]{selection};
  531. selection = "(?)";
  532. }
  533. sqlQuery.setStrict(true);
  534. Cursor c = sqlQuery.query(db, projectionArray, selection, selectionArgs, null, null, order);
  535. c.setNotificationUri(mContext.getContentResolver(), uri);
  536. return c;
  537. }
  538. @Override
  539. public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
  540. if (isCallerNotAllowed(uri)) {
  541. return -1;
  542. }
  543. int count;
  544. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  545. db.beginTransaction();
  546. try {
  547. count = update(db, uri, values, selection, selectionArgs);
  548. db.setTransactionSuccessful();
  549. } finally {
  550. db.endTransaction();
  551. }
  552. mContext.getContentResolver().notifyChange(uri, null);
  553. return count;
  554. }
  555. private int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String... selectionArgs) {
  556. switch (mUriMatcher.match(uri)) {
  557. case DIRECTORY:
  558. return 0;
  559. case SHARES:
  560. return db.update(ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs);
  561. case CAPABILITIES:
  562. return db.update(ProviderTableMeta.CAPABILITIES_TABLE_NAME, values, selection, selectionArgs);
  563. case UPLOADS:
  564. return db.update(ProviderTableMeta.UPLOADS_TABLE_NAME, values, selection, selectionArgs);
  565. case SYNCED_FOLDERS:
  566. return db.update(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, values, selection, selectionArgs);
  567. case ARBITRARY_DATA:
  568. return db.update(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, values, selection, selectionArgs);
  569. case FILESYSTEM:
  570. return db.update(ProviderTableMeta.FILESYSTEM_TABLE_NAME, values, selection, selectionArgs);
  571. default:
  572. return db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs);
  573. }
  574. }
  575. @NonNull
  576. @Override
  577. public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations)
  578. throws OperationApplicationException {
  579. Log_OC.d("FileContentProvider", "applying batch in provider " + this +
  580. " (temporary: " + isTemporary() + ")");
  581. ContentProviderResult[] results = new ContentProviderResult[operations.size()];
  582. int i = 0;
  583. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  584. db.beginTransaction(); // it's supposed that transactions can be nested
  585. try {
  586. for (ContentProviderOperation operation : operations) {
  587. results[i] = operation.apply(this, results, i);
  588. i++;
  589. }
  590. db.setTransactionSuccessful();
  591. } finally {
  592. db.endTransaction();
  593. }
  594. Log_OC.d("FileContentProvider", "applied batch in provider " + this);
  595. return results;
  596. }
  597. private boolean checkIfColumnExists(SQLiteDatabase database, String table, String column) {
  598. Cursor cursor = database.rawQuery("SELECT * FROM " + table + " LIMIT 0", null);
  599. boolean exists = cursor.getColumnIndex(column) != -1;
  600. cursor.close();
  601. return exists;
  602. }
  603. private void createFilesTable(SQLiteDatabase db) {
  604. db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "("
  605. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  606. + ProviderTableMeta.FILE_NAME + TEXT
  607. + ProviderTableMeta.FILE_ENCRYPTED_NAME + TEXT
  608. + ProviderTableMeta.FILE_PATH + TEXT
  609. + ProviderTableMeta.FILE_PARENT + INTEGER
  610. + ProviderTableMeta.FILE_CREATION + INTEGER
  611. + ProviderTableMeta.FILE_MODIFIED + INTEGER
  612. + ProviderTableMeta.FILE_CONTENT_TYPE + TEXT
  613. + ProviderTableMeta.FILE_CONTENT_LENGTH + INTEGER
  614. + ProviderTableMeta.FILE_STORAGE_PATH + TEXT
  615. + ProviderTableMeta.FILE_ACCOUNT_OWNER + TEXT
  616. + ProviderTableMeta.FILE_LAST_SYNC_DATE + INTEGER
  617. + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + INTEGER
  618. + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + INTEGER
  619. + ProviderTableMeta.FILE_ETAG + TEXT
  620. + ProviderTableMeta.FILE_ETAG_ON_SERVER + TEXT
  621. + ProviderTableMeta.FILE_SHARED_VIA_LINK + INTEGER
  622. + ProviderTableMeta.FILE_PUBLIC_LINK + TEXT
  623. + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
  624. + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null,"
  625. + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + INTEGER //boolean
  626. + ProviderTableMeta.FILE_IS_DOWNLOADING + INTEGER //boolean
  627. + ProviderTableMeta.FILE_FAVORITE + INTEGER // boolean
  628. + ProviderTableMeta.FILE_IS_ENCRYPTED + INTEGER // boolean
  629. + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + TEXT
  630. + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + INTEGER
  631. + ProviderTableMeta.FILE_MOUNT_TYPE + INTEGER
  632. + ProviderTableMeta.FILE_HAS_PREVIEW + INTEGER
  633. + ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT + INTEGER
  634. + ProviderTableMeta.FILE_OWNER_ID + TEXT
  635. + ProviderTableMeta.FILE_OWNER_DISPLAY_NAME + TEXT
  636. + ProviderTableMeta.FILE_NOTE + TEXT
  637. + ProviderTableMeta.FILE_SHAREES + " TEXT);"
  638. );
  639. }
  640. private void createOCSharesTable(SQLiteDatabase db) {
  641. db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
  642. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  643. + ProviderTableMeta.OCSHARES_FILE_SOURCE + INTEGER
  644. + ProviderTableMeta.OCSHARES_ITEM_SOURCE + INTEGER
  645. + ProviderTableMeta.OCSHARES_SHARE_TYPE + INTEGER
  646. + ProviderTableMeta.OCSHARES_SHARE_WITH + TEXT
  647. + ProviderTableMeta.OCSHARES_PATH + TEXT
  648. + ProviderTableMeta.OCSHARES_PERMISSIONS + INTEGER
  649. + ProviderTableMeta.OCSHARES_SHARED_DATE + INTEGER
  650. + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + INTEGER
  651. + ProviderTableMeta.OCSHARES_TOKEN + TEXT
  652. + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + TEXT
  653. + ProviderTableMeta.OCSHARES_IS_DIRECTORY + INTEGER // boolean
  654. + ProviderTableMeta.OCSHARES_USER_ID + INTEGER
  655. + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + INTEGER
  656. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + TEXT
  657. + ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + INTEGER
  658. + ProviderTableMeta.OCSHARES_NOTE + TEXT
  659. + ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + " INTEGER );");
  660. }
  661. private void createCapabilitiesTable(SQLiteDatabase db) {
  662. db.execSQL("CREATE TABLE " + ProviderTableMeta.CAPABILITIES_TABLE_NAME + "("
  663. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  664. + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + TEXT
  665. + ProviderTableMeta.CAPABILITIES_VERSION_MAYOR + INTEGER
  666. + ProviderTableMeta.CAPABILITIES_VERSION_MINOR + INTEGER
  667. + ProviderTableMeta.CAPABILITIES_VERSION_MICRO + INTEGER
  668. + ProviderTableMeta.CAPABILITIES_VERSION_STRING + TEXT
  669. + ProviderTableMeta.CAPABILITIES_VERSION_EDITION + TEXT
  670. + ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL + INTEGER
  671. + ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED + INTEGER // boolean
  672. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED + INTEGER // boolean
  673. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED + INTEGER // boolean
  674. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED + INTEGER // boolean
  675. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS + INTEGER
  676. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED + INTEGER // boolean
  677. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL + INTEGER // boolean
  678. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD + INTEGER // boolean
  679. + ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL + INTEGER // boolean
  680. + ProviderTableMeta.CAPABILITIES_SHARING_RESHARING + INTEGER // boolean
  681. + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING + INTEGER // boolean
  682. + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING + INTEGER // boolean
  683. + ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING + INTEGER // boolean
  684. + ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + INTEGER // boolean
  685. + ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + INTEGER // boolean
  686. + ProviderTableMeta.CAPABILITIES_FILES_DROP + INTEGER // boolean
  687. + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS + INTEGER // boolean
  688. + ProviderTableMeta.CAPABILITIES_SERVER_NAME + TEXT
  689. + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + TEXT
  690. + ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + TEXT
  691. + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + TEXT
  692. + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + TEXT
  693. + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + TEXT
  694. + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + INTEGER
  695. + ProviderTableMeta.CAPABILITIES_ACTIVITY + INTEGER
  696. + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + INTEGER
  697. + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + INTEGER
  698. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT + INTEGER
  699. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST + TEXT
  700. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + INTEGER
  701. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + " INTEGER );");
  702. }
  703. private void createUploadsTable(SQLiteDatabase db) {
  704. db.execSQL("CREATE TABLE " + ProviderTableMeta.UPLOADS_TABLE_NAME + "("
  705. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  706. + ProviderTableMeta.UPLOADS_LOCAL_PATH + TEXT
  707. + ProviderTableMeta.UPLOADS_REMOTE_PATH + TEXT
  708. + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + TEXT
  709. + ProviderTableMeta.UPLOADS_FILE_SIZE + " LONG, "
  710. + ProviderTableMeta.UPLOADS_STATUS + INTEGER // UploadStatus
  711. + ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + INTEGER // Upload LocalBehaviour
  712. + ProviderTableMeta.UPLOADS_UPLOAD_TIME + INTEGER
  713. + ProviderTableMeta.UPLOADS_FORCE_OVERWRITE + INTEGER // boolean
  714. + ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + INTEGER // boolean
  715. + ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + INTEGER
  716. + ProviderTableMeta.UPLOADS_LAST_RESULT + INTEGER // Upload LastResult
  717. + ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + INTEGER // boolean
  718. + ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + INTEGER // boolean
  719. + ProviderTableMeta.UPLOADS_CREATED_BY + INTEGER // Upload createdBy
  720. + ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN + " TEXT );");
  721. /* before:
  722. // PRIMARY KEY should always imply NOT NULL. Unfortunately, due to a
  723. // bug in some early versions, this is not the case in SQLite.
  724. //db.execSQL("CREATE TABLE " + TABLE_UPLOAD + " (" + " path TEXT PRIMARY KEY NOT NULL UNIQUE,"
  725. // + " uploadStatus INTEGER NOT NULL, uploadObject TEXT NOT NULL);");
  726. // uploadStatus is used to easy filtering, it has precedence over
  727. // uploadObject.getUploadStatus()
  728. */
  729. }
  730. private void createSyncedFoldersTable(SQLiteDatabase db) {
  731. db.execSQL("CREATE TABLE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + "("
  732. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  733. + ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " TEXT, " // local path
  734. + ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH + " TEXT, " // remote path
  735. + ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY + " INTEGER, " // wifi_only
  736. + ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY + " INTEGER, " // charging only
  737. + ProviderTableMeta.SYNCED_FOLDER_ENABLED + " INTEGER, " // enabled
  738. + ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
  739. + ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " TEXT, " // account
  740. + ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION + " INTEGER, " // upload action
  741. + ProviderTableMeta.SYNCED_FOLDER_TYPE + " INTEGER );" // type
  742. );
  743. }
  744. private void createExternalLinksTable(SQLiteDatabase db) {
  745. db.execSQL("CREATE TABLE " + ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME + "("
  746. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  747. + ProviderTableMeta.EXTERNAL_LINKS_ICON_URL + " TEXT, " // icon url
  748. + ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE + " TEXT, " // language
  749. + ProviderTableMeta.EXTERNAL_LINKS_TYPE + " INTEGER, " // type
  750. + ProviderTableMeta.EXTERNAL_LINKS_NAME + " TEXT, " // name
  751. + ProviderTableMeta.EXTERNAL_LINKS_URL + " TEXT, " // url
  752. + ProviderTableMeta.EXTERNAL_LINKS_REDIRECT + " INTEGER );" // redirect
  753. );
  754. }
  755. private void createArbitraryData(SQLiteDatabase db) {
  756. db.execSQL("CREATE TABLE " + ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME + "("
  757. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  758. + ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " TEXT, " // cloud id (account name + FQDN)
  759. + ProviderTableMeta.ARBITRARY_DATA_KEY + " TEXT, " // key
  760. + ProviderTableMeta.ARBITRARY_DATA_VALUE + " TEXT );" // value
  761. );
  762. }
  763. private void createVirtualTable(SQLiteDatabase db) {
  764. db.execSQL("CREATE TABLE " + ProviderTableMeta.VIRTUAL_TABLE_NAME + "("
  765. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  766. + ProviderTableMeta.VIRTUAL_TYPE + " TEXT, " // type
  767. + ProviderTableMeta.VIRTUAL_OCFILE_ID + " INTEGER )" // file id
  768. );
  769. }
  770. private void createFileSystemTable(SQLiteDatabase db) {
  771. db.execSQL("CREATE TABLE IF NOT EXISTS " + ProviderTableMeta.FILESYSTEM_TABLE_NAME + "("
  772. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  773. + ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " TEXT, "
  774. + ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER + " INTEGER, "
  775. + ProviderTableMeta.FILESYSTEM_FILE_FOUND_RECENTLY + " LONG, "
  776. + ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD + " INTEGER, "
  777. + ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " STRING, "
  778. + ProviderTableMeta.FILESYSTEM_CRC32 + " STRING, "
  779. + ProviderTableMeta.FILESYSTEM_FILE_MODIFIED + " LONG );"
  780. );
  781. }
  782. /**
  783. * Version 10 of database does not modify its scheme. It coincides with the upgrade of the
  784. * ownCloud account names structure to include in it the path to the server instance. Updating
  785. * the account names and path to local files in the files table is a must to keep the existing
  786. * account working and the database clean.
  787. *
  788. * @param db Database where table of files is included.
  789. */
  790. private void updateAccountName(SQLiteDatabase db) {
  791. Log_OC.d(SQL, "THREAD: " + Thread.currentThread().getName());
  792. AccountManager ama = AccountManager.get(getContext());
  793. try {
  794. // get accounts from AccountManager ; we can't be sure if accounts in it are updated or not although
  795. // we know the update was previously done in {link @FileActivity#onCreate} because the changes through
  796. // AccountManager are not synchronous
  797. Account[] accounts = AccountManager.get(getContext()).getAccountsByType(MainApp.getAccountType(mContext));
  798. String serverUrl;
  799. String username;
  800. String oldAccountName;
  801. String newAccountName;
  802. String[] accountOwner = new String[1];
  803. for (Account account : accounts) {
  804. // build both old and new account name
  805. serverUrl = ama.getUserData(account, AccountUtils.Constants.KEY_OC_BASE_URL);
  806. username = AccountUtils.getUsernameForAccount(account);
  807. oldAccountName = AccountUtils.buildAccountNameOld(Uri.parse(serverUrl), username);
  808. newAccountName = AccountUtils.buildAccountName(Uri.parse(serverUrl), username);
  809. // update values in database
  810. db.beginTransaction();
  811. try {
  812. ContentValues cv = new ContentValues();
  813. cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, newAccountName);
  814. accountOwner[0] = oldAccountName;
  815. int num = db.update(ProviderTableMeta.FILE_TABLE_NAME,
  816. cv,
  817. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
  818. accountOwner);
  819. Log_OC.d(SQL, "Updated account in database: old name == " + oldAccountName +
  820. ", new name == " + newAccountName + " (" + num + " rows updated )");
  821. // update path for downloaded files
  822. updateDownloadedFiles(db, newAccountName, oldAccountName);
  823. db.setTransactionSuccessful();
  824. } catch (SQLException e) {
  825. Log_OC.e(TAG, "SQL Exception upgrading account names or paths in database", e);
  826. } finally {
  827. db.endTransaction();
  828. }
  829. }
  830. } catch (Exception e) {
  831. Log_OC.e(TAG, "Exception upgrading account names or paths in database", e);
  832. }
  833. }
  834. /**
  835. * Rename the local ownCloud folder of one account to match the a rename of the account itself.
  836. * Updates the table of files in database so that the paths to the local files keep being the
  837. * same.
  838. *
  839. * @param db Database where table of files is included.
  840. * @param newAccountName New name for the target OC account.
  841. * @param oldAccountName Old name of the target OC account.
  842. */
  843. private void updateDownloadedFiles(SQLiteDatabase db, String newAccountName,
  844. String oldAccountName) {
  845. String whereClause = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  846. ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL";
  847. Cursor c = db.query(ProviderTableMeta.FILE_TABLE_NAME,
  848. null,
  849. whereClause,
  850. new String[]{newAccountName},
  851. null, null, null);
  852. try {
  853. if (c.moveToFirst()) {
  854. // create storage path
  855. String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
  856. String newAccountPath = FileStorageUtils.getSavePath(newAccountName);
  857. // move files
  858. File oldAccountFolder = new File(oldAccountPath);
  859. File newAccountFolder = new File(newAccountPath);
  860. oldAccountFolder.renameTo(newAccountFolder);
  861. String[] storagePath = new String[1];
  862. // update database
  863. do {
  864. // Update database
  865. String oldPath = c.getString(
  866. c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
  867. OCFile file = new OCFile(
  868. c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH)));
  869. String newPath = FileStorageUtils.getDefaultSavePathFor(newAccountName, file);
  870. ContentValues cv = new ContentValues();
  871. cv.put(ProviderTableMeta.FILE_STORAGE_PATH, newPath);
  872. storagePath[0] = oldPath;
  873. db.update(ProviderTableMeta.FILE_TABLE_NAME,
  874. cv,
  875. ProviderTableMeta.FILE_STORAGE_PATH + "=?",
  876. storagePath);
  877. Log_OC.v(SQL, "Updated path of downloaded file: old file name == " + oldPath +
  878. ", new file name == " + newPath);
  879. } while (c.moveToNext());
  880. }
  881. } finally {
  882. c.close();
  883. }
  884. }
  885. private boolean isCallerNotAllowed(Uri uri) {
  886. switch (mUriMatcher.match(uri)) {
  887. case SHARES:
  888. case CAPABILITIES:
  889. case UPLOADS:
  890. case SYNCED_FOLDERS:
  891. case EXTERNAL_LINKS:
  892. case ARBITRARY_DATA:
  893. case VIRTUAL:
  894. case FILESYSTEM:
  895. String callingPackage = mContext.getPackageManager().getNameForUid(Binder.getCallingUid());
  896. return callingPackage == null || !callingPackage.equals(mContext.getPackageName());
  897. case ROOT_DIRECTORY:
  898. case SINGLE_FILE:
  899. case DIRECTORY:
  900. default:
  901. return false;
  902. }
  903. }
  904. class DataBaseHelper extends SQLiteOpenHelper {
  905. DataBaseHelper(Context context) {
  906. super(context, ProviderMeta.DB_NAME, null, ProviderMeta.DB_VERSION);
  907. }
  908. @Override
  909. public void onCreate(SQLiteDatabase db) {
  910. // files table
  911. Log_OC.i(SQL, "Entering in onCreate");
  912. createFilesTable(db);
  913. // Create OCShares table
  914. createOCSharesTable(db);
  915. // Create capabilities table
  916. createCapabilitiesTable(db);
  917. // Create uploads table
  918. createUploadsTable(db);
  919. // Create synced folders table
  920. createSyncedFoldersTable(db);
  921. // Create external links table
  922. createExternalLinksTable(db);
  923. // Create arbitrary data table
  924. createArbitraryData(db);
  925. // Create virtual table
  926. createVirtualTable(db);
  927. // Create filesystem table
  928. createFileSystemTable(db);
  929. }
  930. @Override
  931. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  932. Log_OC.i(SQL, "Entering in onUpgrade");
  933. boolean upgraded = false;
  934. if (oldVersion == 1 && newVersion >= 2) {
  935. Log_OC.i(SQL, "Entering in the #2 ADD in onUpgrade");
  936. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  937. ADD_COLUMN + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER " +
  938. " DEFAULT 0");
  939. upgraded = true;
  940. }
  941. if (oldVersion < 3 && newVersion >= 3) {
  942. Log_OC.i(SQL, "Entering in the #3 ADD in onUpgrade");
  943. db.beginTransaction();
  944. try {
  945. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  946. ADD_COLUMN + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA +
  947. " INTEGER " + " DEFAULT 0");
  948. // assume there are not local changes pending to upload
  949. db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
  950. " SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = "
  951. + System.currentTimeMillis() +
  952. " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
  953. upgraded = true;
  954. db.setTransactionSuccessful();
  955. } finally {
  956. db.endTransaction();
  957. }
  958. }
  959. if (oldVersion < 4 && newVersion >= 4) {
  960. Log_OC.i(SQL, "Entering in the #4 ADD in onUpgrade");
  961. db.beginTransaction();
  962. try {
  963. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  964. ADD_COLUMN + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA +
  965. " INTEGER " + " DEFAULT 0");
  966. db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
  967. " SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " +
  968. ProviderTableMeta.FILE_MODIFIED +
  969. " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
  970. upgraded = true;
  971. db.setTransactionSuccessful();
  972. } finally {
  973. db.endTransaction();
  974. }
  975. }
  976. if (!upgraded) {
  977. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  978. }
  979. if (oldVersion < 5 && newVersion >= 5) {
  980. Log_OC.i(SQL, "Entering in the #5 ADD in onUpgrade");
  981. db.beginTransaction();
  982. try {
  983. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  984. ADD_COLUMN + ProviderTableMeta.FILE_ETAG + " TEXT " +
  985. " DEFAULT NULL");
  986. upgraded = true;
  987. db.setTransactionSuccessful();
  988. } finally {
  989. db.endTransaction();
  990. }
  991. }
  992. if (!upgraded) {
  993. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  994. }
  995. if (oldVersion < 6 && newVersion >= 6) {
  996. Log_OC.i(SQL, "Entering in the #6 ADD in onUpgrade");
  997. db.beginTransaction();
  998. try {
  999. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1000. ADD_COLUMN + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER " +
  1001. " DEFAULT 0");
  1002. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1003. ADD_COLUMN + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT " +
  1004. " DEFAULT NULL");
  1005. // Create table OCShares
  1006. createOCSharesTable(db);
  1007. upgraded = true;
  1008. db.setTransactionSuccessful();
  1009. } finally {
  1010. db.endTransaction();
  1011. }
  1012. }
  1013. if (!upgraded) {
  1014. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1015. }
  1016. if (oldVersion < 7 && newVersion >= 7) {
  1017. Log_OC.i(SQL, "Entering in the #7 ADD in onUpgrade");
  1018. db.beginTransaction();
  1019. try {
  1020. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1021. ADD_COLUMN + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
  1022. " DEFAULT NULL");
  1023. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1024. ADD_COLUMN + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " +
  1025. " DEFAULT NULL");
  1026. upgraded = true;
  1027. db.setTransactionSuccessful();
  1028. } finally {
  1029. db.endTransaction();
  1030. }
  1031. }
  1032. if (!upgraded) {
  1033. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1034. }
  1035. if (oldVersion < 8 && newVersion >= 8) {
  1036. Log_OC.i(SQL, "Entering in the #8 ADD in onUpgrade");
  1037. db.beginTransaction();
  1038. try {
  1039. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1040. ADD_COLUMN + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER " +
  1041. " DEFAULT 0");
  1042. upgraded = true;
  1043. db.setTransactionSuccessful();
  1044. } finally {
  1045. db.endTransaction();
  1046. }
  1047. }
  1048. if (!upgraded) {
  1049. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1050. }
  1051. if (oldVersion < 9 && newVersion >= 9) {
  1052. Log_OC.i(SQL, "Entering in the #9 ADD in onUpgrade");
  1053. db.beginTransaction();
  1054. try {
  1055. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1056. ADD_COLUMN + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER " +
  1057. " DEFAULT 0");
  1058. upgraded = true;
  1059. db.setTransactionSuccessful();
  1060. } finally {
  1061. db.endTransaction();
  1062. }
  1063. }
  1064. if (!upgraded) {
  1065. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1066. }
  1067. if (oldVersion < 10 && newVersion >= 10) {
  1068. Log_OC.i(SQL, "Entering in the #10 ADD in onUpgrade");
  1069. updateAccountName(db);
  1070. upgraded = true;
  1071. }
  1072. if (!upgraded) {
  1073. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1074. }
  1075. if (oldVersion < 11 && newVersion >= 11) {
  1076. Log_OC.i(SQL, "Entering in the #11 ADD in onUpgrade");
  1077. db.beginTransaction();
  1078. try {
  1079. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1080. ADD_COLUMN + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT " +
  1081. " DEFAULT NULL");
  1082. upgraded = true;
  1083. db.setTransactionSuccessful();
  1084. } finally {
  1085. db.endTransaction();
  1086. }
  1087. }
  1088. if (!upgraded) {
  1089. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1090. }
  1091. if (oldVersion < 12 && newVersion >= 12) {
  1092. Log_OC.i(SQL, "Entering in the #12 ADD in onUpgrade");
  1093. db.beginTransaction();
  1094. try {
  1095. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1096. ADD_COLUMN + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER " +
  1097. " DEFAULT 0");
  1098. upgraded = true;
  1099. db.setTransactionSuccessful();
  1100. } finally {
  1101. db.endTransaction();
  1102. }
  1103. }
  1104. if (!upgraded) {
  1105. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1106. }
  1107. if (oldVersion < 13 && newVersion >= 13) {
  1108. Log_OC.i(SQL, "Entering in the #13 ADD in onUpgrade");
  1109. db.beginTransaction();
  1110. try {
  1111. // Create capabilities table
  1112. createCapabilitiesTable(db);
  1113. upgraded = true;
  1114. db.setTransactionSuccessful();
  1115. } finally {
  1116. db.endTransaction();
  1117. }
  1118. }
  1119. if (oldVersion < 14 && newVersion >= 14) {
  1120. Log_OC.i(SQL, "Entering in the #14 ADD in onUpgrade");
  1121. db.beginTransaction();
  1122. try {
  1123. // drop old instant_upload table
  1124. db.execSQL("DROP TABLE IF EXISTS " + "instant_upload" + ";");
  1125. // Create uploads table
  1126. createUploadsTable(db);
  1127. upgraded = true;
  1128. db.setTransactionSuccessful();
  1129. } finally {
  1130. db.endTransaction();
  1131. }
  1132. }
  1133. if (oldVersion < 15 && newVersion >= 15) {
  1134. Log_OC.i(SQL, "Entering in the #15 ADD in onUpgrade");
  1135. db.beginTransaction();
  1136. try {
  1137. // drop old capabilities table
  1138. db.execSQL("DROP TABLE IF EXISTS " + "capabilities" + ";");
  1139. // Create uploads table
  1140. createCapabilitiesTable(db);
  1141. upgraded = true;
  1142. db.setTransactionSuccessful();
  1143. } finally {
  1144. db.endTransaction();
  1145. }
  1146. }
  1147. if (oldVersion < 16 && newVersion >= 16) {
  1148. Log_OC.i(SQL, "Entering in the #16 ADD synced folders table");
  1149. db.beginTransaction();
  1150. try {
  1151. // Create synced folders table
  1152. createSyncedFoldersTable(db);
  1153. upgraded = true;
  1154. db.setTransactionSuccessful();
  1155. } finally {
  1156. db.endTransaction();
  1157. }
  1158. }
  1159. if (!upgraded) {
  1160. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1161. }
  1162. if (oldVersion < 17 && newVersion >= 17) {
  1163. Log_OC.i(SQL, "Entering in the #17 ADD in onUpgrade");
  1164. db.beginTransaction();
  1165. try {
  1166. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1167. ADD_COLUMN + ProviderTableMeta.FILE_FAVORITE +
  1168. " INTEGER " + " DEFAULT 0");
  1169. upgraded = true;
  1170. db.setTransactionSuccessful();
  1171. } finally {
  1172. db.endTransaction();
  1173. }
  1174. }
  1175. if (!upgraded) {
  1176. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1177. }
  1178. if (oldVersion < 18 && newVersion >= 18) {
  1179. Log_OC.i(SQL, "Entering in the #18 Adding external link column to capabilities");
  1180. db.beginTransaction();
  1181. try {
  1182. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1183. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS +
  1184. " INTEGER " + " DEFAULT -1");
  1185. upgraded = true;
  1186. db.setTransactionSuccessful();
  1187. } finally {
  1188. db.endTransaction();
  1189. }
  1190. }
  1191. if (!upgraded) {
  1192. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1193. }
  1194. if (oldVersion < 19 && newVersion >= 19) {
  1195. Log_OC.i(SQL, "Entering in the #19 Adding external link column to capabilities");
  1196. db.beginTransaction();
  1197. try {
  1198. createExternalLinksTable(db);
  1199. upgraded = true;
  1200. db.setTransactionSuccessful();
  1201. } finally {
  1202. db.endTransaction();
  1203. }
  1204. }
  1205. if (!upgraded) {
  1206. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1207. }
  1208. if (oldVersion < 20 && newVersion >= 20) {
  1209. Log_OC.i(SQL, "Entering in the #20 Adding arbitrary data table");
  1210. db.beginTransaction();
  1211. try {
  1212. createArbitraryData(db);
  1213. upgraded = true;
  1214. db.setTransactionSuccessful();
  1215. } finally {
  1216. db.endTransaction();
  1217. }
  1218. }
  1219. if (!upgraded) {
  1220. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1221. }
  1222. if (oldVersion < 21 && newVersion >= 21) {
  1223. Log_OC.i(SQL, "Entering in the #21 Adding virtual table");
  1224. db.beginTransaction();
  1225. try {
  1226. createVirtualTable(db);
  1227. upgraded = true;
  1228. db.setTransactionSuccessful();
  1229. } finally {
  1230. db.endTransaction();
  1231. }
  1232. }
  1233. if (!upgraded) {
  1234. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1235. }
  1236. if (oldVersion < 22 && newVersion >= 22) {
  1237. Log_OC.i(SQL, "Entering in the #22 Adding user theming to capabilities table");
  1238. db.beginTransaction();
  1239. try {
  1240. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1241. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
  1242. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1243. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
  1244. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1245. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
  1246. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1247. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
  1248. upgraded = true;
  1249. db.setTransactionSuccessful();
  1250. } finally {
  1251. db.endTransaction();
  1252. }
  1253. }
  1254. if (!upgraded) {
  1255. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1256. }
  1257. if (oldVersion < 23 && newVersion >= 23) {
  1258. Log_OC.i(SQL, "Entering in the #23 adding type column for synced folders, Create filesystem table");
  1259. db.beginTransaction();
  1260. try {
  1261. // add type column default being CUSTOM (0)
  1262. if (!checkIfColumnExists(db, ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME,
  1263. ProviderTableMeta.SYNCED_FOLDER_TYPE)) {
  1264. Log_OC.i(SQL, "Add type column and default value 0 (CUSTOM) to synced_folders table");
  1265. db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
  1266. ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_TYPE +
  1267. " INTEGER " + " DEFAULT 0");
  1268. } else {
  1269. Log_OC.i(SQL, "Type column of synced_folders table already exists");
  1270. }
  1271. if (!checkIfColumnExists(db, ProviderTableMeta.UPLOADS_TABLE_NAME,
  1272. ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)) {
  1273. Log_OC.i(SQL, "Add charging and wifi columns to uploads");
  1274. db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
  1275. ADD_COLUMN + ProviderTableMeta.UPLOADS_IS_WIFI_ONLY +
  1276. " INTEGER " + " DEFAULT 0");
  1277. } else {
  1278. Log_OC.i(SQL, "Wifi column of uploads table already exists");
  1279. }
  1280. if (!checkIfColumnExists(db, ProviderTableMeta.UPLOADS_TABLE_NAME,
  1281. ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY)) {
  1282. db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
  1283. ADD_COLUMN + ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY +
  1284. " INTEGER " + " DEFAULT 0");
  1285. } else {
  1286. Log_OC.i(SQL, "Charging column of uploads table already exists");
  1287. }
  1288. // create Filesystem table
  1289. Log_OC.i(SQL, "Create filesystem table");
  1290. createFileSystemTable(db);
  1291. upgraded = true;
  1292. db.setTransactionSuccessful();
  1293. } catch (Throwable t) {
  1294. Log_OC.e(TAG, "ERROR!", t);
  1295. } finally {
  1296. db.endTransaction();
  1297. }
  1298. }
  1299. if (!upgraded) {
  1300. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1301. }
  1302. if (oldVersion < 24 && newVersion >= 24) {
  1303. Log_OC.i(SQL, "Entering in the #24 Re-adding user theming to capabilities table");
  1304. db.beginTransaction();
  1305. try {
  1306. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1307. ProviderTableMeta.CAPABILITIES_SERVER_NAME)) {
  1308. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1309. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
  1310. }
  1311. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1312. ProviderTableMeta.CAPABILITIES_SERVER_COLOR)) {
  1313. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1314. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
  1315. }
  1316. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1317. ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL)) {
  1318. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1319. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
  1320. }
  1321. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1322. ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN)) {
  1323. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1324. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
  1325. }
  1326. upgraded = true;
  1327. db.setTransactionSuccessful();
  1328. } finally {
  1329. db.endTransaction();
  1330. }
  1331. }
  1332. if (!upgraded) {
  1333. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1334. }
  1335. if (oldVersion < 25 && newVersion >= 25) {
  1336. Log_OC.i(SQL, "Entering in the #25 Adding encryption flag to file");
  1337. db.beginTransaction();
  1338. try {
  1339. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1340. ADD_COLUMN + ProviderTableMeta.FILE_IS_ENCRYPTED + " INTEGER ");
  1341. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1342. ADD_COLUMN + ProviderTableMeta.FILE_ENCRYPTED_NAME + " TEXT ");
  1343. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1344. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + " INTEGER ");
  1345. upgraded = true;
  1346. db.setTransactionSuccessful();
  1347. } finally {
  1348. db.endTransaction();
  1349. }
  1350. }
  1351. if (!upgraded) {
  1352. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1353. }
  1354. if (oldVersion < 26 && newVersion >= 26) {
  1355. Log_OC.i(SQL, "Entering in the #26 Adding text and element color to capabilities");
  1356. db.beginTransaction();
  1357. try {
  1358. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1359. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + " TEXT ");
  1360. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1361. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + " TEXT ");
  1362. upgraded = true;
  1363. db.setTransactionSuccessful();
  1364. } finally {
  1365. db.endTransaction();
  1366. }
  1367. }
  1368. if (!upgraded) {
  1369. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1370. }
  1371. if (!upgraded) {
  1372. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1373. }
  1374. if (oldVersion < 27 && newVersion >= 27) {
  1375. Log_OC.i(SQL, "Entering in the #27 Adding token to ocUpload");
  1376. db.beginTransaction();
  1377. try {
  1378. db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
  1379. ADD_COLUMN + ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN + " TEXT ");
  1380. upgraded = true;
  1381. db.setTransactionSuccessful();
  1382. } finally {
  1383. db.endTransaction();
  1384. }
  1385. }
  1386. if (!upgraded) {
  1387. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1388. }
  1389. if (oldVersion < 28 && newVersion >= 28) {
  1390. Log_OC.i(SQL, "Entering in the #28 Adding CRC32 column to filesystem table");
  1391. db.beginTransaction();
  1392. try {
  1393. if (!checkIfColumnExists(db, ProviderTableMeta.FILESYSTEM_TABLE_NAME,
  1394. ProviderTableMeta.FILESYSTEM_CRC32)) {
  1395. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILESYSTEM_TABLE_NAME +
  1396. ADD_COLUMN + ProviderTableMeta.FILESYSTEM_CRC32 + " TEXT ");
  1397. }
  1398. upgraded = true;
  1399. db.setTransactionSuccessful();
  1400. } finally {
  1401. db.endTransaction();
  1402. }
  1403. }
  1404. if (!upgraded) {
  1405. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1406. }
  1407. if (oldVersion < 29 && newVersion >= 29) {
  1408. Log_OC.i(SQL, "Entering in the #29 Adding background default/plain to capabilities");
  1409. db.beginTransaction();
  1410. try {
  1411. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1412. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + " INTEGER ");
  1413. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1414. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + " INTEGER ");
  1415. upgraded = true;
  1416. db.setTransactionSuccessful();
  1417. } finally {
  1418. db.endTransaction();
  1419. }
  1420. }
  1421. if (!upgraded) {
  1422. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1423. }
  1424. if (oldVersion < 30 && newVersion >= 30) {
  1425. Log_OC.i(SQL, "Entering in the #30 Re-add 25, 26 if needed");
  1426. db.beginTransaction();
  1427. try {
  1428. if (!checkIfColumnExists(db, ProviderTableMeta.FILE_TABLE_NAME,
  1429. ProviderTableMeta.FILE_IS_ENCRYPTED)) {
  1430. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1431. ADD_COLUMN + ProviderTableMeta.FILE_IS_ENCRYPTED + " INTEGER ");
  1432. }
  1433. if (!checkIfColumnExists(db, ProviderTableMeta.FILE_TABLE_NAME,
  1434. ProviderTableMeta.FILE_ENCRYPTED_NAME)) {
  1435. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1436. ADD_COLUMN + ProviderTableMeta.FILE_ENCRYPTED_NAME + " TEXT ");
  1437. }
  1438. if (oldVersion > ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION) {
  1439. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1440. ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION)) {
  1441. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1442. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + " INTEGER ");
  1443. }
  1444. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1445. ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR)) {
  1446. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1447. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + " TEXT ");
  1448. }
  1449. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1450. ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR)) {
  1451. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1452. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + " TEXT ");
  1453. }
  1454. if (!checkIfColumnExists(db, ProviderTableMeta.FILESYSTEM_TABLE_NAME,
  1455. ProviderTableMeta.FILESYSTEM_CRC32)) {
  1456. try {
  1457. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILESYSTEM_TABLE_NAME +
  1458. ADD_COLUMN + ProviderTableMeta.FILESYSTEM_CRC32 + " TEXT ");
  1459. } catch (SQLiteException e) {
  1460. Log_OC.d(TAG, "Known problem on adding same column twice when upgrading from 24->30");
  1461. }
  1462. }
  1463. }
  1464. upgraded = true;
  1465. db.setTransactionSuccessful();
  1466. } finally {
  1467. db.endTransaction();
  1468. }
  1469. }
  1470. if (!upgraded) {
  1471. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1472. }
  1473. if (oldVersion < 31 && newVersion >= 31) {
  1474. Log_OC.i(SQL, "Entering in the #31 add mount type");
  1475. db.beginTransaction();
  1476. try {
  1477. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1478. ADD_COLUMN + ProviderTableMeta.FILE_MOUNT_TYPE + " INTEGER ");
  1479. upgraded = true;
  1480. db.setTransactionSuccessful();
  1481. } finally {
  1482. db.endTransaction();
  1483. }
  1484. }
  1485. if (!upgraded) {
  1486. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1487. }
  1488. if (oldVersion < 32 && newVersion >= 32) {
  1489. Log_OC.i(SQL, "Entering in the #32 add ocshares.is_password_protected");
  1490. db.beginTransaction();
  1491. try {
  1492. db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
  1493. ADD_COLUMN + ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + " INTEGER "); // boolean
  1494. upgraded = true;
  1495. db.setTransactionSuccessful();
  1496. } finally {
  1497. db.endTransaction();
  1498. }
  1499. }
  1500. if (!upgraded) {
  1501. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1502. }
  1503. if (oldVersion < 33 && newVersion >= 33) {
  1504. Log_OC.i(SQL, "Entering in the #3 Adding activity to capability");
  1505. db.beginTransaction();
  1506. try {
  1507. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1508. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_ACTIVITY + " INTEGER ");
  1509. upgraded = true;
  1510. db.setTransactionSuccessful();
  1511. } finally {
  1512. db.endTransaction();
  1513. }
  1514. }
  1515. if (!upgraded) {
  1516. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1517. }
  1518. if (oldVersion < 34 && newVersion >= 34) {
  1519. Log_OC.i(SQL, "Entering in the #34 add redirect to external links");
  1520. db.beginTransaction();
  1521. try {
  1522. if (!checkIfColumnExists(db, ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME,
  1523. ProviderTableMeta.EXTERNAL_LINKS_REDIRECT)) {
  1524. db.execSQL(ALTER_TABLE + ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME +
  1525. ADD_COLUMN + ProviderTableMeta.EXTERNAL_LINKS_REDIRECT + " INTEGER "); // boolean
  1526. }
  1527. upgraded = true;
  1528. db.setTransactionSuccessful();
  1529. } finally {
  1530. db.endTransaction();
  1531. }
  1532. }
  1533. if (!upgraded) {
  1534. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1535. }
  1536. if (oldVersion < 35 && newVersion >= 35) {
  1537. Log_OC.i(SQL, "Entering in the #35 add note to share table");
  1538. db.beginTransaction();
  1539. try {
  1540. db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
  1541. ADD_COLUMN + ProviderTableMeta.OCSHARES_NOTE + " TEXT ");
  1542. upgraded = true;
  1543. db.setTransactionSuccessful();
  1544. } finally {
  1545. db.endTransaction();
  1546. }
  1547. }
  1548. if (!upgraded) {
  1549. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1550. }
  1551. if (oldVersion < 36 && newVersion >= 36) {
  1552. Log_OC.i(SQL, "Entering in the #36 add has-preview to file table");
  1553. db.beginTransaction();
  1554. try {
  1555. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1556. ADD_COLUMN + ProviderTableMeta.FILE_HAS_PREVIEW + " INTEGER ");
  1557. upgraded = true;
  1558. db.setTransactionSuccessful();
  1559. } finally {
  1560. db.endTransaction();
  1561. }
  1562. }
  1563. if (!upgraded) {
  1564. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1565. }
  1566. if (oldVersion < 37 && newVersion >= 37) {
  1567. Log_OC.i(SQL, "Entering in the #37 add hide-download to share table");
  1568. db.beginTransaction();
  1569. try {
  1570. db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
  1571. ADD_COLUMN + ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + " INTEGER ");
  1572. upgraded = true;
  1573. db.setTransactionSuccessful();
  1574. } finally {
  1575. db.endTransaction();
  1576. }
  1577. }
  1578. if (!upgraded) {
  1579. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1580. }
  1581. if (oldVersion < 38 && newVersion >= 38) {
  1582. Log_OC.i(SQL, "Entering in the #38 add richdocuments");
  1583. db.beginTransaction();
  1584. try {
  1585. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1586. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT + " INTEGER "); // boolean
  1587. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1588. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST + " TEXT "); // string
  1589. upgraded = true;
  1590. db.setTransactionSuccessful();
  1591. } finally {
  1592. db.endTransaction();
  1593. }
  1594. }
  1595. if (!upgraded) {
  1596. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1597. }
  1598. if (oldVersion < 39 && newVersion >= 39) {
  1599. Log_OC.i(SQL, "Entering in the #39 add richdocuments direct editing");
  1600. db.beginTransaction();
  1601. try {
  1602. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1603. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + " INTEGER "); // bool
  1604. upgraded = true;
  1605. db.setTransactionSuccessful();
  1606. } finally {
  1607. db.endTransaction();
  1608. }
  1609. }
  1610. if (!upgraded) {
  1611. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1612. }
  1613. if (oldVersion < 40 && newVersion >= 40) {
  1614. Log_OC.i(SQL, "Entering in the #40 add unreadCommentsCount to file table");
  1615. db.beginTransaction();
  1616. try {
  1617. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1618. ADD_COLUMN + ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT + " INTEGER ");
  1619. upgraded = true;
  1620. db.setTransactionSuccessful();
  1621. } finally {
  1622. db.endTransaction();
  1623. }
  1624. }
  1625. if (!upgraded) {
  1626. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1627. }
  1628. if (oldVersion < 41 && newVersion >= 41) {
  1629. Log_OC.i(SQL, "Entering in the #41 add eTagOnServer");
  1630. db.beginTransaction();
  1631. try {
  1632. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1633. ADD_COLUMN + ProviderTableMeta.FILE_ETAG_ON_SERVER + " TEXT ");
  1634. upgraded = true;
  1635. db.setTransactionSuccessful();
  1636. } finally {
  1637. db.endTransaction();
  1638. }
  1639. }
  1640. if (!upgraded) {
  1641. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1642. }
  1643. if (oldVersion < 42 && newVersion >= 42) {
  1644. Log_OC.i(SQL, "Entering in the #42 add richDocuments templates");
  1645. db.beginTransaction();
  1646. try {
  1647. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1648. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + " INTEGER ");
  1649. upgraded = true;
  1650. db.setTransactionSuccessful();
  1651. } finally {
  1652. db.endTransaction();
  1653. }
  1654. }
  1655. if (!upgraded) {
  1656. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1657. }
  1658. if (oldVersion < 43 && newVersion >= 43) {
  1659. Log_OC.i(SQL, "Entering in the #43 add ownerId and owner display name to file table");
  1660. db.beginTransaction();
  1661. try {
  1662. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1663. ADD_COLUMN + ProviderTableMeta.FILE_OWNER_ID + " TEXT ");
  1664. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1665. ADD_COLUMN + ProviderTableMeta.FILE_OWNER_DISPLAY_NAME + " TEXT ");
  1666. upgraded = true;
  1667. db.setTransactionSuccessful();
  1668. } finally {
  1669. db.endTransaction();
  1670. }
  1671. }
  1672. if (!upgraded) {
  1673. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1674. }
  1675. if (oldVersion < 44 && newVersion >= 44) {
  1676. Log_OC.i(SQL, "Entering in the #44 add note to file table");
  1677. db.beginTransaction();
  1678. try {
  1679. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1680. ADD_COLUMN + ProviderTableMeta.FILE_NOTE + " TEXT ");
  1681. upgraded = true;
  1682. db.setTransactionSuccessful();
  1683. } finally {
  1684. db.endTransaction();
  1685. }
  1686. }
  1687. if (!upgraded) {
  1688. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1689. }
  1690. if (oldVersion < 45 && newVersion >= 45) {
  1691. Log_OC.i(SQL, "Entering in the #45 add sharees to file table");
  1692. db.beginTransaction();
  1693. try {
  1694. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1695. ADD_COLUMN + ProviderTableMeta.FILE_SHAREES + " TEXT ");
  1696. upgraded = true;
  1697. db.setTransactionSuccessful();
  1698. } finally {
  1699. db.endTransaction();
  1700. }
  1701. }
  1702. if (!upgraded) {
  1703. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1704. }
  1705. }
  1706. @Override
  1707. public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  1708. if (oldVersion == 25 && newVersion == 24) {
  1709. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1710. REMOVE_COLUMN + ProviderTableMeta.FILE_IS_ENCRYPTED);
  1711. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1712. REMOVE_COLUMN + ProviderTableMeta.FILE_ENCRYPTED_NAME);
  1713. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1714. REMOVE_COLUMN + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION);
  1715. }
  1716. }
  1717. }
  1718. }