use of android.accounts.AccountManager in project talk-android by nextcloud.
the class AccountUtils method getInformationFromAccount.
public static ImportAccount getInformationFromAccount(Account account) {
int lastAtPos = account.name.lastIndexOf("@");
String urlString = account.name.substring(lastAtPos + 1);
String username = account.name.substring(0, lastAtPos);
Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext();
final AccountManager accMgr = AccountManager.get(context);
String password = accMgr.getPassword(account);
if (urlString.endsWith("/")) {
urlString = urlString.substring(0, urlString.length() - 1);
}
return new ImportAccount(username, password, urlString);
}
use of android.accounts.AccountManager in project android_packages_apps_Settings by DirtyUnicorns.
the class MasterClear method loadAccountList.
private void loadAccountList(final UserManager um) {
View accountsLabel = mContentView.findViewById(R.id.accounts_label);
LinearLayout contents = (LinearLayout) mContentView.findViewById(R.id.accounts);
contents.removeAllViews();
Context context = getActivity();
final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId());
final int profilesSize = profiles.size();
AccountManager mgr = AccountManager.get(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int accountsCount = 0;
for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) {
final UserInfo userInfo = profiles.get(profileIndex);
final int profileId = userInfo.id;
final UserHandle userHandle = new UserHandle(profileId);
Account[] accounts = mgr.getAccountsAsUser(profileId);
final int N = accounts.length;
if (N == 0) {
continue;
}
accountsCount += N;
AuthenticatorDescription[] descs = AccountManager.get(context).getAuthenticatorTypesAsUser(profileId);
final int M = descs.length;
if (profilesSize > 1) {
View titleView = Utils.inflateCategoryHeader(inflater, contents);
final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
titleText.setText(userInfo.isManagedProfile() ? R.string.category_work : R.string.category_personal);
contents.addView(titleView);
}
for (int i = 0; i < N; i++) {
Account account = accounts[i];
AuthenticatorDescription desc = null;
for (int j = 0; j < M; j++) {
if (account.type.equals(descs[j].type)) {
desc = descs[j];
break;
}
}
if (desc == null) {
Log.w(TAG, "No descriptor for account name=" + account.name + " type=" + account.type);
continue;
}
Drawable icon = null;
try {
if (desc.iconId != 0) {
Context authContext = context.createPackageContextAsUser(desc.packageName, 0, userHandle);
icon = context.getPackageManager().getUserBadgedIcon(authContext.getDrawable(desc.iconId), userHandle);
}
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Bad package name for account type " + desc.type);
} catch (Resources.NotFoundException e) {
Log.w(TAG, "Invalid icon id for account type " + desc.type, e);
}
if (icon == null) {
icon = context.getPackageManager().getDefaultActivityIcon();
}
View child = inflater.inflate(R.layout.master_clear_account, contents, false);
((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon);
((TextView) child.findViewById(android.R.id.title)).setText(account.name);
contents.addView(child);
}
}
if (accountsCount > 0) {
accountsLabel.setVisibility(View.VISIBLE);
contents.setVisibility(View.VISIBLE);
}
// Checking for all other users and their profiles if any.
View otherUsers = mContentView.findViewById(R.id.other_users_present);
final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0;
otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE);
}
use of android.accounts.AccountManager in project android_packages_apps_GmsCore by microg.
the class LoginActivity method onCreate.
@SuppressLint("AddJavascriptInterface")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
accountType = AuthConstants.DEFAULT_ACCOUNT_TYPE;
accountManager = AccountManager.get(LoginActivity.this);
inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
webView = createWebView(this);
webView.addJavascriptInterface(new JsBridge(), "mm");
authContent = (ViewGroup) findViewById(R.id.auth_content);
((ViewGroup) findViewById(R.id.auth_root)).addView(webView);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
Log.d(TAG, "pageFinished: " + url);
if ("identifier".equals(Uri.parse(url).getFragment()))
runOnUiThread(new Runnable() {
@Override
public void run() {
webView.setVisibility(VISIBLE);
}
});
if ("close".equals(Uri.parse(url).getFragment()))
closeWeb(false);
if (url.startsWith(PROGRAMMATIC_AUTH_URL))
closeWeb(true);
}
});
if (getIntent().hasExtra(EXTRA_TOKEN)) {
if (getIntent().hasExtra(EXTRA_EMAIL)) {
AccountManager accountManager = AccountManager.get(LoginActivity.this);
Account account = new Account(getIntent().getStringExtra(EXTRA_EMAIL), accountType);
accountManager.addAccountExplicitly(account, getIntent().getStringExtra(EXTRA_TOKEN), null);
retrieveGmsToken(account);
} else {
retrieveRtToken(getIntent().getStringExtra(EXTRA_TOKEN));
}
} else {
setMessage(R.string.auth_before_connect);
setBackButtonText(android.R.string.cancel);
setNextButtonText(R.string.auth_sign_in);
}
}
use of android.accounts.AccountManager in project android_packages_apps_GmsCore by microg.
the class AccountAuthenticator method hasFeatures.
@Override
public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException {
Log.d(TAG, "hasFeatures: " + account + ", " + Arrays.toString(features));
AccountManager accountManager = AccountManager.get(context);
String services = accountManager.getUserData(account, "services");
boolean res = true;
if (services != null) {
List<String> servicesList = Arrays.asList(services.split(","));
for (String feature : features) {
if (feature.startsWith("service_") && !servicesList.contains(feature.substring(8)))
res = false;
}
} else {
res = false;
}
Bundle result = new Bundle();
result.putBoolean(KEY_BOOLEAN_RESULT, res);
return result;
}
use of android.accounts.AccountManager in project android_packages_apps_GmsCore by microg.
the class PeopleServiceImpl method loadOwners.
@SuppressWarnings("MissingPermission")
@Override
public void loadOwners(final IPeopleCallbacks callbacks, boolean var2, boolean var3, final String accountName, String var5, int sortOrder) {
Log.d(TAG, "loadOwners: " + var2 + ", " + var3 + ", " + accountName + ", " + var5 + ", " + sortOrder);
PackageUtils.assertExtendedAccess(context);
AccountManager accountManager = AccountManager.get(context);
Bundle accountMetadata = new Bundle();
String accountType = AuthConstants.DEFAULT_ACCOUNT_TYPE;
for (Account account : accountManager.getAccountsByType(accountType)) {
if (accountName == null || account.name.equals(accountName)) {
accountMetadata.putParcelable(account.name, new AccountMetadata());
}
}
Bundle extras = new Bundle();
extras.putBundle("account_metadata", accountMetadata);
try {
DatabaseHelper databaseHelper = new DatabaseHelper(context);
DataHolder dataHolder = new DataHolder(databaseHelper.getOwners(), 0, extras);
Log.d(TAG, "loadOwners[result]: " + dataHolder);
callbacks.onDataHolder(0, extras, dataHolder);
databaseHelper.close();
} catch (Exception e) {
Log.w(TAG, e);
}
}
Aggregations