diff options
| author | Nick Pelly <npelly@google.com> | 2009-10-08 00:12:45 +0200 |
|---|---|---|
| committer | Nick Pelly <npelly@google.com> | 2009-10-08 00:27:17 +0200 |
| commit | 79b3ff80ff00f3186f8d8cc07520a3c211e489a0 (patch) | |
| tree | cc189b553d084a6717f944c376166e319caab7f1 /framework/java/android/bluetooth/BluetoothAdapter.java | |
| parent | 07b84cb5bb5283352a27cc0cf651586ed00035a0 (diff) | |
Introduce BluetoothAdapter.getDefaultAdapter().
This is the main entry point to the Bluetooth APIs, and returns the default
local Bluetooth adapter.
It replaces context.getSystemService(Context.BLUETOOTH_SERVICE). This was
never in a public SDK release.
DrNo: eastham
Bug: 2158765
Joke: Why can't you play cards in the jungle? Because there's too many cheetas!
Change-Id: Ieed8be009ee5aba621cb69090ee8c8a9c19c840d
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
| -rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index 8ce911de37..cc35b7da9f 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -20,9 +20,11 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.os.Binder; import android.os.Handler; +import android.os.IBinder; import android.os.Message; import android.os.ParcelUuid; import android.os.RemoteException; +import android.os.ServiceManager; import android.util.Log; import java.io.IOException; @@ -36,10 +38,8 @@ import java.util.UUID; /** * Represents the local Bluetooth adapter. * - * <p>Use {@link android.content.Context#getSystemService} with {@link - * android.content.Context#BLUETOOTH_SERVICE} to get the default local - * Bluetooth adapter. On most Android devices there is only one local - * Bluetotoh adapter. + * <p>Use {@link #getDefaultAdapter} to get the default local Bluetooth + * adapter. * * <p>Use the {@link BluetoothDevice} class for operations on remote Bluetooth * devices. @@ -257,12 +257,40 @@ public final class BluetoothAdapter { */ public static final String EXTRA_LOCAL_NAME = "android.bluetooth.adapter.extra.LOCAL_NAME"; + /** @hide */ + public static final String BLUETOOTH_SERVICE = "bluetooth"; + private static final int ADDRESS_LENGTH = 17; + /** + * Lazyily initialized singleton. Guaranteed final after first object + * constructed. + */ + private static BluetoothAdapter sAdapter; + private final IBluetooth mService; /** - * Do not use this constructor. Use Context.getSystemService() instead. + * Get a handle to the default local Bluetooth adapter. + * <p>Currently Android only supports one Bluetooth adapter, but the API + * could be extended to support more. This will always return the default + * adapter. + * @return the default local adapter, or null if Bluetooth is not supported + * on this hardware platform + */ + public static synchronized BluetoothAdapter getDefaultAdapter() { + if (sAdapter == null) { + IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE); + if (b != null) { + IBluetooth service = IBluetooth.Stub.asInterface(b); + sAdapter = new BluetoothAdapter(service); + } + } + return sAdapter; + } + + /** + * Use {@link #getDefaultAdapter} to get the BluetoothAdapter instance. * @hide */ public BluetoothAdapter(IBluetooth service) { |
