The issue was the original commit had a bug (using the wrong variable),
and also that there were no tests to verify the functionality. This
patchset fixes the bug and adds tests to verify the contract.
Closes-Bug: #1805128
(cherry picked from commit 50a7253b80)
Change-Id: I4c85cf14de2c3b3459330586ec2ffd261fed7a5e