Skip to content

Commit

Permalink
fix(networks): manage exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelje authored and Hector Rondon committed Jan 18, 2018
1 parent 6437c0d commit 160c240
Showing 1 changed file with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,41 @@ public int hashCode() {
public Networks(Context xCtx) {
super(xCtx);

WifiManager pWM = (WifiManager) xCtx.getSystemService(Service.WIFI_SERVICE);
boolean wasWifiEnabled = pWM.isWifiEnabled();

// Enable Wifi State if not
if (!wasWifiEnabled) {
pWM.setWifiEnabled(true);
}
Category c = new Category("NETWORKS", "networks");
c.put("TYPE", new CategoryValue(TYPE, "TYPE", "type"));

dhcp = pWM.getDhcpInfo();
wifi = pWM.getConnectionInfo();

FILog.d("<===WIFI DHCP===>");
FILog.d("dns1=" + StringUtils.intToIp(dhcp.dns1));
FILog.d("dns2=" + StringUtils.intToIp(dhcp.dns2));
FILog.d("leaseDuration=" + dhcp.leaseDuration);

c.put("MACADDR", new CategoryValue(getMacaddr(), "MACADDR", "macAddress"));
c.put("SPEED", new CategoryValue(getSpeed(), "SPEED", "speed"));
c.put("BSSID", new CategoryValue(getBSSID(), "BSSID", "bssid"));
c.put("SSID", new CategoryValue(getSSID(), "SSID", "ssid"));
c.put("IPGATEWAY", new CategoryValue(getIpgateway(), "IPGATEWAY", "ipGateway"));
c.put("IPADDRESS", new CategoryValue(getIpaddress(), "IPADDRESS", "ipAddress", true));
c.put("IPMASK", new CategoryValue(getIpmask(), "IPMASK", "ipMask", true));
c.put("IPDHCP", new CategoryValue(getIpdhcp(), "IPDHCP", "ipDhcp", true));

this.add(c);
// Restore Wifi State
if (!wasWifiEnabled) {
pWM.setWifiEnabled(false);
try {
WifiManager pWM = (WifiManager) xCtx.getSystemService(Service.WIFI_SERVICE);
boolean wasWifiEnabled = pWM.isWifiEnabled();

// Enable Wifi State if not
if (!wasWifiEnabled) {
pWM.setWifiEnabled(true);
}
Category c = new Category("NETWORKS", "networks");
c.put("TYPE", new CategoryValue(TYPE, "TYPE", "type"));

dhcp = pWM.getDhcpInfo();
wifi = pWM.getConnectionInfo();

FILog.d("<===WIFI DHCP===>");
FILog.d("dns1=" + StringUtils.intToIp(dhcp.dns1));
FILog.d("dns2=" + StringUtils.intToIp(dhcp.dns2));
FILog.d("leaseDuration=" + dhcp.leaseDuration);

c.put("MACADDR", new CategoryValue(getMacaddr(), "MACADDR", "macAddress"));
c.put("SPEED", new CategoryValue(getSpeed(), "SPEED", "speed"));
c.put("BSSID", new CategoryValue(getBSSID(), "BSSID", "bssid"));
c.put("SSID", new CategoryValue(getSSID(), "SSID", "ssid"));
c.put("IPGATEWAY", new CategoryValue(getIpgateway(), "IPGATEWAY", "ipGateway"));
c.put("IPADDRESS", new CategoryValue(getIpaddress(), "IPADDRESS", "ipAddress", true));
c.put("IPMASK", new CategoryValue(getIpmask(), "IPMASK", "ipMask", true));
c.put("IPDHCP", new CategoryValue(getIpdhcp(), "IPDHCP", "ipDhcp", true));

this.add(c);
// Restore Wifi State
if (!wasWifiEnabled) {
pWM.setWifiEnabled(false);
}
} catch (Exception ex) {
FILog.e(ex.getMessage());
}
}

Expand Down

0 comments on commit 160c240

Please sign in to comment.