FileContentProvider.java 113 KB

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