diff options
| author | Patrick Scott <phanna@android.com> | 2011-01-13 11:27:38 -0500 |
|---|---|---|
| committer | Patrick Scott <phanna@android.com> | 2011-01-13 13:23:18 -0500 |
| commit | 539e2eced0f35144d7841477e5cdc2d8c521e82a (patch) | |
| tree | 057cf38e40ac61c9378d39798cb1bfc649a2bde0 /src/com/android/browser/UrlHandler.java | |
| parent | 840e81a85044d7a5dc1f9ead35cfaf862457597e (diff) | |
| download | packages_apps_Browser-539e2eced0f35144d7841477e5cdc2d8c521e82a.tar.gz packages_apps_Browser-539e2eced0f35144d7841477e5cdc2d8c521e82a.tar.bz2 packages_apps_Browser-539e2eced0f35144d7841477e5cdc2d8c521e82a.zip | |
Different approach to auto signin.
On startup, attempt to log the user into google sites. Show a progress dialog
that the user can cancel if login takes too long.
Add a new preference for toggling auto signin. This preference shows the
current account and allows the user to choose the account to use. If there are
no accounts, the option is disabled. The saved account is validated each time
it is accessed in case the account was removed.
Bug: 3278072
Change-Id: I10ce1dc57a683b2820b17ef6955577037c82f332
Diffstat (limited to 'src/com/android/browser/UrlHandler.java')
| -rw-r--r-- | src/com/android/browser/UrlHandler.java | 181 |
1 files changed, 0 insertions, 181 deletions
diff --git a/src/com/android/browser/UrlHandler.java b/src/com/android/browser/UrlHandler.java index f39ac4b6b..9e41990be 100644 --- a/src/com/android/browser/UrlHandler.java +++ b/src/com/android/browser/UrlHandler.java @@ -16,29 +16,12 @@ package com.android.browser; -import org.apache.http.Header; -import org.apache.http.HeaderIterator; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.util.EntityUtils; - -import android.accounts.Account; -import android.accounts.AccountManager; -import android.accounts.AccountManagerCallback; -import android.accounts.AccountManagerFuture; import android.app.Activity; -import android.app.AlertDialog; import android.content.ActivityNotFoundException; -import android.content.DialogInterface; -import android.content.DialogInterface.OnCancelListener; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; -import android.net.http.AndroidHttpClient; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; @@ -125,14 +108,6 @@ public class UrlHandler { } } - // Check for service login and prompt the user for an account to use. - if (url.startsWith("https://www.google.com/accounts/ServiceLogin?") || - url.startsWith("https://www.google.com/accounts/Login?")) { - if (loginWithDeviceAccount(view, url)) { - return true; - } - } - if (startActivityForUrl(url)) { return true; } @@ -209,162 +184,6 @@ public class UrlHandler { return false; } - // Url for issuing the uber token. - private final static Uri ISSUE_AUTH_TOKEN_URL = Uri.parse( - "https://www.google.com/accounts/IssueAuthToken?service=gaia&Session=false"); - // Url for signing into a particular service. - private final static Uri TOKEN_AUTH_URL = Uri.parse( - "https://www.google.com/accounts/TokenAuth"); - - private class GoogleServiceLogin extends Thread implements - AccountManagerCallback<Bundle>, OnClickListener, OnCancelListener { - // For choosing the account. - private final Account[] mAccounts; - private int mCurrentAccount; // initially 0 for the first account - - // For loading the auth token urls or the original url on error. - private final WebView mWebView; - private final String mUrl; - - // SID and LSID retrieval process. - private String mSid; - private String mLsid; - private int mState; // {NONE(0), SID(1), LSID(2)} - - GoogleServiceLogin(Account[] accounts, WebView view, String url) { - mAccounts = accounts; - mWebView = view; - mUrl = url; - } - - // Thread - public void run() { - String url = ISSUE_AUTH_TOKEN_URL.buildUpon() - .appendQueryParameter("SID", mSid) - .appendQueryParameter("LSID", mLsid) - .build().toString(); - // Intentionally not using Proxy. - AndroidHttpClient client = AndroidHttpClient.newInstance( - mWebView.getSettings().getUserAgentString()); - HttpPost request = new HttpPost(url); - - String result = null; - try { - HttpResponse response = client.execute(request); - if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { - onCancel(null); - return; - } - HttpEntity entity = response.getEntity(); - if (entity == null) { - onCancel(null); - return; - } - result = EntityUtils.toString(entity, "UTF-8"); - } catch (Exception e) { - request.abort(); - onCancel(null); - } finally { - client.close(); - } - Uri parsedUri = Uri.parse(mUrl); - String service = parsedUri.getQueryParameter("service"); - String redirect = parsedUri.getQueryParameter("continue"); - final String newUrl = TOKEN_AUTH_URL.buildUpon() - .appendQueryParameter("service", service) - .appendQueryParameter("source", "android-browser") - .appendQueryParameter("auth", result) - .appendQueryParameter("continue", redirect) - .build().toString(); - mActivity.runOnUiThread(new Runnable() { - @Override public void run() { - mController.loadUrl(mWebView, newUrl); - } - }); - } - - // AccountManager callbacks. - public void run(AccountManagerFuture<Bundle> value) { - try { - String id = value.getResult().getString( - AccountManager.KEY_AUTHTOKEN); - switch (mState) { - default: - case 0: - throw new IllegalStateException( - "Impossible to get into this state"); - case 1: - mSid = id; - mState = 2; // LSID - AccountManager.get(mActivity).getAuthToken( - mAccounts[mCurrentAccount], "LSID", null, - mActivity, this, null); - break; - case 2: - mLsid = id; - this.start(); - break; - } - } catch (Exception e) { - // For all exceptions load the original signin page. - // TODO: toast login failed? - onCancel(null); - } - } - - // Handle picking an account and "OK." - public void onClick(DialogInterface unused, int which) { - if (which == DialogInterface.BUTTON_POSITIVE) { - // TODO: toast loading...? - Account current = mAccounts[mCurrentAccount]; - mState = 1; // SID - AccountManager.get(mActivity).getAuthToken( - mAccounts[mCurrentAccount], "SID", null, - mActivity, this, null); - } else if (which == DialogInterface.BUTTON_NEGATIVE) { - onCancel(null); - } else { - mCurrentAccount = which; - } - } - - // Handle "cancel." - public void onCancel(DialogInterface unusued) { - // load the original url to login manually. - mController.loadUrl(mWebView, mUrl); - } - } - - private boolean loginWithDeviceAccount(WebView view, String url) { - Uri parsedUri = Uri.parse(url); - if ("true".equals(parsedUri.getQueryParameter("go"))) { - return false; - } - Account[] accounts = - AccountManager.get(mActivity).getAccountsByType("com.google"); - if (accounts.length == 0) { - return false; - } - - // Populate the account list. - CharSequence[] names = new CharSequence[accounts.length]; - int i = 0; - for (Account a : accounts) { - names[i++] = a.name; - } - - GoogleServiceLogin login = new GoogleServiceLogin(accounts, view, url); - new AlertDialog.Builder(mActivity) - .setTitle(R.string.account_picker_title) - .setSingleChoiceItems(names, 0 /* first choice */, login) - .setPositiveButton(R.string.ok, login) - .setNegativeButton(R.string.cancel, login) - .setCancelable(true) - .setOnCancelListener(login) - .show(); - return true; - } - private class RLZTask extends AsyncTask<Void, Void, String> { private Tab mTab; private Uri mSiteUri; |
