From cc1e4794c9f383d0fb49acb5502bdb2ab9a9f83a Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 19 Aug 2021 20:59:24 +0800 Subject: Catch SecurityException when getting network type. --- .../docilealligator/infinityforreddit/utils/Utils.java | 18 ++++++++++-------- app/src/main/res/layout/fragment_inbox.xml | 6 +++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 567f3afe..ad2b7405 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -220,15 +220,17 @@ public class Utils { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Network nw = connMgr.getActiveNetwork(); if (nw == null) return NETWORK_TYPE_OTHER; - NetworkCapabilities actNw = connMgr.getNetworkCapabilities(nw); - if (actNw != null) { - if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { - return NETWORK_TYPE_WIFI; - } - if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { - return NETWORK_TYPE_CELLULAR; + try { + NetworkCapabilities actNw = connMgr.getNetworkCapabilities(nw); + if (actNw != null) { + if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { + return NETWORK_TYPE_WIFI; + } + if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { + return NETWORK_TYPE_CELLULAR; + } } - } + } catch (SecurityException ignore) {} return NETWORK_TYPE_OTHER; } else { boolean isWifi = false; diff --git a/app/src/main/res/layout/fragment_inbox.xml b/app/src/main/res/layout/fragment_inbox.xml index 3fcaecbf..7b45b676 100644 --- a/app/src/main/res/layout/fragment_inbox.xml +++ b/app/src/main/res/layout/fragment_inbox.xml @@ -1,5 +1,5 @@ - @@ -43,4 +43,4 @@ - \ No newline at end of file + \ No newline at end of file -- cgit v1.2.3