Skip to content

Commit

Permalink
validate phone number parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Sep 5, 2019
1 parent d169c64 commit 6ba3361
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ dependencies {
implementation 'androidx.vectordrawable:vectordrawable:1.1.0-rc01'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.9.2'
}
7 changes: 2 additions & 5 deletions app/src/main/java/co/tinode/tindroid/account/SyncAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;

import co.tinode.tindroid.Cache;
import co.tinode.tindroid.media.VxCard;
import co.tinode.tinodesdk.InProgressException;
import co.tinode.tinodesdk.PromisedReply;
import co.tinode.tinodesdk.Tinode;
import co.tinode.tinodesdk.Topic;
Expand Down Expand Up @@ -96,9 +94,8 @@ public void onPerformSync(final Account account, final Bundle extras, String aut
}

// Load contacts and send them to server as fnd.Private.
SparseArray<Utils.ContactHolder> contactList =
Utils.fetchContacts(getContext().getContentResolver(),
Utils.FETCH_EMAIL | Utils.FETCH_PHONE);
SparseArray<Utils.ContactHolder> contactList = Utils.fetchContacts(getContext().getContentResolver(),
Utils.FETCH_EMAIL | Utils.FETCH_PHONE);
StringBuilder contactsBuilder = new StringBuilder();
for (int i=0; i<contactList.size(); i++) {
Utils.ContactHolder ch = contactList.get(contactList.keyAt(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

/**
* Service to handle sync requests.
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/co/tinode/tindroid/account/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -19,7 +20,6 @@

import androidx.annotation.NonNull;


/**
* Constants and misc utils
*/
Expand Down Expand Up @@ -160,12 +160,12 @@ public static SparseArray<ContactHolder> fetchContacts(ContentResolver resolver,
case ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE:
// This is a phone number. Use mobile phones only.
if (type == ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE) {
// Log.d(TAG, "Adding mobile phone '" + data + "' to contact=" + contact_id);
try {
// Normalize phone number format
data = phoneUtil.format(phoneUtil.parse(data, country),
PhoneNumberUtil.PhoneNumberFormat.E164);
holder.putPhone(data);
Phonenumber.PhoneNumber number = phoneUtil.parse(data, country);
if (phoneUtil.isValidNumber(number)) {
holder.putPhone(phoneUtil.format(number, PhoneNumberUtil.PhoneNumberFormat.E164));
}
} catch (NumberParseException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 6ba3361

Please sign in to comment.