diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java index 757fdd6e4..2418f97a1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java @@ -202,7 +202,7 @@ public class DebugActivity extends Activity { GBApplication.deviceService().onSetMusicInfo( editContent.getText().toString() + "(artist)", editContent.getText().toString() + "(album)", - editContent.getText().toString() + "(tracl)"); + editContent.getText().toString() + "(track)", 90, 10, 2); } }); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java index 616e678a4..34942ef29 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java @@ -12,7 +12,6 @@ import android.widget.Toast; import java.io.IOException; import java.util.List; -import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity; import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java index adcf077d5..f03413afa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java @@ -24,7 +24,7 @@ public interface EventHandler { void onSetCallState(@Nullable String number, @Nullable String name, ServiceCommand command); - void onSetMusicInfo(String artist, String album, String track); + void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr); void onEnableRealtimeSteps(boolean enable); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandFWHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandFWHelper.java index 4e88e43a2..20ff39d92 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandFWHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandFWHelper.java @@ -1,6 +1,5 @@ package nodomain.freeyourgadget.gadgetbridge.devices.miband; -import android.content.ContentResolver; import android.content.Context; import android.net.Uri; import android.support.annotation.NonNull; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/MusicPlaybackReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/MusicPlaybackReceiver.java index 371e33d44..1b4520303 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/MusicPlaybackReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/MusicPlaybackReceiver.java @@ -19,9 +19,16 @@ public class MusicPlaybackReceiver extends BroadcastReceiver { String artist = intent.getStringExtra("artist"); String album = intent.getStringExtra("album"); String track = intent.getStringExtra("track"); - + /* + Bundle bundle = intent.getExtras(); + for (String key : bundle.keySet()) { + Object value = bundle.get(key); + LOG.info(String.format("%s %s (%s)", key, + value.toString(), value.getClass().getName())); + } + */ LOG.info("Current track: " + artist + ", " + album + ", " + track); - GBApplication.deviceService().onSetMusicInfo(artist, album, track); + GBApplication.deviceService().onSetMusicInfo(artist, album, track, 0, 0, 0); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java index 222786937..62d7f15cf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java @@ -124,10 +124,14 @@ public class GBDeviceService implements DeviceService { } @Override - public void onSetMusicInfo(String artist, String album, String track) { + public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) { Intent intent = createIntent().setAction(ACTION_SETMUSICINFO) .putExtra(EXTRA_MUSIC_ARTIST, artist) - .putExtra(EXTRA_MUSIC_TRACK, track); + .putExtra(EXTRA_MUSIC_ALBUM, album) + .putExtra(EXTRA_MUSIC_TRACK, track) + .putExtra(EXTRA_MUSIC_DURATION, duration) + .putExtra(EXTRA_MUSIC_TRACKCOUNT, trackCount) + .putExtra(EXTRA_MUSIC_TRACKNR, trackNr); invokeService(intent); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java index 498cb29c9..8217f6d4c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java @@ -49,6 +49,9 @@ public interface DeviceService extends EventHandler { String EXTRA_MUSIC_ARTIST = "music_artist"; String EXTRA_MUSIC_ALBUM = "music_album"; String EXTRA_MUSIC_TRACK = "music_track"; + String EXTRA_MUSIC_DURATION = "music_duration"; + String EXTRA_MUSIC_TRACKNR = "music_tracknr"; + String EXTRA_MUSIC_TRACKCOUNT = "music_trackcount"; String EXTRA_APP_UUID = "app_uuid"; String EXTRA_APP_START = "app_start"; String EXTRA_APP_CONFIG = "app_config"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index e16d9325d..a9261f7ba 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -70,7 +70,10 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_ENA import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_FIND_START; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_ALBUM; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_ARTIST; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_DURATION; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_TRACK; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_TRACKCOUNT; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_TRACKNR; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_BODY; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_FLAGS; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_ID; @@ -290,7 +293,10 @@ public class DeviceCommunicationService extends Service { String artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST); String album = intent.getStringExtra(EXTRA_MUSIC_ALBUM); String track = intent.getStringExtra(EXTRA_MUSIC_TRACK); - mDeviceSupport.onSetMusicInfo(artist, album, track); + int duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0); + int trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0); + int trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0); + mDeviceSupport.onSetMusicInfo(artist, album, track, duration, trackCount, trackNr); break; case ACTION_REQUEST_APPINFO: mDeviceSupport.onAppInfoReq(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java index d13c90d22..993b03190 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java @@ -139,11 +139,11 @@ public class ServiceDeviceSupport implements DeviceSupport { } @Override - public void onSetMusicInfo(String artist, String album, String track) { + public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) { if (checkBusy("set music info")) { return; } - delegate.onSetMusicInfo(artist, album, track); + delegate.onSetMusicInfo(artist, album, track, duration, trackCount, trackNr); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1FirmwareInfo.java index f14fd50bf..e274c9ce4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1FirmwareInfo.java @@ -13,15 +13,15 @@ import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; public abstract class AbstractMi1FirmwareInfo extends AbstractMiFirmwareInfo { private static final Logger LOG = LoggerFactory.getLogger(AbstractMi1FirmwareInfo.class); - private static final byte[] SINGLE_FW_HEADER = new byte[] { + private static final byte[] SINGLE_FW_HEADER = new byte[]{ 0, - (byte)0x98, + (byte) 0x98, 0, - (byte)0x20, - (byte)0x89, + (byte) 0x20, + (byte) 0x89, 4, 0, - (byte)0x20 + (byte) 0x20 }; private static final int SINGLE_FW_HEADER_OFFSET = 0; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMiFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMiFirmwareInfo.java index 43a360892..a4b3daf6d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMiFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMiFirmwareInfo.java @@ -2,11 +2,9 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband; import android.support.annotation.NonNull; -import java.lang.reflect.Array; import java.util.Arrays; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; public abstract class AbstractMiFirmwareInfo { @@ -32,7 +30,7 @@ public abstract class AbstractMiFirmwareInfo { if (MiBandSupport.MI_1A_HR_FW_UPDATE_TEST_MODE_ENABLED) { TestMi1AFirmwareInfo info = TestMi1AFirmwareInfo.getInstance(wholeFirmwareBytes); if (info != null) { - return new AbstractMiFirmwareInfo[] { info }; + return new AbstractMiFirmwareInfo[]{info}; } } @@ -82,11 +80,13 @@ public abstract class AbstractMiFirmwareInfo { /** * Checks whether this instance, with the provided firmware data is compatible with the * given device. Must be called to avoid installing Mi1 firmware on Mi1A, for example. + * * @param device */ public abstract boolean isGenerallyCompatibleWith(GBDevice device); - public @NonNull byte[] getFirmwareBytes() { + @NonNull + public byte[] getFirmwareBytes() { return Arrays.copyOfRange(wholeFirmwareBytes, getFirmwareOffset(), getFirmwareOffset() + getFirmwareLength()); } @@ -103,6 +103,7 @@ public abstract class AbstractMiFirmwareInfo { /** * Performs a thorough sanity check of the firmware data and throws IllegalArgumentException * if there's any problem with it. + * * @throws IllegalArgumentException */ public void checkValid() throws IllegalArgumentException { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java index d2aa5cb1a..926afca19 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java @@ -16,11 +16,11 @@ import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; public class Mi1SFirmwareInfo extends CompositeMiFirmwareInfo { private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfo.class); - private static final byte[] DOUBLE_FW_HEADER = new byte[] { - (byte)0x78, - (byte)0x75, - (byte)0x63, - (byte)0x6b + private static final byte[] DOUBLE_FW_HEADER = new byte[]{ + (byte) 0x78, + (byte) 0x75, + (byte) 0x63, + (byte) 0x6b }; private static final int DOUBLE_FW_HEADER_OFFSET = 0; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index a4aa4a423..733b89acb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -540,7 +540,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } @Override - public void onSetMusicInfo(String artist, String album, String track) { + public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) { // not supported } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/TestMi1AFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/TestMi1AFirmwareInfo.java index 14c4df335..9df8b7782 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/TestMi1AFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/TestMi1AFirmwareInfo.java @@ -11,9 +11,9 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; * This is a class just for testing the dual fw firmware update procedure. * It uses two instances of the known-to-be-working Mi1A firmware update instances * and combines them in a CompositeMiFirmwareInfo. - * + *
* Most methods simply delegate to one of the child instances (FW1). - * + * * FW1 is the default Mi 1A Band firmware * FW2 is the same default Mi 1A Band firmware */ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/UpdateFirmwareOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/UpdateFirmwareOperation.java index d3cf3b2bf..f2de50d90 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/UpdateFirmwareOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/UpdateFirmwareOperation.java @@ -15,7 +15,6 @@ import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService; -import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.PlainAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index d426740bc..3a7e2a37c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -1083,9 +1083,51 @@ public class PebbleProtocol extends GBDeviceProtocol { } @Override - public byte[] encodeSetMusicInfo(String artist, String album, String track) { + public byte[] encodeSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) { String[] parts = {artist, album, track}; - return encodeMessage(ENDPOINT_MUSICCONTROL, MUSICCONTROL_SETMUSICINFO, 0, parts); + if (duration == 0) { + return encodeMessage(ENDPOINT_MUSICCONTROL, MUSICCONTROL_SETMUSICINFO, 0, parts); + } else { + // Calculate length first + int length = LENGTH_PREFIX + 13; + if (parts != null) { + for (String s : parts) { + if (s == null || s.equals("")) { + length++; // encode null or empty strings as 0x00 later + continue; + } + length += (1 + s.getBytes().length); + } + } + + // Encode Prefix + ByteBuffer buf = ByteBuffer.allocate(length); + buf.order(ByteOrder.BIG_ENDIAN); + buf.putShort((short) (length - LENGTH_PREFIX)); + buf.putShort(ENDPOINT_MUSICCONTROL); + buf.put(MUSICCONTROL_SETMUSICINFO); + + // Encode Pascal-Style Strings + for (String s : parts) { + if (s == null || s.equals("")) { + buf.put((byte) 0x00); + continue; + } + + int partlength = s.getBytes().length; + if (partlength > 255) partlength = 255; + buf.put((byte) partlength); + buf.put(s.getBytes(), 0, partlength); + } + + buf.order(ByteOrder.LITTLE_ENDIAN); + buf.putInt(duration*1000); + buf.putInt(trackCount); + buf.putInt(trackNr); + + return buf.array(); + + } } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java index eaea3c84d..5563de599 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java @@ -126,8 +126,8 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport } @Override - public void onSetMusicInfo(String artist, String album, String track) { - byte[] bytes = gbDeviceProtocol.encodeSetMusicInfo(artist, album, track); + public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) { + byte[] bytes = gbDeviceProtocol.encodeSetMusicInfo(artist, album, track, duration, trackCount, trackNr); sendToDevice(bytes); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java index 439c75290..b08b105d5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java @@ -20,7 +20,7 @@ public abstract class GBDeviceProtocol { return null; } - public byte[] encodeSetMusicInfo(String artist, String album, String track) { + public byte[] encodeSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) { return null; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/ArrayUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/ArrayUtils.java index da0aa7ee4..7c767cc11 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/ArrayUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/ArrayUtils.java @@ -4,10 +4,11 @@ public class ArrayUtils { /** * Checks the two given arrays for equality, but comparing only a subset of the second * array with the whole first array. - * @param first the whole array to compare against - * @param second the array, of which a subset shall be compared against the whole first array + * + * @param first the whole array to compare against + * @param second the array, of which a subset shall be compared against the whole first array * @param secondStartIndex the start index (inclusive) of the second array from which to start the comparison - * @param secondEndIndex the end index (exclusive) of the second array until which to compare + * @param secondEndIndex the end index (exclusive) of the second array until which to compare * @return whether the first byte array is equal to the specified subset of the second byte array * @throws IllegalArgumentException when one of the arrays is null or start and end index are wrong */ diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java index 29043020b..6528b6131 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java @@ -66,7 +66,7 @@ public class TestDeviceSupport extends AbstractDeviceSupport { } @Override - public void onSetMusicInfo(String artist, String album, String track) { + public void onSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) { }