public abstract class DfuBaseService
extends android.app.IntentService
To run the service to your application extend it in your project and overwrite the missing method. Remember to add your class to the AndroidManifest.xml file.
The DfuServiceInitiator
object should be used to start the DFU Service.
final DfuServiceInitiator starter = new DfuServiceInitiator(mSelectedDevice.getAddress()) .setDeviceName(mSelectedDevice.getName()) .setKeepBond(keepBond) .setZip(mFileStreamUri, mFilePath) .start(this, DfuService.class);
You may register the progress and log listeners using the DfuServiceListenerHelper
helper class. See DfuProgressListener
and DfuLogListener
for
more information.
The service will show its progress on the notification bar and will send local broadcasts to the application.
Modifier and Type | Field and Description |
---|---|
static int |
ACTION_ABORT
Aborts the upload.
|
static int |
ACTION_PAUSE
Pauses the upload.
|
static int |
ACTION_RESUME
Resumes the upload that has been paused before using
ACTION_PAUSE . |
static java.lang.String |
BROADCAST_ACTION
Activity may broadcast this broadcast in order to pause, resume or abort DFU process.
|
static java.lang.String |
BROADCAST_ERROR
The broadcast error message contains the following extras:
EXTRA_DATA - the error number. |
static java.lang.String |
BROADCAST_LOG
The log events are only broadcast when there is no nRF Logger installed.
|
static java.lang.String |
BROADCAST_PROGRESS
The broadcast message contains the following extras:
EXTRA_DATA - the progress value (percentage 0-100) or:
PROGRESS_CONNECTING
PROGRESS_STARTING
PROGRESS_ENABLING_DFU_MODE
PROGRESS_VALIDATING
PROGRESS_DISCONNECTING
PROGRESS_COMPLETED
PROGRESS_ABORTED
EXTRA_DEVICE_ADDRESS - the target device address
EXTRA_PART_CURRENT - the number of currently transmitted part
EXTRA_PARTS_TOTAL - total number of parts that are being sent, f.e. |
static int |
DFU_STATUS_CRC_ERROR
Deprecated.
|
static int |
DFU_STATUS_DATA_SIZE_EXCEEDS_LIMIT
Deprecated.
|
static int |
DFU_STATUS_INVALID_STATE
Deprecated.
|
static int |
DFU_STATUS_NOT_SUPPORTED
Deprecated.
|
static int |
DFU_STATUS_OPERATION_FAILED
Deprecated.
|
static int |
DFU_STATUS_SUCCESS
Deprecated.
|
static int |
ERROR_BLUETOOTH_DISABLED
Thrown when the the Bluetooth adapter is disabled.
|
static int |
ERROR_CHARACTERISTICS_NOT_FOUND
Deprecated.
This error will no longer be thrown.
ERROR_SERVICE_NOT_FOUND will be thrown instead. |
static int |
ERROR_CONNECTION_MASK
The flag set when one of
BluetoothGattCallback methods was called with status other than BluetoothGatt.GATT_SUCCESS . |
static int |
ERROR_CONNECTION_STATE_MASK
The flag set when the
BluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int) method was called with
status other than BluetoothGatt.GATT_SUCCESS . |
static int |
ERROR_CRC_ERROR
Thrown when the received CRC does not match with the calculated one.
|
static int |
ERROR_DEVICE_DISCONNECTED |
static int |
ERROR_DEVICE_NOT_BONDED
Thrown when device had to be paired before the DFU process was started.
|
static int |
ERROR_FILE_ERROR
Thrown if service was unable to open the file (
IOException has been thrown). |
static int |
ERROR_FILE_INVALID
Thrown when input file is not a valid HEX or ZIP file.
|
static int |
ERROR_FILE_IO_EXCEPTION
Thrown when
IOException occurred when reading from file. |
static int |
ERROR_FILE_NOT_FOUND |
static int |
ERROR_FILE_SIZE_INVALID
Thrown when the firmware file is not word-aligned.
|
static int |
ERROR_FILE_TYPE_UNSUPPORTED
Thrown when the the service does not support given type or mime-type.
|
static int |
ERROR_INIT_PACKET_REQUIRED
DFU Bootloader version 0.6+ requires sending the Init packet.
|
static int |
ERROR_INVALID_RESPONSE
Thrown when unknown response has been obtained from the target.
|
static int |
ERROR_MASK
If this bit is set than the progress value indicates an error.
|
static int |
ERROR_REMOTE_MASK
Flag set when the DFU target returned a DFU error.
|
static int |
ERROR_SERVICE_DISCOVERY_NOT_STARTED
Error thrown when
gatt.discoverServices(); returns false. |
static int |
ERROR_SERVICE_NOT_FOUND
Thrown when the service discovery has finished but the DFU service has not been found.
|
static int |
ERROR_TYPE_COMMUNICATION |
static int |
ERROR_TYPE_COMMUNICATION_STATE |
static int |
ERROR_TYPE_DFU_REMOTE |
static int |
ERROR_TYPE_OTHER |
static java.lang.String |
EXTRA_ACTION
The action extra.
|
static java.lang.String |
EXTRA_AVG_SPEED_B_PER_MS
The average upload speed in bytes/millisecond for the current part.
|
static java.lang.String |
EXTRA_CUSTOM_UUIDS_FOR_BUTTONLESS_DFU_WITH_BOND_SHARING |
static java.lang.String |
EXTRA_CUSTOM_UUIDS_FOR_BUTTONLESS_DFU_WITHOUT_BOND_SHARING |
static java.lang.String |
EXTRA_CUSTOM_UUIDS_FOR_EXPERIMENTAL_BUTTONLESS_DFU |
static java.lang.String |
EXTRA_CUSTOM_UUIDS_FOR_LEGACY_DFU |
static java.lang.String |
EXTRA_CUSTOM_UUIDS_FOR_SECURE_DFU |
static java.lang.String |
EXTRA_DATA
An extra field with progress and error information used in broadcast events.
|
static java.lang.String |
EXTRA_DEVICE_ADDRESS
The address of the device to update.
|
static java.lang.String |
EXTRA_DEVICE_NAME
The optional device name.
|
static java.lang.String |
EXTRA_DISABLE_NOTIFICATION
A boolean indicating whether to disable the progress notification in the status bar.
|
static java.lang.String |
EXTRA_ERROR_TYPE
The type of the error.
|
static java.lang.String |
EXTRA_FILE_MIME_TYPE
The input file mime-type.
|
static java.lang.String |
EXTRA_FILE_PATH
A path to the file with the new firmware.
|
static java.lang.String |
EXTRA_FILE_RES_ID
See
EXTRA_FILE_PATH for details. |
static java.lang.String |
EXTRA_FILE_TYPE
This optional extra parameter may contain a file type.
|
static java.lang.String |
EXTRA_FILE_URI
See
EXTRA_FILE_PATH for details. |
static java.lang.String |
EXTRA_FORCE_DFU
This property must contain a boolean value.
|
static java.lang.String |
EXTRA_INIT_FILE_PATH
The Init packet URI.
|
static java.lang.String |
EXTRA_INIT_FILE_RES_ID
The Init packet URI.
|
static java.lang.String |
EXTRA_INIT_FILE_URI
The Init packet URI.
|
static java.lang.String |
EXTRA_KEEP_BOND
This flag indicated whether the bond information should be kept or removed after an upgrade of the Application.
|
static java.lang.String |
EXTRA_LOG_LEVEL |
static java.lang.String |
EXTRA_LOG_MESSAGE |
static java.lang.String |
EXTRA_PACKET_RECEIPT_NOTIFICATIONS_ENABLED
This property must contain a boolean value.
|
static java.lang.String |
EXTRA_PACKET_RECEIPT_NOTIFICATIONS_VALUE
This property must contain a positive integer value, usually from range 1-200.
|
static java.lang.String |
EXTRA_PART_CURRENT
The number of currently transferred part.
|
static java.lang.String |
EXTRA_PARTS_TOTAL
Number of parts in total.
|
static java.lang.String |
EXTRA_PROGRESS
An extra field to send the progress or error information in the DFU notification.
|
static java.lang.String |
EXTRA_RESTORE_BOND
If the new firmware (application) does not share the bond information with the old one, the bond information is lost.
|
static java.lang.String |
EXTRA_SPEED_B_PER_MS
The current upload speed in bytes/millisecond.
|
static java.lang.String |
EXTRA_UNSAFE_EXPERIMENTAL_BUTTONLESS_DFU
Set this flag to true to enable experimental buttonless feature in Secure DFU.
|
static int |
LOG_LEVEL_APPLICATION
Log entries level for applications
|
static int |
LOG_LEVEL_DEBUG
Level used just for debugging purposes.
|
static int |
LOG_LEVEL_ERROR
Log entries with very high importance, like errors
|
static int |
LOG_LEVEL_INFO
Default logging level for important entries
|
static int |
LOG_LEVEL_VERBOSE
Log entries with minor importance
|
static int |
LOG_LEVEL_WARNING
Log entries with high importance
|
protected int |
mConnectionState
The current connection state.
|
static java.lang.String |
MIME_TYPE_OCTET_STREAM |
static java.lang.String |
MIME_TYPE_ZIP |
static java.lang.String |
NOTIFICATION_CHANNEL_DFU |
static int |
NOTIFICATION_ID |
static int |
PROGRESS_ABORTED
The upload has been aborted.
|
static int |
PROGRESS_COMPLETED
The connection is successful.
|
static int |
PROGRESS_CONNECTING
Service is connecting to the remote DFU target.
|
static int |
PROGRESS_DISCONNECTING
Service is disconnecting from the DFU target.
|
static int |
PROGRESS_ENABLING_DFU_MODE
Service has triggered a switch to bootloader mode.
|
static int |
PROGRESS_STARTING
Service is enabling notifications and starting transmission.
|
static int |
PROGRESS_VALIDATING
Service is sending validation request to the remote DFU target.
|
protected static int |
STATE_CLOSED |
protected static int |
STATE_CONNECTED |
protected static int |
STATE_CONNECTED_AND_READY |
protected static int |
STATE_CONNECTING |
protected static int |
STATE_DISCONNECTED |
protected static int |
STATE_DISCONNECTING |
static int |
TYPE_APPLICATION
The file contains a new version of Application.
|
static int |
TYPE_AUTO
A ZIP file that consists of more than 1 file.
|
static int |
TYPE_BOOTLOADER
The file contains a new version of Bootloader.
|
static int |
TYPE_SOFT_DEVICE
The file contains a new version of Soft Device.
|
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, STOP_FOREGROUND_DETACH, STOP_FOREGROUND_REMOVE
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, COMPANION_DEVICE_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, FINGERPRINT_SERVICE, HARDWARE_PROPERTIES_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_STATS_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, PRINT_SERVICE, RECEIVER_VISIBLE_TO_INSTANT_APPS, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SHORTCUT_SERVICE, STORAGE_SERVICE, STORAGE_STATS_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_CLASSIFICATION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_AWARE_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
Constructor and Description |
---|
DfuBaseService() |
Modifier and Type | Method and Description |
---|---|
protected void |
close(android.bluetooth.BluetoothGatt gatt)
Closes the GATT device and cleans up.
|
protected android.bluetooth.BluetoothGatt |
connect(java.lang.String address)
Connects to the BLE device with given address.
|
protected void |
disconnect(android.bluetooth.BluetoothGatt gatt)
Disconnects from the device.
|
protected abstract java.lang.Class<? extends android.app.Activity> |
getNotificationTarget()
This method must return the activity class that will be used to create the pending intent used as a content intent in the notification showing the upload progress.
|
protected boolean |
isDebug()
Override this method to enable detailed debug LogCat logs with DFU events.
|
void |
onCreate() |
void |
onDestroy() |
protected void |
onHandleIntent(android.content.Intent intent) |
void |
onTaskRemoved(android.content.Intent rootIntent) |
protected void |
refreshDeviceCache(android.bluetooth.BluetoothGatt gatt,
boolean force)
Clears the device cache.
|
protected void |
terminateConnection(android.bluetooth.BluetoothGatt gatt,
int error)
Disconnects from the device and cleans local variables in case of error.
|
void |
updateProgressNotification()
Creates or updates the notification in the Notification Manager.
|
protected void |
waitFor(int millis)
Wait for given number of milliseconds.
|
protected void |
waitUntilDisconnected()
Wait until the connection state will change to
STATE_DISCONNECTED or until an error occurs. |
onBind, onStart, onStartCommand, setIntentRedelivery
dump, getApplication, onConfigurationChanged, onLowMemory, onRebind, onTrimMemory, onUnbind, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getSystemServiceName, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivity, startActivity, startForegroundService, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterReceiver
public static final int NOTIFICATION_ID
public static final java.lang.String NOTIFICATION_CHANNEL_DFU
public static final java.lang.String EXTRA_DEVICE_ADDRESS
public static final java.lang.String EXTRA_DEVICE_NAME
public static final java.lang.String EXTRA_DISABLE_NOTIFICATION
public static final java.lang.String EXTRA_RESTORE_BOND
If the new firmware (application) does not share the bond information with the old one, the bond information is lost. Set this flag to true
to make the service create new bond with the new application when the upload is done (and remove the old one). When set to false
(default),
the DFU service assumes that the LTK is shared between them. Note: currently it is not possible to remove the old bond without creating a new one so if
your old application supported bonding while the new one does not you have to modify the source code yourself.
In case of updating the soft device the application is always removed together with the bond information.
Search for occurrences of EXTRA_RESTORE_BOND in this file to check the implementation and get more details.
public static final java.lang.String EXTRA_KEEP_BOND
This flag indicated whether the bond information should be kept or removed after an upgrade of the Application.
If an application is being updated on a bonded device with the DFU Bootloader that has been configured to preserve the bond information for the new application,
set it to true
.
By default the Legacy DFU Bootloader clears the whole application's memory. It may be however configured in the \Nordic\nrf51\components\libraries\bootloader_dfu\dfu_types.h
file (sdk 11, line 76: #define DFU_APP_DATA_RESERVED 0x0000
) to preserve some pages. The BLE_APP_HRM_DFU sample app stores the LTK and System Attributes in the first
two pages, so in order to preserve the bond information this value should be changed to 0x0800 or more. For Secure DFU this value is by default set to 3 pages.
When those data are preserved, the new Application will notify the app with the Service Changed indication when launched for the first time. Otherwise this
service will remove the bond information from the phone and force to refresh the device cache (see refreshDeviceCache(android.bluetooth.BluetoothGatt, boolean)
).
In contrast to EXTRA_RESTORE_BOND
this flag will not remove the old bonding and recreate a new one, but will keep the bond information untouched.
The default value of this flag is false
public static final java.lang.String EXTRA_FORCE_DFU
The DfuBaseService
, when connected to a DFU target will check whether it is in application or in DFU bootloader mode. For DFU implementations from SDK 7.0 or newer
this is done by reading the value of DFU Version characteristic. If the returned value is equal to 0x0100 (major = 0, minor = 1) it means that we are in the application mode and
jump to the bootloader mode is required.
However, for DFU implementations from older SDKs, where there was no DFU Version characteristic, the service must guess. If this option is set to false (default) it will count number of device's services. If the count is equal to 3 (Generic Access, Generic Attribute, DFU Service) it will assume that it's in DFU mode. If greater than 3 - in app mode. This guessing may not be always correct. One situation may be when the nRF chip is used to flash update on external MCU using DFU. The DFU procedure may be implemented in the application, which may (and usually does) have more services. In such case set the value of this property to true.
public static final java.lang.String EXTRA_UNSAFE_EXPERIMENTAL_BUTTONLESS_DFU
Please, read the information below before setting it to true.
In the SDK 12.x the Buttonless DFU feature for Secure DFU was experimental. It is NOT recommended to use it: it was not properly tested, had implementation bugs (e.g. https://devzone.nordicsemi.com/question/100609/sdk-12-bootloader-erased-after-programming/) and does not required encryption and therefore may lead to DOS attack (anyone can use it to switch the device to bootloader mode). However, as there is no other way to trigger bootloader mode on devices without a button, this DFU Library supports this service, but the feature must be explicitly enabled here. Be aware, that setting this flag to false will no protect your devices from this kind of attacks, as an attacker may use another app for that purpose. To be sure your device is secure remove this experimental service from your device.
Spec:
Buttonless DFU Service UUID: 8E400001-F315-4F60-9FB8-838830DAEA50
Buttonless DFU characteristic UUID: 8E400001-F315-4F60-9FB8-838830DAEA50 (the same)
Enter Bootloader Op Code: 0x01
Correct return value: 0x20-01-01 , where:
0x20 - Response Op Code
0x01 - Request Code
0x01 - Success
The device should disconnect and restart in DFU mode after sending the notification.
In SDK 13 this issue will be fixed by a proper implementation (bonding required, passing bond information to the bootloader, encryption, well tested). It is recommended to use this new service when SDK 13 (or later) is out. TODO: fix the docs when SDK 13 is out.
public static final java.lang.String EXTRA_PACKET_RECEIPT_NOTIFICATIONS_ENABLED
If true the Packet Receipt Notification procedure will be enabled. See DFU documentation on http://infocenter.nordicsemi.com for more details.
The number of packets before receiving a Packet Receipt Notification is set with property EXTRA_PACKET_RECEIPT_NOTIFICATIONS_VALUE
.
The PRNs by default are enabled on devices running Android 4.3, 4.4.x and 5.x and disabled on 6.x and newer.
public static final java.lang.String EXTRA_PACKET_RECEIPT_NOTIFICATIONS_VALUE
The default value is . Setting it to 0 will disable the Packet Receipt Notification procedure. When sending a firmware using the DFU procedure the service will send this number of packets before waiting for a notification. Packet Receipt Notifications are used to synchronize the sender with receiver.
On Android, calling BluetoothGatt.writeCharacteristic(BluetoothGattCharacteristic)
simply adds the packet to outgoing queue before returning the callback. Adding the next packet in the callback is much faster than the real transmission
(also the speed depends on the device chip manufacturer) and the queue may reach its limit. When does, the transmission stops and Android Bluetooth hangs (see Note below).
Using PRN procedure eliminates this problem as the notification is send when all packets were delivered the queue is empty.
Note: this bug has been fixed on Android 6.0 Marshmallow and now no notifications are required. The onCharacteristicWrite callback will be postponed until half of the queue is empty and upload will be resumed automatically. Disabling PRNs speeds up the upload process on those devices.
public static final java.lang.String EXTRA_FILE_PATH
EXTRA_FILE_URI
in the later case.
For files included in /res/raw resource directory please use EXTRA_FILE_RES_ID
instead.public static final java.lang.String EXTRA_FILE_URI
EXTRA_FILE_PATH
for details.public static final java.lang.String EXTRA_FILE_RES_ID
EXTRA_FILE_PATH
for details.public static final java.lang.String EXTRA_INIT_FILE_PATH
public static final java.lang.String EXTRA_INIT_FILE_URI
public static final java.lang.String EXTRA_INIT_FILE_RES_ID
public static final java.lang.String EXTRA_FILE_MIME_TYPE
public static final java.lang.String MIME_TYPE_OCTET_STREAM
public static final java.lang.String MIME_TYPE_ZIP
public static final java.lang.String EXTRA_FILE_TYPE
TYPE_SOFT_DEVICE
- only Soft Device updateTYPE_BOOTLOADER
- only Bootloader updateTYPE_APPLICATION
- only application updateTYPE_AUTO
- the file is a ZIP file that may contain more than one HEX/BIN + DAT files. Since SDK 8.0 the ZIP Distribution packet is a recommended
way of delivering firmware files. Please, see the DFU documentation for more details. A ZIP distribution packet may be created using the 'nrf utility'
command line application, that is a part of Master Control Panel 3.8.0.The ZIP file MAY contain only the following files:
softdevice.hex/bin, bootloader.hex/bin, application.hex/bin to determine the type based on its name. At lease one of them MUST be present.
EXTRA_FILE_MIME_TYPE
field is null
or is equal to "application/octet-stream" - the TYPE_APPLICATION
is assumed.EXTRA_FILE_MIME_TYPE
field is equal to "application/zip" - the TYPE_AUTO
is assumed.public static final int TYPE_SOFT_DEVICE
The file contains a new version of Soft Device.
Since DFU Library 7.0 all firmware may contain an Init packet. The Init packet is required if Extended Init Packet is used by the DFU bootloader (SDK 7.0+).. The Init packet for the bootloader must be placed in the .dat file.
EXTRA_FILE_TYPE
,
Constant Field Valuespublic static final int TYPE_BOOTLOADER
The file contains a new version of Bootloader.
Since DFU Library 7.0 all firmware may contain an Init packet. The Init packet is required if Extended Init Packet is used by the DFU bootloader (SDK 7.0+). The Init packet for the bootloader must be placed in the .dat file.
EXTRA_FILE_TYPE
,
Constant Field Valuespublic static final int TYPE_APPLICATION
The file contains a new version of Application.
Since DFU Library 0.5 all firmware may contain an Init packet. The Init packet is required if Extended Init Packet is used by the DFU bootloader (SDK 7.0+). The Init packet for the application must be placed in the .dat file.
EXTRA_FILE_TYPE
,
Constant Field Valuespublic static final int TYPE_AUTO
A ZIP file that consists of more than 1 file. Since SDK 8.0 the ZIP Distribution packet is a recommended way of delivering firmware files. Please, see the DFU documentation for more details. A ZIP distribution packet may be created using the 'nrf utility' command line application, that is a part of Master Control Panel 3.8.0. For backwards compatibility this library supports also ZIP files without the manifest file. Instead they must follow the fixed naming convention: The names of files in the ZIP must be: softdevice.hex (or .bin), bootloader.hex (or .bin), application.hex (or .bin) in order to be read correctly. Using the Soft Device v7.0.0+ the Soft Device and Bootloader may be updated and sent together. In case of additional application file included, the service will try to send Soft Device, Bootloader and Application together (which is not supported currently) and if it fails, send first SD+BL, reconnect and send the application in the following connection.
Since the DFU Library 0.5 you may specify the Init packet, that will be send prior to the firmware. The init packet contains some verification data, like a device type and revision, application version or a list of supported Soft Devices. The Init packet is required if Extended Init Packet is used by the DFU bootloader (SDK 7.0+). In case of using the compatibility ZIP files the Init packet for the Soft Device and Bootloader must be in the 'system.dat' file while for the application in the 'application.dat' file (included in the ZIP). The CRC in the 'system.dat' must be a CRC of both BIN contents if both a Soft Device and a Bootloader is present.
EXTRA_FILE_TYPE
,
Constant Field Valuespublic static final java.lang.String EXTRA_DATA
public static final java.lang.String EXTRA_PROGRESS
ERROR_MASK
if initialization error occurredERROR_REMOTE_MASK
if remote DFU target returned an errorERROR_CONNECTION_MASK
if connection error occurred (f.e. GATT error (133) or Internal GATT Error (129))boolean error = progressValue >= DfuBaseService.ERROR_MASK;
public static final java.lang.String EXTRA_PART_CURRENT
EXTRA_PARTS_TOTAL
,
Constant Field Valuespublic static final java.lang.String EXTRA_PARTS_TOTAL
EXTRA_PART_CURRENT
,
Constant Field Valuespublic static final java.lang.String EXTRA_SPEED_B_PER_MS
public static final java.lang.String EXTRA_AVG_SPEED_B_PER_MS
public static final java.lang.String BROADCAST_PROGRESS
EXTRA_DATA
- the progress value (percentage 0-100) or:
EXTRA_DEVICE_ADDRESS
- the target device addressEXTRA_PART_CURRENT
- the number of currently transmitted partEXTRA_PARTS_TOTAL
- total number of parts that are being sent, f.e. if a ZIP file contains a Soft Device, a Bootloader and an Application,
the SoftDevice and Bootloader will be send together as one part. Then the service will disconnect and reconnect to the new Bootloader and send the
application as part number two.EXTRA_SPEED_B_PER_MS
- current speed in bytes/millisecond as floatEXTRA_AVG_SPEED_B_PER_MS
- the average transmission speed in bytes/millisecond as floatpublic static final int PROGRESS_CONNECTING
public static final int PROGRESS_STARTING
public static final int PROGRESS_ENABLING_DFU_MODE
public static final int PROGRESS_VALIDATING
public static final int PROGRESS_DISCONNECTING
public static final int PROGRESS_COMPLETED
public static final int PROGRESS_ABORTED
public static final java.lang.String BROADCAST_ERROR
EXTRA_DATA
- the error number. Use GattError.parse(int)
to get String representationEXTRA_DEVICE_ADDRESS
- the target device addresspublic static final java.lang.String EXTRA_ERROR_TYPE
BluetoothGattCallback.onCharacteristicWrite(BluetoothGatt, BluetoothGattCharacteristic, int)
method may return a status code 8 (GATT INSUF AUTHORIZATION),
while the status code 8 returned by BluetoothGattCallback.onConnectionStateChange(BluetoothGatt, int, int)
is a GATT CONN TIMEOUT error.public static final int ERROR_TYPE_OTHER
public static final int ERROR_TYPE_COMMUNICATION_STATE
public static final int ERROR_TYPE_COMMUNICATION
public static final int ERROR_TYPE_DFU_REMOTE
public static final int ERROR_MASK
GattError.parse(int)
to obtain error name.public static final int ERROR_DEVICE_DISCONNECTED
public static final int ERROR_FILE_NOT_FOUND
public static final int ERROR_FILE_ERROR
IOException
has been thrown).public static final int ERROR_FILE_INVALID
public static final int ERROR_FILE_IO_EXCEPTION
IOException
occurred when reading from file.public static final int ERROR_SERVICE_DISCOVERY_NOT_STARTED
gatt.discoverServices();
returns false.public static final int ERROR_SERVICE_NOT_FOUND
@Deprecated public static final int ERROR_CHARACTERISTICS_NOT_FOUND
ERROR_SERVICE_NOT_FOUND
will be thrown instead.public static final int ERROR_INVALID_RESPONSE
public static final int ERROR_FILE_TYPE_UNSUPPORTED
public static final int ERROR_BLUETOOTH_DISABLED
public static final int ERROR_INIT_PACKET_REQUIRED
public static final int ERROR_FILE_SIZE_INVALID
public static final int ERROR_CRC_ERROR
public static final int ERROR_DEVICE_NOT_BONDED
public static final int ERROR_REMOTE_MASK
public static final int ERROR_CONNECTION_MASK
BluetoothGattCallback
methods was called with status other than BluetoothGatt.GATT_SUCCESS
.public static final int ERROR_CONNECTION_STATE_MASK
BluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)
method was called with
status other than BluetoothGatt.GATT_SUCCESS
.public static final java.lang.String BROADCAST_LOG
EXTRA_LOG_LEVEL
- The log level, one of following: LOG_LEVEL_DEBUG
, LOG_LEVEL_VERBOSE
, LOG_LEVEL_INFO
,
LOG_LEVEL_APPLICATION
, LOG_LEVEL_WARNING
, LOG_LEVEL_ERROR
EXTRA_LOG_MESSAGE
- The log messagepublic static final java.lang.String EXTRA_LOG_MESSAGE
public static final java.lang.String EXTRA_LOG_LEVEL
public static final int LOG_LEVEL_DEBUG
public static final int LOG_LEVEL_VERBOSE
public static final int LOG_LEVEL_INFO
public static final int LOG_LEVEL_APPLICATION
public static final int LOG_LEVEL_WARNING
public static final int LOG_LEVEL_ERROR
public static final java.lang.String BROADCAST_ACTION
EXTRA_ACTION
extra to pass the action.public static final java.lang.String EXTRA_ACTION
ACTION_PAUSE
, ACTION_RESUME
, ACTION_ABORT
.public static final int ACTION_PAUSE
ACTION_RESUME
or ACTION_ABORT
.public static final int ACTION_RESUME
ACTION_PAUSE
.public static final int ACTION_ABORT
BROADCAST_ACTION
with extra EXTRA_ACTION
set to this value the DFU bootloader will restore the old application
(if there was already an application). Be aware that uploading the Soft Device will erase the application in order to make space in the memory.
In case there is no application, or the application has been removed, the DFU bootloader will be started and user may try to send the application again.
The bootloader may advertise with the address incremented by 1 to prevent caching services.public static final java.lang.String EXTRA_CUSTOM_UUIDS_FOR_LEGACY_DFU
public static final java.lang.String EXTRA_CUSTOM_UUIDS_FOR_SECURE_DFU
public static final java.lang.String EXTRA_CUSTOM_UUIDS_FOR_EXPERIMENTAL_BUTTONLESS_DFU
public static final java.lang.String EXTRA_CUSTOM_UUIDS_FOR_BUTTONLESS_DFU_WITHOUT_BOND_SHARING
public static final java.lang.String EXTRA_CUSTOM_UUIDS_FOR_BUTTONLESS_DFU_WITH_BOND_SHARING
@Deprecated public static final int DFU_STATUS_SUCCESS
@Deprecated public static final int DFU_STATUS_INVALID_STATE
@Deprecated public static final int DFU_STATUS_NOT_SUPPORTED
@Deprecated public static final int DFU_STATUS_DATA_SIZE_EXCEEDS_LIMIT
@Deprecated public static final int DFU_STATUS_CRC_ERROR
@Deprecated public static final int DFU_STATUS_OPERATION_FAILED
protected int mConnectionState
protected static final int STATE_DISCONNECTED
protected static final int STATE_CONNECTING
protected static final int STATE_CONNECTED
protected static final int STATE_CONNECTED_AND_READY
protected static final int STATE_DISCONNECTING
protected static final int STATE_CLOSED
public void onCreate()
onCreate
in class android.app.IntentService
public void onTaskRemoved(android.content.Intent rootIntent)
onTaskRemoved
in class android.app.Service
public void onDestroy()
onDestroy
in class android.app.IntentService
protected void onHandleIntent(android.content.Intent intent)
onHandleIntent
in class android.app.IntentService
protected android.bluetooth.BluetoothGatt connect(java.lang.String address)
STATE_CONNECTING
to STATE_CONNECTED_AND_READY
or an
error occurs. This method returns null
if Bluetooth adapter is disabled.address
- the device addressnull
if Bluetooth adapter is disabled.protected void terminateConnection(android.bluetooth.BluetoothGatt gatt, int error)
gatt
- the GATT device to be disconnectederror
- error numberprotected void disconnect(android.bluetooth.BluetoothGatt gatt)
terminateConnection(android.bluetooth.BluetoothGatt, int)
instead.gatt
- the GATT device that has to be disconnectedprotected void waitUntilDisconnected()
STATE_DISCONNECTED
or until an error occurs.protected void waitFor(int millis)
millis
- waiting periodprotected void close(android.bluetooth.BluetoothGatt gatt)
gatt
- the GATT device to be closedprotected void refreshDeviceCache(android.bluetooth.BluetoothGatt gatt, boolean force)
gatt
- the GATT device to be refreshedforce
- true
to force the refreshpublic void updateProgressNotification()
protected abstract java.lang.Class<? extends android.app.Activity> getNotificationTarget()
Intent.FLAG_ACTIVITY_NEW_TASK
flag and the following extras:
EXTRA_DEVICE_ADDRESS
- target device addressEXTRA_DEVICE_NAME
- target device nameEXTRA_PROGRESS
- the connection state (values < 0)*, current progress (0-100) or error number if ERROR_MASK
bit set.DfuServiceInitiator.setDisableNotification(boolean)
with parameter true this method will never be called
and may return null.protected boolean isDebug()
Recommended use:
@Override protected boolean isDebug() { return BuildConfig.DEBUG; }