Search in sources :

Example 86 with Account

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

the class MagicCreateActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    if (getResources().getBoolean(R.bool.portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.magic_create);
    mFullJidDisplay = findViewById(R.id.full_jid);
    mUsername = findViewById(R.id.username);
    mRandom = new SecureRandom();
    Button next = findViewById(R.id.create_account);
    next.setOnClickListener(v -> {
        String username = mUsername.getText().toString();
        if (username.contains("@") || username.length() < 3) {
            mUsername.setError(getString(R.string.invalid_username));
            mUsername.requestFocus();
        } else {
            mUsername.setError(null);
            try {
                Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
                Account account = xmppConnectionService.findAccountByJid(jid);
                if (account == null) {
                    account = new Account(jid, createPassword());
                    account.setOption(Account.OPTION_REGISTER, true);
                    account.setOption(Account.OPTION_DISABLED, true);
                    account.setOption(Account.OPTION_MAGIC_CREATE, true);
                    xmppConnectionService.createAccount(account);
                }
                Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class);
                intent.putExtra("jid", account.getJid().toBareJid().toString());
                intent.putExtra("init", true);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show();
                WelcomeActivity.addInviteUri(intent, getIntent());
                startActivity(intent);
            } catch (InvalidJidException e) {
                mUsername.setError(getString(R.string.invalid_username));
                mUsername.requestFocus();
            }
        }
    });
    mUsername.addTextChangedListener(this);
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) Button(android.widget.Button) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) SecureRandom(java.security.SecureRandom) Intent(android.content.Intent)

Example 87 with Account

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

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(de.pixart.messenger.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)

Example 88 with Account

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

the class ExportLogsService method ExportDatabase.

public void ExportDatabase() throws IOException {
    Account mAccount = mAccounts.get(0);
    String EncryptionKey = null;
    // Get hold of the db:
    FileInputStream InputFile = new FileInputStream(this.getDatabasePath(DatabaseBackend.DATABASE_NAME));
    // Set the output folder on the SDcard
    File directory = new File(FileBackend.getConversationsDirectory("Database", false));
    // Create the folder if it doesn't exist:
    if (!directory.exists()) {
        directory.mkdirs();
    }
    // Delete old database export file
    File temp_db_file = new File(directory + "/database.bak");
    if (temp_db_file.exists()) {
        Log.d(Config.LOGTAG, "Delete temp database backup file from " + temp_db_file.toString());
        temp_db_file.delete();
    }
    // Set the output file stream up:
    FileOutputStream OutputFile = new FileOutputStream(directory.getPath() + "/database.db.crypt");
    if (mAccounts.size() == 1 && !multipleAccounts()) {
        // get account password
        EncryptionKey = mAccount.getPassword();
    } else {
        SharedPreferences multiaccount_prefs = getApplicationContext().getSharedPreferences(USE_MULTI_ACCOUNTS, Context.MODE_PRIVATE);
        String password = multiaccount_prefs.getString("BackupPW", null);
        if (password == null) {
            Log.d(Config.LOGTAG, "Database exporter: failed to write encryted backup to sdcard because of missing password");
            return;
        }
        // get previously set backup password
        EncryptionKey = password;
    }
    // encrypt database from the input file to the output file
    try {
        EncryptDecryptFile.encrypt(InputFile, OutputFile, EncryptionKey);
    } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
        Log.d(Config.LOGTAG, "Database exporter: encryption failed with " + e);
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        Log.d(Config.LOGTAG, "Database exporter: encryption failed (invalid key) with " + e);
        e.printStackTrace();
    } catch (IOException e) {
        Log.d(Config.LOGTAG, "Database exporter: encryption failed (IO) with " + e);
        e.printStackTrace();
    }
}
Also used : Account(de.pixart.messenger.entities.Account) SharedPreferences(android.content.SharedPreferences) FileOutputStream(java.io.FileOutputStream) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) EncryptDecryptFile(de.pixart.messenger.utils.EncryptDecryptFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 89 with Account

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

the class XmppConnectionService method sendReadMarker.

public void sendReadMarker(final Conversation conversation) {
    final boolean isPrivateAndNonAnonymousMuc = conversation.getMode() == Conversation.MODE_MULTI && conversation.isPrivateAndNonAnonymous();
    final Message markable = conversation.getLatestMarkableMessage(isPrivateAndNonAnonymousMuc);
    if (this.markRead(conversation)) {
        updateConversationUi();
    }
    if (confirmMessages() && markable != null && (markable.trusted() || isPrivateAndNonAnonymousMuc) && markable.getRemoteMsgId() != null) {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString());
        Account account = conversation.getAccount();
        final Jid to = markable.getCounterpart();
        final boolean groupChat = conversation.getMode() == Conversation.MODE_MULTI;
        MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId(), markable.getCounterpart(), groupChat);
        this.sendMessagePacket(conversation.getAccount(), packet);
    }
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) Account(de.pixart.messenger.entities.Account) XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message) Jid(de.pixart.messenger.xmpp.jid.Jid)

Example 90 with Account

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

the class XmppConnectionService method logoutAndSave.

private void logoutAndSave(boolean stop) {
    int activeAccounts = 0;
    for (final Account account : accounts) {
        if (account.getStatus() != Account.State.DISABLED) {
            activeAccounts++;
        }
        databaseBackend.writeRoster(account.getRoster());
        if (account.getXmppConnection() != null) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    disconnect(account, false);
                }
            }).start();
        }
    }
    if (stop || activeAccounts == 0) {
        Log.d(Config.LOGTAG, "good bye");
        stopSelf();
    }
}
Also used : Account(de.pixart.messenger.entities.Account) SuppressLint(android.annotation.SuppressLint)

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