Search in sources :

Example 56 with Account

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

the class DatabaseBackend method onUpgrade.

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    if (oldVersion < 2 && newVersion >= 2) {
        db.execSQL("update " + Account.TABLENAME + " set " + Account.OPTIONS + " = " + Account.OPTIONS + " | 8");
    }
    if (oldVersion < 3 && newVersion >= 3) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.TYPE + " NUMBER");
    }
    if (oldVersion < 5 && newVersion >= 5) {
        db.execSQL("DROP TABLE " + Contact.TABLENAME);
        db.execSQL(CREATE_CONTATCS_STATEMENT);
        db.execSQL("UPDATE " + Account.TABLENAME + " SET " + Account.ROSTERVERSION + " = NULL");
    }
    if (oldVersion < 6 && newVersion >= 6) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.TRUE_COUNTERPART + " TEXT");
    }
    if (oldVersion < 7 && newVersion >= 7) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.REMOTE_MSG_ID + " TEXT");
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.AVATAR + " TEXT");
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.AVATAR + " TEXT");
    }
    if (oldVersion < 8 && newVersion >= 8) {
        db.execSQL("ALTER TABLE " + Conversation.TABLENAME + " ADD COLUMN " + Conversation.ATTRIBUTES + " TEXT");
    }
    if (oldVersion < 9 && newVersion >= 9) {
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.LAST_TIME + " NUMBER");
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.LAST_PRESENCE + " TEXT");
    }
    if (oldVersion < 10 && newVersion >= 10) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.RELATIVE_FILE_PATH + " TEXT");
    }
    if (oldVersion < 11 && newVersion >= 11) {
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.GROUPS + " TEXT");
        db.execSQL("delete from " + Contact.TABLENAME);
        db.execSQL("update " + Account.TABLENAME + " set " + Account.ROSTERVERSION + " = NULL");
    }
    if (oldVersion < 12 && newVersion >= 12) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.SERVER_MSG_ID + " TEXT");
    }
    if (oldVersion < 13 && newVersion >= 13) {
        db.execSQL("delete from " + Contact.TABLENAME);
        db.execSQL("update " + Account.TABLENAME + " set " + Account.ROSTERVERSION + " = NULL");
    }
    if (oldVersion < 14 && newVersion >= 14) {
        canonicalizeJids(db);
    }
    if (oldVersion < 15 && newVersion >= 15) {
        recreateAxolotlDb(db);
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.FINGERPRINT + " TEXT");
    } else if (oldVersion < 22 && newVersion >= 22) {
        db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.CERTIFICATE);
    }
    if (oldVersion < 16 && newVersion >= 16) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.CARBON + " INTEGER");
    }
    if (oldVersion < 19 && newVersion >= 19) {
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.DISPLAY_NAME + " TEXT");
    }
    if (oldVersion < 20 && newVersion >= 20) {
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.HOSTNAME + " TEXT");
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.PORT + " NUMBER DEFAULT 5222");
    }
    if (oldVersion < 26 && newVersion >= 26) {
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.STATUS + " TEXT");
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.STATUS_MESSAGE + " TEXT");
    }
    /* Any migrations that alter the Account table need to happen BEFORE this migration, as it
		 * depends on account de-serialization.
		 */
    if (oldVersion < 17 && newVersion >= 17) {
        List<Account> accounts = getAccounts(db);
        for (Account account : accounts) {
            String ownDeviceIdString = account.getKey(SQLiteAxolotlStore.JSONKEY_REGISTRATION_ID);
            if (ownDeviceIdString == null) {
                continue;
            }
            int ownDeviceId = Integer.valueOf(ownDeviceIdString);
            AxolotlAddress ownAddress = new AxolotlAddress(account.getJid().toBareJid().toPreppedString(), ownDeviceId);
            deleteSession(db, account, ownAddress);
            IdentityKeyPair identityKeyPair = loadOwnIdentityKeyPair(db, account);
            if (identityKeyPair != null) {
                String[] selectionArgs = { account.getUuid(), identityKeyPair.getPublicKey().getFingerprint().replaceAll("\\s", "") };
                ContentValues values = new ContentValues();
                values.put(SQLiteAxolotlStore.TRUSTED, 2);
                db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, values, SQLiteAxolotlStore.ACCOUNT + " = ? AND " + SQLiteAxolotlStore.FINGERPRINT + " = ? ", selectionArgs);
            } else {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not load own identity key pair");
            }
        }
    }
    if (oldVersion < 18 && newVersion >= 18) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.READ + " NUMBER DEFAULT 1");
    }
    if (oldVersion < 21 && newVersion >= 21) {
        List<Account> accounts = getAccounts(db);
        for (Account account : accounts) {
            account.unsetPgpSignature();
            db.update(Account.TABLENAME, account.getContentValues(), Account.UUID + "=?", new String[] { account.getUuid() });
        }
    }
    if (oldVersion < 23 && newVersion >= 23) {
        db.execSQL(CREATE_DISCOVERY_RESULTS_STATEMENT);
    }
    if (oldVersion < 24 && newVersion >= 24) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.EDITED + " TEXT");
    }
    if (oldVersion < 25 && newVersion >= 25) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.OOB + " INTEGER");
    }
    if (oldVersion < 26 && newVersion >= 26) {
        db.execSQL(CREATE_PRESENCE_TEMPLATES_STATEMENT);
    }
    if (oldVersion < 27 && newVersion >= 27) {
        db.execSQL("DELETE FROM " + ServiceDiscoveryResult.TABLENAME);
    }
    if (oldVersion < 28 && newVersion >= 28) {
        canonicalizeJids(db);
    }
    if (oldVersion < 29 && newVersion >= 29) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.ERROR_MESSAGE + " TEXT");
    }
    if (oldVersion < 30 && newVersion >= 30) {
        db.execSQL(CREATE_START_TIMES_TABLE);
    }
    if (oldVersion < 31 && newVersion >= 31) {
        db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.TRUST + " TEXT");
        db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.ACTIVE + " NUMBER");
        HashMap<Integer, ContentValues> migration = new HashMap<>();
        migration.put(0, createFingerprintStatusContentValues(FingerprintStatus.Trust.TRUSTED, true));
        migration.put(1, createFingerprintStatusContentValues(FingerprintStatus.Trust.TRUSTED, true));
        migration.put(2, createFingerprintStatusContentValues(FingerprintStatus.Trust.UNTRUSTED, true));
        migration.put(3, createFingerprintStatusContentValues(FingerprintStatus.Trust.COMPROMISED, false));
        migration.put(4, createFingerprintStatusContentValues(FingerprintStatus.Trust.TRUSTED, false));
        migration.put(5, createFingerprintStatusContentValues(FingerprintStatus.Trust.TRUSTED, false));
        migration.put(6, createFingerprintStatusContentValues(FingerprintStatus.Trust.UNTRUSTED, false));
        migration.put(7, createFingerprintStatusContentValues(FingerprintStatus.Trust.VERIFIED_X509, true));
        migration.put(8, createFingerprintStatusContentValues(FingerprintStatus.Trust.VERIFIED_X509, false));
        for (Map.Entry<Integer, ContentValues> entry : migration.entrySet()) {
            String whereClause = SQLiteAxolotlStore.TRUSTED + "=?";
            String[] where = { String.valueOf(entry.getKey()) };
            db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, entry.getValue(), whereClause, where);
        }
    }
    if (oldVersion < 32 && newVersion >= 32) {
        db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.LAST_ACTIVATION + " NUMBER");
        ContentValues defaults = new ContentValues();
        defaults.put(SQLiteAxolotlStore.LAST_ACTIVATION, System.currentTimeMillis());
        db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, defaults, null, null);
    }
    if (oldVersion < 33 && newVersion >= 33) {
        String whereClause = SQLiteAxolotlStore.OWN + "=1";
        db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, createFingerprintStatusContentValues(FingerprintStatus.Trust.VERIFIED, true), whereClause, null);
    }
    if (oldVersion < 34 && newVersion >= 34) {
        db.execSQL(CREATE_MESSAGE_TIME_INDEX);
        final File oldPicturesDirectory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Conversations/");
        final File oldFilesDirectory = new File(Environment.getExternalStorageDirectory() + "/Conversations/");
        final File newFilesDirectory = new File(Environment.getExternalStorageDirectory() + "/Conversations/Media/Conversations Files/");
        final File newVideosDirectory = new File(Environment.getExternalStorageDirectory() + "/Conversations/Media/Conversations Videos/");
        if (oldPicturesDirectory.exists() && oldPicturesDirectory.isDirectory()) {
            final File newPicturesDirectory = new File(Environment.getExternalStorageDirectory() + "/Conversations/Media/Conversations Images/");
            newPicturesDirectory.getParentFile().mkdirs();
            if (oldPicturesDirectory.renameTo(newPicturesDirectory)) {
                Log.d(Config.LOGTAG, "moved " + oldPicturesDirectory.getAbsolutePath() + " to " + newPicturesDirectory.getAbsolutePath());
            }
        }
        if (oldFilesDirectory.exists() && oldFilesDirectory.isDirectory()) {
            newFilesDirectory.mkdirs();
            newVideosDirectory.mkdirs();
            final File[] files = oldFilesDirectory.listFiles();
            if (files == null) {
                return;
            }
            for (File file : files) {
                if (file.getName().equals(".nomedia")) {
                    if (file.delete()) {
                        Log.d(Config.LOGTAG, "deleted nomedia file in " + oldFilesDirectory.getAbsolutePath());
                    }
                } else if (file.isFile()) {
                    final String name = file.getName();
                    boolean isVideo = false;
                    int start = name.lastIndexOf('.') + 1;
                    if (start < name.length()) {
                        String mime = MimeUtils.guessMimeTypeFromExtension(name.substring(start));
                        isVideo = mime != null && mime.startsWith("video/");
                    }
                    File dst = new File((isVideo ? newVideosDirectory : newFilesDirectory).getAbsolutePath() + "/" + file.getName());
                    if (file.renameTo(dst)) {
                        Log.d(Config.LOGTAG, "moved " + file + " to " + dst);
                    }
                }
            }
        }
    }
    if (oldVersion < 35 && newVersion >= 35) {
        db.execSQL(CREATE_MESSAGE_CONVERSATION_INDEX);
    }
}
Also used : ContentValues(android.content.ContentValues) Account(eu.siacs.conversations.entities.Account) HashMap(java.util.HashMap) AxolotlAddress(org.whispersystems.libaxolotl.AxolotlAddress) IdentityKeyPair(org.whispersystems.libaxolotl.IdentityKeyPair) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File)

