예제 #1
0
 /**
  * Creates an account object from another one, given as argument.
  *
  * @param o other account to copy
  */
 public static Account create(Account o) {
   Account a = new AccountImpl();
   a.setUid(o.getUid());
   a.setCommonName(o.getCommonName());
   a.setSurname(o.getSurname());
   a.setOrg(o.getOrg());
   a.setEmail(o.getEmail());
   a.setPhone(o.getPhone());
   a.setDescription(o.getDescription());
   // passwords / new passwords fields voluntarily omitted:
   // the password update process should not go through this.
   a.setGivenName(o.getGivenName());
   a.setTitle(o.getTitle());
   a.setPostalAddress(o.getPostalAddress());
   a.setPostalCode(o.getPostalCode());
   a.setRegisteredAddress(o.getRegisteredAddress());
   a.setPostOfficeBox(o.getPostOfficeBox());
   a.setPhysicalDeliveryOfficeName(o.getPhysicalDeliveryOfficeName());
   a.setStreet(o.getStreet());
   a.setLocality(o.getLocality());
   a.setFacsimile(o.getFacsimile());
   a.setMobile(o.getMobile());
   a.setRoomNumber(o.getRoomNumber());
   a.setStateOrProvince(o.getStateOrProvince());
   a.setOrganizationalUnit(o.getOrganizationalUnit());
   a.setHomePostalAddress(o.getHomePostalAddress());
   return a;
 }
예제 #2
0
  private void initializeActivityView() {
    mAdapter = new FolderListAdapter();
    restorePreviousData();

    setListAdapter(mAdapter);

    setTitle(mAccount.getDescription());
  }
