Dropbox: make sure the token upgrade does not run on Main thread

WebDav: fix bug in certificate error handling
release 1.01-pre3
This commit is contained in:
Philipp Crocoll 2016-11-30 04:01:43 +01:00
parent f5d3aed721
commit 0afe1f97ff
5 changed files with 54 additions and 30 deletions

View File

@ -33,6 +33,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
@ -271,21 +272,6 @@ public class DropboxV2Storage extends JavaFileStorageBase
String v2Token = getKeyV2();
if (v2Token == null) {
String[] storedV1Keys = getKeysV1();
if (storedV1Keys != null) {
DbxOAuth1AccessToken v1Token = new DbxOAuth1AccessToken(storedV1Keys[0], storedV1Keys[1]);
DbxOAuth1Upgrader upgrader = new DbxOAuth1Upgrader(requestConfig, appInfo);
try {
v2Token = upgrader.createOAuth2AccessToken(v1Token);
upgrader.disableOAuth1AccessToken(v1Token);
storeKey(v2Token);
} catch (DbxException e) {
}
}
}
if (v2Token != null)
{
dbxClient = new DbxClientV2(requestConfig, v2Token);
@ -502,7 +488,7 @@ public class DropboxV2Storage extends JavaFileStorageBase
}
@Override
public void onResume(FileStorageSetupActivity activity) {
public void onResume(final FileStorageSetupActivity activity) {
if (activity.getProcessName().equals(PROCESS_NAME_SELECTFILE))
activity.getState().putString(EXTRA_PATH, activity.getPath());
@ -514,10 +500,52 @@ public class DropboxV2Storage extends JavaFileStorageBase
return;
}*/
JavaFileStorage.FileStorageSetupActivity storageSetupAct = (JavaFileStorage.FileStorageSetupActivity)activity;
if (storageSetupAct.getState().containsKey("hasStartedAuth"))
{
final String[] storedV1Keys = getKeysV1();
if (storedV1Keys != null) {
new AsyncTask<Object, Object, Object>()
{
@Override
protected Object doInBackground(Object... objects) {
DbxOAuth1AccessToken v1Token = new DbxOAuth1AccessToken(storedV1Keys[0], storedV1Keys[1]);
DbxOAuth1Upgrader upgrader = new DbxOAuth1Upgrader(requestConfig, appInfo);
try {
String v2Token = upgrader.createOAuth2AccessToken(v1Token);
upgrader.disableOAuth1AccessToken(v1Token);
storeKey(v2Token);
return v2Token;
} catch (Exception e) {
e.printStackTrace();
clearKeys();
return null;
}
}
@Override
protected void onPostExecute(Object o) {
if (o != null) {
buildSession();
finishActivityWithSuccess(activity);
}
else
resumeGetAuthToken(activity);
}
}.execute();
}
else {
resumeGetAuthToken(activity);
}
}
private void resumeGetAuthToken(FileStorageSetupActivity activity) {
FileStorageSetupActivity storageSetupAct = activity;
if (storageSetupAct.getState().containsKey("hasStartedAuth")) {
Log.d("KP2AJ", "auth started");
String v2Token = Auth.getOAuth2Token();
@ -542,18 +570,14 @@ public class DropboxV2Storage extends JavaFileStorageBase
Log.i(TAG, "authenticating not succesful");
Intent data = new Intent();
data.putExtra(EXTRA_ERROR_MESSAGE, "authenticating not succesful");
((Activity)activity).setResult(Activity.RESULT_CANCELED, data);
((Activity)activity).finish();
}
else
{
((Activity) activity).setResult(Activity.RESULT_CANCELED, data);
((Activity) activity).finish();
} else {
Log.d("KP2AJ", "Starting auth");
Auth.startOAuth2Authentication((Activity)activity, appInfo.getKey());
Auth.startOAuth2Authentication((Activity) activity, appInfo.getKey());
storageSetupAct.getState().putBoolean("hasStartedAuth", true);
}
}
@Override

View File

@ -130,7 +130,7 @@ public class WebDavStorage extends JavaFileStorageBase {
builder = builder.authenticator(new CachingAuthenticatorDecorator(authenticator, authCache))
.addInterceptor(new AuthenticationCacheInterceptor(authCache));
if ((mCertificateErrorHandler != null) && (mCertificateErrorHandler.alwaysFailOnValidationError())) {
if ((mCertificateErrorHandler != null) && (!mCertificateErrorHandler.alwaysFailOnValidationError())) {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="84"
android:versionName="1.01-pre2"
android:versionCode="85"
android:versionName="1.01-pre3"
package="keepass2android.keepass2android"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />