fix BT and SMS game creation in response to invitations by passing a

UtilCtxt they can use to get the devices ID, allowing relay messages
to reach the games when they're not open. Move into superclass while
at it.
This commit is contained in:
Eric House 2016-01-21 06:27:51 -08:00
parent 3bff4c070a
commit 16b558a566
4 changed files with 19 additions and 20 deletions

View file

@ -1124,7 +1124,8 @@ public class BTService extends XWService {
if ( null == rowids || 0 == rowids.length ) {
CommsAddrRec addr = nli.makeAddrRec( BTService.this );
long rowid = GameUtils.makeNewMultiGame( BTService.this, nli,
m_btMsgSink, null );
m_btMsgSink,
getUtilCtxt() );
if ( DBUtils.ROWID_NOTFOUND == rowid ) {
result = BTCmd.INVITE_FAILED;
} else {

View file

@ -53,8 +53,6 @@ import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.jni.LastMoveInfo;
import org.eehouse.android.xw4.jni.UtilCtxt.DevIDType;
import org.eehouse.android.xw4.jni.UtilCtxt;
import org.eehouse.android.xw4.jni.UtilCtxtImpl;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils;
@ -256,8 +254,8 @@ public class RelayService extends XWService
// make the initial connection -- needs access to util. That
// should be fixable -- eventually.
RelayMsgSink sink = new RelayMsgSink();
UtilCtxt util = new UtilCtxtImpl( this );
long rowid = GameUtils.makeNewMultiGame( this, nli, sink, util );
long rowid = GameUtils.makeNewMultiGame( this, nli, sink,
getUtilCtxt() );
if ( DBUtils.ROWID_NOTFOUND != rowid ) {
if ( null != nli.gameName && 0 < nli.gameName.length() ) {
DBUtils.setName( this, rowid, nli.gameName );

View file

@ -637,24 +637,13 @@ public class SMSService extends XWService {
private void makeForInvite( String phone, NetLaunchInfo nli )
{
SMSMsgSink sink = new SMSMsgSink( this );
long rowid = GameUtils.makeNewMultiGame( this, nli, sink, null );
long rowid = GameUtils.makeNewMultiGame( this, nli,
new SMSMsgSink( this ),
getUtilCtxt() );
postNotification( phone, nli.gameID(), rowid );
ackInvite( phone, nli.gameID() );
}
private void makeForInvite( String phone, int gameID, String gameName,
int lang, String dict, int nPlayersT,
int nPlayersH, int forceChannel )
{
long rowid =
GameUtils.makeNewGame( this, gameID, new CommsAddrRec( phone ),
lang, dict, nPlayersT, nPlayersH,
forceChannel, gameName );
postNotification( phone, gameID, rowid );
ackInvite( phone, gameID );
}
private PendingIntent makeStatusIntent( String msg )
{
Intent intent = new Intent( msg );

View file

@ -28,13 +28,16 @@ import java.util.HashSet;
import java.util.Set;
import org.eehouse.android.xw4.MultiService.MultiEvent;
import org.eehouse.android.xw4.jni.UtilCtxt;
import org.eehouse.android.xw4.jni.UtilCtxtImpl;
public class XWService extends Service {
protected static MultiService s_srcMgr = null;
private static Set<String> s_seen = new HashSet<String>();
private UtilCtxt m_utilCtxt;
@Override
public IBinder onBind( Intent intent )
{
@ -74,4 +77,12 @@ public class XWService extends Service {
DbgUtils.logf( "XWService.checkNotDupe(%s) => %b", inviteID, !isDupe );
return !isDupe;
}
protected UtilCtxt getUtilCtxt()
{
if ( null == m_utilCtxt ) {
m_utilCtxt = new UtilCtxtImpl( this );
}
return m_utilCtxt;
}
}