Don't use AsyncTask for beta calling capabilities refresh

Also, actually store the result in the directory db.

Fixes #6212
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-02-12 11:27:26 -08:00
parent 6b737a3d48
commit 0efd6d9341
2 changed files with 21 additions and 18 deletions

View File

@ -917,7 +917,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
UserCapabilities capabilities = DirectoryHelper.getUserCapabilities(context, recipients); UserCapabilities capabilities = DirectoryHelper.getUserCapabilities(context, recipients);
if (capabilities.getTextCapability() == Capability.UNKNOWN || if (capabilities.getTextCapability() == Capability.UNKNOWN ||
capabilities.getVoiceCapability() == Capability.UNKNOWN) capabilities.getVideoCapability() == Capability.UNKNOWN)
{ {
try { try {
capabilities = DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipients, capabilities = DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipients,
@ -928,7 +928,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
return new boolean[] {capabilities.getTextCapability() == Capability.SUPPORTED, return new boolean[] {capabilities.getTextCapability() == Capability.SUPPORTED,
capabilities.getVoiceCapability() == Capability.SUPPORTED && !isSelfConversation(), capabilities.getVideoCapability() == Capability.SUPPORTED && !isSelfConversation(),
Util.isDefaultSmsProvider(context)}; Util.isDefaultSmsProvider(context)};
} }
@ -950,31 +950,32 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
return; return;
} }
new AsyncTask<Void, Void, boolean[]>() { new Thread() {
@Override @Override
protected boolean[] doInBackground(Void... params) { public void run() {
try { try {
Context context = ConversationActivity.this; Context context = ConversationActivity.this;
UserCapabilities userCapabilities = DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipients, UserCapabilities userCapabilities = DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipients,
TextSecurePreferences.getLocalNumber(context)); TextSecurePreferences.getLocalNumber(context));
return new boolean[] {userCapabilities.getTextCapability() == Capability.SUPPORTED, final boolean secureText = userCapabilities.getTextCapability() == Capability.SUPPORTED;
userCapabilities.getVideoCapability() == Capability.SUPPORTED && !isSelfConversation(), final boolean secureVideo = userCapabilities.getVideoCapability() == Capability.SUPPORTED;
Util.isDefaultSmsProvider(context)}; final boolean defaultSms = Util.isDefaultSmsProvider(context);
Util.runOnMain(new Runnable() {
@Override
public void run() {
if (secureText != isSecureText || secureVideo != isSecureVideo || defaultSms != isDefaultSms) {
handleSecurityChange(secureText, secureVideo, defaultSms);
}
}
});
} catch (IOException e) { } catch (IOException e) {
Log.w(TAG, e); Log.w(TAG, e);
return null;
} }
} }
}.start();
@Override
protected void onPostExecute(boolean[] result) {
if (result != null && (result[0] != isSecureText || result[1] != isSecureVideo || result[2] != isDefaultSms)) {
handleSecurityChange(result[0], result[1], result[2]);
}
}
}.execute();
} }
private void onSecurityUpdated() { private void onSecurityUpdated() {

View File

@ -166,9 +166,11 @@ public class TextSecureDirectory {
SQLiteDatabase db = databaseHelper.getWritableDatabase(); SQLiteDatabase db = databaseHelper.getWritableDatabase();
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(NUMBER, token.getNumber()); values.put(NUMBER, token.getNumber());
values.put(RELAY, token.getRelay());
values.put(REGISTERED, active ? 1 : 0); values.put(REGISTERED, active ? 1 : 0);
values.put(TIMESTAMP, System.currentTimeMillis()); values.put(TIMESTAMP, System.currentTimeMillis());
values.put(RELAY, token.getRelay());
values.put(VOICE, token.isVoice());
values.put(VIDEO, token.isVideo());
db.replace(TABLE_NAME, null, values); db.replace(TABLE_NAME, null, values);
} }