Skip to content

Commit

Permalink
Show sender of verification message or call (fix #317)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Mar 11, 2015
1 parent 2f189e1 commit de81d2c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/kontalk/client/NumberValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void processPacket(Stanza packet) {
if (field.getVariable().equals("from")) {
String smsFrom = field.getValues().get(0);
Log.d(TAG, "using sms sender id: " + smsFrom);
mListener.onValidationRequested(NumberValidator.this);
mListener.onValidationRequested(NumberValidator.this, smsFrom);

// prevent error handling
return;
Expand Down Expand Up @@ -472,7 +472,7 @@ public abstract interface NumberValidatorListener {
public void onServerCheckFailed(NumberValidator v);

/** Called on confirmation that the validation SMS is being sent. */
public void onValidationRequested(NumberValidator v);
public void onValidationRequested(NumberValidator v, String sender);

/** Called if phone number validation failed. */
public void onValidationFailed(NumberValidator v, int reason);
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/java/org/kontalk/ui/CodeValidation.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,19 @@ protected void onCreate(Bundle savedInstanceState) {
}

int requestCode = getIntent().getIntExtra("requestCode", -1);
if (requestCode == NumberValidation.REQUEST_VALIDATION_CODE) {
if (requestCode == NumberValidation.REQUEST_VALIDATION_CODE ||
getIntent().getStringExtra("sender") == null) {
findViewById(R.id.code_validation_sender)
.setVisibility(View.GONE);
findViewById(R.id.code_validation_intro2)
.setVisibility(View.GONE);
((TextView) findViewById(R.id.code_validation_intro))
.setText(R.string.code_validation_intro2);
.setText(R.string.code_validation_intro_manual);
}
else {
String sender = getIntent().getStringExtra("sender");
((TextView) findViewById(R.id.code_validation_sender))
.setText(sender);
}

Intent i = getIntent();
Expand Down Expand Up @@ -245,7 +255,7 @@ public void run() {
}

@Override
public void onValidationRequested(NumberValidator v) {
public void onValidationRequested(NumberValidator v, String sender) {
// not used.
}

Expand Down
21 changes: 11 additions & 10 deletions app/src/main/java/org/kontalk/ui/NumberValidation.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ protected void onStart() {
mPhone.setText(mPhoneNumber);
syncCountryCodeSelector();

startValidationCode(REQUEST_MANUAL_VALIDATION, saved.server, false);
startValidationCode(REQUEST_MANUAL_VALIDATION, saved.sender, saved.server, false);
}

if (mKey == null) {
Expand Down Expand Up @@ -570,7 +570,7 @@ public void validatePhone(View v) {
*/
public void validateCode(View v) {
if (checkInput())
startValidationCode(REQUEST_VALIDATION_CODE);
startValidationCode(REQUEST_VALIDATION_CODE, null);
}

/**
Expand Down Expand Up @@ -915,27 +915,27 @@ public void run() {
}

@Override
public void onValidationRequested(NumberValidator v) {
public void onValidationRequested(NumberValidator v, String sender) {
Log.d(TAG, "validation has been requested, requesting validation code to user");
proceedManual();
proceedManual(sender);
}

/** Proceeds to the next step in manual validation. */
private void proceedManual() {
private void proceedManual(final String sender) {
runOnUiThread(new Runnable() {
@Override
public void run() {
abortProgress(true);
startValidationCode(REQUEST_MANUAL_VALIDATION);
startValidationCode(REQUEST_MANUAL_VALIDATION, sender);
}
});
}

private void startValidationCode(int requestCode) {
startValidationCode(requestCode, null, true);
private void startValidationCode(int requestCode, String sender) {
startValidationCode(requestCode, sender, null, true);
}

private void startValidationCode(int requestCode, EndpointServer server, boolean saveProgress) {
private void startValidationCode(int requestCode, String sender, EndpointServer server, boolean saveProgress) {
// validator might be null if we are skipping verification code request
String serverUri = null;
if (server != null)
Expand All @@ -948,7 +948,7 @@ else if (mValidator != null)
Preferences.saveRegistrationProgress(this,
mName, mPhoneNumber, mKey, mPassphrase,
mImportedPublicKey, mImportedPrivateKey,
serverUri);
serverUri, sender);
}

Intent i = new Intent(NumberValidation.this, CodeValidation.class);
Expand All @@ -959,6 +959,7 @@ else if (mValidator != null)
i.putExtra("importedPublicKey", mImportedPublicKey);
i.putExtra("importedPrivateKey", mImportedPrivateKey);
i.putExtra("server", serverUri);
i.putExtra("sender", sender);
i.putExtra(KeyPairGeneratorService.EXTRA_KEY, mKey);

startActivityForResult(i, REQUEST_MANUAL_VALIDATION);
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/org/kontalk/util/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ public static boolean setRosterVersion(String version) {
*/
public static boolean saveRegistrationProgress(Context context, String name,
String phoneNumber, PersonalKey key, String passphrase,
byte[] importedPublicKey, byte[] importedPrivateKey, String serverUri) {
byte[] importedPublicKey, byte[] importedPrivateKey, String serverUri,
String sender) {
return sPreferences.edit()
.putString("registration_name", name)
.putString("registration_phone", phoneNumber)
Expand All @@ -477,6 +478,7 @@ public static boolean saveRegistrationProgress(Context context, String name,
Base64.encodeToString(importedPrivateKey, Base64.NO_WRAP) : null)
.putString("registration_passphrase", passphrase)
.putString("registration_server", serverUri)
.putString("registration_sender", sender)
.commit();
}

Expand All @@ -498,6 +500,8 @@ public static RegistrationProgress getRegistrationProgress(Context context) {
if (importedPrivateKey != null)
p.importedPrivateKey = Base64.decode(importedPrivateKey, Base64.NO_WRAP);

p.sender = getString(context, "registration_sender", null);

return p;
}
return null;
Expand All @@ -523,6 +527,7 @@ public static final class RegistrationProgress {
public byte[] importedPublicKey;
public byte[] importedPrivateKey;
public EndpointServer server;
public String sender;
}

/** Recent statuses database helper. */
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/layout/code_validation_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@
android:id="@+id/code_validation_intro"
android:text="@string/code_validation_intro" />

<TextView
android:id="@+id/code_validation_sender"
style="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingBottom="10dip"
android:layout_marginLeft="-20dp"
android:layout_marginStart="-20dp"
android:gravity="center"
android:drawableLeft="@drawable/ic_menu_call"
android:drawableStart="@drawable/ic_menu_call" />

<TextView
android:id="@+id/code_validation_intro2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingBottom="10dip"
android:text="@string/code_validation_intro2" />

<EditText
android:id="@+id/validation_code"
android:layout_width="match_parent"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
<string name="pref_title_network_uri">This will override server list automatic management</string>
<string name="number_validation_intro1">Please enter your name, select your country code and input your mobile phone number. A SMS with a verification code will be sent to you. Your phone number will be used once and then discarded.</string>
<string name="number_validation_intro2">If you are unable to receive SMS on this device, insert a phone number you own and input the verification code you will receive via SMS.</string>
<string name="code_validation_intro">You shall receive a SMS to the number you input briefly. Please insert the code you receive below.</string>
<string name="code_validation_intro2">Please insert a verification code you received. Please note that a verification code can be used only once.</string>
<string name="code_validation_intro">You should receive a SMS or a call from this number briefly:</string>
<string name="code_validation_intro2">Please insert the code you receive or hear below.</string>
<string name="code_validation_intro_manual">Please insert a verification code you received. Please note that a verification code can be used only once.</string>
<string name="hint_validation_name">Your name</string>
<string name="hint_validation_number">Your number</string>
<string name="hint_validation_code">Verification code</string>
Expand Down

0 comments on commit de81d2c

Please sign in to comment.