Commit 6e7bc97a authored by maybelle's avatar maybelle Committed by Commit bot

In case of an AuthException, start the recovery intent if it exists. This is a...

In case of an AuthException, start the recovery intent if it exists. This is a temporary fix to unblock devs while we work towards the real solution.

BUG=547048

Review URL: https://codereview.chromium.org/1630673002

Cr-Commit-Position: refs/heads/master@{#371505}
parent 4208a052
...@@ -9,6 +9,7 @@ import android.Manifest; ...@@ -9,6 +9,7 @@ import android.Manifest;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AuthenticatorDescription; import android.accounts.AuthenticatorDescription;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Process; import android.os.Process;
...@@ -298,13 +299,16 @@ public class AccountManagerHelper { ...@@ -298,13 +299,16 @@ public class AccountManagerHelper {
*/ */
public void getAuthToken(final Account account, final String authTokenType, public void getAuthToken(final Account account, final String authTokenType,
final GetAuthTokenCallback callback) { final GetAuthTokenCallback callback) {
ConnectionRetry.runAuthTask(new AuthTask<String>() { ConnectionRetry.runAuthTask(mApplicationContext, new AuthTask<String>() {
@Override
public String run() throws AuthException { public String run() throws AuthException {
return mAccountManager.getAuthToken(account, authTokenType); return mAccountManager.getAuthToken(account, authTokenType);
} }
@Override
public void onSuccess(String token) { public void onSuccess(String token) {
callback.tokenAvailable(token); callback.tokenAvailable(token);
} }
@Override
public void onFailure(boolean isTransientError) { public void onFailure(boolean isTransientError) {
callback.tokenUnavailable(isTransientError); callback.tokenUnavailable(isTransientError);
} }
...@@ -334,12 +338,15 @@ public class AccountManagerHelper { ...@@ -334,12 +338,15 @@ public class AccountManagerHelper {
if (authToken == null || authToken.isEmpty()) { if (authToken == null || authToken.isEmpty()) {
return; return;
} }
ConnectionRetry.runAuthTask(new AuthTask<Boolean>() { ConnectionRetry.runAuthTask(mApplicationContext, new AuthTask<Boolean>() {
@Override
public Boolean run() throws AuthException { public Boolean run() throws AuthException {
mAccountManager.invalidateAuthToken(authToken); mAccountManager.invalidateAuthToken(authToken);
return true; return true;
} }
@Override
public void onSuccess(Boolean result) {} public void onSuccess(Boolean result) {}
@Override
public void onFailure(boolean isTransientError) { public void onFailure(boolean isTransientError) {
Log.e(TAG, "Failed to invalidate auth token: " + authToken); Log.e(TAG, "Failed to invalidate auth token: " + authToken);
} }
...@@ -367,15 +374,17 @@ public class AccountManagerHelper { ...@@ -367,15 +374,17 @@ public class AccountManagerHelper {
implements NetworkChangeNotifier.ConnectionTypeObserver { implements NetworkChangeNotifier.ConnectionTypeObserver {
private static final int MAX_TRIES = 3; private static final int MAX_TRIES = 3;
private final Context mContext;
private final AuthTask<T> mAuthTask; private final AuthTask<T> mAuthTask;
private final AtomicInteger mNumTries; private final AtomicInteger mNumTries;
private final AtomicBoolean mIsTransientError; private final AtomicBoolean mIsTransientError;
public static <T> void runAuthTask(AuthTask<T> authTask) { public static <T> void runAuthTask(Context context, AuthTask<T> authTask) {
new ConnectionRetry<T>(authTask).attempt(); new ConnectionRetry<T>(context, authTask).attempt();
} }
private ConnectionRetry(AuthTask<T> authTask) { private ConnectionRetry(Context context, AuthTask<T> authTask) {
mContext = context;
mAuthTask = authTask; mAuthTask = authTask;
mNumTries = new AtomicInteger(0); mNumTries = new AtomicInteger(0);
mIsTransientError = new AtomicBoolean(false); mIsTransientError = new AtomicBoolean(false);
...@@ -394,9 +403,17 @@ public class AccountManagerHelper { ...@@ -394,9 +403,17 @@ public class AccountManagerHelper {
try { try {
return mAuthTask.run(); return mAuthTask.run();
} catch (AuthException ex) { } catch (AuthException ex) {
// TODO(547048): Handle the recovery intent if it is present. Log.w(TAG, "Failed to perform auth task", ex);
Log.e(TAG, "Failed to perform auth task", ex);
mIsTransientError.set(ex.isTransientError()); mIsTransientError.set(ex.isTransientError());
// TODO(547048): This will fire the intent indiscriminately. We should fix
// this in the future to fire only once per user actionable intent to avoid
// spamming the user.
if (ex.getRecoveryIntent() != null) {
Intent i = ex.getRecoveryIntent();
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(i);
}
} }
return null; return null;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment