mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-09 03:37:03 +01:00
Garmin: simplify handling canned replies and only send error if no reply is set at all
This commit is contained in:
parent
29787d0c9b
commit
3f8eeebc5a
@ -350,50 +350,26 @@ public class ProtocolBufferHandler implements MessageHandler {
|
|||||||
// Mark canned messages as supported
|
// Mark canned messages as supported
|
||||||
deviceSupport.evaluateGBDeviceEvent(new GBDeviceEventUpdatePreferences(GarminPreferences.PREF_FEAT_CANNED_MESSAGES, true));
|
deviceSupport.evaluateGBDeviceEvent(new GBDeviceEventUpdatePreferences(GarminPreferences.PREF_FEAT_CANNED_MESSAGES, true));
|
||||||
|
|
||||||
if (this.cannedListTypeMap.isEmpty()) {
|
|
||||||
List<GdiSmsNotification.SmsNotificationService.CannedListType> requestedTypes = smsNotificationService.getSmsCannedListRequest().getRequestedTypesList();
|
|
||||||
for (GdiSmsNotification.SmsNotificationService.CannedListType type :
|
|
||||||
requestedTypes) {
|
|
||||||
if (GdiSmsNotification.SmsNotificationService.CannedListType.SMS_MESSAGE_RESPONSE.equals(type)) {
|
|
||||||
final ArrayList<String> messages = new ArrayList<>();
|
|
||||||
for (int i = 1; i <= 16; i++) {
|
|
||||||
String message = deviceSupport.getDevicePrefs().getString("canned_reply_" + i, null);
|
|
||||||
if (message != null && !message.isEmpty()) {
|
|
||||||
messages.add(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!messages.isEmpty())
|
|
||||||
this.cannedListTypeMap.put(type, messages.toArray(new String[0]));
|
|
||||||
} else if (GdiSmsNotification.SmsNotificationService.CannedListType.PHONE_CALL_RESPONSE.equals(type)) {
|
|
||||||
final ArrayList<String> messages = new ArrayList<>();
|
|
||||||
for (int i = 1; i <= 16; i++) {
|
|
||||||
String message = deviceSupport.getDevicePrefs().getString("canned_message_dismisscall_" + i, null);
|
|
||||||
if (message != null && !message.isEmpty()) {
|
|
||||||
messages.add(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!messages.isEmpty())
|
|
||||||
this.cannedListTypeMap.put(type, messages.toArray(new String[0]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
List<GdiSmsNotification.SmsNotificationService.CannedListType> requestedTypes = smsNotificationService.getSmsCannedListRequest().getRequestedTypesList();
|
List<GdiSmsNotification.SmsNotificationService.CannedListType> requestedTypes = smsNotificationService.getSmsCannedListRequest().getRequestedTypesList();
|
||||||
|
|
||||||
|
populateCannedListTypeMap(requestedTypes);
|
||||||
|
|
||||||
GdiSmsNotification.SmsNotificationService.SmsCannedListResponse.Builder builder = GdiSmsNotification.SmsNotificationService.SmsCannedListResponse.newBuilder()
|
GdiSmsNotification.SmsNotificationService.SmsCannedListResponse.Builder builder = GdiSmsNotification.SmsNotificationService.SmsCannedListResponse.newBuilder()
|
||||||
.setStatus(GdiSmsNotification.SmsNotificationService.ResponseStatus.SUCCESS);
|
.setStatus(GdiSmsNotification.SmsNotificationService.ResponseStatus.SUCCESS);
|
||||||
|
boolean found = false;
|
||||||
for (GdiSmsNotification.SmsNotificationService.CannedListType requestedType : requestedTypes) {
|
for (GdiSmsNotification.SmsNotificationService.CannedListType requestedType : requestedTypes) {
|
||||||
if (this.cannedListTypeMap.containsKey(requestedType)) {
|
if (this.cannedListTypeMap.containsKey(requestedType)) {
|
||||||
|
found = true;
|
||||||
builder.addLists(GdiSmsNotification.SmsNotificationService.SmsCannedList.newBuilder()
|
builder.addLists(GdiSmsNotification.SmsNotificationService.SmsCannedList.newBuilder()
|
||||||
.addAllResponse(Arrays.asList(Objects.requireNonNull(this.cannedListTypeMap.get(requestedType))))
|
.addAllResponse(Arrays.asList(Objects.requireNonNull(this.cannedListTypeMap.get(requestedType))))
|
||||||
.setType(requestedType)
|
.setType(requestedType)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
builder.setStatus(GdiSmsNotification.SmsNotificationService.ResponseStatus.GENERIC_ERROR);
|
LOG.warn("Missing canned messages data for type {}", requestedType);
|
||||||
LOG.info("Missing canned messages data for type {}", requestedType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!found)
|
||||||
|
builder.setStatus(GdiSmsNotification.SmsNotificationService.ResponseStatus.GENERIC_ERROR);
|
||||||
|
|
||||||
return GdiSmartProto.Smart.newBuilder().setSmsNotificationService(GdiSmsNotification.SmsNotificationService.newBuilder().setSmsCannedListResponse(builder)).build();
|
return GdiSmartProto.Smart.newBuilder().setSmsNotificationService(GdiSmsNotification.SmsNotificationService.newBuilder().setSmsCannedListResponse(builder)).build();
|
||||||
} else {
|
} else {
|
||||||
@ -402,6 +378,30 @@ public class ProtocolBufferHandler implements MessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void populateCannedListTypeMap(List<GdiSmsNotification.SmsNotificationService.CannedListType> requestedTypes) {
|
||||||
|
if (this.cannedListTypeMap.isEmpty()) {
|
||||||
|
for (GdiSmsNotification.SmsNotificationService.CannedListType type :
|
||||||
|
requestedTypes) {
|
||||||
|
String preferencesPrefix = "";
|
||||||
|
if (GdiSmsNotification.SmsNotificationService.CannedListType.SMS_MESSAGE_RESPONSE.equals(type))
|
||||||
|
preferencesPrefix = "canned_reply_";
|
||||||
|
else if (GdiSmsNotification.SmsNotificationService.CannedListType.PHONE_CALL_RESPONSE.equals(type))
|
||||||
|
preferencesPrefix = "canned_message_dismisscall_";
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
final ArrayList<String> messages = new ArrayList<>();
|
||||||
|
for (int i = 1; i <= 16; i++) {
|
||||||
|
String message = deviceSupport.getDevicePrefs().getString(preferencesPrefix + i, null);
|
||||||
|
if (message != null && !message.isEmpty()) {
|
||||||
|
messages.add(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!messages.isEmpty())
|
||||||
|
this.cannedListTypeMap.put(type, messages.toArray(new String[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void processProtobufFindMyWatchResponse(GdiFindMyWatch.FindMyWatchService findMyWatchService) {
|
private void processProtobufFindMyWatchResponse(GdiFindMyWatch.FindMyWatchService findMyWatchService) {
|
||||||
if (findMyWatchService.hasCancelRequest()) {
|
if (findMyWatchService.hasCancelRequest()) {
|
||||||
LOG.info("Watch found");
|
LOG.info("Watch found");
|
||||||
|
Loading…
Reference in New Issue
Block a user