diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 0fad8a8352..0fbbc75c5a 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -66,6 +66,7 @@ import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.OwnCloudCredentials; +import com.owncloud.android.lib.common.network.CertificateCombinedException; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -84,8 +85,10 @@ import com.owncloud.android.services.OperationsService; import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.ui.NavigationDrawerItem; import com.owncloud.android.ui.adapter.NavigationDrawerListAdapter; +import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.LoadingDialog; import com.owncloud.android.ui.dialog.SharePasswordDialogFragment; +import com.owncloud.android.ui.dialog.SslUntrustedCertDialog; import com.owncloud.android.utils.ErrorMessageAdapter; import java.util.ArrayList; @@ -96,7 +99,7 @@ import java.util.ArrayList; * {@link Account}s . */ public class FileActivity extends AppCompatActivity - implements OnRemoteOperationListener, ComponentsGetter { + implements OnRemoteOperationListener, ComponentsGetter, SslUntrustedCertDialog.OnSslUntrustedCertListener { public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE"; public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT"; @@ -116,6 +119,10 @@ public class FileActivity extends AppCompatActivity protected static final long DELAY_TO_REQUEST_OPERATIONS_LATER = 200; + /* Dialog tags */ + private static final String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT"; + private static final String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED"; + /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/ private Account mAccount; @@ -741,7 +748,7 @@ public class FileActivity extends AppCompatActivity @Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { Log_OC.d(TAG, "Received result of operation in FileActivity - common behaviour for all the " - + "FileActivities "); + + "FileActivities "); mFileOperationsHelper.setOpIdWaitingFor(Long.MAX_VALUE); @@ -756,11 +763,15 @@ public class FileActivity extends AppCompatActivity if (result.getCode() == ResultCode.UNAUTHORIZED) { Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, - operation, getResources()), - Toast.LENGTH_LONG); + operation, getResources()), + Toast.LENGTH_LONG); t.show(); } + } else if (!result.isSuccess() && ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(result.getCode())) { + + showUntrustedCertDialog(result); + } else if (operation == null || operation instanceof CreateShareWithShareeOperation || operation instanceof UnshareOperation || @@ -861,7 +872,20 @@ public class FileActivity extends AppCompatActivity } - + /** + * Show untrusted cert dialog + */ + public void showUntrustedCertDialog(RemoteOperationResult result) { + // Show a dialog with the certificate info + FragmentManager fm = getSupportFragmentManager(); + SslUntrustedCertDialog dialog = (SslUntrustedCertDialog) fm.findFragmentByTag(DIALOG_UNTRUSTED_CERT); + if(dialog == null) { + dialog = SslUntrustedCertDialog.newInstanceForFullSslError( + (CertificateCombinedException) result.getException()); + FragmentTransaction ft = fm.beginTransaction(); + dialog.show(ft, DIALOG_UNTRUSTED_CERT); + } + } private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation operation, RemoteOperationResult result) { @@ -1027,6 +1051,39 @@ public class FileActivity extends AppCompatActivity restart(); } + protected OCFile getCurrentDir() { + OCFile file = getFile(); + if (file != null) { + if (file.isFolder()) { + return file; + } else if (getStorageManager() != null) { + String parentPath = file.getParentRemotePath(); + return getStorageManager().getFileByPath(parentPath); + } + } + return null; + } + + /* OnSslUntrustedCertListener methods */ + + @Override + public void onSavedCertificate() { + // Nothing to do in this context + } + + @Override + public void onFailedSavingCertificate() { + ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance( + R.string.ssl_validator_not_saved, new String[]{}, R.string.common_ok, -1, -1 + ); + dialog.show(getSupportFragmentManager(), DIALOG_CERT_NOT_SAVED); + } + + @Override + public void onCancelCertificate() { + // nothing to do + } + private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 8b833df054..0ba8f31c44 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -46,7 +46,6 @@ import android.preference.PreferenceManager; import android.provider.OpenableColumns; import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.view.GravityCompat; @@ -66,7 +65,6 @@ import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; -import com.owncloud.android.lib.common.network.CertificateCombinedException; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; @@ -81,9 +79,6 @@ import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.UploadFileOperation; import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.syncadapter.FileSyncAdapter; -import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; -import com.owncloud.android.ui.dialog.SslUntrustedCertDialog; -import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener; import com.owncloud.android.ui.fragment.FileDetailFragment; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.OCFileListFragment; @@ -104,9 +99,9 @@ import java.io.File; * Displays, what files the user has available in his ownCloud. This is the main view. */ -public class FileDisplayActivity extends HookActivity implements - FileFragment.ContainerActivity, - OnSslUntrustedCertListener, OnEnforceableRefreshListener { +public class FileDisplayActivity extends HookActivity + implements FileFragment.ContainerActivity, + OnEnforceableRefreshListener { private SyncBroadcastReceiver mSyncBroadcastReceiver; private UploadFinishReceiver mUploadFinishReceiver; @@ -138,10 +133,6 @@ public class FileDisplayActivity extends HookActivity implements private boolean mSyncInProgress = false; - private static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT"; - private static String DIALOG_UPLOAD_SOURCE = "DIALOG_UPLOAD_SOURCE"; - private static String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED"; - private OCFile mWaitingToSend; @@ -1031,14 +1022,21 @@ public class FileDisplayActivity extends HookActivity implements .equals(event)); if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. - equals(event) &&/// TODO refactor and make common + equals(event) &&/// TODO refactor and make common - synchResult != null && !synchResult.isSuccess() && - (ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) || - (synchResult.isException() && synchResult.getException() - instanceof AuthenticatorException))) { + synchResult != null && !synchResult.isSuccess()) { - requestCredentialsUpdate(context); + if(ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) || + (synchResult.isException() && synchResult.getException() + instanceof AuthenticatorException)) { + + requestCredentialsUpdate(context); + + } else if(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals( + synchResult.getCode())) { + + showUntrustedCertDialog(synchResult); + } } @@ -1363,25 +1361,6 @@ public class FileDisplayActivity extends HookActivity implements } } - @Override - public void onSavedCertificate() { - startSyncFolderOperation(getCurrentDir(), false); - } - - - @Override - public void onFailedSavingCertificate() { - ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance( - R.string.ssl_validator_not_saved, new String[]{}, R.string.common_ok, -1, -1 - ); - dialog.show(getSupportFragmentManager(), DIALOG_CERT_NOT_SAVED); - } - - @Override - public void onCancelCertificate() { - // nothing to do - } - /** * Updates the view associated to the activity after the finish of some operation over files * in the current account. @@ -1444,8 +1423,8 @@ public class FileDisplayActivity extends HookActivity implements private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) { Toast msg = Toast.makeText(this, - ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); msg.show(); if (result.isSuccess()) { @@ -1645,19 +1624,9 @@ public class FileDisplayActivity extends HookActivity implements } } - - private OCFile getCurrentDir() { - OCFile file = getFile(); - if (file != null) { - if (file.isFolder()) { - return file; - } else if (getStorageManager() != null) { - String parentPath = file.getRemotePath().substring(0, - file.getRemotePath().lastIndexOf(file.getFileName())); - return getStorageManager().getFileByPath(parentPath); - } - } - return null; + @Override + public void onSavedCertificate() { + startSyncFolderOperation(getCurrentDir(), false); } /** @@ -1716,18 +1685,6 @@ public class FileDisplayActivity extends HookActivity implements } - /** - * Show untrusted cert dialog - */ - public void showUntrustedCertDialog(RemoteOperationResult result) { - // Show a dialog with the certificate info - SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstanceForFullSslError( - (CertificateCombinedException) result.getException()); - FragmentManager fm = getSupportFragmentManager(); - FragmentTransaction ft = fm.beginTransaction(); - dialog.show(ft, DIALOG_UNTRUSTED_CERT); - } - private void requestForDownload(OCFile file) { Account account = getAccount(); if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) { diff --git a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java index 3d86621988..a75d53df20 100644 --- a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java +++ b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java @@ -197,6 +197,10 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C } + @Override + public void onSavedCertificate() { + startSyncFolderOperation(getCurrentDir(), false); + } public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) { long currentSyncTime = System.currentTimeMillis(); @@ -343,9 +347,9 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C actionBar.setDisplayHomeAsUpEnabled(!atRoot); actionBar.setHomeButtonEnabled(!atRoot); actionBar.setTitle( - atRoot - ? getString(R.string.default_display_name_for_root_folder) - : currentDir.getFileName() + atRoot + ? getString(R.string.default_display_name_for_root_folder) + : currentDir.getFileName() ); } @@ -480,12 +484,18 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. equals(event) && /// TODO refactor and make common - synchResult != null && !synchResult.isSuccess() && - (ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) || - (synchResult.isException() && synchResult.getException() - instanceof AuthenticatorException))) { + synchResult != null && !synchResult.isSuccess()) { - requestCredentialsUpdate(context); + if(ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) || + (synchResult.isException() && synchResult.getException() + instanceof AuthenticatorException)) { + + requestCredentialsUpdate(context); + + } else if(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(synchResult.getCode())) { + + showUntrustedCertDialog(synchResult); + } } } diff --git a/src/com/owncloud/android/ui/activity/Uploader.java b/src/com/owncloud/android/ui/activity/Uploader.java index 87d32ee9e7..acde42586d 100644 --- a/src/com/owncloud/android/ui/activity/Uploader.java +++ b/src/com/owncloud/android/ui/activity/Uploader.java @@ -472,7 +472,12 @@ public class Uploader extends FileActivity mListView.setOnItemClickListener(this); } } - + + @Override + public void onSavedCertificate() { + startSyncFolderOperation(getCurrentDir()); + } + private void startSyncFolderOperation(OCFile folder) { long currentSyncTime = System.currentTimeMillis(); @@ -793,13 +798,18 @@ public class Uploader extends FileActivity if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. equals(event) && /// TODO refactor and make common - synchResult != null && !synchResult.isSuccess() && - (synchResult.getCode() == ResultCode.UNAUTHORIZED || - synchResult.isIdPRedirection() || - (synchResult.isException() && synchResult.getException() - instanceof AuthenticatorException))) { + synchResult != null && !synchResult.isSuccess()) { - requestCredentialsUpdate(context); + if(synchResult.getCode() == ResultCode.UNAUTHORIZED || + (synchResult.isException() && synchResult.getException() + instanceof AuthenticatorException)) { + + requestCredentialsUpdate(context); + + } else if(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(synchResult.getCode())) { + + showUntrustedCertDialog(synchResult); + } } } removeStickyBroadcast(intent);