import android.accounts.Account;
import android.accounts.AccountManager;
+import android.accounts.OperationCanceledException;
+import android.accounts.AccountManagerFuture;
+import android.accounts.AuthenticatorException;
+import android.accounts.AccountManagerCallback;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.widget.RelativeLayout;
import android.widget.TextView;
+import java.io.IOException;
+
/**
* When the user forgets their password a bunch of times, we fall back on their
* account's login/password to unlock the phone (and reset their lock pattern).
public void onClick(View v) {
mCallback.pokeWakelock();
if (v == mOk) {
- if (checkPassword()) {
- // clear out forgotten password
- mLockPatternUtils.setPermanentlyLocked(false);
-
- // launch the 'choose lock pattern' activity so
- // the user can pick a new one if they want to
- Intent intent = new Intent();
- intent.setClassName(LOCK_PATTERN_PACKAGE, LOCK_PATTERN_CLASS);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- mContext.startActivity(intent);
-
- // close the keyguard
- mCallback.keyguardDone(true);
- } else {
- mInstructions.setText(R.string.lockscreen_glogin_invalid_input);
- mPassword.setText("");
- }
+ asyncCheckPassword();
}
if (v == mEmergencyCall) {
}
}
+ private void onCheckPasswordResult(boolean flag) {
+ if (flag) {
+ // clear out forgotten password
+ mLockPatternUtils.setPermanentlyLocked(false);
+
+ // launch the 'choose lock pattern' activity so
+ // the user can pick a new one if they want to
+ Intent intent = new Intent();
+ intent.setClassName(LOCK_PATTERN_PACKAGE, LOCK_PATTERN_CLASS);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(intent);
+
+ // close the keyguard
+ mCallback.keyguardDone(true);
+ } else {
+ mInstructions.setText(R.string.lockscreen_glogin_invalid_input);
+ mPassword.setText("");
+ }
+ }
+
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
* find a single best match.
*/
private Account findIntendedAccount(String username) {
- Account[] accounts = AccountManager.get(mContext).blockingGetAccounts();
+ Account[] accounts = AccountManager.get(mContext).getAccounts();
// Try to figure out which account they meant if they
// typed only the username (and not the domain), or got
int bestScore = 0;
for (Account a: accounts) {
int score = 0;
- if (username.equals(a.mName)) {
+ if (username.equals(a.name)) {
score = 4;
- } else if (username.equalsIgnoreCase(a.mName)) {
+ } else if (username.equalsIgnoreCase(a.name)) {
score = 3;
} else if (username.indexOf('@') < 0) {
- int i = a.mName.indexOf('@');
+ int i = a.name.indexOf('@');
if (i >= 0) {
- String aUsername = a.mName.substring(0, i);
+ String aUsername = a.name.substring(0, i);
if (username.equals(aUsername)) {
score = 2;
} else if (username.equalsIgnoreCase(aUsername)) {
return bestAccount;
}
- private boolean checkPassword() {
+ private void asyncCheckPassword() {
final String login = mLogin.getText().toString();
final String password = mPassword.getText().toString();
Account account = findIntendedAccount(login);
if (account == null) {
- return false;
- }
- // TODO(fredq) change this to asynchronously issue the request and wait for the response (by
- // supplying a callback rather than calling get() immediately)
- try {
- return AccountManager.get(mContext).confirmPassword(
- account, password, null /* callback */, null /* handler */).getResult();
- } catch (android.accounts.OperationCanceledException e) {
- // the request was canceled
- return false;
+ onCheckPasswordResult(false);
+ return;
}
+ AccountManager.get(mContext).confirmPassword(
+ account, password, new AccountManagerCallback<Boolean>() {
+ public void run(AccountManagerFuture<Boolean> future) {
+ boolean result = false;
+ try {
+ result = future.getResult();
+ } catch (OperationCanceledException e) {
+ } catch (IOException e) {
+ } catch (AuthenticatorException e) {
+ }
+ onCheckPasswordResult(result);
+ }
+ }, null /* handler */);
}
}
KeyguardWindowController controller) {
super(context);
- final boolean hasAccount = AccountManager.get(context).blockingGetAccounts().length > 0;
+ final boolean hasAccount = AccountManager.get(context).getAccounts().length > 0;
boolean hasSAMLAccount = false;
if (hasAccount) {
/* If we have a SAML account which requires web login we can not use the
For now we will disable fallback screen in this case.
Ultimately we could consider bringing up a web login from GLS
but need to make sure that it will work in the "locked screen" mode. */
-
try {
+ String[] features = new String[] {"saml"};
hasSAMLAccount =
- AccountManager.get(context).blockingGetAccountsWithTypeAndFeatures(
- "com.GOOGLE.GAIA", new String[] {"saml"}).length > 0;
+ AccountManager.get(context).getAccountsByTypeAndFeatures(
+ "com.google.GAIA", features, null, null).getResult().length > 0;
} catch (Exception e) {
// We err on the side of caution.
// In case of error we assume we have a SAML account.