Skip to content

Commit 40bb099

Browse files
committed
MOBILE-4842 network: Simplify network type management
1 parent bd96f8a commit 40bb099

File tree

18 files changed

+90
-72
lines changed

18 files changed

+90
-72
lines changed

local_moodleappbehat/tests/behat/behat_app.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,15 +1179,16 @@ public function i_switch_offline_mode(string $offline) {
11791179
public function i_switch_network_connection(string $mode) {
11801180
switch ($mode) {
11811181
case 'wifi':
1182-
$this->runtime_js("network.setForceConnectionMode('$mode');");
1182+
$this->runtime_js("network.setForceConnectionMode('not_measured');");
11831183
break;
11841184
case 'cellular':
1185-
$this->runtime_js("network.setForceConnectionMode('$mode');");
1185+
$this->runtime_js("network.setForceConnectionMode('measured');");
11861186
break;
11871187
case 'offline':
1188-
$this->runtime_js("network.setForceConnectionMode('none');");
1188+
$this->runtime_js("network.setForceConnectionMode('offline');");
11891189
break;
11901190
default:
1191+
$this->runtime_js("network.setForceConnectionMode('unknown');");
11911192
break;
11921193
}
11931194
}

scripts/langindex.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,7 @@
25372537
"core.settings.loggedin": "message",
25382538
"core.settings.loggedoff": "message",
25392539
"core.settings.logintosync": "local_moodlemobileapp",
2540+
"core.settings.measuredconnection": "local_moodlemobileapp",
25402541
"core.settings.navigatorlanguage": "local_moodlemobileapp",
25412542
"core.settings.navigatoruseragent": "local_moodlemobileapp",
25422543
"core.settings.networkstatus": "local_moodlemobileapp",
@@ -2560,7 +2561,6 @@
25602561
"core.settings.synchronizenowhelp": "local_moodlemobileapp",
25612562
"core.settings.syncsettings": "local_moodlemobileapp",
25622563
"core.settings.total": "moodle",
2563-
"core.settings.wificonnection": "local_moodlemobileapp",
25642564
"core.settings.youradev": "local_moodlemobileapp",
25652565
"core.share": "moodle",
25662566
"core.sharedfiles.chooseaccountstorefile": "local_moodlemobileapp",

src/core/classes/sites/authenticated-site.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite {
15921592
let expirationDelay = CoreAuthenticatedSite.UPDATE_FREQUENCIES[updateFrequency] ||
15931593
CoreAuthenticatedSite.UPDATE_FREQUENCIES[CoreCacheUpdateFrequency.USUALLY];
15941594

1595-
if (CoreNetwork.isNetworkAccessLimited()) {
1595+
if (CoreNetwork.connectionIsMeasured()) {
15961596
// Not WiFi, increase the expiration delay a 50% to decrease the data usage in this case.
15971597
expirationDelay *= 1.5;
15981598
}

src/core/directives/external-content.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
518518
clickableEl.addEventListener(eventName, () => {
519519
// User played media or opened a downloadable link.
520520
// Download the file if in wifi and it hasn't been downloaded already (for big files).
521-
if (state !== DownloadStatus.DOWNLOADED && state !== DownloadStatus.DOWNLOADING && CoreNetwork.isWifi()) {
521+
if (state !== DownloadStatus.DOWNLOADED && state !== DownloadStatus.DOWNLOADING &&
522+
CoreNetwork.connectionIsNotMeasured()) {
522523
// We aren't using the result, so it doesn't matter which of the 2 functions we call.
523524
CoreFilepool.getUrlByUrl(site.getId(), url, this.component, this.componentId, 0, false);
524525
}

src/core/features/course/services/course-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ export class CoreCourseHelperProvider {
890890
}
891891

892892
// Start the download if in wifi, but return the URL right away so the file is opened.
893-
if (CoreNetwork.isWifi()) {
893+
if (CoreNetwork.connectionIsNotMeasured()) {
894894
this.downloadModule(module, courseId, component, componentId, files, siteId);
895895
}
896896

src/core/features/fileuploader/services/fileuploader-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class CoreFileUploaderHelperProvider {
140140

141141
if (size < 0) {
142142
return CoreAlerts.confirm(Translate.instant('core.fileuploader.confirmuploadunknownsize'));
143-
} else if (size >= wifiThreshold || (CoreNetwork.isNetworkAccessLimited() && size >= limitedThreshold)) {
143+
} else if (size >= wifiThreshold || (CoreNetwork.connectionIsMeasured() && size >= limitedThreshold)) {
144144
const readableSize = CoreText.bytesToSize(size, 2);
145145

146146
return CoreAlerts.confirm(Translate.instant('core.fileuploader.confirmuploadfile', { size: readableSize }));

src/core/features/settings/lang.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@
7979
"synchronizenowhelp": "Synchronising a site will send pending changes and all offline activity stored in the device and will synchronise some data like messages and notifications.",
8080
"syncsettings": "Synchronisation settings",
8181
"total": "Total",
82-
"wificonnection": "Wi-Fi connection",
82+
"measuredconnection": "Measured data connection",
8383
"youradev": "You are now a developer"
8484
}

src/core/features/settings/pages/deviceinfo/deviceinfo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ <h1>
148148
</ion-item>
149149
<ion-item (longPress)="copyItemInfo($event)">
150150
<ion-label class="ion-text-wrap">
151-
<p class="item-heading">{{ 'core.settings.wificonnection' | translate}}</p>
152-
@if (deviceInfo.wifiConnection()) {
151+
<p class="item-heading">{{ 'core.settings.measuredconnection' | translate}}</p>
152+
@if (deviceInfo.measuredConnection()) {
153153
<p>{{ 'core.yes' | translate }}</p>
154154
} @else {
155155
<p>{{ 'core.no' | translate }}</p>

src/core/features/settings/pages/deviceinfo/deviceinfo.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { CoreConfig } from '@services/config';
2525
import { CoreToasts } from '@services/overlays/toasts';
2626
import { CoreNavigator } from '@services/navigator';
2727
import { CorePlatform } from '@services/platform';
28-
import { CoreNetwork, CoreNetworkConnection } from '@services/network';
28+
import { CoreNetwork, CoreNetworkConnectionType } from '@services/network';
2929
import { CoreLoginHelper } from '@features/login/services/login-helper';
3030
import { CoreSitesFactory } from '@services/sites-factory';
3131
import { CoreText } from '@singletons/text';
@@ -53,7 +53,7 @@ interface CoreSettingsDeviceInfo {
5353
deviceType: string;
5454
screen?: string;
5555
isOnline: Signal<boolean>;
56-
wifiConnection: Signal<boolean>;
56+
measuredConnection: Signal<boolean>;
5757
cordovaVersion?: string;
5858
platform?: string;
5959
osVersion?: string;
@@ -96,7 +96,7 @@ export default class CoreSettingsDeviceInfoPage {
9696
compilationTime: CoreConstants.BUILD.compilationTime || 0,
9797
lastCommit: CoreConstants.BUILD.lastCommitHash || '',
9898
isOnline: CoreNetwork.onlineSignal(),
99-
wifiConnection: computed(() => CoreNetwork.connectionTypeSignal()() === CoreNetworkConnection.WIFI),
99+
measuredConnection: computed(() => CoreNetwork.connectionTypeSignal()() === CoreNetworkConnectionType.MEASURED),
100100
localNotifAvailable: CoreLocalNotifications.isPluginAvailable() ? 'yes' : 'no',
101101
pushId: CorePushNotifications.getPushId(),
102102
deviceType: '',
@@ -212,7 +212,7 @@ export default class CoreSettingsDeviceInfoPage {
212212
const deviceInfo = {
213213
...this.deviceInfo,
214214
isOnline: this.deviceInfo.isOnline(),
215-
wifiConnection: this.deviceInfo.wifiConnection(),
215+
measuredConnection: this.deviceInfo.measuredConnection(),
216216
};
217217
CoreText.copyToClipboard(JSON.stringify(deviceInfo));
218218
}

src/core/features/settings/pages/site/site.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ export default class CoreSitePreferencesPage implements AfterViewInit, OnDestroy
7373
}, this.siteId);
7474

7575
this.isOnline = CoreNetwork.isOnline();
76-
this.limitedConnection = this.isOnline && CoreNetwork.isNetworkAccessLimited();
76+
this.limitedConnection = CoreNetwork.connectionIsMeasured();
7777

7878
this.networkObserver = CoreNetwork.onChange().subscribe(() => {
7979
// Execute the callback in the Angular zone, so change detection doesn't stop working.
8080
NgZone.run(() => {
8181
this.isOnline = CoreNetwork.isOnline();
82-
this.limitedConnection = this.isOnline && CoreNetwork.isNetworkAccessLimited();
82+
this.limitedConnection = CoreNetwork.connectionIsMeasured();
8383
});
8484
});
8585
}

0 commit comments

Comments
 (0)