summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothSap.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-08-24 21:25:49 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-08-24 21:25:49 +0000
commit94bbd4256d7261aa1d8ddf660e7856cde5afa49f (patch)
tree8299c300f3b4dbc2a5360c3319ac41bf1b389e55 /framework/java/android/bluetooth/BluetoothSap.java
parent931010f176faa894f06051c57290f7723dfbcd49 (diff)
parent9e045d26d0128826b40520f523307d8d16473779 (diff)
Merge changes from topic "bt-fix-checkstyle-errors"
* changes: Fix checkstyle errors (2/2) Fix checkstyle errors (1/2)
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothSap.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothSap.java107
1 files changed, 60 insertions, 47 deletions
diff --git a/framework/java/android/bluetooth/BluetoothSap.java b/framework/java/android/bluetooth/BluetoothSap.java
index 89c1bf8f9a..bcdf4938fe 100644
--- a/framework/java/android/bluetooth/BluetoothSap.java
+++ b/framework/java/android/bluetooth/BluetoothSap.java
@@ -16,19 +16,18 @@
package android.bluetooth;
-import java.util.ArrayList;
-import java.util.List;
-
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
-import android.os.RemoteException;
import android.os.Binder;
import android.os.IBinder;
-import android.os.ServiceManager;
+import android.os.RemoteException;
import android.util.Log;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* This class provides the APIs to control the Bluetooth SIM
* Access Profile (SAP).
@@ -38,6 +37,7 @@ import android.util.Log;
* the BluetoothSap proxy object.
*
* <p>Each method is protected with its appropriate permission.
+ *
* @hide
*/
public final class BluetoothSap implements BluetoothProfile {
@@ -51,9 +51,9 @@ public final class BluetoothSap implements BluetoothProfile {
*
* <p>This intent will have 4 extras:
* <ul>
- * <li> {@link #EXTRA_STATE} - The current state of the profile. </li>
- * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile.</li>
- * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li>
+ * <li> {@link #EXTRA_STATE} - The current state of the profile. </li>
+ * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile.</li>
+ * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li>
* </ul>
*
* <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
@@ -62,10 +62,11 @@ public final class BluetoothSap implements BluetoothProfile {
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to
* receive.
+ *
* @hide
*/
public static final String ACTION_CONNECTION_STATE_CHANGED =
- "android.bluetooth.sap.profile.action.CONNECTION_STATE_CHANGED";
+ "android.bluetooth.sap.profile.action.CONNECTION_STATE_CHANGED";
private IBluetoothSap mService;
private final Context mContext;
@@ -74,50 +75,53 @@ public final class BluetoothSap implements BluetoothProfile {
/**
* There was an error trying to obtain the state.
+ *
* @hide
*/
public static final int STATE_ERROR = -1;
/**
* Connection state change succceeded.
+ *
* @hide
*/
public static final int RESULT_SUCCESS = 1;
/**
* Connection canceled before completion.
+ *
* @hide
*/
public static final int RESULT_CANCELED = 2;
- final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
new IBluetoothStateChangeCallback.Stub() {
public void onBluetoothStateChange(boolean up) {
if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
if (!up) {
- if (VDBG) Log.d(TAG,"Unbinding service...");
+ if (VDBG) Log.d(TAG, "Unbinding service...");
synchronized (mConnection) {
try {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
} else {
synchronized (mConnection) {
try {
if (mService == null) {
- if (VDBG) Log.d(TAG,"Binding service...");
+ if (VDBG) Log.d(TAG, "Binding service...");
doBind();
}
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
}
- };
+ };
/**
* Create a BluetoothSap proxy object.
@@ -132,7 +136,7 @@ public final class BluetoothSap implements BluetoothProfile {
try {
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
doBind();
@@ -163,6 +167,7 @@ public final class BluetoothSap implements BluetoothProfile {
* Other public functions of BluetoothSap will return default error
* results once close() has been called. Multiple invocations of close()
* are ok.
+ *
* @hide
*/
public synchronized void close() {
@@ -171,7 +176,7 @@ public final class BluetoothSap implements BluetoothProfile {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -181,7 +186,7 @@ public final class BluetoothSap implements BluetoothProfile {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
@@ -190,8 +195,9 @@ public final class BluetoothSap implements BluetoothProfile {
/**
* Get the current state of the BluetoothSap service.
- * @return One of the STATE_ return codes, or STATE_ERROR if this proxy
- * object is currently not connected to the Sap service.
+ *
+ * @return One of the STATE_ return codes, or STATE_ERROR if this proxy object is currently not
+ * connected to the Sap service.
* @hide
*/
public int getState() {
@@ -199,7 +205,9 @@ public final class BluetoothSap implements BluetoothProfile {
if (mService != null) {
try {
return mService.getState();
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) log(Log.getStackTraceString(new Throwable()));
@@ -209,9 +217,9 @@ public final class BluetoothSap implements BluetoothProfile {
/**
* Get the currently connected remote Bluetooth device (PCE).
- * @return The remote Bluetooth device, or null if not in connected or
- * connecting state, or if this proxy object is not connected to
- * the Sap service.
+ *
+ * @return The remote Bluetooth device, or null if not in connected or connecting state, or if
+ * this proxy object is not connected to the Sap service.
* @hide
*/
public BluetoothDevice getClient() {
@@ -219,7 +227,9 @@ public final class BluetoothSap implements BluetoothProfile {
if (mService != null) {
try {
return mService.getClient();
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) log(Log.getStackTraceString(new Throwable()));
@@ -231,6 +241,7 @@ public final class BluetoothSap implements BluetoothProfile {
* Returns true if the specified Bluetooth device is connected.
* Returns false if not connected, or if this proxy object is not
* currently connected to the Sap service.
+ *
* @hide
*/
public boolean isConnected(BluetoothDevice device) {
@@ -238,7 +249,9 @@ public final class BluetoothSap implements BluetoothProfile {
if (mService != null) {
try {
return mService.isConnected(device);
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) log(Log.getStackTraceString(new Throwable()));
@@ -249,6 +262,7 @@ public final class BluetoothSap implements BluetoothProfile {
/**
* Initiate connection. Initiation of outgoing connections is not
* supported for SAP server.
+ *
* @hide
*/
public boolean connect(BluetoothDevice device) {
@@ -260,19 +274,17 @@ public final class BluetoothSap implements BluetoothProfile {
* Initiate disconnect.
*
* @param device Remote Bluetooth Device
- * @return false on error,
- * true otherwise
+ * @return false on error, true otherwise
* @hide
*/
public boolean disconnect(BluetoothDevice device) {
if (DBG) log("disconnect(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.disconnect(device);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
- return false;
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ return false;
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -327,8 +339,7 @@ public final class BluetoothSap implements BluetoothProfile {
*/
public int getConnectionState(BluetoothDevice device) {
if (DBG) log("getConnectionState(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getConnectionState(device);
} catch (RemoteException e) {
@@ -352,11 +363,10 @@ public final class BluetoothSap implements BluetoothProfile {
*/
public boolean setPriority(BluetoothDevice device, int priority) {
if (DBG) log("setPriority(" + device + ", " + priority + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON) {
- return false;
+ if (mService != null && isEnabled() && isValidDevice(device)) {
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
+ return false;
}
try {
return mService.setPriority(device, priority);
@@ -378,8 +388,7 @@ public final class BluetoothSap implements BluetoothProfile {
*/
public int getPriority(BluetoothDevice device) {
if (VDBG) log("getPriority(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getPriority(device);
} catch (RemoteException e) {
@@ -399,6 +408,7 @@ public final class BluetoothSap implements BluetoothProfile {
mServiceListener.onServiceConnected(BluetoothProfile.SAP, BluetoothSap.this);
}
}
+
public void onServiceDisconnected(ComponentName className) {
if (DBG) log("Proxy object disconnected");
mService = null;
@@ -415,19 +425,22 @@ public final class BluetoothSap implements BluetoothProfile {
private boolean isEnabled() {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
- if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON)
+ if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON) {
return true;
+ }
log("Bluetooth is Not enabled");
return false;
}
private boolean isValidDevice(BluetoothDevice device) {
- if (device == null)
- return false;
+ if (device == null) {
+ return false;
+ }
- if (BluetoothAdapter.checkBluetoothAddress(device.getAddress()))
- return true;
- return false;
+ if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) {
+ return true;
+ }
+ return false;
}
}