Search in sources :

Example 41 with AccountManager

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);
}
Also used : Context(android.content.Context) AccountManager(android.accounts.AccountManager) ImportAccount(com.nextcloud.talk.models.ImportAccount)

Example 42 with AccountManager

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);
}
Also used : Context(android.content.Context) Account(android.accounts.Account) Drawable(android.graphics.drawable.Drawable) UserInfo(android.content.pm.UserInfo) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) AuthenticatorDescription(android.accounts.AuthenticatorDescription) PackageManager(android.content.pm.PackageManager) LayoutInflater(android.view.LayoutInflater) UserHandle(android.os.UserHandle) AccountManager(android.accounts.AccountManager) TextView(android.widget.TextView) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 43 with AccountManager

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);
    }
}
Also used : Account(android.accounts.Account) ViewGroup(android.view.ViewGroup) AccountManager(android.accounts.AccountManager) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) SuppressLint(android.annotation.SuppressLint)

Example 44 with AccountManager

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;
}
Also used : Bundle(android.os.Bundle) AccountManager(android.accounts.AccountManager)

Example 45 with AccountManager

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);
    }
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) DataHolder(com.google.android.gms.common.data.DataHolder) AccountMetadata(com.google.android.gms.people.model.AccountMetadata) AccountManager(android.accounts.AccountManager) RemoteException(android.os.RemoteException)

Aggregations

AccountManager (android.accounts.AccountManager)180 Account (android.accounts.Account)121 Bundle (android.os.Bundle)28 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)16 View (android.view.View)16 TextView (android.widget.TextView)16 Context (android.content.Context)15 IOException (java.io.IOException)14 UserAccountManager (com.nextcloud.client.account.UserAccountManager)13 OperationCanceledException (android.accounts.OperationCanceledException)11 ImageView (android.widget.ImageView)9 AuthenticatorDescription (android.accounts.AuthenticatorDescription)8 UserHandle (android.os.UserHandle)8 LayoutInflater (android.view.LayoutInflater)8 AuthenticatorException (android.accounts.AuthenticatorException)7 UserInfo (android.content.pm.UserInfo)7 Resources (android.content.res.Resources)7 Drawable (android.graphics.drawable.Drawable)7 LinearLayout (android.widget.LinearLayout)7