diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/AsynchronousResponse.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/AsynchronousResponse.java
index edbed55ff..8a71f6f99 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/AsynchronousResponse.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/AsynchronousResponse.java
@@ -22,6 +22,7 @@ import android.content.SharedPreferences;
import android.media.AudioManager;
import android.os.Build;
import android.os.Handler;
+import android.os.Looper;
import android.widget.Toast;
import org.slf4j.Logger;
@@ -244,7 +245,9 @@ public class AsynchronousResponse {
GB.toast("Failed to send music status request", Toast.LENGTH_SHORT, GB.ERROR, e);
LOG.error("Failed to send music status request (1)", e);
}
- // Send Music Info
+
+ // Update and send Music Info
+ this.support.refreshMediaManager();
this.support.sendSetMusic();
} else if (response.commandId == MusicControl.Control.id) {
if (!(response instanceof MusicControl.Control.Response))
@@ -319,6 +322,13 @@ public class AsynchronousResponse {
GB.toast("Failed to send music status request", Toast.LENGTH_SHORT, GB.ERROR, e);
LOG.error("Failed to send music status request (2)", e);
}
+
+ // Delay so the media app has a moment to change state
+ new Handler(Looper.getMainLooper()).postDelayed(() -> {
+ // Update and send Music Info
+ this.support.refreshMediaManager();
+ this.support.sendSetMusic();
+ }, 100);
}
}
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiBRSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiBRSupport.java
index 3c2bd15c4..78bc704e7 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiBRSupport.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiBRSupport.java
@@ -16,6 +16,8 @@
along with this program. If not, see . */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei;
+import android.bluetooth.BluetoothAdapter;
+import android.content.Context;
import android.location.Location;
import android.net.Uri;
@@ -25,6 +27,7 @@ import java.util.ArrayList;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiConstants;
+import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
@@ -46,6 +49,12 @@ public class HuaweiBRSupport extends AbstractBTBRDeviceSupport {
}
+ @Override
+ public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
+ super.setContext(gbDevice, btAdapter, context);
+ supportProvider.setContext(context);
+ }
+
@Override
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
return supportProvider.initializeDevice(builder);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiLESupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiLESupport.java
index 1775fd230..44a8689a5 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiLESupport.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiLESupport.java
@@ -16,8 +16,10 @@
along with this program. If not, see . */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei;
+import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
+import android.content.Context;
import android.location.Location;
import android.net.Uri;
@@ -29,6 +31,7 @@ import java.util.ArrayList;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiConstants;
+import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
@@ -53,6 +56,12 @@ public class HuaweiLESupport extends AbstractBTLEDeviceSupport {
supportProvider = new HuaweiSupportProvider(this);
}
+ @Override
+ public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
+ super.setContext(gbDevice, btAdapter, context);
+ supportProvider.setContext(context);
+ }
+
@Override
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
return supportProvider.initializeDevice(builder);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java
index 33a30b309..f272e97ff 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java
@@ -155,6 +155,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.FitnessData;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SetWorkModeRequest;
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
+import nodomain.freeyourgadget.gadgetbridge.util.MediaManager;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
public class HuaweiSupportProvider {
@@ -174,8 +175,7 @@ public class HuaweiSupportProvider {
protected String androidID;
protected short msgId = 0;
- private MusicStateSpec musicStateSpec = null;
- private MusicSpec musicSpec = null;
+ private MediaManager mediaManager = null;
private GpsAndTime.GpsParameters.Response gpsParametersResponse = null;
@@ -205,6 +205,10 @@ public class HuaweiSupportProvider {
this.leSupport = support;
}
+ public void setContext(Context context) {
+ mediaManager = new MediaManager(context);
+ }
+
public boolean isBLE() {
return huaweiType == HuaweiDeviceType.AW || huaweiType == HuaweiDeviceType.BLE || huaweiType == HuaweiDeviceType.SMART;
}
@@ -1333,26 +1337,31 @@ public class HuaweiSupportProvider {
}
public void onSetMusicState(MusicStateSpec stateSpec) {
- this.musicStateSpec = stateSpec;
- sendSetMusic();
+ if (mediaManager.onSetMusicState(stateSpec))
+ sendSetMusic();
}
public void onSetMusicInfo(MusicSpec musicSpec) {
- this.musicSpec = musicSpec;
- sendSetMusic();
+ if (mediaManager.onSetMusicInfo(musicSpec))
+ sendSetMusic();
}
public void onSetPhoneVolume() {
- // TODO: check when implemented in GB
-
- // We get the audio volume manually, so ignoring the argument
sendSetMusic();
}
+ public void refreshMediaManager() {
+ mediaManager.refresh();
+ }
+
public void sendSetMusic() {
// This often gets called twice in a row because of onSetMusicState and onSetMusicInfo
// Maybe we can consolidate that into just one request?
- SetMusicRequest setMusicRequest = new SetMusicRequest(this, this.musicStateSpec, this.musicSpec);
+ SetMusicRequest setMusicRequest = new SetMusicRequest(
+ this,
+ mediaManager.getBufferMusicStateSpec(),
+ mediaManager.getBufferMusicSpec()
+ );
try {
setMusicRequest.doPerform();
} catch (IOException e) {