Skip to content

Commit

Permalink
fix(nm): avoid error when Modem.Location interface is missing [back…
Browse files Browse the repository at this point in the history
…port release-5.3.0] (#4522)

fix(nm): avoid error when `Modem.Location` interface is missing (#4516)

* fix(nm): avoid error when Modem.Location interface is missing

* fix: simplify logic

* fix: do not call Location.Setup if there's no location source available

* fix: change log level

(cherry picked from commit b01a813)

Co-authored-by: Mattia Dal Ben <[email protected]>
  • Loading branch information
github-actions[bot] and mattdibi authored Apr 4, 2023
1 parent 78c40bf commit d7b952d
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,22 @@ private void handleModemManagerGPSSetup(Device device, Optional<Boolean> enableG
Properties modemLocationProperties = this.dbusConnection.getRemoteObject(MM_BUS_NAME,
modemLocation.getObjectPath(), Properties.class);

Set<MMModemLocationSource> availableLocationSources = MMModemLocationSource
.toMMModemLocationSourceFromBitMask(modemLocationProperties.Get(MM_LOCATION_BUS_NAME, "Capabilities"));
Set<MMModemLocationSource> currentLocationSources = MMModemLocationSource
.toMMModemLocationSourceFromBitMask(modemLocationProperties.Get(MM_LOCATION_BUS_NAME, "Enabled"));
Set<MMModemLocationSource> availableLocationSources = EnumSet
.of(MMModemLocationSource.MM_MODEM_LOCATION_SOURCE_NONE);
Set<MMModemLocationSource> currentLocationSources = EnumSet
.of(MMModemLocationSource.MM_MODEM_LOCATION_SOURCE_NONE);

try {
availableLocationSources = MMModemLocationSource.toMMModemLocationSourceFromBitMask(
modemLocationProperties.Get(MM_LOCATION_BUS_NAME, "Capabilities"));
currentLocationSources = MMModemLocationSource
.toMMModemLocationSourceFromBitMask(modemLocationProperties.Get(MM_LOCATION_BUS_NAME, "Enabled"));
} catch (DBusExecutionException e) {
logger.warn("Cannot retrive Modem.Location capabilities for {}. Caused by: ",
modemLocationProperties.getObjectPath(), e);
return;
}

EnumSet<MMModemLocationSource> managedLocationSources = EnumSet.of(
MMModemLocationSource.MM_MODEM_LOCATION_SOURCE_GPS_RAW,
MMModemLocationSource.MM_MODEM_LOCATION_SOURCE_GPS_NMEA);
Expand All @@ -467,7 +479,10 @@ private void handleModemManagerGPSSetup(Device device, Optional<Boolean> enableG

logger.debug("Modem location setup {} for modem {}", currentLocationSources, modemDevicePath.get());

modemLocation.Setup(MMModemLocationSource.toBitMaskFromMMModemLocationSource(currentLocationSources), false);
if (!currentLocationSources.contains(MMModemLocationSource.MM_MODEM_LOCATION_SOURCE_NONE)) {
modemLocation.Setup(MMModemLocationSource.toBitMaskFromMMModemLocationSource(currentLocationSources),
false);
}
}

private String getDeviceId(Device device) throws DBusException {
Expand Down

0 comments on commit d7b952d

Please sign in to comment.