public class DfuServiceInitiator
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PRN_VALUE |
static int |
SCOPE_APPLICATION
Constant used to narrow the scope of the update to application only.
|
static int |
SCOPE_SYSTEM_COMPONENTS
Constant used to narrow the scope of the update to system components (SD+BL) only.
|
Constructor and Description |
---|
DfuServiceInitiator(java.lang.String deviceAddress)
Creates the builder.
|
Modifier and Type | Method and Description |
---|---|
static void |
createDfuNotificationChannel(android.content.Context context) |
DfuServiceInitiator |
setBinOrHex(int fileType,
int rawResId)
Deprecated.
|
DfuServiceInitiator |
setBinOrHex(int fileType,
java.lang.String path)
Deprecated.
|
DfuServiceInitiator |
setBinOrHex(int fileType,
android.net.Uri uri)
Deprecated.
|
DfuServiceInitiator |
setBinOrHex(int fileType,
android.net.Uri uri,
java.lang.String path)
Deprecated.
The Distribution packet (ZIP) should be used for DFU Bootloader version 0.5 or newer
|
DfuServiceInitiator |
setCustomUuidsForButtonlessDfuWithBondSharing(java.util.UUID buttonlessDfuServiceUuid,
java.util.UUID buttonlessDfuControlPointUuid)
Sets custom UUIDs for the Buttonless DFU Service from SDK 14 (or later).
|
DfuServiceInitiator |
setCustomUuidsForButtonlessDfuWithoutBondSharing(java.util.UUID buttonlessDfuServiceUuid,
java.util.UUID buttonlessDfuControlPointUuid)
Sets custom UUIDs for the Buttonless DFU Service from SDK 13.
|
DfuServiceInitiator |
setCustomUuidsForExperimentalButtonlessDfu(java.util.UUID buttonlessDfuServiceUuid,
java.util.UUID buttonlessDfuControlPointUuid)
Sets custom UUIDs for the experimental Buttonless DFU Service from SDK 12.x.
|
DfuServiceInitiator |
setCustomUuidsForLegacyDfu(java.util.UUID dfuServiceUuid,
java.util.UUID dfuControlPointUuid,
java.util.UUID dfuPacketUuid,
java.util.UUID dfuVersionUuid)
Sets custom UUIDs for Legacy DFU and Legacy Buttonless DFU.
|
DfuServiceInitiator |
setCustomUuidsForSecureDfu(java.util.UUID dfuServiceUuid,
java.util.UUID dfuControlPointUuid,
java.util.UUID dfuPacketUuid)
Sets custom UUIDs for Secure DFU.
|
DfuServiceInitiator |
setDeviceName(java.lang.String name)
Sets the device name.
|
DfuServiceInitiator |
setDisableNotification(boolean disableNotification)
Sets whether the progress notification in the status bar should be disabled.
|
DfuServiceInitiator |
setForceDfu(boolean force)
Setting force DFU to true will prevent from jumping to the DFU Bootloader
mode in case there is no DFU Version characteristic (Legacy DFU only!).
|
DfuServiceInitiator |
setInitFile(int initFileResId)
Deprecated.
|
DfuServiceInitiator |
setInitFile(java.lang.String initFilePath)
Deprecated.
|
DfuServiceInitiator |
setInitFile(android.net.Uri initFileUri)
Deprecated.
|
DfuServiceInitiator |
setInitFile(android.net.Uri initFileUri,
java.lang.String initFilePath)
Deprecated.
|
DfuServiceInitiator |
setKeepBond(boolean keepBond)
Sets whether the bond information should be preserver after flashing new application.
|
DfuServiceInitiator |
setPacketsReceiptNotificationsEnabled(boolean enabled)
Enables or disables the Packet Receipt Notification (PRN) procedure.
|
DfuServiceInitiator |
setPacketsReceiptNotificationsValue(int number)
If Packet Receipt Notification procedure is enabled, this method sets number of packets to be sent before
receiving a PRN.
|
DfuServiceInitiator |
setRestoreBond(boolean restoreBond)
Sets whether the bond should be created after the DFU is complete.
|
DfuServiceInitiator |
setScope(int scope)
This method allows to narrow the update to selected parts from the ZIP, for example
to allow only application update from a ZIP file that has SD+BL+App.
|
DfuServiceInitiator |
setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(boolean enable)
Set this flag to true to enable experimental buttonless feature in Secure DFU.
|
DfuServiceInitiator |
setZip(int rawResId)
Sets the resource ID of the Distribution packet (ZIP) or the a ZIP file matching the deprecated naming convention.
|
DfuServiceInitiator |
setZip(java.lang.String path)
Sets the path to the Distribution packet (ZIP) or the a ZIP file matching the deprecated naming convention.
|
DfuServiceInitiator |
setZip(android.net.Uri uri)
Sets the URI to the Distribution packet (ZIP) or to a ZIP file matching the deprecated naming convention.
|
DfuServiceInitiator |
setZip(android.net.Uri uri,
java.lang.String path)
Sets the URI or path of the ZIP file.
|
DfuServiceController |
start(android.content.Context context,
java.lang.Class<? extends DfuBaseService> service)
Starts the DFU service.
|
public static final int DEFAULT_PRN_VALUE
public static final int SCOPE_SYSTEM_COMPONENTS
public static final int SCOPE_APPLICATION
public DfuServiceInitiator(java.lang.String deviceAddress)
deviceAddress
- the target device device addresspublic DfuServiceInitiator setDeviceName(java.lang.String name)
R.string.dfu_unknown_name
value will be used.name
- the device name (optional)public DfuServiceInitiator setDisableNotification(boolean disableNotification)
disableNotification
- whether to disable the notificationpublic DfuServiceInitiator setKeepBond(boolean keepBond)
DfuBaseService.EXTRA_KEEP_BOND
for more information regarding requirements. Remember that currently updating the Soft Device will remove the bond information.keepBond
- whether the bond information should be preserved in the new application.public DfuServiceInitiator setRestoreBond(boolean restoreBond)
DfuBaseService.EXTRA_RESTORE_BOND
for more information regarding requirements.restoreBond
- whether the bond should be created after the DFU is complete.public DfuServiceInitiator setPacketsReceiptNotificationsEnabled(boolean enabled)
By default the PRNs are disabled on devices with Android Marshmallow or newer and enabled on older ones.
enabled
- true to enabled PRNs, false to disableDfuSettingsConstants.SETTINGS_PACKET_RECEIPT_NOTIFICATION_ENABLED
public DfuServiceInitiator setPacketsReceiptNotificationsValue(int number)
number
- number of packets to be sent before receiving a PRN. Defaulted when set to 0.setPacketsReceiptNotificationsEnabled(boolean)
,
DfuSettingsConstants.SETTINGS_NUMBER_OF_PACKETS
public DfuServiceInitiator setForceDfu(boolean force)
If the DFU Version characteristic exists, the information whether to begin DFU operation, or jump to bootloader, is taken from that characteristic's value. The value returned equal to 0x0100 (read as: minor=1, major=0, or version 0.1) means that the device is in the application mode and buttonless jump to DFU Bootloader is supported.
However, if there is no DFU Version characteristic, a device may support only Application update (version from SDK 4.3.0), may support Soft Device, Bootloader and Application update but without buttonless jump to bootloader (SDK 6.0.0) or with buttonless jump (SDK 6.1.0).
In the last case, the DFU Library determines whether the device is in application mode or in DFU Bootloader mode
by counting number of services: if no DFU Service found - device is in app mode and does not support
buttonless jump, if the DFU Service is the only service found (except General Access and General Attribute
services) - it assumes it is in DFU Bootloader mode and may start DFU immediately, if there is
at least one service except DFU Service - the device is in application mode and supports buttonless
jump. In the last case, if you want to perform DFU operation without jumping - call the setForceDfu(boolean)
method with parameter equal to true.
This method is ignored in Secure DFU.
force
- true to ensure the DFU will start if there is no DFU Version characteristic (Legacy DFU only)DfuSettingsConstants.SETTINGS_ASSUME_DFU_NODE
public DfuServiceInitiator setScope(int scope)
scope
- the update scope, one of SCOPE_SYSTEM_COMPONENTS
or SCOPE_APPLICATION
.public DfuServiceInitiator setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(boolean enable)
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. link) 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 DfuServiceInitiator setCustomUuidsForLegacyDfu(java.util.UUID dfuServiceUuid, java.util.UUID dfuControlPointUuid, java.util.UUID dfuPacketUuid, java.util.UUID dfuVersionUuid)
null
will reset the UUID to the default value.dfuServiceUuid
- custom Legacy DFU service UUID or null, if default is to be useddfuControlPointUuid
- custom Legacy DFU Control Point characteristic UUID or null, if default is to be useddfuPacketUuid
- custom Legacy DFU Packet characteristic UUID or null, if default is to be useddfuVersionUuid
- custom Legacy DFU Version characteristic UUID or null, if default is to be used (SDK 7.0 - 11.0 only, set null for earlier SDKs)public DfuServiceInitiator setCustomUuidsForSecureDfu(java.util.UUID dfuServiceUuid, java.util.UUID dfuControlPointUuid, java.util.UUID dfuPacketUuid)
null
will reset the UUID to the default value.dfuServiceUuid
- custom Secure DFU service UUID or null, if default is to be useddfuControlPointUuid
- custom Secure DFU Control Point characteristic UUID or null, if default is to be useddfuPacketUuid
- custom Secure DFU Packet characteristic UUID or null, if default is to be usedpublic DfuServiceInitiator setCustomUuidsForExperimentalButtonlessDfu(java.util.UUID buttonlessDfuServiceUuid, java.util.UUID buttonlessDfuControlPointUuid)
null
will reset the UUID to the default value.
Remember to call setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(boolean)
with parameter true
if you intent to use this service.
buttonlessDfuServiceUuid
- custom Buttonless DFU service UUID or null, if default is to be usedbuttonlessDfuControlPointUuid
- custom Buttonless DFU characteristic UUID or null, if default is to be usedpublic DfuServiceInitiator setCustomUuidsForButtonlessDfuWithBondSharing(java.util.UUID buttonlessDfuServiceUuid, java.util.UUID buttonlessDfuControlPointUuid)
null
will reset the UUID to the default value.buttonlessDfuServiceUuid
- custom Buttonless DFU service UUID or null, if default is to be usedbuttonlessDfuControlPointUuid
- custom Buttonless DFU characteristic UUID or null, if default is to be usedpublic DfuServiceInitiator setCustomUuidsForButtonlessDfuWithoutBondSharing(java.util.UUID buttonlessDfuServiceUuid, java.util.UUID buttonlessDfuControlPointUuid)
null
will reset the UUID to the default value.buttonlessDfuServiceUuid
- custom Buttonless DFU service UUID or null, if default is to be usedbuttonlessDfuControlPointUuid
- custom Buttonless DFU characteristic UUID or null, if default is to be usedpublic DfuServiceInitiator setZip(android.net.Uri uri)
uri
- the URI of the filesetZip(String)
,
setZip(int)
public DfuServiceInitiator setZip(java.lang.String path)
path
- path to the filesetZip(Uri)
,
setZip(int)
public DfuServiceInitiator setZip(int rawResId)
rawResId
- file's resource IDsetZip(Uri)
,
setZip(String)
public DfuServiceInitiator setZip(android.net.Uri uri, java.lang.String path)
uri
- the URI of the filepath
- the path of the file@Deprecated public DfuServiceInitiator setBinOrHex(int fileType, android.net.Uri uri)
setInitFile(Uri)
methods.fileType
- the file type, a bit field created from:
DfuBaseService.TYPE_APPLICATION
- the Application will be sentDfuBaseService.TYPE_SOFT_DEVICE
- he Soft Device will be sentDfuBaseService.TYPE_BOOTLOADER
- the Bootloader will be senturi
- the URI of the file@Deprecated public DfuServiceInitiator setBinOrHex(int fileType, java.lang.String path)
setInitFile(String)
methods.fileType
- see setBinOrHex(int, Uri)
for detailspath
- path to the file@Deprecated public DfuServiceInitiator setBinOrHex(int fileType, android.net.Uri uri, java.lang.String path)
setInitFile(String)
methods.fileType
- see setBinOrHex(int, Uri)
for detailsuri
- the URI of the filepath
- path to the file@Deprecated public DfuServiceInitiator setBinOrHex(int fileType, int rawResId)
setInitFile(int)
methods.fileType
- see setBinOrHex(int, Uri)
for detailsrawResId
- resource ID@Deprecated public DfuServiceInitiator setInitFile(android.net.Uri initFileUri)
initFileUri
- the URI of the init file@Deprecated public DfuServiceInitiator setInitFile(java.lang.String initFilePath)
initFilePath
- the path to the init file@Deprecated public DfuServiceInitiator setInitFile(int initFileResId)
initFileResId
- the resource ID of the init file@Deprecated public DfuServiceInitiator setInitFile(android.net.Uri initFileUri, java.lang.String initFilePath)
initFileUri
- the URI of the init fileinitFilePath
- the path of the init filepublic DfuServiceController start(android.content.Context context, java.lang.Class<? extends DfuBaseService> service)
context
- the application contextservice
- the class derived from the BaseDfuServicepublic static void createDfuNotificationChannel(android.content.Context context)