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));
}
}
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();
}
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();
}
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();
}
}
}
});
}
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());
}
}
});
}
Aggregations