private void resetAndRestart ( @ NonNull final BluetoothGatt gatt , @ NonNull final Intent intent ) throws DfuException , DeviceDisconnectedException , UploadAbortedException { mService . sendLogBroadcast ( DfuBaseService . LOG_LEVEL_WARNING , "Last upload interrupted. Restarting device..." ) ; // Send 'jump to bootloader command' (Start DFU) mProgressInfo . setProgress ( DfuBaseService . PROGRESS_DISCONNECTING ) ; logi ( "Sending Reset command (Op Code = 6)" ) ; writeOpCode ( mControlPointCharacteristic , OP_CODE_RESET ) ; mService . sendLogBroadcast ( DfuBaseService . LOG_LEVEL_APPLICATION , "Reset request sent" ) ; // The device will reset so we don't have to send Disconnect signal. mService . waitUntilDisconnected ( ) ; mService . sendLogBroadcast ( DfuBaseService . LOG_LEVEL_INFO , "Disconnected by the remote device" ) ; final BluetoothGattService gas = gatt . getService ( GENERIC_ATTRIBUTE_SERVICE_UUID ) ; final boolean hasServiceChanged = gas != null && gas . getCharacteristic ( SERVICE_CHANGED_UUID ) != null ; mService . refreshDeviceCache ( gatt , ! hasServiceChanged ) ; // Close the device mService . close ( gatt ) ; logi ( "Restarting the service" ) ; final Intent newIntent = new Intent ( ) ; newIntent . fillIn ( intent , Intent . FILL_IN_COMPONENT | Intent . FILL_IN_PACKAGE ) ; restartService ( newIntent , false ) ; }
Sends Reset command to the target device to reset its state and restarts the DFU Service that will start again .