am 7a865a5d: Merge change Ieed8be00 into eclair

Merge commit '7a865a5de8214aa4975371b9d8a2165a01f6b69c' into eclair-mr2

* commit '7a865a5de8214aa4975371b9d8a2165a01f6b69c':
  Introduce BluetoothAdapter.getDefaultAdapter().
This commit is contained in:
Nick Pelly
2009-10-07 16:36:15 -07:00
committed by Android Git Automerger
10 changed files with 53 additions and 52 deletions

View File

@@ -25550,6 +25550,17 @@
visibility="public" visibility="public"
> >
</method> </method>
<method name="getDefaultAdapter"
return="android.bluetooth.BluetoothAdapter"
abstract="false"
native="false"
synchronized="true"
static="true"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getName" <method name="getName"
return="java.lang.String" return="java.lang.String"
abstract="false" abstract="false"
@@ -31505,17 +31516,6 @@
visibility="public" visibility="public"
> >
</field> </field>
<field name="BLUETOOTH_SERVICE"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;bluetooth&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="CLIPBOARD_SERVICE" <field name="CLIPBOARD_SERVICE"
type="java.lang.String" type="java.lang.String"
transient="false" transient="false"

View File

@@ -22,8 +22,6 @@ import com.google.android.collect.Maps;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.IBluetooth;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.ContentResolver; import android.content.ContentResolver;
@@ -182,8 +180,6 @@ class ApplicationContext extends Context {
private StatusBarManager mStatusBarManager = null; private StatusBarManager mStatusBarManager = null;
private TelephonyManager mTelephonyManager = null; private TelephonyManager mTelephonyManager = null;
private ClipboardManager mClipboardManager = null; private ClipboardManager mClipboardManager = null;
private boolean mIsBluetoothAdapterCached = false;
private BluetoothAdapter mBluetoothAdapter;
private boolean mRestricted; private boolean mRestricted;
private AccountManager mAccountManager; // protected by mSync private AccountManager mAccountManager; // protected by mSync
@@ -883,8 +879,6 @@ class ApplicationContext extends Context {
return getSearchManager(); return getSearchManager();
} else if (SENSOR_SERVICE.equals(name)) { } else if (SENSOR_SERVICE.equals(name)) {
return getSensorManager(); return getSensorManager();
} else if (BLUETOOTH_SERVICE.equals(name)) {
return getBluetoothAdapter();
} else if (VIBRATOR_SERVICE.equals(name)) { } else if (VIBRATOR_SERVICE.equals(name)) {
return getVibrator(); return getVibrator();
} else if (STATUS_BAR_SERVICE.equals(name)) { } else if (STATUS_BAR_SERVICE.equals(name)) {
@@ -1034,18 +1028,6 @@ class ApplicationContext extends Context {
return mSearchManager; 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() { private SensorManager getSensorManager() {
synchronized (mSync) { synchronized (mSync) {
if (mSensorManager == null) { if (mSensorManager == null) {

View File

@@ -20,9 +20,11 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SdkConstant.SdkConstantType;
import android.os.Binder; import android.os.Binder;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.os.ParcelUuid; import android.os.ParcelUuid;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log; import android.util.Log;
import java.io.IOException; import java.io.IOException;
@@ -36,10 +38,8 @@ import java.util.UUID;
/** /**
* Represents the local Bluetooth adapter. * Represents the local Bluetooth adapter.
* *
* <p>Use {@link android.content.Context#getSystemService} with {@link * <p>Use {@link #getDefaultAdapter} to get the default local Bluetooth
* android.content.Context#BLUETOOTH_SERVICE} to get the default local * adapter.
* Bluetooth adapter. On most Android devices there is only one local
* Bluetotoh adapter.
* *
* <p>Use the {@link BluetoothDevice} class for operations on remote Bluetooth * <p>Use the {@link BluetoothDevice} class for operations on remote Bluetooth
* devices. * devices.
@@ -257,12 +257,40 @@ public final class BluetoothAdapter {
*/ */
public static final String EXTRA_LOCAL_NAME = "android.bluetooth.adapter.extra.LOCAL_NAME"; 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; private static final int ADDRESS_LENGTH = 17;
/**
* Lazyily initialized singleton. Guaranteed final after first object
* constructed.
*/
private static BluetoothAdapter sAdapter;
private final IBluetooth mService; 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 * @hide
*/ */
public BluetoothAdapter(IBluetooth service) { public BluetoothAdapter(IBluetooth service) {

View File

@@ -18,7 +18,6 @@ package android.bluetooth;
import android.annotation.SdkConstant; import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.os.IBinder; import android.os.IBinder;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -328,7 +327,7 @@ public final class BluetoothDevice implements Parcelable {
/*package*/ static IBluetooth getService() { /*package*/ static IBluetooth getService() {
synchronized (BluetoothDevice.class) { synchronized (BluetoothDevice.class) {
if (sService == null) { if (sService == null) {
IBinder b = ServiceManager.getService(Context.BLUETOOTH_SERVICE); IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
if (b == null) { if (b == null) {
throw new RuntimeException("Bluetooth service not available"); throw new RuntimeException("Bluetooth service not available");
} }

View File

@@ -1217,14 +1217,6 @@ public abstract class Context {
* @see android.hardware.SensorManager * @see android.hardware.SensorManager
*/ */
public static final String SENSOR_SERVICE = "sensor"; 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 * Use with {@link #getSystemService} to retrieve a
* com.android.server.WallpaperService for accessing wallpapers. * com.android.server.WallpaperService for accessing wallpapers.

View File

@@ -137,7 +137,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
throw new RuntimeException("Could not init BluetoothA2dpService"); 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 = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
mIntentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);

View File

@@ -154,7 +154,7 @@ public class BluetoothService extends IBluetooth.Stub {
} }
public synchronized void initAfterRegistration() { public synchronized void initAfterRegistration() {
mAdapter = (BluetoothAdapter) mContext.getSystemService(Context.BLUETOOTH_SERVICE); mAdapter = BluetoothAdapter.getDefaultAdapter();
mEventLoop = new BluetoothEventLoop(mContext, mAdapter, this); mEventLoop = new BluetoothEventLoop(mContext, mAdapter, this);
} }

View File

@@ -181,7 +181,7 @@ public final class ShutdownThread extends Thread {
ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
final IBluetooth bluetooth = final IBluetooth bluetooth =
IBluetooth.Stub.asInterface(ServiceManager.checkService( IBluetooth.Stub.asInterface(ServiceManager.checkService(
Context.BLUETOOTH_SERVICE)); BluetoothAdapter.BLUETOOTH_SERVICE));
try { try {
bluetoothOff = bluetooth == null || bluetoothOff = bluetooth == null ||

View File

@@ -23,6 +23,7 @@ import com.android.internal.os.SamplingProfilerIntegration;
import dalvik.system.VMRuntime; import dalvik.system.VMRuntime;
import android.app.ActivityManagerNative; import android.app.ActivityManagerNative;
import android.bluetooth.BluetoothAdapter;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.ContentService; import android.content.ContentService;
@@ -172,14 +173,14 @@ class ServerThread extends Thread {
// support Bluetooth - see bug 988521 // support Bluetooth - see bug 988521
if (SystemProperties.get("ro.kernel.qemu").equals("1")) { if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
Log.i(TAG, "Registering null Bluetooth Service (emulator)"); Log.i(TAG, "Registering null Bluetooth Service (emulator)");
ServiceManager.addService(Context.BLUETOOTH_SERVICE, null); ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
} else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) { } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
Log.i(TAG, "Registering null Bluetooth Service (factory test)"); Log.i(TAG, "Registering null Bluetooth Service (factory test)");
ServiceManager.addService(Context.BLUETOOTH_SERVICE, null); ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
} else { } else {
Log.i(TAG, "Bluetooth Service"); Log.i(TAG, "Bluetooth Service");
bluetooth = new BluetoothService(context); bluetooth = new BluetoothService(context);
ServiceManager.addService(Context.BLUETOOTH_SERVICE, bluetooth); ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
bluetooth.initAfterRegistration(); bluetooth.initAfterRegistration();
bluetoothA2dp = new BluetoothA2dpService(context, bluetooth); bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE, ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,

View File

@@ -448,8 +448,7 @@ public class StatusBarPolicy {
mBluetoothData = IconData.makeIcon("bluetooth", mBluetoothData = IconData.makeIcon("bluetooth",
null, com.android.internal.R.drawable.stat_sys_data_bluetooth, 0, 0); null, com.android.internal.R.drawable.stat_sys_data_bluetooth, 0, 0);
mBluetoothIcon = service.addIcon(mBluetoothData, null); mBluetoothIcon = service.addIcon(mBluetoothData, null);
BluetoothAdapter adapter = BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
(BluetoothAdapter) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
if (adapter != null) { if (adapter != null) {
mBluetoothEnabled = adapter.isEnabled(); mBluetoothEnabled = adapter.isEnabled();
} else { } else {