Search in sources :

Example 1 with ConnectionSettings

use of com.xabber.android.data.connection.ConnectionSettings in project xabber-android by redsolution.

the class AccountManager method setPassword.

public void setPassword(String account, boolean storePassword, String password) {
    AccountItem accountItem = getAccount(account);
    ConnectionSettings connectionSettings = accountItem.getConnectionSettings();
    updateAccount(account, connectionSettings.isCustomHostAndPort(), connectionSettings.getHost(), connectionSettings.getPort(), connectionSettings.getServerName(), connectionSettings.getUserName(), storePassword, password, connectionSettings.getResource(), accountItem.getPriority(), accountItem.isEnabled(), connectionSettings.isSaslEnabled(), connectionSettings.getTlsMode(), connectionSettings.useCompression(), connectionSettings.getProxyType(), connectionSettings.getProxyHost(), connectionSettings.getProxyPort(), connectionSettings.getProxyUser(), connectionSettings.getProxyPassword(), accountItem.isSyncable(), accountItem.getArchiveMode(), accountItem.getColorIndex());
}
Also used : ConnectionSettings(com.xabber.android.data.connection.ConnectionSettings)

Example 2 with ConnectionSettings

use of com.xabber.android.data.connection.ConnectionSettings in project xabber-android by redsolution.

the class AccountManager method setEnabled.

public void setEnabled(String account, boolean enabled) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    ConnectionSettings connectionSettings = accountItem.getConnectionSettings();
    AccountManager.getInstance().updateAccount(account, connectionSettings.isCustomHostAndPort(), connectionSettings.getHost(), connectionSettings.getPort(), connectionSettings.getServerName(), connectionSettings.getUserName(), accountItem.isStorePassword(), connectionSettings.getPassword(), connectionSettings.getResource(), accountItem.getPriority(), enabled, connectionSettings.isSaslEnabled(), connectionSettings.getTlsMode(), connectionSettings.useCompression(), connectionSettings.getProxyType(), connectionSettings.getProxyHost(), connectionSettings.getProxyPort(), connectionSettings.getProxyUser(), connectionSettings.getProxyPassword(), accountItem.isSyncable(), accountItem.getArchiveMode(), accountItem.getColorIndex());
}
Also used : ConnectionSettings(com.xabber.android.data.connection.ConnectionSettings)

Example 3 with ConnectionSettings

use of com.xabber.android.data.connection.ConnectionSettings in project xabber-android by redsolution.

the class AccountTable method write.

public long write(Long id, AccountItem accountItem) {
    ConnectionSettings connectionSettings = accountItem.getConnectionSettings();
    ContentValues values = new ContentValues();
    values.put(Fields.PROTOCOL, connectionSettings.getProtocol().name());
    values.put(Fields.CUSTOM, connectionSettings.isCustomHostAndPort() ? 1 : 0);
    values.put(Fields.HOST, connectionSettings.getHost());
    values.put(Fields.PORT, connectionSettings.getPort());
    values.put(Fields.SERVER_NAME, connectionSettings.getServerName());
    values.put(Fields.USER_NAME, connectionSettings.getUserName());
    String password = connectionSettings.getPassword();
    if (!accountItem.isStorePassword()) {
        password = AccountItem.UNDEFINED_PASSWORD;
    }
    values.put(Fields.PASSWORD, password);
    values.put(Fields.RESOURCE, connectionSettings.getResource());
    values.put(Fields.COLOR_INDEX, accountItem.getColorIndex());
    values.put(Fields.PRIORITY, accountItem.getPriority());
    values.put(Fields.STATUS_MODE, accountItem.getRawStatusMode().ordinal());
    values.put(Fields.STATUS_TEXT, accountItem.getStatusText());
    values.put(Fields.ENABLED, accountItem.isEnabled() ? 1 : 0);
    values.put(Fields.SASL_ENABLED, connectionSettings.isSaslEnabled() ? 1 : 0);
    values.put(Fields.TLS_MODE, connectionSettings.getTlsMode().ordinal());
    values.put(Fields.COMPRESSION, connectionSettings.useCompression() ? 1 : 0);
    values.put(Fields.PROXY_TYPE, connectionSettings.getProxyType().ordinal());
    values.put(Fields.PROXY_HOST, connectionSettings.getProxyHost());
    values.put(Fields.PROXY_PORT, connectionSettings.getProxyPort());
    values.put(Fields.PROXY_USER, connectionSettings.getProxyUser());
    values.put(Fields.PROXY_PASSWORD, connectionSettings.getProxyPassword());
    values.put(Fields.SYNCABLE, accountItem.isSyncable() ? 1 : 0);
    values.put(Fields.STORE_PASSWORD, accountItem.isStorePassword() ? 1 : 0);
    final KeyPair keyPair = accountItem.getKeyPair();
    if (keyPair == null) {
        values.putNull(Fields.PUBLIC_KEY);
        values.putNull(Fields.PRIVATE_KEY);
    } else {
        PublicKey publicKey = keyPair.getPublic();
        X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(publicKey.getEncoded());
        PrivateKey privateKey = keyPair.getPrivate();
        PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
        byte[] publicKeyBytes = x509EncodedKeySpec.getEncoded();
        byte[] privateKeyBytes = pkcs8EncodedKeySpec.getEncoded();
        values.put(Fields.PUBLIC_KEY, publicKeyBytes);
        values.put(Fields.PRIVATE_KEY, privateKeyBytes);
    }
    if (accountItem.getLastSync() == null) {
        values.putNull(Fields.LAST_SYNC);
    } else {
        values.put(Fields.LAST_SYNC, accountItem.getLastSync().getTime());
    }
    values.put(Fields.ARCHIVE_MODE, accountItem.getArchiveMode().ordinal());
    SQLiteDatabase db = databaseManager.getWritableDatabase();
    if (id == null) {
        return db.insert(NAME, Fields.USER_NAME, values);
    }
    db.update(NAME, values, Fields._ID + " = ?", new String[] { String.valueOf(id) });
    return id;
}
Also used : ContentValues(android.content.ContentValues) KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) PublicKey(java.security.PublicKey) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) ConnectionSettings(com.xabber.android.data.connection.ConnectionSettings)

