add null checks to huawei settings code

This commit is contained in:
Daniel Gultsch 2018-02-09 22:11:11 +01:00
parent af81bb1958
commit d33fca09cf

View file

@ -101,11 +101,13 @@ public class SettingsActivity extends XmppActivity implements
//this feature is only available on Huawei Android 6. //this feature is only available on Huawei Android 6.
PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei"); PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei");
Intent intent = huaweiPreferenceScreen.getIntent(); if (huaweiPreferenceScreen != null) {
//remove when Api version is above M (Version 6.0) or if the intent is not callable Intent intent = huaweiPreferenceScreen.getIntent();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) { //remove when Api version is above M (Version 6.0) or if the intent is not callable
PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general"); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) {
generalCategory.removePreference(huaweiPreferenceScreen); PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general");
generalCategory.removePreference(huaweiPreferenceScreen);
}
} }
boolean removeLocation = new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null; 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) { private boolean isCallable(final Intent i) {
return getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0; return i != null && getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
} }