Prevent preferences fragment from crashing when resuming.

It was assuming there is always a priv ext preference. However, we
remove the priv ext preference the first time the fragment is opened. In
these circumstances, the preference no longer exists, resulting in a
NPE.
This commit is contained in:
Peter Serwylo 2017-03-29 16:20:55 +11:00
parent 05f6f08832
commit 5ef5288e3a

View File

@ -215,6 +215,13 @@ public class PreferencesFragment extends PreferenceFragment
*/
private void initPrivilegedInstallerPreference() {
final CheckBoxPreference pref = (CheckBoxPreference) findPreference(Preferences.PREF_PRIVILEGED_INSTALLER);
// This code will be run each time the activity is resumed, and so we may have already removed
// this preference.
if (pref == null) {
return;
}
Preferences p = Preferences.get();
boolean enabled = p.isPrivilegedInstallerEnabled();
boolean installed = PrivilegedInstaller.isExtensionInstalledCorrectly(getActivity())