Exemple #1
0
 public void invalidateAuth() {
   if (!isClientLogin()) {
     accMgr.invalidateAuthToken(
         ACCOUNT_TYPE, DataMgr.getInstance().getSettingByName(Setting.SETTING_AUTH));
   }
   DataMgr.getInstance().removeSettingByName(Setting.SETTING_AUTH);
 }
Exemple #2
0
 public void run(final AccountManagerFuture<Bundle> result) {
   try {
     final Bundle bundle = result.getResult();
     final Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT);
     if (intent != null) {
       /*
        * Remember: This returns onAuthUpdateFinished(true), then
        * it may still be canceled by user!
        */
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       if (showIntent) {
         context.startActivity(intent);
       }
     } else {
       final DataMgr dataMgr = DataMgr.getInstance();
       dataMgr.updateSetting(
           new Setting(Setting.SETTING_AUTH, bundle.getString(AccountManager.KEY_AUTHTOKEN)));
     }
     notifyOnAuthUpdateFinished(true);
   } catch (final OperationCanceledException exception) {
     notifyOnAuthUpdateFinished(false);
     exception.printStackTrace();
   } catch (final AuthenticatorException exception) {
     notifyOnAuthUpdateFinished(false);
     exception.printStackTrace();
   } catch (final IOException exception) {
     notifyOnAuthUpdateFinished(false);
     exception.printStackTrace();
   }
 }
Exemple #3
0
 public void clearLogin() {
   final DataMgr dataMgr = DataMgr.getInstance();
   dataMgr.removeSettingByName(Setting.SETTING_AUTH);
   dataMgr.removeSettingByName(Setting.SETTING_IS_CLIENT_LOGIN);
   dataMgr.removeSettingByName(Setting.SETTING_USERNAME);
   dataMgr.removeSettingByName(Setting.SETTING_PASSWORD);
 }
Exemple #4
0
 public void setClientLogin(final String serverUrl, final String user, final String pass) {
   final DataMgr dataMgr = DataMgr.getInstance();
   dataMgr.updateSetting(new Setting(Setting.SETTING_SERVER_URL, serverUrl));
   AbsURL.setServerUrl(serverUrl);
   dataMgr.updateSetting(new Setting(Setting.SETTING_USERNAME, user));
   dataMgr.updateSetting(new Setting(Setting.SETTING_PASSWORD, pass));
   dataMgr.updateSetting(new Setting(Setting.SETTING_IS_CLIENT_LOGIN, String.valueOf(true)));
 }
Exemple #5
0
 public synchronized String blockingGetAuth() {
   if (!getAuth()) {
     return DataMgr.getInstance().getSettingByName(Setting.SETTING_AUTH);
   }
   try {
     wait();
   } catch (final InterruptedException exception) {
     exception.printStackTrace();
   }
   return DataMgr.getInstance().getSettingByName(Setting.SETTING_AUTH);
 }
Exemple #6
0
 /*
  * @return whether syncing is started
  */
 public boolean getAuth() {
   if (isAuthValid()) {
     return false;
   }
   final DataMgr dataMgr = DataMgr.getInstance();
   final String user = dataMgr.getSettingByName(Setting.SETTING_USERNAME);
   if (user == null) {
     return false;
   }
   if (isClientLogin()) {
     final String pass = dataMgr.getSettingByName(Setting.SETTING_PASSWORD);
     if (pass == null) {
       return false;
     }
     return tryClientLogin(user, pass);
   } else {
     return tryNonClicentLogin(user);
   }
 }
Exemple #7
0
 public boolean hasAccount() {
   final DataMgr dataMgr = DataMgr.getInstance();
   final String user = dataMgr.getSettingByName(Setting.SETTING_USERNAME);
   final String cLogin = dataMgr.getSettingByName(Setting.SETTING_IS_CLIENT_LOGIN);
   if (user == null || cLogin == null) {
     return false;
   }
   if (Boolean.valueOf(cLogin)) {
     final String pass = dataMgr.getSettingByName(Setting.SETTING_PASSWORD);
     return (pass != null);
   } else {
     final Account[] accounts = accMgr.getAccountsByType(ACCOUNT_TYPE);
     for (int i = 0; i < accounts.length; i++) {
       if (accounts[i].name.equals(user)) {
         return true;
       }
     }
     return false;
   }
 }
Exemple #8
0
 public void setNonClientLogin(final String user) {
   final DataMgr dataMgr = DataMgr.getInstance();
   dataMgr.updateSetting(new Setting(Setting.SETTING_USERNAME, user));
   dataMgr.updateSetting(new Setting(Setting.SETTING_IS_CLIENT_LOGIN, String.valueOf(false)));
 }
Exemple #9
0
 public boolean isClientLogin() {
   final String cLogin = DataMgr.getInstance().getSettingByName(Setting.SETTING_IS_CLIENT_LOGIN);
   return (cLogin != null && Boolean.valueOf(cLogin));
 }
Exemple #10
0
 public boolean isAuthValid() {
   final String auth = DataMgr.getInstance().getSettingByName(Setting.SETTING_AUTH);
   return (auth != null);
 }