wifi: tweaks

fix race condition in accept thread; only call wifimgr.connect() on
guest side. Connectivity now works reliably if the guest starts, or is
restarted, when the group owner is running. If owner is restarted the
guest seems never to connect (without restart.)
This commit is contained in:
Eric House 2016-11-30 07:06:59 -08:00
parent a686541f96
commit 0a26496e73

View file

@ -372,6 +372,7 @@ public class WiDirService extends XWService {
} }
public void onWriteSuccess( BiDiSockWrap wrap ) { public void onWriteSuccess( BiDiSockWrap wrap ) {
DbgUtils.logd( TAG, "onWriteSuccess()" );
updateStatusOut( true ); updateStatusOut( true );
} }
}; };
@ -606,7 +607,10 @@ public class WiDirService extends XWService {
private static void tryConnect( WifiP2pDevice device ) private static void tryConnect( WifiP2pDevice device )
{ {
final String macAddress = device.deviceAddress; final String macAddress = device.deviceAddress;
if ( sSocketWrapMap.containsKey(macAddress) if ( sAmGroupOwner ) {
DbgUtils.logd( TAG, "tryConnect(%s): dropping because group owner",
macAddress );
} else if ( sSocketWrapMap.containsKey(macAddress)
&& sSocketWrapMap.get(macAddress).isConnected() ) { && sSocketWrapMap.get(macAddress).isConnected() ) {
DbgUtils.logd( TAG, "tryConnect(%s): already connected", DbgUtils.logd( TAG, "tryConnect(%s): already connected",
macAddress ); macAddress );
@ -865,17 +869,19 @@ public class WiDirService extends XWService {
sAcceptThread = new Thread( new Runnable() { sAcceptThread = new Thread( new Runnable() {
public void run() { public void run() {
DbgUtils.logd( TAG, "accept thread starting" ); DbgUtils.logd( TAG, "accept thread starting" );
boolean done = false;
try { try {
sServerSock = new ServerSocket( OWNER_PORT ); sServerSock = new ServerSocket( OWNER_PORT );
while ( sAmServer ) { while ( !done ) {
DbgUtils.logd( TAG, "calling accept()" ); DbgUtils.logd( TAG, "calling accept()" );
Socket socket = sServerSock.accept(); Socket socket = sServerSock.accept();
DbgUtils.logd( TAG, "accept() returned!!" ); DbgUtils.logd( TAG, "accept() returned!!" );
new BiDiSockWrap( socket, sIface ); new BiDiSockWrap( socket, sIface );
} }
} catch ( IOException ioe ) { } catch ( IOException ioe ) {
sAmServer = false;
DbgUtils.loge( TAG, ioe.toString() ); DbgUtils.loge( TAG, ioe.toString() );
sAmServer = false;
done = true;
} }
DbgUtils.logd( TAG, "accept thread exiting" ); DbgUtils.logd( TAG, "accept thread exiting" );
} }