<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
- <service android:name=".files.services.FileObserverService"/>
+ <service android:name=".services.observer.FileObserverService"/>
<activity
android:name=".ui.activity.CopyToClipboardActivity"
<string name="downloader_download_failed_credentials_error">La descàrrega ha fallat, t\'has de tornar a acreditar</string>
<string name="common_choose_account">Escolliu el compte</string>
<string name="sync_fail_ticker">La sincronització ha fallat</string>
+ <string name="sync_fail_ticker_unauthorized">La sincronització ha fallat, us heu d\'acreditar de nou</string>
<string name="sync_fail_content">La sincronització de %1$s no s\'ha pogut acabar</string>
<string name="sync_fail_content_unauthorized">Contrasenya no vàlida per %1$s</string>
<string name="sync_conflicts_in_favourites_ticker">S\'han trobat conflictes</string>
<string name="downloader_download_failed_credentials_error">ダウンロードに失敗しました。再ログインする必要があります。</string>
<string name="common_choose_account">アカウントを選択</string>
<string name="sync_fail_ticker">同期失敗</string>
+ <string name="sync_fail_ticker_unauthorized">同期に失敗しました。再ログインする必要があります。</string>
<string name="sync_fail_content">%1$s の同期が完了しませんでした。</string>
<string name="sync_fail_content_unauthorized">1$sの無効なパスワード</string>
<string name="sync_conflicts_in_favourites_ticker">競合が見つかりました</string>
<string name="foreign_files_fail">一部のファイルは移動できませんでした</string>
<string name="foreign_files_local_text">ローカル: %1$s</string>
<string name="foreign_files_remote_text">リモート: %1$s</string>
- <string name="upload_query_move_foreign_files">十分なスペースが無いため、選択されたファイルを %1$s フォルダーにコピーすることができません。コピーする代わりに、それらを移動させますか?</string>
+ <string name="upload_query_move_foreign_files">十分なスペースがないため、選択されたファイルを %1$s フォルダーにコピーすることができません。コピーする代わりに、それらを移動させますか?</string>
<string name="pincode_enter_pin_code">アプリのパスワードを入力してください</string>
<string name="pincode_configure_your_pin">アプリのパスワードを入力してください</string>
<string name="pincode_configure_your_pin_explanation">アプリ開始時に毎回PINが要求されます。</string>
<string name="prefs_instant_upload">即时图片上传</string>
<string name="prefs_instant_upload_summary">即时上传相机拍摄的图片</string>
<string name="prefs_instant_video_upload">立即上传视频</string>
+ <string name="prefs_instant_video_upload_summary">即时上传由相机拍摄的视频</string>
<string name="prefs_log_title">开启日志</string>
<string name="prefs_log_summary">这过去是日志问题</string>
<string name="prefs_log_title_history">日志历史</string>
<string name="prefs_feedback">反馈</string>
<string name="prefs_imprint">版本说明</string>
<string name="recommend_subject">在您的智能手机上试用一下 %1$s!</string>
+ <string name="recommend_text">“我邀请你使用在你的智能手机上使用 %1$s!\n立即下载:%2$s”\n\t</string>
<string name="auth_check_server">检查服务器</string>
<string name="auth_host_url">服务器地址 https://...</string>
<string name="auth_username">用户名</string>
<string name="uploader_upload_succeeded_content_single">%1$s 成功上传</string>
<string name="uploader_upload_failed_ticker">上传失败</string>
<string name="uploader_upload_failed_content_single">1$上传未能完成</string>
+ <string name="uploader_upload_failed_credentials_error">上传失败,您需要重新登录</string>
<string name="downloader_download_in_progress_ticker">下载中……</string>
<string name="downloader_download_in_progress_content">%1$d%% 下载中 %2$s</string>
<string name="downloader_download_succeeded_ticker">下载成功</string>
<string name="downloader_download_failed_ticker">下载失败</string>
<string name="downloader_download_failed_content">下载1$s 未能完成</string>
<string name="downloader_not_downloaded_yet">未下载完毕</string>
+ <string name="downloader_download_failed_credentials_error">下载失败,您需要重新登录</string>
<string name="common_choose_account">选择账户</string>
<string name="sync_fail_ticker">同步失败</string>
+ <string name="sync_fail_ticker_unauthorized">同步失败,您需要重新登录</string>
<string name="sync_fail_content"> %1$s同步未完成。</string>
<string name="sync_fail_content_unauthorized">密码错误%1$s</string>
<string name="sync_conflicts_in_favourites_ticker">发现冲突</string>
<string name="foreign_files_fail">某些文件无法被移动</string>
<string name="foreign_files_local_text">本地: %1$s</string>
<string name="foreign_files_remote_text">远程:%1$s</string>
+ <string name="upload_query_move_foreign_files">没有足够的空间以复制选定的文件到 %1$s 文件夹,您想移动文件到此文件夹吗?</string>
<string name="pincode_enter_pin_code">请输入您的App PIN码</string>
<string name="pincode_configure_your_pin">输入 App PIN码</string>
<string name="pincode_configure_your_pin_explanation">每次应用启动时都会请求PIN码</string>
<string name="auth_connection_established">连接已建立。</string>
<string name="auth_testing_connection">测试连接……</string>
<string name="auth_not_configured_title">服务器配置不正确。</string>
+ <string name="auth_account_not_new">此设备中已经存在同名同服务器的帐号</string>
+ <string name="auth_account_not_the_same">输入用户与此帐户的用户不符</string>
<string name="auth_unknown_error_title">发生未知错误!</string>
<string name="auth_unknown_host_title">无法找到服务器</string>
<string name="auth_incorrect_path_title">未发现服务器实例</string>
<string name="auth_expired_oauth_token_toast">你的授权已经过期。请重新授权。</string>
<string name="auth_expired_basic_auth_toast">请输入当前密码:</string>
<string name="auth_expired_saml_sso_token_toast">您的会话超时了,请重新连接</string>
+ <string name="auth_connecting_auth_server">正在连接到认证服务器....</string>
<string name="auth_unsupported_auth_method">服务器不支持这种验证方式</string>
<string name="auth_unsupported_multiaccount">%1$s不支持多个账户</string>
<string name="auth_fail_get_user_name">您的服务器没有返回一个正确的用户 id,请联系管理员\n\t</string>
+ <string name="auth_can_not_auth_against_server">无法通过此服务器认证</string>
<string name="fd_keep_in_sync">保证文件更新</string>
<string name="common_rename">重命名</string>
<string name="common_remove">删除</string>
<string name="sync_file_nothing_to_do_msg">文件内容已同步</string>
<string name="create_dir_fail_msg">文件夹无法创建</string>
<string name="filename_forbidden_characters">禁用字符: / \\ < > : \" | ? *</string>
+ <string name="filename_empty">文件名不能为空</string>
<string name="wait_a_moment">请稍候</string>
<string name="filedisplay_unexpected_bad_get_content">未知问题;请试试用其他程序选择此文件</string>
<string name="filedisplay_no_file_selected">未选择文件。</string>
<string name="placeholder_timestamp">2012/05/18 下午12:23 </string>
<string name="placeholder_media_time">12:23:45</string>
<string name="instant_upload_on_wifi">仅通过WIFI上传图片。</string>
+ <string name="instant_video_upload_on_wifi">仅在 WIFI 下上传视频</string>
<string name="instant_upload_path">/InstantUpload</string>
<string name="conflict_title">上传冲突</string>
<string name="conflict_message">远程文件 %s 未与本地文件同步。继续将替换服务器上的文件内容。</string>
<string name="activity_chooser_send_file_title">发送</string>
<string name="copy_link">复制链接</string>
<string name="clipboard_text_copied">复制到剪贴板</string>
+ <string name="error_cant_bind_to_operations_service">严重错误:无法执行操作</string>
+ <string name="network_error_socket_exception">连接到服务器时发生了一个错误。</string>
+ <string name="network_error_socket_timeout_exception">等待服务器响应时发生了一个错误,此操作无法完成</string>
+ <string name="network_error_connect_timeout_exception">等待服务器响应时发生了一个错误,此操作无法完成</string>
+ <string name="network_host_not_available">服务器不可用,此操作无法完成</string>
</resources>
package com.owncloud.android.files;
-import com.owncloud.android.files.services.FileObserverService;
+import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.utils.Log_OC;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+
+/**
+ * App-registered receiver catching the broadcast intent reporting that the system was
+ * just boot up.
+ *
+ * @author David A. Velasco
+ */
public class BootupBroadcastReceiver extends BroadcastReceiver {
- private static String TAG = "BootupBroadcastReceiver";
+ private static String TAG = BootupBroadcastReceiver.class.getSimpleName();
+ /**
+ * Receives broadcast intent reporting that the system was just boot up.
+ *
+ * Starts {@link FileObserverService} to enable observation of favourite files.
+ *
+ * @param context The context where the receiver is running.
+ * @param intent The intent received.
+ */
@Override
public void onReceive(Context context, Intent intent) {
if (!intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
return;
}
Log_OC.d(TAG, "Starting file observer service...");
- Intent i = new Intent(context, FileObserverService.class);
- i.putExtra(FileObserverService.KEY_FILE_CMD,
- FileObserverService.CMD_INIT_OBSERVED_LIST);
- context.startService(i);
- Log_OC.d(TAG, "DONE");
+ Intent initObservers = FileObserverService.makeInitIntent(context);
+ context.startService(initObservers);
}
}
+++ /dev/null
-/* ownCloud Android client application
- * Copyright (C) 2012 Bartek Przybylski
- * Copyright (C) 2012-2014 ownCloud Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.files;
-
-import java.io.File;
-
-import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.ui.activity.ConflictsResolveActivity;
-import com.owncloud.android.utils.Log_OC;
-
-import android.accounts.Account;
-import android.content.Context;
-import android.content.Intent;
-import android.os.FileObserver;
-
-public class OwnCloudFileObserver extends FileObserver {
-
- private static int MASK = (FileObserver.MODIFY | FileObserver.CLOSE_WRITE);
-
- private static String TAG = OwnCloudFileObserver.class.getSimpleName();
-
- private String mPath;
- private int mMask;
- private Account mOCAccount;
- private Context mContext;
- private boolean mModified;
-
-
- public OwnCloudFileObserver(String path, Account account, Context context) {
- super(path, MASK);
- if (path == null)
- throw new IllegalArgumentException("NULL path argument received");
- if (account == null)
- throw new IllegalArgumentException("NULL account argument received");
- if (context == null)
- throw new IllegalArgumentException("NULL context argument received");
- mPath = path;
- mOCAccount = account;
- mContext = context;
- mModified = false;
- }
-
-
- @Override
- public void onEvent(int event, String path) {
- Log_OC.d(TAG, "Got file modified with event " + event + " and path " + mPath + ((path != null) ? File.separator + path : ""));
- if ((event & MASK) == 0) {
- Log_OC.wtf(TAG, "Incorrect event " + event + " sent for file " + mPath + ((path != null) ? File.separator + path : "") +
- " with registered for " + mMask + " and original path " +
- mPath);
- } else {
- if ((event & FileObserver.MODIFY) != 0) {
- // file changed
- mModified = true;
- }
- // not sure if it's possible, but let's assume that both kind of events can be received at the same time
- if ((event & FileObserver.CLOSE_WRITE) != 0) {
- // file closed
- if (mModified) {
- mModified = false;
- startSyncOperation();
- }
- }
- }
- }
-
-
- private void startSyncOperation() {
- FileDataStorageManager storageManager = new FileDataStorageManager(mOCAccount, mContext.getContentResolver());
- OCFile file = storageManager.getFileByLocalPath(mPath); // a fresh object is needed; many things could have occurred to the file since it was registered to observe
- // again, assuming that local files are linked to a remote file AT MOST, SOMETHING TO BE DONE;
- SynchronizeFileOperation sfo = new SynchronizeFileOperation(file,
- null,
- mOCAccount,
- true,
- mContext);
- RemoteOperationResult result = sfo.execute(storageManager, mContext);
- if (result.getCode() == ResultCode.SYNC_CONFLICT) {
- // ISSUE 5: if the user is not running the app (this is a service!), this can be very intrusive; a notification should be preferred
- Intent i = new Intent(mContext, ConflictsResolveActivity.class);
- i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
- i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
- i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mOCAccount);
- mContext.startActivity(i);
- }
- // TODO save other errors in some point where the user can inspect them later;
- // or maybe just toast them;
- // or nothing, very strange fails
- }
-
-}
+++ /dev/null
-/* ownCloud Android client application
- * Copyright (C) 2012 Bartek Przybylski
- * Copyright (C) 2012-2013 ownCloud Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.files.services;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-
-import com.owncloud.android.MainApp;
-import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
-import com.owncloud.android.files.OwnCloudFileObserver;
-import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.utils.FileStorageUtils;
-import com.owncloud.android.utils.Log_OC;
-
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.app.Service;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.database.Cursor;
-import android.os.Binder;
-import android.os.IBinder;
-
-public class FileObserverService extends Service {
-
- public final static int CMD_INIT_OBSERVED_LIST = 1;
- public final static int CMD_ADD_OBSERVED_FILE = 2;
- public final static int CMD_DEL_OBSERVED_FILE = 3;
-
- public final static String KEY_FILE_CMD = "KEY_FILE_CMD";
- public final static String KEY_CMD_ARG_FILE = "KEY_CMD_ARG_FILE";
- public final static String KEY_CMD_ARG_ACCOUNT = "KEY_CMD_ARG_ACCOUNT";
-
- private static String TAG = FileObserverService.class.getSimpleName();
-
- private static Map<String, OwnCloudFileObserver> mObserversMap;
- private static DownloadCompletedReceiverBis mDownloadReceiver;
- private IBinder mBinder = new LocalBinder();
-
- public class LocalBinder extends Binder {
- FileObserverService getService() {
- return FileObserverService.this;
- }
- }
-
- @Override
- public void onCreate() {
- super.onCreate();
- mDownloadReceiver = new DownloadCompletedReceiverBis();
-
- IntentFilter filter = new IntentFilter();
- filter.addAction(FileDownloader.getDownloadAddedMessage());
- filter.addAction(FileDownloader.getDownloadFinishMessage());
- registerReceiver(mDownloadReceiver, filter);
-
- mObserversMap = new HashMap<String, OwnCloudFileObserver>();
- //initializeObservedList();
- }
-
-
- @Override
- public void onDestroy() {
- unregisterReceiver(mDownloadReceiver);
- mObserversMap = null; // TODO study carefully the life cycle of Services to grant the best possible observance
- Log_OC.d(TAG, "Bye, bye");
- super.onDestroy();
- }
-
-
- @Override
- public IBinder onBind(Intent intent) {
- return mBinder;
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- // this occurs when system tries to restart
- // service, so we need to reinitialize observers
- if (intent == null) {
- initializeObservedList();
- return Service.START_STICKY;
- }
-
- if (!intent.hasExtra(KEY_FILE_CMD)) {
- Log_OC.e(TAG, "No KEY_FILE_CMD argument given");
- return Service.START_STICKY;
- }
-
- switch (intent.getIntExtra(KEY_FILE_CMD, -1)) {
- case CMD_INIT_OBSERVED_LIST:
- initializeObservedList();
- break;
- case CMD_ADD_OBSERVED_FILE:
- addObservedFile( (OCFile)intent.getParcelableExtra(KEY_CMD_ARG_FILE),
- (Account)intent.getParcelableExtra(KEY_CMD_ARG_ACCOUNT));
- break;
- case CMD_DEL_OBSERVED_FILE:
- removeObservedFile( (OCFile)intent.getParcelableExtra(KEY_CMD_ARG_FILE),
- (Account)intent.getParcelableExtra(KEY_CMD_ARG_ACCOUNT));
- break;
- default:
- Log_OC.wtf(TAG, "Incorrect key given");
- }
-
- return Service.START_STICKY;
- }
-
-
- /**
- * Read from the local database the list of files that must to be kept synchronized and
- * starts file observers to monitor local changes on them
- */
- private void initializeObservedList() {
- mObserversMap.clear();
- Cursor c = getContentResolver().query(
- ProviderTableMeta.CONTENT_URI,
- null,
- ProviderTableMeta.FILE_KEEP_IN_SYNC + " = ?",
- new String[] {String.valueOf(1)},
- null);
- if (c == null || !c.moveToFirst()) return;
- AccountManager acm = AccountManager.get(this);
- Account[] accounts = acm.getAccountsByType(MainApp.getAccountType());
- do {
- Account account = null;
- for (Account a : accounts)
- if (a.name.equals(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ACCOUNT_OWNER)))) {
- account = a;
- break;
- }
-
- if (account == null) continue;
- FileDataStorageManager storage =
- new FileDataStorageManager(account, getContentResolver());
- if (!storage.fileExists(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH))))
- continue;
-
- String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
- if (path == null || path.length() <= 0)
- continue;
- OwnCloudFileObserver observer =
- new OwnCloudFileObserver( path,
- account,
- getApplicationContext());
- mObserversMap.put(path, observer);
- if (new File(path).exists()) {
- observer.startWatching();
- Log_OC.d(TAG, "Started watching file " + path);
- }
-
- } while (c.moveToNext());
- c.close();
- }
-
-
- /**
- * Registers the local copy of a remote file to be observed for local changes,
- * an automatically updated in the ownCloud server.
- *
- * This method does NOT perform a {@link SynchronizeFileOperation} over the file.
- *
- * TODO We are ignoring that, currently, a local file can be linked to different files
- * in ownCloud if it's uploaded several times. That's something pending to update: we
- * will avoid that the same local file is linked to different remote files.
- *
- * @param file Object representing a remote file which local copy must be observed.
- * @param account OwnCloud account containing file.
- */
- private void addObservedFile(OCFile file, Account account) {
- if (file == null) {
- Log_OC.e(TAG, "Trying to add a NULL file to observer");
- return;
- }
- String localPath = file.getStoragePath();
- if (localPath == null || localPath.length() <= 0) { // file downloading / to be download for the first time
- localPath = FileStorageUtils.getDefaultSavePathFor(account.name, file);
- }
- OwnCloudFileObserver observer = mObserversMap.get(localPath);
- if (observer == null) {
- /// the local file was never registered to observe before
- observer = new OwnCloudFileObserver( localPath,
- account,
- getApplicationContext());
- mObserversMap.put(localPath, observer);
- Log_OC.d(TAG, "Observer added for path " + localPath);
-
- if (file.isDown()) {
- observer.startWatching();
- Log_OC.d(TAG, "Started watching " + localPath);
- } // else - the observance can't be started on a file not already down; mDownloadReceiver will get noticed when the download of the file finishes
- }
-
- }
-
-
- /**
- * Unregisters the local copy of a remote file to be observed for local changes.
- *
- * Starts to watch it, if the file has a local copy to watch.
- *
- * TODO We are ignoring that, currently, a local file can be linked to different files
- * in ownCloud if it's uploaded several times. That's something pending to update: we
- * will avoid that the same local file is linked to different remote files.
- *
- * @param file Object representing a remote file which local copy must be not observed longer.
- * @param account OwnCloud account containing file.
- */
- private void removeObservedFile(OCFile file, Account account) {
- if (file == null) {
- Log_OC.e(TAG, "Trying to remove a NULL file");
- return;
- }
- String localPath = file.getStoragePath();
- if (localPath == null || localPath.length() <= 0) {
- localPath = FileStorageUtils.getDefaultSavePathFor(account.name, file);
- }
-
- OwnCloudFileObserver observer = mObserversMap.get(localPath);
- if (observer != null) {
- observer.stopWatching();
- mObserversMap.remove(observer);
- Log_OC.d(TAG, "Stopped watching " + localPath);
- }
-
- }
-
-
- /**
- * Private receiver listening to events broadcast by the FileDownloader service.
- *
- * Starts and stops the observance on registered files when they are being download,
- * in order to avoid to start unnecessary synchronizations.
- */
- private class DownloadCompletedReceiverBis extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- String downloadPath = intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH);
- OwnCloudFileObserver observer = mObserversMap.get(downloadPath);
- if (observer != null) {
- if (intent.getAction().equals(FileDownloader.getDownloadFinishMessage()) &&
- new File(downloadPath).exists()) { // the download could be successful. not; in both cases, the file could be down, due to a former download or upload
- observer.startWatching();
- Log_OC.d(TAG, "Watching again " + downloadPath);
-
- } else if (intent.getAction().equals(FileDownloader.getDownloadAddedMessage())) {
- observer.stopWatching();
- Log_OC.d(TAG, "Disabling observance of " + downloadPath);
- }
- }
- }
-
- }
-
-}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012 Bartek Przybylski
+ * Copyright (C) 2012-2014 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.services.observer;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import android.accounts.Account;
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.database.Cursor;
+import android.os.IBinder;
+
+import com.owncloud.android.MainApp;
+import com.owncloud.android.authentication.AccountUtils;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
+import com.owncloud.android.files.services.FileDownloader;
+import com.owncloud.android.operations.SynchronizeFileOperation;
+import com.owncloud.android.utils.FileStorageUtils;
+import com.owncloud.android.utils.Log_OC;
+
+
+/**
+ * Service keeping a list of {@link FolderObserver} instances that watch for local
+ * changes in favorite files (formerly known as kept-in-sync files) and try to
+ * synchronize them with the OC server as soon as possible.
+ *
+ * Tries to be alive as long as possible; that is the reason why stopSelf() is
+ * never called.
+ *
+ * It is expected that the system eventually kills the service when runs low of
+ * memory. To minimize the impact of this, the service always returns
+ * Service.START_STICKY, and the later restart of the service is explicitly
+ * considered in {@link FileObserverService#onStartCommand(Intent, int, int)}.
+ *
+ * @author David A. Velasco
+ */
+public class FileObserverService extends Service {
+
+ public final static String MY_NAME = FileObserverService.class.getCanonicalName();
+ public final static String ACTION_START_OBSERVE = MY_NAME + ".action.START_OBSERVATION";
+ public final static String ACTION_ADD_OBSERVED_FILE = MY_NAME + ".action.ADD_OBSERVED_FILE";
+ public final static String ACTION_DEL_OBSERVED_FILE = MY_NAME + ".action.DEL_OBSERVED_FILE";
+
+ private final static String ARG_FILE = "ARG_FILE";
+ private final static String ARG_ACCOUNT = "ARG_ACCOUNT";
+
+ private static String TAG = FileObserverService.class.getSimpleName();
+
+ private Map<String, FolderObserver> mFolderObserversMap;
+ private DownloadCompletedReceiver mDownloadReceiver;
+
+ /**
+ * Factory method to create intents that allow to start an ACTION_START_OBSERVE command.
+ *
+ * @param context Android context of the caller component.
+ * @return Intent that starts a command ACTION_START_OBSERVE when
+ * {@link Context#startService(Intent)} is called.
+ */
+ public static Intent makeInitIntent(Context context) {
+ Intent i = new Intent(context, FileObserverService.class);
+ i.setAction(ACTION_START_OBSERVE);
+ return i;
+ }
+
+ /**
+ * Factory method to create intents that allow to start or stop the
+ * observance of a file.
+ *
+ * @param context Android context of the caller component.
+ * @param file OCFile to start or stop to watch.
+ * @param account OC account containing file.
+ * @param watchIt 'True' creates an intent to watch, 'false' an intent to stop watching.
+ * @return Intent to start or stop the observance of a file through a call
+ * to {@link Context#startService(Intent)}.
+ */
+ public static Intent makeObservedFileIntent(
+ Context context, OCFile file, Account account, boolean watchIt) {
+ Intent intent = new Intent(context, FileObserverService.class);
+ intent.setAction(watchIt ? FileObserverService.ACTION_ADD_OBSERVED_FILE
+ : FileObserverService.ACTION_DEL_OBSERVED_FILE);
+ intent.putExtra(FileObserverService.ARG_FILE, file);
+ intent.putExtra(FileObserverService.ARG_ACCOUNT, account);
+ return intent;
+ }
+
+ /**
+ * Initialize the service.
+ */
+ @Override
+ public void onCreate() {
+ Log_OC.d(TAG, "onCreate");
+ super.onCreate();
+
+ mDownloadReceiver = new DownloadCompletedReceiver();
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(FileDownloader.getDownloadAddedMessage());
+ filter.addAction(FileDownloader.getDownloadFinishMessage());
+ registerReceiver(mDownloadReceiver, filter);
+
+ mFolderObserversMap = new HashMap<String, FolderObserver>();
+ }
+
+ /**
+ * Release resources.
+ */
+ @Override
+ public void onDestroy() {
+ Log_OC.d(TAG, "onDestroy - finishing observation of favorite files");
+
+ unregisterReceiver(mDownloadReceiver);
+
+ Iterator<FolderObserver> itOCFolder = mFolderObserversMap.values().iterator();
+ while (itOCFolder.hasNext()) {
+ itOCFolder.next().stopWatching();
+ }
+ mFolderObserversMap.clear();
+ mFolderObserversMap = null;
+
+ super.onDestroy();
+ }
+
+ /**
+ * This service cannot be bound.
+ */
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ /**
+ * Handles requests to:
+ * - (re)start watching (ACTION_START_OBSERVE)
+ * - add an {@link OCFile} to be watched (ATION_ADD_OBSERVED_FILE)
+ * - stop observing an {@link OCFile} (ACTION_DEL_OBSERVED_FILE)
+ */
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Log_OC.d(TAG, "Starting command " + intent);
+
+ if (intent == null || ACTION_START_OBSERVE.equals(intent.getAction())) {
+ // NULL occurs when system tries to restart the service after its
+ // process was killed
+ startObservation();
+ return Service.START_STICKY;
+
+ } else if (ACTION_ADD_OBSERVED_FILE.equals(intent.getAction())) {
+ OCFile file = (OCFile) intent.getParcelableExtra(ARG_FILE);
+ Account account = (Account) intent.getParcelableExtra(ARG_ACCOUNT);
+ addObservedFile(file, account);
+
+ } else if (ACTION_DEL_OBSERVED_FILE.equals(intent.getAction())) {
+ removeObservedFile((OCFile) intent.getParcelableExtra(ARG_FILE),
+ (Account) intent.getParcelableExtra(ARG_ACCOUNT));
+
+ } else {
+ Log_OC.e(TAG, "Unknown action recieved; ignoring it: " + intent.getAction());
+ }
+
+ return Service.START_STICKY;
+ }
+
+
+ /**
+ * Read from the local database the list of files that must to be kept
+ * synchronized and starts observers to monitor local changes on them.
+ *
+ * Updates the list of currently observed files if called multiple times.
+ */
+ private void startObservation() {
+ Log_OC.d(TAG, "Loading all kept-in-sync files from database to start watching them");
+
+ // query for any favorite file in any OC account
+ Cursor cursorOnKeptInSync = getContentResolver().query(
+ ProviderTableMeta.CONTENT_URI,
+ null,
+ ProviderTableMeta.FILE_KEEP_IN_SYNC + " = ?",
+ new String[] { String.valueOf(1) },
+ null
+ );
+
+ if (cursorOnKeptInSync != null) {
+
+ if (cursorOnKeptInSync.moveToFirst()) {
+
+ String localPath = "";
+ String accountName = "";
+ Account account = null;
+ do {
+ localPath = cursorOnKeptInSync.getString(cursorOnKeptInSync
+ .getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
+ accountName = cursorOnKeptInSync.getString(cursorOnKeptInSync
+ .getColumnIndex(ProviderTableMeta.FILE_ACCOUNT_OWNER));
+
+ account = new Account(accountName, MainApp.getAccountType());
+ if (!AccountUtils.exists(account, this) || localPath == null || localPath.length() <= 0) {
+ continue;
+ }
+
+ addObservedFile(localPath, account);
+
+ } while (cursorOnKeptInSync.moveToNext());
+
+ }
+ cursorOnKeptInSync.close();
+ }
+
+ // service does not stopSelf() ; that way it tries to be alive forever
+
+ }
+
+
+ /**
+ * Registers the local copy of a remote file to be observed for local
+ * changes, an automatically updated in the ownCloud server.
+ *
+ * This method does NOT perform a {@link SynchronizeFileOperation} over the
+ * file.
+ *
+ * @param file Object representing a remote file which local copy must be observed.
+ * @param account OwnCloud account containing file.
+ */
+ private void addObservedFile(OCFile file, Account account) {
+ Log_OC.v(TAG, "Adding a file to be watched");
+
+ if (file == null) {
+ Log_OC.e(TAG, "Trying to add a NULL file to observer");
+ return;
+ }
+ if (account == null) {
+ Log_OC.e(TAG, "Trying to add a file with a NULL account to observer");
+ return;
+ }
+
+ String localPath = file.getStoragePath();
+ if (localPath == null || localPath.length() <= 0) {
+ // file downloading or to be downloaded for the first time
+ localPath = FileStorageUtils.getDefaultSavePathFor(account.name, file);
+ }
+
+ addObservedFile(localPath, account);
+
+ }
+
+
+
+
+ /**
+ * Registers a local file to be observed for changes.
+ *
+ * @param localPath Absolute path in the local file system to the file to be observed.
+ * @param account OwnCloud account associated to the local file.
+ */
+ private void addObservedFile(String localPath, Account account) {
+ File file = new File(localPath);
+ String parentPath = file.getParent();
+ FolderObserver observer = mFolderObserversMap.get(parentPath);
+ if (observer == null) {
+ observer = new FolderObserver(parentPath, account, getApplicationContext());
+ mFolderObserversMap.put(parentPath, observer);
+ Log_OC.d(TAG, "Observer added for parent folder " + parentPath + "/");
+ }
+
+ observer.startWatching(file.getName());
+ Log_OC.d(TAG, "Added " + localPath + " to list of observed children");
+ }
+
+
+ /**
+ * Unregisters the local copy of a remote file to be observed for local changes.
+ *
+ * @param file Object representing a remote file which local copy must be not
+ * observed longer.
+ * @param account OwnCloud account containing file.
+ */
+ private void removeObservedFile(OCFile file, Account account) {
+ Log_OC.v(TAG, "Removing a file from being watched");
+
+ if (file == null) {
+ Log_OC.e(TAG, "Trying to remove a NULL file");
+ return;
+ }
+ if (account == null) {
+ Log_OC.e(TAG, "Trying to add a file with a NULL account to observer");
+ return;
+ }
+
+ String localPath = file.getStoragePath();
+ if (localPath == null || localPath.length() <= 0) {
+ localPath = FileStorageUtils.getDefaultSavePathFor(account.name, file);
+ }
+
+ removeObservedFile(localPath);
+ }
+
+
+ /**
+ * Unregisters a local file from being observed for changes.
+ *
+ * @param localPath Absolute path in the local file system to the target file.
+ */
+ private void removeObservedFile(String localPath) {
+ File file = new File(localPath);
+ String parentPath = file.getParent();
+ FolderObserver observer = mFolderObserversMap.get(parentPath);
+ if (observer != null) {
+ observer.stopWatching(file.getName());
+ if (observer.isEmpty()) {
+ mFolderObserversMap.remove(parentPath);
+ Log_OC.d(TAG, "Observer removed for parent folder " + parentPath + "/");
+ }
+
+ } else {
+ Log_OC.d(TAG, "No observer to remove for path " + localPath);
+ }
+ }
+
+
+ /**
+ * Private receiver listening to events broadcasted by the {@link FileDownloader} service.
+ *
+ * Pauses and resumes the observance on registered files while being download,
+ * in order to avoid to unnecessary synchronizations.
+ */
+ private class DownloadCompletedReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log_OC.d(TAG, "Received broadcast intent " + intent);
+
+ File downloadedFile = new File(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH));
+ String parentPath = downloadedFile.getParent();
+ FolderObserver observer = mFolderObserversMap.get(parentPath);
+ if (observer != null) {
+ if (intent.getAction().equals(FileDownloader.getDownloadFinishMessage())
+ && downloadedFile.exists()) {
+ // no matter if the download was successful or not; the
+ // file could be down anyway due to a former download or upload
+ observer.startWatching(downloadedFile.getName());
+ Log_OC.d(TAG, "Resuming observance of " + downloadedFile.getAbsolutePath());
+
+ } else if (intent.getAction().equals(FileDownloader.getDownloadAddedMessage())) {
+ observer.stopWatching(downloadedFile.getName());
+ Log_OC.d(TAG, "Pausing observance of " + downloadedFile.getAbsolutePath());
+ }
+
+ } else {
+ Log_OC.d(TAG, "No observer for path " + downloadedFile.getAbsolutePath());
+ }
+ }
+
+ }
+
+}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012-2014 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.services.observer;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import android.accounts.Account;
+import android.content.Context;
+import android.content.Intent;
+import android.os.FileObserver;
+
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.operations.SynchronizeFileOperation;
+import com.owncloud.android.ui.activity.ConflictsResolveActivity;
+import com.owncloud.android.utils.Log_OC;
+
+/**
+ * Observer watching a folder to request the synchronization of kept-in-sync files
+ * inside it.
+ *
+ * Takes into account two possible update cases:
+ * - an editor directly updates the file;
+ * - an editor works on a temporary file, and later replaces the kept-in-sync file with the
+ * former.
+ *
+ * The second case requires to monitor the folder parent of the files, since a direct
+ * {@link FileObserver} on it will not receive more events after the file is deleted to
+ * be replaced.
+ *
+ * @author David A. Velasco
+ */
+public class FolderObserver extends FileObserver {
+
+ private static String TAG = FolderObserver.class.getSimpleName();
+
+ private static int UPDATE_MASK = (
+ FileObserver.ATTRIB | FileObserver.MODIFY |
+ FileObserver.MOVED_TO | FileObserver.CLOSE_WRITE
+ );
+
+ private static int IN_IGNORE = 32768;
+ /*
+ private static int ALL_EVENTS_EVEN_THOSE_NOT_DOCUMENTED = 0x7fffffff; // NEVER use 0xffffffff
+ */
+
+ private String mPath;
+ private Account mAccount;
+ private Context mContext;
+ private Map<String, Boolean> mObservedChildren;
+
+ /**
+ * Constructor.
+ *
+ * Initializes the observer to receive events about the update of the passed folder, and
+ * its children files.
+ *
+ * @param path Absolute path to the local folder to watch.
+ * @param account OwnCloud account associated to the folder.
+ * @param context Used to start an operation to synchronize the file, when needed.
+ */
+ public FolderObserver(String path, Account account, Context context) {
+ super(path, UPDATE_MASK);
+
+ if (path == null)
+ throw new IllegalArgumentException("NULL path argument received");
+ if (account == null)
+ throw new IllegalArgumentException("NULL account argument received");
+ if (context == null)
+ throw new IllegalArgumentException("NULL context argument received");
+
+ mPath = path;
+ mAccount = account;
+ mContext = context;
+ mObservedChildren = new HashMap<String, Boolean>();
+ }
+
+
+ /**
+ * Receives and processes events about updates of the monitor folder and its children files.
+ *
+ * @param event Kind of event occurred.
+ * @param path Relative path of the file referred by the event.
+ */
+ @Override
+ public void onEvent(int event, String path) {
+ Log_OC.d(TAG, "Got event " + event + " on FOLDER " + mPath + " about "
+ + ((path != null) ? path : ""));
+
+ boolean shouldSynchronize = false;
+ synchronized(mObservedChildren) {
+ if (path != null && path.length() > 0 && mObservedChildren.containsKey(path)) {
+
+ if ( ((event & FileObserver.MODIFY) != 0) ||
+ ((event & FileObserver.ATTRIB) != 0) ||
+ ((event & FileObserver.MOVED_TO) != 0) ) {
+
+ if (mObservedChildren.get(path) != true) {
+ mObservedChildren.put(path, Boolean.valueOf(true));
+ }
+ }
+
+ if ((event & FileObserver.CLOSE_WRITE) != 0 && mObservedChildren.get(path)) {
+ mObservedChildren.put(path, Boolean.valueOf(false));
+ shouldSynchronize = true;
+ }
+ }
+ }
+ if (shouldSynchronize) {
+ startSyncOperation(path);
+ }
+
+ if ((event & IN_IGNORE) != 0 &&
+ (path == null || path.length() == 0)) {
+ Log_OC.d(TAG, "Stopping the observance on " + mPath);
+ }
+
+ }
+
+
+ /**
+ * Adds a child file to the list of files observed by the folder observer.
+ *
+ * @param fileName Name of a file inside the observed folder.
+ */
+ public void startWatching(String fileName) {
+ synchronized (mObservedChildren) {
+ if (!mObservedChildren.containsKey(fileName)) {
+ mObservedChildren.put(fileName, Boolean.valueOf(false));
+ }
+ }
+
+ if (new File(mPath).exists()) {
+ startWatching();
+ Log_OC.d(TAG, "Started watching parent folder " + mPath + "/");
+ }
+ // else - the observance can't be started on a file not existing;
+ }
+
+
+ /**
+ * Removes a child file from the list of files observed by the folder observer.
+ *
+ * @param fileName Name of a file inside the observed folder.
+ */
+ public void stopWatching(String fileName) {
+ synchronized (mObservedChildren) {
+ mObservedChildren.remove(fileName);
+ if (mObservedChildren.isEmpty()) {
+ stopWatching();
+ Log_OC.d(TAG, "Stopped watching parent folder " + mPath + "/");
+ }
+ }
+ }
+
+ /**
+ * @return 'True' when the folder is not watching any file inside.
+ */
+ public boolean isEmpty() {
+ synchronized (mObservedChildren) {
+ return mObservedChildren.isEmpty();
+ }
+ }
+
+
+ /**
+ * Triggers an operation to synchronize the contents of a file inside the observed folder with
+ * its remote counterpart in the associated ownCloud account.
+ *
+ * @param fileName Name of a file inside the watched folder.
+ */
+ private void startSyncOperation(String fileName) {
+ FileDataStorageManager storageManager =
+ new FileDataStorageManager(mAccount, mContext.getContentResolver());
+ // a fresh object is needed; many things could have occurred to the file
+ // since it was registered to observe again, assuming that local files
+ // are linked to a remote file AT MOST, SOMETHING TO BE DONE;
+ OCFile file = storageManager.getFileByLocalPath(mPath + File.separator + fileName);
+ SynchronizeFileOperation sfo =
+ new SynchronizeFileOperation(file, null, mAccount, true, mContext);
+ RemoteOperationResult result = sfo.execute(storageManager, mContext);
+ if (result.getCode() == ResultCode.SYNC_CONFLICT) {
+ // ISSUE 5: if the user is not running the app (this is a service!),
+ // this can be very intrusive; a notification should be preferred
+ Intent i = new Intent(mContext, ConflictsResolveActivity.class);
+ i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
+ i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
+ i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount);
+ mContext.startActivity(i);
+ }
+ // TODO save other errors in some point where the user can inspect them later;
+ // or maybe just toast them;
+ // or nothing, very strange fails
+ }
+
+}
import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader;
-import com.owncloud.android.files.services.FileObserverService;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareLinkOperation;
+import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
requestPinCode();
}
- /// file observer
- Intent observer_intent = new Intent(this, FileObserverService.class);
- observer_intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_INIT_OBSERVED_LIST);
- startService(observer_intent);
-
+ /// grant that FileObserverService is watching favourite files
+ if (savedInstanceState == null) {
+ Intent initObserversIntent = FileObserverService.makeInitIntent(this);
+ startService(initObserversIntent);
+ }
+
/// Load of saved instance state
if(savedInstanceState != null) {
mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
*/
@Override
public void onReceive(Context context, Intent intent) {
- String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
- String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
- boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
- OCFile currentDir = getCurrentDir();
- boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) &&
- (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
-
- if (sameAccount && isDescendant) {
- refreshListOfFilesFragment();
- }
-
- boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false);
- boolean renamedInUpload = getFile().getRemotePath().
- equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
- boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) ||
- renamedInUpload;
- FileFragment details = getSecondFragment();
- boolean detailFragmentIsShown = (details != null &&
- details instanceof FileDetailFragment);
-
- if (sameAccount && sameFile && detailFragmentIsShown) {
- if (uploadWasFine) {
- setFile(getStorageManager().getFileByPath(uploadedRemotePath));
- }
- if (renamedInUpload) {
- String newName = (new File(uploadedRemotePath)).getName();
- Toast msg = Toast.makeText(
- context,
- String.format(
- getString(R.string.filedetails_renamed_in_upload_msg),
- newName),
- Toast.LENGTH_LONG);
- msg.show();
+ try {
+ String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
+ String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
+ boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
+ OCFile currentDir = getCurrentDir();
+ boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) &&
+ (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
+
+ if (sameAccount && isDescendant) {
+ refreshListOfFilesFragment();
}
- if (uploadWasFine || getFile().fileExists()) {
- ((FileDetailFragment)details).updateFileDetails(false, true);
- } else {
- cleanSecondFragment();
+
+ boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false);
+ boolean renamedInUpload = getFile().getRemotePath().
+ equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
+ boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) ||
+ renamedInUpload;
+ FileFragment details = getSecondFragment();
+ boolean detailFragmentIsShown = (details != null &&
+ details instanceof FileDetailFragment);
+
+ if (sameAccount && sameFile && detailFragmentIsShown) {
+ if (uploadWasFine) {
+ setFile(getStorageManager().getFileByPath(uploadedRemotePath));
+ }
+ if (renamedInUpload) {
+ String newName = (new File(uploadedRemotePath)).getName();
+ Toast msg = Toast.makeText(
+ context,
+ String.format(
+ getString(R.string.filedetails_renamed_in_upload_msg),
+ newName),
+ Toast.LENGTH_LONG);
+ msg.show();
+ }
+ if (uploadWasFine || getFile().fileExists()) {
+ ((FileDetailFragment)details).updateFileDetails(false, true);
+ } else {
+ cleanSecondFragment();
+ }
+
+ // Force the preview if the file is an image
+ if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) {
+ startImagePreview(getFile());
+ } // TODO what about other kind of previews?
}
- // Force the preview if the file is an image
- if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) {
- startImagePreview(getFile());
- } // TODO what about other kind of previews?
+ } finally {
+ if (intent != null) {
+ removeStickyBroadcast(intent);
+ }
}
-
- removeStickyBroadcast(intent);
}
private class DownloadFinishReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- boolean sameAccount = isSameAccount(context, intent);
- String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
- boolean isDescendant = isDescendant(downloadedRemotePath);
-
- if (sameAccount && isDescendant) {
- refreshListOfFilesFragment();
- refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
- }
-
- if (mWaitingToSend != null) {
- mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); // Update the file to send
- if (mWaitingToSend.isDown()) {
- sendDownloadedFile();
+ try {
+ boolean sameAccount = isSameAccount(context, intent);
+ String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
+ boolean isDescendant = isDescendant(downloadedRemotePath);
+
+ if (sameAccount && isDescendant) {
+ refreshListOfFilesFragment();
+ refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
+ }
+
+ if (mWaitingToSend != null) {
+ mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); // Update the file to send
+ if (mWaitingToSend.isDown()) {
+ sendDownloadedFile();
+ }
}
- }
- removeStickyBroadcast(intent);
+ } finally {
+ if (intent != null) {
+ removeStickyBroadcast(intent);
+ }
+ }
}
private boolean isDescendant(String downloadedRemotePath) {
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.FileMenuFilter;
-import com.owncloud.android.files.services.FileObserverService;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
+import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
file.setKeepInSync(cb.isChecked());
mContainerActivity.getStorageManager().saveFile(file);
- /// register the OCFile instance in the observer service to monitor local updates;
- /// if necessary, the file is download
- Intent intent = new Intent(getActivity().getApplicationContext(),
- FileObserverService.class);
- intent.putExtra(FileObserverService.KEY_FILE_CMD,
- (cb.isChecked()?
- FileObserverService.CMD_ADD_OBSERVED_FILE:
- FileObserverService.CMD_DEL_OBSERVED_FILE));
- intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, file);
- intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
- getActivity().startService(intent);
+ /// register the OCFile instance in the observer service to monitor local updates
+ Intent observedFileIntent = FileObserverService.makeObservedFileIntent(
+ getActivity(),
+ file,
+ mAccount,
+ cb.isChecked());
+ getActivity().startService(observedFileIntent);
+ /// immediate content synchronization
if (file.keepInSync()) {
mContainerActivity.getFileOperationsHelper().syncFile(getFile());
}