mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Make default SMS provider lookup asynchronous
// FREEBIE
This commit is contained in:
parent
f0b615eda6
commit
4906bdbdcc
@ -191,6 +191,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
private static final int ADD_CONTACT = 7;
|
private static final int ADD_CONTACT = 7;
|
||||||
private static final int PICK_LOCATION = 8;
|
private static final int PICK_LOCATION = 8;
|
||||||
private static final int PICK_GIF = 9;
|
private static final int PICK_GIF = 9;
|
||||||
|
private static final int SMS_DEFAULT = 10;
|
||||||
|
|
||||||
private MasterSecret masterSecret;
|
private MasterSecret masterSecret;
|
||||||
protected ComposeText composeText;
|
protected ComposeText composeText;
|
||||||
@ -222,6 +223,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
private boolean archived;
|
private boolean archived;
|
||||||
private boolean isSecureText;
|
private boolean isSecureText;
|
||||||
private boolean isSecureVoice;
|
private boolean isSecureVoice;
|
||||||
|
private boolean isDefaultSms = true;
|
||||||
private boolean isMmsEnabled = true;
|
private boolean isMmsEnabled = true;
|
||||||
|
|
||||||
private DynamicTheme dynamicTheme = new DynamicTheme();
|
private DynamicTheme dynamicTheme = new DynamicTheme();
|
||||||
@ -248,7 +250,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
initializeActionBar();
|
initializeActionBar();
|
||||||
initializeViews();
|
initializeViews();
|
||||||
initializeResources();
|
initializeResources();
|
||||||
initializeSecurity(false, false).addListener(new AssertedSuccessListener<Boolean>() {
|
initializeSecurity(false, false, isDefaultSms).addListener(new AssertedSuccessListener<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Boolean result) {
|
public void onSuccess(Boolean result) {
|
||||||
initializeDraft();
|
initializeDraft();
|
||||||
@ -273,7 +275,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
|
|
||||||
setIntent(intent);
|
setIntent(intent);
|
||||||
initializeResources();
|
initializeResources();
|
||||||
initializeSecurity(false, false).addListener(new AssertedSuccessListener<Boolean>() {
|
initializeSecurity(false, false, isDefaultSms).addListener(new AssertedSuccessListener<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Boolean result) {
|
public void onSuccess(Boolean result) {
|
||||||
initializeDraft();
|
initializeDraft();
|
||||||
@ -298,7 +300,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
|
|
||||||
titleView.setTitle(recipients);
|
titleView.setTitle(recipients);
|
||||||
setActionBarColor(recipients.getColor());
|
setActionBarColor(recipients.getColor());
|
||||||
setBlockedUserState(recipients, isSecureText);
|
setBlockedUserState(recipients, isSecureText, isDefaultSms);
|
||||||
calculateCharactersRemaining();
|
calculateCharactersRemaining();
|
||||||
|
|
||||||
MessageNotifier.setVisibleThread(threadId);
|
MessageNotifier.setVisibleThread(threadId);
|
||||||
@ -339,7 +341,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
Log.w(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data);
|
Log.w(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data);
|
||||||
super.onActivityResult(reqCode, resultCode, data);
|
super.onActivityResult(reqCode, resultCode, data);
|
||||||
|
|
||||||
if (data == null && reqCode != TAKE_PHOTO || resultCode != RESULT_OK) return;
|
if ((data == null && reqCode != TAKE_PHOTO) || (resultCode != RESULT_OK && reqCode != SMS_DEFAULT)) return;
|
||||||
|
|
||||||
switch (reqCode) {
|
switch (reqCode) {
|
||||||
case PICK_IMAGE:
|
case PICK_IMAGE:
|
||||||
@ -359,7 +361,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
recipients = RecipientFactory.getRecipientsForIds(this, data.getLongArrayExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA), true);
|
recipients = RecipientFactory.getRecipientsForIds(this, data.getLongArrayExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA), true);
|
||||||
recipients.addListener(this);
|
recipients.addListener(this);
|
||||||
titleView.setTitle(recipients);
|
titleView.setTitle(recipients);
|
||||||
setBlockedUserState(recipients, isSecureText);
|
setBlockedUserState(recipients, isSecureText, isDefaultSms);
|
||||||
supportInvalidateOptionsMenu();
|
supportInvalidateOptionsMenu();
|
||||||
break;
|
break;
|
||||||
case TAKE_PHOTO:
|
case TAKE_PHOTO:
|
||||||
@ -382,6 +384,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
case ScribbleActivity.SCRIBBLE_REQUEST_CODE:
|
case ScribbleActivity.SCRIBBLE_REQUEST_CODE:
|
||||||
setMedia(data.getData(), MediaType.IMAGE);
|
setMedia(data.getData(), MediaType.IMAGE);
|
||||||
break;
|
break;
|
||||||
|
case SMS_DEFAULT:
|
||||||
|
initializeSecurity(isSecureText, isSecureText, isDefaultSms);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,7 +608,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
private void handleMakeDefaultSms() {
|
private void handleMakeDefaultSms() {
|
||||||
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
|
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
|
||||||
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());
|
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());
|
||||||
startActivity(intent);
|
startActivityForResult(intent, SMS_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleInviteLink() {
|
private void handleInviteLink() {
|
||||||
@ -791,9 +796,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSecurityChange(boolean isSecureText, boolean isSecureVoice) {
|
private void handleSecurityChange(boolean isSecureText, boolean isSecureVoice, boolean isDefaultSms) {
|
||||||
this.isSecureText = isSecureText;
|
this.isSecureText = isSecureText;
|
||||||
this.isSecureVoice = isSecureVoice;
|
this.isSecureVoice = isSecureVoice;
|
||||||
|
this.isDefaultSms = isDefaultSms;
|
||||||
|
|
||||||
boolean isMediaMessage = !recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent();
|
boolean isMediaMessage = !recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent();
|
||||||
|
|
||||||
@ -807,7 +813,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
|
|
||||||
calculateCharactersRemaining();
|
calculateCharactersRemaining();
|
||||||
supportInvalidateOptionsMenu();
|
supportInvalidateOptionsMenu();
|
||||||
setBlockedUserState(recipients, isSecureText);
|
setBlockedUserState(recipients, isSecureText, isDefaultSms);
|
||||||
}
|
}
|
||||||
|
|
||||||
///// Initializers
|
///// Initializers
|
||||||
@ -873,16 +879,18 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<Boolean> initializeSecurity(final boolean currentSecureText,
|
private ListenableFuture<Boolean> initializeSecurity(final boolean currentSecureText,
|
||||||
final boolean currentSecureVoice)
|
final boolean currentSecureVoice,
|
||||||
|
final boolean currentIsDefaultSms)
|
||||||
{
|
{
|
||||||
final SettableFuture<Boolean> future = new SettableFuture<>();
|
final SettableFuture<Boolean> future = new SettableFuture<>();
|
||||||
|
|
||||||
handleSecurityChange(currentSecureText || isPushGroupConversation(),
|
handleSecurityChange(currentSecureText || isPushGroupConversation(),
|
||||||
currentSecureVoice && !isGroupConversation());
|
currentSecureVoice && !isGroupConversation(),
|
||||||
|
currentIsDefaultSms);
|
||||||
|
|
||||||
new AsyncTask<Recipients, Void, Pair<Boolean, Boolean>>() {
|
new AsyncTask<Recipients, Void, boolean[]>() {
|
||||||
@Override
|
@Override
|
||||||
protected Pair<Boolean, Boolean> doInBackground(Recipients... params) {
|
protected boolean[] doInBackground(Recipients... params) {
|
||||||
try {
|
try {
|
||||||
Context context = ConversationActivity.this;
|
Context context = ConversationActivity.this;
|
||||||
Recipients recipients = params[0];
|
Recipients recipients = params[0];
|
||||||
@ -895,19 +903,19 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
TextSecurePreferences.getLocalNumber(context));
|
TextSecurePreferences.getLocalNumber(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Pair<>(capabilities.getTextCapability() == Capability.SUPPORTED,
|
return new boolean[] {capabilities.getTextCapability() == Capability.SUPPORTED,
|
||||||
capabilities.getVoiceCapability() == Capability.SUPPORTED &&
|
capabilities.getVoiceCapability() == Capability.SUPPORTED && !isSelfConversation(),
|
||||||
!isSelfConversation());
|
Util.isDefaultSmsProvider(context)};
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
return new Pair<>(false, false);
|
return new boolean[]{false, false, false};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Pair<Boolean, Boolean> result) {
|
protected void onPostExecute(boolean[] result) {
|
||||||
if (result.first != currentSecureText || result.second != currentSecureVoice) {
|
if (result[0] != currentSecureText || result[1] != currentSecureVoice || result[2] != currentIsDefaultSms) {
|
||||||
handleSecurityChange(result.first, result.second);
|
handleSecurityChange(result[0], result[1], result[2]);
|
||||||
}
|
}
|
||||||
future.set(true);
|
future.set(true);
|
||||||
onSecurityUpdated();
|
onSecurityUpdated();
|
||||||
@ -1092,7 +1100,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
titleView.setTitle(recipients);
|
titleView.setTitle(recipients);
|
||||||
setBlockedUserState(recipients, isSecureText);
|
setBlockedUserState(recipients, isSecureText, isDefaultSms);
|
||||||
setActionBarColor(recipients.getColor());
|
setActionBarColor(recipients.getColor());
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
updateRecipientPreferences();
|
updateRecipientPreferences();
|
||||||
@ -1104,7 +1112,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
securityUpdateReceiver = new BroadcastReceiver() {
|
securityUpdateReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
initializeSecurity(isSecureText, isSecureVoice);
|
initializeSecurity(isSecureText, isSecureVoice, isDefaultSms);
|
||||||
calculateCharactersRemaining();
|
calculateCharactersRemaining();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1258,12 +1266,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
setStatusBarColor(color.toStatusBarColor(this));
|
setStatusBarColor(color.toStatusBarColor(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBlockedUserState(Recipients recipients, boolean isSecureText) {
|
private void setBlockedUserState(Recipients recipients, boolean isSecureText, boolean isDefaultSms) {
|
||||||
if (recipients.isBlocked()) {
|
if (recipients.isBlocked()) {
|
||||||
unblockButton.setVisibility(View.VISIBLE);
|
unblockButton.setVisibility(View.VISIBLE);
|
||||||
composePanel.setVisibility(View.GONE);
|
composePanel.setVisibility(View.GONE);
|
||||||
makeDefaultSmsButton.setVisibility(View.GONE);
|
makeDefaultSmsButton.setVisibility(View.GONE);
|
||||||
} else if (!isSecureText && !Util.isDefaultSmsProvider(this)) {
|
} else if (!isSecureText && !isDefaultSms) {
|
||||||
unblockButton.setVisibility(View.GONE);
|
unblockButton.setVisibility(View.GONE);
|
||||||
composePanel.setVisibility(View.GONE);
|
composePanel.setVisibility(View.GONE);
|
||||||
makeDefaultSmsButton.setVisibility(View.VISIBLE);
|
makeDefaultSmsButton.setVisibility(View.VISIBLE);
|
||||||
@ -1744,7 +1752,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachmentChanged() {
|
public void onAttachmentChanged() {
|
||||||
handleSecurityChange(isSecureText, isSecureVoice);
|
handleSecurityChange(isSecureText, isSecureVoice, isDefaultSms);
|
||||||
updateToggleButtonState();
|
updateToggleButtonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user