Skip to content

Commit

Permalink
[CrOS Cellular] Add ManagedCellularProperties property to apn-subpage
Browse files Browse the repository at this point in the history
* Add NetworkListenerBegavior and RouteObserverBehavior to apn-subpage.
* Update ManagedCellularProperties when NetworkState is changed.
* Add FakeNetworkConfig to apn-subpage tests.
* Implement apn-list getApns_ function that returns an array of
all the APNs that must be shown in the correct order.

Test: --gtest_filter=*ApnList* && --gtest_filter=*ApnSubpage*
Bug: b:162365553
Change-Id: I953e8cbb5d4e2f03df690205af14d12d46a2b045
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4022123
Reviewed-by: Chad Duffin <chadduffin@chromium.org>
Commit-Queue: Antoni Dikov <adikov@google.com>
Cr-Commit-Position: refs/heads/main@{#1075235}
  • Loading branch information
Antoni Dikov authored and Chromium LUCI CQ committed Nov 23, 2022
1 parent 3716507 commit 5ce14a5
Show file tree
Hide file tree
Showing 12 changed files with 519 additions and 78 deletions.
3 changes: 3 additions & 0 deletions ash/webui/common/resources/network/BUILD.gn
Expand Up @@ -70,8 +70,10 @@ js_library("cr_policy_network_indicator_mojo") {

js_library("apn_list") {
deps = [
":onc_mojo",
"//ash/webui/common/resources:i18n_behavior",
"//ash/webui/common/resources/network:apn_list_item",
"//chromeos/services/network_config/public/mojom:mojom_webui_js",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/js:load_time_data.m",
]
Expand All @@ -81,6 +83,7 @@ js_library("apn_list") {
js_library("apn_list_item") {
deps = [
"//ash/webui/common/resources:i18n_behavior",
"//chromeos/services/network_config/public/mojom:mojom_webui_js",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/js:load_time_data.m",
]
Expand Down
8 changes: 6 additions & 2 deletions ash/webui/common/resources/network/apn_list.html
Expand Up @@ -35,8 +35,12 @@
</div>
</template>
</div>
<iron-list items="[[apns]]">

<iron-list items="[[getApns_(managedCellularProperties)]]">
<template>
<apn-list-item apn="[[item]]"></apn-list-item>
<apn-list-item
apn="[[item]]"
is-connected="[[isApnConnected_(index)]]">
</apn-list-item>
</template>
</iron-list>
41 changes: 37 additions & 4 deletions ash/webui/common/resources/network/apn_list.js
Expand Up @@ -14,6 +14,8 @@ import 'chrome://resources/ash/common/network/apn_list_item.js';

import {I18nBehavior} from '//resources/ash/common/i18n_behavior.js';
import {Polymer} from '//resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {OncMojo} from 'chrome://resources/ash/common/network/onc_mojo.js';
import {ApnProperties, ApnState, ManagedCellularProperties} from 'chrome://resources/mojo/chromeos/services/network_config/public/mojom/cros_network_config.mojom-webui.js';

import {getTemplate} from './apn_list.html.js';

Expand All @@ -24,10 +26,9 @@ Polymer({
behaviors: [I18nBehavior],

properties: {
// TODO(b/162365553): Populate with real data and remove dummy values.
apns: {
type: Array,
value: [{name: 'apn1'}, {name: 'apn2'}, {name: 'apn3'}],
/**@type {!ManagedCellularProperties}*/
managedCellularProperties: {
type: Object,
},

shouldOmitLinks: {
Expand All @@ -36,6 +37,38 @@ Polymer({
},
},

/**
* Returns an array with all the APN properties that need to be displayed.
* TODO(b/162365553): Implement logic for customApnList.
* TODO(b/162365553): Handle managedCellularProperties.apnList.policyValue
* when policies are included.
* @return {Array<!ApnProperties>}
* @private
*/
getApns_() {
if (!this.managedCellularProperties) {
return [];
}

const connectedApn = this.managedCellularProperties.connectedApn;
if (connectedApn) {
return [connectedApn];
}
// TODO(b/162365553): Handle the case when there is no connected APN.
return [];
},

/**
* Returns true if the APN on this index is connected.
* @param {number} index index in the APNs array.
* @return {boolean}
* @private
*/
isApnConnected_(index) {
return !!this.managedCellularProperties &&
!!this.managedCellularProperties.connectedApn && index === 0;
},

/**
* Redirects to "Lean more about APN" page.
* TODO(b/162365553): Implement.
Expand Down
3 changes: 2 additions & 1 deletion ash/webui/common/resources/network/apn_list_item.js
Expand Up @@ -11,6 +11,7 @@ import 'chrome://resources/cr_elements/cr_action_menu/cr_action_menu.js';

import {I18nBehavior} from '//resources/ash/common/i18n_behavior.js';
import {Polymer} from '//resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {ApnProperties} from 'chrome://resources/mojo/chromeos/services/network_config/public/mojom/cros_network_config.mojom-webui.js';

import {getTemplate} from './apn_list_item.html.js';

Expand All @@ -21,7 +22,7 @@ Polymer({
behaviors: [I18nBehavior],

properties: {
// TODO(b/162365553): Add type annotations for apn property.
/**@type {!ApnProperties}*/
apn: {
type: Object,
},
Expand Down
56 changes: 56 additions & 0 deletions ash/webui/common/resources/network/cellular_utils.js
Expand Up @@ -5,6 +5,7 @@
import 'chrome://resources/ash/common/network/onc_mojo.js';

import {MojoInterfaceProviderImpl} from 'chrome://resources/ash/common/network/mojo_interface_provider.js';
import {OncMojo} from 'chrome://resources/ash/common/network/onc_mojo.js';
import {DeviceStateProperties, FilterType, NetworkStateProperties, NO_LIMIT} from 'chrome://resources/mojo/chromeos/services/network_config/public/mojom/cros_network_config.mojom-webui.js';
import {ConnectionStateType, NetworkType} from 'chrome://resources/mojo/chromeos/services/network_config/public/mojom/network_types.mojom-webui.js';

Expand Down Expand Up @@ -96,3 +97,58 @@ export function isActiveSim(networkState, deviceState) {
});
return !!isActiveSim;
}

/**
* Returns true if all significant DeviceState fields match. Ignores
* |scanning| which can be noisy and is handled separately.
* @param {!OncMojo.DeviceStateProperties} a
* @param {!OncMojo.DeviceStateProperties} b
* @return {boolean}
*/
export function deviceStatesMatch(a, b) {
return a.type === b.type && a.macAddress === b.macAddress &&
a.simAbsent === b.simAbsent && a.deviceState === b.deviceState &&
a.managedNetworkAvailable === b.managedNetworkAvailable &&
OncMojo.ipAddressMatch(a.ipv4Address, b.ipv4Address) &&
OncMojo.ipAddressMatch(a.ipv6Address, b.ipv6Address) &&
OncMojo.simLockStatusMatch(a.simLockStatus, b.simLockStatus) &&
OncMojo.simInfosMatch(a.simInfos, b.simInfos) &&
a.inhibitReason === b.inhibitReason;
}

/**
* @param {!NetworkType} type
* @param {!Array<!DeviceStateProperties>} devices
* @param {?OncMojo.DeviceStateProperties} deviceState
* @return {{deviceState: OncMojo.DeviceStateProperties,
* shouldGetNetworkDetails: boolean}}
*/
export function processDeviceState(type, devices, deviceState) {
const newDeviceState = devices.find(device => device.type === type) || null;
let shouldGetNetworkDetails = false;
if (!deviceState || !newDeviceState) {
deviceState = /**@type {?OncMojo.DeviceStateProperties}*/ (newDeviceState);
shouldGetNetworkDetails = !!deviceState;
} else if (!deviceStatesMatch(deviceState, newDeviceState)) {
// Only request a network state update if the deviceState changed.
shouldGetNetworkDetails =
deviceState.deviceState !== newDeviceState.deviceState;
deviceState = /**@type {?OncMojo.DeviceStateProperties}*/ (newDeviceState);
} else if (deviceState.scanning !== newDeviceState.scanning) {
// Update just the scanning state to avoid interrupting other parts of
// the UI (e.g. custom IP addresses or nameservers).
deviceState.scanning = newDeviceState.scanning;
// Cellular properties are not updated while scanning (since they
// may be invalid), so request them on scan completion.
if (type === NetworkType.kCellular) {
shouldGetNetworkDetails = true;
}
} else if (type === NetworkType.kCellular) {
// If there are no device state property changes but type is
// cellular, then always fetch network details. This is because
// for cellular networks, some shill device level properties are
// represented at network level in ONC.
shouldGetNetworkDetails = true;
}
return {deviceState, shouldGetNetworkDetails};
}
Expand Up @@ -41,7 +41,16 @@ js_type_check("closure_compile_module") {
js_library("apn_subpage") {
deps = [
"//ash/webui/common/resources/network:apn_list",
"//ash/webui/common/resources/network:cellular_utils",
"//ash/webui/common/resources/network:mojo_interface_provider",
"//ash/webui/common/resources/network:network_listener_behavior",
"//ash/webui/common/resources/network:onc_mojo",
"//chrome/browser/resources/settings:router",
"//chrome/browser/resources/settings/chromeos:route_observer_behavior",
"//chromeos/services/network_config/public/mojom:mojom_webui_js",
"//chromeos/services/network_config/public/mojom:network_types_webui_js",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/js:assert",
]

externs_list = []
Expand Down
@@ -1,3 +1,5 @@
<style include="settings-shared">
</style>
<apn-list></apn-list>
<apn-list
managed-cellular-properties="[[managedProperties_.typeProperties.cellular]]">
</apn-list>

0 comments on commit 5ce14a5

Please sign in to comment.