Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88427cff authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change Ibcfb7d10 into eclair-sdk

* changes:
  docs: add more documentation for the bluetooth apis.
parents 3a103a87 9fab0aef
Loading
Loading
Loading
Loading
+22 −5
Original line number Original line Diff line number Diff line
@@ -36,13 +36,30 @@ import java.util.Set;
import java.util.UUID;
import java.util.UUID;


/**
/**
 * Represents the local Bluetooth adapter.
 * Represents the local device Bluetooth adapter. The {@link BluetoothAdapter}
 * lets you perform fundamental Bluetooth tasks, such as initiate
 * device discovery, query a list of bonded (paired) devices,
 * instantiate a {@link BluetoothDevice} using a known MAC address, and create
 * a {@link BluetoothServerSocket} to listen for connection requests from other
 * devices.
 *
 *
 * <p>Use {@link #getDefaultAdapter} to get the default local Bluetooth
 * <p>To get a {@link BluetoothAdapter} representing the local Bluetooth
 * adapter.
 * adapter, call the static {@link #getDefaultAdapter} method.
 * Fundamentally, this is your starting point for all
 * Bluetooth actions. Once you have the local adapter, you can get a set of
 * {@link BluetoothDevice} objects representing all paired devices with
 * {@link #getBondedDevices()}; start device discovery with
 * {@link #startDiscovery()}; or create a {@link BluetoothServerSocket} to
 * listen for incoming connection requests with
 * {@link #listenUsingRfcommWithServiceRecord(String,UUID)}.
 *
 *
 * <p>Use the {@link BluetoothDevice} class for operations on remote Bluetooth
 * <p class="note"><strong>Note:</strong>
 * devices.
 * Most methods require the {@link android.Manifest.permission#BLUETOOTH}
 * permission and some also require the
 * {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
 *
 * {@see BluetoothDevice}
 * {@see BluetoothServerSocket}
 */
 */
public final class BluetoothAdapter {
public final class BluetoothAdapter {
    private static final String TAG = "BluetoothAdapter";
    private static final String TAG = "BluetoothAdapter";
+35 −17
Original line number Original line Diff line number Diff line
@@ -20,25 +20,37 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;


/**
/**
 * Represents a Bluetooth class.
 * Represents a Bluetooth class, which describes general characteristics
 * and capabilities of a device. For example, a Bluetooth class will
 * specify the general device type such as a phone, a computer, or
 * headset, and whether it's capable of services such as audio or telephony.
 *
 *
 * <p>Bluetooth Class is a 32 bit field. The format of these bits is defined at
 * <p>The Bluetooth class is useful as a hint to roughly describe a device (for example to
 *   http://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
 * show an icon in the UI), but does not reliably describe which Bluetooth
 * (login required). This class contains that 32 bit field, and provides
 * profiles or services are actually supported by a device.
 * constants and methods to determine which Service Class(es) and Device Class
 * are encoded in that field.
 *
 *
 * <p>Every Bluetooth Class is composed of zero or more service classes, and
 * <p>Every Bluetooth class is composed of zero or more service classes, and
 * exactly one device class. The device class is further broken down into major
 * exactly one device class. The device class is further broken down into major
 * and minor device class components.
 * and minor device class components.
 *
 *
 * <p>Class is useful as a hint to roughly describe a device (for example to
 * <p>{@link BluetoothClass} is useful as a hint to roughly describe a device
 * show an icon in the UI), but does not reliably describe which Bluetooth
 * (for example to show an icon in the UI), but does not reliably describe which
 * profiles or services are actually supported by a device. Accurate service
 * Bluetooth profiles or services are actually supported by a device. Accurate
 * discovery is done through SDP requests.
 * service discovery is done through SDP requests, which are automatically
 * performed when creating an RFCOMM socket with {@link
 * BluetoothDevice#createRfcommSocketToServiceRecord(UUID)} and {@link
 * BluetoothAdapter#listenUsingRfcommWithServiceRecord(String,UUID)}</p>
 *
 *
 * <p>Use {@link BluetoothDevice#getBluetoothClass} to retrieve the class for
 * <p>Use {@link BluetoothDevice#getBluetoothClass} to retrieve the class for
 * a remote device.
 * a remote device.
 *
 * <!--
 * The Bluetooth class is a 32 bit field. The format of these bits is defined at
 * http://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
 * (login required). This class contains that 32 bit field, and provides
 * constants and methods to determine which Service Class(es) and Device Class
 * are encoded in that field.
 * -->
 */
 */
public final class BluetoothClass implements Parcelable {
public final class BluetoothClass implements Parcelable {
    /**
    /**
@@ -91,7 +103,7 @@ public final class BluetoothClass implements Parcelable {
    }
    }


    /**
    /**
     * Bluetooth service classes.
     * Defines all service class constants.
     * <p>Each {@link BluetoothClass} encodes zero or more service classes.
     * <p>Each {@link BluetoothClass} encodes zero or more service classes.
     */
     */
    public static final class Service {
    public static final class Service {
@@ -109,7 +121,8 @@ public final class BluetoothClass implements Parcelable {
    }
    }


