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.DownloadRequestMessage;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.GFDIMessage;
|
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.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.SetDeviceSettingsMessage;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SetFileFlagsMessage;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SetFileFlagsMessage;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SupportedFileTypesMessage;
|
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 (newSyncProtocol() && directoryEntry.getFiletype() != FileType.FILETYPE.DEVICE_XML) {
|
||||||
if (directoryEntry.getFiletype() == FileType.FILETYPE.DIRECTORY) {
|
if (directoryEntry.getFiletype() == FileType.FILETYPE.DIRECTORY) {
|
||||||
LOG.debug("Got directory entry, syncing with new protocol");
|
LOG.debug("Got directory entry, syncing with new protocol");
|
||||||
sendOutgoingMessage(
|
sendProtobufRequest("request file list",
|
||||||
"request file list",
|
|
||||||
protocolBufferHandler.prepareProtobufRequest(
|
|
||||||
GdiSmartProto.Smart.newBuilder().setFileSyncService(
|
GdiSmartProto.Smart.newBuilder().setFileSyncService(
|
||||||
protocolBufferHandler.getFileSyncServiceHandler().requestFileList()
|
protocolBufferHandler.getFileSyncServiceHandler().requestFileList()
|
||||||
).build()
|
).build());
|
||||||
)
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG.warn("Ignoring directory entry {} in new sync protocol", directoryEntry.getFileName());
|
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 language = Locale.getDefault().getLanguage();
|
||||||
final String country = Locale.getDefault().getCountry();
|
final String country = Locale.getDefault().getCountry();
|
||||||
final String localeString = language + "_" + country.toUpperCase();
|
final String localeString = language + "_" + country.toUpperCase();
|
||||||
final ProtobufMessage realtimeSettingsInit = protocolBufferHandler.prepareProtobufRequest(GdiSmartProto.Smart.newBuilder()
|
sendProtobufRequest("init realtime settings", GdiSmartProto.Smart.newBuilder()
|
||||||
.setSettingsService(
|
.setSettingsService(
|
||||||
GdiSettingsService.SettingsService.newBuilder()
|
GdiSettingsService.SettingsService.newBuilder()
|
||||||
.setInitRequest(
|
.setInitRequest(
|
||||||
@@ -425,7 +420,6 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.build());
|
.build());
|
||||||
sendOutgoingMessage("init realtime settings", realtimeSettingsInit);
|
|
||||||
}
|
}
|
||||||
} else if (deviceEvent instanceof ProtobufResponseEvent protobufResponseEvent) {
|
} else if (deviceEvent instanceof ProtobufResponseEvent protobufResponseEvent) {
|
||||||
sendOutgoingMessage(
|
sendOutgoingMessage(
|
||||||
@@ -567,17 +561,13 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAppInfoReq() {
|
public void onAppInfoReq() {
|
||||||
sendOutgoingMessage(
|
sendProtobufRequest("request apps",
|
||||||
"request apps",
|
|
||||||
protocolBufferHandler.prepareProtobufRequest(
|
|
||||||
GdiSmartProto.Smart.newBuilder().setInstalledAppsService(
|
GdiSmartProto.Smart.newBuilder().setInstalledAppsService(
|
||||||
GdiInstalledAppsService.InstalledAppsService.newBuilder().setGetInstalledAppsRequest(
|
GdiInstalledAppsService.InstalledAppsService.newBuilder().setGetInstalledAppsRequest(
|
||||||
GdiInstalledAppsService.InstalledAppsService.GetInstalledAppsRequest.newBuilder()
|
GdiInstalledAppsService.InstalledAppsService.GetInstalledAppsRequest.newBuilder()
|
||||||
.setAppType(GdiInstalledAppsService.InstalledAppsService.AppType.ALL)
|
.setAppType(GdiInstalledAppsService.InstalledAppsService.AppType.ALL)
|
||||||
)
|
)
|
||||||
).build()
|
).build());
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -601,32 +591,26 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendOutgoingMessage(
|
sendProtobufRequest("delete app",
|
||||||
"delete app",
|
|
||||||
protocolBufferHandler.prepareProtobufRequest(
|
|
||||||
GdiSmartProto.Smart.newBuilder().setInstalledAppsService(
|
GdiSmartProto.Smart.newBuilder().setInstalledAppsService(
|
||||||
GdiInstalledAppsService.InstalledAppsService.newBuilder().setDeleteAppRequest(
|
GdiInstalledAppsService.InstalledAppsService.newBuilder().setDeleteAppRequest(
|
||||||
GdiInstalledAppsService.InstalledAppsService.DeleteAppRequest.newBuilder()
|
GdiInstalledAppsService.InstalledAppsService.DeleteAppRequest.newBuilder()
|
||||||
.setStoreAppId(app.getStoreAppId())
|
.setStoreAppId(app.getStoreAppId())
|
||||||
.setAppType(app.getType())
|
.setAppType(app.getType())
|
||||||
)
|
)
|
||||||
).build()
|
).build());
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAppConfigRequest(final UUID uuid) {
|
public void onAppConfigRequest(final UUID uuid) {
|
||||||
sendOutgoingMessage("app config request " + uuid, protocolBufferHandler.prepareProtobufRequest(
|
sendProtobufRequest("app config request " + uuid,
|
||||||
protocolBufferHandler.getAppConfigHandler().onAppConfigRequest(uuid)
|
protocolBufferHandler.getAppConfigHandler().onAppConfigRequest(uuid));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAppConfigSet(final UUID uuid, final ArrayList<DynamicAppConfig> configs) {
|
public void onAppConfigSet(final UUID uuid, final ArrayList<DynamicAppConfig> configs) {
|
||||||
sendOutgoingMessage("app config set " + uuid, protocolBufferHandler.prepareProtobufRequest(
|
sendProtobufRequest("app config set " + uuid,
|
||||||
protocolBufferHandler.getAppConfigHandler().onAppConfigSet(uuid, configs)
|
protocolBufferHandler.getAppConfigHandler().onAppConfigSet(uuid, configs));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAppListReceived(final List<GdiInstalledAppsService.InstalledAppsService.InstalledApp> apps) {
|
public void onAppListReceived(final List<GdiInstalledAppsService.InstalledAppsService.InstalledApp> apps) {
|
||||||
@@ -675,6 +659,11 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
sendWeatherConditions(weatherSpec);
|
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) {
|
private void sendOutgoingMessage(final String taskName, final GFDIMessage message) {
|
||||||
if (message == null)
|
if (message == null)
|
||||||
return;
|
return;
|
||||||
@@ -838,7 +827,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
if (config.startsWith("protobuf:")) {
|
if (config.startsWith("protobuf:")) {
|
||||||
try {
|
try {
|
||||||
final GdiSmartProto.Smart smart = GdiSmartProto.Smart.parseFrom(GB.hexStringToByteArray(config.replaceFirst("protobuf:", "")));
|
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) {
|
} catch (final Exception e) {
|
||||||
LOG.error("Failed to send {} as protobuf", config, 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) {
|
} else if (currentlyDownloading.getSyncFile() != null) {
|
||||||
LOG.debug("Will download file: {}/{}", currentlyDownloading.getSyncFile().getId().getId1(), currentlyDownloading.getSyncFile().getId().getId2());
|
LOG.debug("Will download file: {}/{}", currentlyDownloading.getSyncFile().getId().getId1(), currentlyDownloading.getSyncFile().getId().getId2());
|
||||||
|
|
||||||
sendOutgoingMessage(
|
sendProtobufRequest("request file",
|
||||||
"request file",
|
|
||||||
protocolBufferHandler.prepareProtobufRequest(
|
|
||||||
GdiSmartProto.Smart.newBuilder().setFileSyncService(
|
GdiSmartProto.Smart.newBuilder().setFileSyncService(
|
||||||
protocolBufferHandler.getFileSyncServiceHandler().requestFile(currentlyDownloading.getSyncFile())
|
protocolBufferHandler.getFileSyncServiceHandler().requestFile(currentlyDownloading.getSyncFile())
|
||||||
).build()
|
).build());
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Unexpected FileToDownload");
|
LOG.error("Unexpected FileToDownload");
|
||||||
}
|
}
|
||||||
@@ -982,7 +967,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enableBatteryLevelUpdate() {
|
private void enableBatteryLevelUpdate() {
|
||||||
final ProtobufMessage batteryLevelProtobufRequest = protocolBufferHandler.prepareProtobufRequest(GdiSmartProto.Smart.newBuilder()
|
sendProtobufRequest("enable battery updates", GdiSmartProto.Smart.newBuilder()
|
||||||
.setDeviceStatusService(
|
.setDeviceStatusService(
|
||||||
GdiDeviceStatus.DeviceStatusService.newBuilder()
|
GdiDeviceStatus.DeviceStatusService.newBuilder()
|
||||||
.setRemoteDeviceBatteryStatusRequest(
|
.setRemoteDeviceBatteryStatusRequest(
|
||||||
@@ -990,7 +975,6 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.build());
|
.build());
|
||||||
sendOutgoingMessage("enable battery updates", batteryLevelProtobufRequest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendDeviceSettings() {
|
private void sendDeviceSettings() {
|
||||||
@@ -1019,11 +1003,8 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
GdiFindMyWatch.FindMyWatchService.FindMyWatchCancelRequest.newBuilder()
|
GdiFindMyWatch.FindMyWatchService.FindMyWatchCancelRequest.newBuilder()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final ProtobufMessage findMyWatch = protocolBufferHandler.prepareProtobufRequest(
|
sendProtobufRequest("find device",
|
||||||
GdiSmartProto.Smart.newBuilder()
|
GdiSmartProto.Smart.newBuilder().setFindMyWatchService(a).build());
|
||||||
.setFindMyWatchService(a).build());
|
|
||||||
|
|
||||||
sendOutgoingMessage("find device", findMyWatch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1255,12 +1236,10 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
GarminUtils.toLocationData(location, GdiCore.CoreService.DataType.REALTIME_TRACKING)
|
GarminUtils.toLocationData(location, GdiCore.CoreService.DataType.REALTIME_TRACKING)
|
||||||
);
|
);
|
||||||
|
|
||||||
final ProtobufMessage locationUpdatedNotificationRequest = protocolBufferHandler.prepareProtobufRequest(
|
sendProtobufRequest("set gps location",
|
||||||
GdiSmartProto.Smart.newBuilder().setCoreService(
|
GdiSmartProto.Smart.newBuilder().setCoreService(
|
||||||
GdiCore.CoreService.newBuilder().setLocationUpdatedNotification(locationUpdatedNotification)
|
GdiCore.CoreService.newBuilder().setLocationUpdatedNotification(locationUpdatedNotification)
|
||||||
).build()
|
).build());
|
||||||
);
|
|
||||||
sendOutgoingMessage("set gps location", locationUpdatedNotificationRequest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -1316,7 +1295,7 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
final String country = Locale.getDefault().getCountry();
|
final String country = Locale.getDefault().getCountry();
|
||||||
final String localeString = language + "_" + country.toUpperCase();
|
final String localeString = language + "_" + country.toUpperCase();
|
||||||
|
|
||||||
sendOutgoingMessage("get settings screen " + screenId, protocolBufferHandler.prepareProtobufRequest(
|
sendProtobufRequest("get settings screen " + screenId,
|
||||||
GdiSmartProto.Smart.newBuilder()
|
GdiSmartProto.Smart.newBuilder()
|
||||||
.setSettingsService(GdiSettingsService.SettingsService.newBuilder()
|
.setSettingsService(GdiSettingsService.SettingsService.newBuilder()
|
||||||
.setDefinitionRequest(
|
.setDefinitionRequest(
|
||||||
@@ -1325,18 +1304,16 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
.setUnk2(0)
|
.setUnk2(0)
|
||||||
.setLanguage(localeString.length() == 5 ? localeString : "en_US")
|
.setLanguage(localeString.length() == 5 ? localeString : "en_US")
|
||||||
)
|
)
|
||||||
).build()
|
).build());
|
||||||
));
|
|
||||||
|
|
||||||
sendOutgoingMessage("get settings state " + screenId, protocolBufferHandler.prepareProtobufRequest(
|
sendProtobufRequest("get settings state " + screenId,
|
||||||
GdiSmartProto.Smart.newBuilder()
|
GdiSmartProto.Smart.newBuilder()
|
||||||
.setSettingsService(GdiSettingsService.SettingsService.newBuilder()
|
.setSettingsService(GdiSettingsService.SettingsService.newBuilder()
|
||||||
.setStateRequest(
|
.setStateRequest(
|
||||||
GdiSettingsService.ScreenStateRequest.newBuilder()
|
GdiSettingsService.ScreenStateRequest.newBuilder()
|
||||||
.setScreenId(screenId)
|
.setScreenId(screenId)
|
||||||
)
|
)
|
||||||
).build()
|
).build());
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1481,12 +1458,8 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
|||||||
final GdiFileSyncService.FileSyncService syncedCommand = protocolBufferHandler.getFileSyncServiceHandler()
|
final GdiFileSyncService.FileSyncService syncedCommand = protocolBufferHandler.getFileSyncServiceHandler()
|
||||||
.markSynced(currentlyDownloading.getSyncFile());
|
.markSynced(currentlyDownloading.getSyncFile());
|
||||||
if (syncedCommand != null) {
|
if (syncedCommand != null) {
|
||||||
sendOutgoingMessage(
|
sendProtobufRequest("mark file as synced",
|
||||||
"mark file as synced",
|
GdiSmartProto.Smart.newBuilder().setFileSyncService(syncedCommand).build());
|
||||||
protocolBufferHandler.prepareProtobufRequest(
|
|
||||||
GdiSmartProto.Smart.newBuilder().setFileSyncService(syncedCommand).build()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user