perms: use stored pairs when don't have

If user hasn't granted READ_CONTACTS permission, use the pairing of
numbers/names that's come from Contacts via the SMS invitation dialog.
Sometimes it'll have names for numbers that arrived via invitations. Do
some cleanup while at it to prevent stored BT mac addresses from being
looked up as phone numbers.
This commit is contained in:
Eric House 2016-12-19 22:11:26 -08:00
parent f8ec19b35c
commit 994de23145
3 changed files with 34 additions and 17 deletions

View file

@ -220,7 +220,8 @@ public class DBUtils {
for ( Iterator<CommsConnType> iter = summary.conTypes.iterator();
iter.hasNext(); ) {
switch ( iter.next() ) {
CommsConnType typ = iter.next();
switch ( typ ) {
case COMMS_CONN_RELAY:
col = cursor.getColumnIndex( DBHelper.ROOMNAME );
if ( col >= 0 ) {
@ -235,7 +236,7 @@ public class DBUtils {
case COMMS_CONN_SMS:
col = cursor.getColumnIndex( DBHelper.REMOTEDEVS );
if ( col >= 0 ) {
summary.setRemoteDevs( context,
summary.setRemoteDevs( context, typ,
cursor.getString( col ) );
}
break;

View file

@ -40,6 +40,7 @@ import android.media.RingtoneManager;
import android.net.Uri;
import android.provider.ContactsContract.PhoneLookup;
import android.support.v4.app.NotificationCompat;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.view.Menu;
@ -50,17 +51,21 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import junit.framework.Assert;
import org.eehouse.android.xw4.jni.CommonPrefs;
import org.eehouse.android.xw4.loc.LocUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import junit.framework.Assert;
import org.eehouse.android.xw4.jni.CommonPrefs;
import org.eehouse.android.xw4.loc.LocUtils;
public class Utils {
private static final String TAG = Utils.class.getSimpleName();
public static final int TURN_COLOR = 0x7F00FF00;
@ -274,16 +279,15 @@ public class Utils {
// I'm assuming that since context is passed this needn't
// worry about synchronization -- will always be called from
// UI thread.
String name;
String name = null;
synchronized ( s_phonesHash ) {
if ( s_phonesHash.containsKey( phone ) ) {
name = s_phonesHash.get( phone );
} else {
} else if ( Perms23.havePermission( Perms23.Perm.READ_CONTACTS ) ) {
try {
name = null;
ContentResolver contentResolver = context.getContentResolver();
Cursor cursor =
contentResolver
ContentResolver contentResolver = context
.getContentResolver();
Cursor cursor = contentResolver
.query( Uri.withAppendedPath( PhoneLookup.CONTENT_FILTER_URI,
Uri.encode( phone )),
new String[] { PhoneLookup.DISPLAY_NAME },
@ -298,6 +302,17 @@ public class Utils {
// could just be lack of permsisions
name = null;
}
} else {
JSONObject phones = XWPrefs.getSMSPhones( context );
for ( Iterator<String> iter = phones.keys(); iter.hasNext(); ) {
String key = iter.next();
DbgUtils.logd( TAG, "comparing %s, %s", key, phone );
if ( PhoneNumberUtils.compare( key, phone ) ) {
name = phones.optString( key, phone );
s_phonesHash.put( phone, name );
break;
}
}
}
}
if ( null == name && phoneStandsIn ) {

View file

@ -140,15 +140,16 @@ public class GameSummary {
playerNames() );
}
public void setRemoteDevs( Context context, String asString )
public void setRemoteDevs( Context context, CommsConnType typ, String str )
{
if ( null != asString ) {
remoteDevs = TextUtils.split( asString, "\n" );
if ( null != str && 0 < str.length() ) {
remoteDevs = TextUtils.split( str, "\n" );
m_remotePhones = new String[remoteDevs.length];
for ( int ii = 0; ii < remoteDevs.length; ++ii ) {
m_remotePhones[ii] =
Utils.phoneToContact( context, remoteDevs[ii], true );
m_remotePhones[ii] = (typ == CommsConnType.COMMS_CONN_SMS)
? Utils.phoneToContact( context, remoteDevs[ii], true )
: remoteDevs[ii];
}
}
}