RefreshFolderOperation.java 24 KB

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