/**
  * Get battery usage hint for Bluetooth Headset service. This is a monotonically increasing
  * integer. Wraps to 0 at Integer.MAX_INT, and at boot. Current implementation returns the number
  * of AT commands handled since boot. This is a good indicator for spammy headset/handsfree units
  * that can keep the device awake by polling for cellular status updates. As a rule of thumb, each
  * AT command prevents the CPU from sleeping for 500 ms
  *
  * @param device the bluetooth headset.
  * @return monotonically increasing battery usage hint, or a negative error code on error
  * @hide
  */
 public int getBatteryUsageHint(BluetoothDevice device) {
   if (DBG) log("getBatteryUsageHint()");
   if (mService != null && isEnabled() && isValidDevice(device)) {
     try {
       return mService.getBatteryUsageHint(device);
     } catch (RemoteException e) {
       Log.e(TAG, Log.getStackTraceString(new Throwable()));
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return -1;
 }
 /**
  * Check if Bluetooth SCO audio is connected.
  *
  * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
  *
  * @param device Bluetooth headset
  * @return true if SCO is connected, false otherwise or on error
  */
 public boolean isAudioConnected(BluetoothDevice device) {
   if (DBG) log("isAudioConnected()");
   if (mService != null && isEnabled() && isValidDevice(device)) {
     try {
       return mService.isAudioConnected(device);
     } catch (RemoteException e) {
       Log.e(TAG, Log.getStackTraceString(new Throwable()));
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return false;
 }
 /**
  * Get the priority of the profile.
  *
  * <p>The priority can be any of: {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF}, {@link
  * #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
  *
  * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
  *
  * @param device Bluetooth device
  * @return priority of the device
  * @hide
  */
 public int getPriority(BluetoothDevice device) {
   if (DBG) log("getPriority(" + device + ")");
   if (mService != null && isEnabled() && isValidDevice(device)) {
     try {
       return mService.getPriority(device);
     } catch (RemoteException e) {
       Log.e(TAG, Log.getStackTraceString(new Throwable()));
       return PRIORITY_OFF;
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return PRIORITY_OFF;
 }
 /** {@inheritDoc} */
 public int getConnectionState(BluetoothDevice device) {
   if (DBG) log("getConnectionState(" + device + ")");
   if (mService != null && isEnabled() && isValidDevice(device)) {
     try {
       return mService.getConnectionState(device);
     } catch (RemoteException e) {
       Log.e(TAG, Log.getStackTraceString(new Throwable()));
       return BluetoothProfile.STATE_DISCONNECTED;
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return BluetoothProfile.STATE_DISCONNECTED;
 }
 /** {@inheritDoc} */
 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
   if (DBG) log("getDevicesMatchingStates()");
   if (mService != null && isEnabled()) {
     try {
       return mService.getDevicesMatchingConnectionStates(states);
     } catch (RemoteException e) {
       Log.e(TAG, Log.getStackTraceString(new Throwable()));
       return new ArrayList<BluetoothDevice>();
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return new ArrayList<BluetoothDevice>();
 }
 /**
  * Terminates an ongoing SCO connection and the associated virtual call.
  *
  * @param device Remote Bluetooth Device
  * @return true if successful, false if there was some error.
  * @hide
  */
 public boolean stopScoUsingVirtualVoiceCall(BluetoothDevice device) {
   if (DBG) log("stopScoUsingVirtualVoiceCall()");
   if (mService != null && isEnabled() && isValidDevice(device)) {
     try {
       return mService.stopScoUsingVirtualVoiceCall(device);
     } catch (RemoteException e) {
       Log.e(TAG, e.toString());
     }
   } else {
     Log.w(TAG, "Proxy not attached to service");
     if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
   }
   return false;
 }
 /**
  * Get the current audio state of the Headset. Note: This is an internal function and shouldn't be
  * exposed
  *
  * @hide
  */
 public int getAudioState(BluetoothDevice device) {
   if (DBG) log("getAudioState");
   if (mService != null && !isDisabled()) {
     try {
       return mService.getAudioState(device);
     } catch (RemoteException e) {
       Log.e(TAG, e.toString());
     }
   } else {
     Log.w(TAG, "Proxy not attached to service");
     if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
   }
   return BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
 }
 /**
  * Set the audio state of the Headset. Note: This is an internal function and shouldn't be exposed
  *
  * @hide
  */
 public boolean setAudioState(BluetoothDevice device, int state) {
   if (DBG) log("setAudioState");
   if (mService != null && !isDisabled()) {
     try {
       return mService.setAudioState(device, state);
     } catch (RemoteException e) {
       Log.e(TAG, e.toString());
     }
   } else {
     Log.w(TAG, "Proxy not attached to service");
     if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
   }
   return false;
 }
 /**
  * Disconnect a Bluetooth Headset. Note: This is an internal function and shouldn't be exposed
  *
  * @hide
  */
 public boolean disconnectHeadsetInternal(BluetoothDevice device) {
   if (DBG) log("disconnectHeadsetInternal");
   if (mService != null && !isDisabled()) {
     try {
       return mService.disconnectHeadsetInternal(device);
     } catch (RemoteException e) {
       Log.e(TAG, e.toString());
     }
   } else {
     Log.w(TAG, "Proxy not attached to service");
     if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
   }
   return false;
 }
 /**
  * Reject the incoming connection.
  *
  * @hide
  */
 public boolean rejectIncomingConnect(BluetoothDevice device) {
   if (DBG) log("rejectIncomingConnect");
   if (mService != null) {
     try {
       return mService.rejectIncomingConnect(device);
     } catch (RemoteException e) {
       Log.e(TAG, e.toString());
     }
   } else {
     Log.w(TAG, "Proxy not attached to service");
     if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
   }
   return false;
 }
 /**
  * Cancel the outgoing connection. Note: This is an internal function and shouldn't be exposed
  *
  * @hide
  */
 public boolean cancelConnectThread() {
   if (DBG) log("cancelConnectThread");
   if (mService != null && isEnabled()) {
     try {
       return mService.cancelConnectThread();
     } catch (RemoteException e) {
       Log.e(TAG, e.toString());
     }
   } else {
     Log.w(TAG, "Proxy not attached to service");
     if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
   }
   return false;
 }
 /**
  * Set priority of the profile
  *
  * <p>The device should already be paired. Priority can be one of {@link #PRIORITY_ON} or {@link
  * #PRIORITY_OFF},
  *
  * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
  *
  * @param device Paired bluetooth device
  * @param priority
  * @return true if priority is set, false on error
  * @hide
  */
 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;
     }
     try {
       return mService.setPriority(device, priority);
     } catch (RemoteException e) {
       Log.e(TAG, Log.getStackTraceString(new Throwable()));
       return false;
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return false;
 }