FileContentProvider.java 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494
  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.nextcloud.client.core.Clock;
  43. import com.owncloud.android.MainApp;
  44. import com.owncloud.android.R;
  45. import com.owncloud.android.datamodel.OCFile;
  46. import com.owncloud.android.datamodel.SyncedFolder;
  47. import com.owncloud.android.db.ProviderMeta;
  48. import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
  49. import com.owncloud.android.files.services.NameCollisionPolicy;
  50. import com.owncloud.android.lib.common.accounts.AccountUtils;
  51. import com.owncloud.android.lib.common.utils.Log_OC;
  52. import com.owncloud.android.lib.resources.shares.ShareType;
  53. import com.owncloud.android.utils.FileStorageUtils;
  54. import com.owncloud.android.utils.MimeType;
  55. import java.io.File;
  56. import java.util.ArrayList;
  57. import java.util.Collections;
  58. import java.util.HashMap;
  59. import java.util.Locale;
  60. import java.util.Map;
  61. import javax.inject.Inject;
  62. import androidx.annotation.NonNull;
  63. import androidx.annotation.Nullable;
  64. import androidx.annotation.VisibleForTesting;
  65. import dagger.android.AndroidInjection;
  66. import third_parties.aosp.SQLiteTokenizer;
  67. /**
  68. * The ContentProvider for the ownCloud App.
  69. */
  70. @SuppressWarnings("PMD.AvoidDuplicateLiterals")
  71. public class FileContentProvider extends ContentProvider {
  72. private static final int SINGLE_FILE = 1;
  73. private static final int DIRECTORY = 2;
  74. private static final int ROOT_DIRECTORY = 3;
  75. private static final int SHARES = 4;
  76. private static final int CAPABILITIES = 5;
  77. private static final int UPLOADS = 6;
  78. private static final int SYNCED_FOLDERS = 7;
  79. private static final int EXTERNAL_LINKS = 8;
  80. private static final int ARBITRARY_DATA = 9;
  81. private static final int VIRTUAL = 10;
  82. private static final int FILESYSTEM = 11;
  83. private static final String TAG = FileContentProvider.class.getSimpleName();
  84. // todo avoid string concatenation and use string formatting instead later.
  85. private static final String ERROR = "ERROR ";
  86. private static final String SQL = "SQL";
  87. private static final String INTEGER = " INTEGER, ";
  88. private static final String TEXT = " TEXT, ";
  89. private static final String ALTER_TABLE = "ALTER TABLE ";
  90. private static final String ADD_COLUMN = " ADD COLUMN ";
  91. private static final String UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";
  92. private static final int SINGLE_PATH_SEGMENT = 1;
  93. public static final int ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION = 20;
  94. public static final int MINIMUM_PATH_SEGMENTS_SIZE = 1;
  95. private static final String[] PROJECTION_CONTENT_TYPE = new String[]{
  96. ProviderTableMeta._ID, ProviderTableMeta.FILE_CONTENT_TYPE
  97. };
  98. private static final String[] PROJECTION_REMOTE_ID = new String[]{
  99. ProviderTableMeta._ID, ProviderTableMeta.FILE_REMOTE_ID
  100. };
  101. private static final String[] PROJECTION_FILE_AND_STORAGE_PATH = new String[]{
  102. ProviderTableMeta._ID, ProviderTableMeta.FILE_STORAGE_PATH, ProviderTableMeta.FILE_PATH
  103. };
  104. private static final String[] PROJECTION_FILE_PATH_AND_OWNER = new String[]{
  105. ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, ProviderTableMeta.FILE_ACCOUNT_OWNER
  106. };
  107. private static final Map<String, String> FILE_PROJECTION_MAP;
  108. static {
  109. HashMap<String,String> tempMap = new HashMap<>();
  110. for (String projection : ProviderTableMeta.FILE_ALL_COLUMNS) {
  111. tempMap.put(projection, projection);
  112. }
  113. FILE_PROJECTION_MAP = Collections.unmodifiableMap(tempMap);
  114. }
  115. @Inject protected Clock clock;
  116. private DataBaseHelper mDbHelper;
  117. private Context mContext;
  118. private UriMatcher mUriMatcher;
  119. @Override
  120. public int delete(@NonNull Uri uri, String where, String[] whereArgs) {
  121. if (isCallerNotAllowed(uri)) {
  122. return -1;
  123. }
  124. int count;
  125. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  126. db.beginTransaction();
  127. try {
  128. count = delete(db, uri, where, whereArgs);
  129. db.setTransactionSuccessful();
  130. } finally {
  131. db.endTransaction();
  132. }
  133. mContext.getContentResolver().notifyChange(uri, null);
  134. return count;
  135. }
  136. private int delete(SQLiteDatabase db, Uri uri, String where, String... whereArgs) {
  137. if (isCallerNotAllowed(uri)) {
  138. return -1;
  139. }
  140. // verify where for public paths
  141. switch (mUriMatcher.match(uri)) {
  142. case ROOT_DIRECTORY:
  143. case SINGLE_FILE:
  144. case DIRECTORY:
  145. VerificationUtils.verifyWhere(where);
  146. }
  147. int count;
  148. switch (mUriMatcher.match(uri)) {
  149. case SINGLE_FILE:
  150. count = deleteSingleFile(db, uri, where, whereArgs);
  151. break;
  152. case DIRECTORY:
  153. count = deleteDirectory(db, uri, where, whereArgs);
  154. break;
  155. case ROOT_DIRECTORY:
  156. count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs);
  157. break;
  158. case SHARES:
  159. count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs);
  160. break;
  161. case CAPABILITIES:
  162. count = db.delete(ProviderTableMeta.CAPABILITIES_TABLE_NAME, where, whereArgs);
  163. break;
  164. case UPLOADS:
  165. count = db.delete(ProviderTableMeta.UPLOADS_TABLE_NAME, where, whereArgs);
  166. break;
  167. case SYNCED_FOLDERS:
  168. count = db.delete(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, where, whereArgs);
  169. break;
  170. case EXTERNAL_LINKS:
  171. count = db.delete(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, where, whereArgs);
  172. break;
  173. case ARBITRARY_DATA:
  174. count = db.delete(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, where, whereArgs);
  175. break;
  176. case VIRTUAL:
  177. count = db.delete(ProviderTableMeta.VIRTUAL_TABLE_NAME, where, whereArgs);
  178. break;
  179. case FILESYSTEM:
  180. count = db.delete(ProviderTableMeta.FILESYSTEM_TABLE_NAME, where, whereArgs);
  181. break;
  182. default:
  183. throw new IllegalArgumentException(String.format(Locale.US, "Unknown uri: %s", uri.toString()));
  184. }
  185. return count;
  186. }
  187. private int deleteDirectory(SQLiteDatabase db, Uri uri, String where, String... whereArgs) {
  188. int count = 0;
  189. Cursor children = query(uri, PROJECTION_CONTENT_TYPE, null, null, null);
  190. if (children != null) {
  191. if (children.moveToFirst()) {
  192. long childId;
  193. boolean isDir;
  194. while (!children.isAfterLast()) {
  195. childId = children.getLong(children.getColumnIndexOrThrow(ProviderTableMeta._ID));
  196. isDir = MimeType.DIRECTORY.equals(children.getString(
  197. children.getColumnIndexOrThrow(ProviderTableMeta.FILE_CONTENT_TYPE)
  198. ));
  199. if (isDir) {
  200. count += delete(db, ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
  201. null, (String[]) null);
  202. } else {
  203. count += delete(db, ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
  204. null, (String[]) null);
  205. }
  206. children.moveToNext();
  207. }
  208. }
  209. children.close();
  210. }
  211. if (uri.getPathSegments().size() > MINIMUM_PATH_SEGMENTS_SIZE) {
  212. count += deleteWithuri(db, uri, where, whereArgs);
  213. }
  214. return count;
  215. }
  216. private int deleteSingleFile(SQLiteDatabase db, Uri uri, String where, String... whereArgs) {
  217. int count = 0;
  218. Cursor c = query(db, uri, PROJECTION_REMOTE_ID, where, whereArgs, null);
  219. String remoteId = "";
  220. try {
  221. if (c != null && c.moveToFirst()) {
  222. remoteId = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.FILE_REMOTE_ID));
  223. }
  224. Log_OC.d(TAG, "Removing FILE " + remoteId);
  225. if (remoteId == null) {
  226. return 0;
  227. } else {
  228. count = deleteWithuri(db, uri, where, whereArgs);
  229. }
  230. } catch (Exception e) {
  231. Log_OC.d(TAG, "DB-Error removing file!", e);
  232. } finally {
  233. if (c != null) {
  234. c.close();
  235. }
  236. }
  237. return count;
  238. }
  239. private int deleteWithuri(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) {
  240. final String[] argsWithUri = VerificationUtils.prependUriFirstSegmentToSelectionArgs(whereArgs, uri);
  241. return db.delete(ProviderTableMeta.FILE_TABLE_NAME,
  242. ProviderTableMeta._ID + "=?"
  243. + (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""), argsWithUri);
  244. }
  245. @Override
  246. public String getType(@NonNull Uri uri) {
  247. switch (mUriMatcher.match(uri)) {
  248. case ROOT_DIRECTORY:
  249. return ProviderTableMeta.CONTENT_TYPE;
  250. case SINGLE_FILE:
  251. return ProviderTableMeta.CONTENT_TYPE_ITEM;
  252. default:
  253. throw new IllegalArgumentException(String.format(Locale.US, "Unknown Uri id: %s", uri));
  254. }
  255. }
  256. @Override
  257. public Uri insert(@NonNull Uri uri, ContentValues values) {
  258. if (isCallerNotAllowed(uri)) {
  259. return null;
  260. }
  261. Uri newUri;
  262. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  263. db.beginTransaction();
  264. try {
  265. newUri = insert(db, uri, values);
  266. db.setTransactionSuccessful();
  267. } finally {
  268. db.endTransaction();
  269. }
  270. mContext.getContentResolver().notifyChange(newUri, null);
  271. return newUri;
  272. }
  273. private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) {
  274. // verify only for those requests that are not internal (files table)
  275. switch (mUriMatcher.match(uri)) {
  276. case ROOT_DIRECTORY:
  277. case SINGLE_FILE:
  278. case DIRECTORY:
  279. VerificationUtils.verifyColumns(values);
  280. break;
  281. }
  282. switch (mUriMatcher.match(uri)) {
  283. case ROOT_DIRECTORY:
  284. case SINGLE_FILE:
  285. String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
  286. String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
  287. String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
  288. String[] whereArgs = {remotePath, accountName};
  289. Cursor doubleCheck = query(db, uri, PROJECTION_FILE_PATH_AND_OWNER, where, whereArgs, null);
  290. // ugly patch; serious refactoring is needed to reduce work in
  291. // FileDataStorageManager and bring it to FileContentProvider
  292. if (!doubleCheck.moveToFirst()) {
  293. doubleCheck.close();
  294. long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
  295. if (rowId > 0) {
  296. return ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
  297. } else {
  298. throw new SQLException(ERROR + uri);
  299. }
  300. } else {
  301. // file is already inserted; race condition, let's avoid a duplicated entry
  302. Uri insertedFileUri = ContentUris.withAppendedId(
  303. ProviderTableMeta.CONTENT_URI_FILE,
  304. doubleCheck.getLong(doubleCheck.getColumnIndexOrThrow(ProviderTableMeta._ID))
  305. );
  306. doubleCheck.close();
  307. return insertedFileUri;
  308. }
  309. case SHARES:
  310. Uri insertedShareUri;
  311. long idShares = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
  312. if (idShares > 0) {
  313. insertedShareUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, idShares);
  314. } else {
  315. throw new SQLException(ERROR + uri);
  316. }
  317. updateFilesTableAccordingToShareInsertion(db, values);
  318. return insertedShareUri;
  319. case CAPABILITIES:
  320. Uri insertedCapUri;
  321. long idCapabilities = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, null, values);
  322. if (idCapabilities > 0) {
  323. insertedCapUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_CAPABILITIES, idCapabilities);
  324. } else {
  325. throw new SQLException(ERROR + uri);
  326. }
  327. return insertedCapUri;
  328. case UPLOADS:
  329. Uri insertedUploadUri;
  330. long uploadId = db.insert(ProviderTableMeta.UPLOADS_TABLE_NAME, null, values);
  331. if (uploadId > 0) {
  332. insertedUploadUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_UPLOADS, uploadId);
  333. } else {
  334. throw new SQLException(ERROR + uri);
  335. }
  336. return insertedUploadUri;
  337. case SYNCED_FOLDERS:
  338. Uri insertedSyncedFolderUri;
  339. long syncedFolderId = db.insert(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, null, values);
  340. if (syncedFolderId > 0) {
  341. insertedSyncedFolderUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
  342. syncedFolderId);
  343. } else {
  344. throw new SQLException("ERROR " + uri);
  345. }
  346. return insertedSyncedFolderUri;
  347. case EXTERNAL_LINKS:
  348. Uri insertedExternalLinkUri;
  349. long externalLinkId = db.insert(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, null, values);
  350. if (externalLinkId > 0) {
  351. insertedExternalLinkUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_EXTERNAL_LINKS,
  352. externalLinkId);
  353. } else {
  354. throw new SQLException("ERROR " + uri);
  355. }
  356. return insertedExternalLinkUri;
  357. case ARBITRARY_DATA:
  358. Uri insertedArbitraryDataUri;
  359. long arbitraryDataId = db.insert(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, null, values);
  360. if (arbitraryDataId > 0) {
  361. insertedArbitraryDataUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA,
  362. arbitraryDataId);
  363. } else {
  364. throw new SQLException("ERROR " + uri);
  365. }
  366. return insertedArbitraryDataUri;
  367. case VIRTUAL:
  368. Uri insertedVirtualUri;
  369. long virtualId = db.insert(ProviderTableMeta.VIRTUAL_TABLE_NAME, null, values);
  370. if (virtualId > 0) {
  371. insertedVirtualUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_VIRTUAL, virtualId);
  372. } else {
  373. throw new SQLException("ERROR " + uri);
  374. }
  375. return insertedVirtualUri;
  376. case FILESYSTEM:
  377. Uri insertedFilesystemUri;
  378. long filesystemId = db.insert(ProviderTableMeta.FILESYSTEM_TABLE_NAME, null, values);
  379. if (filesystemId > 0) {
  380. insertedFilesystemUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILESYSTEM,
  381. filesystemId);
  382. } else {
  383. throw new SQLException("ERROR " + uri);
  384. }
  385. return insertedFilesystemUri;
  386. default:
  387. throw new IllegalArgumentException("Unknown uri id: " + uri);
  388. }
  389. }
  390. private void updateFilesTableAccordingToShareInsertion(SQLiteDatabase db, ContentValues newShare) {
  391. ContentValues fileValues = new ContentValues();
  392. ShareType newShareType = ShareType.fromValue(newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE));
  393. switch (newShareType) {
  394. case PUBLIC_LINK:
  395. fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1);
  396. break;
  397. case USER:
  398. case GROUP:
  399. case EMAIL:
  400. case FEDERATED:
  401. case FEDERATED_GROUP:
  402. case ROOM:
  403. case CIRCLE:
  404. case DECK:
  405. case GUEST:
  406. fileValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, 1);
  407. break;
  408. default:
  409. // everything should be handled
  410. }
  411. String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
  412. String[] whereArgs = new String[]{
  413. newShare.getAsString(ProviderTableMeta.OCSHARES_PATH),
  414. newShare.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)
  415. };
  416. db.update(ProviderTableMeta.FILE_TABLE_NAME, fileValues, where, whereArgs);
  417. }
  418. @Override
  419. public boolean onCreate() {
  420. AndroidInjection.inject(this);
  421. mDbHelper = new DataBaseHelper(getContext());
  422. mContext = getContext();
  423. if (mContext == null) {
  424. return false;
  425. }
  426. String authority = mContext.getResources().getString(R.string.authority);
  427. mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  428. mUriMatcher.addURI(authority, null, ROOT_DIRECTORY);
  429. mUriMatcher.addURI(authority, "file/", SINGLE_FILE);
  430. mUriMatcher.addURI(authority, "file/#", SINGLE_FILE);
  431. mUriMatcher.addURI(authority, "dir/", DIRECTORY);
  432. mUriMatcher.addURI(authority, "dir/#", DIRECTORY);
  433. mUriMatcher.addURI(authority, "shares/", SHARES);
  434. mUriMatcher.addURI(authority, "shares/#", SHARES);
  435. mUriMatcher.addURI(authority, "capabilities/", CAPABILITIES);
  436. mUriMatcher.addURI(authority, "capabilities/#", CAPABILITIES);
  437. mUriMatcher.addURI(authority, "uploads/", UPLOADS);
  438. mUriMatcher.addURI(authority, "uploads/#", UPLOADS);
  439. mUriMatcher.addURI(authority, "synced_folders", SYNCED_FOLDERS);
  440. mUriMatcher.addURI(authority, "external_links", EXTERNAL_LINKS);
  441. mUriMatcher.addURI(authority, "arbitrary_data", ARBITRARY_DATA);
  442. mUriMatcher.addURI(authority, "virtual", VIRTUAL);
  443. mUriMatcher.addURI(authority, "filesystem", FILESYSTEM);
  444. return true;
  445. }
  446. @Override
  447. public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
  448. String sortOrder) {
  449. // skip check for files as they need to be queried to get access via document provider
  450. switch (mUriMatcher.match(uri)) {
  451. case ROOT_DIRECTORY:
  452. case SINGLE_FILE:
  453. case DIRECTORY:
  454. break;
  455. default:
  456. if (isCallerNotAllowed(uri)) {
  457. return null;
  458. }
  459. }
  460. Cursor result;
  461. SQLiteDatabase db = mDbHelper.getReadableDatabase();
  462. db.beginTransaction();
  463. try {
  464. result = query(db, uri, projection, selection, selectionArgs, sortOrder);
  465. db.setTransactionSuccessful();
  466. } finally {
  467. db.endTransaction();
  468. }
  469. return result;
  470. }
  471. private Cursor query(SQLiteDatabase db,
  472. Uri uri,
  473. String[] projectionArray,
  474. String selection,
  475. String[] selectionArgs,
  476. String sortOrder) {
  477. // verify only for those requests that are not internal
  478. final int uriMatch = mUriMatcher.match(uri);
  479. SQLiteQueryBuilder sqlQuery = new SQLiteQueryBuilder();
  480. switch (uriMatch) {
  481. case ROOT_DIRECTORY:
  482. case DIRECTORY:
  483. case SINGLE_FILE:
  484. VerificationUtils.verifyWhere(selection); // prevent injection in public paths
  485. sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME);
  486. break;
  487. case SHARES:
  488. sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME);
  489. break;
  490. case CAPABILITIES:
  491. sqlQuery.setTables(ProviderTableMeta.CAPABILITIES_TABLE_NAME);
  492. break;
  493. case UPLOADS:
  494. sqlQuery.setTables(ProviderTableMeta.UPLOADS_TABLE_NAME);
  495. break;
  496. case SYNCED_FOLDERS:
  497. sqlQuery.setTables(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME);
  498. break;
  499. case EXTERNAL_LINKS:
  500. sqlQuery.setTables(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME);
  501. break;
  502. case ARBITRARY_DATA:
  503. sqlQuery.setTables(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME);
  504. break;
  505. case VIRTUAL:
  506. sqlQuery.setTables(ProviderTableMeta.VIRTUAL_TABLE_NAME);
  507. break;
  508. case FILESYSTEM:
  509. sqlQuery.setTables(ProviderTableMeta.FILESYSTEM_TABLE_NAME);
  510. break;
  511. default:
  512. throw new IllegalArgumentException("Unknown uri id: " + uri);
  513. }
  514. // add ID to arguments if Uri has more than one segment
  515. if (uriMatch != ROOT_DIRECTORY && uri.getPathSegments().size() > SINGLE_PATH_SEGMENT ) {
  516. String idColumn = uriMatch == DIRECTORY ? ProviderTableMeta.FILE_PARENT : ProviderTableMeta._ID;
  517. sqlQuery.appendWhere(idColumn + "=?");
  518. selectionArgs = VerificationUtils.prependUriFirstSegmentToSelectionArgs(selectionArgs, uri);
  519. }
  520. String order;
  521. if (TextUtils.isEmpty(sortOrder)) {
  522. switch (uriMatch) {
  523. case SHARES:
  524. order = ProviderTableMeta.OCSHARES_DEFAULT_SORT_ORDER;
  525. break;
  526. case CAPABILITIES:
  527. order = ProviderTableMeta.CAPABILITIES_DEFAULT_SORT_ORDER;
  528. break;
  529. case UPLOADS:
  530. order = ProviderTableMeta.UPLOADS_DEFAULT_SORT_ORDER;
  531. break;
  532. case SYNCED_FOLDERS:
  533. order = ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH;
  534. break;
  535. case EXTERNAL_LINKS:
  536. order = ProviderTableMeta.EXTERNAL_LINKS_NAME;
  537. break;
  538. case ARBITRARY_DATA:
  539. order = ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID;
  540. break;
  541. case VIRTUAL:
  542. order = ProviderTableMeta.VIRTUAL_TYPE;
  543. break;
  544. default: // Files
  545. order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
  546. break;
  547. case FILESYSTEM:
  548. order = ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH;
  549. break;
  550. }
  551. } else {
  552. if (uriMatch == ROOT_DIRECTORY || uriMatch == SINGLE_FILE || uriMatch == DIRECTORY) {
  553. VerificationUtils.verifySortOrder(sortOrder);
  554. }
  555. order = sortOrder;
  556. }
  557. // DB case_sensitive
  558. db.execSQL("PRAGMA case_sensitive_like = true");
  559. // only file list is accessible via content provider, so only this has to be protected with projectionMap
  560. if ((uriMatch == ROOT_DIRECTORY || uriMatch == SINGLE_FILE ||
  561. uriMatch == DIRECTORY) && projectionArray != null) {
  562. sqlQuery.setProjectionMap(FILE_PROJECTION_MAP);
  563. }
  564. // if both are null, let them pass to query
  565. if (selectionArgs == null && selection != null) {
  566. selectionArgs = new String[]{selection};
  567. selection = "(?)";
  568. }
  569. sqlQuery.setStrict(true);
  570. Cursor c = sqlQuery.query(db, projectionArray, selection, selectionArgs, null, null, order);
  571. c.setNotificationUri(mContext.getContentResolver(), uri);
  572. return c;
  573. }
  574. @Override
  575. public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
  576. if (isCallerNotAllowed(uri)) {
  577. return -1;
  578. }
  579. int count;
  580. SQLiteDatabase db = mDbHelper.getWritableDatabase();
  581. db.beginTransaction();
  582. try {
  583. count = update(db, uri, values, selection, selectionArgs);
  584. db.setTransactionSuccessful();
  585. } finally {
  586. db.endTransaction();
  587. }
  588. mContext.getContentResolver().notifyChange(uri, null);
  589. return count;
  590. }
  591. private int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String... selectionArgs) {
  592. // verify contentValues and selection for public paths to prevent injection
  593. switch (mUriMatcher.match(uri)) {
  594. case ROOT_DIRECTORY:
  595. case SINGLE_FILE:
  596. case DIRECTORY:
  597. VerificationUtils.verifyColumns(values);
  598. VerificationUtils.verifyWhere(selection);
  599. }
  600. switch (mUriMatcher.match(uri)) {
  601. case DIRECTORY:
  602. return 0;
  603. case SHARES:
  604. return db.update(ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs);
  605. case CAPABILITIES:
  606. return db.update(ProviderTableMeta.CAPABILITIES_TABLE_NAME, values, selection, selectionArgs);
  607. case UPLOADS:
  608. return db.update(ProviderTableMeta.UPLOADS_TABLE_NAME, values, selection, selectionArgs);
  609. case SYNCED_FOLDERS:
  610. return db.update(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, values, selection, selectionArgs);
  611. case ARBITRARY_DATA:
  612. return db.update(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, values, selection, selectionArgs);
  613. case FILESYSTEM:
  614. return db.update(ProviderTableMeta.FILESYSTEM_TABLE_NAME, values, selection, selectionArgs);
  615. default:
  616. return db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs);
  617. }
  618. }
  619. @NonNull
  620. @Override
  621. public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations)
  622. throws OperationApplicationException {
  623. Log_OC.d("FileContentProvider", "applying batch in provider " + this +
  624. " (temporary: " + isTemporary() + ")");
  625. ContentProviderResult[] results = new ContentProviderResult[operations.size()];
  626. int i = 0;
  627. SQLiteDatabase database = mDbHelper.getWritableDatabase();
  628. database.beginTransaction(); // it's supposed that transactions can be nested
  629. try {
  630. for (ContentProviderOperation operation : operations) {
  631. results[i] = operation.apply(this, results, i);
  632. i++;
  633. }
  634. database.setTransactionSuccessful();
  635. } finally {
  636. database.endTransaction();
  637. }
  638. Log_OC.d("FileContentProvider", "applied batch in provider " + this);
  639. return results;
  640. }
  641. private boolean checkIfColumnExists(SQLiteDatabase database, String table, String column) {
  642. Cursor cursor = database.rawQuery("SELECT * FROM " + table + " LIMIT 0", null);
  643. boolean exists = cursor.getColumnIndexOrThrow(column) != -1;
  644. cursor.close();
  645. return exists;
  646. }
  647. private void createFilesTable(SQLiteDatabase db) {
  648. db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "("
  649. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  650. + ProviderTableMeta.FILE_NAME + TEXT
  651. + ProviderTableMeta.FILE_ENCRYPTED_NAME + TEXT
  652. + ProviderTableMeta.FILE_PATH + TEXT
  653. + ProviderTableMeta.FILE_PATH_DECRYPTED + TEXT
  654. + ProviderTableMeta.FILE_PARENT + INTEGER
  655. + ProviderTableMeta.FILE_CREATION + INTEGER
  656. + ProviderTableMeta.FILE_MODIFIED + INTEGER
  657. + ProviderTableMeta.FILE_CONTENT_TYPE + TEXT
  658. + ProviderTableMeta.FILE_CONTENT_LENGTH + INTEGER
  659. + ProviderTableMeta.FILE_STORAGE_PATH + TEXT
  660. + ProviderTableMeta.FILE_ACCOUNT_OWNER + TEXT
  661. + ProviderTableMeta.FILE_LAST_SYNC_DATE + INTEGER
  662. + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + INTEGER
  663. + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + INTEGER
  664. + ProviderTableMeta.FILE_ETAG + TEXT
  665. + ProviderTableMeta.FILE_ETAG_ON_SERVER + TEXT
  666. + ProviderTableMeta.FILE_SHARED_VIA_LINK + INTEGER
  667. + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
  668. + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null,"
  669. + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + INTEGER //boolean
  670. + ProviderTableMeta.FILE_IS_DOWNLOADING + INTEGER //boolean
  671. + ProviderTableMeta.FILE_FAVORITE + INTEGER // boolean
  672. + ProviderTableMeta.FILE_IS_ENCRYPTED + INTEGER // boolean
  673. + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + TEXT
  674. + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + INTEGER
  675. + ProviderTableMeta.FILE_MOUNT_TYPE + INTEGER
  676. + ProviderTableMeta.FILE_HAS_PREVIEW + INTEGER
  677. + ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT + INTEGER
  678. + ProviderTableMeta.FILE_OWNER_ID + TEXT
  679. + ProviderTableMeta.FILE_OWNER_DISPLAY_NAME + TEXT
  680. + ProviderTableMeta.FILE_NOTE + TEXT
  681. + ProviderTableMeta.FILE_SHAREES + TEXT
  682. + ProviderTableMeta.FILE_RICH_WORKSPACE + " TEXT);"
  683. );
  684. }
  685. private void createOCSharesTable(SQLiteDatabase db) {
  686. db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
  687. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  688. + ProviderTableMeta.OCSHARES_FILE_SOURCE + INTEGER
  689. + ProviderTableMeta.OCSHARES_ITEM_SOURCE + INTEGER
  690. + ProviderTableMeta.OCSHARES_SHARE_TYPE + INTEGER
  691. + ProviderTableMeta.OCSHARES_SHARE_WITH + TEXT
  692. + ProviderTableMeta.OCSHARES_PATH + TEXT
  693. + ProviderTableMeta.OCSHARES_PERMISSIONS + INTEGER
  694. + ProviderTableMeta.OCSHARES_SHARED_DATE + INTEGER
  695. + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + INTEGER
  696. + ProviderTableMeta.OCSHARES_TOKEN + TEXT
  697. + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + TEXT
  698. + ProviderTableMeta.OCSHARES_IS_DIRECTORY + INTEGER // boolean
  699. + ProviderTableMeta.OCSHARES_USER_ID + INTEGER
  700. + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + INTEGER
  701. + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + TEXT
  702. + ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + INTEGER
  703. + ProviderTableMeta.OCSHARES_NOTE + TEXT
  704. + ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + INTEGER
  705. + ProviderTableMeta.OCSHARES_SHARE_LINK + TEXT
  706. + ProviderTableMeta.OCSHARES_SHARE_LABEL + " TEXT );");
  707. }
  708. private void createCapabilitiesTable(SQLiteDatabase db) {
  709. db.execSQL("CREATE TABLE " + ProviderTableMeta.CAPABILITIES_TABLE_NAME + "("
  710. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  711. + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + TEXT
  712. + ProviderTableMeta.CAPABILITIES_VERSION_MAYOR + INTEGER
  713. + ProviderTableMeta.CAPABILITIES_VERSION_MINOR + INTEGER
  714. + ProviderTableMeta.CAPABILITIES_VERSION_MICRO + INTEGER
  715. + ProviderTableMeta.CAPABILITIES_VERSION_STRING + TEXT
  716. + ProviderTableMeta.CAPABILITIES_VERSION_EDITION + TEXT
  717. + ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT + INTEGER
  718. + ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL + INTEGER
  719. + ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED + INTEGER // boolean
  720. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED + INTEGER // boolean
  721. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED + INTEGER // boolean
  722. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED + INTEGER // boolean
  723. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS + INTEGER
  724. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED + INTEGER // boolean
  725. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL + INTEGER // boolean
  726. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD + INTEGER // boolean
  727. + ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL + INTEGER // boolean
  728. + ProviderTableMeta.CAPABILITIES_SHARING_RESHARING + INTEGER // boolean
  729. + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING + INTEGER // boolean
  730. + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING + INTEGER // boolean
  731. + ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING + INTEGER // boolean
  732. + ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + INTEGER // boolean
  733. + ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + INTEGER // boolean
  734. + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS + INTEGER // boolean
  735. + ProviderTableMeta.CAPABILITIES_SERVER_NAME + TEXT
  736. + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + TEXT
  737. + ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + TEXT
  738. + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + TEXT
  739. + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + TEXT
  740. + ProviderTableMeta.CAPABILITIES_SERVER_LOGO + TEXT
  741. + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + TEXT
  742. + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + INTEGER
  743. + ProviderTableMeta.CAPABILITIES_ACTIVITY + INTEGER
  744. + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + INTEGER
  745. + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + INTEGER
  746. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT + INTEGER
  747. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST + TEXT
  748. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + INTEGER
  749. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + INTEGER
  750. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST + TEXT
  751. + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD + INTEGER
  752. + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME + TEXT
  753. + ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG + TEXT
  754. + ProviderTableMeta.CAPABILITIES_USER_STATUS + INTEGER
  755. + ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI + INTEGER
  756. + ProviderTableMeta.CAPABILITIES_ETAG + " TEXT );");
  757. }
  758. private void createUploadsTable(SQLiteDatabase db) {
  759. db.execSQL("CREATE TABLE " + ProviderTableMeta.UPLOADS_TABLE_NAME + "("
  760. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
  761. + ProviderTableMeta.UPLOADS_LOCAL_PATH + TEXT
  762. + ProviderTableMeta.UPLOADS_REMOTE_PATH + TEXT
  763. + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + TEXT
  764. + ProviderTableMeta.UPLOADS_FILE_SIZE + " LONG, "
  765. + ProviderTableMeta.UPLOADS_STATUS + INTEGER // UploadStatus
  766. + ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + INTEGER // Upload LocalBehaviour
  767. + ProviderTableMeta.UPLOADS_UPLOAD_TIME + INTEGER
  768. + ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY + INTEGER // boolean
  769. + ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + INTEGER // boolean
  770. + ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + INTEGER
  771. + ProviderTableMeta.UPLOADS_LAST_RESULT + INTEGER // Upload LastResult
  772. + ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + INTEGER // boolean
  773. + ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + INTEGER // boolean
  774. + ProviderTableMeta.UPLOADS_CREATED_BY + INTEGER // Upload createdBy
  775. + ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN + " TEXT );");
  776. /* before:
  777. // PRIMARY KEY should always imply NOT NULL. Unfortunately, due to a
  778. // bug in some early versions, this is not the case in SQLite.
  779. //db.execSQL("CREATE TABLE " + TABLE_UPLOAD + " (" + " path TEXT PRIMARY KEY NOT NULL UNIQUE,"
  780. // + " uploadStatus INTEGER NOT NULL, uploadObject TEXT NOT NULL);");
  781. // uploadStatus is used to easy filtering, it has precedence over
  782. // uploadObject.getUploadStatus()
  783. */
  784. }
  785. private void createSyncedFoldersTable(SQLiteDatabase db) {
  786. db.execSQL("CREATE TABLE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + "("
  787. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  788. + ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " TEXT, " // local path
  789. + ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH + " TEXT, " // remote path
  790. + ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY + " INTEGER, " // wifi_only
  791. + ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY + " INTEGER, " // charging only
  792. + ProviderTableMeta.SYNCED_FOLDER_EXISTING + " INTEGER, " // existing
  793. + ProviderTableMeta.SYNCED_FOLDER_ENABLED + " INTEGER, " // enabled
  794. + ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER, " // enable date
  795. + ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
  796. + ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " TEXT, " // account
  797. + ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION + " INTEGER, " // upload action
  798. + ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " INTEGER, " // name collision policy
  799. + ProviderTableMeta.SYNCED_FOLDER_TYPE + " INTEGER, " // type
  800. + ProviderTableMeta.SYNCED_FOLDER_HIDDEN + " INTEGER );" // hidden
  801. );
  802. }
  803. private void createExternalLinksTable(SQLiteDatabase db) {
  804. db.execSQL("CREATE TABLE " + ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME + "("
  805. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  806. + ProviderTableMeta.EXTERNAL_LINKS_ICON_URL + " TEXT, " // icon url
  807. + ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE + " TEXT, " // language
  808. + ProviderTableMeta.EXTERNAL_LINKS_TYPE + " INTEGER, " // type
  809. + ProviderTableMeta.EXTERNAL_LINKS_NAME + " TEXT, " // name
  810. + ProviderTableMeta.EXTERNAL_LINKS_URL + " TEXT, " // url
  811. + ProviderTableMeta.EXTERNAL_LINKS_REDIRECT + " INTEGER );" // redirect
  812. );
  813. }
  814. private void createArbitraryData(SQLiteDatabase db) {
  815. db.execSQL("CREATE TABLE " + ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME + "("
  816. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  817. + ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " TEXT, " // cloud id (account name + FQDN)
  818. + ProviderTableMeta.ARBITRARY_DATA_KEY + " TEXT, " // key
  819. + ProviderTableMeta.ARBITRARY_DATA_VALUE + " TEXT );" // value
  820. );
  821. }
  822. private void createVirtualTable(SQLiteDatabase db) {
  823. db.execSQL("CREATE TABLE " + ProviderTableMeta.VIRTUAL_TABLE_NAME + "("
  824. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  825. + ProviderTableMeta.VIRTUAL_TYPE + " TEXT, " // type
  826. + ProviderTableMeta.VIRTUAL_OCFILE_ID + " INTEGER )" // file id
  827. + ProviderTableMeta.VIRTUAL_OCFILE_REMOTE_ID + " STRING )" // remote id
  828. );
  829. }
  830. private void createFileSystemTable(SQLiteDatabase db) {
  831. db.execSQL("CREATE TABLE IF NOT EXISTS " + ProviderTableMeta.FILESYSTEM_TABLE_NAME + "("
  832. + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
  833. + ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " TEXT, "
  834. + ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER + " INTEGER, "
  835. + ProviderTableMeta.FILESYSTEM_FILE_FOUND_RECENTLY + " LONG, "
  836. + ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD + " INTEGER, "
  837. + ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " STRING, "
  838. + ProviderTableMeta.FILESYSTEM_CRC32 + " STRING, "
  839. + ProviderTableMeta.FILESYSTEM_FILE_MODIFIED + " LONG );"
  840. );
  841. }
  842. /**
  843. * Version 10 of database does not modify its scheme. It coincides with the upgrade of the
  844. * ownCloud account names structure to include in it the path to the server instance. Updating
  845. * the account names and path to local files in the files table is a must to keep the existing
  846. * account working and the database clean.
  847. *
  848. * @param db Database where table of files is included.
  849. */
  850. private void updateAccountName(SQLiteDatabase db) {
  851. Log_OC.d(SQL, "THREAD: " + Thread.currentThread().getName());
  852. AccountManager ama = AccountManager.get(getContext());
  853. try {
  854. // get accounts from AccountManager ; we can't be sure if accounts in it are updated or not although
  855. // we know the update was previously done in {link @FileActivity#onCreate} because the changes through
  856. // AccountManager are not synchronous
  857. Account[] accounts = AccountManager.get(getContext()).getAccountsByType(MainApp.getAccountType(mContext));
  858. String serverUrl;
  859. String username;
  860. String oldAccountName;
  861. String newAccountName;
  862. String[] accountOwner = new String[1];
  863. for (Account account : accounts) {
  864. // build both old and new account name
  865. serverUrl = ama.getUserData(account, AccountUtils.Constants.KEY_OC_BASE_URL);
  866. username = AccountUtils.getUsernameForAccount(account);
  867. oldAccountName = AccountUtils.buildAccountNameOld(Uri.parse(serverUrl), username);
  868. newAccountName = AccountUtils.buildAccountName(Uri.parse(serverUrl), username);
  869. // update values in database
  870. db.beginTransaction();
  871. try {
  872. ContentValues cv = new ContentValues();
  873. cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, newAccountName);
  874. accountOwner[0] = oldAccountName;
  875. int num = db.update(ProviderTableMeta.FILE_TABLE_NAME,
  876. cv,
  877. ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
  878. accountOwner);
  879. Log_OC.d(SQL, "Updated account in database: old name == " + oldAccountName +
  880. ", new name == " + newAccountName + " (" + num + " rows updated )");
  881. // update path for downloaded files
  882. updateDownloadedFiles(db, newAccountName, oldAccountName);
  883. db.setTransactionSuccessful();
  884. } catch (SQLException e) {
  885. Log_OC.e(TAG, "SQL Exception upgrading account names or paths in database", e);
  886. } finally {
  887. db.endTransaction();
  888. }
  889. }
  890. } catch (Exception e) {
  891. Log_OC.e(TAG, "Exception upgrading account names or paths in database", e);
  892. }
  893. }
  894. /**
  895. * Rename the local ownCloud folder of one account to match the a rename of the account itself.
  896. * Updates the table of files in database so that the paths to the local files keep being the
  897. * same.
  898. *
  899. * @param db Database where table of files is included.
  900. * @param newAccountName New name for the target OC account.
  901. * @param oldAccountName Old name of the target OC account.
  902. */
  903. private void updateDownloadedFiles(SQLiteDatabase db, String newAccountName,
  904. String oldAccountName) {
  905. String whereClause = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
  906. ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL";
  907. Cursor c = db.query(ProviderTableMeta.FILE_TABLE_NAME,
  908. PROJECTION_FILE_AND_STORAGE_PATH,
  909. whereClause,
  910. new String[]{newAccountName},
  911. null, null, null);
  912. try {
  913. if (c.moveToFirst()) {
  914. // create storage path
  915. String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
  916. String newAccountPath = FileStorageUtils.getSavePath(newAccountName);
  917. // move files
  918. File oldAccountFolder = new File(oldAccountPath);
  919. File newAccountFolder = new File(newAccountPath);
  920. oldAccountFolder.renameTo(newAccountFolder);
  921. String[] storagePath = new String[1];
  922. // update database
  923. do {
  924. // Update database
  925. String oldPath = c.getString(
  926. c.getColumnIndexOrThrow(ProviderTableMeta.FILE_STORAGE_PATH));
  927. OCFile file = new OCFile(
  928. c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.FILE_PATH)));
  929. String newPath = FileStorageUtils.getDefaultSavePathFor(newAccountName, file);
  930. ContentValues cv = new ContentValues();
  931. cv.put(ProviderTableMeta.FILE_STORAGE_PATH, newPath);
  932. storagePath[0] = oldPath;
  933. db.update(ProviderTableMeta.FILE_TABLE_NAME,
  934. cv,
  935. ProviderTableMeta.FILE_STORAGE_PATH + "=?",
  936. storagePath);
  937. Log_OC.v(SQL, "Updated path of downloaded file: old file name == " + oldPath +
  938. ", new file name == " + newPath);
  939. } while (c.moveToNext());
  940. }
  941. } finally {
  942. c.close();
  943. }
  944. }
  945. private boolean isCallerNotAllowed(Uri uri) {
  946. switch (mUriMatcher.match(uri)) {
  947. case SHARES:
  948. case CAPABILITIES:
  949. case UPLOADS:
  950. case SYNCED_FOLDERS:
  951. case EXTERNAL_LINKS:
  952. case ARBITRARY_DATA:
  953. case VIRTUAL:
  954. case FILESYSTEM:
  955. String callingPackage = mContext.getPackageManager().getNameForUid(Binder.getCallingUid());
  956. return callingPackage == null || !callingPackage.equals(mContext.getPackageName());
  957. case ROOT_DIRECTORY:
  958. case SINGLE_FILE:
  959. case DIRECTORY:
  960. default:
  961. return false;
  962. }
  963. }
  964. static class VerificationUtils {
  965. private static boolean isValidColumnName(@NonNull String columnName) {
  966. return ProviderTableMeta.FILE_ALL_COLUMNS.contains(columnName);
  967. }
  968. @VisibleForTesting
  969. public static void verifyColumns(@Nullable ContentValues contentValues) {
  970. if (contentValues == null || contentValues.keySet().size() == 0) {
  971. return;
  972. }
  973. for (String name : contentValues.keySet()) {
  974. verifyColumnName(name);
  975. }
  976. }
  977. @VisibleForTesting
  978. public static void verifyColumnName(@NonNull String columnName) {
  979. if (!isValidColumnName(columnName)) {
  980. throw new IllegalArgumentException(String.format("Column name \"%s\" is not allowed", columnName));
  981. }
  982. }
  983. public static String[] prependUriFirstSegmentToSelectionArgs(@Nullable final String[] originalArgs, final Uri uri) {
  984. String[] args;
  985. if (originalArgs == null) {
  986. args = new String[1];
  987. } else {
  988. args = new String[originalArgs.length + 1];
  989. System.arraycopy(originalArgs, 0, args, 1, originalArgs.length);
  990. }
  991. args[0] = uri.getPathSegments().get(1);
  992. return args;
  993. }
  994. public static void verifySortOrder(@Nullable String sortOrder) {
  995. if (sortOrder == null) {
  996. return;
  997. }
  998. SQLiteTokenizer.tokenize(sortOrder, SQLiteTokenizer.OPTION_NONE, VerificationUtils::verifySortToken);
  999. }
  1000. private static void verifySortToken(String token){
  1001. // accept empty tokens and valid column names
  1002. if (TextUtils.isEmpty(token) || isValidColumnName(token)) {
  1003. return;
  1004. }
  1005. // accept only a small subset of keywords
  1006. if(SQLiteTokenizer.isKeyword(token)){
  1007. switch (token.toUpperCase(Locale.ROOT)) {
  1008. case "ASC":
  1009. case "DESC":
  1010. case "COLLATE":
  1011. case "NOCASE":
  1012. return;
  1013. }
  1014. }
  1015. // if none of the above, invalid token
  1016. throw new IllegalArgumentException("Invalid token " + token);
  1017. }
  1018. public static void verifyWhere(@Nullable String where) {
  1019. if (where == null) {
  1020. return;
  1021. }
  1022. SQLiteTokenizer.tokenize(where, SQLiteTokenizer.OPTION_NONE, VerificationUtils::verifyWhereToken);
  1023. }
  1024. private static void verifyWhereToken(String token) {
  1025. // allow empty, valid column names, functions (min,max,count) and types
  1026. if (TextUtils.isEmpty(token) || isValidColumnName(token)
  1027. || SQLiteTokenizer.isFunction(token) || SQLiteTokenizer.isType(token)) {
  1028. return;
  1029. }
  1030. // Disallow dangerous keywords, allow others
  1031. if (SQLiteTokenizer.isKeyword(token)) {
  1032. switch (token.toUpperCase(Locale.ROOT)) {
  1033. case "SELECT":
  1034. case "FROM":
  1035. case "WHERE":
  1036. case "GROUP":
  1037. case "HAVING":
  1038. case "WINDOW":
  1039. case "VALUES":
  1040. case "ORDER":
  1041. case "LIMIT":
  1042. throw new IllegalArgumentException("Invalid token " + token);
  1043. default:
  1044. return;
  1045. }
  1046. }
  1047. // if none of the above: invalid token
  1048. throw new IllegalArgumentException("Invalid token " + token);
  1049. }
  1050. }
  1051. class DataBaseHelper extends SQLiteOpenHelper {
  1052. DataBaseHelper(Context context) {
  1053. super(context, ProviderMeta.DB_NAME, null, ProviderMeta.DB_VERSION);
  1054. }
  1055. @Override
  1056. public void onCreate(SQLiteDatabase db) {
  1057. // files table
  1058. Log_OC.i(SQL, "Entering in onCreate");
  1059. createFilesTable(db);
  1060. // Create OCShares table
  1061. createOCSharesTable(db);
  1062. // Create capabilities table
  1063. createCapabilitiesTable(db);
  1064. // Create uploads table
  1065. createUploadsTable(db);
  1066. // Create synced folders table
  1067. createSyncedFoldersTable(db);
  1068. // Create external links table
  1069. createExternalLinksTable(db);
  1070. // Create arbitrary data table
  1071. createArbitraryData(db);
  1072. // Create virtual table
  1073. createVirtualTable(db);
  1074. // Create filesystem table
  1075. createFileSystemTable(db);
  1076. }
  1077. @Override
  1078. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  1079. Log_OC.i(SQL, "Entering in onUpgrade");
  1080. boolean upgraded = false;
  1081. if (oldVersion == 1 && newVersion >= 2) {
  1082. Log_OC.i(SQL, "Entering in the #2 ADD in onUpgrade");
  1083. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1084. ADD_COLUMN + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER " +
  1085. " DEFAULT 0");
  1086. upgraded = true;
  1087. }
  1088. if (oldVersion < 3 && newVersion >= 3) {
  1089. Log_OC.i(SQL, "Entering in the #3 ADD in onUpgrade");
  1090. db.beginTransaction();
  1091. try {
  1092. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1093. ADD_COLUMN + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA +
  1094. " INTEGER " + " DEFAULT 0");
  1095. // assume there are not local changes pending to upload
  1096. db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
  1097. " SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = "
  1098. + System.currentTimeMillis() +
  1099. " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
  1100. upgraded = true;
  1101. db.setTransactionSuccessful();
  1102. } finally {
  1103. db.endTransaction();
  1104. }
  1105. }
  1106. if (oldVersion < 4 && newVersion >= 4) {
  1107. Log_OC.i(SQL, "Entering in the #4 ADD in onUpgrade");
  1108. db.beginTransaction();
  1109. try {
  1110. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1111. ADD_COLUMN + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA +
  1112. " INTEGER " + " DEFAULT 0");
  1113. db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
  1114. " SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " +
  1115. ProviderTableMeta.FILE_MODIFIED +
  1116. " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
  1117. upgraded = true;
  1118. db.setTransactionSuccessful();
  1119. } finally {
  1120. db.endTransaction();
  1121. }
  1122. }
  1123. if (!upgraded) {
  1124. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1125. }
  1126. if (oldVersion < 5 && newVersion >= 5) {
  1127. Log_OC.i(SQL, "Entering in the #5 ADD in onUpgrade");
  1128. db.beginTransaction();
  1129. try {
  1130. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1131. ADD_COLUMN + ProviderTableMeta.FILE_ETAG + " TEXT " +
  1132. " DEFAULT NULL");
  1133. upgraded = true;
  1134. db.setTransactionSuccessful();
  1135. } finally {
  1136. db.endTransaction();
  1137. }
  1138. }
  1139. if (!upgraded) {
  1140. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1141. }
  1142. if (oldVersion < 6 && newVersion >= 6) {
  1143. Log_OC.i(SQL, "Entering in the #6 ADD in onUpgrade");
  1144. db.beginTransaction();
  1145. try {
  1146. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1147. ADD_COLUMN + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER " +
  1148. " DEFAULT 0");
  1149. // Create table OCShares
  1150. createOCSharesTable(db);
  1151. upgraded = true;
  1152. db.setTransactionSuccessful();
  1153. } finally {
  1154. db.endTransaction();
  1155. }
  1156. }
  1157. if (!upgraded) {
  1158. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1159. }
  1160. if (oldVersion < 7 && newVersion >= 7) {
  1161. Log_OC.i(SQL, "Entering in the #7 ADD in onUpgrade");
  1162. db.beginTransaction();
  1163. try {
  1164. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1165. ADD_COLUMN + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
  1166. " DEFAULT NULL");
  1167. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1168. ADD_COLUMN + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " +
  1169. " DEFAULT NULL");
  1170. upgraded = true;
  1171. db.setTransactionSuccessful();
  1172. } finally {
  1173. db.endTransaction();
  1174. }
  1175. }
  1176. if (!upgraded) {
  1177. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1178. }
  1179. if (oldVersion < 8 && newVersion >= 8) {
  1180. Log_OC.i(SQL, "Entering in the #8 ADD in onUpgrade");
  1181. db.beginTransaction();
  1182. try {
  1183. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1184. ADD_COLUMN + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER " +
  1185. " DEFAULT 0");
  1186. upgraded = true;
  1187. db.setTransactionSuccessful();
  1188. } finally {
  1189. db.endTransaction();
  1190. }
  1191. }
  1192. if (!upgraded) {
  1193. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1194. }
  1195. if (oldVersion < 9 && newVersion >= 9) {
  1196. Log_OC.i(SQL, "Entering in the #9 ADD in onUpgrade");
  1197. db.beginTransaction();
  1198. try {
  1199. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1200. ADD_COLUMN + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER " +
  1201. " DEFAULT 0");
  1202. upgraded = true;
  1203. db.setTransactionSuccessful();
  1204. } finally {
  1205. db.endTransaction();
  1206. }
  1207. }
  1208. if (!upgraded) {
  1209. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1210. }
  1211. if (oldVersion < 10 && newVersion >= 10) {
  1212. Log_OC.i(SQL, "Entering in the #10 ADD in onUpgrade");
  1213. updateAccountName(db);
  1214. upgraded = true;
  1215. }
  1216. if (!upgraded) {
  1217. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1218. }
  1219. if (oldVersion < 11 && newVersion >= 11) {
  1220. Log_OC.i(SQL, "Entering in the #11 ADD in onUpgrade");
  1221. db.beginTransaction();
  1222. try {
  1223. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1224. ADD_COLUMN + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT " +
  1225. " DEFAULT NULL");
  1226. upgraded = true;
  1227. db.setTransactionSuccessful();
  1228. } finally {
  1229. db.endTransaction();
  1230. }
  1231. }
  1232. if (!upgraded) {
  1233. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1234. }
  1235. if (oldVersion < 12 && newVersion >= 12) {
  1236. Log_OC.i(SQL, "Entering in the #12 ADD in onUpgrade");
  1237. db.beginTransaction();
  1238. try {
  1239. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1240. ADD_COLUMN + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER " +
  1241. " DEFAULT 0");
  1242. upgraded = true;
  1243. db.setTransactionSuccessful();
  1244. } finally {
  1245. db.endTransaction();
  1246. }
  1247. }
  1248. if (!upgraded) {
  1249. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1250. }
  1251. if (oldVersion < 13 && newVersion >= 13) {
  1252. Log_OC.i(SQL, "Entering in the #13 ADD in onUpgrade");
  1253. db.beginTransaction();
  1254. try {
  1255. // Create capabilities table
  1256. createCapabilitiesTable(db);
  1257. upgraded = true;
  1258. db.setTransactionSuccessful();
  1259. } finally {
  1260. db.endTransaction();
  1261. }
  1262. }
  1263. if (oldVersion < 14 && newVersion >= 14) {
  1264. Log_OC.i(SQL, "Entering in the #14 ADD in onUpgrade");
  1265. db.beginTransaction();
  1266. try {
  1267. // drop old instant_upload table
  1268. db.execSQL("DROP TABLE IF EXISTS " + "instant_upload" + ";");
  1269. // Create uploads table
  1270. createUploadsTable(db);
  1271. upgraded = true;
  1272. db.setTransactionSuccessful();
  1273. } finally {
  1274. db.endTransaction();
  1275. }
  1276. }
  1277. if (oldVersion < 15 && newVersion >= 15) {
  1278. Log_OC.i(SQL, "Entering in the #15 ADD in onUpgrade");
  1279. db.beginTransaction();
  1280. try {
  1281. // drop old capabilities table
  1282. db.execSQL("DROP TABLE IF EXISTS " + "capabilities" + ";");
  1283. // Create uploads table
  1284. createCapabilitiesTable(db);
  1285. upgraded = true;
  1286. db.setTransactionSuccessful();
  1287. } finally {
  1288. db.endTransaction();
  1289. }
  1290. }
  1291. if (oldVersion < 16 && newVersion >= 16) {
  1292. Log_OC.i(SQL, "Entering in the #16 ADD synced folders table");
  1293. db.beginTransaction();
  1294. try {
  1295. // Create synced folders table
  1296. createSyncedFoldersTable(db);
  1297. upgraded = true;
  1298. db.setTransactionSuccessful();
  1299. } finally {
  1300. db.endTransaction();
  1301. }
  1302. }
  1303. if (!upgraded) {
  1304. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1305. }
  1306. if (oldVersion < 17 && newVersion >= 17) {
  1307. Log_OC.i(SQL, "Entering in the #17 ADD in onUpgrade");
  1308. db.beginTransaction();
  1309. try {
  1310. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1311. ADD_COLUMN + ProviderTableMeta.FILE_FAVORITE +
  1312. " INTEGER " + " DEFAULT 0");
  1313. upgraded = true;
  1314. db.setTransactionSuccessful();
  1315. } finally {
  1316. db.endTransaction();
  1317. }
  1318. }
  1319. if (!upgraded) {
  1320. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1321. }
  1322. if (oldVersion < 18 && newVersion >= 18) {
  1323. Log_OC.i(SQL, "Entering in the #18 Adding external link column to capabilities");
  1324. db.beginTransaction();
  1325. try {
  1326. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1327. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS +
  1328. " INTEGER " + " DEFAULT -1");
  1329. upgraded = true;
  1330. db.setTransactionSuccessful();
  1331. } finally {
  1332. db.endTransaction();
  1333. }
  1334. }
  1335. if (!upgraded) {
  1336. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1337. }
  1338. if (oldVersion < 19 && newVersion >= 19) {
  1339. Log_OC.i(SQL, "Entering in the #19 Adding external link column to capabilities");
  1340. db.beginTransaction();
  1341. try {
  1342. createExternalLinksTable(db);
  1343. upgraded = true;
  1344. db.setTransactionSuccessful();
  1345. } finally {
  1346. db.endTransaction();
  1347. }
  1348. }
  1349. if (!upgraded) {
  1350. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1351. }
  1352. if (oldVersion < 20 && newVersion >= 20) {
  1353. Log_OC.i(SQL, "Entering in the #20 Adding arbitrary data table");
  1354. db.beginTransaction();
  1355. try {
  1356. createArbitraryData(db);
  1357. upgraded = true;
  1358. db.setTransactionSuccessful();
  1359. } finally {
  1360. db.endTransaction();
  1361. }
  1362. }
  1363. if (!upgraded) {
  1364. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1365. }
  1366. if (oldVersion < 21 && newVersion >= 21) {
  1367. Log_OC.i(SQL, "Entering in the #21 Adding virtual table");
  1368. db.beginTransaction();
  1369. try {
  1370. createVirtualTable(db);
  1371. upgraded = true;
  1372. db.setTransactionSuccessful();
  1373. } finally {
  1374. db.endTransaction();
  1375. }
  1376. }
  1377. if (!upgraded) {
  1378. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1379. }
  1380. if (oldVersion < 22 && newVersion >= 22) {
  1381. Log_OC.i(SQL, "Entering in the #22 Adding user theming to capabilities table");
  1382. db.beginTransaction();
  1383. try {
  1384. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1385. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
  1386. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1387. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
  1388. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1389. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
  1390. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1391. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
  1392. upgraded = true;
  1393. db.setTransactionSuccessful();
  1394. } finally {
  1395. db.endTransaction();
  1396. }
  1397. }
  1398. if (!upgraded) {
  1399. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1400. }
  1401. if (oldVersion < 23 && newVersion >= 23) {
  1402. Log_OC.i(SQL, "Entering in the #23 adding type column for synced folders, Create filesystem table");
  1403. db.beginTransaction();
  1404. try {
  1405. // add type column default being CUSTOM (0)
  1406. if (!checkIfColumnExists(db, ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME,
  1407. ProviderTableMeta.SYNCED_FOLDER_TYPE)) {
  1408. Log_OC.i(SQL, "Add type column and default value 0 (CUSTOM) to synced_folders table");
  1409. db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
  1410. ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_TYPE +
  1411. " INTEGER " + " DEFAULT 0");
  1412. } else {
  1413. Log_OC.i(SQL, "Type column of synced_folders table already exists");
  1414. }
  1415. if (!checkIfColumnExists(db, ProviderTableMeta.UPLOADS_TABLE_NAME,
  1416. ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)) {
  1417. Log_OC.i(SQL, "Add charging and wifi columns to uploads");
  1418. db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
  1419. ADD_COLUMN + ProviderTableMeta.UPLOADS_IS_WIFI_ONLY +
  1420. " INTEGER " + " DEFAULT 0");
  1421. } else {
  1422. Log_OC.i(SQL, "Wifi column of uploads table already exists");
  1423. }
  1424. if (!checkIfColumnExists(db, ProviderTableMeta.UPLOADS_TABLE_NAME,
  1425. ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY)) {
  1426. db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
  1427. ADD_COLUMN + ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY +
  1428. " INTEGER " + " DEFAULT 0");
  1429. } else {
  1430. Log_OC.i(SQL, "Charging column of uploads table already exists");
  1431. }
  1432. // create Filesystem table
  1433. Log_OC.i(SQL, "Create filesystem table");
  1434. createFileSystemTable(db);
  1435. upgraded = true;
  1436. db.setTransactionSuccessful();
  1437. } catch (Throwable t) {
  1438. Log_OC.e(TAG, "ERROR!", t);
  1439. } finally {
  1440. db.endTransaction();
  1441. }
  1442. }
  1443. if (!upgraded) {
  1444. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1445. }
  1446. if (oldVersion < 24 && newVersion >= 24) {
  1447. Log_OC.i(SQL, "Entering in the #24 Re-adding user theming to capabilities table");
  1448. db.beginTransaction();
  1449. try {
  1450. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1451. ProviderTableMeta.CAPABILITIES_SERVER_NAME)) {
  1452. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1453. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_NAME + " TEXT ");
  1454. }
  1455. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1456. ProviderTableMeta.CAPABILITIES_SERVER_COLOR)) {
  1457. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1458. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_COLOR + " TEXT ");
  1459. }
  1460. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1461. ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL)) {
  1462. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1463. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_URL + " TEXT ");
  1464. }
  1465. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1466. ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN)) {
  1467. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1468. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN + " TEXT ");
  1469. }
  1470. upgraded = true;
  1471. db.setTransactionSuccessful();
  1472. } finally {
  1473. db.endTransaction();
  1474. }
  1475. }
  1476. if (!upgraded) {
  1477. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1478. }
  1479. if (oldVersion < 25 && newVersion >= 25) {
  1480. Log_OC.i(SQL, "Entering in the #25 Adding encryption flag to file");
  1481. db.beginTransaction();
  1482. try {
  1483. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1484. ADD_COLUMN + ProviderTableMeta.FILE_IS_ENCRYPTED + " INTEGER ");
  1485. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1486. ADD_COLUMN + ProviderTableMeta.FILE_ENCRYPTED_NAME + " TEXT ");
  1487. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1488. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + " INTEGER ");
  1489. upgraded = true;
  1490. db.setTransactionSuccessful();
  1491. } finally {
  1492. db.endTransaction();
  1493. }
  1494. }
  1495. if (!upgraded) {
  1496. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1497. }
  1498. if (oldVersion < 26 && newVersion >= 26) {
  1499. Log_OC.i(SQL, "Entering in the #26 Adding text and element color to capabilities");
  1500. db.beginTransaction();
  1501. try {
  1502. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1503. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + " TEXT ");
  1504. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1505. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + " TEXT ");
  1506. upgraded = true;
  1507. db.setTransactionSuccessful();
  1508. } finally {
  1509. db.endTransaction();
  1510. }
  1511. }
  1512. if (!upgraded) {
  1513. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1514. }
  1515. if (!upgraded) {
  1516. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1517. }
  1518. if (oldVersion < 27 && newVersion >= 27) {
  1519. Log_OC.i(SQL, "Entering in the #27 Adding token to ocUpload");
  1520. db.beginTransaction();
  1521. try {
  1522. db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME +
  1523. ADD_COLUMN + ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN + " TEXT ");
  1524. upgraded = true;
  1525. db.setTransactionSuccessful();
  1526. } finally {
  1527. db.endTransaction();
  1528. }
  1529. }
  1530. if (!upgraded) {
  1531. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1532. }
  1533. if (oldVersion < 28 && newVersion >= 28) {
  1534. Log_OC.i(SQL, "Entering in the #28 Adding CRC32 column to filesystem table");
  1535. db.beginTransaction();
  1536. try {
  1537. if (!checkIfColumnExists(db, ProviderTableMeta.FILESYSTEM_TABLE_NAME,
  1538. ProviderTableMeta.FILESYSTEM_CRC32)) {
  1539. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILESYSTEM_TABLE_NAME +
  1540. ADD_COLUMN + ProviderTableMeta.FILESYSTEM_CRC32 + " TEXT ");
  1541. }
  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 < 29 && newVersion >= 29) {
  1552. Log_OC.i(SQL, "Entering in the #29 Adding background default/plain to capabilities");
  1553. db.beginTransaction();
  1554. try {
  1555. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1556. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT + " INTEGER ");
  1557. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1558. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN + " INTEGER ");
  1559. upgraded = true;
  1560. db.setTransactionSuccessful();
  1561. } finally {
  1562. db.endTransaction();
  1563. }
  1564. }
  1565. if (!upgraded) {
  1566. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1567. }
  1568. if (oldVersion < 30 && newVersion >= 30) {
  1569. Log_OC.i(SQL, "Entering in the #30 Re-add 25, 26 if needed");
  1570. db.beginTransaction();
  1571. try {
  1572. if (!checkIfColumnExists(db, ProviderTableMeta.FILE_TABLE_NAME,
  1573. ProviderTableMeta.FILE_IS_ENCRYPTED)) {
  1574. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1575. ADD_COLUMN + ProviderTableMeta.FILE_IS_ENCRYPTED + " INTEGER ");
  1576. }
  1577. if (!checkIfColumnExists(db, ProviderTableMeta.FILE_TABLE_NAME,
  1578. ProviderTableMeta.FILE_ENCRYPTED_NAME)) {
  1579. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1580. ADD_COLUMN + ProviderTableMeta.FILE_ENCRYPTED_NAME + " TEXT ");
  1581. }
  1582. if (oldVersion > ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION) {
  1583. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1584. ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION)) {
  1585. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1586. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION + " INTEGER ");
  1587. }
  1588. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1589. ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR)) {
  1590. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1591. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_TEXT_COLOR + " TEXT ");
  1592. }
  1593. if (!checkIfColumnExists(db, ProviderTableMeta.CAPABILITIES_TABLE_NAME,
  1594. ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR)) {
  1595. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1596. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_ELEMENT_COLOR + " TEXT ");
  1597. }
  1598. if (!checkIfColumnExists(db, ProviderTableMeta.FILESYSTEM_TABLE_NAME,
  1599. ProviderTableMeta.FILESYSTEM_CRC32)) {
  1600. try {
  1601. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILESYSTEM_TABLE_NAME +
  1602. ADD_COLUMN + ProviderTableMeta.FILESYSTEM_CRC32 + " TEXT ");
  1603. } catch (SQLiteException e) {
  1604. Log_OC.d(TAG, "Known problem on adding same column twice when upgrading from 24->30");
  1605. }
  1606. }
  1607. }
  1608. upgraded = true;
  1609. db.setTransactionSuccessful();
  1610. } finally {
  1611. db.endTransaction();
  1612. }
  1613. }
  1614. if (!upgraded) {
  1615. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1616. }
  1617. if (oldVersion < 31 && newVersion >= 31) {
  1618. Log_OC.i(SQL, "Entering in the #31 add mount type");
  1619. db.beginTransaction();
  1620. try {
  1621. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1622. ADD_COLUMN + ProviderTableMeta.FILE_MOUNT_TYPE + " INTEGER ");
  1623. upgraded = true;
  1624. db.setTransactionSuccessful();
  1625. } finally {
  1626. db.endTransaction();
  1627. }
  1628. }
  1629. if (!upgraded) {
  1630. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1631. }
  1632. if (oldVersion < 32 && newVersion >= 32) {
  1633. Log_OC.i(SQL, "Entering in the #32 add ocshares.is_password_protected");
  1634. db.beginTransaction();
  1635. try {
  1636. db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
  1637. ADD_COLUMN + ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + " INTEGER "); // boolean
  1638. upgraded = true;
  1639. db.setTransactionSuccessful();
  1640. } finally {
  1641. db.endTransaction();
  1642. }
  1643. }
  1644. if (!upgraded) {
  1645. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1646. }
  1647. if (oldVersion < 33 && newVersion >= 33) {
  1648. Log_OC.i(SQL, "Entering in the #3 Adding activity to capability");
  1649. db.beginTransaction();
  1650. try {
  1651. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1652. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_ACTIVITY + " INTEGER ");
  1653. upgraded = true;
  1654. db.setTransactionSuccessful();
  1655. } finally {
  1656. db.endTransaction();
  1657. }
  1658. }
  1659. if (!upgraded) {
  1660. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1661. }
  1662. if (oldVersion < 34 && newVersion >= 34) {
  1663. Log_OC.i(SQL, "Entering in the #34 add redirect to external links");
  1664. db.beginTransaction();
  1665. try {
  1666. if (!checkIfColumnExists(db, ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME,
  1667. ProviderTableMeta.EXTERNAL_LINKS_REDIRECT)) {
  1668. db.execSQL(ALTER_TABLE + ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME +
  1669. ADD_COLUMN + ProviderTableMeta.EXTERNAL_LINKS_REDIRECT + " INTEGER "); // boolean
  1670. }
  1671. upgraded = true;
  1672. db.setTransactionSuccessful();
  1673. } finally {
  1674. db.endTransaction();
  1675. }
  1676. }
  1677. if (!upgraded) {
  1678. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1679. }
  1680. if (oldVersion < 35 && newVersion >= 35) {
  1681. Log_OC.i(SQL, "Entering in the #35 add note to share table");
  1682. db.beginTransaction();
  1683. try {
  1684. db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
  1685. ADD_COLUMN + ProviderTableMeta.OCSHARES_NOTE + " TEXT ");
  1686. upgraded = true;
  1687. db.setTransactionSuccessful();
  1688. } finally {
  1689. db.endTransaction();
  1690. }
  1691. }
  1692. if (!upgraded) {
  1693. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1694. }
  1695. if (oldVersion < 36 && newVersion >= 36) {
  1696. Log_OC.i(SQL, "Entering in the #36 add has-preview to file table");
  1697. db.beginTransaction();
  1698. try {
  1699. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1700. ADD_COLUMN + ProviderTableMeta.FILE_HAS_PREVIEW + " INTEGER ");
  1701. upgraded = true;
  1702. db.setTransactionSuccessful();
  1703. } finally {
  1704. db.endTransaction();
  1705. }
  1706. }
  1707. if (!upgraded) {
  1708. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1709. }
  1710. if (oldVersion < 37 && newVersion >= 37) {
  1711. Log_OC.i(SQL, "Entering in the #37 add hide-download to share table");
  1712. db.beginTransaction();
  1713. try {
  1714. db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
  1715. ADD_COLUMN + ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + " INTEGER ");
  1716. upgraded = true;
  1717. db.setTransactionSuccessful();
  1718. } finally {
  1719. db.endTransaction();
  1720. }
  1721. }
  1722. if (!upgraded) {
  1723. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1724. }
  1725. if (oldVersion < 38 && newVersion >= 38) {
  1726. Log_OC.i(SQL, "Entering in the #38 add richdocuments");
  1727. db.beginTransaction();
  1728. try {
  1729. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1730. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT + " INTEGER "); // boolean
  1731. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1732. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST + " TEXT "); // string
  1733. upgraded = true;
  1734. db.setTransactionSuccessful();
  1735. } finally {
  1736. db.endTransaction();
  1737. }
  1738. }
  1739. if (!upgraded) {
  1740. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1741. }
  1742. if (oldVersion < 39 && newVersion >= 39) {
  1743. Log_OC.i(SQL, "Entering in the #39 add richdocuments direct editing");
  1744. db.beginTransaction();
  1745. try {
  1746. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1747. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_DIRECT_EDITING + " INTEGER "); // bool
  1748. upgraded = true;
  1749. db.setTransactionSuccessful();
  1750. } finally {
  1751. db.endTransaction();
  1752. }
  1753. }
  1754. if (!upgraded) {
  1755. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1756. }
  1757. if (oldVersion < 40 && newVersion >= 40) {
  1758. Log_OC.i(SQL, "Entering in the #40 add unreadCommentsCount to file table");
  1759. db.beginTransaction();
  1760. try {
  1761. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1762. ADD_COLUMN + ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT + " INTEGER ");
  1763. upgraded = true;
  1764. db.setTransactionSuccessful();
  1765. } finally {
  1766. db.endTransaction();
  1767. }
  1768. }
  1769. if (!upgraded) {
  1770. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1771. }
  1772. if (oldVersion < 41 && newVersion >= 41) {
  1773. Log_OC.i(SQL, "Entering in the #41 add eTagOnServer");
  1774. db.beginTransaction();
  1775. try {
  1776. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1777. ADD_COLUMN + ProviderTableMeta.FILE_ETAG_ON_SERVER + " TEXT ");
  1778. upgraded = true;
  1779. db.setTransactionSuccessful();
  1780. } finally {
  1781. db.endTransaction();
  1782. }
  1783. }
  1784. if (!upgraded) {
  1785. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1786. }
  1787. if (oldVersion < 42 && newVersion >= 42) {
  1788. Log_OC.i(SQL, "Entering in the #42 add richDocuments templates");
  1789. db.beginTransaction();
  1790. try {
  1791. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1792. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_TEMPLATES + " INTEGER ");
  1793. upgraded = true;
  1794. db.setTransactionSuccessful();
  1795. } finally {
  1796. db.endTransaction();
  1797. }
  1798. }
  1799. if (!upgraded) {
  1800. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1801. }
  1802. if (oldVersion < 43 && newVersion >= 43) {
  1803. Log_OC.i(SQL, "Entering in the #43 add ownerId and owner display name to file table");
  1804. db.beginTransaction();
  1805. try {
  1806. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1807. ADD_COLUMN + ProviderTableMeta.FILE_OWNER_ID + " TEXT ");
  1808. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1809. ADD_COLUMN + ProviderTableMeta.FILE_OWNER_DISPLAY_NAME + " TEXT ");
  1810. upgraded = true;
  1811. db.setTransactionSuccessful();
  1812. } finally {
  1813. db.endTransaction();
  1814. }
  1815. }
  1816. if (!upgraded) {
  1817. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1818. }
  1819. if (oldVersion < 44 && newVersion >= 44) {
  1820. Log_OC.i(SQL, "Entering in the #44 add note to file table");
  1821. db.beginTransaction();
  1822. try {
  1823. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1824. ADD_COLUMN + ProviderTableMeta.FILE_NOTE + " TEXT ");
  1825. upgraded = true;
  1826. db.setTransactionSuccessful();
  1827. } finally {
  1828. db.endTransaction();
  1829. }
  1830. }
  1831. if (!upgraded) {
  1832. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1833. }
  1834. if (oldVersion < 45 && newVersion >= 45) {
  1835. Log_OC.i(SQL, "Entering in the #45 add sharees to file table");
  1836. db.beginTransaction();
  1837. try {
  1838. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1839. ADD_COLUMN + ProviderTableMeta.FILE_SHAREES + " TEXT ");
  1840. upgraded = true;
  1841. db.setTransactionSuccessful();
  1842. } finally {
  1843. db.endTransaction();
  1844. }
  1845. }
  1846. if (!upgraded) {
  1847. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1848. }
  1849. if (oldVersion < 46 && newVersion >= 46) {
  1850. Log_OC.i(SQL, "Entering in the #46 add optional mimetypes to capabilities table");
  1851. db.beginTransaction();
  1852. try {
  1853. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1854. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_OPTIONAL_MIMETYPE_LIST
  1855. + " TEXT ");
  1856. upgraded = true;
  1857. db.setTransactionSuccessful();
  1858. } finally {
  1859. db.endTransaction();
  1860. }
  1861. }
  1862. if (!upgraded) {
  1863. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1864. }
  1865. if (oldVersion < 47 && newVersion >= 47) {
  1866. Log_OC.i(SQL, "Entering in the #47 add askForPassword to capability table");
  1867. db.beginTransaction();
  1868. try {
  1869. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1870. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ASK_FOR_OPTIONAL_PASSWORD +
  1871. " INTEGER ");
  1872. upgraded = true;
  1873. db.setTransactionSuccessful();
  1874. } finally {
  1875. db.endTransaction();
  1876. }
  1877. }
  1878. if (!upgraded) {
  1879. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1880. }
  1881. if (oldVersion < 48 && newVersion >= 48) {
  1882. Log_OC.i(SQL, "Entering in the #48 add product name to capabilities table");
  1883. db.beginTransaction();
  1884. try {
  1885. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1886. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_RICHDOCUMENT_PRODUCT_NAME + " TEXT ");
  1887. upgraded = true;
  1888. db.setTransactionSuccessful();
  1889. } finally {
  1890. db.endTransaction();
  1891. }
  1892. }
  1893. if (!upgraded) {
  1894. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1895. }
  1896. if (oldVersion < 49 && newVersion >= 49) {
  1897. Log_OC.i(SQL, "Entering in the #49 add extended support to capabilities table");
  1898. db.beginTransaction();
  1899. try {
  1900. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1901. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_EXTENDED_SUPPORT + " INTEGER ");
  1902. upgraded = true;
  1903. db.setTransactionSuccessful();
  1904. } finally {
  1905. db.endTransaction();
  1906. }
  1907. }
  1908. if (!upgraded) {
  1909. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1910. }
  1911. if (oldVersion < 50 && newVersion >= 50) {
  1912. Log_OC.i(SQL, "Entering in the #50 add persistent enable date to synced_folders table");
  1913. db.beginTransaction();
  1914. try {
  1915. db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
  1916. ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER ");
  1917. db.execSQL("UPDATE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + " SET " +
  1918. ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " = CASE " +
  1919. " WHEN enabled = 0 THEN " + SyncedFolder.EMPTY_ENABLED_TIMESTAMP_MS + " " +
  1920. " ELSE " + clock.getCurrentTime() +
  1921. " END ");
  1922. upgraded = true;
  1923. db.setTransactionSuccessful();
  1924. } finally {
  1925. db.endTransaction();
  1926. }
  1927. }
  1928. if (!upgraded) {
  1929. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1930. }
  1931. if (oldVersion < 51 && newVersion >= 51) {
  1932. Log_OC.i(SQL, "Entering in the #51 add show/hide to folderSync table");
  1933. db.beginTransaction();
  1934. try {
  1935. db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
  1936. ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_HIDDEN + " INTEGER ");
  1937. upgraded = true;
  1938. db.setTransactionSuccessful();
  1939. } finally {
  1940. db.endTransaction();
  1941. }
  1942. }
  1943. if (!upgraded) {
  1944. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1945. }
  1946. if (oldVersion < 52 && newVersion >= 52) {
  1947. Log_OC.i(SQL, "Entering in the #52 add etag for directEditing to capability");
  1948. db.beginTransaction();
  1949. try {
  1950. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  1951. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_DIRECT_EDITING_ETAG + " TEXT ");
  1952. upgraded = true;
  1953. db.setTransactionSuccessful();
  1954. } finally {
  1955. db.endTransaction();
  1956. }
  1957. }
  1958. if (!upgraded) {
  1959. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1960. }
  1961. if (oldVersion < 53 && newVersion >= 53) {
  1962. Log_OC.i(SQL, "Entering in the #53 add rich workspace to file table");
  1963. db.beginTransaction();
  1964. try {
  1965. if (!checkIfColumnExists(db, ProviderTableMeta.FILE_TABLE_NAME,
  1966. ProviderTableMeta.FILE_RICH_WORKSPACE)) {
  1967. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  1968. ADD_COLUMN + ProviderTableMeta.FILE_RICH_WORKSPACE + " TEXT ");
  1969. }
  1970. upgraded = true;
  1971. db.setTransactionSuccessful();
  1972. } finally {
  1973. db.endTransaction();
  1974. }
  1975. }
  1976. if (!upgraded) {
  1977. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  1978. }
  1979. if (oldVersion < 54 && newVersion >= 54) {
  1980. Log_OC.i(SQL, "Entering in the #54 add synced.existing," +
  1981. " rename uploads.force_overwrite to uploads.name_collision_policy");
  1982. db.beginTransaction();
  1983. try {
  1984. // Add synced.existing
  1985. db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
  1986. ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_EXISTING + " INTEGER "); // boolean
  1987. // Rename uploads.force_overwrite to uploads.name_collision_policy
  1988. String tmpTableName = ProviderTableMeta.UPLOADS_TABLE_NAME + "_old";
  1989. db.execSQL(ALTER_TABLE + ProviderTableMeta.UPLOADS_TABLE_NAME + " RENAME TO " + tmpTableName);
  1990. createUploadsTable(db);
  1991. db.execSQL("INSERT INTO " + ProviderTableMeta.UPLOADS_TABLE_NAME + " (" +
  1992. ProviderTableMeta._ID + ", " +
  1993. ProviderTableMeta.UPLOADS_LOCAL_PATH + ", " +
  1994. ProviderTableMeta.UPLOADS_REMOTE_PATH + ", " +
  1995. ProviderTableMeta.UPLOADS_ACCOUNT_NAME + ", " +
  1996. ProviderTableMeta.UPLOADS_FILE_SIZE + ", " +
  1997. ProviderTableMeta.UPLOADS_STATUS + ", " +
  1998. ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + ", " +
  1999. ProviderTableMeta.UPLOADS_UPLOAD_TIME + ", " +
  2000. ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY + ", " +
  2001. ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + ", " +
  2002. ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + ", " +
  2003. ProviderTableMeta.UPLOADS_LAST_RESULT + ", " +
  2004. ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + ", " +
  2005. ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + ", " +
  2006. ProviderTableMeta.UPLOADS_CREATED_BY + ", " +
  2007. ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN +
  2008. ") " +
  2009. " SELECT " +
  2010. ProviderTableMeta._ID + ", " +
  2011. ProviderTableMeta.UPLOADS_LOCAL_PATH + ", " +
  2012. ProviderTableMeta.UPLOADS_REMOTE_PATH + ", " +
  2013. ProviderTableMeta.UPLOADS_ACCOUNT_NAME + ", " +
  2014. ProviderTableMeta.UPLOADS_FILE_SIZE + ", " +
  2015. ProviderTableMeta.UPLOADS_STATUS + ", " +
  2016. ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR + ", " +
  2017. ProviderTableMeta.UPLOADS_UPLOAD_TIME + ", " +
  2018. "force_overwrite" + ", " + // See FileUploader.NameCollisionPolicy
  2019. ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER + ", " +
  2020. ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP + ", " +
  2021. ProviderTableMeta.UPLOADS_LAST_RESULT + ", " +
  2022. ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY + ", " +
  2023. ProviderTableMeta.UPLOADS_IS_WIFI_ONLY + ", " +
  2024. ProviderTableMeta.UPLOADS_CREATED_BY + ", " +
  2025. ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN +
  2026. " FROM " + tmpTableName);
  2027. db.execSQL("DROP TABLE " + tmpTableName);
  2028. upgraded = true;
  2029. db.setTransactionSuccessful();
  2030. } finally {
  2031. db.endTransaction();
  2032. }
  2033. }
  2034. if (!upgraded) {
  2035. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2036. }
  2037. if (oldVersion < 55 && newVersion >= 55) {
  2038. Log_OC.i(SQL, "Entering in the #55 add synced.name_collision_policy.");
  2039. db.beginTransaction();
  2040. try {
  2041. // Add synced.name_collision_policy
  2042. db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
  2043. ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " INTEGER "); // integer
  2044. // make sure all existing folders set to FileUploader.NameCollisionPolicy.ASK_USER.
  2045. db.execSQL("UPDATE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + " SET " +
  2046. ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY + " = " +
  2047. NameCollisionPolicy.ASK_USER.serialize());
  2048. upgraded = true;
  2049. db.setTransactionSuccessful();
  2050. } finally {
  2051. db.endTransaction();
  2052. }
  2053. }
  2054. if (!upgraded) {
  2055. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2056. }
  2057. if (oldVersion < 56 && newVersion >= 56) {
  2058. Log_OC.i(SQL, "Entering in the #56 add decrypted remote path");
  2059. db.beginTransaction();
  2060. try {
  2061. // Add synced.name_collision_policy
  2062. db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
  2063. ADD_COLUMN + ProviderTableMeta.FILE_PATH_DECRYPTED + " TEXT "); // strin
  2064. upgraded = true;
  2065. db.setTransactionSuccessful();
  2066. } finally {
  2067. db.endTransaction();
  2068. }
  2069. }
  2070. if (!upgraded) {
  2071. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2072. }
  2073. if (oldVersion < 57 && newVersion >= 57) {
  2074. Log_OC.i(SQL, "Entering in the #57 add etag for capabilities");
  2075. db.beginTransaction();
  2076. try {
  2077. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  2078. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_ETAG + " TEXT ");
  2079. upgraded = true;
  2080. db.setTransactionSuccessful();
  2081. } finally {
  2082. db.endTransaction();
  2083. }
  2084. }
  2085. if (!upgraded) {
  2086. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2087. }
  2088. if (oldVersion < 58 && newVersion >= 58) {
  2089. Log_OC.i(SQL, "Entering in the #58 add public link to share table");
  2090. db.beginTransaction();
  2091. try {
  2092. db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
  2093. ADD_COLUMN + ProviderTableMeta.OCSHARES_SHARE_LINK + " TEXT ");
  2094. upgraded = true;
  2095. db.setTransactionSuccessful();
  2096. } finally {
  2097. db.endTransaction();
  2098. }
  2099. }
  2100. if (!upgraded) {
  2101. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2102. }
  2103. if (oldVersion < 59 && newVersion >= 59) {
  2104. Log_OC.i(SQL, "Entering in the #59 add public label to share table");
  2105. db.beginTransaction();
  2106. try {
  2107. db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
  2108. ADD_COLUMN + ProviderTableMeta.OCSHARES_SHARE_LABEL + " TEXT ");
  2109. upgraded = true;
  2110. db.setTransactionSuccessful();
  2111. } finally {
  2112. db.endTransaction();
  2113. }
  2114. }
  2115. if (!upgraded) {
  2116. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2117. }
  2118. if (oldVersion < 60 && newVersion >= 60) {
  2119. Log_OC.i(SQL, "Entering in the #60 add user status to capability table");
  2120. db.beginTransaction();
  2121. try {
  2122. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  2123. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_USER_STATUS + " INTEGER ");
  2124. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  2125. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI + " INTEGER ");
  2126. upgraded = true;
  2127. db.setTransactionSuccessful();
  2128. } finally {
  2129. db.endTransaction();
  2130. }
  2131. }
  2132. if (!upgraded) {
  2133. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2134. }
  2135. if (oldVersion < 61 && newVersion >= 61) {
  2136. Log_OC.i(SQL, "Entering in the #61 reset eTag to force capability refresh");
  2137. db.beginTransaction();
  2138. try {
  2139. db.execSQL("UPDATE capabilities SET etag = '' WHERE 1=1");
  2140. upgraded = true;
  2141. db.setTransactionSuccessful();
  2142. } finally {
  2143. db.endTransaction();
  2144. }
  2145. }
  2146. if (!upgraded) {
  2147. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2148. }
  2149. if (oldVersion < 62 && newVersion >= 62) {
  2150. Log_OC.i(SQL, "Entering in the #62 add logo to capability");
  2151. db.beginTransaction();
  2152. try {
  2153. db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
  2154. ADD_COLUMN + ProviderTableMeta.CAPABILITIES_SERVER_LOGO + " TEXT ");
  2155. // force refresh
  2156. db.execSQL("UPDATE capabilities SET etag = '' WHERE 1=1");
  2157. upgraded = true;
  2158. db.setTransactionSuccessful();
  2159. } finally {
  2160. db.endTransaction();
  2161. }
  2162. }
  2163. if (!upgraded) {
  2164. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2165. }
  2166. if (oldVersion < 63 && newVersion >= 63) {
  2167. Log_OC.i(SQL, "Entering in the #63 add remote_id to virtuals");
  2168. db.beginTransaction();
  2169. try {
  2170. db.execSQL(ALTER_TABLE + ProviderTableMeta.VIRTUAL_TABLE_NAME +
  2171. ADD_COLUMN + ProviderTableMeta.VIRTUAL_OCFILE_REMOTE_ID + " TEXT ");
  2172. // delete all virtual
  2173. db.execSQL("DELETE FROM `virtual`");
  2174. upgraded = true;
  2175. db.setTransactionSuccessful();
  2176. } finally {
  2177. db.endTransaction();
  2178. }
  2179. }
  2180. if (!upgraded) {
  2181. Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
  2182. }
  2183. }
  2184. }
  2185. }