Locales in String.format(...)
This commit is contained in:
parent
7c68625ebf
commit
0094b4b040
|
@ -4,6 +4,8 @@ import android.bluetooth.BluetoothGatt;
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import no.nordicsemi.android.dfu.internal.exception.DeviceDisconnectedException;
|
import no.nordicsemi.android.dfu.internal.exception.DeviceDisconnectedException;
|
||||||
import no.nordicsemi.android.dfu.internal.exception.DfuException;
|
import no.nordicsemi.android.dfu.internal.exception.DfuException;
|
||||||
import no.nordicsemi.android.dfu.internal.exception.RemoteDfuException;
|
import no.nordicsemi.android.dfu.internal.exception.RemoteDfuException;
|
||||||
|
@ -128,7 +130,7 @@ import no.nordicsemi.android.error.SecureDfuError;
|
||||||
} catch (final RemoteDfuException e) {
|
} catch (final RemoteDfuException e) {
|
||||||
final int error = DfuBaseService.ERROR_REMOTE_TYPE_SECURE_BUTTONLESS | e.getErrorNumber();
|
final int error = DfuBaseService.ERROR_REMOTE_TYPE_SECURE_BUTTONLESS | e.getErrorNumber();
|
||||||
loge(e.getMessage());
|
loge(e.getMessage());
|
||||||
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_ERROR, String.format("Remote DFU error: %s", SecureDfuError.parseButtonlessError(error)));
|
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_ERROR, String.format(Locale.US, "Remote DFU error: %s", SecureDfuError.parseButtonlessError(error)));
|
||||||
mService.terminateConnection(gatt, error | DfuBaseService.ERROR_REMOTE_MASK);
|
mService.terminateConnection(gatt, error | DfuBaseService.ERROR_REMOTE_MASK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1112,11 +1112,11 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres
|
||||||
if ((mError & ERROR_CONNECTION_STATE_MASK) > 0) {
|
if ((mError & ERROR_CONNECTION_STATE_MASK) > 0) {
|
||||||
final int error = mError & ~ERROR_CONNECTION_STATE_MASK;
|
final int error = mError & ~ERROR_CONNECTION_STATE_MASK;
|
||||||
loge("An error occurred while connecting to the device:" + error);
|
loge("An error occurred while connecting to the device:" + error);
|
||||||
sendLogBroadcast(LOG_LEVEL_ERROR, String.format("Connection failed (0x%02X): %s", error, GattError.parseConnectionError(error)));
|
sendLogBroadcast(LOG_LEVEL_ERROR, String.format(Locale.US, "Connection failed (0x%02X): %s", error, GattError.parseConnectionError(error)));
|
||||||
} else {
|
} else {
|
||||||
final int error = mError & ~ERROR_CONNECTION_MASK;
|
final int error = mError & ~ERROR_CONNECTION_MASK;
|
||||||
loge("An error occurred during discovering services:" + error);
|
loge("An error occurred during discovering services:" + error);
|
||||||
sendLogBroadcast(LOG_LEVEL_ERROR, String.format("Connection failed (0x%02X): %s", error, GattError.parse(error)));
|
sendLogBroadcast(LOG_LEVEL_ERROR, String.format(Locale.US, "Connection failed (0x%02X): %s", error, GattError.parse(error)));
|
||||||
}
|
}
|
||||||
// Connection usually fails due to a 133 error (device unreachable, or.. something else went wrong).
|
// Connection usually fails due to a 133 error (device unreachable, or.. something else went wrong).
|
||||||
// Usually trying the same for the second time works.
|
// Usually trying the same for the second time works.
|
||||||
|
@ -1188,10 +1188,10 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres
|
||||||
// Connection state errors and other Bluetooth GATT callbacks share the same error numbers. Therefore we are using bit masks to identify the type.
|
// Connection state errors and other Bluetooth GATT callbacks share the same error numbers. Therefore we are using bit masks to identify the type.
|
||||||
if ((error & ERROR_CONNECTION_STATE_MASK) > 0) {
|
if ((error & ERROR_CONNECTION_STATE_MASK) > 0) {
|
||||||
error &= ~ERROR_CONNECTION_STATE_MASK;
|
error &= ~ERROR_CONNECTION_STATE_MASK;
|
||||||
sendLogBroadcast(LOG_LEVEL_ERROR, String.format("Error (0x%02X): %s", error, GattError.parseConnectionError(error)));
|
sendLogBroadcast(LOG_LEVEL_ERROR, String.format(Locale.US, "Error (0x%02X): %s", error, GattError.parseConnectionError(error)));
|
||||||
} else {
|
} else {
|
||||||
error &= ~ERROR_CONNECTION_MASK;
|
error &= ~ERROR_CONNECTION_MASK;
|
||||||
sendLogBroadcast(LOG_LEVEL_ERROR, String.format("Error (0x%02X): %s", error, GattError.parse(error)));
|
sendLogBroadcast(LOG_LEVEL_ERROR, String.format(Locale.US, "Error (0x%02X): %s", error, GattError.parse(error)));
|
||||||
}
|
}
|
||||||
loge(e.getMessage());
|
loge(e.getMessage());
|
||||||
terminateConnection(gatt, e.getErrorNumber() /* we return the whole error number, including the error type mask */);
|
terminateConnection(gatt, e.getErrorNumber() /* we return the whole error number, including the error type mask */);
|
||||||
|
|
|
@ -29,6 +29,7 @@ import android.content.IntentFilter;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import no.nordicsemi.android.dfu.internal.scanner.BootloaderScanner;
|
import no.nordicsemi.android.dfu.internal.scanner.BootloaderScanner;
|
||||||
|
@ -368,7 +369,7 @@ public class DfuServiceListenerHelper {
|
||||||
private static String getIncrementedAddress(final String deviceAddress) {
|
private static String getIncrementedAddress(final String deviceAddress) {
|
||||||
final String firstBytes = deviceAddress.substring(0, 15);
|
final String firstBytes = deviceAddress.substring(0, 15);
|
||||||
final String lastByte = deviceAddress.substring(15); // assuming that the device address is correct
|
final String lastByte = deviceAddress.substring(15); // assuming that the device address is correct
|
||||||
final String lastByteIncremented = String.format("%02X", (Integer.valueOf(lastByte, 16) + BootloaderScanner.ADDRESS_DIFF) & 0xFF);
|
final String lastByteIncremented = String.format(Locale.US, "%02X", (Integer.valueOf(lastByte, 16) + BootloaderScanner.ADDRESS_DIFF) & 0xFF);
|
||||||
return firstBytes + lastByteIncremented;
|
return firstBytes + lastByteIncremented;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import android.bluetooth.BluetoothGattService;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import no.nordicsemi.android.dfu.internal.ArchiveInputStream;
|
import no.nordicsemi.android.dfu.internal.ArchiveInputStream;
|
||||||
|
@ -532,7 +533,7 @@ import no.nordicsemi.android.error.LegacyDfuError;
|
||||||
} catch (final RemoteDfuException e) {
|
} catch (final RemoteDfuException e) {
|
||||||
final int error = DfuBaseService.ERROR_REMOTE_TYPE_LEGACY | e.getErrorNumber();
|
final int error = DfuBaseService.ERROR_REMOTE_TYPE_LEGACY | e.getErrorNumber();
|
||||||
loge(e.getMessage() + ": " + LegacyDfuError.parse(error));
|
loge(e.getMessage() + ": " + LegacyDfuError.parse(error));
|
||||||
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_ERROR, String.format("Remote DFU error: %s", LegacyDfuError.parse(error)));
|
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_ERROR, String.format(Locale.US, "Remote DFU error: %s", LegacyDfuError.parse(error)));
|
||||||
|
|
||||||
logi("Sending Reset command (Op Code = 6)");
|
logi("Sending Reset command (Op Code = 6)");
|
||||||
writeOpCode(mControlPointCharacteristic, OP_CODE_RESET);
|
writeOpCode(mControlPointCharacteristic, OP_CODE_RESET);
|
||||||
|
|
|
@ -238,7 +238,7 @@ import no.nordicsemi.android.error.SecureDfuError;
|
||||||
} catch (final RemoteDfuException e) {
|
} catch (final RemoteDfuException e) {
|
||||||
final int error = DfuBaseService.ERROR_REMOTE_TYPE_SECURE | e.getErrorNumber();
|
final int error = DfuBaseService.ERROR_REMOTE_TYPE_SECURE | e.getErrorNumber();
|
||||||
loge(e.getMessage() + ": " + SecureDfuError.parse(error));
|
loge(e.getMessage() + ": " + SecureDfuError.parse(error));
|
||||||
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_ERROR, String.format("Remote DFU error: %s", SecureDfuError.parse(error)));
|
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_ERROR, String.format(Locale.US, "Remote DFU error: %s", SecureDfuError.parse(error)));
|
||||||
|
|
||||||
// For the Extended Error more details can be obtained on some devices.
|
// For the Extended Error more details can be obtained on some devices.
|
||||||
if (e instanceof RemoteDfuExtendedErrorException) {
|
if (e instanceof RemoteDfuExtendedErrorException) {
|
||||||
|
@ -839,7 +839,7 @@ import no.nordicsemi.android.error.SecureDfuError;
|
||||||
logw("Are you sure your new SoftDevice is API compatible with the updated one? If not, update the bootloader as well");
|
logw("Are you sure your new SoftDevice is API compatible with the updated one? If not, update the bootloader as well");
|
||||||
// API compatible = both SoftDevices have the same Major version
|
// API compatible = both SoftDevices have the same Major version
|
||||||
}
|
}
|
||||||
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_WARNING, String.format("Remote DFU error: %s. SD busy? Retrying...",
|
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_WARNING, String.format(Locale.US, "Remote DFU error: %s. SD busy? Retrying...",
|
||||||
SecureDfuError.parse(DfuBaseService.ERROR_REMOTE_TYPE_SECURE | SecureDfuError.INVALID_OBJECT)));
|
SecureDfuError.parse(DfuBaseService.ERROR_REMOTE_TYPE_SECURE | SecureDfuError.INVALID_OBJECT)));
|
||||||
logi("SD busy? Retrying...");
|
logi("SD busy? Retrying...");
|
||||||
logi("Executing data object (Op Code = 4)");
|
logi("Executing data object (Op Code = 4)");
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
package no.nordicsemi.android.dfu.internal.exception;
|
package no.nordicsemi.android.dfu.internal.exception;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class UnknownResponseException extends Exception {
|
public class UnknownResponseException extends Exception {
|
||||||
private static final long serialVersionUID = -8716125467309979289L;
|
private static final long serialVersionUID = -8716125467309979289L;
|
||||||
private static final char[] HEX_ARRAY = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
private static final char[] HEX_ARRAY = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||||
|
@ -40,7 +42,7 @@ public class UnknownResponseException extends Exception {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return String.format("%s (response: %s, expected: 0x%02X%02X..)", super.getMessage(), bytesToHex(mResponse, 0, mResponse.length), mExpectedReturnCode, mExpectedOpCode);
|
return String.format(Locale.US, "%s (response: %s, expected: 0x%02X%02X..)", super.getMessage(), bytesToHex(mResponse, 0, mResponse.length), mExpectedReturnCode, mExpectedOpCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String bytesToHex(final byte[] bytes, final int start, final int length) {
|
public static String bytesToHex(final byte[] bytes, final int start, final int length) {
|
||||||
|
|
|
@ -25,6 +25,8 @@ package no.nordicsemi.android.dfu.internal.scanner;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BootloaderScanner
|
* @see BootloaderScanner
|
||||||
*/
|
*/
|
||||||
|
@ -40,7 +42,7 @@ public class BootloaderScannerJB implements BootloaderScanner, BluetoothAdapter.
|
||||||
public String searchFor(final String deviceAddress) {
|
public String searchFor(final String deviceAddress) {
|
||||||
final String firstBytes = deviceAddress.substring(0, 15);
|
final String firstBytes = deviceAddress.substring(0, 15);
|
||||||
final String lastByte = deviceAddress.substring(15); // assuming that the device address is correct
|
final String lastByte = deviceAddress.substring(15); // assuming that the device address is correct
|
||||||
final String lastByteIncremented = String.format("%02X", (Integer.valueOf(lastByte, 16) + ADDRESS_DIFF) & 0xFF);
|
final String lastByteIncremented = String.format(Locale.US, "%02X", (Integer.valueOf(lastByte, 16) + ADDRESS_DIFF) & 0xFF);
|
||||||
|
|
||||||
mDeviceAddress = deviceAddress;
|
mDeviceAddress = deviceAddress;
|
||||||
mDeviceAddressIncremented = firstBytes + lastByteIncremented;
|
mDeviceAddressIncremented = firstBytes + lastByteIncremented;
|
||||||
|
|
|
@ -30,6 +30,8 @@ import android.bluetooth.le.ScanResult;
|
||||||
import android.bluetooth.le.ScanSettings;
|
import android.bluetooth.le.ScanSettings;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BootloaderScanner
|
* @see BootloaderScanner
|
||||||
*/
|
*/
|
||||||
|
@ -45,7 +47,7 @@ public class BootloaderScannerLollipop extends ScanCallback implements Bootloade
|
||||||
public String searchFor(final String deviceAddress) {
|
public String searchFor(final String deviceAddress) {
|
||||||
final String firstBytes = deviceAddress.substring(0, 15);
|
final String firstBytes = deviceAddress.substring(0, 15);
|
||||||
final String lastByte = deviceAddress.substring(15); // assuming that the device address is correct
|
final String lastByte = deviceAddress.substring(15); // assuming that the device address is correct
|
||||||
final String lastByteIncremented = String.format("%02X", (Integer.valueOf(lastByte, 16) + ADDRESS_DIFF) & 0xFF);
|
final String lastByteIncremented = String.format(Locale.US, "%02X", (Integer.valueOf(lastByte, 16) + ADDRESS_DIFF) & 0xFF);
|
||||||
|
|
||||||
mDeviceAddress = deviceAddress;
|
mDeviceAddress = deviceAddress;
|
||||||
mDeviceAddressIncremented = firstBytes + lastByteIncremented;
|
mDeviceAddressIncremented = firstBytes + lastByteIncremented;
|
||||||
|
|
Loading…
Reference in New Issue