feat(windows): honour Windows "metered connection" flag for downloading updates#16099
feat(windows): honour Windows "metered connection" flag for downloading updates#16099rc-swag wants to merge 6 commits into
Conversation
This adds a helper unit which uses the windows API to obtain a ConnectionProfile. This profile provides information about the connection status and connectivity statistics. This includes the connection costs, roaming, restricted etc. It also can check to see if background networking activity has been restricted. Using the recommened example this commit combines these to determine if a network is metered. It also provides access to the background network being restricted. Fixes: #13566
If the download has already occured before calling the pop up then there is no reason to warn about the metered connection.
| if bucStateContext.FAutomaticUpdate then | ||
|
|
||
| if bucStateContext.FAutomaticUpdate and | ||
| not UtilNetworkConnection.IsBackgroundUpdateAllowed then |
There was a problem hiding this comment.
Isn't this backwards and it would do it if background updates are not allowed? Shouldn't it be
| not UtilNetworkConnection.IsBackgroundUpdateAllowed then | |
| UtilNetworkConnection.IsBackgroundUpdateAllowed then |
(see also the comment on the implementation of IsBackgroundUpdateAllowed)
There was a problem hiding this comment.
Yes I had a different name for this function when I first implemented it but changed it to a incorrect name. The comment of the implementation was wrong.
| begin | ||
| if bucStateContext.FAutomaticUpdate then | ||
| if bucStateContext.FAutomaticUpdate and | ||
| not UtilNetworkConnection.IsBackgroundUpdateAllowed then |
There was a problem hiding this comment.
See above
| not UtilNetworkConnection.IsBackgroundUpdateAllowed then | |
| UtilNetworkConnection.IsBackgroundUpdateAllowed then |
| // it would be better to have this warning in a banner on the configuration | ||
| // page. | ||
| IsMetered := UtilNetworkConnection.IsMetered; | ||
| if HasKeymanRun OR IsMetered then |
There was a problem hiding this comment.
IsMetered doesn't make sense to me here. I'd expect it to be not IsMetered, but maybe I don't understand when this code runs. Also, the comment about the metered warning seems a bit out of place here since I don't see how the code here is connected to the install dialog.
Or is the key the next line where we create the install dialog? Maybe it would be better (and easier to see the connection) if we'd pass IsMetered as a parameter to the dialog?
But it leaves me still wondering why we would want to run this code on a metered connection, but not on an un-metered one.
There was a problem hiding this comment.
The StartInstall form is used currently in two scenarios. They where allmost identical forms except for the message so I just made them one.
The scenario you are commenting on is when using the configuration to check for updates and if the are found choosing the "Install Now" button. If Keyman has run they will need to restart there machine so the pop-up gives them a chance to bail. Like wise if they are metered they still might like to (download) and install anyway or choose not to.
The other time is in called when starting Keyman and all the conditions are met to install the update now. It doesn't need to show the warnings but we use the same form.
| // Currently this checks for metered connection OR background | ||
| // data usage restricted. If a configuration item is added that | ||
| // provides the option to download on metered connections then | ||
| // this should be updated to include that logic | ||
| function IsBackgroundUpdateAllowed: Boolean; | ||
| begin | ||
| Result := IsMetered OR IsBackgroundDataRestricted; | ||
| end; |
There was a problem hiding this comment.
To me the logic of this function is very unexpected. From the name of the function I'd expect it to return true if we can do background updates (which is in line what the description in line 31 says), which in my mind would be if we're on an un-metered connection and there are no restrictions on background data.
Currently the function returns the opposite.
There was a problem hiding this comment.
The name is wrong I want all three functions to return True pattern. I will update the name and the comment to match
| IsMetered := UtilNetworkConnection.IsMetered; | ||
| if HasKeymanRun OR IsMetered then | ||
| begin | ||
| frmStartInstallNow := TfrmStartInstall.Create(nil, true); |
There was a problem hiding this comment.
From devin.ai:
RestartRequired hardcoded to true when dialog can also be shown for metered-only case
In Update_ApplyNow, the condition to show the confirmation dialog was expanded from if HasKeymanRun to if HasKeymanRun OR IsMetered (line 829), but the RestartRequired constructor parameter remains hardcoded to true (line 831). When HasKeymanRun is False but IsMetered is True, the dialog is shown with the restart warning message (S_Update_Restart_Req: "Installing the update now will require a restart of your computer...") even though no restart is actually needed — the only concern is the metered connection. The RestartRequired parameter should be HasKeymanRun to show the correct message.
Co-authored-by: Eberhard Beilharz <ermshiperete@users.noreply.github.com>

This adds a helper unit which uses the windows API to obtain a ConnectionProfile. This profile provides information about the connection status and connectivity statistics. This includes the connection costs, roaming, restricted etc. It also can check to see if background networking activity has been restricted.
Using the recommened example this commit combines these to determine if a network is metered. It also provides access to the background network being restricted.
There is a call that
IsBackgroundUpdateAllowedthat will return true if a background update is allowed.This is then use in the Update State Machine and also by update pop up.
UpdateStateMachine
Before downloading
IsBackgroundUpdateAllowedis calledUpdate Pop Up
This uses the
IsMeteredcall and adds a warning if to the user who is wanting to Install Now.This message would be better as a banner in the Update Configuration tab, rather than a delphi tab. This is the most efficent place to add the message for now.
Fixes: #13566
Build-bot: release:windows
User Testing
Mark connection as metered
For this we need to use windows setting to set the test machines network to metered. Right click the network connection icon in the Windows System tray and select
network & internet settingsSelected the connected work and the change the toggle forMetered connectiontoOnWindows 11

Windwos 10

TEST_WARNING_MESSAGE
Use a keyboard update to test.
TEST_NO_WARNING_MESSAGE_PART1
This is to make sure a warning message is not present on non-metered connection.
TEST_NO_WARNING_MESSAGE_PART2
This is to make sure a warning message is not present on a metered connection when
we already have the download and are just in the WaitingRestart State.
TEST_NO_BACKGROUND_UPDATE
regeditupdate stateback tousIdlelast update check time. This needs to be done otherwise it will stay inusIdlefor 7 days.c:\Program Files (x86)\Keyman\Keyman Desktopkmshell.exe -cThis will run the configurationTEST_BACKGROUND_UPDATE
This is a regresion test.
OFFas explanined above.regeditupdate stateback tousIdlelast update check time. This needs to be done otherwise it will stay inusIdlefor 7 days.c:\Program Files (x86)\Keyman\Keyman Desktopkmshell.exe -cThis will run the configuration