FileContentProvider.java 107 KB

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