Add null-guards for IP address.

This commit is contained in:
Bowie Chen
2019-10-29 21:17:56 +08:00
parent 7038b98122
commit 6e137dfd67
2 changed files with 12 additions and 4 deletions
@@ -320,6 +320,9 @@ public class FtpService extends Service implements Runnable {
Enumeration<InetAddress> addresses = netinterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
if (address == null) {
continue;
}
if(address.getHostAddress().startsWith(WIFI_AP_ADDRESS_PREFIX) && isEnabledWifiHotspot(context))
return address;
@@ -88,12 +88,17 @@ public class FtpNotification extends BroadcastReceiver {
InetAddress address = FtpService.getLocalInetAddress(context);
String iptext = (secureConnection ? FtpService.INITIALS_HOST_SFTP : FtpService.INITIALS_HOST_FTP)
+ address.getHostAddress() + ":"
+ port + "/";
String address_text = "Address not found";
if (address != null) {
address_text = (secureConnection ? FtpService.INITIALS_HOST_SFTP : FtpService.INITIALS_HOST_FTP)
+ address.getHostAddress() + ":"
+ port + "/";
}
NotificationCompat.Builder builder = buildNotification(context,
R.string.ftp_notif_title, context.getString(R.string.ftp_notif_text, iptext), noStopButton);
R.string.ftp_notif_title, context.getString(R.string.ftp_notif_text, address_text), noStopButton);
notificationManager.notify(NotificationConstants.FTP_ID, builder.build());
}