1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-12 10:55:49 +01:00

Remove hard-coded name list and use Java Reflection to get the correct field names - fixes issue where call state reporting was corrupted

This commit is contained in:
Gordon Williams 2020-09-28 10:09:27 +01:00
parent ac5e7608fc
commit 5c2ee15988

View File

@ -34,6 +34,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.SimpleTimeZone;
import java.util.UUID;
import java.lang.reflect.Field;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
@ -325,8 +326,14 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
try {
JSONObject o = new JSONObject();
o.put("t", "call");
String[] cmdString = {"", "undefined", "accept", "incoming", "outgoing", "reject", "start", "end"};
o.put("cmd", cmdString[callSpec.command]);
String cmdName = "";
try {
Field fields[] = callSpec.getClass().getDeclaredFields();
for (Field field : fields)
if (field.getName().startsWith("CALL_") && field.getInt(callSpec) == callSpec.command)
cmdName = field.getName().substring(5).toLowerCase();
} catch (IllegalAccessException e) {}
o.put("cmd", cmdName);
o.put("name", callSpec.name);
o.put("number", callSpec.number);
uartTxJSON("onSetCallState", o);