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

Commit 88cafbaa authored by Weng Su's avatar Weng Su
Browse files

[Provider Model] Fix settings crash issue

- The GlobalSettingsChangeListener needs to be closed after the life
cycle is destroyed

Bug: 185756174
Bug: 186404332
Bug: 186591527
Test: manual test
atest -c InternetUpdaterTest

Change-Id: I9fbad3b303055c6c7a61ccad8efe69cefef56c58
parent b4a9916a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;

import static androidx.lifecycle.Lifecycle.Event.ON_DESTROY;
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;

@@ -191,6 +192,12 @@ public class InternetUpdater implements AirplaneModeEnabler.OnAirplaneModeChange
        mContext.unregisterReceiver(mWifiStateReceiver);
    }

    /** @OnLifecycleEvent(ON_DESTROY) */
    @OnLifecycleEvent(ON_DESTROY)
    public void onDestroy() {
        mAirplaneModeEnabler.close();
    }

    @Override
    public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
        fetchActiveNetwork();
+7 −0
Original line number Diff line number Diff line
@@ -107,6 +107,13 @@ public class InternetUpdaterTest {
                any(ConnectivityManager.NetworkCallback.class));
    }

    @Test
    public void onDestroy_shouldCloseCallback() {
        mInternetUpdater.onDestroy();

        verify(mAirplaneModeEnabler).close();
    }

    @Test
    public void updateInternetAvailable_wifiConnectedAndNoValidated_internetUnavailable() {
        final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()