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

Commit 5d14fd7b authored by Sundeep Ghuman's avatar Sundeep Ghuman
Browse files

Safeguard against NPE race condition.

It is possible for the main activity to be quit before the posted
message is executed, safeguard against NPEs in this scenario.

Bug: 73484470
Test: runtest --path frameworks/base/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.jav
Change-Id: I34b40089ef2eae213c804e4e379d6ab7825bbceb
parent f6965c9c
Loading
Loading
Loading
Loading
+26 −11
Original line number Diff line number Diff line
@@ -1048,14 +1048,19 @@ public class AccessPoint implements Comparable<AccessPoint> {
        if (newLevel > 0 && newLevel != oldLevel) {
            // Only update labels on visible rssi changes
            updateSpeed();
            ThreadUtils.postOnMainThread(() -> {
                if (mAccessPointListener != null) {
                ThreadUtils.postOnMainThread(() -> mAccessPointListener.onLevelChanged(this));
                    mAccessPointListener.onLevelChanged(this);
                }
            });

        }

        ThreadUtils.postOnMainThread(() -> {
            if (mAccessPointListener != null) {
            ThreadUtils.postOnMainThread(() -> mAccessPointListener.onAccessPointChanged(this));
                mAccessPointListener.onAccessPointChanged(this);
            }
        });

        if (!scanResults.isEmpty()) {
            ScanResult result = scanResults.iterator().next();
@@ -1102,10 +1107,18 @@ public class AccessPoint implements Comparable<AccessPoint> {
            mNetworkInfo = null;
        }
        if (updated && mAccessPointListener != null) {
            ThreadUtils.postOnMainThread(() -> mAccessPointListener.onAccessPointChanged(this));
            ThreadUtils.postOnMainThread(() -> {
                if (mAccessPointListener != null) {
                    mAccessPointListener.onAccessPointChanged(this);
                }
            });

            if (oldLevel != getLevel() /* current level */) {
                ThreadUtils.postOnMainThread(() -> mAccessPointListener.onLevelChanged(this));
                ThreadUtils.postOnMainThread(() -> {
                    if (mAccessPointListener != null) {
                        mAccessPointListener.onLevelChanged(this);
                    }
                });
            }
        }

@@ -1115,9 +1128,11 @@ public class AccessPoint implements Comparable<AccessPoint> {
    void update(@Nullable WifiConfiguration config) {
        mConfig = config;
        networkId = config != null ? config.networkId : WifiConfiguration.INVALID_NETWORK_ID;
        ThreadUtils.postOnMainThread(() -> {
            if (mAccessPointListener != null) {
            ThreadUtils.postOnMainThread(() -> mAccessPointListener.onAccessPointChanged(this));
                mAccessPointListener.onAccessPointChanged(this);
            }
        });
    }

    @VisibleForTesting