Example 57 with Account

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

the class MessageGenerator method preparePacket.

private MessagePacket preparePacket(Message message) {
    Conversation conversation = message.getConversation();
    Account account = conversation.getAccount();
    MessagePacket packet = new MessagePacket();
    if (conversation.getMode() == Conversation.MODE_SINGLE) {
        packet.setTo(message.getCounterpart());
        packet.setType(MessagePacket.TYPE_CHAT);
        packet.addChild("markable", "urn:xmpp:chat-markers:0");
        if (this.mXmppConnectionService.indicateReceived()) {
            packet.addChild("request", "urn:xmpp:receipts");
        }
    } else if (message.getType() == Message.TYPE_PRIVATE) {
        packet.setTo(message.getCounterpart());
        packet.setType(MessagePacket.TYPE_CHAT);
        packet.addChild("x", "http://jabber.org/protocol/muc#user");
        if (this.mXmppConnectionService.indicateReceived()) {
            packet.addChild("request", "urn:xmpp:receipts");
        }
    } else {
        packet.setTo(message.getCounterpart().toBareJid());
        packet.setType(MessagePacket.TYPE_GROUPCHAT);
    }
    packet.setFrom(account.getJid());
    packet.setId(message.getUuid());
    packet.addChild("origin-id", Namespace.STANZA_IDS).setAttribute("id", message.getUuid());
    if (message.edited()) {
        packet.addChild("replace", "urn:xmpp:message-correct:0").setAttribute("id", message.getEditedId());
    }
    return packet;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) Conversation(eu.siacs.conversations.entities.Conversation)

