mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Moved up the logic of the 'SSL untrusted' dialog to FileActivity to be shown in all refreshes
This commit is contained in:
parent
47560ea7d5
commit
9c617e993b
4 changed files with 110 additions and 85 deletions
|
@ -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,40 @@ 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.getRemotePath().substring(0,
|
||||
file.getRemotePath().lastIndexOf(file.getFileName()));
|
||||
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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
@ -1036,7 +1027,6 @@ public class FileDisplayActivity extends HookActivity implements
|
|||
synchResult != null && !synchResult.isSuccess()) {
|
||||
|
||||
if(ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) ||
|
||||
synchResult.isIdPRedirection() ||
|
||||
(synchResult.isException() && synchResult.getException()
|
||||
instanceof AuthenticatorException)) {
|
||||
|
||||
|
@ -1370,25 +1360,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.
|
||||
|
@ -1451,8 +1422,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()) {
|
||||
|
@ -1652,19 +1623,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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1723,21 +1684,6 @@ public class FileDisplayActivity extends HookActivity implements
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 requestForDownload(OCFile file) {
|
||||
Account account = getAccount();
|
||||
if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -350,7 +350,7 @@ public class Uploader extends FileActivity
|
|||
} else {
|
||||
mParents.pop();
|
||||
String full_path = generatePath(mParents);
|
||||
startSyncFolderOperation(getStorageManager().getFileByPath(full_path));
|
||||
startSyncFolderOperation(getStorageManager().getFileByPath(full_path), false);
|
||||
populateDirectoryList();
|
||||
}
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ public class Uploader extends FileActivity
|
|||
}
|
||||
if (files.get(position).isFolder()){
|
||||
OCFile folderToEnter = files.get(position);
|
||||
startSyncFolderOperation(folderToEnter);
|
||||
startSyncFolderOperation(folderToEnter, false);
|
||||
mParents.push(folderToEnter.getFileName());
|
||||
populateDirectoryList();
|
||||
}
|
||||
|
@ -472,8 +472,13 @@ public class Uploader extends FileActivity
|
|||
mListView.setOnItemClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void startSyncFolderOperation(OCFile folder) {
|
||||
|
||||
@Override
|
||||
public void onSavedCertificate() {
|
||||
startSyncFolderOperation(getCurrentDir(), false);
|
||||
}
|
||||
|
||||
private void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
|
||||
long currentSyncTime = System.currentTimeMillis();
|
||||
|
||||
mSyncInProgress = true;
|
||||
|
@ -483,7 +488,7 @@ public class Uploader extends FileActivity
|
|||
currentSyncTime,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
ignoreETag,
|
||||
getStorageManager(),
|
||||
getAccount(),
|
||||
getApplicationContext()
|
||||
|
@ -731,7 +736,7 @@ public class Uploader extends FileActivity
|
|||
private void browseToRoot() {
|
||||
OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
|
||||
mFile = root;
|
||||
startSyncFolderOperation(root);
|
||||
startSyncFolderOperation(root, false);
|
||||
}
|
||||
|
||||
private class SyncBroadcastReceiver extends BroadcastReceiver {
|
||||
|
@ -793,13 +798,19 @@ 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 != null && !synchResult.isSuccess()) {
|
||||
|
||||
if(synchResult.getCode() == ResultCode.UNAUTHORIZED ||
|
||||
synchResult.isIdPRedirection() ||
|
||||
(synchResult.isException() && synchResult.getException()
|
||||
instanceof AuthenticatorException))) {
|
||||
instanceof AuthenticatorException)) {
|
||||
|
||||
requestCredentialsUpdate(context);
|
||||
requestCredentialsUpdate(context);
|
||||
|
||||
} else if(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(synchResult.getCode())) {
|
||||
|
||||
showUntrustedCertDialog(synchResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
removeStickyBroadcast(intent);
|
||||
|
|
Loading…
Reference in a new issue