*/\r
public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {\r
\r
- private final static String TAG = "FileSyncAdapter"; \r
+ private final static String TAG = "FileSyncAdapter";\r
+\r
+ /** \r
+ * Maximum number of failed folder synchronizations that are supported before finishing the synchronization operation\r
+ */\r
+ private static final int MAX_FAILED_RESULTS = 3; \r
\r
private long mCurrentSyncTime;\r
private boolean mCancellation;\r
private boolean mIsManualSync;\r
- private boolean mRightSync;\r
+ private int mFailedResultsCounter; \r
+ private RemoteOperationResult mLastFailedResult;\r
\r
public FileSyncAdapter(Context context, boolean autoInitialize) {\r
super(context, autoInitialize);\r
\r
mCancellation = false;\r
mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);\r
- mRightSync = true;\r
+ mFailedResultsCounter = 0;\r
+ mLastFailedResult = null;\r
\r
this.setAccount(account);\r
this.setContentProvider(provider);\r
\r
Log.d(TAG, "syncing owncloud account " + account.name);\r
\r
- sendStickyBroadcast(true, null); // message to signal the start to the UI\r
+ sendStickyBroadcast(true, null, null); // message to signal the start of the synchronization to the UI\r
\r
try {\r
updateOCVersion();\r
} finally {\r
// it's important making this although very unexpected errors occur; that's the reason for the finally\r
\r
- mRightSync &= (syncResult.stats.numIoExceptions == 0 && syncResult.stats.numAuthExceptions == 0 && syncResult.stats.numParseExceptions == 0);\r
- if (!mRightSync && mIsManualSync) {\r
+ if (mFailedResultsCounter > 0 && mIsManualSync) {\r
/// don't let the system synchronization manager retries MANUAL synchronizations\r
// (be careful: "MANUAL" currently includes the synchronization requested when a new account is created and when the user changes the current account)\r
syncResult.tooManyRetries = true;\r
/// notify the user about the failure of MANUAL synchronization\r
notifyFailedSynchronization();\r
}\r
- sendStickyBroadcast(false, null); // message to signal the end to the UI\r
+ sendStickyBroadcast(false, null, mLastFailedResult); // message to signal the end to the UI\r
}\r
\r
}\r
*/\r
private void fetchData(String remotePath, SyncResult syncResult, long parentId) {\r
\r
+ if (mFailedResultsCounter > MAX_FAILED_RESULTS && isFinisher(mLastFailedResult))\r
+ return;\r
+ \r
// get client object to connect to the remote ownCloud server\r
WebdavClient client = null;\r
try {\r
\r
\r
// synchronized folder -> notice to UI - ALWAYS, although !result.isSuccess\r
- sendStickyBroadcast(true, remotePath);\r
+ sendStickyBroadcast(true, remotePath, null);\r
\r
if (result.isSuccess()) {\r
// synchronize children folders \r
} else if (result.getException() instanceof IOException) { \r
syncResult.stats.numIoExceptions++;\r
\r
- } else if (result.getException() != null) {\r
- // TODO maybe something smarter with syncResult\r
- mRightSync = false;\r
}\r
+ mFailedResultsCounter++;\r
+ mLastFailedResult = result;\r
}\r
\r
}\r
\r
/**\r
+ * Checks if a failed result should terminate the synchronization process immediately, according to\r
+ * OUR OWN POLICY\r
+ * \r
+ * @param failedResult Remote operation result to check.\r
+ * @return 'True' if the result should immediately finish the synchronization\r
+ */\r
+ private boolean isFinisher(RemoteOperationResult failedResult) {\r
+ if (failedResult != null) {\r
+ RemoteOperationResult.ResultCode code = failedResult.getCode();\r
+ return (code.equals(RemoteOperationResult.ResultCode.SSL_ERROR) ||\r
+ code.equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) ||\r
+ code.equals(RemoteOperationResult.ResultCode.BAD_OC_VERSION) ||\r
+ code.equals(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED));\r
+ }\r
+ return false;\r
+ }\r
+\r
+ /**\r
* Synchronize data of folders in the list of received files\r
* \r
* @param files Files to recursively fetch \r
\r
\r
/**\r
- * Sends a message to any app component interested in the progress of the synchronization.\r
+ * Sends a message to any application component interested in the progress of the synchronization.\r
* \r
* @param inProgress 'True' when the synchronization progress is not finished.\r
* @param dirRemotePath Remote path of a folder that was just synchronized (with or without success)\r
*/\r
- private void sendStickyBroadcast(boolean inProgress, String dirRemotePath/*, RemoteOperationResult result*/) {\r
+ private void sendStickyBroadcast(boolean inProgress, String dirRemotePath, RemoteOperationResult result) {\r
Intent i = new Intent(FileSyncService.SYNC_MESSAGE);\r
i.putExtra(FileSyncService.IN_PROGRESS, inProgress);\r
i.putExtra(FileSyncService.ACCOUNT_NAME, getAccount().name);\r
if (dirRemotePath != null) {\r
i.putExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH, dirRemotePath);\r
}\r
- /*if (result != null) {\r
+ if (result != null) {\r
i.putExtra(FileSyncService.SYNC_RESULT, result);\r
- }*/\r
+ }\r
getContext().sendStickyBroadcast(i);\r
}\r
\r
import com.owncloud.android.files.services.FileUploader;\r
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
import com.owncloud.android.network.OwnCloudClientUtils;\r
+import com.owncloud.android.operations.RemoteOperationResult;\r
import com.owncloud.android.syncadapter.FileSyncService;\r
+import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
+import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
import com.owncloud.android.ui.fragment.FileDetailFragment;\r
import com.owncloud.android.ui.fragment.OCFileListFragment;\r
\r
*/\r
\r
public class FileDisplayActivity extends SherlockFragmentActivity implements\r
- OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener {\r
+ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener {\r
\r
private ArrayAdapter<String> mDirectories;\r
private OCFile mCurrentDir = null;\r
private FileDownloaderBinder mDownloaderBinder = null;\r
private FileUploaderBinder mUploaderBinder = null;\r
private ServiceConnection mDownloadConnection = null, mUploadConnection = null;\r
+ private RemoteOperationResult mLastSslUntrustedServerResult = null;\r
\r
private OCFileListFragment mFileList;\r
\r
private static final int DIALOG_ABOUT_APP = 2;\r
public static final int DIALOG_SHORT_WAIT = 3;\r
private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 4;\r
+ private static final int DIALOG_SSL_VALIDATOR = 5;\r
+ private static final int DIALOG_CERT_NOT_SAVED = 6;\r
+\r
\r
private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;\r
private static final int ACTION_SELECT_MULTIPLE_FILES = 2;\r
break;\r
}\r
case R.id.startSync: {\r
- ContentResolver.cancelSync(null, AccountAuthenticator.AUTH_TOKEN_TYPE); // cancel the current synchronizations of any ownCloud account\r
- Bundle bundle = new Bundle();\r
- bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
- ContentResolver.requestSync(\r
- AccountUtils.getCurrentOwnCloudAccount(this),\r
- AccountAuthenticator.AUTH_TOKEN_TYPE, bundle);\r
+ startSynchronization();\r
break;\r
}\r
case R.id.action_upload: {\r
return retval;\r
}\r
\r
+ private void startSynchronization() {\r
+ ContentResolver.cancelSync(null, AccountAuthenticator.AUTH_TOKEN_TYPE); // cancel the current synchronizations of any ownCloud account\r
+ Bundle bundle = new Bundle();\r
+ bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
+ ContentResolver.requestSync(\r
+ AccountUtils.getCurrentOwnCloudAccount(this),\r
+ AccountAuthenticator.AUTH_TOKEN_TYPE, bundle);\r
+ }\r
+\r
+\r
@Override\r
public boolean onNavigationItemSelected(int itemPosition, long itemId) {\r
int i = itemPosition;\r
Log.d(getClass().toString(), "onPause() end");\r
}\r
\r
+ \r
+ @Override\r
+ protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {\r
+ if (id == DIALOG_SSL_VALIDATOR && mLastSslUntrustedServerResult != null) {\r
+ ((SslValidatorDialog)dialog).updateResult(mLastSslUntrustedServerResult);\r
+ }\r
+ }\r
+\r
+ \r
@Override\r
protected Dialog onCreateDialog(int id) {\r
Dialog dialog = null;\r
dialog = builder.create();\r
break;\r
}\r
+ case DIALOG_SSL_VALIDATOR: {\r
+ dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);\r
+ break;\r
+ }\r
+ case DIALOG_CERT_NOT_SAVED: {\r
+ builder = new AlertDialog.Builder(this);\r
+ builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));\r
+ builder.setCancelable(false);\r
+ builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {\r
+ @Override\r
+ public void onClick(DialogInterface dialog, int which) {\r
+ dialog.dismiss();\r
+ };\r
+ });\r
+ dialog = builder.create();\r
+ break;\r
+ }\r
default:\r
dialog = null;\r
}\r
}\r
\r
private class SyncBroadcastReceiver extends BroadcastReceiver {\r
+\r
/**\r
* {@link BroadcastReceiver} to enable syncing feedback in UI\r
*/\r
setSupportProgressBarIndeterminateVisibility(inProgress);\r
\r
}\r
+ \r
+ RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncService.SYNC_RESULT);\r
+ if (synchResult != null) {\r
+ if (synchResult.getCode().equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {\r
+ mLastSslUntrustedServerResult = synchResult;\r
+ showDialog(DIALOG_SSL_VALIDATOR); \r
+ }\r
+ }\r
}\r
}\r
\r
}\r
\r
\r
+ @Override\r
+ public void onSavedCertificate() {\r
+ startSynchronization(); \r
+ }\r
+\r
+\r
+ @Override\r
+ public void onFailedSavingCertificate() {\r
+ showDialog(DIALOG_CERT_NOT_SAVED);\r
+ }\r
+\r
+\r
}\r