From 4b6f4047fbe6ee4d9d425f1c69b1eb6cc3d836c7 Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 14 Sep 2020 08:27:18 -0700 Subject: [PATCH] add tmp key to backstop model names I'm using model names to detect duplicates, but there are enough that may not suffice. So add a new random per-device ID to be used only until the dupes are resolved. --- .../java/org/eehouse/android/xw4/MQTTUtils.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java index 283e2798d..f26ecec12 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java @@ -49,6 +49,7 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba private static final String TAG = MQTTUtils.class.getSimpleName(); private static final String KEY_NEXT_REG = TAG + "/next_reg"; private static final String KEY_LAST_WRITE = TAG + "/last_write"; + private static final String KEY_TMP_KEY = TAG + "/tmp_key"; private static enum State { NONE, CONNECTING, CONNECTED, SUBSCRIBING, SUBSCRIBED, CLOSING }; @@ -314,6 +315,7 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba params.put( "myNow", now ); params.put( "loc", LocUtils.getCurLocale( mContext ) ); params.put( "knowsDup", true ); + params.put( "tmpKey", getTmpKey(mContext) ); String fcmid = FBMService.getFCMDevID( mContext ); if ( null != fcmid ) { @@ -356,6 +358,19 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba } } + private static int sTmpKey; + private static int getTmpKey( Context context ) + { + while ( 0 == sTmpKey ) { + sTmpKey = DBUtils.getIntFor( context, KEY_TMP_KEY, 0 ); + if ( 0 == sTmpKey ) { + sTmpKey = Math.abs( Utils.nextRandomInt() ); + DBUtils.setIntFor( context, KEY_TMP_KEY, sTmpKey ); + } + } + return sTmpKey; + } + private void disconnect() { Log.d( TAG, "%H.disconnect()", this );