diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-08-19 12:59:24 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-08-19 12:59:24 +0000 |
commit | cc1e4794c9f383d0fb49acb5502bdb2ab9a9f83a (patch) | |
tree | 0dd764d731022e26762a5162cd244be092891340 | |
parent | e2cca45f555f3f6c0bc2bd6a671cad2bf7d12e2c (diff) | |
download | infinity-for-reddit-cc1e4794c9f383d0fb49acb5502bdb2ab9a9f83a.tar infinity-for-reddit-cc1e4794c9f383d0fb49acb5502bdb2ab9a9f83a.tar.gz infinity-for-reddit-cc1e4794c9f383d0fb49acb5502bdb2ab9a9f83a.tar.bz2 infinity-for-reddit-cc1e4794c9f383d0fb49acb5502bdb2ab9a9f83a.tar.lz infinity-for-reddit-cc1e4794c9f383d0fb49acb5502bdb2ab9a9f83a.tar.xz infinity-for-reddit-cc1e4794c9f383d0fb49acb5502bdb2ab9a9f83a.tar.zst infinity-for-reddit-cc1e4794c9f383d0fb49acb5502bdb2ab9a9f83a.zip |
Catch SecurityException when getting network type.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 18 | ||||
-rw-r--r-- | 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 @@ <?xml version="1.0" encoding="utf-8"?> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" @@ -22,7 +22,7 @@ android:id="@+id/fetch_messages_info_linear_layout_inbox_fragment" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_centerInParent="true" + android:layout_gravity="center" android:gravity="center" android:orientation="vertical" android:visibility="gone"> @@ -43,4 +43,4 @@ </LinearLayout> -</RelativeLayout>
\ No newline at end of file +</FrameLayout>
\ No newline at end of file |