forked from upstream-mirrors/OpenTracks
Attempt at working around Samsung bug which crashes the account manager service - the auth token call now synchronously calls
This commit is contained in:
@@ -97,41 +97,32 @@ public class ModernAuthManager implements AuthManager {
|
|||||||
// Keep the account in case we need to retry.
|
// Keep the account in case we need to retry.
|
||||||
this.lastAccount = account;
|
this.lastAccount = account;
|
||||||
|
|
||||||
accountManager.getAuthToken(account, service, true,
|
// NOTE: Many Samsung phones have a crashing bug in
|
||||||
|
// AccountManager#getAuthToken(Account, String, boolean, AccountManagerCallback<Bundle>)
|
||||||
|
// so we use the other version of the method.
|
||||||
|
// More details here:
|
||||||
|
// http://forum.xda-developers.com/showthread.php?p=15155487
|
||||||
|
// http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/accounts/AccountManagerService.java
|
||||||
|
accountManager.getAuthToken(account, service, null, activity,
|
||||||
new AccountManagerCallback<Bundle>() {
|
new AccountManagerCallback<Bundle>() {
|
||||||
public void run(AccountManagerFuture<Bundle> future) {
|
public void run(AccountManagerFuture<Bundle> future) {
|
||||||
try {
|
try {
|
||||||
Bundle result = future.getResult();
|
authToken = future.getResult().getString(
|
||||||
|
|
||||||
// AccountManager needs user to grant permission
|
|
||||||
if (result.containsKey(AccountManager.KEY_INTENT)) {
|
|
||||||
Intent intent = (Intent) result.get(AccountManager.KEY_INTENT);
|
|
||||||
clearNewTaskFlag(intent);
|
|
||||||
activity.startActivityForResult(intent, Constants.GET_LOGIN);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
authToken = result.getString(
|
|
||||||
AccountManager.KEY_AUTHTOKEN);
|
AccountManager.KEY_AUTHTOKEN);
|
||||||
Log.i(Constants.TAG, "Got auth token.");
|
Log.i(Constants.TAG, "Got auth token");
|
||||||
runAuthCallback();
|
|
||||||
} catch (OperationCanceledException e) {
|
} catch (OperationCanceledException e) {
|
||||||
Log.e(Constants.TAG, "Operation Canceled", e);
|
Log.e(Constants.TAG, "Auth token operation Canceled", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "IOException", e);
|
Log.e(Constants.TAG, "Auth token IO exception", e);
|
||||||
} catch (AuthenticatorException e) {
|
} catch (AuthenticatorException e) {
|
||||||
Log.e(Constants.TAG, "Authentication Failed", e);
|
Log.e(Constants.TAG, "Authentication Failed", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runAuthCallback();
|
||||||
}
|
}
|
||||||
}, null /* handler */);
|
}, null /* handler */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void clearNewTaskFlag(Intent intent) {
|
|
||||||
int flags = intent.getFlags();
|
|
||||||
flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
|
|
||||||
intent.setFlags(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Activity} passed into the constructor should call this
|
* The {@link Activity} passed into the constructor should call this
|
||||||
* function when it gets {@link Activity#onActivityResult} with the request
|
* function when it gets {@link Activity#onActivityResult} with the request
|
||||||
|
|||||||
Reference in New Issue
Block a user