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

Commit bf7865b2 authored by tom hsu's avatar tom hsu Committed by Tom Hsu
Browse files

[Settings] Fix crash when user enter bluetooth page quickly.

 - When SliceManager try to pinSlice, process may not have the permssion
   yet, so in Androix lib it use try/catch to avoid Security exception.
   However, if SliceManger quickly unpinSlice after pinSlice, process
   may still not get the permission yet, then due to no security
   exception, it cause the settings crash.

Bug: 283065718
Test: atest passed
Test: Manual test passed
Change-Id: I2293fca73e65dfaa34237abe57e0c6a3fe0f62bb
parent c4ed48cb
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");
        }
    }
}