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 --> <!-- for google tasks -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> <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" /> <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
<!-- for task sharing --> <!-- for task sharing -->
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />

@ -2,6 +2,9 @@ package com.todoroo.astrid.gtasks.api;
import java.io.IOException; 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.extensions.android2.AndroidHttp;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource; import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
import com.google.api.client.http.HttpResponseException; 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.Task;
import com.google.api.services.tasks.v1.model.TaskList; import com.google.api.services.tasks.v1.model.TaskList;
import com.google.api.services.tasks.v1.model.TaskLists; 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; import com.todoroo.astrid.gtasks.auth.GtasksTokenValidator;
/** /**
@ -27,11 +36,14 @@ public class GtasksService {
private GoogleAccessProtectedResource accessProtectedResource; private GoogleAccessProtectedResource accessProtectedResource;
private String token; private String token;
@Autowired ExceptionService exceptionService;
private static final String API_KEY = "AIzaSyCIYZTBo6haRHxmiplZsfYdagFEpaiFnAk"; // non-production API key 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 static final String AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/tasks";
public GtasksService(String authToken) { public GtasksService(String authToken) {
DependencyInjectionService.getInstance().inject(this);
authenticate(authToken); authenticate(authToken);
} }
@ -45,7 +57,7 @@ public class GtasksService {
} }
//If we get a 401 or 403, try revalidating the auth token before bailing //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) { if (e instanceof HttpResponseException) {
HttpResponseException h = (HttpResponseException)e; HttpResponseException h = (HttpResponseException)e;
if (h.response.statusCode == 401 || h.response.statusCode == 403) { if (h.response.statusCode == 401 || h.response.statusCode == 403) {
@ -53,6 +65,16 @@ public class GtasksService {
if (token != null) { if (token != null) {
accessProtectedResource.setAccessToken(token); 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; syncSuccess = true;
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// occurs when application was closed // occurs when application was closed
} catch (Exception e) { } catch (IOException e) {
handleException("gtasks-sync", e, true); //$NON-NLS-1$ handleException("gtasks-sync", e, true); //$NON-NLS-1$
} finally { } finally {
StatisticsService.reportEvent("gtasks-sync-finished", StatisticsService.reportEvent("gtasks-sync-finished",
@ -207,8 +207,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
} }
} }
private void getActiveList(TaskLists taskView) throws JSONException, private void getActiveList(TaskLists taskView) throws IOException {
IOException {
String listId; String listId;
if(taskView.items.size() == 0) { if(taskView.items.size() == 0) {
if(Constants.DEBUG) if(Constants.DEBUG)
@ -298,7 +297,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
* Populate SyncData data structure * Populate SyncData data structure
* @throws JSONException * @throws JSONException
*/ */
private SyncData<GtasksTaskContainer> populateSyncData() throws JSONException, IOException { private SyncData<GtasksTaskContainer> populateSyncData() throws IOException {
// fetch remote tasks // fetch remote tasks
ArrayList<GtasksTaskContainer> remoteTasks = readAllRemoteTasks(false); ArrayList<GtasksTaskContainer> remoteTasks = readAllRemoteTasks(false);

@ -66,7 +66,7 @@
<!-- Error Message when we receive a HTTP 401 Unauthorized --> <!-- Error Message when we receive a HTTP 401 Unauthorized -->
<string name="gtasks_GLA_errorAuth">Error authenticating! Please check your username and password in your phone\'s account manager</string> <string name="gtasks_GLA_errorAuth">Error authenticating! Please check your username and password in your phone\'s account manager</string>
<!-- Error Message when we receive a HTTP 401 Unauthorized multiple times --> <!-- Error Message when we receive a HTTP 401 Unauthorized multiple times -->
<string name="gtasks_GLA_errorAuth_captcha">You may have encountered a captcha. <string name="gtasks_GLA_errorAuth_captcha">You may have encountered a captcha.
Try logging in from the browser, then come back to try again:</string> Try logging in from the browser, then come back to try again:</string>
@ -84,6 +84,11 @@
<!-- title for notification tray when synchronizing --> <!-- title for notification tray when synchronizing -->
<string name="gtasks_notification_title">Astrid: Google Tasks</string> <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> </resources>

Loading…
Cancel
Save