RefreshFolderOperation.java 25 KB

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