Make sure google auth token is valid before using it

pull/14/head
Sam Bosley 12 years ago
parent c3117d08bf
commit 4bde104157

@ -54,6 +54,9 @@ public class ActFmGoogleAuthActivity extends ListActivity {
private String authToken;
private String accountName;
private boolean onSuccess = false;
private boolean dismissDialog = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -96,7 +99,7 @@ public class ActFmGoogleAuthActivity extends ListActivity {
}
}
private void getAuthToken(Account a, final ProgressDialog pd) {
private void getAuthToken(final Account a, final ProgressDialog pd) {
AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() {
public void run(final AccountManagerFuture<Bundle> future) {
new Thread() {
@ -106,7 +109,16 @@ public class ActFmGoogleAuthActivity extends ListActivity {
Bundle bundle = future.getResult(30, TimeUnit.SECONDS);
if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
if (!onSuccess) {
accountManager.manager.invalidateAuthToken(AUTH_TOKEN_TYPE, authToken);
getAuthToken(a, pd);
onSuccess = true;
} else {
onAuthTokenSuccess();
dismissDialog = true;
}
} else {
dismissDialog = true;
}
} catch (final Exception e) {
Log.e("actfm-google-auth", "Login Error", e); //$NON-NLS-1$ //$NON-NLS-2$
@ -121,6 +133,7 @@ public class ActFmGoogleAuthActivity extends ListActivity {
}
});
} finally {
if (dismissDialog)
DialogUtilities.dismissDialog(ActFmGoogleAuthActivity.this, pd);
}
}

@ -43,6 +43,10 @@ public class WelcomeWalkthrough extends ActFmLoginActivity {
private View currentView;
private int currentPage;
private String authToken;
private boolean onSuccess = false;
private boolean dismissDialog = false;
public static final String KEY_SHOWED_WELCOME_LOGIN = "key_showed_welcome_login"; //$NON-NLS-1$
public static final String TOKEN_MANUAL_SHOW = "manual"; //$NON-NLS-1$
@ -111,8 +115,13 @@ public class WelcomeWalkthrough extends ActFmLoginActivity {
StatisticsService.reportEvent(StatisticsConstants.ACTFM_LOGIN_SIMPLE);
final ProgressDialog pd = DialogUtilities.progressDialog(WelcomeWalkthrough.this, getString(R.string.gtasks_GLA_authenticating));
pd.show();
GoogleAccountManager accountManager = new GoogleAccountManager(WelcomeWalkthrough.this);
Account a = accountManager.getAccountByName(email);
getAuthToken(email, pd);
}
private void getAuthToken(final String e,
final ProgressDialog pd) {
final GoogleAccountManager accountManager = new GoogleAccountManager(WelcomeWalkthrough.this);
Account a = accountManager.getAccountByName(e);
AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() {
public void run(final AccountManagerFuture<Bundle> future) {
new Thread() {
@ -121,8 +130,17 @@ public class WelcomeWalkthrough extends ActFmLoginActivity {
try {
Bundle bundle = future.getResult(30, TimeUnit.SECONDS);
if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
onAuthTokenSuccess(email, authToken);
authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
if (!onSuccess) {
accountManager.manager.invalidateAuthToken(ActFmGoogleAuthActivity.AUTH_TOKEN_TYPE, authToken);
getAuthToken(e, pd);
onSuccess = true;
} else {
onAuthTokenSuccess(e, authToken);
dismissDialog = true;
}
} else {
dismissDialog = true;
}
} catch (final Exception e) {
Log.e("actfm-google-auth", "Login Error", e); //$NON-NLS-1$ //$NON-NLS-2$
@ -138,6 +156,7 @@ public class WelcomeWalkthrough extends ActFmLoginActivity {
}
});
} finally {
if (dismissDialog)
DialogUtilities.dismissDialog(WelcomeWalkthrough.this, pd);
}
}

Loading…
Cancel
Save