Option to disable resume in Secure DFU (#141)
This commit is contained in:
parent
8e6dd807f2
commit
4840d89533
|
@ -163,6 +163,18 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres
|
|||
* application, which may (and usually does) have more services. In such case set the value of this property to true.
|
||||
*/
|
||||
public static final String EXTRA_FORCE_DFU = "no.nordicsemi.android.dfu.extra.EXTRA_FORCE_DFU";
|
||||
/**
|
||||
* This options allows to disable the resume feature in Secure DFU. When the extra value is set
|
||||
* to true, the DFU will send Init Packet and Data again, despite the firmware might have been
|
||||
* send partially before. By default, without setting this extra, or by setting it to false,
|
||||
* the DFU will resume the previously cancelled upload if CRC values match.
|
||||
* <p>
|
||||
* It is ignored when Legacy DFU is used.
|
||||
* <p>
|
||||
* This feature seems to help in some cases:
|
||||
* <a href="https://github.com/NordicSemiconductor/Android-DFU-Library/issues/71">#71</a>.
|
||||
*/
|
||||
public static final String EXTRA_DISABLE_RESUME = "no.nordicsemi.android.dfu.extra.EXTRA_DISABLE_RESUME";
|
||||
/**
|
||||
* This extra allows you to control the MTU that will be requested (on Lollipop or newer devices).
|
||||
* If the field is null, the service will not request higher MTU and will use MTU = 23
|
||||
|
|
|
@ -75,6 +75,7 @@ public class DfuServiceInitiator {
|
|||
private boolean restoreBond;
|
||||
private boolean forceDfu = false;
|
||||
private boolean enableUnsafeExperimentalButtonlessDfu = false;
|
||||
private boolean disableResume = false;
|
||||
|
||||
private Boolean packetReceiptNotificationsEnabled;
|
||||
private int numberOfPackets = 12;
|
||||
|
@ -243,6 +244,24 @@ public class DfuServiceInitiator {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This options allows to disable the resume feature in Secure DFU. When the extra value is set
|
||||
* to true, the DFU will send Init Packet and Data again, despite the firmware might have been
|
||||
* send partially before. By default, without setting this extra, or by setting it to false,
|
||||
* the DFU will resume the previously cancelled upload if CRC values match.
|
||||
* <p>
|
||||
* It is ignored when Legacy DFU is used.
|
||||
* <p>
|
||||
* This feature seems to help in some cases:
|
||||
* <a href="https://github.com/NordicSemiconductor/Android-DFU-Library/issues/71">#71</a>.
|
||||
*
|
||||
* @return the builder
|
||||
*/
|
||||
public DfuServiceInitiator disableResume() {
|
||||
this.disableResume = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Maximum Transfer Unit (MTU) value that the Secure DFU service will try to request
|
||||
* before performing DFU. By default, value 517 will be used, which is the highest supported
|
||||
|
@ -675,10 +694,12 @@ public class DfuServiceInitiator {
|
|||
intent.putExtra(DfuBaseService.EXTRA_KEEP_BOND, keepBond);
|
||||
intent.putExtra(DfuBaseService.EXTRA_RESTORE_BOND, restoreBond);
|
||||
intent.putExtra(DfuBaseService.EXTRA_FORCE_DFU, forceDfu);
|
||||
intent.putExtra(DfuBaseService.EXTRA_DISABLE_RESUME, disableResume);
|
||||
if (mtu > 0)
|
||||
intent.putExtra(DfuBaseService.EXTRA_MTU, mtu);
|
||||
intent.putExtra(DfuBaseService.EXTRA_CURRENT_MTU, currentMtu);
|
||||
intent.putExtra(DfuBaseService.EXTRA_UNSAFE_EXPERIMENTAL_BUTTONLESS_DFU, enableUnsafeExperimentalButtonlessDfu);
|
||||
//noinspection StatementWithEmptyBody
|
||||
if (packetReceiptNotificationsEnabled != null) {
|
||||
intent.putExtra(DfuBaseService.EXTRA_PACKET_RECEIPT_NOTIFICATIONS_ENABLED, packetReceiptNotificationsEnabled);
|
||||
intent.putExtra(DfuBaseService.EXTRA_PACKET_RECEIPT_NOTIFICATIONS_VALUE, numberOfPackets);
|
||||
|
@ -750,6 +771,8 @@ public class DfuServiceInitiator {
|
|||
|
||||
final NotificationManager notificationManager =
|
||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (notificationManager != null) {
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -223,8 +223,12 @@ class SecureDfuImpl extends BaseCustomDfuImpl {
|
|||
mService.waitFor(1000);
|
||||
// End
|
||||
|
||||
final boolean allowResume = !intent.hasExtra(DfuBaseService.EXTRA_DISABLE_RESUME)
|
||||
|| !intent.getBooleanExtra(DfuBaseService.EXTRA_DISABLE_RESUME, false);
|
||||
if (!allowResume)
|
||||
logi("Resume feature disabled. Performing fresh DFU");
|
||||
try {
|
||||
sendInitPacket(gatt, true);
|
||||
sendInitPacket(gatt, allowResume);
|
||||
} catch (final RemoteDfuException e) {
|
||||
// If the SD+BL upload failed, we may still be able to upload the App.
|
||||
// The SD+BL might have been updated before.
|
||||
|
|
Loading…
Reference in New Issue