use of android.accounts.AccountManager in project Signal-Android by WhisperSystems.
the class DirectoryHelper method getOrCreateAccount.
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType("org.thoughtcrime.securesms");
Optional<AccountHolder> account;
if (accounts.length == 0)
account = createAccount(context);
else
account = Optional.of(new AccountHolder(accounts[0], false));
if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
}
return account;
}
use of android.accounts.AccountManager in project JamsMusicPlayer by psaravan.
the class GooglePlayMusicAuthenticationDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
parentActivity = getActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
sharedPreferences = parentActivity.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);
View rootView = parentActivity.getLayoutInflater().inflate(R.layout.dialog_google_authentication_layout, null);
//Check if this dialog was called from the Welcome sequence.
mFirstRun = getArguments().getBoolean(Common.FIRST_RUN);
infoText = (TextView) rootView.findViewById(R.id.google_authentication_dialog_text);
infoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light"));
infoText.setPaintFlags(infoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext());
final Account[] accounts = accountManager.getAccountsByType("com.google");
final int size = accounts.length;
String[] accountNames = new String[size];
for (int i = 0; i < size; i++) {
accountNames[i] = accounts[i].name;
}
//Set the dialog title.
builder.setTitle(R.string.sign_in_google_play_music);
builder.setCancelable(false);
builder.setItems(accountNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
account = accounts[which];
sharedPreferences.edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name).commit();
AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(parentActivity.getApplicationContext(), parentActivity, mFirstRun, account.name);
task.execute();
}
});
return builder.create();
}
use of android.accounts.AccountManager in project android by owncloud.
the class FileDownloader method onDestroy.
/**
* Service clean up
*/
@Override
public void onDestroy() {
Log_OC.v(TAG, "Destroying service");
mBinder = null;
mServiceHandler = null;
mServiceLooper.quit();
mServiceLooper = null;
mNotificationManager = null;
// remove AccountsUpdatedListener
AccountManager am = AccountManager.get(getApplicationContext());
am.removeOnAccountsUpdatedListener(this);
super.onDestroy();
}
use of android.accounts.AccountManager in project android by owncloud.
the class AccountUtils method updateAccountVersion.
/**
* Update the accounts in AccountManager to meet the current version of accounts expected by the app, if needed.
*
* Introduced to handle a change in the structure of stored account names needed to allow different OC servers
* in the same domain, but not in the same path.
*
* @param context Used to access the AccountManager.
*/
public static void updateAccountVersion(Context context) {
Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(context);
AccountManager accountMgr = AccountManager.get(context);
if (currentAccount != null) {
String currentAccountVersion = accountMgr.getUserData(currentAccount, Constants.KEY_OC_ACCOUNT_VERSION);
if (currentAccountVersion == null) {
Log_OC.i(TAG, "Upgrading accounts to account version #" + ACCOUNT_VERSION);
Account[] ocAccounts = accountMgr.getAccountsByType(MainApp.getAccountType());
String serverUrl, username, newAccountName, password;
Account newAccount;
for (Account account : ocAccounts) {
// build new account name
serverUrl = accountMgr.getUserData(account, Constants.KEY_OC_BASE_URL);
username = com.owncloud.android.lib.common.accounts.AccountUtils.getUsernameForAccount(account);
newAccountName = com.owncloud.android.lib.common.accounts.AccountUtils.buildAccountName(Uri.parse(serverUrl), username);
// migrate to a new account, if needed
if (!newAccountName.equals(account.name)) {
Log_OC.d(TAG, "Upgrading " + account.name + " to " + newAccountName);
// create the new account
newAccount = new Account(newAccountName, MainApp.getAccountType());
password = accountMgr.getPassword(account);
accountMgr.addAccountExplicitly(newAccount, (password != null) ? password : "", null);
// copy base URL
accountMgr.setUserData(newAccount, Constants.KEY_OC_BASE_URL, serverUrl);
// copy server version
accountMgr.setUserData(newAccount, Constants.KEY_OC_VERSION, accountMgr.getUserData(account, Constants.KEY_OC_VERSION));
// copy cookies
accountMgr.setUserData(newAccount, Constants.KEY_COOKIES, accountMgr.getUserData(account, Constants.KEY_COOKIES));
// copy type of authentication
String isSamlStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO);
boolean isSaml = "TRUE".equals(isSamlStr);
if (isSaml) {
accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");
}
String isOauthStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2);
boolean isOAuth = "TRUE".equals(isOauthStr);
if (isOAuth) {
accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE");
}
// don't forget the account saved in preferences as the current one
if (currentAccount.name.equals(account.name)) {
AccountUtils.setCurrentOwnCloudAccount(context, newAccountName);
}
// remove the old account
accountMgr.removeAccount(account, null, null);
// will assume it succeeds, not a big deal otherwise
} else {
// servers which base URL is in the root of their domain need no change
Log_OC.d(TAG, account.name + " needs no upgrade ");
newAccount = account;
}
// at least, upgrade account version
Log_OC.d(TAG, "Setting version " + ACCOUNT_VERSION + " to " + newAccountName);
accountMgr.setUserData(newAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION));
}
}
}
}
use of android.accounts.AccountManager in project android by owncloud.
the class AccountUtils method getServerVersion.
/**
* Access the version of the OC server corresponding to an account SAVED IN THE ACCOUNTMANAGER
*
* @param account ownCloud account
* @return Version of the OC server corresponding to account, according to the data saved
* in the system AccountManager
*/
public static OwnCloudVersion getServerVersion(Account account) {
OwnCloudVersion serverVersion = null;
if (account != null) {
AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());
String serverVersionStr = accountMgr.getUserData(account, Constants.KEY_OC_VERSION);
if (serverVersionStr != null) {
serverVersion = new OwnCloudVersion(serverVersionStr);
}
}
return serverVersion;
}
Aggregations