diff options
author | Mark Spruiell <mes@zeroc.com> | 2017-11-09 09:16:21 -0800 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2017-11-09 09:16:21 -0800 |
commit | 82c20fbbf7641c47e91509a5c90a104cdaaeceb4 (patch) | |
tree | 6fd83e517bce70fc5607235b4e7f8924f0dffa04 /java-compat/src | |
parent | ICE-8539 - C++ fix for BT addressing (diff) | |
download | ice-82c20fbbf7641c47e91509a5c90a104cdaaeceb4.tar.bz2 ice-82c20fbbf7641c47e91509a5c90a104cdaaeceb4.tar.xz ice-82c20fbbf7641c47e91509a5c90a104cdaaeceb4.zip |
ICE-8539 - Android fixes for Bluetooth addressing
Diffstat (limited to 'java-compat/src')
4 files changed, 77 insertions, 68 deletions
diff --git a/java-compat/src/IceBT/src/main/java/IceBT/AcceptorI.java b/java-compat/src/IceBT/src/main/java/IceBT/AcceptorI.java index 568d6b9946a..89eaa0b1ae5 100644 --- a/java-compat/src/IceBT/src/main/java/IceBT/AcceptorI.java +++ b/java-compat/src/IceBT/src/main/java/IceBT/AcceptorI.java @@ -62,12 +62,22 @@ final class AcceptorI implements IceInternal.Acceptor @Override public IceInternal.EndpointI listen() { + UUID uuid = null; + try + { + uuid = UUID.fromString(_uuid); + } + catch(IllegalArgumentException ex) + { + throw new Ice.SocketException(ex); + } + try { // // We always listen using the "secure" method. // - _socket = _instance.bluetoothAdapter().listenUsingRfcommWithServiceRecord(_name, _uuid); + _socket = _instance.bluetoothAdapter().listenUsingRfcommWithServiceRecord(_name, uuid); } catch(java.io.IOException ex) { @@ -136,15 +146,15 @@ final class AcceptorI implements IceInternal.Acceptor s.append(_name); s.append("'"); } - if(_uuid != null) + if(!_uuid.isEmpty()) { s.append("\nservice uuid = "); - s.append(_uuid.toString()); + s.append(_uuid); } return s.toString(); } - AcceptorI(EndpointI endpoint, Instance instance, String adapterName, UUID uuid, String name) + AcceptorI(EndpointI endpoint, Instance instance, String adapterName, String uuid, String name) { _endpoint = endpoint; _instance = instance; @@ -214,7 +224,7 @@ final class AcceptorI implements IceInternal.Acceptor private Instance _instance; private String _adapterName; private String _name; - private UUID _uuid; + private String _uuid; private IceInternal.ReadyCallback _readyCallback; private BluetoothServerSocket _socket; private java.util.Stack<BluetoothSocket> _pending; diff --git a/java-compat/src/IceBT/src/main/java/IceBT/ConnectorI.java b/java-compat/src/IceBT/src/main/java/IceBT/ConnectorI.java index 785c178bf60..878a9b3542b 100644 --- a/java-compat/src/IceBT/src/main/java/IceBT/ConnectorI.java +++ b/java-compat/src/IceBT/src/main/java/IceBT/ConnectorI.java @@ -33,13 +33,13 @@ final class ConnectorI implements IceInternal.Connector { buf.append(_addr); } - if(_uuid != null) + if(!_uuid.isEmpty()) { if(!_addr.isEmpty()) { buf.append(';'); } - buf.append(_uuid.toString()); + buf.append(_uuid); } return buf.toString(); } @@ -53,7 +53,7 @@ final class ConnectorI implements IceInternal.Connector // // Only for use by EndpointI. // - ConnectorI(Instance instance, String addr, UUID uuid, int timeout, String connectionId) + ConnectorI(Instance instance, String addr, String uuid, int timeout, String connectionId) { _instance = instance; _addr = addr; @@ -62,10 +62,10 @@ final class ConnectorI implements IceInternal.Connector _connectionId = connectionId; _hashCode = 5381; - _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr); - _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _uuid); - _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _timeout); - _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _connectionId); + _hashCode = IceInternal.HashUtil.hashAdd(_hashCode, _addr); + _hashCode = IceInternal.HashUtil.hashAdd(_hashCode, _uuid); + _hashCode = IceInternal.HashUtil.hashAdd(_hashCode, _timeout); + _hashCode = IceInternal.HashUtil.hashAdd(_hashCode, _connectionId); } @Override @@ -102,7 +102,7 @@ final class ConnectorI implements IceInternal.Connector private Instance _instance; private String _addr; - private UUID _uuid; + private String _uuid; private int _timeout; private String _connectionId; private int _hashCode; diff --git a/java-compat/src/IceBT/src/main/java/IceBT/EndpointI.java b/java-compat/src/IceBT/src/main/java/IceBT/EndpointI.java index 21b4da20deb..451079c5998 100644 --- a/java-compat/src/IceBT/src/main/java/IceBT/EndpointI.java +++ b/java-compat/src/IceBT/src/main/java/IceBT/EndpointI.java @@ -14,7 +14,7 @@ import java.util.UUID; final class EndpointI extends IceInternal.EndpointI { - public EndpointI(Instance instance, String addr, UUID uuid, String name, int channel, int timeout, + public EndpointI(Instance instance, String addr, String uuid, String name, int channel, int timeout, String connectionId, boolean compress) { _instance = instance; @@ -32,7 +32,7 @@ final class EndpointI extends IceInternal.EndpointI { _instance = instance; _addr = ""; - _uuid = null; + _uuid = ""; _name = ""; _channel = 0; _timeout = instance.defaultTimeout(); @@ -50,22 +50,8 @@ final class EndpointI extends IceInternal.EndpointI _name = ""; _channel = 0; _connectionId = ""; - _addr = s.readString().toUpperCase(); - if(!BluetoothAdapter.checkBluetoothAddress(_addr)) - { - throw new Ice.MarshalException("invalid address `" + _addr + "' in endpoint"); - } - - try - { - _uuid = UUID.fromString(s.readString()); - } - catch(IllegalArgumentException ex) - { - throw new Ice.MarshalException("invalid UUID for Bluetooth endpoint", ex); - } - + _uuid = s.readString(); _timeout = s.readInt(); _compress = s.readBool(); hashInit(); @@ -78,7 +64,7 @@ final class EndpointI extends IceInternal.EndpointI // _name and _channel are not marshaled. // s.writeString(_addr); - s.writeString(_uuid.toString()); + s.writeString(_uuid); s.writeInt(_timeout); s.writeBool(_compress); } @@ -188,7 +174,18 @@ final class EndpointI extends IceInternal.EndpointI public java.util.List<IceInternal.EndpointI> expandIfWildcard() { java.util.List<IceInternal.EndpointI> endps = new java.util.ArrayList<IceInternal.EndpointI>(); - endps.add(this); + if(_addr.isEmpty()) + { + // + // Starting in Android 6 (API 23), BluetoothAdapter.getAddress() returns a bogus constant value. + // + String addr = BluetoothAdapter.getDefaultAdapter().getAddress(); + endps.add(new EndpointI(_instance, addr, _uuid, _name, _channel, _timeout, _connectionId, _compress)); + } + else + { + endps.add(this); + } return endps; } @@ -225,7 +222,7 @@ final class EndpointI extends IceInternal.EndpointI // String s = ""; - if(_addr != null && _addr.length() > 0) + if(!_addr.isEmpty()) { s += " -a "; boolean addQuote = _addr.indexOf(':') != -1; @@ -240,16 +237,15 @@ final class EndpointI extends IceInternal.EndpointI } } - if(_uuid != null) + if(!_uuid.isEmpty()) { s += " -u "; - String uuidStr = _uuid.toString(); - boolean addQuote = uuidStr.indexOf(':') != -1; + boolean addQuote = _uuid.indexOf(':') != -1; if(addQuote) { s += "\""; } - s += uuidStr; + s += _uuid; if(addQuote) { s += "\""; @@ -282,7 +278,7 @@ final class EndpointI extends IceInternal.EndpointI { super.initWithOptions(args); - if(_addr.length() == 0) + if(_addr.isEmpty()) { _addr = _instance.defaultHost(); if(_addr == null) @@ -290,35 +286,31 @@ final class EndpointI extends IceInternal.EndpointI _addr = ""; } } - - if(_addr.length() == 0 || _addr.equals("*")) + else if(_addr.equals("*")) { if(oaEndpoint) { - // - // Ignore a missing address, we always use the default adapter anyway. - // + _addr = ""; } else { - throw new Ice.EndpointParseException( - "a device address must be specified using the -a option or Ice.Default.Host"); + throw new Ice.EndpointParseException("`-a *' not valid for proxy endpoint `" + toString() + "'"); } } - if(_name.length() == 0) + if(_name.isEmpty()) { _name = "Ice Service"; } - if(_uuid == null) + if(_uuid.isEmpty()) { if(oaEndpoint) { // // Generate a UUID for object adapters that don't specify one. // - _uuid = UUID.randomUUID(); + _uuid = UUID.randomUUID().toString(); } else { @@ -353,7 +345,7 @@ final class EndpointI extends IceInternal.EndpointI } }; info.addr = _addr; - info.uuid = _uuid.toString(); + info.uuid = _uuid; return info; } @@ -377,7 +369,7 @@ final class EndpointI extends IceInternal.EndpointI return v; } - v = _uuid.toString().compareTo(p._uuid.toString()); + v = _uuid.compareTo(p._uuid); if(v != 0) { return v; @@ -453,12 +445,13 @@ final class EndpointI extends IceInternal.EndpointI } try { - _uuid = UUID.fromString(argument); + UUID.fromString(argument); } catch(IllegalArgumentException ex) { throw new Ice.EndpointParseException("invalid UUID for Bluetooth endpoint", ex); } + _uuid = argument; } else if(option.equals("-c")) { @@ -542,7 +535,7 @@ final class EndpointI extends IceInternal.EndpointI { int h = 5381; h = IceInternal.HashUtil.hashAdd(h, _addr); - h = IceInternal.HashUtil.hashAdd(h, _uuid.toString()); + h = IceInternal.HashUtil.hashAdd(h, _uuid); h = IceInternal.HashUtil.hashAdd(h, _timeout); h = IceInternal.HashUtil.hashAdd(h, _connectionId); h = IceInternal.HashUtil.hashAdd(h, _compress); @@ -551,7 +544,7 @@ final class EndpointI extends IceInternal.EndpointI private Instance _instance; private String _addr; - private UUID _uuid; + private String _uuid; private String _name; private int _channel; private int _timeout; diff --git a/java-compat/src/IceBT/src/main/java/IceBT/TransceiverI.java b/java-compat/src/IceBT/src/main/java/IceBT/TransceiverI.java index aed2a2d5f42..a23a6b49792 100644 --- a/java-compat/src/IceBT/src/main/java/IceBT/TransceiverI.java +++ b/java-compat/src/IceBT/src/main/java/IceBT/TransceiverI.java @@ -279,7 +279,7 @@ final class TransceiverI implements IceInternal.Transceiver //info.localChannel - not available, use default value of -1 info.remoteAddress = _remoteAddr; //info.remoteChannel - not available, use default value of -1 - info.uuid = _uuid.toString(); + info.uuid = _uuid; return info; } @@ -298,7 +298,7 @@ final class TransceiverI implements IceInternal.Transceiver // // Used by ConnectorI. // - TransceiverI(Instance instance, String remoteAddr, UUID uuid, String connectionId) + TransceiverI(Instance instance, String remoteAddr, String uuid, String connectionId) { _instance = instance; _remoteAddr = remoteAddr; @@ -318,10 +318,16 @@ final class TransceiverI implements IceInternal.Transceiver } catch(IllegalArgumentException ex) { - // - // Illegal address - This should have been detected by the endpoint. - // - assert(false); + throw new Ice.SocketException(ex); + } + + UUID uuidObj = null; + try + { + uuidObj = UUID.fromString(_uuid); + } + catch(IllegalArgumentException ex) + { throw new Ice.SocketException(ex); } @@ -330,7 +336,7 @@ final class TransceiverI implements IceInternal.Transceiver // // We always connect using the "secure" method. // - _socket = device.createRfcommSocketToServiceRecord(_uuid); + _socket = device.createRfcommSocketToServiceRecord(uuidObj); } catch(java.io.IOException ex) { @@ -346,9 +352,9 @@ final class TransceiverI implements IceInternal.Transceiver { name += "-" + _remoteAddr; } - if(_uuid != null) + if(!_uuid.isEmpty()) { - name += "-" + _uuid.toString(); + name += "-" + _uuid; } setName(name); @@ -361,7 +367,7 @@ final class TransceiverI implements IceInternal.Transceiver // // Used by AcceptorI. // - TransceiverI(Instance instance, BluetoothSocket socket, UUID uuid, String adapterName) + TransceiverI(Instance instance, BluetoothSocket socket, String uuid, String adapterName) { _instance = instance; _remoteAddr = socket.getRemoteDevice().getAddress(); @@ -383,9 +389,9 @@ final class TransceiverI implements IceInternal.Transceiver { _desc += "\nremote address = " + _remoteAddr; } - if(_uuid != null) + if(!_uuid.isEmpty()) { - _desc += "\nservice uuid = " + _uuid.toString(); + _desc += "\nservice uuid = " + _uuid; } final int defaultBufSize = 128 * 1024; @@ -451,9 +457,9 @@ final class TransceiverI implements IceInternal.Transceiver { s += "-" + _remoteAddr; } - if(_uuid != null) + if(!_uuid.isEmpty()) { - s += "-" + _uuid.toString(); + s += "-" + _uuid; } final String suffix = s; @@ -664,7 +670,7 @@ final class TransceiverI implements IceInternal.Transceiver private Instance _instance; private String _remoteAddr; - private UUID _uuid; + private String _uuid; private String _connectionId; private String _adapterName; |