Deprecating last settings constant
This commit is contained in:
parent
ebe65dbd64
commit
1a40f78a08
|
@ -93,6 +93,7 @@ import no.nordicsemi.android.error.GattError;
|
||||||
* The service will show its progress on the notification bar and will send local broadcasts to the
|
* The service will show its progress on the notification bar and will send local broadcasts to the
|
||||||
* application.
|
* application.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public abstract class DfuBaseService extends IntentService implements DfuProgressInfo.ProgressListener {
|
public abstract class DfuBaseService extends IntentService implements DfuProgressInfo.ProgressListener {
|
||||||
private static final String TAG = "DfuBaseService";
|
private static final String TAG = "DfuBaseService";
|
||||||
|
|
||||||
|
@ -214,6 +215,12 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres
|
||||||
* <a href="https://github.com/NordicSemiconductor/Android-DFU-Library/issues/71">#71</a>.
|
* <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";
|
public static final String EXTRA_DISABLE_RESUME = "no.nordicsemi.android.dfu.extra.EXTRA_DISABLE_RESUME";
|
||||||
|
/**
|
||||||
|
* The MBR size.
|
||||||
|
*
|
||||||
|
* @see DfuServiceInitiator#setMbrSize(int)
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_MBR_SIZE = "no.nordicsemi.android.dfu.extra.EXTRA_MBR_SIZE";
|
||||||
/**
|
/**
|
||||||
* This extra allows you to control the MTU that will be requested (on Lollipop or newer devices).
|
* 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
|
* If the field is null, the service will not request higher MTU and will use MTU = 23
|
||||||
|
@ -1108,14 +1115,20 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres
|
||||||
// Applications and bootloader starts from bigger address. However, in custom DFU
|
// Applications and bootloader starts from bigger address. However, in custom DFU
|
||||||
// implementations, user may want to transmit the whole whole data, even from address 0x0000.
|
// implementations, user may want to transmit the whole whole data, even from address 0x0000.
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
final String value = preferences.getString(DfuSettingsConstants.SETTINGS_MBR_SIZE, String.valueOf(DfuSettingsConstants.SETTINGS_DEFAULT_MBR_SIZE));
|
int mbrSize = DfuServiceInitiator.DEFAULT_MBR_SIZE;
|
||||||
int mbrSize;
|
if (preferences.contains(DfuSettingsConstants.SETTINGS_MBR_SIZE)) {
|
||||||
try {
|
final String value = preferences.getString(DfuSettingsConstants.SETTINGS_MBR_SIZE, String.valueOf(DfuServiceInitiator.DEFAULT_MBR_SIZE));
|
||||||
mbrSize = Integer.parseInt(value);
|
try {
|
||||||
|
mbrSize = Integer.parseInt(value);
|
||||||
|
if (mbrSize < 0)
|
||||||
|
mbrSize = 0;
|
||||||
|
} catch (final NumberFormatException e) {
|
||||||
|
// ignore, default value will be used
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mbrSize = intent.getIntExtra(EXTRA_MBR_SIZE, DfuServiceInitiator.DEFAULT_MBR_SIZE);
|
||||||
if (mbrSize < 0)
|
if (mbrSize < 0)
|
||||||
mbrSize = 0;
|
mbrSize = 0;
|
||||||
} catch (final NumberFormatException e) {
|
|
||||||
mbrSize = DfuSettingsConstants.SETTINGS_DEFAULT_MBR_SIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foregroundService) {
|
if (foregroundService) {
|
||||||
|
|
|
@ -48,9 +48,10 @@ import java.util.UUID;
|
||||||
* parameters to the service. The DfuServiceInitiator class may be used to make this process easier.
|
* parameters to the service. The DfuServiceInitiator class may be used to make this process easier.
|
||||||
* It provides simple API that covers all low lever operations.
|
* It provides simple API that covers all low lever operations.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
@SuppressWarnings({"WeakerAccess", "unused", "deprecation"})
|
||||||
public class DfuServiceInitiator {
|
public final class DfuServiceInitiator {
|
||||||
public static final int DEFAULT_PRN_VALUE = 12;
|
public static final int DEFAULT_PRN_VALUE = 12;
|
||||||
|
public static final int DEFAULT_MBR_SIZE = 0x1000;
|
||||||
|
|
||||||
/** Constant used to narrow the scope of the update to system components (SD+BL) only. */
|
/** Constant used to narrow the scope of the update to system components (SD+BL) only. */
|
||||||
public static final int SCOPE_SYSTEM_COMPONENTS = 1;
|
public static final int SCOPE_SYSTEM_COMPONENTS = 1;
|
||||||
|
@ -80,6 +81,7 @@ public class DfuServiceInitiator {
|
||||||
private boolean enableUnsafeExperimentalButtonlessDfu = false;
|
private boolean enableUnsafeExperimentalButtonlessDfu = false;
|
||||||
private boolean disableResume = false;
|
private boolean disableResume = false;
|
||||||
private int numberOfRetries = 0; // 0 to be backwards compatible
|
private int numberOfRetries = 0; // 0 to be backwards compatible
|
||||||
|
private int mbrSize = DEFAULT_MBR_SIZE;
|
||||||
|
|
||||||
private Boolean packetReceiptNotificationsEnabled;
|
private Boolean packetReceiptNotificationsEnabled;
|
||||||
private int numberOfPackets = 12;
|
private int numberOfPackets = 12;
|
||||||
|
@ -374,6 +376,32 @@ public class DfuServiceInitiator {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the size of an MBR (Master Boot Record). It should be used only
|
||||||
|
* when updating a file from a HEX file. If you use BIN or ZIP, value set here will
|
||||||
|
* be ignored.
|
||||||
|
* <p>
|
||||||
|
* The MBR size is important for the HEX parser, which has to cut it from the Soft Device's
|
||||||
|
* HEX before sending it to the DFU target. The MBR can't be updated using DFU, and the
|
||||||
|
* bootloader expects only the Soft Device bytes. Usually, the Soft Device HEX provided
|
||||||
|
* by Nordic contains an MBR at addresses 0x0000 to 0x1000.
|
||||||
|
* 0x1000 is the default size of MBR which will be used.
|
||||||
|
* <p>
|
||||||
|
* If you have a HEX file which address start from 0 and want to send the whole BIN content
|
||||||
|
* from it, you have to set the MBR size to 0, otherwise first 4096 bytes will be cut off.
|
||||||
|
* <p>
|
||||||
|
* The value set here will not be used if the {@link DfuSettingsConstants#SETTINGS_MBR_SIZE}
|
||||||
|
* is set in Shared Preferences.
|
||||||
|
*
|
||||||
|
* @param mbrSize the MBR size in bytes. Defaults to 4096 (0x1000) bytes.
|
||||||
|
* @return the builder
|
||||||
|
* @see DfuSettingsConstants#SETTINGS_MBR_SIZE
|
||||||
|
*/
|
||||||
|
public DfuServiceInitiator setMbrSize(@IntRange(from = 0) final int mbrSize) {
|
||||||
|
this.mbrSize = mbrSize;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this flag to true to enable experimental buttonless feature in Secure DFU. When the
|
* Set this flag to true to enable experimental buttonless feature in Secure DFU. When the
|
||||||
* experimental Buttonless DFU Service is found on a device, the service will use it to
|
* experimental Buttonless DFU Service is found on a device, the service will use it to
|
||||||
|
@ -730,6 +758,7 @@ public class DfuServiceInitiator {
|
||||||
intent.putExtra(DfuBaseService.EXTRA_FORCE_DFU, forceDfu);
|
intent.putExtra(DfuBaseService.EXTRA_FORCE_DFU, forceDfu);
|
||||||
intent.putExtra(DfuBaseService.EXTRA_DISABLE_RESUME, disableResume);
|
intent.putExtra(DfuBaseService.EXTRA_DISABLE_RESUME, disableResume);
|
||||||
intent.putExtra(DfuBaseService.EXTRA_MAX_DFU_ATTEMPTS, numberOfRetries);
|
intent.putExtra(DfuBaseService.EXTRA_MAX_DFU_ATTEMPTS, numberOfRetries);
|
||||||
|
intent.putExtra(DfuBaseService.EXTRA_MBR_SIZE, mbrSize);
|
||||||
if (mtu > 0)
|
if (mtu > 0)
|
||||||
intent.putExtra(DfuBaseService.EXTRA_MTU, mtu);
|
intent.putExtra(DfuBaseService.EXTRA_MTU, mtu);
|
||||||
intent.putExtra(DfuBaseService.EXTRA_CURRENT_MTU, currentMtu);
|
intent.putExtra(DfuBaseService.EXTRA_CURRENT_MTU, currentMtu);
|
||||||
|
|
|
@ -24,7 +24,14 @@ package no.nordicsemi.android.dfu;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of constants used for reading DFU constants from
|
||||||
|
* {@link android.preference.PreferenceManager} in previous versions of DFU Library.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link DfuServiceInitiator} methods instead.
|
||||||
|
*/
|
||||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||||
|
@Deprecated
|
||||||
public interface DfuSettingsConstants {
|
public interface DfuSettingsConstants {
|
||||||
/**
|
/**
|
||||||
* This property must contain a boolean value.
|
* This property must contain a boolean value.
|
||||||
|
@ -91,15 +98,12 @@ public interface DfuSettingsConstants {
|
||||||
* If you are using the PC nrf util tool to create a ZIP Distribution Packet with the
|
* If you are using the PC nrf util tool to create a ZIP Distribution Packet with the
|
||||||
* firmware and Init Packet this option does not apply as the nrf tool will convert
|
* firmware and Init Packet this option does not apply as the nrf tool will convert
|
||||||
* HEX to BIN itself.
|
* HEX to BIN itself.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link DfuServiceInitiator#setMbrSize(int)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
String SETTINGS_MBR_SIZE = "settings_mbr_size";
|
String SETTINGS_MBR_SIZE = "settings_mbr_size";
|
||||||
|
|
||||||
/**
|
|
||||||
* The default value of the MBR size.
|
|
||||||
* @see #SETTINGS_DEFAULT_MBR_SIZE
|
|
||||||
*/
|
|
||||||
int SETTINGS_DEFAULT_MBR_SIZE = 0x1000;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This property must contain a boolean value.
|
* This property must contain a boolean value.
|
||||||
* <p>
|
* <p>
|
||||||
|
|
Loading…
Reference in New Issue