public long l2ServerAcceptAndOpenServerConnection(long handle) throws IOException { EmulatorL2CAPService s = ((EmulatorL2CAPService) activeLocalDevice().getConnection(handle)); if (!localDevice.isConnectable()) { throw new BluetoothStateException("Local device is not connectable"); } long clientHandle = 0; boolean success = false; while (!success) { long connectionHandle = s.accept(); try { long remoteAddress = localDevice .getDeviceManagerService() .getRemoteAddress(localDevice.getAddress(), connectionHandle); EmulatorL2CAPClient c = localDevice.createL2CAPClient(remoteAddress); c.connect(remoteAddress, connectionHandle, s.getReceiveMTU(), s.getTransmitMTU()); localDevice .getDeviceManagerService() .connectionAccepted(localDevice.getAddress(), connectionHandle); success = true; clientHandle = c.getHandle(); } catch (IOException e) { DebugLog.debug("fail to accept connection", e); continue; } finally { if (!success) { localDevice .getDeviceManagerService() .closeConnection(localDevice.getAddress(), connectionHandle); } } } return clientHandle; }
public void l2ServerClose(long handle, ServiceRecordImpl serviceRecord) throws IOException { assertClosed(); EmulatorL2CAPService s = ((EmulatorL2CAPService) localDevice.getConnection(handle)); try { s.close(serviceRecord); } finally { localDevice.removeConnection(s); } }
public long l2ServerOpen( BluetoothConnectionNotifierParams params, int receiveMTU, int transmitMTU, ServiceRecordImpl serviceRecord) throws IOException { validateMTU(receiveMTU, transmitMTU); EmulatorL2CAPService s = activeLocalDevice().createL2CAPService(params.bluecove_ext_psm); boolean success = false; try { s.open(params, receiveMTU, transmitMTU); serviceRecord.setHandle(s.getHandle()); serviceRecord.populateL2CAPAttributes( (int) s.getHandle(), s.getPcm(), params.uuid, params.name); s.updateServiceRecord(serviceRecord); success = true; } finally { if (!success) { localDevice.removeConnection(s); } } return s.getHandle(); }