diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index b861da5dd..09a08c425 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -220,7 +220,8 @@ public class DBUtils { for ( Iterator 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; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java index 4afd2860d..4b6d08e14 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java @@ -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 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 ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java index 430a67a3f..c112caea4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java @@ -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]; } } }