FileContentProvider.java 111 KB

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