Skip to content

Commit

Permalink
alioth: parts: Prevent NPE before DiracSound is initialized
Browse files Browse the repository at this point in the history
There can be an edge case where the BOOT_COMPLETED intent is not
yet received and user tries to open Dirac sound settings. Avoid
letting it crash by making sure init is executed before showing the
preference screen.

Change-Id: I77e6bdd0c61994338f0dbbce4bfa532d84b8afb7
  • Loading branch information
bgcngm authored and Laulan56 committed Aug 15, 2022
1 parent 911585f commit 47fec87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 The LineageOS Project
* Copyright (C) 2018,2020 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
final ActionBar actionBar = getActivity().getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

DiracUtils.initialize(getActivity());
boolean enhancerEnabled = DiracUtils.isDiracEnabled();

mHeadsetType = (ListPreference) findPreference(PREF_HEADSET);
Expand Down
6 changes: 3 additions & 3 deletions parts/src/org/lineageos/settings/dirac/DiracUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 The LineageOS Project
* Copyright (C) 2018,2020 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,9 +28,9 @@ public final class DiracUtils {

public static void initialize(Context context) {
if (!mInitialized) {
mInitialized = true;
mContext = context;
mDiracSound = new DiracSound(0, 0);
mInitialized = true;
}
}

Expand All @@ -39,7 +39,7 @@ protected static void setMusic(boolean enable) {
}

protected static boolean isDiracEnabled() {
return mDiracSound.getMusic() == 1;
return mDiracSound != null && mDiracSound.getMusic() == 1;
}

protected static void setLevel(String preset) {
Expand Down

0 comments on commit 47fec87

Please sign in to comment.