    /**
    /**
     * Return true if the specified service class is supported by this class.
     * Return true if the specified service class is supported by this
     * {@link BluetoothClass}.
     * <p>Valid service classes are the public constants in
     * <p>Valid service classes are the public constants in
     * {@link BluetoothClass.Service}. For example, {@link
     * {@link BluetoothClass.Service}. For example, {@link
     * BluetoothClass.Service#AUDIO}.
     * BluetoothClass.Service#AUDIO}.
@@ -122,17 +135,22 @@ public final class BluetoothClass implements Parcelable {
    }
    }


    /**
    /**
     * Bluetooth device classes.
     * Defines all device class constants.
     * <p>Each {@link BluetoothClass} encodes exactly one device class, with
     * <p>Each {@link BluetoothClass} encodes exactly one device class, with
     * major and minor components.
     * major and minor components.
     * <p>The constants in {@link
     * <p>The constants in {@link
     * BluetoothClass.Device} represent a combination of major and minor
     * BluetoothClass.Device} represent a combination of major and minor
     * components (the complete device class). The constants in {@link
     * device components (the complete device class). The constants in {@link
     * BluetoothClass.Device.Major} represent just the major device classes.
     * BluetoothClass.Device.Major} represent only major device classes.
     * <p>See {@link BluetoothClass.Service} for service class constants.
     */
     */
    public static class Device {
    public static class Device {
        private static final int BITMASK               = 0x1FFC;
        private static final int BITMASK               = 0x1FFC;


        /**
         * Defines all major device class constants.
         * <p>See {@link BluetoothClass.Device} for minor classes.
         */
        public static class Major {
        public static class Major {
            private static final int BITMASK           = 0x1F00;
            private static final int BITMASK           = 0x1F00;


@@ -215,7 +233,7 @@ public final class BluetoothClass implements Parcelable {
    }
    }


