use of android.accounts.OnAccountsUpdateListener 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.OnAccountsUpdateListener in project android by owncloud.
the class MediaService method onCreate.
/**
* Initialize a service instance
*
* {@inheritDoc}
*/
@Override
public void onCreate() {
super.onCreate();
Log_OC.d(TAG, "Creating ownCloud media service");
mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, MEDIA_WIFI_LOCK_TAG);
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationBuilder = new NotificationCompat.Builder(this);
mNotificationBuilder.setColor(this.getResources().getColor(R.color.primary));
mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
mBinder = new MediaServiceBinder(this);
// add AccountsUpdatedListener
mAccountManager = AccountManager.get(this);
mAccountManager.addOnAccountsUpdatedListener(new OnAccountsUpdateListener() {
@Override
public void onAccountsUpdated(Account[] accounts) {
// stop playback if account of the played media files was removed
if (mAccount != null && !AccountUtils.exists(mAccount, MediaService.this)) {
processStopRequest(false);
}
}
}, null, false);
}
Aggregations