aboutsummaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothDevice.java
diff options
context:
space:
mode:
authorfredc <fredc@broadcom.com>2012-04-12 00:02:00 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-07-16 21:20:54 -0700
commit3c7196448a62414bf1bfcc94947bfcfa2d60278a (patch)
tree8c6be2ed45eeadc53202eb7956519f9b96808b6b /framework/java/android/bluetooth/BluetoothDevice.java
parenta5d5a9c3c2dd28a5bd5a719af0a52f5e5a03f6e1 (diff)
Non persistent adapter service
Change-Id: Ib13d5c77416e58161df0e04d7a15ec0dddbde8b5 Conflicts: core/java/android/bluetooth/BluetoothInputDevice.java Conflicts: core/java/com/android/internal/app/ShutdownThread.java services/java/com/android/server/SystemServer.java Conflicts: services/java/com/android/server/SystemServer.java services/java/com/android/server/pm/ShutdownThread.java
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothDevice.java')
-rwxr-xr-xframework/java/android/bluetooth/BluetoothDevice.java57
1 files changed, 52 insertions, 5 deletions
diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java
index 4d9dd82ee2..82bd702bac 100755
--- a/framework/java/android/bluetooth/BluetoothDevice.java
+++ b/framework/java/android/bluetooth/BluetoothDevice.java
@@ -65,6 +65,7 @@ import java.util.UUID;
*/
public final class BluetoothDevice implements Parcelable {
private static final String TAG = "BluetoothDevice";
+ private static final boolean DBG = true;
/**
* Sentinel error value for this class. Guaranteed to not equal any other
@@ -483,11 +484,8 @@ public final class BluetoothDevice implements Parcelable {
/*package*/ static IBluetooth getService() {
synchronized (BluetoothDevice.class) {
if (sService == null) {
- IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
- if (b == null) {
- throw new RuntimeException("Bluetooth service not available");
- }
- sService = IBluetooth.Stub.asInterface(b);
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ sService = adapter.getBluetoothService();
}
}
return sService;
@@ -561,6 +559,7 @@ public final class BluetoothDevice implements Parcelable {
* @return Bluetooth hardware address as string
*/
public String getAddress() {
+ if (DBG) Log.d(TAG, "mAddress: " + mAddress);
return mAddress;
}
@@ -575,6 +574,10 @@ public final class BluetoothDevice implements Parcelable {
* @return the Bluetooth name, or null if there was a problem.
*/
public String getName() {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot get Remote Device name");
+ return null;
+ }
try {
return sService.getRemoteName(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -589,6 +592,10 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
public String getAlias() {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias");
+ return null;
+ }
try {
return sService.getRemoteAlias(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -606,6 +613,10 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
public boolean setAlias(String alias) {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot set Remote Device name");
+ return false;
+ }
try {
return sService.setRemoteAlias(this, alias);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -642,6 +653,10 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
public boolean createBond() {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
+ return false;
+ }
try {
return sService.createBond(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -706,6 +721,10 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
public boolean cancelBondProcess() {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond");
+ return false;
+ }
try {
return sService.cancelBondProcess(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -723,6 +742,10 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
public boolean removeBond() {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond");
+ return false;
+ }
try {
return sService.removeBond(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -740,6 +763,10 @@ public final class BluetoothDevice implements Parcelable {
* @return the bond state
*/
public int getBondState() {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot get bond state");
+ return BOND_NONE;
+ }
try {
return sService.getBondState(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -753,6 +780,10 @@ public final class BluetoothDevice implements Parcelable {
* @return Bluetooth class object, or null on error
*/
public BluetoothClass getBluetoothClass() {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class");
+ return null;
+ }
try {
int classInt = sService.getRemoteClass(this);
if (classInt == BluetoothClass.ERROR) return null;
@@ -807,6 +838,10 @@ public final class BluetoothDevice implements Parcelable {
* or null on error
*/
public ParcelUuid[] getUuids() {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot get remote device Uuids");
+ return null;
+ }
try {
return sService.getRemoteUuids(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -847,6 +882,10 @@ public final class BluetoothDevice implements Parcelable {
/** @hide */
public boolean setPin(byte[] pin) {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot set Remote Device pin");
+ return false;
+ }
try {
return sService.setPin(this, true, pin.length, pin);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -865,6 +904,10 @@ public final class BluetoothDevice implements Parcelable {
/** @hide */
public boolean setPairingConfirmation(boolean confirm) {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot set pairing confirmation");
+ return false;
+ }
try {
return sService.setPairingConfirmation(this, confirm);
} catch (RemoteException e) {Log.e(TAG, "", e);}
@@ -883,6 +926,10 @@ public final class BluetoothDevice implements Parcelable {
/** @hide */
public boolean cancelPairingUserInput() {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot create pairing user input");
+ return false;
+ }
try {
return sService.cancelBondProcess(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}