Moved up the logic of the 'SSL untrusted' dialog to FileActivity to be shown in all refreshes

This commit is contained in:
Juan Carlos González Cabrero 2016-04-08 12:49:12 +02:00
parent 47560ea7d5
commit 9c617e993b
4 changed files with 110 additions and 85 deletions

View file

@ -66,6 +66,7 @@ import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.OwnCloudCredentials; 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.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; 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.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.NavigationDrawerItem; import com.owncloud.android.ui.NavigationDrawerItem;
import com.owncloud.android.ui.adapter.NavigationDrawerListAdapter; 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.LoadingDialog;
import com.owncloud.android.ui.dialog.SharePasswordDialogFragment; import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.ErrorMessageAdapter;
import java.util.ArrayList; import java.util.ArrayList;
@ -96,7 +99,7 @@ import java.util.ArrayList;
* {@link Account}s . * {@link Account}s .
*/ */
public class FileActivity extends AppCompatActivity 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_FILE = "com.owncloud.android.ui.activity.FILE";
public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT"; 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; 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.*/ /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
private Account mAccount; private Account mAccount;
@ -761,6 +768,10 @@ public class FileActivity extends AppCompatActivity
t.show(); t.show();
} }
} else if (!result.isSuccess() && ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(result.getCode())) {
showUntrustedCertDialog(result);
} else if (operation == null || } else if (operation == null ||
operation instanceof CreateShareWithShareeOperation || operation instanceof CreateShareWithShareeOperation ||
operation instanceof UnshareOperation || 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, private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation operation,
RemoteOperationResult result) { RemoteOperationResult result) {
@ -1027,6 +1051,40 @@ public class FileActivity extends AppCompatActivity
restart(); 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 { private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

View file

@ -46,7 +46,6 @@ import android.preference.PreferenceManager;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat; 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.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; 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.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; 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.operations.UploadFileOperation;
import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.syncadapter.FileSyncAdapter; 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.FileDetailFragment;
import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment; 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. * Displays, what files the user has available in his ownCloud. This is the main view.
*/ */
public class FileDisplayActivity extends HookActivity implements public class FileDisplayActivity extends HookActivity
FileFragment.ContainerActivity, implements FileFragment.ContainerActivity,
OnSslUntrustedCertListener, OnEnforceableRefreshListener { OnEnforceableRefreshListener {
private SyncBroadcastReceiver mSyncBroadcastReceiver; private SyncBroadcastReceiver mSyncBroadcastReceiver;
private UploadFinishReceiver mUploadFinishReceiver; private UploadFinishReceiver mUploadFinishReceiver;
@ -138,10 +133,6 @@ public class FileDisplayActivity extends HookActivity implements
private boolean mSyncInProgress = false; 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; private OCFile mWaitingToSend;
@ -1036,7 +1027,6 @@ public class FileDisplayActivity extends HookActivity implements
synchResult != null && !synchResult.isSuccess()) { synchResult != null && !synchResult.isSuccess()) {
if(ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) || if(ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) ||
synchResult.isIdPRedirection() ||
(synchResult.isException() && synchResult.getException() (synchResult.isException() && synchResult.getException()
instanceof AuthenticatorException)) { 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 * Updates the view associated to the activity after the finish of some operation over files
* in the current account. * in the current account.
@ -1652,19 +1623,9 @@ public class FileDisplayActivity extends HookActivity implements
} }
} }
@Override
private OCFile getCurrentDir() { public void onSavedCertificate() {
OCFile file = getFile(); startSyncFolderOperation(getCurrentDir(), false);
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;
} }
/** /**
@ -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) { private void requestForDownload(OCFile file) {
Account account = getAccount(); Account account = getAccount();
if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) { if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {

View file

@ -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) { public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
long currentSyncTime = System.currentTimeMillis(); long currentSyncTime = System.currentTimeMillis();
@ -480,13 +484,19 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
equals(event) && equals(event) &&
/// TODO refactor and make common /// TODO refactor and make common
synchResult != null && !synchResult.isSuccess() && synchResult != null && !synchResult.isSuccess()) {
(ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) ||
if(ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) ||
(synchResult.isException() && synchResult.getException() (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); removeStickyBroadcast(intent);

View file

@ -350,7 +350,7 @@ public class Uploader extends FileActivity
} else { } else {
mParents.pop(); mParents.pop();
String full_path = generatePath(mParents); String full_path = generatePath(mParents);
startSyncFolderOperation(getStorageManager().getFileByPath(full_path)); startSyncFolderOperation(getStorageManager().getFileByPath(full_path), false);
populateDirectoryList(); populateDirectoryList();
} }
} }
@ -371,7 +371,7 @@ public class Uploader extends FileActivity
} }
if (files.get(position).isFolder()){ if (files.get(position).isFolder()){
OCFile folderToEnter = files.get(position); OCFile folderToEnter = files.get(position);
startSyncFolderOperation(folderToEnter); startSyncFolderOperation(folderToEnter, false);
mParents.push(folderToEnter.getFileName()); mParents.push(folderToEnter.getFileName());
populateDirectoryList(); populateDirectoryList();
} }
@ -473,7 +473,12 @@ public class Uploader extends FileActivity
} }
} }
private void startSyncFolderOperation(OCFile folder) { @Override
public void onSavedCertificate() {
startSyncFolderOperation(getCurrentDir(), false);
}
private void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
long currentSyncTime = System.currentTimeMillis(); long currentSyncTime = System.currentTimeMillis();
mSyncInProgress = true; mSyncInProgress = true;
@ -483,7 +488,7 @@ public class Uploader extends FileActivity
currentSyncTime, currentSyncTime,
false, false,
false, false,
false, ignoreETag,
getStorageManager(), getStorageManager(),
getAccount(), getAccount(),
getApplicationContext() getApplicationContext()
@ -731,7 +736,7 @@ public class Uploader extends FileActivity
private void browseToRoot() { private void browseToRoot() {
OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
mFile = root; mFile = root;
startSyncFolderOperation(root); startSyncFolderOperation(root, false);
} }
private class SyncBroadcastReceiver extends BroadcastReceiver { private class SyncBroadcastReceiver extends BroadcastReceiver {
@ -793,13 +798,19 @@ public class Uploader extends FileActivity
if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
equals(event) && equals(event) &&
/// TODO refactor and make common /// TODO refactor and make common
synchResult != null && !synchResult.isSuccess() && synchResult != null && !synchResult.isSuccess()) {
(synchResult.getCode() == ResultCode.UNAUTHORIZED ||
if(synchResult.getCode() == ResultCode.UNAUTHORIZED ||
synchResult.isIdPRedirection() || synchResult.isIdPRedirection() ||
(synchResult.isException() && synchResult.getException() (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); removeStickyBroadcast(intent);