Huawei: Fix notification constraints for Watch 3

* Watch 3 reports some values as integer, while internal buffer
now uses short values. Actually all values here fits in short
so just cut leading zeros now. Addin exception for case cutted
values was non zeros
This commit is contained in:
Vitaliy Tomin 2024-07-22 23:21:35 +08:00
parent a994603389
commit 5a6a39d059

View File

@ -135,7 +135,13 @@ public class Notifications {
private void putByteBuffer(ByteBuffer bBuffer, byte position, byte[] value) {
ByteBuffer bValue = ByteBuffer.wrap(value);
if (bValue.capacity() == 2) {
if (bValue.capacity() == 4) {
short highbytes = bValue.getShort();
if (highbytes != 0) {
throw new RuntimeException("This should not happen until very large messages allowed");
}
bBuffer.putShort(position, bValue.getShort());
} else if (bValue.capacity() == 2) {
bBuffer.putShort(position, bValue.getShort());
} else {
bBuffer.put(position, (byte) 0x00);