forked from upstream-mirrors/OpenTracks
Self-review
This commit is contained in:
@@ -209,7 +209,7 @@ public class SendToDocs {
|
|||||||
androidClient = GDataClientFactory.getGDataClient(activity);
|
androidClient = GDataClientFactory.getGDataClient(activity);
|
||||||
SpreadsheetsClient gdataClient = new SpreadsheetsClient(androidClient,
|
SpreadsheetsClient gdataClient = new SpreadsheetsClient(androidClient,
|
||||||
new XmlMapsGDataParserFactory(new AndroidXmlParserFactory()));
|
new XmlMapsGDataParserFactory(new AndroidXmlParserFactory()));
|
||||||
wiseWrapper.setClient(androidClient, gdataClient);
|
wiseWrapper.setClient(gdataClient);
|
||||||
Log.d(MyTracksConstants.TAG,
|
Log.d(MyTracksConstants.TAG,
|
||||||
"GData connection prepared: " + this.writelyAuth);
|
"GData connection prepared: " + this.writelyAuth);
|
||||||
String sheetTitle = "My Tracks";
|
String sheetTitle = "My Tracks";
|
||||||
@@ -220,7 +220,7 @@ public class SendToDocs {
|
|||||||
|
|
||||||
DocumentsClient docsGdataClient = new DocumentsClient(androidClient,
|
DocumentsClient docsGdataClient = new DocumentsClient(androidClient,
|
||||||
new XmlMapsGDataParserFactory(new AndroidXmlParserFactory()));
|
new XmlMapsGDataParserFactory(new AndroidXmlParserFactory()));
|
||||||
writelyWrapper.setClient(androidClient, docsGdataClient);
|
writelyWrapper.setClient(docsGdataClient);
|
||||||
|
|
||||||
// First try to find the spreadsheet:
|
// First try to find the spreadsheet:
|
||||||
if (!getSpreadsheetId(writelyWrapper, sheetTitle)) {
|
if (!getSpreadsheetId(writelyWrapper, sheetTitle)) {
|
||||||
@@ -302,9 +302,7 @@ public class SendToDocs {
|
|||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (androidClient != null) {
|
if (androidClient != null) {
|
||||||
Log.e(MyTracksConstants.TAG, "closing the android client");
|
|
||||||
androidClient.close();
|
androidClient.close();
|
||||||
Log.e(MyTracksConstants.TAG, "closed the android client");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -17,21 +17,17 @@ package com.google.android.apps.mytracks.io.gdata;
|
|||||||
|
|
||||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||||
import com.google.android.apps.mytracks.io.AuthManager;
|
import com.google.android.apps.mytracks.io.AuthManager;
|
||||||
import com.google.wireless.gdata.client.GDataClient;
|
|
||||||
import com.google.wireless.gdata.client.GDataServiceClient;
|
import com.google.wireless.gdata.client.GDataServiceClient;
|
||||||
import com.google.wireless.gdata.client.HttpException;
|
import com.google.wireless.gdata.client.HttpException;
|
||||||
import com.google.wireless.gdata.parser.ParseException;
|
import com.google.wireless.gdata.parser.ParseException;
|
||||||
import com.google.wireless.gdata2.ConflictDetectedException;
|
import com.google.wireless.gdata2.ConflictDetectedException;
|
||||||
import com.google.wireless.gdata2.client.AuthenticationException;
|
import com.google.wireless.gdata2.client.AuthenticationException;
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
|
||||||
import java.util.concurrent.FutureTask;
|
import java.util.concurrent.FutureTask;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
@@ -99,8 +95,6 @@ public class GDataWrapper {
|
|||||||
private AuthManager auth;
|
private AuthManager auth;
|
||||||
private boolean retryOnAuthFailure;
|
private boolean retryOnAuthFailure;
|
||||||
|
|
||||||
private int count = 0;
|
|
||||||
|
|
||||||
public GDataWrapper() {
|
public GDataWrapper() {
|
||||||
errorType = ERROR_NO_ERROR;
|
errorType = ERROR_NO_ERROR;
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
@@ -108,8 +102,7 @@ public class GDataWrapper {
|
|||||||
retryOnAuthFailure = false;
|
retryOnAuthFailure = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClient(GDataClient androidGDataClient,
|
public void setClient(GDataServiceClient gdataServiceClient) {
|
||||||
GDataServiceClient gdataServiceClient) {
|
|
||||||
this.gdataServiceClient = gdataServiceClient;
|
this.gdataServiceClient = gdataServiceClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,41 +142,13 @@ public class GDataWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates and refreshes the auth token. Blocks until the refresh has
|
* Execute a given function or query. If one is executed, errorType and
|
||||||
* completed or until we deem the refresh as having timed out.
|
* errorMessage will contain the result/status of the function/query.
|
||||||
*
|
*
|
||||||
* @return true If the invalidate/refresh succeeds, false if it fails or
|
* @return true if function or query was non-null. false if both were null.
|
||||||
* times out.
|
|
||||||
*/
|
*/
|
||||||
private boolean invalidateAndRefreshAuthToken() {
|
private boolean runOneActual(final AuthenticatedFunction function,
|
||||||
Log.d(MyTracksConstants.TAG, "Retrying due to auth failure");
|
final QueryFunction query) {
|
||||||
FutureTask<?> whenFinishedFuture = new FutureTask<Object>(new Runnable() {
|
|
||||||
public void run() {}
|
|
||||||
}, null);
|
|
||||||
|
|
||||||
auth.invalidateAndRefresh(whenFinishedFuture);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Log.d(MyTracksConstants.TAG, "waiting for invalidate");
|
|
||||||
whenFinishedFuture.get(5, TimeUnit.SECONDS);
|
|
||||||
Log.d(MyTracksConstants.TAG, "invalidate finished");
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Log.e(MyTracksConstants.TAG, "Failed to invalidate", e);
|
|
||||||
return false;
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
Log.e(MyTracksConstants.TAG, "Failed to invalidate", e);
|
|
||||||
return false;
|
|
||||||
} catch (TimeoutException e) {
|
|
||||||
Log.e(MyTracksConstants.TAG, "Invalidate didn't complete in time", e);
|
|
||||||
return false;
|
|
||||||
} finally {
|
|
||||||
whenFinishedFuture.cancel(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean runOneActual(final AuthenticatedFunction function, final QueryFunction query) {
|
|
||||||
try {
|
try {
|
||||||
if (function != null) {
|
if (function != null) {
|
||||||
function.run(this.auth.getAuthToken());
|
function.run(this.auth.getAuthToken());
|
||||||
@@ -193,11 +158,6 @@ public class GDataWrapper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
count++;
|
|
||||||
throw new AuthenticationException("mts auth fail fake");
|
|
||||||
}
|
|
||||||
|
|
||||||
errorType = ERROR_NO_ERROR;
|
errorType = ERROR_NO_ERROR;
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
return true;
|
return true;
|
||||||
@@ -239,6 +199,41 @@ public class GDataWrapper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidates and refreshes the auth token. Blocks until the refresh has
|
||||||
|
* completed or until we deem the refresh as having timed out.
|
||||||
|
*
|
||||||
|
* @return true If the invalidate/refresh succeeds, false if it fails or
|
||||||
|
* times out.
|
||||||
|
*/
|
||||||
|
private boolean invalidateAndRefreshAuthToken() {
|
||||||
|
Log.d(MyTracksConstants.TAG, "Retrying due to auth failure");
|
||||||
|
FutureTask<?> whenFinishedFuture = new FutureTask<Object>(new Runnable() {
|
||||||
|
public void run() {}
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
auth.invalidateAndRefresh(whenFinishedFuture);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Log.d(MyTracksConstants.TAG, "waiting for invalidate");
|
||||||
|
whenFinishedFuture.get(5, TimeUnit.SECONDS);
|
||||||
|
Log.d(MyTracksConstants.TAG, "invalidate finished");
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.e(MyTracksConstants.TAG, "Failed to invalidate", e);
|
||||||
|
return false;
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
Log.e(MyTracksConstants.TAG, "Failed to invalidate", e);
|
||||||
|
return false;
|
||||||
|
} catch (TimeoutException e) {
|
||||||
|
Log.e(MyTracksConstants.TAG, "Invalidate didn't complete in time", e);
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
whenFinishedFuture.cancel(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public int getErrorType() {
|
public int getErrorType() {
|
||||||
return errorType;
|
return errorType;
|
||||||
}
|
}
|
||||||
@@ -251,10 +246,6 @@ public class GDataWrapper {
|
|||||||
this.auth = auth;
|
this.auth = auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthManager getAuthManager() {
|
|
||||||
return auth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRetryOnAuthFailure(boolean retry) {
|
public void setRetryOnAuthFailure(boolean retry) {
|
||||||
retryOnAuthFailure = retry;
|
retryOnAuthFailure = retry;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user