Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f9b1084 authored by Bonian Chen's avatar Bonian Chen
Browse files

[Settings] Avoid from accessing LifecycleOwner when not available

Only access LifecycleOwner when available.

Bug: 266872811
Test: local

Change-Id: Id575a71e20e79f8efadb49af128c1a43c058acdd
parent 55753796
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -109,13 +109,19 @@ public class SimStatusPreferenceController extends BasePreferenceController {

    @Override
    public void updateState(Preference preference) {
        if (mFragment == null) {
            return;
        }
        final int simSlot = getSimSlotIndex();
        if (mSimChangeObserver == null) {
            mSimChangeObserver = x -> updateStateBySlot(preference, simSlot);
            mSlotSimStatus.observe(mFragment.getViewLifecycleOwner(), mSimChangeObserver);
        }
            mFragment.getViewLifecycleOwnerLiveData().observeForever(lifecycleOwner -> {
                mSlotSimStatus.observe(lifecycleOwner, mSimChangeObserver);
            });
        } else {
            updateStateBySlot(preference, simSlot);
        }
    }

    protected void updateStateBySlot(Preference preference, int simSlot) {
        SubscriptionInfo subInfo = getSubscriptionInfo(simSlot);