Example 4 with ConnectionSettings

use of com.xabber.android.data.connection.ConnectionSettings in project xabber-android by redsolution.

the class AccountManager method setArchiveMode.

public void setArchiveMode(String account, ArchiveMode archiveMode) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    ConnectionSettings connectionSettings = accountItem.getConnectionSettings();
    AccountManager.getInstance().updateAccount(account, connectionSettings.isCustomHostAndPort(), connectionSettings.getHost(), connectionSettings.getPort(), connectionSettings.getServerName(), connectionSettings.getUserName(), accountItem.isStorePassword(), connectionSettings.getPassword(), connectionSettings.getResource(), accountItem.getPriority(), accountItem.isEnabled(), connectionSettings.isSaslEnabled(), connectionSettings.getTlsMode(), connectionSettings.useCompression(), connectionSettings.getProxyType(), connectionSettings.getProxyHost(), connectionSettings.getProxyPort(), connectionSettings.getProxyUser(), connectionSettings.getProxyPassword(), accountItem.isSyncable(), archiveMode, accountItem.getColorIndex());
}
Also used : ConnectionSettings(com.xabber.android.data.connection.ConnectionSettings)

Example 5 with ConnectionSettings

use of com.xabber.android.data.connection.ConnectionSettings in project xabber-android by redsolution.

the class AccountManager method setSyncable.

public void setSyncable(String account, boolean syncable) {
    AccountItem accountItem = getAccount(account);
    ConnectionSettings connectionSettings = accountItem.getConnectionSettings();
    updateAccount(account, connectionSettings.isCustomHostAndPort(), connectionSettings.getHost(), connectionSettings.getPort(), connectionSettings.getServerName(), connectionSettings.getUserName(), accountItem.isStorePassword(), connectionSettings.getPassword(), connectionSettings.getResource(), accountItem.getPriority(), accountItem.isEnabled(), connectionSettings.isSaslEnabled(), connectionSettings.getTlsMode(), connectionSettings.useCompression(), connectionSettings.getProxyType(), connectionSettings.getProxyHost(), connectionSettings.getProxyPort(), connectionSettings.getProxyUser(), connectionSettings.getProxyPassword(), syncable, accountItem.getArchiveMode(), accountItem.getColorIndex());
}
Also used : ConnectionSettings(com.xabber.android.data.connection.ConnectionSettings)

Aggregations

ConnectionSettings (com.xabber.android.data.connection.ConnectionSettings)5 ContentValues (android.content.ContentValues)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)1 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)1