diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-10-07 19:26:59 -0400 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-10-07 19:26:59 -0400 |
commit | 7a865a5de8214aa4975371b9d8a2165a01f6b69c (patch) | |
tree | 51fda51e71d433e96ef39d93c9f0ba0d42d71321 /core/java/android | |
parent | dc2ccb82f96b6a7be7a7b262b81d3aa1422f46fa (diff) | |
parent | f242b7b931898856bcbcb7ec36cacf43098ba544 (diff) | |
download | frameworks_base-7a865a5de8214aa4975371b9d8a2165a01f6b69c.zip frameworks_base-7a865a5de8214aa4975371b9d8a2165a01f6b69c.tar.gz frameworks_base-7a865a5de8214aa4975371b9d8a2165a01f6b69c.tar.bz2 |
Merge change Ieed8be00 into eclair
* changes:
Introduce BluetoothAdapter.getDefaultAdapter().
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/app/ApplicationContext.java | 18 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothAdapter.java | 38 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothDevice.java | 3 | ||||
-rw-r--r-- | core/java/android/content/Context.java | 8 | ||||
-rw-r--r-- | core/java/android/server/BluetoothA2dpService.java | 2 | ||||
-rw-r--r-- | core/java/android/server/BluetoothService.java | 2 |
6 files changed, 36 insertions, 35 deletions
diff --git a/core/java/android/app/ApplicationContext.java b/core/java/android/app/ApplicationContext.java index 8ba7c01..f48f150 100644 --- a/core/java/android/app/ApplicationContext.java +++ b/core/java/android/app/ApplicationContext.java @@ -22,8 +22,6 @@ import com.google.android.collect.Maps; import org.xmlpull.v1.XmlPullParserException; -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.IBluetooth; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; @@ -182,8 +180,6 @@ class ApplicationContext extends Context { private StatusBarManager mStatusBarManager = null; private TelephonyManager mTelephonyManager = null; private ClipboardManager mClipboardManager = null; - private boolean mIsBluetoothAdapterCached = false; - private BluetoothAdapter mBluetoothAdapter; private boolean mRestricted; private AccountManager mAccountManager; // protected by mSync @@ -883,8 +879,6 @@ class ApplicationContext extends Context { return getSearchManager(); } else if (SENSOR_SERVICE.equals(name)) { return getSensorManager(); - } else if (BLUETOOTH_SERVICE.equals(name)) { - return getBluetoothAdapter(); } else if (VIBRATOR_SERVICE.equals(name)) { return getVibrator(); } else if (STATUS_BAR_SERVICE.equals(name)) { @@ -1034,18 +1028,6 @@ class ApplicationContext extends Context { return mSearchManager; } - private synchronized BluetoothAdapter getBluetoothAdapter() { - if (!mIsBluetoothAdapterCached) { - mIsBluetoothAdapterCached = true; - IBinder b = ServiceManager.getService(BLUETOOTH_SERVICE); - if (b != null) { - IBluetooth service = IBluetooth.Stub.asInterface(b); - mBluetoothAdapter = new BluetoothAdapter(service); - } - } - return mBluetoothAdapter; - } - private SensorManager getSensorManager() { synchronized (mSync) { if (mSensorManager == null) { diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index 8ce911d..cc35b7d 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/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) { diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index ce975c2..9c23746 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -18,7 +18,6 @@ package android.bluetooth; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; -import android.content.Context; import android.os.IBinder; import android.os.Parcel; import android.os.Parcelable; @@ -328,7 +327,7 @@ public final class BluetoothDevice implements Parcelable { /*package*/ static IBluetooth getService() { synchronized (BluetoothDevice.class) { if (sService == null) { - IBinder b = ServiceManager.getService(Context.BLUETOOTH_SERVICE); + IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE); if (b == null) { throw new RuntimeException("Bluetooth service not available"); } diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index fe4665e..8f1c671 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -1218,14 +1218,6 @@ public abstract class Context { */ public static final String SENSOR_SERVICE = "sensor"; /** - * Use with {@link #getSystemService} to retrieve a {@link - * android.bluetooth.BluetoothAdapter} for using Bluetooth. - * - * @see #getSystemService - * @see android.bluetooth.BluetoothAdapter - */ - public static final String BLUETOOTH_SERVICE = "bluetooth"; - /** * Use with {@link #getSystemService} to retrieve a * com.android.server.WallpaperService for accessing wallpapers. * diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java index d61b42f..b73e53f 100644 --- a/core/java/android/server/BluetoothA2dpService.java +++ b/core/java/android/server/BluetoothA2dpService.java @@ -137,7 +137,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { throw new RuntimeException("Could not init BluetoothA2dpService"); } - mAdapter = (BluetoothAdapter) context.getSystemService(Context.BLUETOOTH_SERVICE); + mAdapter = BluetoothAdapter.getDefaultAdapter(); mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); mIntentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index 3fdbb68..6d4d152 100644 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -154,7 +154,7 @@ public class BluetoothService extends IBluetooth.Stub { } public synchronized void initAfterRegistration() { - mAdapter = (BluetoothAdapter) mContext.getSystemService(Context.BLUETOOTH_SERVICE); + mAdapter = BluetoothAdapter.getDefaultAdapter(); mEventLoop = new BluetoothEventLoop(mContext, mAdapter, this); } |