Repository navigation
feat(mobile): keep the Glasshouse page out of screenshots and recordings on iPhone - #202
Merged
Merged
Conversation
…ngs on iPhone The Glasshouse page's container layer is moved into the canvas layer of a secure text field, which the system leaves out of screenshots and screen recordings. The view hierarchy stays as it is; only the layer tree changes. The layer is put back when the page leaves the screen or restricted mode ends. The restricted-mode sign sits behind the page and says the page is hidden from screenshots and recordings. The notice that a screenshot cannot be blocked shows only when the system gave the field no canvas layer, and then nothing is changed. Raises the build number to 261126.1. Signed-off-by: Yehor Komarov <10210242+geoolekom@users.noreply.github.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
…sh while it is hidden from screenshots Moving the layer of a view of the page into the secure canvas stopped the web view from taking keyboard focus, and removing the parent of such a view while its layer was in the canvas crashed UIKit. The window has no superview, so the layer of the window is moved instead, as Expo does: typing, scrolling, taps and leaving and coming back to the page all work. The cost is that everything the window shows is out of screenshots and recordings while the page is on the screen, not the page alone. For that reason the "Restricted page" sign behind the page is removed: no picture can show it. The tests of the host are rewritten for the window and split into their own file, with the shared test doubles in another; the README says what was tried and what it costs. Signed-off-by: Yehor Komarov <10210242+geoolekom@users.noreply.github.com>
`main` already carries build number 261126.1, which came in with another change, so this change bumps the build number to the next one of the day. Signed-off-by: Yehor Komarov <geoolekom@gmail.com>
Signed-off-by: Yehor Komarov <geoolekom@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keeps the Glasshouse page out of screenshots and screen recordings on iPhone by moving a layer into the canvas layer of a secure
UITextField(isSecureTextEntry = true). The method follows Expo'spackages/expo-screen-capture/ios/SecureWindowCanvas.swiftandScreenCaptureModule.swift; the code here is written again for this app.The cost: the whole window is hidden, not only the page
The layer that moves is the layer of the page's window. While the Glasshouse page is on the screen, a screenshot or a recording of a real iPhone is expected to show nothing of the window: the address bar and the tab bar too, not only the page. No "Restricted page" sign can be shown in the picture, because it would be in the window as well, so that sign is not in this PR.
I first moved the layer of the page's own container (commit 1 of this branch), because it hides only the page. It does not work:
becomeFirstResponder(), so nothing can be typed into a field of the page. Moving the layer of the view SwiftUI puts around the page failed the same way._didMoveFromWindow:toWindow:). This happened in a unit test and in the app.The window has no superview, so moving its layer has neither problem; this is also what Expo does. If hiding only the page matters more than typing, this needs another idea. I did not find one.
What changed
GlasshouseScreenshotShieldmakes the secure field (no touches, clear background, sized like the parent), puts its layer where the moved layer was, takes the field's first sublayer as the canvas, and moves the layer into it. If the system gives the field no canvas layer, nothing is changed and it says so.GlasshouseWebHost(the view SwiftUI shows) keeps the web view filling it. When it gets a window in restricted mode, the window's layer is moved; when it leaves the window or the mode ends, the layer is put back. The view hierarchy does not change, so touches, scrolling, layout and text selection stay the web view's own.GlasshouseScreenshot.canBeBlockedis gone.GlasshouseRestrictiontakes the result of each try: when it worked there is no notice and the sign under the address bar says "Restricted mode: hidden from screenshots and recordings"; the "a screenshot cannot be blocked" notice shows only after a try that failed. The page stays hidden while the screen is being recorded./long) for the scroll and tap test. The build number is 261126.2 (mainalready carried 261126.1). The README says how the method works, what it costs and what the Simulator cannot test.What the Simulator could not show
The Simulator does not apply the screenshot protection to what it draws, so the black area (and the missing page in a recording) cannot be shown there, and no Simulator workaround is added. In the Simulator the secure field does give a canvas layer (a unit test checks this with the real field), and the app, with the real window's layer in the canvas, loads the page, scrolls, takes taps, selects text, types and keeps working when the person leaves the page and comes back (UI tests). The sign under the address bar says "hidden" only after the real try worked, so the UI test of that sign shows that the real window's layer was moved. Not covered: clipboard-manager tricks, dragging text out, the App Switcher snapshot, video DRM. The app has no pull-to-refresh, and rotation is covered at the layer level by the resize test.
What each new test shows
GlasshouseScreenshotShieldTests(unit, plain layers and the real secure field):UITextFieldgives a canvas layer in the Simulator.GlasshouseWebHostTests(unit, a layer of their own stands in for the window's):GlasshouseRestrictionTests(unit, four new): nothing is said before a try; the notice shows after a failed try and goes when read; protected after a try that worked; the notice follows the last try and does not come back after it was read.GlasshouseRestrictedTests(UI, in the real app): the sign says the page is hidden from screenshots and recordings, with no line asking to read anything; the page scrolls and takes a tap at the end of/long; the page keeps working, and a field of it takes typing, after the person leaves it and comes back.What ran
scripts/test-glasshouse-ios.py, about 11 minutes).iosApp/check.sh(structure check andswiftlint lint --strict): clean, 0 violations.pre-commit run --all-files: passed.To check on a real iPhone (from TestFlight after merge)
Open a page in Glasshouse and take a screenshot: it should be black or empty, with nothing of the app in it. Record the screen: the recording should show nothing of the app while the page is on the screen. Go to another tab: screenshots work there as before. Note the iOS version.