Commit 8ad87b4b authored by Sinan Sahin's avatar Sinan Sahin Committed by Commit Bot

[Offline indicator v2] Fix NullPointerException

After switching themes (dark/light), the ConnectivityDetector instance
would not be destroyed since it's added as an observer to the
NetworkChangeNotifier singleton. This was keeping a lot of objects
around and causing invalid status indicator instances to access a null
activity reference through a lambda created in TabbedRootUiCoordinator.

This CL adds a #destroy method to ConnectivityDetector and a call to
it from OfflineIndicatorControllerV2#destroy().

Bug: 1070386
Change-Id: Iee7a9cb913fa8aa62960f602e6f45242e0cc60e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2150026Reviewed-by: default avatarJian Li <jianli@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Sinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#759357}
parent 679fc79e
...@@ -228,6 +228,10 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp ...@@ -228,6 +228,10 @@ public class ConnectivityDetector implements NetworkChangeNotifier.ConnectionTyp
detect(); detect();
} }
public void destroy() {
NetworkChangeNotifier.removeConnectionTypeObserver(this);
}
public void detect() { public void detect() {
onConnectionTypeChanged(NetworkChangeNotifier.getInstance().getCurrentConnectionType()); onConnectionTypeChanged(NetworkChangeNotifier.getInstance().getCurrentConnectionType());
} }
......
...@@ -73,6 +73,9 @@ public class OfflineIndicatorControllerV2 implements ConnectivityDetector.Observ ...@@ -73,6 +73,9 @@ public class OfflineIndicatorControllerV2 implements ConnectivityDetector.Observ
} }
public void destroy() { public void destroy() {
mConnectivityDetector = null; if (mConnectivityDetector != null) {
mConnectivityDetector.destroy();
mConnectivityDetector = null;
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment