use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method createAdhocConference.
public boolean createAdhocConference(final Account account, final String subject, final Iterable<Jid> jids, final UiCallback<Conversation> callback) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": creating adhoc conference with " + jids.toString());
if (account.getStatus() == Account.State.ONLINE) {
try {
String server = findConferenceServer(account);
if (server == null) {
if (callback != null) {
callback.error(R.string.no_conference_server_found, null);
}
return false;
}
final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true, false, true);
joinMuc(conversation, new OnConferenceJoined() {
@Override
public void onConferenceJoined(final Conversation conversation) {
pushConferenceConfiguration(conversation, IqGenerator.defaultRoomConfiguration(), new OnConfigurationPushed() {
@Override
public void onPushSucceeded() {
if (subject != null && !subject.trim().isEmpty()) {
pushSubjectToConference(conversation, subject.trim());
}
for (Jid invite : jids) {
invite(conversation, invite);
}
if (account.countPresences() > 1) {
directInvite(conversation, account.getJid().toBareJid());
}
saveConversationAsBookmark(conversation, subject);
if (callback != null) {
callback.success(conversation);
}
}
@Override
public void onPushFailed() {
archiveConversation(conversation);
if (callback != null) {
callback.error(R.string.conference_creation_failed, conversation);
}
}
});
}
});
return true;
} catch (InvalidJidException e) {
if (callback != null) {
callback.error(R.string.conference_creation_failed, null);
}
return true;
}
} else {
if (callback != null) {
callback.error(R.string.not_connected_try_again, null);
}
return true;
}
}
use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.
the class ExceptionHelper method checkForCrash.
public static boolean checkForCrash(XmppActivity activity) {
try {
final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService;
if (service == null) {
return false;
}
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
boolean crashreport = preferences.getBoolean("crashreport", activity.getResources().getBoolean(R.bool.send_crashreport));
if (!crashreport || Config.BUG_REPORTS == null) {
return false;
}
List<Account> accounts = service.getAccounts();
Account account = null;
for (int i = 0; i < accounts.size(); ++i) {
if (accounts.get(i).isEnabled()) {
account = accounts.get(i);
break;
}
}
if (account == null) {
return false;
}
final Account finalAccount = account;
FileInputStream file = activity.openFileInput(FILENAME);
InputStreamReader inputStreamReader = new InputStreamReader(file);
BufferedReader stacktrace = new BufferedReader(inputStreamReader);
final StringBuilder report = new StringBuilder();
PackageManager pm = activity.getPackageManager();
PackageInfo packageInfo;
try {
packageInfo = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES);
report.append("Version: ").append(packageInfo.versionName).append('\n');
report.append("Last Update: ").append(DATE_FORMAT.format(new Date(packageInfo.lastUpdateTime))).append('\n');
Signature[] signatures = packageInfo.signatures;
if (signatures != null && signatures.length >= 1) {
report.append("SHA-1: ").append(CryptoHelper.getFingerprintCert(packageInfo.signatures[0].toByteArray())).append('\n');
}
report.append('\n');
} catch (Exception e) {
e.printStackTrace();
return false;
}
String line;
while ((line = stacktrace.readLine()) != null) {
report.append(line);
report.append('\n');
}
file.close();
activity.deleteFile(FILENAME);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(activity.getString(R.string.crash_report_title));
builder.setMessage(activity.getText(R.string.crash_report_message));
builder.setPositiveButton(activity.getText(R.string.send_now), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d(Config.LOGTAG, "using account=" + finalAccount.getJid().toBareJid() + " to send in stack trace");
Conversation conversation = null;
try {
conversation = service.findOrCreateConversation(finalAccount, Jid.fromString(Config.BUG_REPORTS), false, true);
} catch (final InvalidJidException ignored) {
}
Message message = new Message(conversation, report.toString(), Message.ENCRYPTION_NONE);
service.sendMessage(message);
}
});
builder.setNegativeButton(activity.getText(R.string.send_never), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
preferences.edit().putBoolean("crash_report", false).apply();
}
});
builder.create().show();
return true;
} catch (final IOException ignored) {
return false;
}
}
use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.
the class DatabaseBackend method canonicalizeJids.
private void canonicalizeJids(SQLiteDatabase db) {
// migrate db to new, canonicalized JID domainpart representation
// Conversation table
Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME, new String[0]);
while (cursor.moveToNext()) {
String newJid;
try {
newJid = Jid.fromString(cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID))).toPreppedString();
} catch (InvalidJidException ignored) {
Log.e(Config.LOGTAG, "Failed to migrate Conversation CONTACTJID " + cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID)) + ": " + ignored + ". Skipping...");
continue;
}
String[] updateArgs = { newJid, cursor.getString(cursor.getColumnIndex(Conversation.UUID)) };
db.execSQL("update " + Conversation.TABLENAME + " set " + Conversation.CONTACTJID + " = ? " + " where " + Conversation.UUID + " = ?", updateArgs);
}
cursor.close();
// Contact table
cursor = db.rawQuery("select * from " + Contact.TABLENAME, new String[0]);
while (cursor.moveToNext()) {
String newJid;
try {
newJid = Jid.fromString(cursor.getString(cursor.getColumnIndex(Contact.JID))).toPreppedString();
} catch (InvalidJidException ignored) {
Log.e(Config.LOGTAG, "Failed to migrate Contact JID " + cursor.getString(cursor.getColumnIndex(Contact.JID)) + ": " + ignored + ". Skipping...");
continue;
}
String[] updateArgs = { newJid, cursor.getString(cursor.getColumnIndex(Contact.ACCOUNT)), cursor.getString(cursor.getColumnIndex(Contact.JID)) };
db.execSQL("update " + Contact.TABLENAME + " set " + Contact.JID + " = ? " + " where " + Contact.ACCOUNT + " = ? " + " AND " + Contact.JID + " = ?", updateArgs);
}
cursor.close();
// Account table
cursor = db.rawQuery("select * from " + Account.TABLENAME, new String[0]);
while (cursor.moveToNext()) {
String newServer;
try {
newServer = Jid.fromParts(cursor.getString(cursor.getColumnIndex(Account.USERNAME)), cursor.getString(cursor.getColumnIndex(Account.SERVER)), "mobile").getDomainpart();
} catch (InvalidJidException ignored) {
Log.e(Config.LOGTAG, "Failed to migrate Account SERVER " + cursor.getString(cursor.getColumnIndex(Account.SERVER)) + ": " + ignored + ". Skipping...");
continue;
}
String[] updateArgs = { newServer, cursor.getString(cursor.getColumnIndex(Account.UUID)) };
db.execSQL("update " + Account.TABLENAME + " set " + Account.SERVER + " = ? " + " where " + Account.UUID + " = ?", updateArgs);
}
cursor.close();
}
Aggregations