- change the accounts list to include the account type
- removed the list of account types from the top - changed the context menu to use the actual account type, not the one selected in the spinner - add the clear password option to the context menu Change-Id: Icd509ed3f3da889f48b064cf524345e0121899fc
This commit is contained in:
@@ -77,7 +77,8 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="AccountsTester" android:label="AccountsTester"
|
<activity android:name="AccountsTester" android:label="AccountsTester"
|
||||||
android:theme="@android:style/Theme.Light">
|
android:theme="@android:style/Theme.Light"
|
||||||
|
android:windowSoftInputMode="stateHidden">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.TEST" />
|
<category android:name="android.intent.category.TEST" />
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
<item android:id="@+id/accounts_tester_test_has_features"
|
<item android:id="@+id/accounts_tester_test_has_features"
|
||||||
android:title="@string/accounts_tester_test_has_features" />
|
android:title="@string/accounts_tester_test_has_features" />
|
||||||
|
|
||||||
|
<item android:id="@+id/accounts_tester_clear_password"
|
||||||
|
android:title="@string/accounts_tester_clear_password" />
|
||||||
|
|
||||||
<item android:id="@+id/accounts_tester_invalidate_auth_token"
|
<item android:id="@+id/accounts_tester_invalidate_auth_token"
|
||||||
android:title="@string/accounts_tester_invalidate_auth_token" />
|
android:title="@string/accounts_tester_invalidate_auth_token" />
|
||||||
|
|
||||||
|
|||||||
@@ -27,13 +27,13 @@
|
|||||||
android:paddingLeft="9dip"
|
android:paddingLeft="9dip"
|
||||||
android:paddingRight="9dip">
|
android:paddingRight="9dip">
|
||||||
|
|
||||||
<ImageView android:id="@+id/accounts_tester_authenticator_icon"
|
<ImageView android:id="@+id/accounts_tester_account_type_icon"
|
||||||
android:paddingRight="9dip"
|
android:paddingRight="9dip"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<TextView android:id="@+id/accounts_tester_authenticator_label"
|
<TextView android:id="@+id/accounts_tester_account_name"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
@@ -25,9 +25,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<ListView android:id="@+id/accounts_tester_authenticators_list"
|
|
||||||
android:layout_width="match_parent" android:layout_height="match_parent"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -161,15 +161,16 @@
|
|||||||
<string name="accounts_tester_add_account">Add</string>
|
<string name="accounts_tester_add_account">Add</string>
|
||||||
<string name="accounts_tester_select_account_type">Select Account Type</string>
|
<string name="accounts_tester_select_account_type">Select Account Type</string>
|
||||||
<string name="accounts_tester_process_name_header">Process Name:</string>
|
<string name="accounts_tester_process_name_header">Process Name:</string>
|
||||||
<string name="accounts_tester_remove_account">remove</string>
|
<string name="accounts_tester_remove_account">Remove Account</string>
|
||||||
<string name="accounts_tester_get_auth_token">get authtoken</string>
|
<string name="accounts_tester_get_auth_token">Get Auth Token</string>
|
||||||
<string name="accounts_tester_test_has_features">test has features</string>
|
<string name="accounts_tester_test_has_features">Has Features</string>
|
||||||
<string name="accounts_tester_invalidate_auth_token">invalidate token</string>
|
<string name="accounts_tester_invalidate_auth_token">Invalidate Token</string>
|
||||||
<string name="accounts_tester_account_context_menu_title">account operations</string>
|
<string name="accounts_tester_account_context_menu_title">account operations</string>
|
||||||
<string name="accounts_tester_do_get_auth_token">Ok</string>
|
<string name="accounts_tester_do_get_auth_token">Ok</string>
|
||||||
<string name="accounts_tester_enter_auth_token_type">Enter the authtoken type:</string>
|
<string name="accounts_tester_enter_auth_token_type">Enter the authtoken type:</string>
|
||||||
<string name="accounts_tester_update_credentials">Update Credentials</string>
|
<string name="accounts_tester_update_credentials">Update Credentials</string>
|
||||||
<string name="accounts_tester_confirm_credentials">Confirm Credentials</string>
|
<string name="accounts_tester_confirm_credentials">Confirm Credentials</string>
|
||||||
|
<string name="accounts_tester_clear_password">Clear Password</string>
|
||||||
<string name="accounts_tester_edit_properties">Properties</string>
|
<string name="accounts_tester_edit_properties">Properties</string>
|
||||||
<string name="accounts_tester_desired_authtokentype_label">authtoken type:</string>
|
<string name="accounts_tester_desired_authtokentype_label">authtoken type:</string>
|
||||||
<string name="accounts_tester_desired_features_label">features:</string>
|
<string name="accounts_tester_desired_features_label">features:</string>
|
||||||
|
|||||||
@@ -37,10 +37,8 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
private static final String TAG = "AccountsTester";
|
private static final String TAG = "AccountsTester";
|
||||||
private Spinner mAccountTypesSpinner;
|
private Spinner mAccountTypesSpinner;
|
||||||
private ListView mAccountsListView;
|
private ListView mAccountsListView;
|
||||||
private ListView mAuthenticatorsListView;
|
|
||||||
private AccountManager mAccountManager;
|
private AccountManager mAccountManager;
|
||||||
private String mLongPressedAccount = null;
|
private Account mLongPressedAccount = null;
|
||||||
private static final String COM_GOOGLE = "com.google";
|
|
||||||
private AuthenticatorDescription[] mAuthenticatorDescs;
|
private AuthenticatorDescription[] mAuthenticatorDescs;
|
||||||
|
|
||||||
private static final int GET_AUTH_TOKEN_DIALOG_ID = 1;
|
private static final int GET_AUTH_TOKEN_DIALOG_ID = 1;
|
||||||
@@ -61,9 +59,8 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
|
|
||||||
mAccountTypesSpinner = (Spinner) findViewById(R.id.accounts_tester_account_types_spinner);
|
mAccountTypesSpinner = (Spinner) findViewById(R.id.accounts_tester_account_types_spinner);
|
||||||
mAccountsListView = (ListView) findViewById(R.id.accounts_tester_accounts_list);
|
mAccountsListView = (ListView) findViewById(R.id.accounts_tester_accounts_list);
|
||||||
mAuthenticatorsListView = (ListView) findViewById(R.id.accounts_tester_authenticators_list);
|
|
||||||
registerForContextMenu(mAccountsListView);
|
registerForContextMenu(mAccountsListView);
|
||||||
getAuthenticatorTypes();
|
initializeAuthenticatorsSpinner();
|
||||||
findViewById(R.id.accounts_tester_get_all_accounts).setOnClickListener(buttonClickListener);
|
findViewById(R.id.accounts_tester_get_all_accounts).setOnClickListener(buttonClickListener);
|
||||||
findViewById(R.id.accounts_tester_get_accounts_by_type).setOnClickListener(
|
findViewById(R.id.accounts_tester_get_accounts_by_type).setOnClickListener(
|
||||||
buttonClickListener);
|
buttonClickListener);
|
||||||
@@ -74,18 +71,18 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
mDesiredFeaturesEditText = (EditText) findViewById(R.id.accounts_tester_desired_features);
|
mDesiredFeaturesEditText = (EditText) findViewById(R.id.accounts_tester_desired_features);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AuthenticatorsArrayAdapter extends ArrayAdapter<AuthenticatorDescription> {
|
private class AccountArrayAdapter extends ArrayAdapter<Account> {
|
||||||
protected LayoutInflater mInflater;
|
protected LayoutInflater mInflater;
|
||||||
private static final int mResource = R.layout.authenticators_list_item;
|
|
||||||
|
|
||||||
public AuthenticatorsArrayAdapter(Context context, AuthenticatorDescription[] items) {
|
public AccountArrayAdapter(Context context, Account[] accounts) {
|
||||||
super(context, mResource, items);
|
super(context, R.layout.account_list_item, accounts);
|
||||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ViewHolder {
|
class ViewHolder {
|
||||||
TextView label;
|
TextView name;
|
||||||
ImageView icon;
|
ImageView icon;
|
||||||
|
Account account;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -98,15 +95,15 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
// to reinflate it. We only inflate a new View when the convertView supplied
|
// to reinflate it. We only inflate a new View when the convertView supplied
|
||||||
// by ListView is null.
|
// by ListView is null.
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = mInflater.inflate(R.layout.authenticators_list_item, null);
|
convertView = mInflater.inflate(R.layout.account_list_item, null);
|
||||||
|
|
||||||
// Creates a ViewHolder and store references to the two children views
|
// Creates a ViewHolder and store references to the two children views
|
||||||
// we want to bind data to.
|
// we want to bind data to.
|
||||||
holder = new ViewHolder();
|
holder = new ViewHolder();
|
||||||
holder.label = (TextView) convertView.findViewById(
|
holder.name = (TextView) convertView.findViewById(
|
||||||
R.id.accounts_tester_authenticator_label);
|
R.id.accounts_tester_account_name);
|
||||||
holder.icon = (ImageView) convertView.findViewById(
|
holder.icon = (ImageView) convertView.findViewById(
|
||||||
R.id.accounts_tester_authenticator_icon);
|
R.id.accounts_tester_account_type_icon);
|
||||||
|
|
||||||
convertView.setTag(holder);
|
convertView.setTag(holder);
|
||||||
} else {
|
} else {
|
||||||
@@ -115,25 +112,29 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
holder = (ViewHolder) convertView.getTag();
|
holder = (ViewHolder) convertView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
final AuthenticatorDescription desc = getItem(position);
|
final Account account = getItem(position);
|
||||||
final String packageName = desc.packageName;
|
holder.account = account;
|
||||||
try {
|
holder.icon.setVisibility(View.INVISIBLE);
|
||||||
final Context authContext = getContext().createPackageContext(packageName, 0);
|
for (AuthenticatorDescription desc : mAuthenticatorDescs) {
|
||||||
|
if (desc.type.equals(account.type)) {
|
||||||
// Set text field
|
final String packageName = desc.packageName;
|
||||||
holder.label.setText(authContext.getString(desc.labelId));
|
try {
|
||||||
|
final Context authContext = getContext().createPackageContext(packageName, 0);
|
||||||
// Set resource icon
|
holder.icon.setImageDrawable(authContext.getResources().getDrawable(desc.iconId));
|
||||||
holder.icon.setImageDrawable(authContext.getResources().getDrawable(desc.iconId));
|
holder.icon.setVisibility(View.VISIBLE);
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
Log.d(TAG, "error getting the Package Context for " + packageName, e);
|
Log.d(TAG, "error getting the Package Context for " + packageName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set text field
|
||||||
|
holder.name.setText(account.name);
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAuthenticatorTypes() {
|
private void initializeAuthenticatorsSpinner() {
|
||||||
mAuthenticatorDescs = mAccountManager.getAuthenticatorTypes();
|
mAuthenticatorDescs = mAccountManager.getAuthenticatorTypes();
|
||||||
String[] names = new String[mAuthenticatorDescs.length];
|
String[] names = new String[mAuthenticatorDescs.length];
|
||||||
for (int i = 0; i < mAuthenticatorDescs.length; i++) {
|
for (int i = 0; i < mAuthenticatorDescs.length; i++) {
|
||||||
@@ -150,21 +151,11 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
new ArrayAdapter<String>(AccountsTester.this,
|
new ArrayAdapter<String>(AccountsTester.this,
|
||||||
android.R.layout.simple_spinner_item, names);
|
android.R.layout.simple_spinner_item, names);
|
||||||
mAccountTypesSpinner.setAdapter(adapter);
|
mAccountTypesSpinner.setAdapter(adapter);
|
||||||
|
|
||||||
mAuthenticatorsListView.setAdapter(new AuthenticatorsArrayAdapter(
|
|
||||||
AccountsTester.this, mAuthenticatorDescs));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAccountsUpdated(Account[] accounts) {
|
public void onAccountsUpdated(Account[] accounts) {
|
||||||
Log.d(TAG, "onAccountsUpdated: \n " + TextUtils.join("\n ", accounts));
|
Log.d(TAG, "onAccountsUpdated: \n " + TextUtils.join("\n ", accounts));
|
||||||
String[] accountNames = new String[accounts.length];
|
mAccountsListView.setAdapter(new AccountArrayAdapter(this, accounts));
|
||||||
for (int i = 0; i < accounts.length; i++) {
|
|
||||||
accountNames[i] = accounts[i].name;
|
|
||||||
}
|
|
||||||
ArrayAdapter<String> adapter =
|
|
||||||
new ArrayAdapter<String>(AccountsTester.this,
|
|
||||||
android.R.layout.simple_list_item_1, accountNames);
|
|
||||||
mAccountsListView.setAdapter(adapter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
@@ -187,21 +178,6 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
String type = getSelectedAuthenticator().type;
|
String type = getSelectedAuthenticator().type;
|
||||||
onAccountsUpdated(mAccountManager.getAccountsByType(type));
|
onAccountsUpdated(mAccountManager.getAccountsByType(type));
|
||||||
} else if (R.id.accounts_tester_add_account == v.getId()) {
|
} else if (R.id.accounts_tester_add_account == v.getId()) {
|
||||||
AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() {
|
|
||||||
public void run(AccountManagerFuture<Bundle> future) {
|
|
||||||
try {
|
|
||||||
Bundle bundle = future.getResult();
|
|
||||||
bundle.keySet();
|
|
||||||
Log.d(TAG, "account added: " + bundle);
|
|
||||||
} catch (OperationCanceledException e) {
|
|
||||||
Log.d(TAG, "addAccount was canceled");
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d(TAG, "addAccount failed: " + e);
|
|
||||||
} catch (AuthenticatorException e) {
|
|
||||||
Log.d(TAG, "addAccount failed: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
String authTokenType = mDesiredAuthTokenTypeEditText.getText().toString();
|
String authTokenType = mDesiredAuthTokenTypeEditText.getText().toString();
|
||||||
if (TextUtils.isEmpty(authTokenType)) {
|
if (TextUtils.isEmpty(authTokenType)) {
|
||||||
authTokenType = null;
|
authTokenType = null;
|
||||||
@@ -213,30 +189,18 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
}
|
}
|
||||||
mAccountManager.addAccount(getSelectedAuthenticator().type,
|
mAccountManager.addAccount(getSelectedAuthenticator().type,
|
||||||
authTokenType, requiredFeatures, null /* options */,
|
authTokenType, requiredFeatures, null /* options */,
|
||||||
AccountsTester.this, callback, null /* handler */);
|
AccountsTester.this,
|
||||||
|
new CallbackToDialog(AccountsTester.this, "add account"),
|
||||||
|
null /* handler */);
|
||||||
} else if (R.id.accounts_tester_edit_properties == v.getId()) {
|
} else if (R.id.accounts_tester_edit_properties == v.getId()) {
|
||||||
mAccountManager.editProperties(getSelectedAuthenticator().type,
|
mAccountManager.editProperties(getSelectedAuthenticator().type,
|
||||||
AccountsTester.this, new EditPropertiesCallback(), null /* handler */);
|
AccountsTester.this,
|
||||||
|
new CallbackToDialog(AccountsTester.this, "edit properties"),
|
||||||
|
null /* handler */);
|
||||||
} else {
|
} else {
|
||||||
// unknown button
|
// unknown button
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EditPropertiesCallback implements AccountManagerCallback<Bundle> {
|
|
||||||
public void run(AccountManagerFuture<Bundle> future) {
|
|
||||||
try {
|
|
||||||
Bundle bundle = future.getResult();
|
|
||||||
bundle.keySet();
|
|
||||||
Log.d(TAG, "editProperties succeeded: " + bundle);
|
|
||||||
} catch (OperationCanceledException e) {
|
|
||||||
Log.d(TAG, "editProperties was canceled");
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d(TAG, "editProperties failed: ", e);
|
|
||||||
} catch (AuthenticatorException e) {
|
|
||||||
Log.d(TAG, "editProperties failed: ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuthenticatorDescription getSelectedAuthenticator() {
|
private AuthenticatorDescription getSelectedAuthenticator() {
|
||||||
@@ -252,13 +216,15 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
|
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.layout.account_list_context_menu, menu);
|
inflater.inflate(R.layout.account_list_context_menu, menu);
|
||||||
mLongPressedAccount = ((TextView)info.targetView).getText().toString();
|
AccountArrayAdapter.ViewHolder holder =
|
||||||
|
(AccountArrayAdapter.ViewHolder)info.targetView.getTag();
|
||||||
|
mLongPressedAccount = holder.account;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.accounts_tester_remove_account) {
|
if (item.getItemId() == R.id.accounts_tester_remove_account) {
|
||||||
final Account account = new Account(mLongPressedAccount, COM_GOOGLE);
|
final Account account = mLongPressedAccount;
|
||||||
mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() {
|
mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() {
|
||||||
public void run(AccountManagerFuture<Boolean> future) {
|
public void run(AccountManagerFuture<Boolean> future) {
|
||||||
try {
|
try {
|
||||||
@@ -269,6 +235,10 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, null /* handler */);
|
}, null /* handler */);
|
||||||
|
} else if (item.getItemId() == R.id.accounts_tester_clear_password) {
|
||||||
|
final Account account = mLongPressedAccount;
|
||||||
|
mAccountManager.clearPassword(account);
|
||||||
|
showMessageDialog("cleared");
|
||||||
} else if (item.getItemId() == R.id.accounts_tester_get_auth_token) {
|
} else if (item.getItemId() == R.id.accounts_tester_get_auth_token) {
|
||||||
showDialog(GET_AUTH_TOKEN_DIALOG_ID);
|
showDialog(GET_AUTH_TOKEN_DIALOG_ID);
|
||||||
} else if (item.getItemId() == R.id.accounts_tester_test_has_features) {
|
} else if (item.getItemId() == R.id.accounts_tester_test_has_features) {
|
||||||
@@ -278,8 +248,9 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
} else if (item.getItemId() == R.id.accounts_tester_update_credentials) {
|
} else if (item.getItemId() == R.id.accounts_tester_update_credentials) {
|
||||||
showDialog(UPDATE_CREDENTIALS_DIALOG_ID);
|
showDialog(UPDATE_CREDENTIALS_DIALOG_ID);
|
||||||
} else if (item.getItemId() == R.id.accounts_tester_confirm_credentials) {
|
} else if (item.getItemId() == R.id.accounts_tester_confirm_credentials) {
|
||||||
mAccountManager.confirmCredentials(new Account(mLongPressedAccount, COM_GOOGLE), null,
|
mAccountManager.confirmCredentials(mLongPressedAccount, null,
|
||||||
AccountsTester.this, new ConfirmCredentialsCallback(), null /* handler */);
|
AccountsTester.this, new CallbackToDialog(this, "confirm credentials"),
|
||||||
|
null /* handler */);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -297,30 +268,15 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
R.id.accounts_tester_auth_token_type);
|
R.id.accounts_tester_auth_token_type);
|
||||||
|
|
||||||
String authTokenType = value.getText().toString();
|
String authTokenType = value.getText().toString();
|
||||||
AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() {
|
final Account account = mLongPressedAccount;
|
||||||
public void run(AccountManagerFuture<Bundle> future) {
|
|
||||||
try {
|
|
||||||
Bundle bundle = future.getResult();
|
|
||||||
bundle.keySet();
|
|
||||||
Log.d(TAG, "dialog " + id + " success: " + bundle);
|
|
||||||
} catch (OperationCanceledException e) {
|
|
||||||
Log.d(TAG, "dialog " + id + " canceled");
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d(TAG, "dialog " + id + " failed: " + e);
|
|
||||||
} catch (AuthenticatorException e) {
|
|
||||||
Log.d(TAG, "dialog " + id + " failed: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
final Account account = new Account(mLongPressedAccount,
|
|
||||||
COM_GOOGLE);
|
|
||||||
if (id == GET_AUTH_TOKEN_DIALOG_ID) {
|
if (id == GET_AUTH_TOKEN_DIALOG_ID) {
|
||||||
mAccountManager.getAuthToken(account, authTokenType,
|
mAccountManager.getAuthToken(account, authTokenType,
|
||||||
null /* loginOptions */, AccountsTester.this,
|
null /* loginOptions */, AccountsTester.this,
|
||||||
callback, null /* handler */);
|
new CallbackToDialog(AccountsTester.this, "get auth token"),
|
||||||
|
null /* handler */);
|
||||||
} else if (id == INVALIDATE_AUTH_TOKEN_DIALOG_ID) {
|
} else if (id == INVALIDATE_AUTH_TOKEN_DIALOG_ID) {
|
||||||
mAccountManager.getAuthToken(account, authTokenType, false,
|
mAccountManager.getAuthToken(account, authTokenType, false,
|
||||||
new GetAndInvalidateAuthTokenCallback(), null);
|
new GetAndInvalidateAuthTokenCallback(account), null);
|
||||||
} else if (id == TEST_HAS_FEATURES_DIALOG_ID) {
|
} else if (id == TEST_HAS_FEATURES_DIALOG_ID) {
|
||||||
String[] features = TextUtils.split(authTokenType, ",");
|
String[] features = TextUtils.split(authTokenType, ",");
|
||||||
mAccountManager.hasFeatures(account, features,
|
mAccountManager.hasFeatures(account, features,
|
||||||
@@ -329,7 +285,9 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
mAccountManager.updateCredentials(
|
mAccountManager.updateCredentials(
|
||||||
account,
|
account,
|
||||||
authTokenType, null /* loginOptions */,
|
authTokenType, null /* loginOptions */,
|
||||||
AccountsTester.this, callback, null /* handler */);
|
AccountsTester.this,
|
||||||
|
new CallbackToDialog(AccountsTester.this, "update"),
|
||||||
|
null /* handler */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -397,32 +355,22 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
Log.d(TAG, "GetAuthTokenCallback: type " + mAccountType
|
Log.d(TAG, "GetAuthTokenCallback: type " + mAccountType
|
||||||
+ ", features "
|
+ ", features "
|
||||||
+ (mFeatures == null ? "none" : TextUtils.join(",", mFeatures)));
|
+ (mFeatures == null ? "none" : TextUtils.join(",", mFeatures)));
|
||||||
try {
|
getAndLogResult(future, "get auth token");
|
||||||
Bundle result = future.getResult();
|
|
||||||
result.keySet();
|
|
||||||
Log.d(TAG, " result: " + result);
|
|
||||||
} catch (OperationCanceledException e) {
|
|
||||||
Log.d(TAG, "failure", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d(TAG, "failure", e);
|
|
||||||
} catch (AuthenticatorException e) {
|
|
||||||
Log.d(TAG, "failure", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class GetAndInvalidateAuthTokenCallback implements AccountManagerCallback<Bundle> {
|
private class GetAndInvalidateAuthTokenCallback implements AccountManagerCallback<Bundle> {
|
||||||
|
private final Account mAccount;
|
||||||
|
|
||||||
|
private GetAndInvalidateAuthTokenCallback(Account account) {
|
||||||
|
mAccount = account;
|
||||||
|
}
|
||||||
|
|
||||||
public void run(AccountManagerFuture<Bundle> future) {
|
public void run(AccountManagerFuture<Bundle> future) {
|
||||||
try {
|
Bundle result = getAndLogResult(future, "get and invalidate");
|
||||||
Bundle bundle = future.getResult();
|
if (result != null) {
|
||||||
String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
|
String authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
|
||||||
mAccountManager.invalidateAuthToken(COM_GOOGLE, authToken);
|
mAccountManager.invalidateAuthToken(mAccount.type, authToken);
|
||||||
} catch (OperationCanceledException e) {
|
|
||||||
Log.d(TAG, "invalidate: interrupted while getting authToken");
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d(TAG, "invalidate: error getting authToken", e);
|
|
||||||
} catch (AuthenticatorException e) {
|
|
||||||
Log.d(TAG, "invalidate: error getting authToken", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -452,19 +400,48 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ConfirmCredentialsCallback implements AccountManagerCallback<Bundle> {
|
private static class CallbackToDialog implements AccountManagerCallback<Bundle> {
|
||||||
|
private final AccountsTester mActivity;
|
||||||
|
private final String mLabel;
|
||||||
|
|
||||||
|
private CallbackToDialog(AccountsTester activity, String label) {
|
||||||
|
mActivity = activity;
|
||||||
|
mLabel = label;
|
||||||
|
}
|
||||||
|
|
||||||
public void run(AccountManagerFuture<Bundle> future) {
|
public void run(AccountManagerFuture<Bundle> future) {
|
||||||
try {
|
mActivity.getAndLogResult(future, mLabel);
|
||||||
Bundle bundle = future.getResult();
|
}
|
||||||
bundle.keySet();
|
}
|
||||||
Log.d(TAG, "confirmCredentials success: " + bundle);
|
|
||||||
} catch (OperationCanceledException e) {
|
private Bundle getAndLogResult(AccountManagerFuture<Bundle> future, String label) {
|
||||||
Log.d(TAG, "confirmCredentials canceled");
|
try {
|
||||||
} catch (AuthenticatorException e) {
|
Bundle result = future.getResult();
|
||||||
Log.d(TAG, "confirmCredentials failed: " + e);
|
result.keySet();
|
||||||
} catch (IOException e) {
|
Log.d(TAG, label + ": " + result);
|
||||||
Log.d(TAG, "confirmCredentials failed: " + e);
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append(label).append(" result:");
|
||||||
|
for (String key : result.keySet()) {
|
||||||
|
Object value = result.get(key);
|
||||||
|
if (AccountManager.KEY_AUTHTOKEN.equals(key)) {
|
||||||
|
value = "<redacted>";
|
||||||
|
}
|
||||||
|
sb.append("\n ").append(key).append(" -> ").append(value);
|
||||||
}
|
}
|
||||||
|
showMessageDialog(sb.toString());
|
||||||
|
return result;
|
||||||
|
} catch (OperationCanceledException e) {
|
||||||
|
Log.d(TAG, label + " failed", e);
|
||||||
|
showMessageDialog(label + " was canceled");
|
||||||
|
return null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d(TAG, label + " failed", e);
|
||||||
|
showMessageDialog(label + " failed with IOException: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
} catch (AuthenticatorException e) {
|
||||||
|
Log.d(TAG, label + " failed", e);
|
||||||
|
showMessageDialog(label + " failed with an AuthenticatorException: " + e.getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user