mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-06 05:24:46 +01:00
use cmd strings; log discovery running or not
Add a compile-time option to send commands in json as strings rather than ordinals (ints) for easier reading of logs. And log/keep track of when discovery's turned off or on in case it's useful for making all this work.
This commit is contained in:
parent
2b120959ae
commit
25c2fd16ef
2 changed files with 32 additions and 4 deletions
|
@ -102,7 +102,8 @@ public class WiDirService extends XWService {
|
||||||
private static IntentFilter sIntentFilter;
|
private static IntentFilter sIntentFilter;
|
||||||
private static GroupInfoListener sGroupListener;
|
private static GroupInfoListener sGroupListener;
|
||||||
private static WFDBroadcastReceiver sReceiver;
|
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 sEnabled;
|
||||||
private static boolean sHavePermission;
|
private static boolean sHavePermission;
|
||||||
// These two kinda overlap...
|
// 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_PEERS_CHANGED_ACTION);
|
||||||
sIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
|
sIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
|
||||||
sIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
|
sIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
|
||||||
|
sIntentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION);
|
||||||
|
|
||||||
sReceiver = new WFDBroadcastReceiver( mgr, sChannel );
|
sReceiver = new WFDBroadcastReceiver( mgr, sChannel );
|
||||||
succeeded = true;
|
succeeded = true;
|
||||||
|
@ -1060,6 +1062,13 @@ public class WiDirService extends XWService {
|
||||||
if ( null == stored ) {
|
if ( null == stored ) {
|
||||||
DBUtils.setStringFor( context, MAC_ADDR_KEY, sMacAddress );
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ import org.json.JSONArray;
|
||||||
public class XWPacket {
|
public class XWPacket {
|
||||||
private static final String TAG = XWPacket.class.getSimpleName();
|
private static final String TAG = XWPacket.class.getSimpleName();
|
||||||
private static final String KEY_CMD = "cmd";
|
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;
|
private JSONObject m_obj;
|
||||||
|
|
||||||
|
@ -40,7 +43,11 @@ public class XWPacket {
|
||||||
public XWPacket( CMD cmd ) {
|
public XWPacket( CMD cmd ) {
|
||||||
try {
|
try {
|
||||||
m_obj = new JSONObject();
|
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 ) {
|
} catch ( JSONException ex ) {
|
||||||
DbgUtils.logd( TAG, ex.toString() );
|
DbgUtils.logd( TAG, ex.toString() );
|
||||||
}
|
}
|
||||||
|
@ -57,8 +64,20 @@ public class XWPacket {
|
||||||
|
|
||||||
public CMD getCommand()
|
public CMD getCommand()
|
||||||
{
|
{
|
||||||
int cmd = m_obj.optInt( KEY_CMD, -1 ); // let's blow up :-)
|
CMD cmd = null;
|
||||||
return CMD.values()[cmd];
|
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 )
|
public XWPacket put( String key, String value )
|
||||||
|
|
Loading…
Reference in a new issue