RefreshFolderOperation.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2015 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.owncloud.android.operations;
  20. import android.accounts.Account;
  21. import android.content.Context;
  22. import android.content.Intent;
  23. import android.support.annotation.NonNull;
  24. import android.support.annotation.Nullable;
  25. import android.util.Log;
  26. import com.owncloud.android.datamodel.DecryptedFolderMetadata;
  27. import com.owncloud.android.datamodel.FileDataStorageManager;
  28. import com.owncloud.android.datamodel.OCFile;
  29. import com.owncloud.android.lib.common.OwnCloudClient;
  30. import com.owncloud.android.lib.common.operations.RemoteOperation;
  31. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  32. import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
  33. import com.owncloud.android.lib.common.utils.Log_OC;
  34. import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
  35. import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
  36. import com.owncloud.android.lib.resources.files.RemoteFile;
  37. import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation;
  38. import com.owncloud.android.lib.resources.shares.OCShare;
  39. import com.owncloud.android.lib.resources.shares.ShareType;
  40. import com.owncloud.android.syncadapter.FileSyncAdapter;
  41. import com.owncloud.android.utils.DataHolderUtil;
  42. import com.owncloud.android.utils.EncryptionUtils;
  43. import com.owncloud.android.utils.FileStorageUtils;
  44. import com.owncloud.android.utils.MimeTypeUtil;
  45. import java.util.ArrayList;
  46. import java.util.HashMap;
  47. import java.util.List;
  48. import java.util.Map;
  49. import java.util.Vector;
  50. /**
  51. * Remote operation performing the synchronization of the list of files contained
  52. * in a folder identified with its remote path.
  53. *
  54. * Fetches the list and properties of the files contained in the given folder, including their
  55. * properties, and updates the local database with them.
  56. *
  57. * Does NOT enter in the child folders to synchronize their contents also.
  58. */
  59. @SuppressWarnings("PMD.AvoidDuplicateLiterals")
  60. public class RefreshFolderOperation extends RemoteOperation {
  61. private static final String TAG = RefreshFolderOperation.class.getSimpleName();
  62. public static final String EVENT_SINGLE_FOLDER_CONTENTS_SYNCED =
  63. RefreshFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_CONTENTS_SYNCED";
  64. public static final String EVENT_SINGLE_FOLDER_SHARES_SYNCED =
  65. RefreshFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_SHARES_SYNCED";
  66. /** Time stamp for the synchronization process in progress */
  67. private long mCurrentSyncTime;
  68. /** Remote folder to synchronize */
  69. private OCFile mLocalFolder;
  70. /** Access to the local database */
  71. private FileDataStorageManager mStorageManager;
  72. /** Account where the file to synchronize belongs */
  73. private Account mAccount;
  74. /** Android context; necessary to send requests to the download service */
  75. private Context mContext;
  76. /** Files and folders contained in the synchronized folder after a successful operation */
  77. private List<OCFile> mChildren;
  78. /** Counter of conflicts found between local and remote files */
  79. private int mConflictsFound;
  80. /** Counter of failed operations in synchronization of kept-in-sync files */
  81. private int mFailsInKeptInSyncFound;
  82. /**
  83. * Map of remote and local paths to files that where locally stored in a location
  84. * out of the ownCloud folder and couldn't be copied automatically into it
  85. **/
  86. private Map<String, String> mForgottenLocalFiles;
  87. /**
  88. * 'True' means that this operation is part of a full account synchronization
  89. */
  90. private boolean mSyncFullAccount;
  91. /** 'True' means that the remote folder changed and should be fetched */
  92. private boolean mRemoteFolderChanged;
  93. /** 'True' means that Etag will be ignored */
  94. private boolean mIgnoreETag;
  95. private List<SynchronizeFileOperation> mFilesToSyncContents;
  96. // this will be used for every file when 'folder synchronization' replaces 'folder download'
  97. /**
  98. * Creates a new instance of {@link RefreshFolderOperation}.
  99. *
  100. * @param folder Folder to synchronize.
  101. * @param currentSyncTime Time stamp for the synchronization process in progress.
  102. * @param syncFullAccount 'True' means that this operation is part of a full account
  103. * synchronization.
  104. * @param ignoreETag 'True' means that the content of the remote folder should
  105. * be fetched and updated even though the 'eTag' did not
  106. * change.
  107. * @param dataStorageManager Interface with the local database.
  108. * @param account ownCloud account where the folder is located.
  109. * @param context Application context.
  110. */
  111. public RefreshFolderOperation(OCFile folder,
  112. long currentSyncTime,
  113. boolean syncFullAccount,
  114. boolean ignoreETag,
  115. FileDataStorageManager dataStorageManager,
  116. Account account,
  117. Context context) {
  118. mLocalFolder = folder;
  119. mCurrentSyncTime = currentSyncTime;
  120. mSyncFullAccount = syncFullAccount;
  121. mStorageManager = dataStorageManager;
  122. mAccount = account;
  123. mContext = context;
  124. mForgottenLocalFiles = new HashMap<>();
  125. mRemoteFolderChanged = false;
  126. mIgnoreETag = ignoreETag;
  127. mFilesToSyncContents = new Vector<>();
  128. }
  129. public int getConflictsFound() {
  130. return mConflictsFound;
  131. }
  132. public int getFailsInKeptInSyncFound() {
  133. return mFailsInKeptInSyncFound;
  134. }
  135. public Map<String, String> getForgottenLocalFiles() {
  136. return mForgottenLocalFiles;
  137. }
  138. /**
  139. * Returns the list of files and folders contained in the synchronized folder,
  140. * if called after synchronization is complete.
  141. *
  142. * @return List of files and folders contained in the synchronized folder.
  143. */
  144. public List<OCFile> getChildren() {
  145. return mChildren;
  146. }
  147. /**
  148. * Performs the synchronization.
  149. *
  150. * {@inheritDoc}
  151. */
  152. @Override
  153. protected RemoteOperationResult run(OwnCloudClient client) {
  154. RemoteOperationResult result;
  155. mFailsInKeptInSyncFound = 0;
  156. mConflictsFound = 0;
  157. mForgottenLocalFiles.clear();
  158. if (OCFile.ROOT_PATH.equals(mLocalFolder.getRemotePath()) && !mSyncFullAccount) {
  159. updateOCVersion(client);
  160. updateUserProfile();
  161. }
  162. result = checkForChanges(client);
  163. if (result.isSuccess()) {
  164. if (mRemoteFolderChanged) {
  165. result = fetchAndSyncRemoteFolder(client);
  166. } else {
  167. fetchKeptInSyncFilesToSyncFromLocalData();
  168. mChildren = mStorageManager.getFolderContent(mLocalFolder, false);
  169. }
  170. if (result.isSuccess()) {
  171. // request for the synchronization of KEPT-IN-SYNC file contents
  172. startContentSynchronizations(mFilesToSyncContents);
  173. }
  174. mLocalFolder.setLastSyncDateForData(System.currentTimeMillis());
  175. mStorageManager.saveFile(mLocalFolder);
  176. }
  177. if (!mSyncFullAccount) {
  178. sendLocalBroadcast(
  179. EVENT_SINGLE_FOLDER_CONTENTS_SYNCED, mLocalFolder.getRemotePath(), result
  180. );
  181. }
  182. if (result.isSuccess() && !mSyncFullAccount) {
  183. refreshSharesForFolder(client); // share result is ignored
  184. }
  185. if (!mSyncFullAccount) {
  186. sendLocalBroadcast(
  187. EVENT_SINGLE_FOLDER_SHARES_SYNCED, mLocalFolder.getRemotePath(), result
  188. );
  189. }
  190. return result;
  191. }
  192. private void updateOCVersion(OwnCloudClient client) {
  193. UpdateOCVersionOperation update = new UpdateOCVersionOperation(mAccount, mContext);
  194. RemoteOperationResult result = update.execute(client);
  195. if (result.isSuccess()) {
  196. // Update Capabilities for this account
  197. updateCapabilities();
  198. }
  199. }
  200. private void updateUserProfile() {
  201. GetUserProfileOperation update = new GetUserProfileOperation();
  202. RemoteOperationResult result = update.execute(mStorageManager, mContext);
  203. if (!result.isSuccess()) {
  204. Log_OC.w(TAG, "Couldn't update user profile from server");
  205. } else {
  206. Log_OC.i(TAG, "Got display name: " + result.getData().get(0));
  207. }
  208. }
  209. private void updateCapabilities() {
  210. GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation();
  211. RemoteOperationResult result = getCapabilities.execute(mStorageManager, mContext);
  212. if (!result.isSuccess()) {
  213. Log_OC.w(TAG, "Update Capabilities unsuccessfully");
  214. }
  215. }
  216. private RemoteOperationResult checkForChanges(OwnCloudClient client) {
  217. mRemoteFolderChanged = true;
  218. RemoteOperationResult result;
  219. String remotePath = mLocalFolder.getRemotePath();
  220. Log_OC.d(TAG, "Checking changes in " + mAccount.name + remotePath);
  221. // remote request
  222. ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath);
  223. result = operation.execute(client, true);
  224. if (result.isSuccess()) {
  225. OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
  226. if (!mIgnoreETag) {
  227. // check if remote and local folder are different
  228. String remoteFolderETag = remoteFolder.getEtag();
  229. if (remoteFolderETag != null) {
  230. mRemoteFolderChanged =
  231. !(remoteFolderETag.equalsIgnoreCase(mLocalFolder.getEtag()));
  232. } else {
  233. Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
  234. "No ETag received from server");
  235. }
  236. }
  237. result = new RemoteOperationResult(ResultCode.OK);
  238. Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " +
  239. (mRemoteFolderChanged ? "changed" : "not changed"));
  240. } else {
  241. // check failed
  242. if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
  243. removeLocalFolder();
  244. }
  245. if (result.isException()) {
  246. Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
  247. result.getLogMessage(), result.getException());
  248. } else {
  249. Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
  250. result.getLogMessage());
  251. }
  252. }
  253. return result;
  254. }
  255. private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) {
  256. String remotePath = mLocalFolder.getRemotePath();
  257. ReadRemoteFolderOperation operation = new ReadRemoteFolderOperation(remotePath);
  258. RemoteOperationResult result = operation.execute(client, true);
  259. Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath);
  260. if (result.isSuccess()) {
  261. synchronizeData(result.getData());
  262. if (mConflictsFound > 0 || mFailsInKeptInSyncFound > 0) {
  263. result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
  264. // should be a different result code, but will do the job
  265. }
  266. } else {
  267. if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
  268. removeLocalFolder();
  269. }
  270. }
  271. return result;
  272. }
  273. private void removeLocalFolder() {
  274. if (mStorageManager.fileExists(mLocalFolder.getFileId())) {
  275. String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
  276. mStorageManager.removeFolder(
  277. mLocalFolder,
  278. true,
  279. mLocalFolder.isDown() && mLocalFolder.getStoragePath().startsWith(currentSavePath)
  280. );
  281. }
  282. }
  283. /**
  284. * Synchronizes the data retrieved from the server about the contents of the target folder
  285. * with the current data in the local database.
  286. *
  287. * Grants that mChildren is updated with fresh data after execution.
  288. *
  289. * @param folderAndFiles Remote folder and children files in Folder
  290. */
  291. private void synchronizeData(List<Object> folderAndFiles) {
  292. // get 'fresh data' from the database
  293. mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath());
  294. // parse data from remote folder
  295. OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0));
  296. remoteFolder.setParentId(mLocalFolder.getParentId());
  297. remoteFolder.setFileId(mLocalFolder.getFileId());
  298. Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
  299. List<OCFile> updatedFiles = new ArrayList<>(folderAndFiles.size() - 1);
  300. mFilesToSyncContents.clear();
  301. // if local folder is encrypted, download fresh metadata
  302. boolean encryptedAncestor = FileStorageUtils.checkEncryptionStatus(mLocalFolder, mStorageManager);
  303. mLocalFolder.setEncrypted(encryptedAncestor);
  304. DecryptedFolderMetadata metadata = getDecryptedFolderMetadata(encryptedAncestor);
  305. // get current data about local contents of the folder to synchronize
  306. Map<String, OCFile> localFilesMap = prefillLocalFilesMap(metadata,
  307. mStorageManager.getFolderContent(mLocalFolder, false));
  308. // loop to update every child
  309. OCFile remoteFile;
  310. OCFile localFile;
  311. OCFile updatedFile;
  312. RemoteFile r;
  313. for (int i = 1; i < folderAndFiles.size(); i++) {
  314. /// new OCFile instance with the data from the server
  315. r = (RemoteFile) folderAndFiles.get(i);
  316. remoteFile = FileStorageUtils.fillOCFile(r);
  317. // new OCFile instance to merge fresh data from server with local state
  318. updatedFile = FileStorageUtils.fillOCFile(r);
  319. updatedFile.setParentId(mLocalFolder.getFileId());
  320. // retrieve local data for the read file
  321. localFile = localFilesMap.remove(remoteFile.getRemotePath());
  322. // add to updatedFile data about LOCAL STATE (not existing in server)
  323. updatedFile.setLastSyncDateForProperties(mCurrentSyncTime);
  324. // add to updatedFile data from local and remote file
  325. setLocalFileDataOnUpdatedFile(remoteFile, localFile, updatedFile, mRemoteFolderChanged);
  326. // check and fix, if needed, local storage path
  327. FileStorageUtils.searchForLocalFileInDefaultPath(updatedFile, mAccount);
  328. // prepare content synchronization for kept-in-sync files
  329. if (updatedFile.isAvailableOffline()) {
  330. mFilesToSyncContents.add(
  331. new SynchronizeFileOperation(localFile, remoteFile, mAccount, true, mContext)
  332. );
  333. }
  334. // update file name for encrypted files
  335. if (metadata != null) {
  336. updateFileNameForEncryptedFile(metadata, updatedFile);
  337. }
  338. // we parse content, so either the folder itself or its direct parent (which we check) must be encrypted
  339. boolean encrypted = updatedFile.isEncrypted() || mLocalFolder.isEncrypted();
  340. updatedFile.setEncrypted(encrypted);
  341. updatedFiles.add(updatedFile);
  342. }
  343. // save updated contents in local database
  344. mStorageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());
  345. mChildren = updatedFiles;
  346. }
  347. @Nullable
  348. private DecryptedFolderMetadata getDecryptedFolderMetadata(boolean encryptedAncestor) {
  349. DecryptedFolderMetadata metadata;
  350. if (encryptedAncestor && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
  351. metadata = EncryptionUtils.downloadFolderMetadata(mLocalFolder, getClient(), mContext, mAccount);
  352. } else {
  353. metadata = null;
  354. }
  355. return metadata;
  356. }
  357. private void updateFileNameForEncryptedFile(@NonNull DecryptedFolderMetadata metadata, OCFile updatedFile) {
  358. updatedFile.setEncryptedFileName(updatedFile.getFileName());
  359. try {
  360. String decryptedFileName = metadata.getFiles().get(updatedFile.getFileName()).getEncrypted()
  361. .getFilename();
  362. String mimetype = metadata.getFiles().get(updatedFile.getFileName()).getEncrypted().getMimetype();
  363. updatedFile.setFileName(decryptedFileName);
  364. if (mimetype == null || mimetype.isEmpty()) {
  365. updatedFile.setMimetype("application/octet-stream");
  366. } else {
  367. updatedFile.setMimetype(mimetype);
  368. }
  369. } catch (NullPointerException e) {
  370. Log_OC.e(TAG, "Metadata for file " + updatedFile.getFileId() + " not found!");
  371. }
  372. }
  373. private void setLocalFileDataOnUpdatedFile(OCFile remoteFile, OCFile localFile, OCFile updatedFile, boolean remoteFolderChanged) {
  374. if (localFile != null) {
  375. updatedFile.setFileId(localFile.getFileId());
  376. updatedFile.setAvailableOffline(localFile.isAvailableOffline());
  377. updatedFile.setLastSyncDateForData(localFile.getLastSyncDateForData());
  378. updatedFile.setModificationTimestampAtLastSyncForData(
  379. localFile.getModificationTimestampAtLastSyncForData()
  380. );
  381. updatedFile.setStoragePath(localFile.getStoragePath());
  382. // eTag will not be updated unless file CONTENTS are synchronized
  383. if (!updatedFile.isFolder() && localFile.isDown() &&
  384. !updatedFile.getEtag().equals(localFile.getEtag())) {
  385. updatedFile.setEtagInConflict(updatedFile.getEtag());
  386. }
  387. updatedFile.setEtag(localFile.getEtag());
  388. if (updatedFile.isFolder()) {
  389. updatedFile.setFileLength(remoteFile.getFileLength());
  390. updatedFile.setMountType(remoteFile.getMountType());
  391. } else if (remoteFolderChanged && MimeTypeUtil.isImage(remoteFile) &&
  392. remoteFile.getModificationTimestamp() !=
  393. localFile.getModificationTimestamp()) {
  394. updatedFile.setNeedsUpdateThumbnail(true);
  395. Log.d(TAG, "Image " + remoteFile.getFileName() + " updated on the server");
  396. }
  397. updatedFile.setPublicLink(localFile.getPublicLink());
  398. updatedFile.setShareViaLink(localFile.isSharedViaLink());
  399. updatedFile.setShareWithSharee(localFile.isSharedWithSharee());
  400. } else {
  401. // remote eTag will not be updated unless file CONTENTS are synchronized
  402. updatedFile.setEtag("");
  403. }
  404. }
  405. @NonNull
  406. private Map<String, OCFile> prefillLocalFilesMap(DecryptedFolderMetadata metadata, List<OCFile> localFiles) {
  407. Map<String, OCFile> localFilesMap = new HashMap<>(localFiles.size());
  408. for (OCFile file : localFiles) {
  409. String remotePath = file.getRemotePath();
  410. if (metadata != null && !file.isFolder()) {
  411. remotePath = file.getParentRemotePath() + file.getEncryptedFileName();
  412. }
  413. localFilesMap.put(remotePath, file);
  414. }
  415. return localFilesMap;
  416. }
  417. /**
  418. * Performs a list of synchronization operations, determining if a download or upload is needed
  419. * or if exists conflict due to changes both in local and remote contents of the each file.
  420. *
  421. * If download or upload is needed, request the operation to the corresponding service and goes
  422. * on.
  423. *
  424. * @param filesToSyncContents Synchronization operations to execute.
  425. */
  426. private void startContentSynchronizations(List<SynchronizeFileOperation> filesToSyncContents) {
  427. RemoteOperationResult contentsResult;
  428. for (SynchronizeFileOperation op : filesToSyncContents) {
  429. contentsResult = op.execute(mStorageManager, mContext); // async
  430. if (!contentsResult.isSuccess()) {
  431. if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
  432. mConflictsFound++;
  433. } else {
  434. mFailsInKeptInSyncFound++;
  435. if (contentsResult.getException() != null) {
  436. Log_OC.e(TAG, "Error while synchronizing favourites : "
  437. + contentsResult.getLogMessage(), contentsResult.getException());
  438. } else {
  439. Log_OC.e(TAG, "Error while synchronizing favourites : "
  440. + contentsResult.getLogMessage());
  441. }
  442. }
  443. } // won't let these fails break the synchronization process
  444. }
  445. }
  446. /**
  447. * Syncs the Share resources for the files contained in the folder refreshed (children, not deeper descendants).
  448. *
  449. * @param client Handler of a session with an OC server.
  450. * @return The result of the remote operation retrieving the Share resources in the folder refreshed by
  451. * the operation.
  452. */
  453. private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) {
  454. RemoteOperationResult result;
  455. // remote request
  456. GetRemoteSharesForFileOperation operation =
  457. new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), true, true);
  458. result = operation.execute(client);
  459. if (result.isSuccess()) {
  460. // update local database
  461. ArrayList<OCShare> shares = new ArrayList<>();
  462. OCShare share;
  463. for (Object obj : result.getData()) {
  464. share = (OCShare) obj;
  465. if (!ShareType.NO_SHARED.equals(share.getShareType())) {
  466. shares.add(share);
  467. }
  468. }
  469. mStorageManager.saveSharesInFolder(shares, mLocalFolder);
  470. }
  471. return result;
  472. }
  473. /**
  474. * Sends a message to any application component interested in the progress
  475. * of the synchronization.
  476. *
  477. * @param event broadcast event (Intent Action)
  478. * @param dirRemotePath Remote path of a folder that was just synchronized
  479. * (with or without success)
  480. * @param result remote operation result
  481. */
  482. private void sendLocalBroadcast(String event, String dirRemotePath, RemoteOperationResult result) {
  483. Log_OC.d(TAG, "Send broadcast " + event);
  484. Intent intent = new Intent(event);
  485. intent.putExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME, mAccount.name);
  486. if (dirRemotePath != null) {
  487. intent.putExtra(FileSyncAdapter.EXTRA_FOLDER_PATH, dirRemotePath);
  488. }
  489. DataHolderUtil dataHolderUtil = DataHolderUtil.getInstance();
  490. String dataHolderItemId = dataHolderUtil.nextItemId();
  491. dataHolderUtil.save(dataHolderItemId, result);
  492. intent.putExtra(FileSyncAdapter.EXTRA_RESULT, dataHolderItemId);
  493. intent.setPackage(mContext.getPackageName());
  494. mContext.sendStickyBroadcast(intent);
  495. //LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
  496. }
  497. private void fetchKeptInSyncFilesToSyncFromLocalData() {
  498. List<OCFile> children = mStorageManager.getFolderContent(mLocalFolder, false);
  499. for (OCFile child : children) {
  500. if (!child.isFolder() && child.isAvailableOffline() && !child.isInConflict()) {
  501. SynchronizeFileOperation operation = new SynchronizeFileOperation(
  502. child,
  503. child, // cheating with the remote file to get an update to server; to refactor
  504. mAccount,
  505. true,
  506. mContext
  507. );
  508. mFilesToSyncContents.add(operation);
  509. }
  510. }
  511. }
  512. }