Skip to content

feat(windows): honour Windows "metered connection" flag for downloading updates#16099

Open
rc-swag wants to merge 6 commits into
masterfrom
feat/windows/13566/check-metered-connection
Open

feat(windows): honour Windows "metered connection" flag for downloading updates#16099
rc-swag wants to merge 6 commits into
masterfrom
feat/windows/13566/check-metered-connection

Conversation

@rc-swag

@rc-swag rc-swag commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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 IsBackgroundUpdateAllowed that 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 IsBackgroundUpdateAllowed is called

Update Pop Up
This uses the IsMetered call 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 settings Selected the connected work and the change the toggle for Metered connection to On

Windows 11
Keyman_network_Metered

Windwos 10
image

TEST_WARNING_MESSAGE

Use a keyboard update to test.

  1. Install Keyman version attached to his PR
  2. Download and install this older version of euro_latin
  3. Make sure you have change the connected network to metered as explanined above.
  4. Go into the Keyman Configuration and the Update Tab
  5. Press the check for updates button.
  6. It should find an update for Euro Latin.
  7. Press install updates ovbserve the warning is shown.
metered_warning

TEST_NO_WARNING_MESSAGE_PART1

This is to make sure a warning message is not present on non-metered connection.

  1. Install Keyman version attached to his PR
  2. Download and install this older version of euro_latin
  3. Run Keyman.
  4. Make sure you have change the connected network to metered OFF
  5. Go into the Keyman Configuration and the Update Tab
  6. Press the check for updates button.
  7. It should find an update for Euro Latin.
  8. Press install updates observe the metered warning is not shown.
not_metered_warning

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.

  1. Install Keyman version attached to his PR
  2. Download and install this older version of euro_latin
  3. Make sure you have change the connected network to metered OFF
  4. Go into the Keyman Configuration and the Update Tab
  5. Press the check for updates button.
  6. It should find an update for Euro Latin.
  7. Close Configuration and the Keyman Splash screen if open.
    1. Do not Run Keyman if Keyman has run you will need to sign out of the current windows session.
  8. Start Keyman
  9. A pop saying an update is ready observe the metered warning is not shown.
not_metered_warning

TEST_NO_BACKGROUND_UPDATE

  1. Install Keyman version attached to his PR
  2. Download and install this older version of sil_euro_latin.zip
  3. Close Keyman an Keyman Configuration
  4. Make sure you have change the connected network to metered as explanined above.
  5. Open Regedit WinR type regedit
  6. Go to the current user key update state found at (Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine).
  7. If required set the update state back to usIdle
  8. Delete last update check time. This needs to be done otherwise it will stay in usIdle for 7 days.
  9. Open Windows Explorer at "C:\Users"yourusername"\AppData\Local\Keyman\UpdateCache" folder.
  10. Delete any *.kmp and *.exe files.
  11. Open a command prompt and go to where kmshell is installed e.g c:\Program Files (x86)\Keyman\Keyman Desktop
  12. run kmshell.exe -c This will run the configuration
  13. Go to the Window Explorer window that is looking at the UpdateCache folder press F5 to refresh the window. No *.kmp or *.exe should appear as we are on metetered connection.

TEST_BACKGROUND_UPDATE

This is a regresion test.

  1. Install Keyman version attached to his PR
  2. Download and install this older version of sil_euro_latin.zip
  3. Close Keyman an Keyman Configuration
  4. Make sure you have change the connected network metered to OFF as explanined above.
  5. Open Regedit WinR type regedit
  6. Go to the current user key update state found at (Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine).
  7. If required set the update state back to usIdle
  8. Delete last update check time. This needs to be done otherwise it will stay in usIdle for 7 days.
  9. Open Windows Explorer at "C:\Users"yourusername"\AppData\Local\Keyman\UpdateCache" folder.
  10. Delete any *.kmp and *.exe files.
  11. Open a command prompt and go to where kmshell is installed e.g c:\Program Files (x86)\Keyman\Keyman Desktop
  12. run kmshell.exe -c This will run the configuration
  13. Go to the Window Explorer window that is looking at the UpdateCache folder press F5 to refresh the window. The sil_euro_latin.kmp should appear as we are not on a metered connection.

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
@github-project-automation github-project-automation Bot moved this to Todo in Keyman Jun 16, 2026
@keymanapp-test-bot keymanapp-test-bot Bot added the user-test-missing User tests have not yet been defined for the PR label Jun 16, 2026
@rc-swag rc-swag self-assigned this Jun 16, 2026
@keymanapp-test-bot

keymanapp-test-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

User Test Results

Test specification and instructions

Test Artifacts

