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

Commit 3e374cc7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Settings] Fix crash when user enter bluetooth page quickly." into udc-dev

parents 832e0b01 bf7865b2
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -113,15 +113,27 @@ public class BlockingPrefWithSliceController extends BasePreferenceController im

    @Override
    public void onStart() {
        if (mLiveData != null) {
        if (mLiveData == null) {
            return;
        }

        try {
            mLiveData.observeForever(this);
        } catch (SecurityException e) {
            Log.w(TAG, "observeForever - no permission");
        }
    }

    @Override
    public void onStop() {
        if (mLiveData != null) {
        if (mLiveData == null) {
            return;
        }

        try {
            mLiveData.removeObserver(this);
        } catch (SecurityException e) {
            Log.w(TAG, "removeObserver - no permission");
        }
    }

+14 −5
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ public class SlicePreferenceController extends BasePreferenceController implemen
    LiveData<Slice> mLiveData;
    @VisibleForTesting
    SlicePreference mSlicePreference;
    private boolean mIsObservering = false;
    private Uri mUri;

    public SlicePreferenceController(Context context, String preferenceKey) {
@@ -74,9 +73,14 @@ public class SlicePreferenceController extends BasePreferenceController implemen

    @Override
    public void onStart() {
        if (mLiveData != null && !mIsObservering) {
            mIsObservering = true;
        if (mLiveData == null) {
            return;
        }

        try {
            mLiveData.observeForever(this);
        } catch (SecurityException e) {
            Log.w(TAG, "observeForever - no permission");
        }
    }

@@ -91,9 +95,14 @@ public class SlicePreferenceController extends BasePreferenceController implemen
    }

    private void removeLiveDataObserver() {
        if (mLiveData != null && mIsObservering && mLiveData.hasActiveObservers()) {
            mIsObservering = false;
        if (mLiveData == null) {
            return;
        }

        try {
            mLiveData.removeObserver(this);
        } catch (SecurityException e) {
            Log.w(TAG, "removeLiveDataObserver - no permission");
        }
    }
}