Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mobile Payments] Prevent sleep during Card Reader software updates #14021

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

joshheald
Copy link
Contributor

@joshheald joshheald commented Sep 23, 2024

Description

This PR disables sleep on a user's device for the duration of any Card Reader software updates.

Steps to reproduce

  1. Set Xcode to use the simulated reader, and set Terminal.shared.simulatorConfiguration.availableReaderUpdate = .required in the StripeCardReaderService
  2. Add breakpoints in StripeCardReaderService.reader(_:didStartInstallingUpdate:cancelable:) and StripeCardReaderService.reader(_:didFinishInstallingUpdate:error:)
  3. Launch the app and connect to a reader
  4. Observe that the sleep timer is disabled and enabled as expected.

Testing information

The shortest auto-lock is 30s – this is longer than it takes to complete a (simulated) reader update, but using a timer to trigger the connection allowed me to check that it doesn't autolock during a (real) update, and does after the update completes.

I added DispatchQueue.main.asyncAfter(deadline: .now() + 22) in a Task in CardReaderConnectionController.onFoundReader(). I used 22 seconds to give it time to connect and start the update before the sleep timer kicks in – we don't disable device sleep until the install actually starts.

It's important to note that the device won't sleep while connected to the Xcode debugger regardless of what you do, so timer-based testing should be done without a connection to Xcode. This means you need a reader which has a pending update to test in this way, as the Stripe simulated readers only work when you're connected to Xcode.

If you have such a reader, be sure to cancel any updates before they complete!

Also it's best to turn of Settings > Face ID > Attention Aware Features to ensure you're not keeping your phone awake by looking at it.

StripeCardReaderService isn't unit tested due to the difficulties presented by faking the Stripe SDK.

Screenshots

Before

before.mp4

After

after.mp4

Note that after the reader update is cancelled, the phone is allowed to go to sleep again, so 30s after the cancellation, the display goes to sleep in this second video.


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

@joshheald joshheald added type: task An internally driven task. feature: mobile payments Related to mobile payments / card present payments / Woo Payments. labels Sep 23, 2024
@joshheald joshheald added this to the 20.6 milestone Sep 23, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 23, 2024

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14021-39750d1
Version20.5
Bundle IDcom.automattic.alpha.woocommerce
Commit39750d1
App Center BuildWooCommerce - Prototype Builds #10961
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@joshheald
Copy link
Contributor Author

@staskus This isn't urgent and can totally wait to 20.7 if you want to focus on HACK week stuff. It's very small but testing it is a pain. Feel free to rely on my testing with a physical device though, it's not so bad with breakpoints/simulator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: mobile payments Related to mobile payments / card present payments / Woo Payments. type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants