add missing util method (fixing crash) and with it wire up new devID

scheme: now relay-assigned shorter id will be saved and used for
future games.
This commit is contained in:
Eric House 2012-11-06 07:08:06 -08:00
parent 9ad28908bb
commit 39dbed2004
5 changed files with 54 additions and 6 deletions

View file

@ -552,9 +552,9 @@ static const XP_UCHAR*
and_util_getDevID( XW_UtilCtxt* uc, DevIDType* typ )
{
const XP_UCHAR* result = NULL;
*typ = ID_TYPE_ANDROID_GCM;
UTIL_CBK_HEADER( "getDevID", "()Ljava/lang/String;" );
jstring jresult = (*env)->CallObjectMethod( env, util->jutil, mid );
UTIL_CBK_HEADER( "getDevID", "([B)Ljava/lang/String;" );
jbyteArray jbarr = makeByteArray( env, 1, NULL );
jstring jresult = (*env)->CallObjectMethod( env, util->jutil, mid, jbarr );
if ( NULL != jresult ) {
const char* jchars = (*env)->GetStringUTFChars( env, jresult, NULL );
jsize len = (*env)->GetStringUTFLength( env, jresult );
@ -570,10 +570,25 @@ and_util_getDevID( XW_UtilCtxt* uc, DevIDType* typ )
}
(*env)->ReleaseStringUTFChars( env, jresult, jchars );
result = (const XP_UCHAR*)util->devIDStorage;
jbyte* elems = (*env)->GetByteArrayElements( env, jbarr, NULL );
*typ = (DevIDType)elems[0];
(*env)->ReleaseByteArrayElements( env, jbarr, elems, 0 );
}
deleteLocalRef( env, jbarr );
UTIL_CBK_TAIL();
return result;
}
static void
and_util_deviceRegistered( XW_UtilCtxt* uc, const XP_UCHAR* idRelay )
{
UTIL_CBK_HEADER( "deviceRegistered", "(Ljava/lang/String;)V" );
jstring jstr = (*env)->NewStringUTF( env, idRelay );
(*env)->CallVoidMethod( env, util->jutil, mid, jstr );
deleteLocalRef( env, jstr );
UTIL_CBK_TAIL();
}
#endif /* XWFEATURE_DEVID */
#endif
@ -677,6 +692,7 @@ makeUtil( MPFORMAL JNIEnv** envp, jobject jutil, CurGameInfo* gi,
SET_PROC(setIsServer);
# ifdef XWFEATURE_DEVID
SET_PROC(getDevID);
SET_PROC(deviceRegistered);
# endif
#endif
#ifdef XWFEATURE_SEARCHLIMIT

View file

@ -69,6 +69,7 @@
<string name="key_connstat_data">key_connstat_data</string>
<string name="key_dev_id">key_dev_id</string>
<string name="key_gcm_regid">key_gcm_regid</string>
<string name="key_relay_regid">key_relay_regid</string>
<string name="key_checked_sms">key_checked_sms</string>
<string name="key_notagain_sync">key_notagain_sync</string>

View file

@ -199,6 +199,20 @@ public class XWPrefs {
clearPrefsKey( context, R.string.key_gcm_regid );
}
public static String getRelayDevID( Context context )
{
String result = getPrefsString( context, R.string.key_relay_regid );
if ( null != result && 0 == result.length() ) {
result = null;
}
return result;
}
public static void setRelayDevID( Context context, String idRelay )
{
setPrefsString( context, R.string.key_relay_regid, idRelay );
}
public static boolean getHaveCheckedSMS( Context context )
{
return getPrefsBoolean( context, R.string.key_checked_sms, false );

View file

@ -56,7 +56,12 @@ public interface UtilCtxt {
void remSelected();
void setIsServer( boolean isServer );
String getDevID();
// Possible values for typ[0], these must match enum in xwrelay.sh
public static final int ID_TYPE_RELAY = 1;
public static final int ID_TYPE_ANDROID_GCM = 3;
String getDevID( /*out*/ byte[] typ );
void deviceRegistered( String idRelay );
void bonusSquareHeld( int bonus );
void playerScoreHeld( int player );

View file

@ -94,9 +94,21 @@ public class UtilCtxtImpl implements UtilCtxt {
subclassOverride( "setIsServer" );
}
public String getDevID()
public String getDevID( /*out*/ byte[] typ )
{
return XWPrefs.getGCMDevID( m_context );
String result = XWPrefs.getRelayDevID( m_context );
if ( null != result ) {
typ[0] = UtilCtxt.ID_TYPE_RELAY;
} else {
result = XWPrefs.getGCMDevID( m_context );
typ[0] = UtilCtxt.ID_TYPE_ANDROID_GCM;
}
return result;
}
public void deviceRegistered( String idRelay )
{
XWPrefs.setRelayDevID( m_context, idRelay );
}
public void bonusSquareHeld( int bonus )