1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-22 14:52:25 +02:00

Huami: Truncate MusicSpec data to 80 characters

This commit is contained in:
José Rebelo 2022-05-23 23:52:58 +01:00
parent cc28879ecc
commit d08fe6ebf7

View File

@ -1339,20 +1339,28 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
return; return;
} }
String artist = "";
String album = "";
String track = "";
byte flags = 0x00; byte flags = 0x00;
flags |= 0x01; flags |= 0x01;
int length = 5; int length = 5;
if (musicSpec != null) { if (musicSpec != null) {
if (musicSpec.artist != null && musicSpec.artist.getBytes().length > 0) { artist = StringUtils.truncate(musicSpec.artist, 80);
length += musicSpec.artist.getBytes().length + 1; album = StringUtils.truncate(musicSpec.album, 80);
track = StringUtils.truncate(musicSpec.album, 80);
if (artist.getBytes().length > 0) {
length += artist.getBytes().length + 1;
flags |= 0x02; flags |= 0x02;
} }
if (musicSpec.album != null && musicSpec.album.getBytes().length > 0) { if (album.getBytes().length > 0) {
length += musicSpec.album.getBytes().length + 1; length += album.getBytes().length + 1;
flags |= 0x04; flags |= 0x04;
} }
if (musicSpec.track != null && musicSpec.track.getBytes().length > 0) { if (track.getBytes().length > 0) {
length += musicSpec.track.getBytes().length + 1; length += track.getBytes().length + 1;
flags |= 0x08; flags |= 0x08;
} }
if (musicSpec.duration != 0) { if (musicSpec.duration != 0) {
@ -1379,16 +1387,16 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
buf.putShort((short) musicStateSpec.position); buf.putShort((short) musicStateSpec.position);
if (musicSpec != null) { if (musicSpec != null) {
if (musicSpec.artist != null && musicSpec.artist.getBytes().length > 0) { if (artist.getBytes().length > 0) {
buf.put(musicSpec.artist.getBytes()); buf.put(artist.getBytes());
buf.put((byte) 0); buf.put((byte) 0);
} }
if (musicSpec.album != null && musicSpec.album.getBytes().length > 0) { if (album.getBytes().length > 0) {
buf.put(musicSpec.album.getBytes()); buf.put(album.getBytes());
buf.put((byte) 0); buf.put((byte) 0);
} }
if (musicSpec.track != null && musicSpec.track.getBytes().length > 0) { if (track.getBytes().length > 0) {
buf.put(musicSpec.track.getBytes()); buf.put(track.getBytes());
buf.put((byte) 0); buf.put((byte) 0);
} }
if (musicSpec.duration != 0) { if (musicSpec.duration != 0) {