public int getPriority(BluetoothDevice device) {
   enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
   synchronized (BluetoothHeadsetService.this) {
     int priority =
         Settings.Secure.getInt(
             getContentResolver(),
             Settings.Secure.getBluetoothHeadsetPriorityKey(device.getAddress()),
             BluetoothHeadset.PRIORITY_UNDEFINED);
     return priority;
   }
 }
 public boolean setPriority(BluetoothDevice device, int priority) {
   enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
   synchronized (BluetoothHeadsetService.this) {
     if (!BluetoothAdapter.checkBluetoothAddress(device.getAddress())) {
       return false;
     }
     if (priority < BluetoothHeadset.PRIORITY_OFF) {
       return false;
     }
     Settings.Secure.putInt(
         getContentResolver(),
         Settings.Secure.getBluetoothHeadsetPriorityKey(device.getAddress()),
         priority);
     if (DBG) log("Saved priority " + device + " = " + priority);
     return true;
   }
 }