add support for testing testFeatures()
This commit is contained in:
@@ -22,6 +22,9 @@
|
|||||||
<item android:id="@+id/accounts_tester_get_auth_token"
|
<item android:id="@+id/accounts_tester_get_auth_token"
|
||||||
android:title="@string/accounts_tester_get_auth_token" />
|
android:title="@string/accounts_tester_get_auth_token" />
|
||||||
|
|
||||||
|
<item android:id="@+id/accounts_tester_test_has_features"
|
||||||
|
android:title="@string/accounts_tester_test_has_features" />
|
||||||
|
|
||||||
<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" />
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,8 @@
|
|||||||
<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</string>
|
||||||
<string name="accounts_tester_get_auth_token">authenticate</string>
|
<string name="accounts_tester_get_auth_token">get authtoken</string>
|
||||||
|
<string name="accounts_tester_test_has_features">test 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>
|
||||||
|
|||||||
@@ -46,8 +46,11 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
private static final int GET_AUTH_TOKEN_DIALOG_ID = 1;
|
private static final int GET_AUTH_TOKEN_DIALOG_ID = 1;
|
||||||
private static final int UPDATE_CREDENTIALS_DIALOG_ID = 2;
|
private static final int UPDATE_CREDENTIALS_DIALOG_ID = 2;
|
||||||
private static final int INVALIDATE_AUTH_TOKEN_DIALOG_ID = 3;
|
private static final int INVALIDATE_AUTH_TOKEN_DIALOG_ID = 3;
|
||||||
|
private static final int TEST_HAS_FEATURES_DIALOG_ID = 4;
|
||||||
|
private static final int MESSAGE_DIALOG_ID = 5;
|
||||||
private EditText mDesiredAuthTokenTypeEditText;
|
private EditText mDesiredAuthTokenTypeEditText;
|
||||||
private EditText mDesiredFeaturesEditText;
|
private EditText mDesiredFeaturesEditText;
|
||||||
|
private volatile CharSequence mDialogMessage;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -268,6 +271,8 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
}, null /* handler */);
|
}, null /* handler */);
|
||||||
} 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) {
|
||||||
|
showDialog(TEST_HAS_FEATURES_DIALOG_ID);
|
||||||
} else if (item.getItemId() == R.id.accounts_tester_invalidate_auth_token) {
|
} else if (item.getItemId() == R.id.accounts_tester_invalidate_auth_token) {
|
||||||
showDialog(INVALIDATE_AUTH_TOKEN_DIALOG_ID);
|
showDialog(INVALIDATE_AUTH_TOKEN_DIALOG_ID);
|
||||||
} else if (item.getItemId() == R.id.accounts_tester_update_credentials) {
|
} else if (item.getItemId() == R.id.accounts_tester_update_credentials) {
|
||||||
@@ -282,7 +287,7 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog(final int id) {
|
protected Dialog onCreateDialog(final int id) {
|
||||||
if (id == GET_AUTH_TOKEN_DIALOG_ID || id == INVALIDATE_AUTH_TOKEN_DIALOG_ID
|
if (id == GET_AUTH_TOKEN_DIALOG_ID || id == INVALIDATE_AUTH_TOKEN_DIALOG_ID
|
||||||
|| id == UPDATE_CREDENTIALS_DIALOG_ID) {
|
|| id == UPDATE_CREDENTIALS_DIALOG_ID || id == TEST_HAS_FEATURES_DIALOG_ID) {
|
||||||
final View view = LayoutInflater.from(this).inflate(R.layout.get_auth_token_view, null);
|
final View view = LayoutInflater.from(this).inflate(R.layout.get_auth_token_view, null);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setPositiveButton(R.string.accounts_tester_do_get_auth_token,
|
builder.setPositiveButton(R.string.accounts_tester_do_get_auth_token,
|
||||||
@@ -316,6 +321,10 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
} 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(), null);
|
||||||
|
} else if (id == TEST_HAS_FEATURES_DIALOG_ID) {
|
||||||
|
String[] features = TextUtils.split(authTokenType, ",");
|
||||||
|
mAccountManager.testHasFeatures(account, features,
|
||||||
|
new TestHasFeaturesCallback(), null);
|
||||||
} else {
|
} else {
|
||||||
mAccountManager.updateCredentials(
|
mAccountManager.updateCredentials(
|
||||||
account,
|
account,
|
||||||
@@ -327,6 +336,11 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
builder.setView(view);
|
builder.setView(view);
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
if (id == MESSAGE_DIALOG_ID) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
builder.setMessage(mDialogMessage);
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
return super.onCreateDialog(id);
|
return super.onCreateDialog(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,6 +427,31 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showMessageDialog(String message) {
|
||||||
|
mDialogMessage = message;
|
||||||
|
removeDialog(MESSAGE_DIALOG_ID);
|
||||||
|
showDialog(MESSAGE_DIALOG_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestHasFeaturesCallback implements AccountManagerCallback<Boolean> {
|
||||||
|
public void run(AccountManagerFuture<Boolean> future) {
|
||||||
|
try {
|
||||||
|
Boolean hasFeatures = future.getResult();
|
||||||
|
Log.d(TAG, "hasFeatures: " + hasFeatures);
|
||||||
|
showMessageDialog("hasFeatures: " + hasFeatures);
|
||||||
|
} catch (OperationCanceledException e) {
|
||||||
|
Log.d(TAG, "interrupted");
|
||||||
|
showMessageDialog("operation was canceled");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d(TAG, "error", e);
|
||||||
|
showMessageDialog("operation got an IOException");
|
||||||
|
} catch (AuthenticatorException e) {
|
||||||
|
Log.d(TAG, "error", e);
|
||||||
|
showMessageDialog("operation got an AuthenticationException");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class ConfirmCredentialsCallback implements AccountManagerCallback<Bundle> {
|
private static class ConfirmCredentialsCallback implements AccountManagerCallback<Bundle> {
|
||||||
public void run(AccountManagerFuture<Bundle> future) {
|
public void run(AccountManagerFuture<Bundle> future) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user