@keymanapp-test-bot keymanapp-test-bot Bot added this to the A19S31 milestone Jun 16, 2026
@keymanapp-test-bot keymanapp-test-bot Bot added has-user-test user-test-required User tests have not been completed and removed user-test-missing User tests have not yet been defined for the PR labels Jun 16, 2026
rc-swag added 2 commits June 16, 2026 15:58
If the download has already occured before calling the pop up
then there is no reason to warn about the metered connection.
@rc-swag rc-swag marked this pull request as ready for review June 17, 2026 03:57
@rc-swag rc-swag requested a review from mcdurdin June 17, 2026 03:58
@rc-swag rc-swag changed the title feat(windows): add network connectivity tool feat(windows): honour Windows "metered connection" flag for downloading updates Jun 19, 2026
@keyman-server keyman-server modified the milestones: A19S31, A19S32 Jun 22, 2026
@Meng-Heng

Meng-Heng commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Test Prerequisite

  1. Windows 10 Bootcamp
  2. Keyman version 19.0.248-alpha-test-16099
  3. sil_euro_latin version 3.0.0

Test Results

  • TEST_WARNING_MESSAGE (PASSED):
  1. The metered connection is set to on
  2. Launch Keyman
  3. Go into the Keyman Configuration -> the Update Tab
  4. Press the check for updates button.
  5. Update for Eurolatin (SIL) appears
  6. Press install updates
  7. Confirm -- The pop-up window does have the metered warning.
  • TEST_NO_WARNING_MESSAGE_PART1 (PASSED):
  1. Launch Keyman
  2. The metered connection is off
  3. Go into the Keyman Configuration -> the Update Tab
  4. Press the check for updates button
  5. Update for Eurolatin (SIL) appears
  6. Press install updates
  7. Confirmed -- The pop-up window does not have the metered warning.
  • TEST_NO_WARNING_MESSAGE_PART2 (PASSED):
  1. Launch Keyman
  2. The metered connection stays off
  3. Go into the Keyman Configuration -> the Update Tab
  4. Press the check for updates button.
  5. Update for Eurolatin (SIL) appears
  6. Exit Keyman Configuration and the Keyman Splash screen from the tray
  7. Start Keyman
  8. Confirmed -- The pop-up window saying an update and does not have the metered warning
    image

Note

I did not get the exact message as in the test requirement (see the image right above this note)

  • TEST_NO_BACKGROUND_UPDATE (PASSED):
  1. Close Keyman and Keyman Configuration
  2. The metered connection is set to on
  3. Follow the instruction to delete last update check time in Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine
  4. Open Windows Explorer at "C:\Users\havm\AppData\Local\Keyman\UpdateCache" folder
  5. Delete *.kmp file
  6. Open a command prompt and go to c:\Program Files (x86)\Keyman\Keyman Desktop
  7. Run kmshell.exe -c
  8. The Keyman Configuration, Update tab opens up
  9. Confirm – In Window Explorer window that is looking at the UpdateCache folder press, there is no *.kmp or *.exe appear as we are on metered connection.
  • TEST_BACKGROUND_UPDATE (PASSED):
  1. Uninstall and reinstall Keyman
  2. Launch Keyman and install the keyboard
  3. Close Keyman and Keyman Configuration
  4. The metered connection is set to off
  5. Follow the instruction to delete last update check time in Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine
  6. Open Windows Explorer at "C:\Users\havm\AppData\Local\Keyman\UpdateCache" folder
  7. The folder is empty
  8. Open a command prompt and go to c:\Program Files (x86)\Keyman\Keyman Desktop
  9. Run kmshell.exe -c This will run the configuration
  10. Confirm – In the Window Explorer window that is looking at the UpdateCache folder, there is now a sil_euro_latin.kmp file as we are not on a metered connection.

if bucStateContext.FAutomaticUpdate then

if bucStateContext.FAutomaticUpdate and
not UtilNetworkConnection.IsBackgroundUpdateAllowed then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this backwards and it would do it if background updates are not allowed? Shouldn't it be

Suggested change
not UtilNetworkConnection.IsBackgroundUpdateAllowed then
UtilNetworkConnection.IsBackgroundUpdateAllowed then

(see also the comment on the implementation of IsBackgroundUpdateAllowed)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

Suggested change
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rc-swag rc-swag Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Image

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.

Comment on lines +85 to +92
// 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread windows/src/desktop/kmshell/main/Keyman.Configuration.UI.UfrmStartInstall.pas Outdated
Co-authored-by: Eberhard Beilharz <ermshiperete@users.noreply.github.com>
@keymanapp-test-bot keymanapp-test-bot Bot removed the user-test-required User tests have not been completed label Jun 23, 2026
@github-actions github-actions Bot added the user-test-required User tests have not been completed label Jun 23, 2026
@keymanapp-test-bot keymanapp-test-bot Bot removed the user-test-required User tests have not been completed label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

feat(windows): honour Windows "metered connection" flag for downloading updates

4 participants