use of android.accounts.AccountManagerCallback in project XPrivacy by M66B.
the class XAccountManager method before.
@Override
@SuppressWarnings("unchecked")
protected void before(XParam param) throws Throwable {
switch(mMethod) {
case addOnAccountsUpdatedListener:
if (param.args.length > 0 && param.args[0] != null)
if (isRestricted(param)) {
int uid = Binder.getCallingUid();
OnAccountsUpdateListener listener = (OnAccountsUpdateListener) param.args[0];
XOnAccountsUpdateListener xListener;
synchronized (mListener) {
xListener = mListener.get(listener);
if (xListener == null) {
xListener = new XOnAccountsUpdateListener(listener, uid);
mListener.put(listener, xListener);
Util.log(this, Log.WARN, "Added count=" + mListener.size() + " uid=" + uid);
}
}
param.args[0] = xListener;
}
break;
case blockingGetAuthToken:
case getAccounts:
case getAccountsByType:
case getAccountsByTypeForPackage:
// Do nothing
break;
case getAccountsByTypeAndFeatures:
if (param.args.length > 2 && param.args[2] != null)
if (isRestrictedExtra(param, (String) param.args[0])) {
AccountManagerCallback<Account[]> callback = (AccountManagerCallback<Account[]>) param.args[2];
param.args[2] = new XAccountManagerCallbackAccount(callback, Binder.getCallingUid());
}
break;
case getAuthenticatorTypes:
// Do nothing
break;
case getAuthToken:
if (param.args.length > 0) {
Account account = (Account) param.args[0];
for (int i = 1; i < param.args.length; i++) if (param.args[i] instanceof AccountManagerCallback<?>)
if (isRestrictedExtra(param, account == null ? null : account.name)) {
AccountManagerCallback<Bundle> callback = (AccountManagerCallback<Bundle>) param.args[i];
param.args[i] = new XAccountManagerCallbackBundle(callback, Binder.getCallingUid());
}
}
break;
case getAuthTokenByFeatures:
if (param.args.length > 0)
for (int i = 1; i < param.args.length; i++) if (param.args[i] instanceof AccountManagerCallback<?>)
if (isRestrictedExtra(param, (String) param.args[0])) {
AccountManagerCallback<Bundle> callback = (AccountManagerCallback<Bundle>) param.args[i];
param.args[i] = new XAccountManagerCallbackBundle(callback, Binder.getCallingUid());
}
break;
case hasFeatures:
if (param.args.length > 0) {
Account account = (Account) param.args[0];
for (int i = 1; i < param.args.length; i++) if (param.args[i] instanceof AccountManagerCallback<?>)
if (isRestrictedExtra(param, account == null ? null : account.name)) {
AccountManagerCallback<Boolean> callback = (AccountManagerCallback<Boolean>) param.args[i];
param.args[i] = new XAccountManagerCallbackBoolean(callback);
}
}
break;
case removeOnAccountsUpdatedListener:
if (param.args.length > 0 && param.args[0] != null)
synchronized (mListener) {
OnAccountsUpdateListener listener = (OnAccountsUpdateListener) param.args[0];
XOnAccountsUpdateListener xListener = mListener.get(listener);
if (xListener != null) {
param.args[0] = xListener;
Util.log(this, Log.WARN, "Removed count=" + mListener.size() + " uid=" + Binder.getCallingUid());
}
}
break;
case Srv_getAccounts:
case Srv_getAccountsAsUser:
case Srv_getAccountsForPackage:
// Do nothing
break;
case Srv_getAccountsByFeatures:
if (param.args.length > 1 && (param.args[1] == null || param.args[1] instanceof String)) {
if (isRestrictedExtra(param, (String) param.args[1]))
param.setResult(null);
} else {
if (isRestricted(param))
param.setResult(null);
}
break;
case Srv_getSharedAccountsAsUser:
// Do nothing
break;
}
}
use of android.accounts.AccountManagerCallback in project android-delicious by lexs.
the class ContainerActivity method logout.
private void logout() {
Log.d(TAG, "Removing account");
AccountManager accountManager = AccountManager.get(this);
Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
Account account = accounts[0];
// Callback to wait for the account to actually be removed
AccountManagerCallback<Boolean> callback = new AccountManagerCallback<Boolean>() {
@Override
public void run(AccountManagerFuture<Boolean> future) {
try {
if (future.getResult()) {
checkAccount();
} else {
// Could not remove account, should not happen
Log.e(TAG, "Could not remove account");
}
} catch (Exception e) {
Log.e(TAG, "Error fetching remove account result", e);
}
}
};
accountManager.removeAccount(account, callback, null);
}
use of android.accounts.AccountManagerCallback in project android by owncloud.
the class RemoveAccountDialogFragment method onConfirmation.
/**
* Performs the removal of the target account.
*/
@Override
public void onConfirmation(String callerTag) {
Activity parentActivity = getActivity();
AccountManager am = AccountManager.get(parentActivity);
AccountManagerCallback<Boolean> callback = (AccountManagerCallback<Boolean>) parentActivity;
am.removeAccount(mTargetAccount, callback, new Handler());
}
use of android.accounts.AccountManagerCallback in project newsrob by marianokamp.
the class AccountManagementUtilsImplementation method getAuthToken.
public void getAuthToken(final Activity waitingActivity, Handler handler, final IAuthenticationCallback callback, String googleAccount) {
PL.log("AMU.getAuthToken for " + googleAccount + ".", waitingActivity);
AccountManager accountManager = AccountManager.get(waitingActivity);
// find the selected account
Account selectedAccount = findAccountByGoogleAccountId(waitingActivity, accountManager, googleAccount);
if (selectedAccount == null)
throw new RuntimeException("No account found for " + googleAccount + ".");
final Account selAccount = selectedAccount;
if (false)
accountManager.getAuthTokenByFeatures(GOOGLE_ACCOUNT_TYPE, "reader", GOOGLE_ACCOUNT, waitingActivity, new Bundle(), null, new AccountManagerCallback<Bundle>() {
public void run(android.accounts.AccountManagerFuture<Bundle> f) {
try {
Bundle b = f.getResult();
for (String key : b.keySet()) System.out.println("key " + key + " value " + b.getByte(key));
String authToken = f.getResult().getString(AccountManager.KEY_AUTHTOKEN);
if (authToken == null)
throw new RuntimeException("AuthToken was null.");
callback.onAuthTokenReceived(selAccount.name, authToken);
} catch (Exception e) {
e.printStackTrace();
if (e instanceof OperationCanceledException)
e = new Exception("Operation canceled by user.");
callback.onError(e);
}
}
}, handler);
if (true)
accountManager.getAuthToken(selectedAccount, AUTH_TOKEN_TYPE_READER, null, waitingActivity, new AccountManagerCallback<Bundle>() {
public void run(android.accounts.AccountManagerFuture<Bundle> f) {
try {
String authToken = f.getResult().getString(AccountManager.KEY_AUTHTOKEN);
if (authToken == null)
throw new RuntimeException("AuthToken was null.");
PL.log("AMU.getAuthToken for " + selAccount.name + "received token=" + authToken.substring(0, 4) + "(2).", waitingActivity);
callback.onAuthTokenReceived(selAccount.name, authToken);
} catch (Exception e) {
e.printStackTrace();
if (e instanceof OperationCanceledException)
e = new Exception("Operation canceled by user.");
callback.onError(e);
}
}
}, handler);
}
Aggregations