mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
handle incoming autocrypt setup messages, closes #43
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- the FrameLayout is needed as View.inflate() without a root discards all layout_-attributes -->
|
||||
|
||||
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:columnCount="6"
|
||||
android:rowCount="1">
|
||||
|
||||
<!-- 1st row -->
|
||||
|
||||
<EditText
|
||||
android:id="@+id/setupCode0"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLength="4"
|
||||
android:minEms="3"/>
|
||||
|
||||
<TextView
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text=" - "
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/setupCode1"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLength="4"
|
||||
android:minEms="3"/>
|
||||
|
||||
<TextView
|
||||
android:text=" - "
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/setupCode2"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLength="4"
|
||||
android:minEms="3"/>
|
||||
|
||||
<TextView
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text=" - "
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"/>
|
||||
|
||||
<!-- 2nd row -->
|
||||
|
||||
<EditText
|
||||
android:id="@+id/setupCode3"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLength="4"
|
||||
android:minEms="3"/>
|
||||
|
||||
<TextView
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text=" - "
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/setupCode4"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLength="4"
|
||||
android:minEms="3"/>
|
||||
|
||||
<TextView
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text=" - "
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/setupCode5"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLength="4"
|
||||
android:minEms="3"/>
|
||||
|
||||
<TextView
|
||||
android:text=" - "
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"/>
|
||||
|
||||
<!-- 3rd row -->
|
||||
|
||||
<EditText
|
||||
android:id="@+id/setupCode6"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLength="4"
|
||||
android:minEms="3"/>
|
||||
|
||||
<TextView
|
||||
android:text=" - "
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/setupCode7"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLength="4"
|
||||
android:minEms="3"/>
|
||||
|
||||
<TextView
|
||||
android:text=" - "
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/setupCode8"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:maxLength="4"
|
||||
android:minEms="3"/>
|
||||
|
||||
<TextView
|
||||
android:text=" "
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"/>
|
||||
|
||||
</GridLayout>
|
||||
|
||||
</FrameLayout>
|
||||
@@ -1449,6 +1449,14 @@
|
||||
<string name="autocrypt__button_send_asm">Send Autocrypt Setup Message</string>
|
||||
<string name="autocrypt__msg_before_sending_asm">An \"Autocrypt Setup Message\" securely shares your end-to-end setup with other Autocrypt-compliant apps.\n\nThe setup will be encrypted by a setup code which is displayed here and must be typed on the other device.</string>
|
||||
<string name="autocrypt__msg_after_sending_asm">Your setup has been sent to yourself. Switch to the other device and open the setup message. You should be prompted for a setup code. Type the following digits into the prompt:\n\n%1$s\n\nOnce you\'re done, your other device will be ready to use Autocrypt.</string>
|
||||
<string name="autocrypt__asm_subject">Autocrypt Setup Message</string>
|
||||
<string name="autocrypt__asm_general_body">This is the Autocrypt Setup Message used to transfer your end-to-end setup between clients.\n\nTo decrypt and use your setup, open the message in an Autocrypt-compliant client and enter the setup code presented on the generating device.</string>
|
||||
<string name="autocrypt__asm_tap_body">This is the Autocrypt Setup Message used to transfer your end-to-end setup between clients.\n\nTo decrypt and use your setup, tap on this message.</string>
|
||||
<string name="autocrypt__continue_transfer_title">Autocrypt Setup Message</string>
|
||||
<string name="autocrypt__continue_transfer_please_enter_code">Please enter the setup code that is displayed on the other device.</string>
|
||||
<string name="autocrypt__continue_transfer_bad_code">Bad setup code. Please try again.\n\nIf you do not remember the setup code, just send another Autocrypt Setup Message from the other device.</string>
|
||||
<string name="autocrypt__continue_transfer_succeeded">End-to-end setup transferred. This device is now ready to use Autocrypt with the same setup as the other device.</string>
|
||||
<string name="autocrypt__continue_button_retry">Retry</string>
|
||||
|
||||
<!-- Generic and reusable strings -->
|
||||
<string name="email_address">Email address</string>
|
||||
|
||||
@@ -245,7 +245,7 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||
else if (type==DcMsg.DC_MSG_AUDIO || type==DcMsg.DC_MSG_VOICE) {
|
||||
return dcMsg.isOutgoing()? MESSAGE_TYPE_AUDIO_OUTGOING : MESSAGE_TYPE_AUDIO_INCOMING;
|
||||
}
|
||||
else if (type==DcMsg.DC_MSG_FILE) {
|
||||
else if (type==DcMsg.DC_MSG_FILE && !dcMsg.isSetupMessage()) {
|
||||
return dcMsg.isOutgoing()? MESSAGE_TYPE_DOCUMENT_OUTGOING : MESSAGE_TYPE_DOCUMENT_INCOMING;
|
||||
}
|
||||
else if (type==DcMsg.DC_MSG_IMAGE || type==DcMsg.DC_MSG_GIF || type==DcMsg.DC_MSG_VIDEO) {
|
||||
|
||||
@@ -37,7 +37,9 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.OnScrollListener;
|
||||
import android.text.ClipboardManager;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@@ -48,6 +50,7 @@ import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ViewSwitcher;
|
||||
@@ -651,6 +654,80 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void querySetupCode(final DcMsg dcMsg, String[] preload)
|
||||
{
|
||||
if( !dcMsg.isSetupMessage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
View gl = View.inflate(getActivity(), R.layout.setup_code_grid, null);
|
||||
final EditText[] editTexts = {
|
||||
(EditText) gl.findViewById(R.id.setupCode0), (EditText) gl.findViewById(R.id.setupCode1), (EditText) gl.findViewById(R.id.setupCode2),
|
||||
(EditText) gl.findViewById(R.id.setupCode3), (EditText) gl.findViewById(R.id.setupCode4), (EditText) gl.findViewById(R.id.setupCode5),
|
||||
(EditText) gl.findViewById(R.id.setupCode6), (EditText) gl.findViewById(R.id.setupCode7), (EditText) gl.findViewById(R.id.setupCode8)
|
||||
};
|
||||
android.app.AlertDialog.Builder builder1 = new android.app.AlertDialog.Builder(getActivity());
|
||||
builder1.setView(gl);
|
||||
editTexts[0].setText(dcMsg.getSetupCodeBegin());
|
||||
editTexts[0].setSelection(editTexts[0].getText().length());
|
||||
|
||||
for( int i = 0; i < 9; i++ ) {
|
||||
if( preload != null && i < preload.length ) {
|
||||
editTexts[i].setText(preload[i]);
|
||||
editTexts[i].setSelection(editTexts[i].getText().length());
|
||||
}
|
||||
editTexts[i].addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if( s.length()==4 ) {
|
||||
for ( int i = 0; i < 8; i++ ) {
|
||||
if( editTexts[i].hasFocus() && editTexts[i+1].getText().length()<4 ) {
|
||||
editTexts[i+1].requestFocus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
builder1.setTitle(getActivity().getString(R.string.autocrypt__continue_transfer_title));
|
||||
builder1.setMessage(getActivity().getString(R.string.autocrypt__continue_transfer_please_enter_code));
|
||||
builder1.setNegativeButton(android.R.string.cancel, null);
|
||||
builder1.setCancelable(false); // prevent the dialog from being dismissed accidentally (when the dialog is closed, the setup code is gone forever and the user has to create a new setup message)
|
||||
builder1.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
String setup_code = "";
|
||||
final String[] preload1 = new String[9];
|
||||
for ( int i = 0; i < 9; i++ ) {
|
||||
preload1[i] = editTexts[i].getText().toString();
|
||||
setup_code += preload1[i];
|
||||
}
|
||||
boolean success = dcContext.continueKeyTransfer(dcMsg.getId(), setup_code);
|
||||
|
||||
android.app.AlertDialog.Builder builder2 = new android.app.AlertDialog.Builder(getActivity());
|
||||
builder2.setTitle(getActivity().getString(R.string.autocrypt__continue_transfer_title));
|
||||
builder2.setMessage(getActivity().getString(success? R.string.autocrypt__continue_transfer_succeeded : R.string.autocrypt__continue_transfer_bad_code));
|
||||
if( success ) {
|
||||
builder2.setPositiveButton(android.R.string.ok, null);
|
||||
}
|
||||
else {
|
||||
builder2.setNegativeButton(android.R.string.cancel, null);
|
||||
builder2.setPositiveButton(R.string.autocrypt__continue_button_retry, (dialog1, which1) -> querySetupCode(dcMsg, preload1));
|
||||
}
|
||||
builder2.show();
|
||||
});
|
||||
builder1.show();
|
||||
}
|
||||
|
||||
private class ConversationFragmentItemClickListener implements ItemClickListener {
|
||||
|
||||
@Override
|
||||
@@ -666,6 +743,9 @@ public class ConversationFragment extends Fragment
|
||||
actionMode.setTitle(String.valueOf(getListAdapter().getSelectedItems().size()));
|
||||
}
|
||||
}
|
||||
else if(messageRecord.isSetupMessage()) {
|
||||
querySetupCode(messageRecord,null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -350,11 +350,6 @@ public class ConversationItem extends LinearLayout
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCaptionlessMms(DcMsg messageRecord) {
|
||||
return false;
|
||||
// return TextUtils.isEmpty(messageRecord.getText()) && messageRecord.isMms();
|
||||
}
|
||||
|
||||
private boolean hasAudio(DcMsg messageRecord) {
|
||||
return false;
|
||||
// return messageRecord.isMms() && ((MmsDcMsg)messageRecord).getSlideDeck().getAudioSlide() != null;
|
||||
@@ -389,12 +384,14 @@ public class ConversationItem extends LinearLayout
|
||||
bodyText.setFocusable(false);
|
||||
bodyText.setTextSize(TypedValue.COMPLEX_UNIT_SP, TextSecurePreferences.getMessageBodyTextSize(context));
|
||||
|
||||
if (isCaptionlessMms(messageRecord)) {
|
||||
bodyText.setVisibility(View.GONE);
|
||||
} else {
|
||||
bodyText.setText(linkifyMessageBody(new SpannableString(messageRecord.getText()), batchSelected.isEmpty()));
|
||||
bodyText.setVisibility(View.VISIBLE);
|
||||
if (messageRecord.isSetupMessage()) {
|
||||
bodyText.setText(context.getString(R.string.autocrypt__asm_tap_body));
|
||||
}
|
||||
else {
|
||||
bodyText.setText(linkifyMessageBody(new SpannableString(messageRecord.getText()), batchSelected.isEmpty()));
|
||||
}
|
||||
|
||||
bodyText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void setMediaAttributes(@NonNull DcMsg messageRecord,
|
||||
@@ -584,7 +581,8 @@ public class ConversationItem extends LinearLayout
|
||||
}
|
||||
|
||||
private void setStatusIcons(DcMsg messageRecord) {
|
||||
bodyText.setCompoundDrawablesWithIntrinsicBounds(0, 0, messageRecord.isSetupMessage() ? R.drawable.ic_menu_login : 0, 0);
|
||||
// disable the icon for for, we should use the same ui on desktop/ios here, so, for now
|
||||
//bodyText.setCompoundDrawablesWithIntrinsicBounds(0, 0, messageRecord.isSetupMessage() ? R.drawable.ic_menu_login : 0, 0);
|
||||
|
||||
if (messageRecord.isFailed()) {
|
||||
alertView.setFailed();
|
||||
@@ -680,8 +678,7 @@ public class ConversationItem extends LinearLayout
|
||||
}
|
||||
|
||||
private boolean shouldInterceptClicks(DcMsg messageRecord) {
|
||||
return batchSelected.isEmpty() && (messageRecord.isFailed() ||
|
||||
messageRecord.isSetupMessage());
|
||||
return batchSelected.isEmpty() && (messageRecord.isFailed());
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.b44t.messenger.DcEventCenter;
|
||||
import com.b44t.messenger.DcLot;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
@@ -343,6 +344,15 @@ public class ApplicationDcContext extends DcContext {
|
||||
}
|
||||
return stringToData(httpContent);
|
||||
|
||||
case DC_EVENT_GET_STRING:
|
||||
String s;
|
||||
switch( (int)data1 ) { // the integers are defined in the core and used only here, an enum or sth. like that won't have a big benefit
|
||||
case 42: s = context.getString(R.string.autocrypt__asm_subject); break;
|
||||
case 43: s = context.getString(R.string.autocrypt__asm_general_body); break;
|
||||
default: s = null; break;
|
||||
}
|
||||
return stringToData(s);
|
||||
|
||||
default:
|
||||
{
|
||||
final Object data1obj = data1IsString(event)? dataToString(data1) : data1;
|
||||
|
||||
Reference in New Issue
Block a user