|
4 | 4 | import android.util.JsonWriter;
|
5 | 5 |
|
6 | 6 | import java.io.IOException;
|
| 7 | +import java.net.InetAddress; |
7 | 8 | import java.util.ArrayList;
|
| 9 | +import java.util.Collections; |
8 | 10 | import java.util.Iterator;
|
9 | 11 | import java.util.List;
|
10 | 12 | import java.util.Map;
|
@@ -179,11 +181,6 @@ public DeviceConnection getFirstReachableConnection(String protocol) {
|
179 | 181 | return null;
|
180 | 182 | }
|
181 | 183 |
|
182 |
| - public void setReachable(int index) { |
183 |
| - DeviceConnections.get(index).setReachable(); |
184 |
| - compute_first_reachable(); |
185 |
| - } |
186 |
| - |
187 | 184 | /**
|
188 | 185 | * Set all device connections to not reachable, which match the given protocol.
|
189 | 186 | *
|
@@ -487,12 +484,31 @@ public String getFeatureString() {
|
487 | 484 | return f;
|
488 | 485 | }
|
489 | 486 |
|
| 487 | + public boolean isReachable() { |
| 488 | + if (!enabled) |
| 489 | + return false; |
| 490 | + for (DeviceConnection connection : DeviceConnections) { |
| 491 | + if (connection.isReachable()) |
| 492 | + return true; |
| 493 | + } |
| 494 | + return false; |
| 495 | + } |
| 496 | + |
| 497 | + public void setReachable(int index) { |
| 498 | + DeviceConnections.get(index).setReachable(); |
| 499 | + compute_first_reachable(); |
| 500 | + } |
| 501 | + |
490 | 502 | public String getNotReachableReasons() {
|
491 | 503 | if (!enabled)
|
492 | 504 | return NetpowerctrlApplication.instance.getString(R.string.error_device_disabled);
|
493 | 505 | String f = "";
|
494 |
| - for (DeviceConnection connection : DeviceConnections) |
495 |
| - f += connection.getNotReachableReason() + " "; |
| 506 | + for (DeviceConnection connection : DeviceConnections) { |
| 507 | + String a = connection.getNotReachableReason(); |
| 508 | + if (a != null) { |
| 509 | + f += a + " "; |
| 510 | + } |
| 511 | + } |
496 | 512 | return f;
|
497 | 513 | }
|
498 | 514 |
|
@@ -524,4 +540,27 @@ public void addConnection(DeviceConnection newConnection) {
|
524 | 540 | setReachable(DeviceConnections.size() - 1);
|
525 | 541 | }
|
526 | 542 | }
|
| 543 | + |
| 544 | + public InetAddress[] getHostnameIPs() { |
| 545 | + List<InetAddress> addresses = new ArrayList<>(); |
| 546 | + for (DeviceConnection connection : DeviceConnections) { |
| 547 | + Collections.addAll(addresses, connection.getHostnameIPs()); |
| 548 | + } |
| 549 | + |
| 550 | + InetAddress[] a = new InetAddress[addresses.size()]; |
| 551 | + addresses.toArray(a); |
| 552 | + return a; |
| 553 | + } |
| 554 | + |
| 555 | + public boolean hasAddress(InetAddress[] hostnameIPs) { |
| 556 | + if (hostnameIPs == null || hostnameIPs.length == 0) |
| 557 | + return false; |
| 558 | + |
| 559 | + for (DeviceConnection connection : DeviceConnections) { |
| 560 | + if (connection.hasAddress(hostnameIPs)) |
| 561 | + return true; |
| 562 | + } |
| 563 | + |
| 564 | + return false; |
| 565 | + } |
527 | 566 | }
|
0 commit comments