diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/WiDirService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/WiDirService.java index 425648ae8..795825f3e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/WiDirService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/WiDirService.java @@ -102,7 +102,8 @@ public class WiDirService extends XWService { private static IntentFilter sIntentFilter; private static GroupInfoListener sGroupListener; private static WFDBroadcastReceiver sReceiver; - private static boolean sDiscoveryStarted; + // private static boolean sDiscoveryStarted; + private static boolean sDiscoveryRunning; // set via broadcast private static boolean sEnabled; private static boolean sHavePermission; // These two kinda overlap... @@ -422,6 +423,7 @@ public class WiDirService extends XWService { sIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); sIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); sIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); + sIntentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION); sReceiver = new WFDBroadcastReceiver( mgr, sChannel ); succeeded = true; @@ -1060,6 +1062,13 @@ public class WiDirService extends XWService { if ( null == stored ) { DBUtils.setStringFor( context, MAC_ADDR_KEY, sMacAddress ); } + } else if (WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION.equals(action)) { + int running = intent + .getIntExtra( WifiP2pManager.EXTRA_DISCOVERY_STATE, -1 ); + Assert.assertTrue( running == 2 || running == 1 ); // remove soon + sDiscoveryRunning = 2 == running; + DbgUtils.logd( TAG, "discovery changed: running: %b", + sDiscoveryRunning ); } } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPacket.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPacket.java index 8b2da1582..0e5959516 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPacket.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPacket.java @@ -26,6 +26,9 @@ import org.json.JSONArray; public class XWPacket { private static final String TAG = XWPacket.class.getSimpleName(); private static final String KEY_CMD = "cmd"; + + // This can't change after ship!!!! + private static final boolean CMDS_AS_STRINGS = true; private JSONObject m_obj; @@ -40,7 +43,11 @@ public class XWPacket { public XWPacket( CMD cmd ) { try { m_obj = new JSONObject(); - m_obj.put( KEY_CMD, cmd.ordinal() ); + if ( CMDS_AS_STRINGS ) { + m_obj.put( KEY_CMD, cmd.toString() ); + } else { + m_obj.put( KEY_CMD, cmd.ordinal() ); + } } catch ( JSONException ex ) { DbgUtils.logd( TAG, ex.toString() ); } @@ -57,8 +64,20 @@ public class XWPacket { public CMD getCommand() { - int cmd = m_obj.optInt( KEY_CMD, -1 ); // let's blow up :-) - return CMD.values()[cmd]; + CMD cmd = null; + if ( CMDS_AS_STRINGS ) { + String str = m_obj.optString( KEY_CMD ); + for ( CMD one : CMD.values() ) { + if ( one.toString().equals(str)) { + cmd = one; + break; + } + } + } else { + int ord = m_obj.optInt( KEY_CMD, -1 ); // let's blow up :-) + cmd = CMD.values()[ord]; + } + return cmd; } public XWPacket put( String key, String value )