FileContentProvider.java 87 KB

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