@@ -922,42 +922,6 @@ public final class BluetoothAdapter {
|
|||||||
return BluetoothProfile.STATE_DISCONNECTED;
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a listening, L2CAP Bluetooth socket.
|
|
||||||
* <p>A remote device connecting to this socket will optionally be
|
|
||||||
* authenticated and communication on this socket will optionally be
|
|
||||||
* encrypted.
|
|
||||||
* <p>Use {@link BluetoothServerSocket#accept} to retrieve incoming
|
|
||||||
* connections from a listening {@link BluetoothServerSocket}.
|
|
||||||
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
|
|
||||||
* @param secure whether security and authentication are required
|
|
||||||
* @param fixedChannel whether we're looking for a PSM-based connection or a fixed channel
|
|
||||||
* @param channel L2CAP PSM or channel to use
|
|
||||||
* @return a listening L2CAP BluetoothServerSocket
|
|
||||||
* @throws IOException on error, for example Bluetooth not available, or
|
|
||||||
* insufficient permissions, or channel in use.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public BluetoothServerSocket listenUsingL2CapOn(boolean secure, boolean fixedChannel,
|
|
||||||
int channel) throws IOException {
|
|
||||||
BluetoothServerSocket socket;
|
|
||||||
|
|
||||||
if (fixedChannel) {
|
|
||||||
channel |= BluetoothSocket.PORT_MASK_FIXED_CHAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
socket = new BluetoothServerSocket(
|
|
||||||
BluetoothSocket.TYPE_L2CAP, secure, secure, channel);
|
|
||||||
int errno = socket.mSocket.bindListen();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a listening, secure RFCOMM Bluetooth socket.
|
* Create a listening, secure RFCOMM Bluetooth socket.
|
||||||
* <p>A remote device connecting to this socket will be authenticated and
|
* <p>A remote device connecting to this socket will be authenticated and
|
||||||
|
|||||||
@@ -1172,33 +1172,6 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null);
|
return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a L2CAP socket ready to start an outgoing connection.
|
|
||||||
* Call #connect on the returned #BluetoothSocket to begin the connection.
|
|
||||||
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
|
|
||||||
*
|
|
||||||
* @param secure select whether security will be required
|
|
||||||
* @param fixedChannel select if this will be a "fixed channel" L2CAP connection
|
|
||||||
* or a PSM-based connection
|
|
||||||
* @param channel fixed channel or PSM to connect to
|
|
||||||
* @return a L2CAP BluetoothSocket
|
|
||||||
* @throws IOException on error, for example Bluetooth not available, or
|
|
||||||
* insufficient permissions.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public BluetoothSocket createL2CapSocket(boolean secure, boolean fixedChannel, int channel)
|
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
if (fixedChannel) {
|
|
||||||
channel |= BluetoothSocket.PORT_MASK_FIXED_CHAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, secure, secure, this,
|
|
||||||
channel, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that a pin is valid and convert to byte array.
|
* Check that a pin is valid and convert to byte array.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -103,8 +103,6 @@ public final class BluetoothSocket implements Closeable {
|
|||||||
/*package*/ static final int SEC_FLAG_ENCRYPT = 1;
|
/*package*/ static final int SEC_FLAG_ENCRYPT = 1;
|
||||||
/*package*/ static final int SEC_FLAG_AUTH = 1 << 1;
|
/*package*/ static final int SEC_FLAG_AUTH = 1 << 1;
|
||||||
|
|
||||||
/*package*/ static final int PORT_MASK_FIXED_CHAN = 1 << 16;
|
|
||||||
|
|
||||||
private final int mType; /* one of TYPE_RFCOMM etc */
|
private final int mType; /* one of TYPE_RFCOMM etc */
|
||||||
private BluetoothDevice mDevice; /* remote device */
|
private BluetoothDevice mDevice; /* remote device */
|
||||||
private String mAddress; /* remote address */
|
private String mAddress; /* remote address */
|
||||||
@@ -117,7 +115,7 @@ public final class BluetoothSocket implements Closeable {
|
|||||||
private LocalSocket mSocket;
|
private LocalSocket mSocket;
|
||||||
private InputStream mSocketIS;
|
private InputStream mSocketIS;
|
||||||
private OutputStream mSocketOS;
|
private OutputStream mSocketOS;
|
||||||
private int mPort; /* RFCOMM channel or L2CAP psm/channel */
|
private int mPort; /* RFCOMM channel or L2CAP psm */
|
||||||
private int mFd;
|
private int mFd;
|
||||||
private String mServiceName;
|
private String mServiceName;
|
||||||
private static int PROXY_CONNECTION_TIMEOUT = 5000;
|
private static int PROXY_CONNECTION_TIMEOUT = 5000;
|
||||||
|
|||||||
Reference in New Issue
Block a user