gt:                 account = new Account(accountName, accountType);
context: /*
   *       ____.____  __.____ ___     _____
   *      |    |    |/ _|    |   \   /  _  \ ______ ______
   *      |    |      < |    |   /  /  /_\  \\____ \\____ \
   *  /\__|    |    |  \|    |  /  /    |    \  |_> >  |_> >
   *  \________|____|__ \______/   \____|__  /   __/|   __/
   *                   \/                  \/|__|   |__|
   *
   *  Copyright (c) 2014-2020 Paul "Marunjar" Pretsch
   *
   *  This program is free software: you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation, either version 3 of the License, or
   *  (at your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program.  If not, see <http://www.gnu.org/licenses/>
   *
   */
  
  package org.voidsink.anewjkuapp.activity;
  
  import android.Manifest;
  import android.accounts.Account;
  import android.accounts.AccountManager;
  import android.app.ProgressDialog;
  import android.content.ContentResolver;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.os.AsyncTask;
  import android.os.Build;
  import android.os.Bundle;
  import android.provider.CalendarContract;
  import android.text.TextUtils;
  import android.view.MenuItem;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import androidx.annotation.NonNull;
  import androidx.annotation.Nullable;
  import androidx.appcompat.app.ActionBar;
  import androidx.appcompat.app.AlertDialog;
  import androidx.appcompat.widget.Toolbar;
  import androidx.core.content.ContextCompat;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.voidsink.anewjkuapp.KusssAuthenticator;
  import org.voidsink.anewjkuapp.KusssContentContract;
  import org.voidsink.anewjkuapp.PreferenceHelper;
  import org.voidsink.anewjkuapp.R;
  import org.voidsink.anewjkuapp.analytics.AnalyticsHelper;
  import org.voidsink.anewjkuapp.calendar.CalendarUtils;
  import org.voidsink.anewjkuapp.kusss.KusssHandler;
  import org.voidsink.anewjkuapp.utils.AppUtils;
  import org.voidsink.anewjkuapp.utils.Consts;
  import org.voidsink.anewjkuapp.utils.UIUtils;
  import org.voidsink.anewjkuapp.workaround.AccountAuthenticatorActivity;
  
  import java.lang.ref.WeakReference;
  
  public class KusssAuthenticatorActivity extends AccountAuthenticatorActivity {
  
      private static final String KEY_ERROR_MESSAGE = "ERR_MSG";
      private final static String PARAM_USER_PASS = "USER_PASS";
  
      private static final Logger logger = LoggerFactory.getLogger(KusssAuthenticatorActivity.class);
  
      private AccountManager mAccountManager;
      private String mAuthTokenType;
      private Button mSubmit;
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.activity_login);
  
          Toolbar toolbar = findViewById(R.id.main_toolbar);
          setSupportActionBar(toolbar);
  
          initActionBar();
  
          mAccountManager = AccountManager.get(this);
  
          Intent mIntent = getIntent();
  
          String accountName = null;
  
          boolean mIsNewAccount = false;
          Account mAccount = AppUtils.getAccount(this);
          if (mAccount != null) {
              accountName = mAccount.name;
  
              if (mIntent != null) {
                  mIntent.removeExtra(Consts.ARG_IS_ADDING_NEW_ACCOUNT);
                  mIntent.putExtra(Consts.ARG_ACCOUNT_NAME,
                          mAccount.name);
                  mIntent.putExtra(Consts.ARG_ACCOUNT_TYPE,
                          mAccount.type);
              }
          } else if (mIntent != null) {
              accountName = getIntent().getStringExtra(
                      Consts.ARG_ACCOUNT_NAME);
              mIsNewAccount = mIntent.getBooleanExtra(
                      Consts.ARG_IS_ADDING_NEW_ACCOUNT, false);
              if (!mIntent.hasExtra(Consts.ARG_ACCOUNT_TYPE)) {
                  mIntent.putExtra(Consts.ARG_ACCOUNT_TYPE,
                          KusssAuthenticator.ACCOUNT_TYPE);
              }
          }
  
          if (mAuthTokenType == null) {
              mAuthTokenType = KusssAuthenticator.AUTHTOKEN_TYPE_READ_ONLY;
          }
  
          if (!mIsNewAccount && accountName != null) {
              final TextView tvAccountName = findViewById(R.id.accountName);
              if (tvAccountName != null) {
                  tvAccountName.setText(accountName);
                  tvAccountName.setEnabled(false);
              }
          }
  
          mSubmit = findViewById(R.id.accountLogin);
          mSubmit.setOnClickListener(v -> {
              if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.M) && (ContextCompat.checkSelfPermission(KusssAuthenticatorActivity.this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED)) {
                  new AlertDialog.Builder(KusssAuthenticatorActivity.this)
                          .setMessage(R.string.alert_permission_get_accounts)
                          .setPositiveButton(R.string.button_ok, null)
                          .setCancelable(false)
                          .show();
              } else {
                  submit();
              }
          });
      }
  
      private void initActionBar() {
          ActionBar actionBar = getSupportActionBar();
          if (actionBar != null) {
              actionBar.setDisplayHomeAsUpEnabled(true);
          }
      }
  
      private void submit() {
          getSubmit().setEnabled(false);
  
          final String userName = ((TextView) findViewById(R.id.accountName))
                  .getText().toString();
          final String userPass = ((TextView) findViewById(R.id.accountPassword))
                  .getText().toString();
  
          final String accountType = getIntent().getStringExtra(
                  Consts.ARG_ACCOUNT_TYPE);
  
          new LoginTask(this, accountType, userName, userPass).execute();
      }
  
      private static class LoginTask extends AsyncTask<String, Void, Intent> {
          private final String mAccountType;
          private final String mUserName;
          private final String mUserPass;
          private ProgressDialog progressDialog;
          private final WeakReference<KusssAuthenticatorActivity> activityReference;
  
          public LoginTask(KusssAuthenticatorActivity context, String accountType, String userName, String userPass) {
              super();
  
              this.activityReference = new WeakReference<>(context);
              this.mAccountType = accountType;
              this.mUserName = userName;
              this.mUserPass = userPass;
          }
  
          @Override
          protected void onPreExecute() {
              KusssAuthenticatorActivity activity = activityReference.get();
  
              progressDialog = ProgressDialog.show(
                      activity,
                      activity.getString(R.string.progress_title),
                      activity.getString(R.string.progress_login), true);
          }
  
          @Override
          protected Intent doInBackground(String... params) {
              Bundle data = new Bundle();
              try {
                  KusssAuthenticatorActivity activity = activityReference.get();
  
                  final String authtoken = KusssHandler.getInstance().login(activity, mUserName, mUserPass);
                  KusssHandler.getInstance().logout(activity);
  
                  data.putString(AccountManager.KEY_ACCOUNT_NAME, mUserName);
                  data.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccountType);
                  data.putString(AccountManager.KEY_AUTHTOKEN, authtoken);
                  data.putString(PARAM_USER_PASS, mUserPass);
  
              } catch (Exception e) {
                  data.putString(KEY_ERROR_MESSAGE, e.getMessage());
              }
  
              final Intent res = new Intent();
              res.putExtras(data);
              return res;
          }
  
          @Override
          protected void onPostExecute(Intent intent) {
              KusssAuthenticatorActivity activity = activityReference.get();
  
              String message = null;
              if (TextUtils.isEmpty(intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME))) {
                  message = activity.getString(R.string.account_login_failed_wrong_user);
              } else if (TextUtils.isEmpty(intent.getStringExtra(PARAM_USER_PASS))) {
                  message = activity.getString(R.string.account_login_failed_wrong_pwd);
              } else if (!TextUtils.isEmpty(intent.getStringExtra(KEY_ERROR_MESSAGE))) {
                  message = intent.getStringExtra(KEY_ERROR_MESSAGE);
              } else if (intent.hasExtra(AccountManager.KEY_AUTHTOKEN)) {
                  String authToken = intent
                          .getStringExtra(AccountManager.KEY_AUTHTOKEN);
                  if (!TextUtils.isEmpty(authToken)) {
                      activity.finishLogin(intent);
                  } else {
                      message = activity.getString(R.string.account_login_failed_wrong_pwd);
                  }
              } else {
                  message = activity.getString(R.string.account_login_failed_wrong_auth_token);
              }
              if (!TextUtils.isEmpty(message)) {
                  Toast.makeText(activity,
                          message,
                          Toast.LENGTH_SHORT).show();
              }
  
              progressDialog.dismiss();
  
              activity.getSubmit().setEnabled(true);
          }
      }
  
      protected void finishLogin(Intent intent) {
          String accountName = intent
                  .getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
          String accountPassword = intent.getStringExtra(PARAM_USER_PASS);
          String accountType = intent
                  .getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
  
          logger.info("finish login to {}", accountName);
  
          Account account;
          boolean addNewAccount;
  
          final Account oldAccount = AppUtils.getAccount(KusssAuthenticatorActivity.this);
          if (oldAccount != null) {
              if (oldAccount.name.equals(accountName)) {
                  account = oldAccount;
                  addNewAccount = false;
              } else {
                  AppUtils.removeAccout(mAccountManager, oldAccount);
  