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