Example 58 with Account

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

the class MessageArchiveService method execute.

private void execute(final Query query) {
    final Account account = query.getAccount();
    if (account.getStatus() == Account.State.ONLINE) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": running mam query " + query.toString());
        IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query);
        this.mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                Element fin = packet.findChild("fin", Namespace.MAM);
                if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
                    synchronized (MessageArchiveService.this.queries) {
                        MessageArchiveService.this.queries.remove(query);
                        if (query.hasCallback()) {
                            query.callback(false);
                        }
                    }
                } else if (packet.getType() == IqPacket.TYPE.RESULT && fin != null) {
                    processFin(fin);
                } else if (packet.getType() == IqPacket.TYPE.RESULT && query.isLegacy()) {
                //do nothing
                } else {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": error executing mam: " + packet.toString());
                    finalizeQuery(query, true);
                }
            }
        });
    } else {
        synchronized (this.pendingQueries) {
            this.pendingQueries.add(query);
        }
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 59 with Account

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

the class MessageParser method extractChatState.

private boolean extractChatState(Conversation c, final boolean isTypeGroupChat, final MessagePacket packet) {
    ChatState state = ChatState.parse(packet);
    if (state != null && c != null) {
        final Account account = c.getAccount();
        Jid from = packet.getFrom();
        if (from.toBareJid().equals(account.getJid().toBareJid())) {
            c.setOutgoingChatState(state);
            if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) {
                mXmppConnectionService.markRead(c);
                activateGracePeriod(account);
            }
            return false;
        } else {
            if (isTypeGroupChat) {
                MucOptions.User user = c.getMucOptions().findUserByFullJid(from);
                if (user != null) {
                    return user.setChatState(state);
                } else {
                    return false;
                }
            } else {
                return c.setIncomingChatState(state);
            }
        }
    }
    return false;
}
Also used : ChatState(eu.siacs.conversations.xmpp.chatstate.ChatState) Account(eu.siacs.conversations.entities.Account) MucOptions(eu.siacs.conversations.entities.MucOptions) Jid(eu.siacs.conversations.xmpp.jid.Jid)