예제 #3
0
  private void openUnreadSearch(Context context, final Account account) {
    String description =
        getString(
            R.string.search_title, mAccount.getDescription(), getString(R.string.unread_modifier));

    SearchSpecification searchSpec =
        new SearchSpecification() {
          // interface has no override            @Override
          public String[] getAccountUuids() {
            return new String[] {account.getUuid()};
          }

          // interface has no override            @Override
          public Flag[] getForbiddenFlags() {
            return UNREAD_FLAG_ARRAY;
          }

          // interface has no override            @Override
          public String getQuery() {
            return "";
          }

          @Override
          public Flag[] getRequiredFlags() {
            return null;
          }

          @Override
          public boolean isIntegrate() {
            return false;
          }

          @Override
          public String[] getFolderNames() {
            return null;
          }
        };
    MessageList.actionHandle(context, description, searchSpec);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_setup_incoming);

    mUsernameView = (EditText) findViewById(R.id.account_username);
    mPasswordView = (EditText) findViewById(R.id.account_password);
    mClientCertificateSpinner =
        (ClientCertificateSpinner) findViewById(R.id.account_client_certificate_spinner);
    mClientCertificateLabelView = (TextView) findViewById(R.id.account_client_certificate_label);
    mPasswordLabelView = (TextView) findViewById(R.id.account_password_label);
    TextView serverLabelView = (TextView) findViewById(R.id.account_server_label);
    mServerView = (EditText) findViewById(R.id.account_server);
    mPortView = (EditText) findViewById(R.id.account_port);
    mSecurityTypeView = (Spinner) findViewById(R.id.account_security_type);
    mAuthTypeView = (Spinner) findViewById(R.id.account_auth_type);
    mImapAutoDetectNamespaceView = (CheckBox) findViewById(R.id.imap_autodetect_namespace);
    mImapPathPrefixView = (EditText) findViewById(R.id.imap_path_prefix);
    mWebdavPathPrefixView = (EditText) findViewById(R.id.webdav_path_prefix);
    mWebdavAuthPathView = (EditText) findViewById(R.id.webdav_auth_path);
    mWebdavMailboxPathView = (EditText) findViewById(R.id.webdav_mailbox_path);
    mNextButton = (Button) findViewById(R.id.next);
    mCompressionMobile = (CheckBox) findViewById(R.id.compression_mobile);
    mCompressionWifi = (CheckBox) findViewById(R.id.compression_wifi);
    mCompressionOther = (CheckBox) findViewById(R.id.compression_other);
    // mSubscribedFoldersOnly = (CheckBox)findViewById(R.id.subscribed_folders_only);
    mRequiresCellular = (CheckBox) findViewById(R.id.account_requires_cellular);
    mAccountName = (EditText) findViewById(R.id.account_name);

    mNextButton.setOnClickListener(this);

    mImapAutoDetectNamespaceView.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mImapPathPrefixView.setEnabled(!isChecked);
            if (isChecked && mImapPathPrefixView.hasFocus()) {
              mImapPathPrefixView.focusSearch(View.FOCUS_UP).requestFocus();
            } else if (!isChecked) {
              mImapPathPrefixView.requestFocus();
            }
          }
        });

    mAuthTypeAdapter = AuthTypeAdapter.get(this);
    mAuthTypeView.setAdapter(mAuthTypeAdapter);

    /*
     * Only allow digits in the port field.
     */
    mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789"));

    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    // mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);

    /*
     * If we're being reloaded we override the original account with the one
     * we saved
     */
    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
      accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
      mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    }

    boolean editSettings = Intent.ACTION_EDIT.equals(getIntent().getAction());

    try {
      ServerSettings settings = RemoteStore.decodeStoreUri(mAccount.getStoreUri());

      if (savedInstanceState == null) {
        // The first item is selected if settings.authenticationType is null or is not in
        // mAuthTypeAdapter
        mCurrentAuthTypeViewPosition =
            mAuthTypeAdapter.getAuthPosition(settings.authenticationType);
      } else {
        mCurrentAuthTypeViewPosition = savedInstanceState.getInt(STATE_AUTH_TYPE_POSITION);
      }
      mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
      updateViewFromAuthType();

      if (settings.username != null) {
        mUsernameView.setText(settings.username);
      }

      if (settings.password != null) {
        mPasswordView.setText(settings.password);
      }

      if (settings.clientCertificateAlias != null) {
        mClientCertificateSpinner.setAlias(settings.clientCertificateAlias);
      }

      mStoreType = settings.type;
      if (Type.POP3 == settings.type) {
        serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
        findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
        findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE);
        findViewById(R.id.compression_section).setVisibility(View.GONE);
        findViewById(R.id.compression_label).setVisibility(View.GONE);
        // mSubscribedFoldersOnly.setVisibility(View.GONE);
      } else if (Type.IMAP == settings.type) {
        serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);

        ImapStoreSettings imapSettings = (ImapStoreSettings) settings;

        mImapAutoDetectNamespaceView.setChecked(imapSettings.autoDetectNamespace);
        if (imapSettings.pathPrefix != null) {
          mImapPathPrefixView.setText(imapSettings.pathPrefix);
        }

        findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
        findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE);

        /*if (!editSettings) {
            findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE);
        }*/
      } else if (Type.WebDAV == settings.type) {
        serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
        mConnectionSecurityChoices =
            new ConnectionSecurity[] {ConnectionSecurity.NONE, ConnectionSecurity.SSL_TLS_REQUIRED};

        // Hide the unnecessary fields
        findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
        findViewById(R.id.account_auth_type_label).setVisibility(View.GONE);
        findViewById(R.id.account_auth_type).setVisibility(View.GONE);
        findViewById(R.id.compression_section).setVisibility(View.GONE);
        findViewById(R.id.compression_label).setVisibility(View.GONE);
        // mSubscribedFoldersOnly.setVisibility(View.GONE);

        WebDavStoreSettings webDavSettings = (WebDavStoreSettings) settings;

        if (webDavSettings.path != null) {
          mWebdavPathPrefixView.setText(webDavSettings.path);
        }

        if (webDavSettings.authPath != null) {
          mWebdavAuthPathView.setText(webDavSettings.authPath);
        }

        if (webDavSettings.mailboxPath != null) {
          mWebdavMailboxPathView.setText(webDavSettings.mailboxPath);
        }
      } else {
        throw new Exception("Unknown account type: " + mAccount.getStoreUri());
      }

      if (!editSettings) {
        mAccount.setDeletePolicy(AccountCreator.getDefaultDeletePolicy(settings.type));
      }

      // Note that mConnectionSecurityChoices is configured above based on server type
      ConnectionSecurityAdapter securityTypesAdapter =
          ConnectionSecurityAdapter.get(this, mConnectionSecurityChoices);
      mSecurityTypeView.setAdapter(securityTypesAdapter);

      // Select currently configured security type
      if (savedInstanceState == null) {
        mCurrentSecurityTypeViewPosition =
            securityTypesAdapter.getConnectionSecurityPosition(settings.connectionSecurity);
      } else {

        /*
         * Restore the spinner state now, before calling
         * setOnItemSelectedListener(), thus avoiding a call to
         * onItemSelected(). Then, when the system restores the state
         * (again) in onRestoreInstanceState(), The system will see that
         * the new state is the same as the current state (set here), so
         * once again onItemSelected() will not be called.
         */
        mCurrentSecurityTypeViewPosition = savedInstanceState.getInt(STATE_SECURITY_TYPE_POSITION);
      }
      mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);

      updateAuthPlainTextFromSecurityType(settings.connectionSecurity);

      mCompressionMobile.setChecked(mAccount.useCompression(NetworkType.MOBILE));
      mCompressionWifi.setChecked(mAccount.useCompression(NetworkType.WIFI));
      mCompressionOther.setChecked(mAccount.useCompression(NetworkType.OTHER));

      if (settings.host != null) {
        mServerView.setText(settings.host);
      }

      if (settings.port != -1) {
        mPortView.setText(Integer.toString(settings.port));
      } else {
        updatePortFromSecurityType();
      }
      mCurrentPortViewSetting = mPortView.getText().toString();

      // mSubscribedFoldersOnly.setChecked(mAccount.subscribedFoldersOnly());
    } catch (Exception e) {
      failure(e);
    }
    // show & populate setup fields
    if (!Intent.ACTION_EDIT.equals(getIntent().getAction())) {
      findViewById(R.id.account_name_label).setVisibility(View.VISIBLE);
      mAccountName.setVisibility(View.VISIBLE);
      String desc = mAccount.getDescription();
      mAccountName.setText((desc != null ? desc : ""));
      findViewById(R.id.account_requires_cellular_label).setVisibility(View.VISIBLE);
      mRequiresCellular.setVisibility(View.VISIBLE);
      mRequiresCellular.setChecked(true);
    }
  }
  public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, int newVersion) {
    // Update database to add the Paid Account flag. This was introduced in
    // DB version 3.
    if (oldVersion <= DatabaseVersionNumber.VERSION_1_0_0) {
      db.execSQL(QUERY_ADD_PAID_ACCOUNT_COLUM);
    }

    // Update database to create account content provider
    if (oldVersion <= DatabaseVersionNumber.VERSION_1_1_0) {
      // Rename old table
      db.execSQL(QUERY_RENAME_TABLE_OLD);
      db.execSQL(QUERY_TABLE_CREATE);
      db.execSQL(REPLICATE_ACCOUNT);
      db.execSQL(QUERY_DROP_TABLE_OLD);
    }

    // Migrate all accounts to Account Manager
    if (oldVersion < DatabaseVersionNumber.VERSION_1_5_0) {
      //
      List<Account> accounts = AccountProvider.retrieveAccounts(db);
      android.accounts.Account newAccount;
      String accountName;
      AccountManager mAccountManager = AccountManager.get(context);
      SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
      SyncContentManager syncManager = SyncContentManager.getInstance(context);
      for (Account account : accounts) {
        // Check Account Name
        accountName =
            AlfrescoAccountManager.getInstance(context)
                .createUniqueAccountName(account.getUsername());
        newAccount = new android.accounts.Account(accountName, AlfrescoAccount.ACCOUNT_TYPE);
        Bundle b = new Bundle();
        // Very important !
        // We keep the same Account Id from previous version.
        // Used by the SyncService
        b.putString(AlfrescoAccount.ACCOUNT_ID, Long.toString(account.getId()));
        BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_NAME, account.getDescription());
        BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_URL, account.getUrl());
        BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_USERNAME, account.getUsername());
        BundleUtils.addIfNotEmpty(
            b, AlfrescoAccount.ACCOUNT_REPOSITORY_ID, account.getRepositoryId());
        BundleUtils.addIfNotEmpty(
            b, AlfrescoAccount.ACCOUNT_REPOSITORY_TYPE_ID, String.valueOf(account.getTypeId()));
        BundleUtils.addIfNotEmpty(
            b,
            AlfrescoAccount.ACCOUNT_IS_PAID_ACCOUNT,
            Boolean.toString(account.getIsPaidAccount()));
        BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_ACTIVATION, account.getActivation());
        BundleUtils.addIfNotEmpty(
            b, AlfrescoAccount.ACCOUNT_ACCESS_TOKEN, account.getAccessToken());
        BundleUtils.addIfNotEmpty(
            b, AlfrescoAccount.ACCOUNT_REFRESH_TOKEN, account.getRefreshToken());

        // Time to create.
        if (mAccountManager.addAccountExplicitly(newAccount, account.getPassword(), b)) {
          // Let's define if sync automatically regarding previous
          // settings
          syncManager.setActivateSync(
              account.getId(), sharedPref.getBoolean(SYNCHRO_PREFIX + account.getId(), false));
          sharedPref.edit().remove(SYNCHRO_PREFIX + account.getId()).apply();
        }

        Log.i(
            "Migration",
            "Account " + account.getDescription() + "[" + account.getId() + "] has been migrated");
      }
      // Delete old table
      db.execSQL(QUERY_DROP_TABLE);
    }
  }