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