Skip to content

Commit 162f0ce

Browse files
Added check on connection status
Signed-off-by: pierantoniomerlino <pierantonio.merlino@eurotech.com>
1 parent f98d351 commit 162f0ce

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/ModemTaskScheduler.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public ModemTaskScheduler(String deviceId, Device device, NetworkProperties prop
6565
}
6666

6767
public void scheduleConnection() {
68-
if (isModemConnected()) {
68+
if (isModemConnectedAndConnectionActivated()) {
6969
logger.info("Connection for modem {} successful", this.deviceId);
7070
return;
7171
}
@@ -84,7 +84,7 @@ private void tryConnection(int attemptNumber) {
8484
if (this.nmDbusConnector.isPresent()) {
8585
this.nmDbusConnector.get().apply(deviceId);
8686
}
87-
if (isModemConnected()) {
87+
if (isModemConnectedAndConnectionActivated()) {
8888
logger.info("Connection for modem {} successful", this.deviceId);
8989
if (this.connectionHandler != null) {
9090
this.connectionHandler.cancel(true);
@@ -112,14 +112,14 @@ private void scheduleConnectInternal(int attemptNumber) {
112112
}
113113

114114
public void scheduleReset() {
115-
if (isResetScheduled.get() || this.resetDelayMinutes <= 0 || isModemConnected()) {
115+
if (isResetScheduled.get() || this.resetDelayMinutes <= 0 || isModemConnectedAndConnectionActivated()) {
116116
return;
117117
}
118118
logger.info("Schedule reset for modem {} with path {}", this.deviceId, this.device.getObjectPath());
119119
this.isResetScheduled.set(true);
120120
this.resetHandler = this.scheduler.schedule(() -> {
121121
try {
122-
if (!isModemConnected()) {
122+
if (!isModemConnectedAndConnectionActivated()) {
123123
if (this.connectionHandler != null) {
124124
this.connectionHandler.cancel(true);
125125
}
@@ -170,17 +170,19 @@ protected boolean isResetScheduled() {
170170
return this.isResetScheduled.get();
171171
}
172172

173-
private boolean isModemConnected() {
173+
private boolean isModemConnectedAndConnectionActivated() {
174174
boolean isConnected = false;
175+
boolean isActivated = false;
175176
try {
176177
if (this.nmDbusConnector.isPresent()) {
177178
isConnected = this.nmDbusConnector.get().isModemConnected(this.device);
179+
isActivated = this.nmDbusConnector.get().isConnectionActivated(this.device);
178180
}
179181
} catch (DBusException e) {
180182
logger.warn("Could not get modem connection status for modem {} with path {} because: ", this.deviceId,
181183
this.device.getObjectPath(), e);
182184
}
183-
return isConnected;
185+
return isConnected && isActivated;
184186
}
185187

186188
protected void setNMDBusConnector(NMDbusConnector nmDbusConnector) {

kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/NMDbusConnector.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -734,13 +734,7 @@ private List<String> getNMModemsPaths() {
734734
}
735735

736736
private Optional<String> getNMModemPath(Device device) throws DBusException {
737-
Optional<String> mmDbusPath = Optional.empty();
738-
739-
if (networkManager.getDeviceType(device.getObjectPath()).equals(NMDeviceType.NM_DEVICE_TYPE_MODEM)) {
740-
mmDbusPath = this.networkManager.getModemManagerDbusPath(device.getObjectPath());
741-
}
742-
743-
return mmDbusPath;
737+
return this.networkManager.getModemManagerDbusPath(device.getObjectPath());
744738
}
745739

746740
public boolean isModemConnected(Device modemDevice) throws DBusException {
@@ -758,6 +752,11 @@ public boolean isModemConnected(Device modemDevice) throws DBusException {
758752
return MMModemState.MM_MODEM_STATE_CONNECTED.equals(modemState);
759753
}
760754

755+
public boolean isConnectionActivated(Device device) throws DBusException {
756+
NMDeviceState deviceState = this.networkManager.getDeviceState(device);
757+
return NMDeviceState.NM_DEVICE_STATE_ACTIVATED.equals(deviceState);
758+
}
759+
761760
public Optional<Modem> getModem(Device device) throws DBusException {
762761
Optional<Modem> modem = Optional.empty();
763762
Optional<String> mmDbusPath = getNMModemPath(device);

kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/ModemTaskSchedulerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public void shouldResetIfResetIsScheduled() throws DBusException {
163163
private void givenNMDbusConnectorMock(boolean isConnectedFirstCall, boolean isConnectedSecondCall)
164164
throws DBusException {
165165
this.nmDbusConnector = mock(NMDbusConnector.class);
166+
when(this.nmDbusConnector.isConnectionActivated(any())).thenReturn(isConnectedFirstCall)
167+
.thenReturn(isConnectedSecondCall);
166168
when(this.nmDbusConnector.isModemConnected(any())).thenReturn(isConnectedFirstCall)
167169
.thenReturn(isConnectedSecondCall);
168170
this.modem = mock(Modem.class);

0 commit comments

Comments
 (0)