Search in sources :

Example 71 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final String action = intent == null ? null : intent.getAction();
    String pushedAccountHash = null;
    boolean interactive = false;
    if (action != null) {
        final Conversation c = findConversationByUuid(intent.getStringExtra("uuid"));
        switch(action) {
            case ConnectivityManager.CONNECTIVITY_ACTION:
                if (hasInternetConnection() && Config.RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE) {
                    resetAllAttemptCounts(true, false);
                }
                break;
            case ACTION_MERGE_PHONE_CONTACTS:
                if (mRestoredFromDatabase) {
                    loadPhoneContacts();
                }
                return START_STICKY;
            case Intent.ACTION_SHUTDOWN:
                logoutAndSave(true);
                return START_NOT_STICKY;
            case ACTION_CLEAR_NOTIFICATION:
                if (c != null) {
                    mNotificationService.clear(c);
                } else {
                    mNotificationService.clear();
                }
                break;
            case ACTION_DISABLE_FOREGROUND:
                getPreferences().edit().putBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE, false).commit();
                toggleForegroundService();
                break;
            case ACTION_DISMISS_ERROR_NOTIFICATIONS:
                dismissErrorNotifications();
                break;
            case ACTION_TRY_AGAIN:
                resetAllAttemptCounts(false, true);
                interactive = true;
                break;
            case ACTION_REPLY_TO_CONVERSATION:
                Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
                if (remoteInput != null && c != null) {
                    final CharSequence body = remoteInput.getCharSequence("text_reply");
                    if (body != null && body.length() > 0) {
                        directReply(c, body.toString(), intent.getBooleanExtra("dismiss_notification", false));
                    }
                }
                break;
            case AudioManager.RINGER_MODE_CHANGED_ACTION:
                if (xaOnSilentMode()) {
                    refreshAllPresences();
                }
                break;
            case Intent.ACTION_SCREEN_ON:
                deactivateGracePeriod();
            case Intent.ACTION_SCREEN_OFF:
                if (awayWhenScreenOff()) {
                    refreshAllPresences();
                }
                break;
            case ACTION_GCM_TOKEN_REFRESH:
                refreshAllGcmTokens();
                break;
            case ACTION_IDLE_PING:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    scheduleNextIdlePing();
                }
                break;
            case ACTION_GCM_MESSAGE_RECEIVED:
                Log.d(Config.LOGTAG, "gcm push message arrived in service. extras=" + intent.getExtras());
                pushedAccountHash = intent.getStringExtra("account");
                break;
        }
    }
    synchronized (this) {
        this.wakeLock.acquire();
        boolean pingNow = ConnectivityManager.CONNECTIVITY_ACTION.equals(action);
        HashSet<Account> pingCandidates = new HashSet<>();
        for (Account account : accounts) {
            pingNow |= processAccountState(account, interactive, "ui".equals(action), CryptoHelper.getAccountFingerprint(account).equals(pushedAccountHash), pingCandidates);
        }
        if (pingNow) {
            for (Account account : pingCandidates) {
                final boolean lowTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid());
                account.getXmppConnection().sendPing();
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping (action=" + action + ",lowTimeout=" + Boolean.toString(lowTimeout) + ")");
                scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, account.getUuid().hashCode());
            }
        }
        if (wakeLock.isHeld()) {
            try {
                wakeLock.release();
            } catch (final RuntimeException ignored) {
            }
        }
    }
    if (SystemClock.elapsedRealtime() - mLastExpiryRun.get() >= Config.EXPIRY_INTERVAL) {
        expireOldMessages();
    }
    return START_STICKY;
}
Also used : Account(eu.siacs.conversations.entities.Account) Bundle(android.os.Bundle) Conversation(eu.siacs.conversations.entities.Conversation) HashSet(java.util.HashSet)

Example 72 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method republishAvatarIfNeeded.