    /**
    /**
     * Return the major device class component of this Bluetooth class.
     * Return the major device class component of this {@link BluetoothClass}.
     * <p>Values returned from this function can be compared with the
     * <p>Values returned from this function can be compared with the
     * public constants in {@link BluetoothClass.Device.Major} to determine
     * public constants in {@link BluetoothClass.Device.Major} to determine
     * which major class is encoded in this Bluetooth class.
     * which major class is encoded in this Bluetooth class.
+19 −4
Original line number Original line Diff line number Diff line
@@ -31,16 +31,31 @@ import java.io.UnsupportedEncodingException;
import java.util.UUID;
import java.util.UUID;


/**
/**
 * Represents a remote Bluetooth device.
 * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you
 *
 * create a connection with the repective device or query information about
 * <p>Use {@link BluetoothAdapter#getRemoteDevice} to create a {@link
 * it, such as the name, address, class, and bonding state.
 * BluetoothDevice}.
 *
 *
 * <p>This class is really just a thin wrapper for a Bluetooth hardware
 * <p>This class is really just a thin wrapper for a Bluetooth hardware
 * address. Objects of this class are immutable. Operations on this class
 * address. Objects of this class are immutable. Operations on this class
 * are performed on the remote Bluetooth hardware address, using the
 * are performed on the remote Bluetooth hardware address, using the
 * {@link BluetoothAdapter} that was used to create this {@link
 * {@link BluetoothAdapter} that was used to create this {@link
 * BluetoothDevice}.
 * BluetoothDevice}.
 *
 * <p>To get a {@link BluetoothDevice}, use
 * {@link BluetoothAdapter#getRemoteDevice(String)
 * BluetoothAdapter.getRemoteDevice(String)} to create one representing a device
 * of a known MAC address (which you can get through device discovery with
 * {@link BluetoothAdapter}) or get one from the set of bonded devices
 * returned by {@link BluetoothAdapter#getBondedDevices()
 * BluetoothAdapter.getBondedDevices()}. You can then open a
 * {@link BluetoothSocket} for communciation with the remote device, using
 * {@link #createRfcommSocketToServiceRecord(UUID)}.
 *
 * <p class="note"><strong>Note:</strong>
 * Requires the {@link android.Manifest.permission#BLUETOOTH} permission.
 *
 * {@see BluetoothAdapter}
 * {@see BluetoothSocket}
 */
 */
public final class BluetoothDevice implements Parcelable {
public final class BluetoothDevice implements Parcelable {
    private static final String TAG = "BluetoothDevice";
    private static final String TAG = "BluetoothDevice";
+20 −18
Original line number Original line Diff line number Diff line
@@ -27,29 +27,31 @@ import java.io.IOException;
 * <p>The interface for Bluetooth Sockets is similar to that of TCP sockets:
 * <p>The interface for Bluetooth Sockets is similar to that of TCP sockets:
 * {@link java.net.Socket} and {@link java.net.ServerSocket}. On the server
 * {@link java.net.Socket} and {@link java.net.ServerSocket}. On the server
 * side, use a {@link BluetoothServerSocket} to create a listening server
 * side, use a {@link BluetoothServerSocket} to create a listening server
 * socket. It will return a new, connected {@link BluetoothSocket} on an
 * socket. When a connection is accepted by the {@link BluetoothServerSocket},
 * accepted connection. On the client side, use the same
 * it will return a new {@link BluetoothSocket} to manage the connection.
 * {@link BluetoothSocket} object to both intiate the outgoing connection,
 * On the client side, use a single {@link BluetoothSocket} to both intiate
 * and to manage the connected socket.
 * an outgoing connection and to manage the connection.
 *
 *
 * <p>The most common type of Bluetooth Socket is RFCOMM. RFCOMM is a
 * <p>The most common type of Bluetooth socket is RFCOMM, which is the type
 * connection orientated, streaming transport over Bluetooth. It is also known
 * supported by the Android APIs. RFCOMM is a connection-oriented, streaming
 * as the Serial Port Profile (SPP).
 * transport over Bluetooth. It is also known as the Serial Port Profile (SPP).
 *
 *
 * <p>Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to create
 * <p>To create a listenting {@link BluetoothServerSocket} that's ready for
 * a new {@link BluetoothSocket} ready for an outgoing connection to a remote
 * incoming connections, use
 * {@link BluetoothDevice}.
 * {@link BluetoothAdapter#listenUsingRfcommWithServiceRecord
 * BluetoothAdapter.listenUsingRfcommWithServiceRecord()}. Then call
 * {@link #accept()} to listen for incoming connection requests. This call
 * will block until a connection is established, at which point, it will return
 * a {@link BluetoothSocket} to manage the connection.
 *
 *
 * <p>Use {@link BluetoothAdapter#listenUsingRfcommWithServiceRecord} to
 * <p>{@link BluetoothServerSocket} is thread
 * create a listening {@link BluetoothServerSocket} ready for incoming
 * connections to the local {@link BluetoothAdapter}.
 *
 * <p>{@link BluetoothSocket} and {@link BluetoothServerSocket} are thread
 * safe. In particular, {@link #close} will always immediately abort ongoing
 * safe. In particular, {@link #close} will always immediately abort ongoing
 * operations and close the socket.
 * operations and close the server socket.
 *
 * <p class="note"><strong>Note:</strong>
 * Requires the {@link android.Manifest.permission#BLUETOOTH} permission.
 *
 *
 * <p>All methods on a {@link BluetoothServerSocket} require
 * {@see BluetoothSocket}
 * {@link android.Manifest.permission#BLUETOOTH}
 */
 */
public final class BluetoothServerSocket implements Closeable {
public final class BluetoothServerSocket implements Closeable {


+28 −16
Original line number Original line Diff line number Diff line
@@ -33,29 +33,41 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 * <p>The interface for Bluetooth Sockets is similar to that of TCP sockets:
 * <p>The interface for Bluetooth Sockets is similar to that of TCP sockets:
 * {@link java.net.Socket} and {@link java.net.ServerSocket}. On the server
 * {@link java.net.Socket} and {@link java.net.ServerSocket}. On the server
 * side, use a {@link BluetoothServerSocket} to create a listening server
 * side, use a {@link BluetoothServerSocket} to create a listening server
 * socket. It will return a new, connected {@link BluetoothSocket} on an
 * socket. When a connection is accepted by the {@link BluetoothServerSocket},
 * accepted connection. On the client side, use the same
 * it will return a new {@link BluetoothSocket} to manage the connection.
 * {@link BluetoothSocket} object to both intiate the outgoing connection,
 * On the client side, use a single {@link BluetoothSocket} to both intiate
 * and to manage the connected socket.
 * an outgoing connection and to manage the connection.
 *
 *
 * <p>The most common type of Bluetooth Socket is RFCOMM. RFCOMM is a
 * <p>The most common type of Bluetooth socket is RFCOMM, which is the type
 * connection orientated, streaming transport over Bluetooth. It is also known
 * supported by the Android APIs. RFCOMM is a connection-oriented, streaming
 * as the Serial Port Profile (SPP).
 * transport over Bluetooth. It is also known as the Serial Port Profile (SPP).
 *
 *
 * <p>Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to create
 * <p>To create a {@link BluetoothSocket} for connecting to a known device, use
 * a new {@link BluetoothSocket} ready for an outgoing connection to a remote
 * {@link BluetoothDevice#createRfcommSocketToServiceRecord
 * {@link BluetoothDevice}.
 * BluetoothDevice.createRfcommSocketToServiceRecord()}.
 * Then call {@link #connect()} to attempt a connection to the remote device.
 * This call will block until a connection is established or the connection
 * fails.
 *
 *
 * <p>Use {@link BluetoothAdapter#listenUsingRfcommWithServiceRecord} to
 * <p>To create a {@link BluetoothSocket} as a server (or "host"), see the
 * create a listening {@link BluetoothServerSocket} ready for incoming
 * {@link BluetoothServerSocket} documentation.
 * connections to the local {@link BluetoothAdapter}.
 *
 *
 * <p>{@link BluetoothSocket} and {@link BluetoothServerSocket} are thread
 * <p>Once the socket is connected, whether initiated as a client or accepted
 * as a server, open the IO streams by calling {@link #getInputStream} and
 * {@link #getOutputStream} in order to retrieve {@link java.io.InputStream}
 * and {@link java.io.OutputStream} objects, respectively, which are
 * automatically connected to the socket.
 *
 * <p>{@link BluetoothSocket} is thread
 * safe. In particular, {@link #close} will always immediately abort ongoing
 * safe. In particular, {@link #close} will always immediately abort ongoing
 * operations and close the socket.
 * operations and close the socket.
 *
 *
 * <p>All methods on a {@link BluetoothSocket} require
 * <p class="note"><strong>Note:</strong>
 * {@link android.Manifest.permission#BLUETOOTH}
 * Requires the {@link android.Manifest.permission#BLUETOOTH} permission.
 *
 * {@see BluetoothServerSocket}
 * {@see java.io.InputStream}
 * {@see java.io.OutputStream}
 */
 */
public final class BluetoothSocket implements Closeable {
public final class BluetoothSocket implements Closeable {
    private static final String TAG = "BluetoothSocket";
    private static final String TAG = "BluetoothSocket";
Loading