Huawei: Fix notifications for Huawei Band 4e

Fixes #3957
This commit is contained in:
Martin.JM 2024-10-27 00:31:57 +02:00
parent cc16906d20
commit 27f61138bc
3 changed files with 19 additions and 17 deletions

View File

@ -87,6 +87,17 @@ public class HuaweiCoordinator {
public HuaweiCoordinator(HuaweiCoordinatorSupplier parent) {
this.parent = parent;
// Set non-numeric capabilities
this.expandCapabilities = GB.hexStringToByteArray(getCapabilitiesSharedPreferences().getString("expandCapabilities", "00"));
this.notificationCapabilities = (byte)getCapabilitiesSharedPreferences().getInt("notificationCapabilities", -0x01);
this.notificationConstraints = ByteBuffer.wrap(GB.hexStringToByteArray(
getCapabilitiesSharedPreferences().getString(
"notificationConstraints",
GB.hexdump(Notifications.defaultConstraints)
)));
this.maxContactsCount = getCapabilitiesSharedPreferences().getInt("maxContactsCount", 0);
for (String key : getCapabilitiesSharedPreferences().getAll().keySet()) {
int service;
try {
@ -94,18 +105,7 @@ public class HuaweiCoordinator {
byte[] commands = GB.hexStringToByteArray(getCapabilitiesSharedPreferences().getString(key, "00"));
this.commandsPerService.put(service, commands);
} catch (NumberFormatException e) {
if (key.equals("expandCapabilities"))
this.expandCapabilities = GB.hexStringToByteArray(getCapabilitiesSharedPreferences().getString(key, "00"));
if (key.equals("notificationCapabilities"))
this.notificationCapabilities = (byte)getCapabilitiesSharedPreferences().getInt(key, -0x01);
if (key.equals("notificationConstraints"))
this.notificationConstraints = ByteBuffer.wrap(GB.hexStringToByteArray(
getCapabilitiesSharedPreferences().getString(
key,
GB.hexdump(Notifications.defaultConstraints)
)));
if (key.equals("maxContactsCount"))
this.maxContactsCount = getCapabilitiesSharedPreferences().getInt(key, 0);
// These are the non-numeric capabilities, which have been set already
}
}
}

View File

@ -24,10 +24,10 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiTLV;
public class Notifications {
public static final byte id = 0x02;
public static final byte[] defaultConstraints = new byte[]{
(short)0x02, (short)0x0F,
(short)0x00, (short)0x02, (short)0x1E,
(short)0x00, (short)0x02, (short)0x1E,
(short)0x00, (short)0x02, (short)0x1E
0x00, 0x02, 0x00, 0x0F,
0x00, 0x00, 0x00, 0x02, 0x00, 0x1E,
0x00, 0x00, 0x00, 0x02, 0x00, 0x1E,
0x00, 0x00, 0x00, 0x02, 0x00, 0x1E
};
public static class NotificationActionRequest extends HuaweiPacket {

View File

@ -24,6 +24,7 @@ import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Notifications;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Notifications.NotificationConstraints;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
public class GetNotificationConstraintsRequest extends Request {
@ -37,7 +38,8 @@ public class GetNotificationConstraintsRequest extends Request {
@Override
protected boolean requestSupported() {
return supportProvider.getHuaweiCoordinator().supportsNotificationAlert() && supportProvider.getProtocolVersion() == 2;
return supportProvider.getHuaweiCoordinator().supportsNotificationAlert() && supportProvider.getProtocolVersion() == 2
&& supportProvider.getCoordinator().getDeviceType() != DeviceType.HUAWEIBANDAW70; // Bit of a workaround, there is probably some capabilities this actually depends on
}
@Override