prevent crash

pull/215/head
M66B 7 months ago
parent 70cac8ba14
commit f0b4472f03

@ -442,33 +442,43 @@ public class ConnectionHelper {
} }
static Boolean isPrivateDnsActive(Context context) { static Boolean isPrivateDnsActive(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) try {
return null; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class); return null;
if (cm == null) ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
return null; if (cm == null)
Network active = cm.getActiveNetwork(); return null;
if (active == null) Network active = cm.getActiveNetwork();
return null; if (active == null)
LinkProperties props = cm.getLinkProperties(active); return null;
if (props == null) LinkProperties props = cm.getLinkProperties(active);
if (props == null)
return null;
return props.isPrivateDnsActive();
} catch (Throwable ex) {
Log.e(ex);
return null; return null;
return props.isPrivateDnsActive(); }
} }
static String getPrivateDnsServerName(Context context) { static String getPrivateDnsServerName(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) try {
return null; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class); return null;
if (cm == null) ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
return null; if (cm == null)
Network active = cm.getActiveNetwork(); return null;
if (active == null) Network active = cm.getActiveNetwork();
return null; if (active == null)
LinkProperties props = cm.getLinkProperties(active); return null;
if (props == null) LinkProperties props = cm.getLinkProperties(active);
if (props == null)
return null;
return props.getPrivateDnsServerName();
} catch (Throwable ex) {
Log.e(ex);
return null; return null;
return props.getPrivateDnsServerName(); }
} }
static boolean isIoError(Throwable ex) { static boolean isIoError(Throwable ex) {

Loading…
Cancel
Save