mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
tweaks to get game initialization working, including not looking on
startup for incoming text messages if on KITKAT or above.
This commit is contained in:
parent
c3482925b4
commit
aec70782f4
3 changed files with 63 additions and 32 deletions
|
@ -25,7 +25,6 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.TelephonyManager;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
import org.json.JSONException;
|
||||
|
@ -100,17 +99,17 @@ public class NetLaunchInfo {
|
|||
for ( CommsConnType typ : m_addrs.getTypes() ) {
|
||||
switch ( typ ) {
|
||||
case COMMS_CONN_BT:
|
||||
btAddress = json.optString( MultiService.BT_ADDRESS );
|
||||
btName = json.optString( MultiService.BT_NAME );
|
||||
btAddress = json.getString( MultiService.BT_ADDRESS );
|
||||
btName = json.getString( MultiService.BT_NAME );
|
||||
break;
|
||||
case COMMS_CONN_RELAY:
|
||||
room = json.optString( MultiService.ROOM );
|
||||
m_inviteID = json.optString( MultiService.INVITEID );
|
||||
room = json.getString( MultiService.ROOM );
|
||||
m_inviteID = json.getString( MultiService.INVITEID );
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
phone = json.optString( PHONE_KEY );
|
||||
isGSM = json.optBoolean( GSM_KEY, false );
|
||||
osVers = json.optInt( OSVERS_KEY );
|
||||
phone = json.getString( PHONE_KEY );
|
||||
isGSM = json.getBoolean( GSM_KEY );
|
||||
osVers = json.getInt( OSVERS_KEY );
|
||||
break;
|
||||
default:
|
||||
DbgUtils.logf( "Unexpected typ %s", typ.toString() );
|
||||
|
@ -418,14 +417,10 @@ public class NetLaunchInfo {
|
|||
|
||||
public void addSMSInfo( Context context )
|
||||
{
|
||||
// look up own phone number, which will require new permission
|
||||
TelephonyManager mgr = (TelephonyManager)
|
||||
context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
phone = mgr.getLine1Number();
|
||||
DbgUtils.logf( "addSMSInfo(): got phone: %s", phone );
|
||||
SMSService.SMSPhoneInfo pi = SMSService.getPhoneInfo( context );
|
||||
phone = pi.number;
|
||||
isGSM = pi.isGSM;
|
||||
|
||||
int type = mgr.getPhoneType();
|
||||
isGSM = TelephonyManager.PHONE_TYPE_GSM == type;
|
||||
osVers = Integer.valueOf( android.os.Build.VERSION.SDK );
|
||||
|
||||
m_addrs.add( CommsConnType.COMMS_CONN_SMS );
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
|
@ -65,6 +66,7 @@ public class SMSService extends XWService {
|
|||
|
||||
private static final String INSTALL_URL = "http://eehouse.org/_/a.py/a ";
|
||||
private static final int MAX_SMS_LEN = 140; // ??? differs by network
|
||||
private static final int KITKAT = 19;
|
||||
|
||||
private static final String MSG_SENT = "MSG_SENT";
|
||||
private static final String MSG_DELIVERED = "MSG_DELIVERED";
|
||||
|
@ -108,18 +110,42 @@ public class SMSService extends XWService {
|
|||
= new HashMap<String, HashMap <Integer, MsgStore>>();
|
||||
private static Set<Integer> s_sentDied = new HashSet<Integer>();
|
||||
|
||||
public static class SMSPhoneInfo {
|
||||
public SMSPhoneInfo( String num, boolean gsm ) {
|
||||
number = num;
|
||||
isGSM = gsm;
|
||||
}
|
||||
public String number;
|
||||
public boolean isGSM;
|
||||
}
|
||||
|
||||
public static SMSPhoneInfo getPhoneInfo( Context context )
|
||||
{
|
||||
TelephonyManager mgr = (TelephonyManager)
|
||||
context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
String number = mgr.getLine1Number();
|
||||
|
||||
int type = mgr.getPhoneType();
|
||||
boolean isGSM = TelephonyManager.PHONE_TYPE_GSM == type;
|
||||
return new SMSPhoneInfo( number, isGSM );
|
||||
}
|
||||
|
||||
public static void smsToastEnable( boolean newVal )
|
||||
{
|
||||
s_showToasts = newVal;
|
||||
}
|
||||
|
||||
public static void registerPhone( Context context, String phone, boolean isGSM )
|
||||
public static void registerPhone( Context context, String phone,
|
||||
boolean isGSM )
|
||||
{
|
||||
DbgUtils.logf( "SMSService.registerPhone(%s, isGSM=%b)", phone, isGSM );
|
||||
Assert.assertTrue( isGSM );
|
||||
Map<String,Boolean> phoneRecs = getPhoneRecs( context );
|
||||
phone = matchKeyIf( phoneRecs, phone );
|
||||
Boolean val = phoneRecs.get( phone );
|
||||
if ( null == val || val != isGSM ) {
|
||||
DbgUtils.logf( "SMSService.registerPhone: making rec for %s", phone );
|
||||
DbgUtils.logf( "SMSService.registerPhone: making rec for %s (isGSM=%b)",
|
||||
phone, isGSM );
|
||||
val = new Boolean( isGSM );
|
||||
phoneRecs.put( phone, val );
|
||||
saveRecs( context, phoneRecs );
|
||||
|
@ -135,7 +161,9 @@ public class SMSService extends XWService {
|
|||
|
||||
public static void checkForInvites( Context context )
|
||||
{
|
||||
if ( XWApp.SMSSUPPORTED && Utils.deviceSupportsSMS( context ) ) {
|
||||
if ( XWApp.SMSSUPPORTED && Utils.deviceSupportsSMS( context )
|
||||
// Earlier than kitkat...
|
||||
&& KITKAT > Integer.valueOf( android.os.Build.VERSION.SDK ) ) {
|
||||
Intent intent = getIntentTo( context, CHECK_MSGDB );
|
||||
context.startService( intent );
|
||||
}
|
||||
|
@ -473,7 +501,7 @@ public class SMSService extends XWService {
|
|||
if ( null == result ) {
|
||||
DbgUtils.logf( "getPhoneDoesData: no record for phone %s", phone );
|
||||
}
|
||||
DbgUtils.logf( "getPhoneDoesData(%s) => %b", phone, result );
|
||||
DbgUtils.logf( "getPhoneDoesData(%s) => %H/%b", phone, result, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -862,7 +890,6 @@ public class SMSService extends XWService {
|
|||
|
||||
private static void saveRecs( Context context, Map<String,Boolean> recs )
|
||||
{
|
||||
DbgUtils.logf( "SMSService.saveRecs()" );
|
||||
Assert.assertNotNull( recs );
|
||||
ByteArrayOutputStream bas = new ByteArrayOutputStream();
|
||||
try {
|
||||
|
@ -977,16 +1004,21 @@ public class SMSService extends XWService {
|
|||
return success;
|
||||
}
|
||||
|
||||
private static String matchKeyIf( Map<String, Boolean> map, String phone )
|
||||
private static String matchKeyIf( Map<String, ?> map, final String phone )
|
||||
{
|
||||
for ( Iterator<String> iter = map.keySet().iterator(); iter.hasNext(); ) {
|
||||
String key = iter.next();
|
||||
if ( PhoneNumberUtils.compare( key, phone ) ) {
|
||||
phone = key;
|
||||
break;
|
||||
String result = phone;
|
||||
Set<String> keys = map.keySet();
|
||||
if ( ! keys.contains( result ) ) {
|
||||
for ( Iterator<String> iter = keys.iterator(); iter.hasNext(); ) {
|
||||
String key = iter.next();
|
||||
if ( PhoneNumberUtils.compare( key, phone ) ) {
|
||||
result = key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return phone;
|
||||
DbgUtils.logf( "matchKeyIf(%s) => %s", phone, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
private class SMSMsgSink extends MultiMsgSink {
|
||||
|
|
|
@ -28,13 +28,14 @@ import java.util.Iterator;
|
|||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.Utils;
|
||||
import org.eehouse.android.xw4.R;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
import org.eehouse.android.xw4.BTService;
|
||||
import org.eehouse.android.xw4.DbgUtils;
|
||||
import org.eehouse.android.xw4.GameUtils;
|
||||
import org.eehouse.android.xw4.R;
|
||||
import org.eehouse.android.xw4.SMSService;
|
||||
import org.eehouse.android.xw4.Utils;
|
||||
import org.eehouse.android.xw4.XWPrefs;
|
||||
import org.eehouse.android.xw4.BTService;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class CommsAddrRec {
|
||||
|
||||
|
@ -204,7 +205,10 @@ public class CommsAddrRec {
|
|||
}
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
// FIXME
|
||||
SMSService.SMSPhoneInfo pi = SMSService.getPhoneInfo( context );
|
||||
sms_phone = pi.number;
|
||||
sms_port = 3; // fix comms already...
|
||||
break;
|
||||
default:
|
||||
Assert.fail();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue