mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Garmin: extract sendProtobufRequest helper
Every watch-bound Smart RPC site followed the same shape: sendOutgoingMessage(taskName, protocolBufferHandler.prepareProtobufRequest(payload)). Fold it into a single sendProtobufRequest(taskName, payload) on GarminSupport. No behaviour change.
This commit is contained in:
committed by
José Rebelo
parent
32a18d8d81
commit
5b375b2bb8
+30
-57
@@ -127,7 +127,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.messages.
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.DownloadRequestMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.GFDIMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.MusicControlEntityUpdateMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.ProtobufMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SetDeviceSettingsMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SetFileFlagsMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SupportedFileTypesMessage;
|
||||
@@ -237,14 +236,10 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
if (newSyncProtocol() && directoryEntry.getFiletype() != FileType.FILETYPE.DEVICE_XML) {
|
||||
if (directoryEntry.getFiletype() == FileType.FILETYPE.DIRECTORY) {
|
||||
LOG.debug("Got directory entry, syncing with new protocol");
|
||||
sendOutgoingMessage(
|
||||
"request file list",
|
||||
protocolBufferHandler.prepareProtobufRequest(
|
||||
sendProtobufRequest("request file list",
|
||||
GdiSmartProto.Smart.newBuilder().setFileSyncService(
|
||||
protocolBufferHandler.getFileSyncServiceHandler().requestFileList()
|
||||
).build()
|
||||
)
|
||||
);
|
||||
).build());
|
||||
return;
|
||||
}
|
||||
LOG.warn("Ignoring directory entry {} in new sync protocol", directoryEntry.getFileName());
|
||||
@@ -415,7 +410,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
final String language = Locale.getDefault().getLanguage();
|
||||
final String country = Locale.getDefault().getCountry();
|
||||
final String localeString = language + "_" + country.toUpperCase();
|
||||
final ProtobufMessage realtimeSettingsInit = protocolBufferHandler.prepareProtobufRequest(GdiSmartProto.Smart.newBuilder()
|
||||
sendProtobufRequest("init realtime settings", GdiSmartProto.Smart.newBuilder()
|
||||
.setSettingsService(
|
||||
GdiSettingsService.SettingsService.newBuilder()
|
||||
.setInitRequest(
|
||||
@@ -425,7 +420,6 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
)
|
||||
)
|
||||
.build());
|
||||
sendOutgoingMessage("init realtime settings", realtimeSettingsInit);
|
||||
}
|
||||
} else if (deviceEvent instanceof ProtobufResponseEvent protobufResponseEvent) {
|
||||
sendOutgoingMessage(
|
||||
@@ -567,17 +561,13 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
|
||||
@Override
|
||||
public void onAppInfoReq() {
|
||||
sendOutgoingMessage(
|
||||
"request apps",
|
||||
protocolBufferHandler.prepareProtobufRequest(
|
||||
sendProtobufRequest("request apps",
|
||||
GdiSmartProto.Smart.newBuilder().setInstalledAppsService(
|
||||
GdiInstalledAppsService.InstalledAppsService.newBuilder().setGetInstalledAppsRequest(
|
||||
GdiInstalledAppsService.InstalledAppsService.GetInstalledAppsRequest.newBuilder()
|
||||
.setAppType(GdiInstalledAppsService.InstalledAppsService.AppType.ALL)
|
||||
)
|
||||
).build()
|
||||
)
|
||||
);
|
||||
).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -601,32 +591,26 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
return;
|
||||
}
|
||||
|
||||
sendOutgoingMessage(
|
||||
"delete app",
|
||||
protocolBufferHandler.prepareProtobufRequest(
|
||||
sendProtobufRequest("delete app",
|
||||
GdiSmartProto.Smart.newBuilder().setInstalledAppsService(
|
||||
GdiInstalledAppsService.InstalledAppsService.newBuilder().setDeleteAppRequest(
|
||||
GdiInstalledAppsService.InstalledAppsService.DeleteAppRequest.newBuilder()
|
||||
.setStoreAppId(app.getStoreAppId())
|
||||
.setAppType(app.getType())
|
||||
)
|
||||
).build()
|
||||
)
|
||||
);
|
||||
).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppConfigRequest(final UUID uuid) {
|
||||
sendOutgoingMessage("app config request " + uuid, protocolBufferHandler.prepareProtobufRequest(
|
||||
protocolBufferHandler.getAppConfigHandler().onAppConfigRequest(uuid)
|
||||
));
|
||||
sendProtobufRequest("app config request " + uuid,
|
||||
protocolBufferHandler.getAppConfigHandler().onAppConfigRequest(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppConfigSet(final UUID uuid, final ArrayList<DynamicAppConfig> configs) {
|
||||
sendOutgoingMessage("app config set " + uuid, protocolBufferHandler.prepareProtobufRequest(
|
||||
protocolBufferHandler.getAppConfigHandler().onAppConfigSet(uuid, configs)
|
||||
));
|
||||
sendProtobufRequest("app config set " + uuid,
|
||||
protocolBufferHandler.getAppConfigHandler().onAppConfigSet(uuid, configs));
|
||||
}
|
||||
|
||||
public void onAppListReceived(final List<GdiInstalledAppsService.InstalledAppsService.InstalledApp> apps) {
|
||||
@@ -675,6 +659,11 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
sendWeatherConditions(weatherSpec);
|
||||
}
|
||||
|
||||
/** Wrap and send a watch-bound Smart RPC. */
|
||||
void sendProtobufRequest(final String taskName, final GdiSmartProto.Smart payload) {
|
||||
sendOutgoingMessage(taskName, protocolBufferHandler.prepareProtobufRequest(payload));
|
||||
}
|
||||
|
||||
private void sendOutgoingMessage(final String taskName, final GFDIMessage message) {
|
||||
if (message == null)
|
||||
return;
|
||||
@@ -838,7 +827,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
if (config.startsWith("protobuf:")) {
|
||||
try {
|
||||
final GdiSmartProto.Smart smart = GdiSmartProto.Smart.parseFrom(GB.hexStringToByteArray(config.replaceFirst("protobuf:", "")));
|
||||
sendOutgoingMessage("send config", protocolBufferHandler.prepareProtobufRequest(smart));
|
||||
sendProtobufRequest("send config", smart);
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Failed to send {} as protobuf", config, e);
|
||||
}
|
||||
@@ -907,14 +896,10 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
} else if (currentlyDownloading.getSyncFile() != null) {
|
||||
LOG.debug("Will download file: {}/{}", currentlyDownloading.getSyncFile().getId().getId1(), currentlyDownloading.getSyncFile().getId().getId2());
|
||||
|
||||
sendOutgoingMessage(
|
||||
"request file",
|
||||
protocolBufferHandler.prepareProtobufRequest(
|
||||
sendProtobufRequest("request file",
|
||||
GdiSmartProto.Smart.newBuilder().setFileSyncService(
|
||||
protocolBufferHandler.getFileSyncServiceHandler().requestFile(currentlyDownloading.getSyncFile())
|
||||
).build()
|
||||
)
|
||||
);
|
||||
).build());
|
||||
} else {
|
||||
LOG.error("Unexpected FileToDownload");
|
||||
}
|
||||
@@ -982,7 +967,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
}
|
||||
|
||||
private void enableBatteryLevelUpdate() {
|
||||
final ProtobufMessage batteryLevelProtobufRequest = protocolBufferHandler.prepareProtobufRequest(GdiSmartProto.Smart.newBuilder()
|
||||
sendProtobufRequest("enable battery updates", GdiSmartProto.Smart.newBuilder()
|
||||
.setDeviceStatusService(
|
||||
GdiDeviceStatus.DeviceStatusService.newBuilder()
|
||||
.setRemoteDeviceBatteryStatusRequest(
|
||||
@@ -990,7 +975,6 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
)
|
||||
)
|
||||
.build());
|
||||
sendOutgoingMessage("enable battery updates", batteryLevelProtobufRequest);
|
||||
}
|
||||
|
||||
private void sendDeviceSettings() {
|
||||
@@ -1019,11 +1003,8 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
GdiFindMyWatch.FindMyWatchService.FindMyWatchCancelRequest.newBuilder()
|
||||
);
|
||||
}
|
||||
final ProtobufMessage findMyWatch = protocolBufferHandler.prepareProtobufRequest(
|
||||
GdiSmartProto.Smart.newBuilder()
|
||||
.setFindMyWatchService(a).build());
|
||||
|
||||
sendOutgoingMessage("find device", findMyWatch);
|
||||
sendProtobufRequest("find device",
|
||||
GdiSmartProto.Smart.newBuilder().setFindMyWatchService(a).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1255,12 +1236,10 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
GarminUtils.toLocationData(location, GdiCore.CoreService.DataType.REALTIME_TRACKING)
|
||||
);
|
||||
|
||||
final ProtobufMessage locationUpdatedNotificationRequest = protocolBufferHandler.prepareProtobufRequest(
|
||||
sendProtobufRequest("set gps location",
|
||||
GdiSmartProto.Smart.newBuilder().setCoreService(
|
||||
GdiCore.CoreService.newBuilder().setLocationUpdatedNotification(locationUpdatedNotification)
|
||||
).build()
|
||||
);
|
||||
sendOutgoingMessage("set gps location", locationUpdatedNotificationRequest);
|
||||
).build());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1316,7 +1295,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
final String country = Locale.getDefault().getCountry();
|
||||
final String localeString = language + "_" + country.toUpperCase();
|
||||
|
||||
sendOutgoingMessage("get settings screen " + screenId, protocolBufferHandler.prepareProtobufRequest(
|
||||
sendProtobufRequest("get settings screen " + screenId,
|
||||
GdiSmartProto.Smart.newBuilder()
|
||||
.setSettingsService(GdiSettingsService.SettingsService.newBuilder()
|
||||
.setDefinitionRequest(
|
||||
@@ -1325,18 +1304,16 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
.setUnk2(0)
|
||||
.setLanguage(localeString.length() == 5 ? localeString : "en_US")
|
||||
)
|
||||
).build()
|
||||
));
|
||||
).build());
|
||||
|
||||
sendOutgoingMessage("get settings state " + screenId, protocolBufferHandler.prepareProtobufRequest(
|
||||
sendProtobufRequest("get settings state " + screenId,
|
||||
GdiSmartProto.Smart.newBuilder()
|
||||
.setSettingsService(GdiSettingsService.SettingsService.newBuilder()
|
||||
.setStateRequest(
|
||||
GdiSettingsService.ScreenStateRequest.newBuilder()
|
||||
.setScreenId(screenId)
|
||||
)
|
||||
).build()
|
||||
));
|
||||
).build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1481,12 +1458,8 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
final GdiFileSyncService.FileSyncService syncedCommand = protocolBufferHandler.getFileSyncServiceHandler()
|
||||
.markSynced(currentlyDownloading.getSyncFile());
|
||||
if (syncedCommand != null) {
|
||||
sendOutgoingMessage(
|
||||
"mark file as synced",
|
||||
protocolBufferHandler.prepareProtobufRequest(
|
||||
GdiSmartProto.Smart.newBuilder().setFileSyncService(syncedCommand).build()
|
||||
)
|
||||
);
|
||||
sendProtobufRequest("mark file as synced",
|
||||
GdiSmartProto.Smart.newBuilder().setFileSyncService(syncedCommand).build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user