From d33fca09cfdfc0f3f2cffa982b2ae46fe6af0c44 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 9 Feb 2018 22:11:11 +0100 Subject: [PATCH] add null checks to huawei settings code --- .../siacs/conversations/ui/SettingsActivity.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index c5f1b0314..d8c9b7675 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -101,11 +101,13 @@ public class SettingsActivity extends XmppActivity implements //this feature is only available on Huawei Android 6. PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei"); - Intent intent = huaweiPreferenceScreen.getIntent(); - //remove when Api version is above M (Version 6.0) or if the intent is not callable - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) { - PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general"); - generalCategory.removePreference(huaweiPreferenceScreen); + if (huaweiPreferenceScreen != null) { + Intent intent = huaweiPreferenceScreen.getIntent(); + //remove when Api version is above M (Version 6.0) or if the intent is not callable + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) { + PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general"); + generalCategory.removePreference(huaweiPreferenceScreen); + } } boolean removeLocation = new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null; @@ -232,8 +234,8 @@ public class SettingsActivity extends XmppActivity implements }); } - private boolean isCallable(Intent intent) { - return getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0; + private boolean isCallable(final Intent i) { + return i != null && getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY).size() > 0; }