RefreshFolderOperation.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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.getCode() == ResultCode.MAINTENANCE_MODE) {
  245. return result;
  246. }
  247. if (result.isException()) {
  248. Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
  249. result.getLogMessage(), result.getException());
  250. } else {
  251. Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
  252. result.getLogMessage());
  253. }
  254. }
  255. return result;
  256. }
  257. private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) {
  258. String remotePath = mLocalFolder.getRemotePath();
  259. ReadRemoteFolderOperation operation = new ReadRemoteFolderOperation(remotePath);
  260. RemoteOperationResult result = operation.execute(client, true);
  261. Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath);
  262. if (result.isSuccess()) {
  263. synchronizeData(result.getData());
  264. if (mConflictsFound > 0 || mFailsInKeptInSyncFound > 0) {
  265. result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
  266. // should be a different result code, but will do the job
  267. }
  268. } else {
  269. if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
  270. removeLocalFolder();
  271. }
  272. }
  273. return result;
  274. }
  275. private void removeLocalFolder() {
  276. if (mStorageManager.fileExists(mLocalFolder.getFileId())) {
  277. String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
  278. mStorageManager.removeFolder(
  279. mLocalFolder,
  280. true,
  281. (mLocalFolder.isDown() &&
  282. mLocalFolder.getStoragePath().startsWith(currentSavePath)
  283. )
  284. );
  285. }
  286. }
  287. /**
  288. * Synchronizes the data retrieved from the server about the contents of the target folder
  289. * with the current data in the local database.
  290. *
  291. * Grants that mChildren is updated with fresh data after execution.
  292. *
  293. * @param folderAndFiles Remote folder and children files in Folder
  294. */
  295. private void synchronizeData(ArrayList<Object> folderAndFiles) {
  296. // get 'fresh data' from the database
  297. mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath());
  298. // parse data from remote folder
  299. OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0));
  300. remoteFolder.setParentId(mLocalFolder.getParentId());
  301. remoteFolder.setFileId(mLocalFolder.getFileId());
  302. Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
  303. List<OCFile> updatedFiles = new ArrayList<>(folderAndFiles.size() - 1);
  304. mFilesToSyncContents.clear();
  305. // if local folder is encrypted, download fresh metadata
  306. boolean encryptedAncestor = FileStorageUtils.checkEncryptionStatus(mLocalFolder, mStorageManager);
  307. mLocalFolder.setEncrypted(encryptedAncestor);
  308. DecryptedFolderMetadata metadata = getDecryptedFolderMetadata(encryptedAncestor);
  309. // get current data about local contents of the folder to synchronize
  310. Map<String, OCFile> localFilesMap = prefillLocalFilesMap(metadata,
  311. mStorageManager.getFolderContent(mLocalFolder, false));
  312. // loop to update every child
  313. OCFile remoteFile;
  314. OCFile localFile;
  315. OCFile updatedFile;
  316. RemoteFile r;
  317. for (int i = 1; i < folderAndFiles.size(); i++) {
  318. /// new OCFile instance with the data from the server
  319. r = (RemoteFile) folderAndFiles.get(i);
  320. remoteFile = FileStorageUtils.fillOCFile(r);
  321. // new OCFile instance to merge fresh data from server with local state
  322. updatedFile = FileStorageUtils.fillOCFile(r);
  323. updatedFile.setParentId(mLocalFolder.getFileId());
  324. // retrieve local data for the read file
  325. localFile = localFilesMap.remove(remoteFile.getRemotePath());
  326. // add to updatedFile data about LOCAL STATE (not existing in server)
  327. updatedFile.setLastSyncDateForProperties(mCurrentSyncTime);
  328. // add to updatedFile data from local and remote file
  329. setLocalFileDataOnUpdatedFile(remoteFile, localFile, updatedFile, mRemoteFolderChanged);
  330. // check and fix, if needed, local storage path
  331. FileStorageUtils.searchForLocalFileInDefaultPath(updatedFile, mAccount);
  332. // prepare content synchronization for kept-in-sync files
  333. if (updatedFile.isAvailableOffline()) {
  334. SynchronizeFileOperation operation = new SynchronizeFileOperation(localFile, remoteFile, mAccount, true,
  335. mContext);
  336. mFilesToSyncContents.add(operation);
  337. }
  338. // update file name for encrypted files
  339. if (metadata != null) {
  340. updateFileNameForEncryptedFile(metadata, updatedFile);
  341. }
  342. // we parse content, so either the folder itself or its direct parent (which we check) must be encrypted
  343. boolean encrypted = updatedFile.isEncrypted() || mLocalFolder.isEncrypted();
  344. updatedFile.setEncrypted(encrypted);
  345. updatedFiles.add(updatedFile);
  346. }
  347. // save updated contents in local database
  348. mStorageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());
  349. mChildren = updatedFiles;
  350. }
  351. @Nullable
  352. private DecryptedFolderMetadata getDecryptedFolderMetadata(boolean encryptedAncestor) {
  353. DecryptedFolderMetadata metadata;
  354. if (encryptedAncestor && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
  355. metadata = EncryptionUtils.downloadFolderMetadata(mLocalFolder, getClient(), mContext, mAccount);
  356. } else {
  357. metadata = null;
  358. }
  359. return metadata;
  360. }
  361. private void updateFileNameForEncryptedFile(@NonNull DecryptedFolderMetadata metadata, OCFile updatedFile) {
  362. updatedFile.setEncryptedFileName(updatedFile.getFileName());
  363. try {
  364. String decryptedFileName = metadata.getFiles().get(updatedFile.getFileName()).getEncrypted()
  365. .getFilename();
  366. String mimetype = metadata.getFiles().get(updatedFile.getFileName()).getEncrypted().getMimetype();
  367. updatedFile.setFileName(decryptedFileName);
  368. if (mimetype == null || mimetype.isEmpty()) {
  369. updatedFile.setMimetype("application/octet-stream");
  370. } else {
  371. updatedFile.setMimetype(mimetype);
  372. }
  373. } catch (NullPointerException e) {
  374. Log_OC.e(TAG, "Metadata for file " + updatedFile.getFileId() + " not found!");
  375. }
  376. }
  377. private void setLocalFileDataOnUpdatedFile(OCFile remoteFile, OCFile localFile, OCFile updatedFile, boolean remoteFolderChanged) {
  378. if (localFile != null) {
  379. updatedFile.setFileId(localFile.getFileId());
  380. updatedFile.setAvailableOffline(localFile.isAvailableOffline());
  381. updatedFile.setLastSyncDateForData(localFile.getLastSyncDateForData());
  382. updatedFile.setModificationTimestampAtLastSyncForData(
  383. localFile.getModificationTimestampAtLastSyncForData()
  384. );
  385. updatedFile.setStoragePath(localFile.getStoragePath());
  386. // eTag will not be updated unless file CONTENTS are synchronized
  387. if (!updatedFile.isFolder() && localFile.isDown() &&
  388. !updatedFile.getEtag().equals(localFile.getEtag())) {
  389. updatedFile.setEtagInConflict(updatedFile.getEtag());
  390. }
  391. updatedFile.setEtag(localFile.getEtag());
  392. if (updatedFile.isFolder()) {
  393. updatedFile.setFileLength(remoteFile.getFileLength());
  394. updatedFile.setMountType(remoteFile.getMountType());
  395. } else if (remoteFolderChanged && MimeTypeUtil.isImage(remoteFile) &&
  396. remoteFile.getModificationTimestamp() !=
  397. localFile.getModificationTimestamp()) {
  398. updatedFile.setNeedsUpdateThumbnail(true);
  399. Log.d(TAG, "Image " + remoteFile.getFileName() + " updated on the server");
  400. }
  401. updatedFile.setPublicLink(localFile.getPublicLink());
  402. updatedFile.setShareViaLink(localFile.isSharedViaLink());
  403. updatedFile.setShareWithSharee(localFile.isSharedWithSharee());
  404. } else {
  405. // remote eTag will not be updated unless file CONTENTS are synchronized
  406. updatedFile.setEtag("");
  407. }
  408. }
  409. @NonNull
  410. private Map<String, OCFile> prefillLocalFilesMap(DecryptedFolderMetadata metadata, List<OCFile> localFiles) {
  411. Map<String, OCFile> localFilesMap = new HashMap<>(localFiles.size());
  412. for (OCFile file : localFiles) {
  413. String remotePath = file.getRemotePath();
  414. if (metadata != null && !file.isFolder()) {
  415. remotePath = file.getParentRemotePath() + file.getEncryptedFileName();
  416. }
  417. localFilesMap.put(remotePath, file);
  418. }
  419. return localFilesMap;
  420. }
  421. /**
  422. * Performs a list of synchronization operations, determining if a download or upload is needed
  423. * or if exists conflict due to changes both in local and remote contents of the each file.
  424. *
  425. * If download or upload is needed, request the operation to the corresponding service and goes
  426. * on.
  427. *
  428. * @param filesToSyncContents Synchronization operations to execute.
  429. */
  430. private void startContentSynchronizations(List<SynchronizeFileOperation> filesToSyncContents) {
  431. RemoteOperationResult contentsResult;
  432. for (SynchronizeFileOperation op : filesToSyncContents) {
  433. contentsResult = op.execute(mStorageManager, mContext); // async
  434. if (!contentsResult.isSuccess()) {
  435. if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
  436. mConflictsFound++;
  437. } else {
  438. mFailsInKeptInSyncFound++;
  439. if (contentsResult.getException() != null) {
  440. Log_OC.e(TAG, "Error while synchronizing favourites : "
  441. + contentsResult.getLogMessage(), contentsResult.getException());
  442. } else {
  443. Log_OC.e(TAG, "Error while synchronizing favourites : "
  444. + contentsResult.getLogMessage());
  445. }
  446. }
  447. } // won't let these fails break the synchronization process
  448. }
  449. }
  450. /**
  451. * Syncs the Share resources for the files contained in the folder refreshed (children, not deeper descendants).
  452. *
  453. * @param client Handler of a session with an OC server.
  454. * @return The result of the remote operation retrieving the Share resources in the folder refreshed by
  455. * the operation.
  456. */
  457. private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) {
  458. RemoteOperationResult result;
  459. // remote request
  460. GetRemoteSharesForFileOperation operation =
  461. new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), true, true);
  462. result = operation.execute(client);
  463. if (result.isSuccess()) {
  464. // update local database
  465. ArrayList<OCShare> shares = new ArrayList<>();
  466. for (Object obj : result.getData()) {
  467. shares.add((OCShare) obj);
  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. }