Loading api/current.txt +9 −1 Original line number Diff line number Diff line Loading @@ -6971,10 +6971,16 @@ package android.bluetooth { public final class BluetoothSocket implements java.io.Closeable { method public void close() throws java.io.IOException; method public void connect() throws java.io.IOException; method public int getConnectionType(); method public java.io.InputStream getInputStream() throws java.io.IOException; method public int getMaxReceivePacketSize(); method public int getMaxTransmitPacketSize(); method public java.io.OutputStream getOutputStream() throws java.io.IOException; method public android.bluetooth.BluetoothDevice getRemoteDevice(); method public boolean isConnected(); field public static final int TYPE_L2CAP = 3; // 0x3 field public static final int TYPE_RFCOMM = 1; // 0x1 field public static final int TYPE_SCO = 2; // 0x2 } } Loading Loading @@ -18108,6 +18114,7 @@ package android.net { public class ConnectivityManager { method public void addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); method public boolean bindProcessToNetwork(android.net.Network); method public android.net.Network getActiveNetwork(); method public android.net.NetworkInfo getActiveNetworkInfo(); method public android.net.NetworkInfo[] getAllNetworkInfo(); method public android.net.Network[] getAllNetworks(); Loading @@ -18126,7 +18133,8 @@ package android.net { method public void registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public void releaseNetworkRequest(android.app.PendingIntent); method public void removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); method public void reportBadNetwork(android.net.Network); method public deprecated void reportBadNetwork(android.net.Network); method public void reportNetworkConnectivity(android.net.Network, boolean); method public void requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public void requestNetwork(android.net.NetworkRequest, android.app.PendingIntent); method public deprecated boolean requestRouteToHost(int, int); api/system-current.txt +9 −1 Original line number Diff line number Diff line Loading @@ -7162,10 +7162,16 @@ package android.bluetooth { public final class BluetoothSocket implements java.io.Closeable { method public void close() throws java.io.IOException; method public void connect() throws java.io.IOException; method public int getConnectionType(); method public java.io.InputStream getInputStream() throws java.io.IOException; method public int getMaxReceivePacketSize(); method public int getMaxTransmitPacketSize(); method public java.io.OutputStream getOutputStream() throws java.io.IOException; method public android.bluetooth.BluetoothDevice getRemoteDevice(); method public boolean isConnected(); field public static final int TYPE_L2CAP = 3; // 0x3 field public static final int TYPE_RFCOMM = 1; // 0x1 field public static final int TYPE_SCO = 2; // 0x2 } } Loading Loading @@ -19566,6 +19572,7 @@ package android.net { public class ConnectivityManager { method public void addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); method public boolean bindProcessToNetwork(android.net.Network); method public android.net.Network getActiveNetwork(); method public android.net.NetworkInfo getActiveNetworkInfo(); method public android.net.NetworkInfo[] getAllNetworkInfo(); method public android.net.Network[] getAllNetworks(); Loading @@ -19584,7 +19591,8 @@ package android.net { method public void registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public void releaseNetworkRequest(android.app.PendingIntent); method public void removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); method public void reportBadNetwork(android.net.Network); method public deprecated void reportBadNetwork(android.net.Network); method public void reportNetworkConnectivity(android.net.Network, boolean); method public void requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public void requestNetwork(android.net.NetworkRequest, android.app.PendingIntent); method public deprecated boolean requestRouteToHost(int, int); core/java/android/bluetooth/BluetoothAdapter.java +47 −1 Original line number Diff line number Diff line /* * Copyright (C) 2009-2014 The Android Open Source Project * Copyright (C) 2009-2015 The Android Open Source Project * Copyright (C) 2015 Samsung LSI * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -374,6 +375,18 @@ public final class BluetoothAdapter { /** @hide */ public static final String BLUETOOTH_MANAGER_SERVICE = "bluetooth_manager"; /** When creating a ServerSocket using listenUsingRfcommOn() or * listenUsingL2capOn() use SOCKET_CHANNEL_AUTO_STATIC to create * a ServerSocket that auto assigns a channel number to the first * bluetooth socket. * The channel number assigned to this first Bluetooth Socket will * be stored in the ServerSocket, and reused for subsequent Bluetooth * sockets. * @hide */ public static final int SOCKET_CHANNEL_AUTO_STATIC_NO_SDP = -2; private static final int ADDRESS_LENGTH = 17; private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30; Loading Loading @@ -1141,6 +1154,9 @@ public final class BluetoothAdapter { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_RFCOMM, true, true, channel); int errno = socket.mSocket.bindListen(); if(channel == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); } if (errno != 0) { //TODO(BT): Throw the same exception error code // that the previous code was using. Loading Loading @@ -1275,6 +1291,9 @@ public final class BluetoothAdapter { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_RFCOMM, false, false, port); int errno = socket.mSocket.bindListen(); if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); } if (errno != 0) { //TODO(BT): Throw the same exception error code // that the previous code was using. Loading @@ -1297,6 +1316,9 @@ public final class BluetoothAdapter { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_RFCOMM, false, true, port); int errno = socket.mSocket.bindListen(); if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); } if (errno < 0) { //TODO(BT): Throw the same exception error code // that the previous code was using. Loading Loading @@ -1326,6 +1348,30 @@ public final class BluetoothAdapter { return socket; } /** * Construct an encrypted, authenticated, L2CAP server socket. * Call #accept to retrieve connections to this socket. * @return An L2CAP BluetoothServerSocket * @throws IOException On error, for example Bluetooth not available, or * insufficient permissions. * @hide */ public BluetoothServerSocket listenUsingL2capOn(int port) throws IOException { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_L2CAP, true, true, port); int errno = socket.mSocket.bindListen(); if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); } if (errno != 0) { //TODO(BT): Throw the same exception error code // that the previous code was using. //socket.mSocket.throwErrnoNative(errno); throw new IOException("Error: " + errno); } return socket; } /** * Read the local Out of Band Pairing Data * <p>Requires {@link android.Manifest.permission#BLUETOOTH} Loading core/java/android/bluetooth/BluetoothDevice.java +66 −3 Original line number Diff line number Diff line Loading @@ -302,6 +302,12 @@ public final class BluetoothDevice implements Parcelable { */ public static final int DEVICE_TYPE_DUAL = 3; /** @hide */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_SDP_RECORD = "android.bluetooth.device.action.SDP_RECORD"; /** * Broadcast Action: This intent is used to broadcast the {@link UUID} * wrapped as a {@link android.os.ParcelUuid} of the remote device after it Loading Loading @@ -526,6 +532,13 @@ public final class BluetoothDevice implements Parcelable { */ public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID"; /** @hide */ public static final String EXTRA_SDP_RECORD = "android.bluetooth.device.extra.SDP_RECORD"; /** @hide */ public static final String EXTRA_SDP_SEARCH_STATUS = "android.bluetooth.device.extra.SDP_SEARCH_STATUS"; /** * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. Loading Loading @@ -1054,14 +1067,34 @@ public final class BluetoothDevice implements Parcelable { return false; } /** * Perform a service discovery on the remote device to get the SDP records associated * with the specified UUID. * * <p>This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent, * with the SDP records found on the remote end. If there is an error * in getting the SDP records or if the process takes a long time, * {@link #ACTION_SDP_RECORD} intent is sent with an status value in * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0. * Detailed status error codes can be found by members of the Bluetooth package in * the AbstractionLayer class. * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}. * The object type will match one of the SdpXxxRecord types, depending on the UUID searched * for. * * @return False if the sanity check fails, True if the process * of initiating an ACL connection to the remote device * was started. */ /** @hide */ public boolean fetchMasInstances() { public boolean sdpSearch(ParcelUuid uuid) { if (sService == null) { Log.e(TAG, "BT not enabled. Cannot query remote device for MAS instances"); Log.e(TAG, "BT not enabled. Cannot query remote device sdp records"); return false; } try { return sService.fetchRemoteMasInstances(this); return sService.sdpSearch(this,uuid); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } Loading Loading @@ -1260,6 +1293,36 @@ public final class BluetoothDevice implements Parcelable { null); } /** * Create an L2cap {@link BluetoothSocket} ready to start a secure * outgoing connection to this remote device on given channel. * <p>The remote device will be authenticated and communication on this * socket will be encrypted. * <p> Use this socket only if an authenticated socket link is possible. * Authentication refers to the authentication of the link key to * prevent man-in-the-middle type of attacks. * For example, for Bluetooth 2.1 devices, if any of the devices does not * have an input and output capability or just has the ability to * display a numeric key, a secure socket connection is not possible. * In such a case, use {#link createInsecureRfcommSocket}. * For more details, refer to the Security Model section 5.2 (vol 3) of * Bluetooth Core Specification version 2.1 + EDR. * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing * connection. * <p>Valid L2CAP PSM channels are in range 1 to 2^16. * <p>Requires {@link android.Manifest.permission#BLUETOOTH} * * @param channel L2cap PSM/channel to connect to * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection * @throws IOException on error, for example Bluetooth not available, or * insufficient permissions * @hide */ public BluetoothSocket createL2capSocket(int channel) throws IOException { return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, true, true, this, channel, null); } /** * Create an RFCOMM {@link BluetoothSocket} ready to start a secure * outgoing connection to this remote device using SDP lookup of uuid. Loading core/java/android/bluetooth/BluetoothServerSocket.java +51 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.bluetooth; import android.os.Handler; import android.os.ParcelUuid; import android.util.Log; import java.io.Closeable; import java.io.IOException; Loading Loading @@ -66,10 +67,11 @@ import java.io.IOException; */ public final class BluetoothServerSocket implements Closeable { private static final String TAG = "BluetoothServerSocket"; /*package*/ final BluetoothSocket mSocket; private Handler mHandler; private int mMessage; private final int mChannel; private int mChannel; /** * Construct a socket for incoming connections. Loading @@ -84,6 +86,9 @@ public final class BluetoothServerSocket implements Closeable { throws IOException { mChannel = port; mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null); if(port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } } /** Loading @@ -98,6 +103,7 @@ public final class BluetoothServerSocket implements Closeable { /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, ParcelUuid uuid) throws IOException { mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, -1, uuid); // TODO: This is the same as mChannel = -1 - is this intentional? mChannel = mSocket.getPort(); } Loading Loading @@ -153,6 +159,7 @@ public final class BluetoothServerSocket implements Closeable { /*package*/ void setServiceName(String ServiceName) { mSocket.setServiceName(ServiceName); } /** * Returns the channel on which this socket is bound. * @hide Loading @@ -160,4 +167,47 @@ public final class BluetoothServerSocket implements Closeable { public int getChannel() { return mChannel; } /** * Sets the channel on which future sockets are bound. * Currently used only when a channel is auto generated. */ /*package*/ void setChannel(int newChannel) { /* TODO: From a design/architecture perspective this is wrong. * The bind operation should be conducted through this class * and the resulting port should be kept in mChannel, and * not set from BluetoothAdapter. */ if(mSocket != null) { if(mSocket.getPort() != newChannel) { Log.w(TAG,"The port set is different that the underlying port. mSocket.getPort(): " + mSocket.getPort() + " requested newChannel: " + newChannel); } } mChannel = newChannel; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("ServerSocket: Type: "); switch(mSocket.getConnectionType()) { case BluetoothSocket.TYPE_RFCOMM: { sb.append("TYPE_RFCOMM"); break; } case BluetoothSocket.TYPE_L2CAP: { sb.append("TYPE_L2CAP"); break; } case BluetoothSocket.TYPE_SCO: { sb.append("TYPE_SCO"); break; } } sb.append(" Channel: ").append(mChannel); return sb.toString(); } } Loading
api/current.txt +9 −1 Original line number Diff line number Diff line Loading @@ -6971,10 +6971,16 @@ package android.bluetooth { public final class BluetoothSocket implements java.io.Closeable { method public void close() throws java.io.IOException; method public void connect() throws java.io.IOException; method public int getConnectionType(); method public java.io.InputStream getInputStream() throws java.io.IOException; method public int getMaxReceivePacketSize(); method public int getMaxTransmitPacketSize(); method public java.io.OutputStream getOutputStream() throws java.io.IOException; method public android.bluetooth.BluetoothDevice getRemoteDevice(); method public boolean isConnected(); field public static final int TYPE_L2CAP = 3; // 0x3 field public static final int TYPE_RFCOMM = 1; // 0x1 field public static final int TYPE_SCO = 2; // 0x2 } } Loading Loading @@ -18108,6 +18114,7 @@ package android.net { public class ConnectivityManager { method public void addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); method public boolean bindProcessToNetwork(android.net.Network); method public android.net.Network getActiveNetwork(); method public android.net.NetworkInfo getActiveNetworkInfo(); method public android.net.NetworkInfo[] getAllNetworkInfo(); method public android.net.Network[] getAllNetworks(); Loading @@ -18126,7 +18133,8 @@ package android.net { method public void registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public void releaseNetworkRequest(android.app.PendingIntent); method public void removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); method public void reportBadNetwork(android.net.Network); method public deprecated void reportBadNetwork(android.net.Network); method public void reportNetworkConnectivity(android.net.Network, boolean); method public void requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public void requestNetwork(android.net.NetworkRequest, android.app.PendingIntent); method public deprecated boolean requestRouteToHost(int, int);
api/system-current.txt +9 −1 Original line number Diff line number Diff line Loading @@ -7162,10 +7162,16 @@ package android.bluetooth { public final class BluetoothSocket implements java.io.Closeable { method public void close() throws java.io.IOException; method public void connect() throws java.io.IOException; method public int getConnectionType(); method public java.io.InputStream getInputStream() throws java.io.IOException; method public int getMaxReceivePacketSize(); method public int getMaxTransmitPacketSize(); method public java.io.OutputStream getOutputStream() throws java.io.IOException; method public android.bluetooth.BluetoothDevice getRemoteDevice(); method public boolean isConnected(); field public static final int TYPE_L2CAP = 3; // 0x3 field public static final int TYPE_RFCOMM = 1; // 0x1 field public static final int TYPE_SCO = 2; // 0x2 } } Loading Loading @@ -19566,6 +19572,7 @@ package android.net { public class ConnectivityManager { method public void addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); method public boolean bindProcessToNetwork(android.net.Network); method public android.net.Network getActiveNetwork(); method public android.net.NetworkInfo getActiveNetworkInfo(); method public android.net.NetworkInfo[] getAllNetworkInfo(); method public android.net.Network[] getAllNetworks(); Loading @@ -19584,7 +19591,8 @@ package android.net { method public void registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public void releaseNetworkRequest(android.app.PendingIntent); method public void removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); method public void reportBadNetwork(android.net.Network); method public deprecated void reportBadNetwork(android.net.Network); method public void reportNetworkConnectivity(android.net.Network, boolean); method public void requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public void requestNetwork(android.net.NetworkRequest, android.app.PendingIntent); method public deprecated boolean requestRouteToHost(int, int);
core/java/android/bluetooth/BluetoothAdapter.java +47 −1 Original line number Diff line number Diff line /* * Copyright (C) 2009-2014 The Android Open Source Project * Copyright (C) 2009-2015 The Android Open Source Project * Copyright (C) 2015 Samsung LSI * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -374,6 +375,18 @@ public final class BluetoothAdapter { /** @hide */ public static final String BLUETOOTH_MANAGER_SERVICE = "bluetooth_manager"; /** When creating a ServerSocket using listenUsingRfcommOn() or * listenUsingL2capOn() use SOCKET_CHANNEL_AUTO_STATIC to create * a ServerSocket that auto assigns a channel number to the first * bluetooth socket. * The channel number assigned to this first Bluetooth Socket will * be stored in the ServerSocket, and reused for subsequent Bluetooth * sockets. * @hide */ public static final int SOCKET_CHANNEL_AUTO_STATIC_NO_SDP = -2; private static final int ADDRESS_LENGTH = 17; private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30; Loading Loading @@ -1141,6 +1154,9 @@ public final class BluetoothAdapter { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_RFCOMM, true, true, channel); int errno = socket.mSocket.bindListen(); if(channel == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); } if (errno != 0) { //TODO(BT): Throw the same exception error code // that the previous code was using. Loading Loading @@ -1275,6 +1291,9 @@ public final class BluetoothAdapter { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_RFCOMM, false, false, port); int errno = socket.mSocket.bindListen(); if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); } if (errno != 0) { //TODO(BT): Throw the same exception error code // that the previous code was using. Loading @@ -1297,6 +1316,9 @@ public final class BluetoothAdapter { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_RFCOMM, false, true, port); int errno = socket.mSocket.bindListen(); if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); } if (errno < 0) { //TODO(BT): Throw the same exception error code // that the previous code was using. Loading Loading @@ -1326,6 +1348,30 @@ public final class BluetoothAdapter { return socket; } /** * Construct an encrypted, authenticated, L2CAP server socket. * Call #accept to retrieve connections to this socket. * @return An L2CAP BluetoothServerSocket * @throws IOException On error, for example Bluetooth not available, or * insufficient permissions. * @hide */ public BluetoothServerSocket listenUsingL2capOn(int port) throws IOException { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_L2CAP, true, true, port); int errno = socket.mSocket.bindListen(); if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); } if (errno != 0) { //TODO(BT): Throw the same exception error code // that the previous code was using. //socket.mSocket.throwErrnoNative(errno); throw new IOException("Error: " + errno); } return socket; } /** * Read the local Out of Band Pairing Data * <p>Requires {@link android.Manifest.permission#BLUETOOTH} Loading
core/java/android/bluetooth/BluetoothDevice.java +66 −3 Original line number Diff line number Diff line Loading @@ -302,6 +302,12 @@ public final class BluetoothDevice implements Parcelable { */ public static final int DEVICE_TYPE_DUAL = 3; /** @hide */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_SDP_RECORD = "android.bluetooth.device.action.SDP_RECORD"; /** * Broadcast Action: This intent is used to broadcast the {@link UUID} * wrapped as a {@link android.os.ParcelUuid} of the remote device after it Loading Loading @@ -526,6 +532,13 @@ public final class BluetoothDevice implements Parcelable { */ public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID"; /** @hide */ public static final String EXTRA_SDP_RECORD = "android.bluetooth.device.extra.SDP_RECORD"; /** @hide */ public static final String EXTRA_SDP_SEARCH_STATUS = "android.bluetooth.device.extra.SDP_SEARCH_STATUS"; /** * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. Loading Loading @@ -1054,14 +1067,34 @@ public final class BluetoothDevice implements Parcelable { return false; } /** * Perform a service discovery on the remote device to get the SDP records associated * with the specified UUID. * * <p>This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent, * with the SDP records found on the remote end. If there is an error * in getting the SDP records or if the process takes a long time, * {@link #ACTION_SDP_RECORD} intent is sent with an status value in * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0. * Detailed status error codes can be found by members of the Bluetooth package in * the AbstractionLayer class. * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}. * The object type will match one of the SdpXxxRecord types, depending on the UUID searched * for. * * @return False if the sanity check fails, True if the process * of initiating an ACL connection to the remote device * was started. */ /** @hide */ public boolean fetchMasInstances() { public boolean sdpSearch(ParcelUuid uuid) { if (sService == null) { Log.e(TAG, "BT not enabled. Cannot query remote device for MAS instances"); Log.e(TAG, "BT not enabled. Cannot query remote device sdp records"); return false; } try { return sService.fetchRemoteMasInstances(this); return sService.sdpSearch(this,uuid); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } Loading Loading @@ -1260,6 +1293,36 @@ public final class BluetoothDevice implements Parcelable { null); } /** * Create an L2cap {@link BluetoothSocket} ready to start a secure * outgoing connection to this remote device on given channel. * <p>The remote device will be authenticated and communication on this * socket will be encrypted. * <p> Use this socket only if an authenticated socket link is possible. * Authentication refers to the authentication of the link key to * prevent man-in-the-middle type of attacks. * For example, for Bluetooth 2.1 devices, if any of the devices does not * have an input and output capability or just has the ability to * display a numeric key, a secure socket connection is not possible. * In such a case, use {#link createInsecureRfcommSocket}. * For more details, refer to the Security Model section 5.2 (vol 3) of * Bluetooth Core Specification version 2.1 + EDR. * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing * connection. * <p>Valid L2CAP PSM channels are in range 1 to 2^16. * <p>Requires {@link android.Manifest.permission#BLUETOOTH} * * @param channel L2cap PSM/channel to connect to * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection * @throws IOException on error, for example Bluetooth not available, or * insufficient permissions * @hide */ public BluetoothSocket createL2capSocket(int channel) throws IOException { return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, true, true, this, channel, null); } /** * Create an RFCOMM {@link BluetoothSocket} ready to start a secure * outgoing connection to this remote device using SDP lookup of uuid. Loading
core/java/android/bluetooth/BluetoothServerSocket.java +51 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.bluetooth; import android.os.Handler; import android.os.ParcelUuid; import android.util.Log; import java.io.Closeable; import java.io.IOException; Loading Loading @@ -66,10 +67,11 @@ import java.io.IOException; */ public final class BluetoothServerSocket implements Closeable { private static final String TAG = "BluetoothServerSocket"; /*package*/ final BluetoothSocket mSocket; private Handler mHandler; private int mMessage; private final int mChannel; private int mChannel; /** * Construct a socket for incoming connections. Loading @@ -84,6 +86,9 @@ public final class BluetoothServerSocket implements Closeable { throws IOException { mChannel = port; mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null); if(port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } } /** Loading @@ -98,6 +103,7 @@ public final class BluetoothServerSocket implements Closeable { /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, ParcelUuid uuid) throws IOException { mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, -1, uuid); // TODO: This is the same as mChannel = -1 - is this intentional? mChannel = mSocket.getPort(); } Loading Loading @@ -153,6 +159,7 @@ public final class BluetoothServerSocket implements Closeable { /*package*/ void setServiceName(String ServiceName) { mSocket.setServiceName(ServiceName); } /** * Returns the channel on which this socket is bound. * @hide Loading @@ -160,4 +167,47 @@ public final class BluetoothServerSocket implements Closeable { public int getChannel() { return mChannel; } /** * Sets the channel on which future sockets are bound. * Currently used only when a channel is auto generated. */ /*package*/ void setChannel(int newChannel) { /* TODO: From a design/architecture perspective this is wrong. * The bind operation should be conducted through this class * and the resulting port should be kept in mChannel, and * not set from BluetoothAdapter. */ if(mSocket != null) { if(mSocket.getPort() != newChannel) { Log.w(TAG,"The port set is different that the underlying port. mSocket.getPort(): " + mSocket.getPort() + " requested newChannel: " + newChannel); } } mChannel = newChannel; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("ServerSocket: Type: "); switch(mSocket.getConnectionType()) { case BluetoothSocket.TYPE_RFCOMM: { sb.append("TYPE_RFCOMM"); break; } case BluetoothSocket.TYPE_L2CAP: { sb.append("TYPE_L2CAP"); break; } case BluetoothSocket.TYPE_SCO: { sb.append("TYPE_SCO"); break; } } sb.append(" Channel: ").append(mChannel); return sb.toString(); } }