The network page within the system tray provides the user visibility into the available networks and provides a convenient entrypoint for connecting to a new network, or viewing the details of an existing network. The VPN page within the system tray provides similar functionality, except this page is concerned with VPNs instead of networks.
The network and VPN concepts are very similar in code and both of their pages within the system tray share a similar structure. The code within this directory was written with these similarities in mind, and much of it is shared between the two distinct pages.
At a high-level, there are three different categories of classes:
The class hierarchy of the views used for the network and VPN pages has many different layers. These different layers are a result of:
While complicated, the end result is that testing each class in isolation is trivial and it becomes possible to introduce comprehensive test coverage for this directory.
NetworkDetailedView └─NetworkDetailedNetworkView ├─FakeNetworkDetailedNetworkView └─NetworkDetailedNetworkViewImpl NetworkListItemView └─NetworkListNetworkItemView NetworkListHeaderView └─NetworkListNetworkHeaderView ├─FakeNetworkListNetworkHeaderView ├─NetworkListMobileHeaderView ├─NetworkListTetherHostsHeaderView └─NetworkListWifiHeaderView
The NetworkDetailedView
class is the top-level view used for the network page and intended to be used by the VPN page. This class implements much of the core, shared logic such as creating the “info” or “settings” buttons shown in the top-right of the pages.
The NetworkDetailedView
class defines a Delegate
class, and accepts an instance of this Delegate
class in its constructor. This pattern allows the view to notify its delegate, in this case implemented by a controller, to be capable of notifying when a network or VPN is selected.
The NetworkDetailedNetworkView
class defines the interface used to interact with the network page. This class inherits from NetworkDetailedView
but includes additional logic that is only applicable to networks, such as APIs to create a WiFi network row or show the WiFi scanning bar. This class is abstract to improve testability and is implemented by NetworkDetailedNetworkViewImpl
. The NetworkDetailedNetworkView
class defines a Delegate
class that extends NetworkDetailedView::Delegate
to include network-specific logic, such as when WiFi is enabled or disabled.
The primary responsibility of this class is to provide the APIs to create the different views needed for the network page, and to own the different views needed for the network page. Most of the logic required to update the network page is delegated to different controllers.
The NetworkListItemView
is an abstract class intended to define the interface used for the individual network and VPN items within the lists of the network and VPN pages. This view can only be updated by using its UpdateViewForNetwork
API and providing it updated network or VPN information.
The NetworkListNetworkItemView
extends NetworkListItemView
to implement all of the logic needed by individual network items with in the list on the network page.
The NetworkListHeaderView
defines the interface of the “header” views used in the network and VPN pages. These header views are used to denote the beginning of a section within these pages, such as the WiFi section or the list of VPNs for a specific provider.
The NetworkListNetworkHeaderView
class extends NetworkListHeaderView
to implement additional logic and provide additional APIs that are specific to headers within the network page. For example, the network section has a toggle in each header that can be used to enable and disable the corresponding technology. The VPN page does not have these toggles.
This class defines additional APIs that are used to control the state of the toggles, including whether it is on, enabled, and visible.
The NetworkListMobileHeaderView
, NetworkListTetherHostsHeaderView
, and NetworkListWifiHeaderView
classes all extend the NetworkListNetworkHeaderView
class and implement additional functionality that is specific to their section e.g., Cellular, Tether Hosts, or WiFi.
The controller logic required by the network and VPN pages has been split into different classes to improve testability. At a high level, we use one controller to manage the entire page and we use a second controller to manage the list of networks or VPNs within that page.
NetworkListViewController └─NetworkListViewControllerImpl NetworkDetailedViewController
The NetworkListViewController
class defines the interface of the class responsible for managing the list of networks within the network page. This class provides minimal APIs and exists to improve testability; this class is instantiated using by the Factory
class that it defines, allowing tests to use fake implementations of NetworkListviewController
. This class is implemented by NetworkListViewControllerImpl
and contains all of the logic to ensure the list of networks and network technologies in the network page are updated.
This class observes the network data model, TrayNetworkStateModel
, and uses the information provided to update the network page. This class will reorder views if possible and will ensure that any network changes are propagated to the corresponding NetworkListNetworkItemView
.
When new networks are added or new technologies become available, the NetworkListViewController
class will leverage the APIs provided by the NetworkDetailedNetworkView
class to instantiate headers or network items.
The NetworkDetailedViewController
is responsible for the creation and management of the NetworkDetailedNetworkView
and NetworkListViewController
classes. This class implements the logic to handle networks being selected from the network list and to handle technologies being enabled or disabled.