Fix account id retrieval for registered G+ accounts

The bug can cause Chrome/Chromium to cause an endless loop (=> high CPU usage, reduced battery time). Please remove and re-add your account...
This commit is contained in:
mar-v-in 2016-01-02 12:05:26 +01:00
parent 9624bb7185
commit 8df631cd95
2 changed files with 9 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
@ -247,6 +248,8 @@ public class LoginActivity extends AssistantActivity {
accountManager.setUserData(account, "oauthAccessToken", "1");
accountManager.setUserData(account, "firstName", response.firstName);
accountManager.setUserData(account, "lastName", response.lastName);
if (!TextUtils.isEmpty(response.accountId))
accountManager.setUserData(account, "GoogleUserId", response.accountId);
retrieveGmsToken(account);
setResult(RESULT_OK);
@ -282,7 +285,9 @@ public class LoginActivity extends AssistantActivity {
@Override
public void onResponse(AuthResponse response) {
authManager.storeResponse(response);
PeopleManager.loadUserInfo(LoginActivity.this, account);
String accountId = PeopleManager.loadUserInfo(LoginActivity.this, account);
if (!TextUtils.isEmpty(accountId))
accountManager.setUserData(account, "GoogleUserId", accountId);
checkin(true);
finish();
}

View File

@ -84,7 +84,7 @@ public class PeopleManager {
return BitmapFactory.decodeFile(avaterFile.getPath());
}
public static void loadUserInfo(Context context, Account account) {
public static String loadUserInfo(Context context, Account account) {
try {
URLConnection conn = new URL(USERINFO_URL).openConnection();
conn.addRequestProperty("Authorization", "Bearer " + getUserInfoAuthKey(context, account));
@ -104,8 +104,10 @@ public class PeopleManager {
DatabaseHelper databaseHelper = new DatabaseHelper(context);
databaseHelper.putOwner(contentValues);
databaseHelper.close();
return contentValues.getAsString("gaia_id");
} catch (Exception e) {
Log.w(TAG, e);
return null;
}
}