Added a check in GtasksService for 503 errors (Google backend issues) and added the MANAGE_ACCOUNTS permission to the manifest

pull/14/head
Sam Bosley 15 years ago
parent 070972f72b
commit cbb1475bec

@ -25,6 +25,7 @@
<!-- for google tasks -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
<!-- for task sharing -->
<uses-permission android:name="android.permission.READ_CONTACTS" />

@ -2,6 +2,9 @@ package com.todoroo.astrid.gtasks.api;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import com.google.api.client.extensions.android2.AndroidHttp;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
import com.google.api.client.http.HttpResponseException;
@ -13,6 +16,12 @@ import com.google.api.services.tasks.v1.Tasks.TasksOperations.Move;
import com.google.api.services.tasks.v1.model.Task;
import com.google.api.services.tasks.v1.model.TaskList;
import com.google.api.services.tasks.v1.model.TaskLists;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.gtasks.auth.GtasksTokenValidator;
/**
@ -27,11 +36,14 @@ public class GtasksService {
private GoogleAccessProtectedResource accessProtectedResource;
private String token;
@Autowired ExceptionService exceptionService;
private static final String API_KEY = "AIzaSyCIYZTBo6haRHxmiplZsfYdagFEpaiFnAk"; // non-production API key
public static final String AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/tasks";
public GtasksService(String authToken) {
DependencyInjectionService.getInstance().inject(this);
authenticate(authToken);
}
@ -45,7 +57,7 @@ public class GtasksService {
}
//If we get a 401 or 403, try revalidating the auth token before bailing
private synchronized void handleException(IOException e) {
private synchronized void handleException(IOException e) throws IOException {
if (e instanceof HttpResponseException) {
HttpResponseException h = (HttpResponseException)e;
if (h.response.statusCode == 401 || h.response.statusCode == 403) {
@ -53,6 +65,16 @@ public class GtasksService {
if (token != null) {
accessProtectedResource.setAccessToken(token);
}
} else if (h.response.statusCode == 503) { // 503 errors are generally either 1) quota limit reached or 2) problems on Google's end
final Context context = ContextManager.getContext();
String message = context.getString(R.string.gtasks_error_backend);
exceptionService.reportError(message, h);
if(context instanceof Activity) {
DialogUtilities.okDialog((Activity)context,
message, null);
}
throw h;
}
}
}

@ -199,7 +199,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
syncSuccess = true;
} catch (IllegalStateException e) {
// occurs when application was closed
} catch (Exception e) {
} catch (IOException e) {
handleException("gtasks-sync", e, true); //$NON-NLS-1$
} finally {
StatisticsService.reportEvent("gtasks-sync-finished",
@ -207,8 +207,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
}
}
private void getActiveList(TaskLists taskView) throws JSONException,
IOException {
private void getActiveList(TaskLists taskView) throws IOException {
String listId;
if(taskView.items.size() == 0) {
if(Constants.DEBUG)
@ -298,7 +297,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
* Populate SyncData data structure
* @throws JSONException
*/
private SyncData<GtasksTaskContainer> populateSyncData() throws JSONException, IOException {
private SyncData<GtasksTaskContainer> populateSyncData() throws IOException {
// fetch remote tasks
ArrayList<GtasksTaskContainer> remoteTasks = readAllRemoteTasks(false);

@ -85,5 +85,10 @@
<!-- title for notification tray when synchronizing -->
<string name="gtasks_notification_title">Astrid: Google Tasks</string>
<!-- Error Message when we receive a HTTP 503 error -->
<string name="gtasks_error_backend">Google\'s Task API is in beta and has encountered an error. The service may be down, please try again later.</string>
</resources>

Loading…
Cancel
Save