Skip to content

Commit 160b90f

Browse files
committed
MOBILE-4653 network: Simplify network type management
1 parent a0507b8 commit 160b90f

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
@@ -1175,15 +1175,16 @@ public function i_switch_offline_mode(string $offline) {
11751175
public function i_switch_network_connection(string $mode) {
11761176
switch ($mode) {
11771177
case 'wifi':
1178-
$this->runtime_js("network.setForceConnectionMode('$mode');");
1178+
$this->runtime_js("network.setForceConnectionMode('not_measured');");
11791179
break;
11801180
case 'cellular':
1181-
$this->runtime_js("network.setForceConnectionMode('$mode');");
1181+
$this->runtime_js("network.setForceConnectionMode('measured');");
11821182
break;
11831183
case 'offline':
1184-
$this->runtime_js("network.setForceConnectionMode('none');");
1184+
$this->runtime_js("network.setForceConnectionMode('offline');");
11851185
break;
11861186
default:
1187+
$this->runtime_js("network.setForceConnectionMode('unknown');");
11871188
break;
11881189
}
11891190
}

scripts/langindex.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2525,6 +2525,7 @@
25252525
"core.settings.loggedin": "message",
25262526
"core.settings.loggedoff": "message",
25272527
"core.settings.logintosync": "local_moodlemobileapp",
2528+
"core.settings.measuredconnection": "local_moodlemobileapp",
25282529
"core.settings.navigatorlanguage": "local_moodlemobileapp",
25292530
"core.settings.navigatoruseragent": "local_moodlemobileapp",
25302531
"core.settings.networkstatus": "local_moodlemobileapp",
@@ -2548,7 +2549,6 @@
25482549
"core.settings.synchronizenowhelp": "local_moodlemobileapp",
25492550
"core.settings.syncsettings": "local_moodlemobileapp",
25502551
"core.settings.total": "moodle",
2551-
"core.settings.wificonnection": "local_moodlemobileapp",
25522552
"core.settings.youradev": "local_moodlemobileapp",
25532553
"core.sharedfiles.chooseaccountstorefile": "local_moodlemobileapp",
25542554
"core.sharedfiles.chooseactionrepeatedfile": "local_moodlemobileapp",

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

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

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

src/core/directives/external-content.ts

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ export class CoreCourseHelperProvider {
907907
}
908908

909909
// Start the download if in wifi, but return the URL right away so the file is opened.
910-
if (CoreNetwork.isWifi()) {
910+
if (CoreNetwork.connectionIsNotMeasured()) {
911911
this.downloadModule(module, courseId, component, componentId, files, siteId);
912912
}
913913

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
@@ -81,6 +81,6 @@
8181
"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.",
8282
"syncsettings": "Synchronisation settings",
8383
"total": "Total",
84-
"wificonnection": "Wi-Fi connection",
84+
"measuredconnection": "Measured data connection",
8585
"youradev": "You are now a developer"
8686
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ <h1>
112112
</ion-item>
113113
<ion-item (longPress)="copyItemInfo($event)">
114114
<ion-label class="ion-text-wrap">
115-
<p class="item-heading">{{ 'core.settings.wificonnection' | translate}}</p>
116-
@if (deviceInfo.wifiConnection()) {
115+
<p class="item-heading">{{ 'core.settings.measuredconnection' | translate}}</p>
116+
@if (deviceInfo.measuredConnection()) {
117117
<p>{{ 'core.yes' | translate }}</p>
118118
} @else {
119119
<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';
@@ -51,7 +51,7 @@ interface CoreSettingsDeviceInfo {
5151
deviceType: string;
5252
screen?: string;
5353
isOnline: Signal<boolean>;
54-
wifiConnection: Signal<boolean>;
54+
measuredConnection: Signal<boolean>;
5555
cordovaVersion?: string;
5656
platform?: string;
5757
osVersion?: string;
@@ -91,7 +91,7 @@ export class CoreSettingsDeviceInfoPage {
9191
compilationTime: CoreConstants.BUILD.compilationTime || 0,
9292
lastCommit: CoreConstants.BUILD.lastCommitHash || '',
9393
isOnline: CoreNetwork.onlineSignal(),
94-
wifiConnection: computed(() => CoreNetwork.connectionTypeSignal()() === CoreNetworkConnection.WIFI),
94+
measuredConnection: computed(() => CoreNetwork.connectionTypeSignal()() === CoreNetworkConnectionType.MEASURED),
9595
localNotifAvailable: CoreLocalNotifications.isPluginAvailable() ? 'yes' : 'no',
9696
pushId: CorePushNotifications.getPushId(),
9797
deviceType: '',
@@ -210,7 +210,7 @@ export class CoreSettingsDeviceInfoPage {
210210
const deviceInfo = {
211211
...this.deviceInfo,
212212
isOnline: this.deviceInfo.isOnline(),
213-
wifiConnection: this.deviceInfo.wifiConnection(),
213+
measuredConnection: this.deviceInfo.measuredConnection(),
214214
};
215215
CoreText.copyToClipboard(JSON.stringify(deviceInfo));
216216
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ export class CoreSitePreferencesPage implements AfterViewInit, OnDestroy {
6969
}, this.siteId);
7070

7171
this.isOnline = CoreNetwork.isOnline();
72-
this.limitedConnection = this.isOnline && CoreNetwork.isNetworkAccessLimited();
72+
this.limitedConnection = CoreNetwork.connectionIsMeasured();
7373

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ export class CoreSettingsSynchronizationPage implements OnInit, OnDestroy {
8989
});
9090

9191
this.isOnline = CoreNetwork.isOnline();
92-
this.limitedConnection = this.isOnline && CoreNetwork.isNetworkAccessLimited();
92+
this.limitedConnection = CoreNetwork.connectionIsMeasured();
9393

9494
this.networkObserver = CoreNetwork.onChange().subscribe(() => {
9595
// Execute the callback in the Angular zone, so change detection doesn't stop working.
9696
NgZone.run(() => {
9797
this.isOnline = CoreNetwork.isOnline();
98-
this.limitedConnection = this.isOnline && CoreNetwork.isNetworkAccessLimited();
98+
this.limitedConnection = CoreNetwork.connectionIsMeasured();
9999
});
100100
});
101101

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export class CoreSettingsHelperProvider {
241241
} else if (hasSyncHandlers && !CoreNetwork.isOnline()) {
242242
// We need connection to execute sync.
243243
throw new CoreError(Translate.instant('core.settings.cannotsyncoffline'));
244-
} else if (hasSyncHandlers && syncOnlyOnWifi && CoreNetwork.isNetworkAccessLimited()) {
244+
} else if (hasSyncHandlers && syncOnlyOnWifi && CoreNetwork.connectionIsMeasured()) {
245245
throw new CoreError(Translate.instant('core.settings.cannotsyncwithoutwifi'));
246246
}
247247

src/core/services/cron.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class CoreCronDelegateService {
9999
// Check network connection.
100100
const syncOnlyOnWifi = await CoreConfig.get(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, false);
101101

102-
if (syncOnlyOnWifi && !CoreNetwork.isWifi()) {
102+
if (syncOnlyOnWifi && !CoreNetwork.connectionIsNotMeasured()) {
103103
// Cannot execute in this network connection, retry soon.
104104
this.logger.debug(`Cron job failed because your device has a limited internet connection: ${name}`);
105105
this.scheduleNextExecution(name, CoreCronDelegateService.MIN_INTERVAL);

src/core/services/file-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class CoreFileHelperProvider {
174174
}
175175

176176
// The file system is available.
177-
const isWifi = CoreNetwork.isWifi();
177+
const isWifi = CoreNetwork.connectionIsNotMeasured();
178178
const isOnline = CoreNetwork.isOnline();
179179

180180
if (state === DownloadStatus.DOWNLOADED) {

src/core/services/filepool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ export class CoreFilepoolProvider {
528528
}
529529

530530
// Calculate the size of the file.
531-
const isWifi = CoreNetwork.isWifi();
531+
const isWifi = CoreNetwork.connectionIsNotMeasured();
532532
const sizeUnknown = size <= 0;
533533

534534
if (!sizeUnknown) {
@@ -2947,7 +2947,7 @@ export class CoreFilepoolProvider {
29472947
*/
29482948
shouldDownload(size: number): boolean {
29492949
return size <= CoreFilepoolProvider.DOWNLOAD_THRESHOLD ||
2950-
(CoreNetwork.isWifi() && size <= CoreFilepoolProvider.WIFI_DOWNLOAD_THRESHOLD);
2950+
(CoreNetwork.connectionIsNotMeasured() && size <= CoreFilepoolProvider.WIFI_DOWNLOAD_THRESHOLD);
29512951
}
29522952

29532953
/**

0 commit comments

Comments
 (0)