Search in sources :

Example 96 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method onCreate.

@SuppressLint("TrulyRandom")
@Override
public void onCreate() {
    ExceptionHelper.init(getApplicationContext());
    PRNGFixes.apply();
    Resolver.init(this);
    this.mRandom = new SecureRandom();
    updateMemorizingTrustmanager();
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    final int cacheSize = maxMemory / 8;
    this.mBitmapCache = new LruCache<String, Bitmap>(cacheSize) {

        @Override
        protected int sizeOf(final String key, final Bitmap bitmap) {
            return bitmap.getByteCount() / 1024;
        }
    };
    Log.d(Config.LOGTAG, "initializing database...");
    this.databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
    Log.d(Config.LOGTAG, "restoring accounts...");
    this.accounts = databaseBackend.getAccounts();
    final SharedPreferences.Editor editor = getPreferences().edit();
    if (this.accounts.size() == 0 && Arrays.asList("Sony", "Sony Ericsson").contains(Build.MANUFACTURER)) {
        editor.putBoolean(SettingsActivity.SHOW_FOREGROUND_SERVICE, true);
        Log.d(Config.LOGTAG, Build.MANUFACTURER + " is on blacklist. enabling foreground service");
    }
    editor.putBoolean(EventReceiver.SETTING_ENABLED_ACCOUNTS, hasEnabledAccounts()).apply();
    editor.apply();
    restoreFromDatabase();
    getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
    new Thread(new Runnable() {

        @Override
        public void run() {
            fileObserver.startWatching();
        }
    }).start();
    if (Config.supportOpenPgp()) {
        this.pgpServiceConnection = new OpenPgpServiceConnection(this, "org.sufficientlysecure.keychain", new OpenPgpServiceConnection.OnBound() {

            @Override
            public void onBound(IOpenPgpService2 service) {
                for (Account account : accounts) {
                    final PgpDecryptionService pgp = account.getPgpDecryptionService();
                    if (pgp != null) {
                        pgp.continueDecryption(true);
                    }
                }
            }

            @Override
            public void onError(Exception e) {
            }
        });
        this.pgpServiceConnection.bindToService();
    }
    this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XmppConnectionService");
    toggleForegroundService();
    updateUnreadCountBadge();
    toggleScreenEventReceiver();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        scheduleNextIdlePing();
    }
    // start export log service every day at given time
    ScheduleAutomaticExport();
    // cancel scheduled exporter
    CancelAutomaticExport(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        registerReceiver(this.mEventReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    }
}
Also used : Account(de.pixart.messenger.entities.Account) IntentFilter(android.content.IntentFilter) IOpenPgpService2(org.openintents.openpgp.IOpenPgpService2) SharedPreferences(android.content.SharedPreferences) SecureRandom(java.security.SecureRandom) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection) PgpDecryptionService(de.pixart.messenger.crypto.PgpDecryptionService) SuppressLint(android.annotation.SuppressLint) OtrException(net.java.otr4j.OtrException) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) CertificateException(java.security.cert.CertificateException) Bitmap(android.graphics.Bitmap) SuppressLint(android.annotation.SuppressLint)

Example 97 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class BlocklistActivity method onBackendConnected.

@Override
public void onBackendConnected() {
    for (final Account account : xmppConnectionService.getAccounts()) {
        if (account.getJid().toString().equals(getIntent().getStringExtra(EXTRA_ACCOUNT))) {
            this.account = account;
            break;
        }
    }
    filterContacts();
    this.mKnownHosts = xmppConnectionService.getKnownHosts();
}
Also used : Account(de.pixart.messenger.entities.Account)

Example 98 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class ChooseContactActivity method onBackendConnected.

@Override
void onBackendConnected() {
    filterContacts();
    this.mActivatedAccounts.clear();
    for (Account account : xmppConnectionService.getAccounts()) {
        if (account.getStatus() != Account.State.DISABLED) {
            if (Config.DOMAIN_LOCK != null) {
                this.mActivatedAccounts.add(account.getJid().getLocalpart());
            } else {
                this.mActivatedAccounts.add(account.getJid().toBareJid().toString());
            }
        }
    }
    this.mKnownHosts = xmppConnectionService.getKnownHosts();
}
Also used : Account(de.pixart.messenger.entities.Account)

Example 99 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppConnection method sendServiceDiscoveryItems.

private void sendServiceDiscoveryItems(final Jid server) {
    mPendingServiceDiscoveries.incrementAndGet();
    final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
    iq.setTo(server.toDomainJid());
    iq.query("http://jabber.org/protocol/disco#items");
    this.sendIqPacket(iq, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, final IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                HashSet<Jid> items = new HashSet<Jid>();
                final List<Element> elements = packet.query().getChildren();
                for (final Element element : elements) {
                    if (element.getName().equals("item")) {
                        final Jid jid = element.getAttributeAsJid("jid");
                        if (jid != null && !jid.equals(account.getServer())) {
                            items.add(jid);
                        }
                    }
                }
                for (Jid jid : items) {
                    sendServiceDiscoveryInfo(jid);
                }
            } else {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not query disco items of " + server);
            }
            if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
                if (mPendingServiceDiscoveries.decrementAndGet() == 0 && mWaitForDisco.compareAndSet(true, false)) {
                    finalizeBind();
                }
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) List(java.util.List) ArrayList(java.util.ArrayList) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) HashSet(java.util.HashSet)

Example 100 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppConnection method sendEnableCarbons.

private void sendEnableCarbons() {
    final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
    iq.addChild("enable", "urn:xmpp:carbons:2");
    this.sendIqPacket(iq, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, final IqPacket packet) {
            if (!packet.hasChild("error")) {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully enabled carbons");
                features.carbonsEnabled = true;
            } else {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": error enableing carbons " + packet.toString());
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6