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/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/src')
4 files changed, 79 insertions, 69 deletions
diff --git a/java/src/IceBT/src/main/java/com/zeroc/IceBT/AcceptorI.java b/java/src/IceBT/src/main/java/com/zeroc/IceBT/AcceptorI.java index d320816f4ed..cb9db0d56c1 100644 --- a/java/src/IceBT/src/main/java/com/zeroc/IceBT/AcceptorI.java +++ b/java/src/IceBT/src/main/java/com/zeroc/IceBT/AcceptorI.java @@ -68,12 +68,22 @@ final class AcceptorI implements Acceptor @Override public com.zeroc.IceInternal.EndpointI listen() { + UUID uuid = null; + try + { + uuid = UUID.fromString(_uuid); + } + catch(IllegalArgumentException ex) + { + throw new 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) { @@ -142,15 +152,15 @@ final class AcceptorI implements 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; @@ -220,7 +230,7 @@ final class AcceptorI implements Acceptor private Instance _instance; private String _adapterName; private String _name; - private UUID _uuid; + private String _uuid; private ReadyCallback _readyCallback; private BluetoothServerSocket _socket; private java.util.Stack<BluetoothSocket> _pending; diff --git a/java/src/IceBT/src/main/java/com/zeroc/IceBT/ConnectorI.java b/java/src/IceBT/src/main/java/com/zeroc/IceBT/ConnectorI.java index 8a3cef88d06..d44982849cf 100644 --- a/java/src/IceBT/src/main/java/com/zeroc/IceBT/ConnectorI.java +++ b/java/src/IceBT/src/main/java/com/zeroc/IceBT/ConnectorI.java @@ -38,13 +38,13 @@ final class ConnectorI implements 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(); } @@ -58,7 +58,7 @@ final class ConnectorI implements 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; @@ -67,10 +67,10 @@ final class ConnectorI implements Connector _connectionId = connectionId; _hashCode = 5381; - _hashCode = HashUtil.hashAdd(_hashCode , _addr); - _hashCode = HashUtil.hashAdd(_hashCode , _uuid); - _hashCode = HashUtil.hashAdd(_hashCode , _timeout); - _hashCode = HashUtil.hashAdd(_hashCode , _connectionId); + _hashCode = HashUtil.hashAdd(_hashCode, _addr); + _hashCode = HashUtil.hashAdd(_hashCode, _uuid); + _hashCode = HashUtil.hashAdd(_hashCode, _timeout); + _hashCode = HashUtil.hashAdd(_hashCode, _connectionId); } @Override @@ -107,7 +107,7 @@ final class ConnectorI implements 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/src/IceBT/src/main/java/com/zeroc/IceBT/EndpointI.java b/java/src/IceBT/src/main/java/com/zeroc/IceBT/EndpointI.java index 92079ba21f4..d1cca47447c 100644 --- a/java/src/IceBT/src/main/java/com/zeroc/IceBT/EndpointI.java +++ b/java/src/IceBT/src/main/java/com/zeroc/IceBT/EndpointI.java @@ -25,7 +25,7 @@ import java.util.UUID; final class EndpointI extends com.zeroc.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; @@ -43,7 +43,7 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI { _instance = instance; _addr = ""; - _uuid = null; + _uuid = ""; _name = ""; _channel = 0; _timeout = instance.defaultTimeout(); @@ -61,22 +61,8 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI _name = ""; _channel = 0; _connectionId = ""; - _addr = s.readString().toUpperCase(); - if(!BluetoothAdapter.checkBluetoothAddress(_addr)) - { - throw new MarshalException("invalid address `" + _addr + "' in endpoint"); - } - - try - { - _uuid = UUID.fromString(s.readString()); - } - catch(IllegalArgumentException ex) - { - throw new MarshalException("invalid UUID for Bluetooth endpoint", ex); - } - + _uuid = s.readString(); _timeout = s.readInt(); _compress = s.readBool(); hashInit(); @@ -89,7 +75,7 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI // _name and _channel are not marshaled. // s.writeString(_addr); - s.writeString(_uuid.toString()); + s.writeString(_uuid); s.writeInt(_timeout); s.writeBool(_compress); } @@ -199,14 +185,26 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI public java.util.List<com.zeroc.IceInternal.EndpointI> expandIfWildcard() { java.util.List<com.zeroc.IceInternal.EndpointI> endps = new java.util.ArrayList<>(); - 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; } @Override public com.zeroc.IceInternal.EndpointI.ExpandHostResult expandHost() { - com.zeroc.IceInternal.EndpointI.ExpandHostResult result = new com.zeroc.IceInternal.EndpointI.ExpandHostResult(); + com.zeroc.IceInternal.EndpointI.ExpandHostResult result = + new com.zeroc.IceInternal.EndpointI.ExpandHostResult(); result.endpoints = new java.util.ArrayList<>(); result.endpoints.add(this); return result; @@ -236,7 +234,7 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI // String s = ""; - if(_addr != null && _addr.length() > 0) + if(!_addr.isEmpty()) { s += " -a "; boolean addQuote = _addr.indexOf(':') != -1; @@ -251,16 +249,15 @@ final class EndpointI extends com.zeroc.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 += "\""; @@ -293,7 +290,7 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI { super.initWithOptions(args); - if(_addr.length() == 0) + if(_addr.isEmpty()) { _addr = _instance.defaultHost(); if(_addr == null) @@ -301,35 +298,31 @@ final class EndpointI extends com.zeroc.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 EndpointParseException( - "a device address must be specified using the -a option or Ice.Default.Host"); + throw new 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 { @@ -364,7 +357,7 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI } }; info.addr = _addr; - info.uuid = _uuid.toString(); + info.uuid = _uuid; return info; } @@ -388,7 +381,7 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI return v; } - v = _uuid.toString().compareTo(p._uuid.toString()); + v = _uuid.compareTo(p._uuid); if(v != 0) { return v; @@ -464,12 +457,13 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI } try { - _uuid = UUID.fromString(argument); + UUID.fromString(argument); } catch(IllegalArgumentException ex) { throw new EndpointParseException("invalid UUID for Bluetooth endpoint", ex); } + _uuid = argument; } else if(option.equals("-c")) { @@ -552,7 +546,7 @@ final class EndpointI extends com.zeroc.IceInternal.EndpointI { int h = 5381; h = HashUtil.hashAdd(h, _addr); - h = HashUtil.hashAdd(h, _uuid.toString()); + h = HashUtil.hashAdd(h, _uuid); h = HashUtil.hashAdd(h, _timeout); h = HashUtil.hashAdd(h, _connectionId); h = HashUtil.hashAdd(h, _compress); @@ -561,7 +555,7 @@ final class EndpointI extends com.zeroc.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/src/IceBT/src/main/java/com/zeroc/IceBT/TransceiverI.java b/java/src/IceBT/src/main/java/com/zeroc/IceBT/TransceiverI.java index 94f56119695..11be0e7b645 100644 --- a/java/src/IceBT/src/main/java/com/zeroc/IceBT/TransceiverI.java +++ b/java/src/IceBT/src/main/java/com/zeroc/IceBT/TransceiverI.java @@ -286,7 +286,7 @@ final class TransceiverI implements 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; } @@ -305,7 +305,7 @@ final class TransceiverI implements 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; @@ -325,10 +325,16 @@ final class TransceiverI implements Transceiver } catch(IllegalArgumentException ex) { - // - // Illegal address - This should have been detected by the endpoint. - // - assert(false); + throw new SocketException(ex); + } + + UUID uuidObj = null; + try + { + uuidObj = UUID.fromString(_uuid); + } + catch(IllegalArgumentException ex) + { throw new SocketException(ex); } @@ -337,7 +343,7 @@ final class TransceiverI implements Transceiver // // We always connect using the "secure" method. // - _socket = device.createRfcommSocketToServiceRecord(_uuid); + _socket = device.createRfcommSocketToServiceRecord(uuidObj); } catch(java.io.IOException ex) { @@ -353,9 +359,9 @@ final class TransceiverI implements Transceiver { name += "-" + _remoteAddr; } - if(_uuid != null) + if(!_uuid.isEmpty()) { - name += "-" + _uuid.toString(); + name += "-" + _uuid; } setName(name); @@ -368,7 +374,7 @@ final class TransceiverI implements 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(); @@ -390,9 +396,9 @@ final class TransceiverI implements 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; @@ -458,9 +464,9 @@ final class TransceiverI implements Transceiver { s += "-" + _remoteAddr; } - if(_uuid != null) + if(!_uuid.isEmpty()) { - s += "-" + _uuid.toString(); + s += "-" + _uuid; } final String suffix = s; @@ -671,7 +677,7 @@ final class TransceiverI implements Transceiver private Instance _instance; private String _remoteAddr; - private UUID _uuid; + private String _uuid; private String _connectionId; private String _adapterName; |