public void republishAvatarIfNeeded(Account account) {
    if (account.getAxolotlService().isPepBroken()) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": skipping republication of avatar because pep is broken");
        return;
    }
    IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null);
    this.sendIqPacket(account, packet, new OnIqPacketReceived() {

        private Avatar parseAvatar(IqPacket packet) {
            Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub");
            if (pubsub != null) {
                Element items = pubsub.findChild("items");
                if (items != null) {
                    return Avatar.parseMetadata(items);
                }
            }
            return null;
        }

        private boolean errorIsItemNotFound(IqPacket packet) {
            Element error = packet.findChild("error");
            return packet.getType() == IqPacket.TYPE.ERROR && error != null && error.hasChild("item-not-found");
        }

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT || errorIsItemNotFound(packet)) {
                Avatar serverAvatar = parseAvatar(packet);
                if (serverAvatar == null && account.getAvatar() != null) {
                    Avatar avatar = fileBackend.getStoredPepAvatar(account.getAvatar());
                    if (avatar != null) {
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": avatar on server was null. republishing");
                        publishAvatar(account, fileBackend.getStoredPepAvatar(account.getAvatar()), null);
                    } else {
                        Log.e(Config.LOGTAG, account.getJid().toBareJid() + ": error rereading avatar");
                    }
                }
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) Avatar(eu.siacs.conversations.xmpp.pep.Avatar) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 73 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method switchToBackground.

private void switchToBackground() {
    final boolean broadcastLastActivity = broadcastLastActivity();
    for (Account account : getAccounts()) {
        if (account.getStatus() == Account.State.ONLINE) {
            XmppConnection connection = account.getXmppConnection();
            if (connection != null) {
                if (broadcastLastActivity) {
                    sendPresence(account, broadcastLastActivity);
                }
                if (connection.getFeatures().csi()) {
                    connection.sendInactive();
                }
            }
        }
    }
    this.mNotificationService.setIsInForeground(false);
    Log.d(Config.LOGTAG, "app switched into background");
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) Account(eu.siacs.conversations.entities.Account)

Example 74 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method saveConversationAsBookmark.

public void saveConversationAsBookmark(Conversation conversation, String name) {
    Account account = conversation.getAccount();
    Bookmark bookmark = new Bookmark(account, conversation.getJid().toBareJid());
    if (!conversation.getJid().isBareJid()) {
        bookmark.setNick(conversation.getJid().getResourcepart());
    }
    if (name != null && !name.trim().isEmpty()) {
        bookmark.setBookmarkName(name.trim());
    }
    bookmark.setAutojoin(getPreferences().getBoolean("autojoin", true));
    account.getBookmarks().add(bookmark);
    pushBookmarks(account);
    conversation.setBookmark(bookmark);
}
Also used : Account(eu.siacs.conversations.entities.Account) Bookmark(eu.siacs.conversations.entities.Bookmark)

Example 75 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method sendFileMessage.

private void sendFileMessage(final Message message, final boolean delay) {
    Log.d(Config.LOGTAG, "send file message");
    final Account account = message.getConversation().getAccount();
    if (account.httpUploadAvailable(fileBackend.getFile(message, false).getSize())) {
        mHttpConnectionManager.createNewUploadConnection(message, delay);
    } else {
        mJingleConnectionManager.createNewConnection(message);
    }
}
Also used : Account(eu.siacs.conversations.entities.Account)

Aggregations

Account (eu.siacs.conversations.entities.Account)100 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)22 Element (eu.siacs.conversations.xml.Element)21 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)17 Conversation (eu.siacs.conversations.entities.Conversation)16 Contact (eu.siacs.conversations.entities.Contact)9 Message (eu.siacs.conversations.entities.Message)9 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Intent (android.content.Intent)7 Bookmark (eu.siacs.conversations.entities.Bookmark)7 SuppressLint (android.annotation.SuppressLint)6 AlertDialog (android.app.AlertDialog)6 TextView (android.widget.TextView)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 FileNotFoundException (java.io.FileNotFoundException)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5