Example 60 with Account

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

the class BarcodeProvider method openFile.

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode, CancellationSignal signal) throws FileNotFoundException {
    Log.d(Config.LOGTAG, "opening file with uri (normal): " + uri.toString());
    String path = uri.getPath();
    if (path != null && path.endsWith(".png") && path.length() >= 5) {
        String jid = path.substring(1).substring(0, path.length() - 4);
        Log.d(Config.LOGTAG, "account:" + jid);
        if (connectAndWait()) {
            Log.d(Config.LOGTAG, "connected to background service");
            try {
                Account account = mXmppConnectionService.findAccountByJid(Jid.fromString(jid));
                if (account != null) {
                    String shareableUri = account.getShareableUri();
                    String hash = CryptoHelper.getFingerprint(shareableUri);
                    File file = new File(getContext().getCacheDir().getAbsolutePath() + "/barcodes/" + hash);
                    if (!file.exists()) {
                        file.getParentFile().mkdirs();
                        file.createNewFile();
                        Bitmap bitmap = create2dBarcodeBitmap(account.getShareableUri(), 1024);
                        OutputStream outputStream = new FileOutputStream(file);
                        bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
                        outputStream.close();
                        outputStream.flush();
                    }
                    return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
                }
            } catch (Exception e) {
                throw new FileNotFoundException();
            }
        }
    }
    throw new FileNotFoundException();
}
Also used : Account(eu.siacs.conversations.entities.Account) Bitmap(android.graphics.Bitmap) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException)

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