@ SuppressWarnings ( "UnusedReturnValue" ) boolean removeBond ( ) { final BluetoothDevice device = mGatt . getDevice ( ) ; if ( device . getBondState ( ) == BluetoothDevice . BOND_NONE ) return true ; mService . sendLogBroadcast ( DfuBaseService . LOG_LEVEL_VERBOSE , "Removing bond information..." ) ; boolean result = false ; /* * There is a removeBond() method in BluetoothDevice class but for now it's hidden. We will call it using reflections. */ try { //noinspection JavaReflectionMemberAccess final Method removeBond = device . getClass ( ) . getMethod ( "removeBond" ) ; mRequestCompleted = false ; mService . sendLogBroadcast ( DfuBaseService . LOG_LEVEL_DEBUG , "gatt.getDevice().removeBond() (hidden)" ) ; result = ( Boolean ) removeBond . invoke ( device ) ; // We have to wait until device is unbounded try { synchronized ( mLock ) { while ( ! mRequestCompleted && ! mAborted ) mLock . wait ( ) ; } } catch ( final InterruptedException e ) { loge ( "Sleeping interrupted" , e ) ; } } catch ( final Exception e ) { Log . w ( TAG , "An exception occurred while removing bond information" , e ) ; } return result ; }
Removes the bond information for the given device .