mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 16:33:39 +00:00
Distinguish between secure and insecure call in conversation menu.
// FREEBIE
This commit is contained in:
parent
c87012ea69
commit
31e20ca87e
BIN
res/drawable-hdpi/ic_call_secure_white_24dp.png
Normal file
BIN
res/drawable-hdpi/ic_call_secure_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
res/drawable-mdpi/ic_call_secure_white_24dp.png
Normal file
BIN
res/drawable-mdpi/ic_call_secure_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 958 B |
BIN
res/drawable-xhdpi/ic_call_secure_white_24dp.png
Normal file
BIN
res/drawable-xhdpi/ic_call_secure_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
res/drawable-xxhdpi/ic_call_secure_white_24dp.png
Normal file
BIN
res/drawable-xxhdpi/ic_call_secure_white_24dp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 925 B |
@ -2,7 +2,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:title="@string/conversation_callable__menu_call"
|
||||
android:id="@+id/menu_call"
|
||||
android:id="@+id/menu_call_insecure"
|
||||
android:icon="?menu_call_icon"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
10
res/menu/conversation_callable_secure.xml
Normal file
10
res/menu/conversation_callable_secure.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:title="@string/conversation_callable__menu_call"
|
||||
android:id="@+id/menu_call_secure"
|
||||
android:icon="@drawable/ic_call_secure_white_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item android:title="@string/conversation_secure_verified__menu_security"
|
||||
android:id="@+id/menu_security"
|
||||
android:icon="?menu_lock_icon"
|
||||
app:showAsAction="ifRoom">
|
||||
<menu>
|
||||
<item android:title="@string/conversation_secure_verified__menu_verify_identity"
|
||||
android:id="@+id/menu_verify_identity"/>
|
||||
</menu>
|
||||
</item>
|
||||
</menu>
|
@ -659,6 +659,7 @@
|
||||
<string name="recipient_preferences__block">Block</string>
|
||||
<string name="recipient_preferences__color">Color</string>
|
||||
<string name="recipient_preferences__color_for_this_contact">Color for this contact</string>
|
||||
<string name="recipient_preferences__verify_identity">Verify identity</string>
|
||||
|
||||
<!--- redphone_call_controls -->
|
||||
<string name="redphone_call_card__signal_call">Signal Call</string>
|
||||
@ -937,7 +938,7 @@
|
||||
<!-- refreshing push directory from menu -->
|
||||
<string name="push_directory__menu_refresh">Refresh contact list</string>
|
||||
|
||||
<!-- conversation_callable -->
|
||||
<!-- conversation_callable_insecure -->
|
||||
<string name="conversation_callable__menu_call">Call</string>
|
||||
|
||||
<!-- conversation_context -->
|
||||
@ -993,7 +994,7 @@
|
||||
<!-- conversation_popup -->
|
||||
<string name="conversation_popup__menu_expand_popup">Expand popup</string>
|
||||
|
||||
<!-- conversation_callable -->
|
||||
<!-- conversation_callable_insecure -->
|
||||
<string name="conversation_add_to_contacts__menu_add_to_contacts">Add to contacts</string>
|
||||
|
||||
<!-- conversation_group_options -->
|
||||
|
@ -36,9 +36,13 @@
|
||||
android:persistent="false"
|
||||
app:numColumns="5" />
|
||||
|
||||
<Preference android:key="pref_key_recipient_identity"
|
||||
android:title="@string/recipient_preferences__verify_identity"
|
||||
android:persistent="false"/>
|
||||
|
||||
<Preference android:key="pref_key_recipient_block"
|
||||
android:title="@string/recipient_preferences__block" />
|
||||
android:title="@string/recipient_preferences__block"
|
||||
android:persistent="false"/>
|
||||
|
||||
|
||||
</PreferenceScreen>
|
@ -39,6 +39,7 @@ import android.support.v4.view.WindowCompat;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -84,8 +85,6 @@ import org.thoughtcrime.securesms.database.DraftDatabase.Draft;
|
||||
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.database.MmsSmsColumns.Types;
|
||||
import org.thoughtcrime.securesms.database.NotInDirectoryException;
|
||||
import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.mms.AttachmentManager;
|
||||
import org.thoughtcrime.securesms.mms.AttachmentManager.MediaType;
|
||||
@ -111,7 +110,8 @@ import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||
import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState;
|
||||
import org.thoughtcrime.securesms.util.Dialogs;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper.RegistrationState;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
@ -121,7 +121,6 @@ import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -188,7 +187,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
private Recipients recipients;
|
||||
private long threadId;
|
||||
private int distributionType;
|
||||
private boolean isEncryptedConversation;
|
||||
private boolean isSecureText;
|
||||
private boolean isSecureVoice;
|
||||
private boolean isMmsEnabled = true;
|
||||
|
||||
private DynamicTheme dynamicTheme = new DynamicTheme();
|
||||
@ -215,7 +215,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
initializeActionBar();
|
||||
initializeViews();
|
||||
initializeResources();
|
||||
initializeSecurity(false);
|
||||
initializeSecurity(false, false);
|
||||
initializeDraft();
|
||||
}
|
||||
|
||||
@ -231,7 +231,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
setIntent(intent);
|
||||
initializeResources();
|
||||
initializeSecurity(false);
|
||||
initializeSecurity(false, false);
|
||||
initializeDraft();
|
||||
|
||||
if (fragment != null) {
|
||||
@ -326,15 +326,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
MenuInflater inflater = this.getMenuInflater();
|
||||
menu.clear();
|
||||
|
||||
if (isSingleConversation() && isEncryptedConversation) {
|
||||
inflater.inflate(R.menu.conversation_secure_identity, menu);
|
||||
inflater.inflate(R.menu.conversation_secure_sms, menu.findItem(R.id.menu_security).getSubMenu());
|
||||
} else if (isSingleConversation()) {
|
||||
inflater.inflate(R.menu.conversation_insecure, menu);
|
||||
}
|
||||
|
||||
if (isSingleConversation()) {
|
||||
inflater.inflate(R.menu.conversation_callable, menu);
|
||||
if (isSecureVoice) inflater.inflate(R.menu.conversation_callable_secure, menu);
|
||||
else inflater.inflate(R.menu.conversation_callable_insecure, menu);
|
||||
} else if (isGroupConversation()) {
|
||||
inflater.inflate(R.menu.conversation_group_options, menu);
|
||||
|
||||
@ -352,6 +346,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
inflater.inflate(R.menu.conversation, menu);
|
||||
|
||||
if (isSingleConversation() && isSecureText) {
|
||||
inflater.inflate(R.menu.conversation_secure, menu);
|
||||
} else if (isSingleConversation()) {
|
||||
inflater.inflate(R.menu.conversation_insecure, menu);
|
||||
}
|
||||
|
||||
if (recipients != null && recipients.isMuted()) inflater.inflate(R.menu.conversation_muted, menu);
|
||||
else inflater.inflate(R.menu.conversation_unmuted, menu);
|
||||
|
||||
@ -367,13 +367,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
super.onOptionsItemSelected(item);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_call: handleDial(getRecipients().getPrimaryRecipient()); return true;
|
||||
case R.id.menu_call_secure:
|
||||
case R.id.menu_call_insecure: handleDial(getRecipients().getPrimaryRecipient()); return true;
|
||||
case R.id.menu_delete_thread: handleDeleteThread(); return true;
|
||||
case R.id.menu_add_attachment: handleAddAttachment(); return true;
|
||||
case R.id.menu_view_media: handleViewMedia(); return true;
|
||||
case R.id.menu_add_to_contacts: handleAddToContacts(); return true;
|
||||
case R.id.menu_abort_session: handleAbortSecureSession(); return true;
|
||||
case R.id.menu_verify_identity: handleVerifyIdentity(); return true;
|
||||
case R.id.menu_group_recipients: handleDisplayGroupRecipients(); return true;
|
||||
case R.id.menu_distribution_broadcast: handleDistributionBroadcastEnabled(item); return true;
|
||||
case R.id.menu_distribution_conversation: handleDistributionConversationEnabled(item); return true;
|
||||
@ -479,12 +479,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void handleVerifyIdentity() {
|
||||
Intent verifyIdentityIntent = new Intent(this, VerifyIdentityActivity.class);
|
||||
verifyIdentityIntent.putExtra("recipient", getRecipients().getPrimaryRecipient().getRecipientId());
|
||||
startActivity(verifyIdentityIntent);
|
||||
}
|
||||
|
||||
private void handleAbortSecureSession() {
|
||||
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(this);
|
||||
builder.setTitle(R.string.ConversationActivity_abort_secure_session_confirmation);
|
||||
@ -607,30 +601,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
private void handleDial(final Recipient recipient) {
|
||||
if (recipient == null) return;
|
||||
|
||||
new AsyncTask<Recipient, Void, Boolean>() {
|
||||
@Override
|
||||
protected Boolean doInBackground(Recipient... params) {
|
||||
try {
|
||||
Context context = ConversationActivity.this;
|
||||
Recipient recipient = params[0];
|
||||
String e164number = Util.canonicalizeNumber(context, recipient.getNumber());
|
||||
|
||||
return TextSecureDirectory.getInstance(context).isSecureVoiceSupported(e164number);
|
||||
} catch (InvalidNumberException | NotInDirectoryException e) {
|
||||
Log.w(TAG, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean secureVoiceSupported) {
|
||||
handleDial(recipient, secureVoiceSupported);
|
||||
}
|
||||
}.execute(recipient);
|
||||
}
|
||||
|
||||
private void handleDial(Recipient recipient, boolean secureVoice) {
|
||||
if (secureVoice) {
|
||||
if (isSecureVoice) {
|
||||
Intent intent = new Intent(this, RedPhoneService.class);
|
||||
intent.setAction(RedPhoneService.ACTION_OUTGOING_CALL);
|
||||
intent.putExtra(RedPhoneService.EXTRA_REMOTE_NUMBER, recipient.getNumber());
|
||||
@ -687,7 +658,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void handleAddAttachment() {
|
||||
if (this.isMmsEnabled || isEncryptedConversation) {
|
||||
if (this.isMmsEnabled || isSecureText) {
|
||||
new AlertDialogWrapper.Builder(this).setAdapter(attachmentAdapter, new AttachmentTypeListener())
|
||||
.show();
|
||||
} else {
|
||||
@ -703,17 +674,19 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void handleSecurityChange(boolean encryptedConversation) {
|
||||
boolean isMediaMessage = !recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent();
|
||||
this.isEncryptedConversation = encryptedConversation;
|
||||
private void handleSecurityChange(boolean isSecureText, boolean isSecureVoice) {
|
||||
this.isSecureText = isSecureText;
|
||||
this.isSecureVoice = isSecureVoice;
|
||||
|
||||
boolean isMediaMessage = !recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent();
|
||||
|
||||
sendButton.resetAvailableTransports(isMediaMessage);
|
||||
|
||||
if (!isEncryptedConversation) sendButton.disableTransport(Type.TEXTSECURE);
|
||||
if (!isSecureText) sendButton.disableTransport(Type.TEXTSECURE);
|
||||
if (recipients.isGroupRecipient()) sendButton.disableTransport(Type.SMS);
|
||||
|
||||
if (isEncryptedConversation) sendButton.setDefaultTransport(Type.TEXTSECURE);
|
||||
else sendButton.setDefaultTransport(Type.SMS);
|
||||
if (isSecureText) sendButton.setDefaultTransport(Type.TEXTSECURE);
|
||||
else sendButton.setDefaultTransport(Type.SMS);
|
||||
|
||||
calculateCharactersRemaining();
|
||||
supportInvalidateOptionsMenu();
|
||||
@ -778,30 +751,38 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void initializeSecurity(final boolean current) {
|
||||
handleSecurityChange(current || isGroupConversation());
|
||||
private void initializeSecurity(final boolean currentSecureText,
|
||||
final boolean currentSecureVoice)
|
||||
{
|
||||
handleSecurityChange(currentSecureText || isGroupConversation(),
|
||||
currentSecureVoice && !isGroupConversation());
|
||||
|
||||
new AsyncTask<Recipients, Void, Boolean>() {
|
||||
new AsyncTask<Recipients, Void, Pair<Boolean, Boolean>>() {
|
||||
@Override
|
||||
protected Boolean doInBackground(Recipients... params) {
|
||||
protected Pair<Boolean, Boolean> doInBackground(Recipients... params) {
|
||||
try {
|
||||
Context context = ConversationActivity.this;
|
||||
Recipients recipients = params[0];
|
||||
RegistrationState registrationState = DirectoryHelper.isTextSecureEnabledRecipient(context, recipients);
|
||||
Context context = ConversationActivity.this;
|
||||
Recipients recipients = params[0];
|
||||
UserCapabilities capabilities = DirectoryHelper.getUserCapabilities(context, recipients);
|
||||
|
||||
if (registrationState == RegistrationState.NOT_REGISTERED) return false;
|
||||
else if (registrationState == RegistrationState.REGISTERED) return true;
|
||||
else return DirectoryHelper.refreshDirectoryFor(context, recipients) == RegistrationState.REGISTERED;
|
||||
if (capabilities.getTextCapability() == Capability.UNKNOWN ||
|
||||
capabilities.getVoiceCapability() == Capability.UNKNOWN)
|
||||
{
|
||||
capabilities = DirectoryHelper.refreshDirectoryFor(context, recipients);
|
||||
}
|
||||
|
||||
return new Pair<>(capabilities.getTextCapability() == Capability.SUPPORTED,
|
||||
capabilities.getVoiceCapability() == Capability.SUPPORTED);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
return false;
|
||||
return new Pair<>(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (current != result) {
|
||||
handleSecurityChange(result);
|
||||
protected void onPostExecute(Pair<Boolean, Boolean> result) {
|
||||
if (result.first != currentSecureText || result.second != currentSecureVoice) {
|
||||
handleSecurityChange(result.first, result.second);
|
||||
}
|
||||
}
|
||||
}.execute(recipients);
|
||||
@ -944,7 +925,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
securityUpdateReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
initializeSecurity(isEncryptedConversation);
|
||||
initializeSecurity(isSecureText, isSecureVoice);
|
||||
calculateCharactersRemaining();
|
||||
}
|
||||
};
|
||||
@ -1249,7 +1230,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
OutgoingMediaMessage outgoingMessage = new OutgoingMediaMessage(this, recipients, slideDeck,
|
||||
getMessage(), distributionType);
|
||||
|
||||
if (isEncryptedConversation && !forceSms) {
|
||||
if (isSecureText && !forceSms) {
|
||||
outgoingMessage = new OutgoingSecureMediaMessage(outgoingMessage);
|
||||
}
|
||||
|
||||
@ -1275,7 +1256,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
final Context context = getApplicationContext();
|
||||
OutgoingTextMessage message;
|
||||
|
||||
if (isEncryptedConversation && !forceSms) {
|
||||
if (isSecureText && !forceSms) {
|
||||
message = new OutgoingEncryptedMessage(recipients, getMessage());
|
||||
} else {
|
||||
message = new OutgoingTextMessage(recipients, getMessage());
|
||||
|
@ -173,7 +173,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity {
|
||||
|
||||
private static boolean isActiveInDirectory(Context context, Recipient recipient) {
|
||||
try {
|
||||
if (!TextSecureDirectory.getInstance(context).isActiveNumber(Util.canonicalizeNumber(context, recipient.getNumber()))) {
|
||||
if (!TextSecureDirectory.getInstance(context).isSecureTextSupported(Util.canonicalizeNumber(context, recipient.getNumber()))) {
|
||||
return false;
|
||||
}
|
||||
} catch (NotInDirectoryException e) {
|
||||
|
@ -44,11 +44,12 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
|
||||
public static final String RECIPIENTS_EXTRA = "recipient_ids";
|
||||
|
||||
private static final String PREFERENCE_MUTED = "pref_key_recipient_mute";
|
||||
private static final String PREFERENCE_TONE = "pref_key_recipient_ringtone";
|
||||
private static final String PREFERENCE_VIBRATE = "pref_key_recipient_vibrate";
|
||||
private static final String PREFERENCE_BLOCK = "pref_key_recipient_block";
|
||||
private static final String PREFERENCE_COLOR = "pref_key_recipient_color";
|
||||
private static final String PREFERENCE_MUTED = "pref_key_recipient_mute";
|
||||
private static final String PREFERENCE_TONE = "pref_key_recipient_ringtone";
|
||||
private static final String PREFERENCE_VIBRATE = "pref_key_recipient_vibrate";
|
||||
private static final String PREFERENCE_BLOCK = "pref_key_recipient_block";
|
||||
private static final String PREFERENCE_COLOR = "pref_key_recipient_color";
|
||||
private static final String PREFERENCE_IDENTITY = "pref_key_recipient_identity";
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
@ -171,7 +172,9 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
.setOnPreferenceClickListener(new BlockClickedListener());
|
||||
this.findPreference(PREFERENCE_COLOR)
|
||||
.setOnPreferenceChangeListener(new ColorChangeListener());
|
||||
}
|
||||
this.findPreference(PREFERENCE_IDENTITY)
|
||||
.setOnPreferenceClickListener(new IdentityClickedListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
@ -191,6 +194,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
ListPreference vibratePreference = (ListPreference) this.findPreference(PREFERENCE_VIBRATE);
|
||||
ColorPreference colorPreference = (ColorPreference) this.findPreference(PREFERENCE_COLOR);
|
||||
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
|
||||
Preference identityPreference = this.findPreference(PREFERENCE_IDENTITY);
|
||||
|
||||
mutePreference.setChecked(recipients.isMuted());
|
||||
|
||||
@ -222,8 +226,11 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
|
||||
if (!recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
|
||||
blockPreference.setEnabled(false);
|
||||
identityPreference.setEnabled(false);
|
||||
} else {
|
||||
blockPreference.setEnabled(true);
|
||||
identityPreference.setEnabled(true);
|
||||
|
||||
if (recipients.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
|
||||
else blockPreference.setTitle(R.string.RecipientPreferenceActivity_block);
|
||||
}
|
||||
@ -352,6 +359,17 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
}
|
||||
}
|
||||
|
||||
private class IdentityClickedListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent verifyIdentityIntent = new Intent(getActivity(), VerifyIdentityActivity.class);
|
||||
verifyIdentityIntent.putExtra("recipient", recipients.getPrimaryRecipient().getRecipientId());
|
||||
startActivity(verifyIdentityIntent);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class BlockClickedListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
@ -66,7 +66,7 @@ public class TextSecureDirectory {
|
||||
this.databaseHelper = new DatabaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
public boolean isActiveNumber(String e164number) throws NotInDirectoryException {
|
||||
public boolean isSecureTextSupported(String e164number) throws NotInDirectoryException {
|
||||
if (e164number == null || e164number.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public abstract class PushReceivedJob extends ContextJob {
|
||||
boolean isActiveNumber;
|
||||
|
||||
try {
|
||||
isActiveNumber = TextSecureDirectory.getInstance(context).isActiveNumber(e164number);
|
||||
isActiveNumber = TextSecureDirectory.getInstance(context).isSecureTextSupported(e164number);
|
||||
} catch (NotInDirectoryException e) {
|
||||
isActiveNumber = false;
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ public class MessageSender {
|
||||
TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
|
||||
|
||||
try {
|
||||
return directory.isActiveNumber(destination);
|
||||
return directory.isSecureTextSupported(destination);
|
||||
} catch (NotInDirectoryException e) {
|
||||
try {
|
||||
TextSecureAccountManager accountManager = TextSecureCommunicationFactory.createManager(context);
|
||||
|
@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
||||
import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob;
|
||||
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.textsecure.api.TextSecureAccountManager;
|
||||
import org.whispersystems.textsecure.api.push.ContactTokenDetails;
|
||||
@ -29,8 +30,30 @@ import java.util.Set;
|
||||
|
||||
public class DirectoryHelper {
|
||||
|
||||
public enum RegistrationState {
|
||||
REGISTERED, NOT_REGISTERED, UNKNOWN
|
||||
public static class UserCapabilities {
|
||||
|
||||
public static final UserCapabilities UNKNOWN = new UserCapabilities(Capability.UNKNOWN, Capability.UNKNOWN);
|
||||
public static final UserCapabilities UNSUPPORTED = new UserCapabilities(Capability.UNSUPPORTED, Capability.UNSUPPORTED);
|
||||
|
||||
public enum Capability {
|
||||
UNKNOWN, SUPPORTED, UNSUPPORTED
|
||||
}
|
||||
|
||||
private final Capability text;
|
||||
private final Capability voice;
|
||||
|
||||
public UserCapabilities(Capability text, Capability voice) {
|
||||
this.text = text;
|
||||
this.voice = voice;
|
||||
}
|
||||
|
||||
public Capability getTextCapability() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public Capability getVoiceCapability() {
|
||||
return voice;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TAG = DirectoryHelper.class.getSimpleName();
|
||||
@ -77,7 +100,7 @@ public class DirectoryHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static RegistrationState refreshDirectoryFor(Context context, Recipients recipients)
|
||||
public static UserCapabilities refreshDirectoryFor(Context context, Recipients recipients)
|
||||
throws IOException
|
||||
{
|
||||
try {
|
||||
@ -90,52 +113,55 @@ public class DirectoryHelper {
|
||||
if (details.isPresent()) {
|
||||
directory.setNumber(details.get(), true);
|
||||
ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
|
||||
return RegistrationState.REGISTERED;
|
||||
return new UserCapabilities(Capability.SUPPORTED, details.get().isVoice() ? Capability.SUPPORTED : Capability.UNSUPPORTED);
|
||||
} else {
|
||||
ContactTokenDetails absent = new ContactTokenDetails();
|
||||
absent.setNumber(number);
|
||||
directory.setNumber(absent, false);
|
||||
return RegistrationState.NOT_REGISTERED;
|
||||
return UserCapabilities.UNSUPPORTED;
|
||||
}
|
||||
} catch (InvalidNumberException e) {
|
||||
Log.w(TAG, e);
|
||||
return RegistrationState.NOT_REGISTERED;
|
||||
return UserCapabilities.UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
public static RegistrationState isTextSecureEnabledRecipient(Context context, Recipients recipients) {
|
||||
public static UserCapabilities getUserCapabilities(Context context, Recipients recipients) {
|
||||
try {
|
||||
if (recipients == null) {
|
||||
return RegistrationState.NOT_REGISTERED;
|
||||
return UserCapabilities.UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (!TextSecurePreferences.isPushRegistered(context)) {
|
||||
return RegistrationState.NOT_REGISTERED;
|
||||
return UserCapabilities.UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (!recipients.isSingleRecipient()) {
|
||||
return RegistrationState.NOT_REGISTERED;
|
||||
return UserCapabilities.UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (recipients.isGroupRecipient()) {
|
||||
return RegistrationState.REGISTERED;
|
||||
return new UserCapabilities(Capability.SUPPORTED, Capability.UNSUPPORTED);
|
||||
}
|
||||
|
||||
final String number = recipients.getPrimaryRecipient().getNumber();
|
||||
|
||||
if (number == null) {
|
||||
return RegistrationState.NOT_REGISTERED;
|
||||
return UserCapabilities.UNSUPPORTED;
|
||||
}
|
||||
|
||||
final String e164number = Util.canonicalizeNumber(context, number);
|
||||
String e164number = Util.canonicalizeNumber(context, number);
|
||||
boolean secureText = TextSecureDirectory.getInstance(context).isSecureTextSupported(e164number);
|
||||
boolean secureVoice = TextSecureDirectory.getInstance(context).isSecureVoiceSupported(e164number);
|
||||
|
||||
return new UserCapabilities(secureText ? Capability.SUPPORTED : Capability.UNSUPPORTED,
|
||||
secureVoice ? Capability.SUPPORTED : Capability.UNSUPPORTED);
|
||||
|
||||
return TextSecureDirectory.getInstance(context).isActiveNumber(e164number) ?
|
||||
RegistrationState.REGISTERED : RegistrationState.NOT_REGISTERED;
|
||||
} catch (InvalidNumberException e) {
|
||||
Log.w(TAG, e);
|
||||
return RegistrationState.NOT_REGISTERED;
|
||||
return UserCapabilities.UNSUPPORTED;
|
||||
} catch (NotInDirectoryException e) {
|
||||
return RegistrationState.UNKNOWN;
|
||||
return UserCapabilities.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user