DEV Community

Cover image for How to Keep OS AI Agents Out of Your App's Sensitive Screens
jamilxt
jamilxt

Posted on Originally published at jamilxt.com

How to Keep OS AI Agents Out of Your App's Sensitive Screens

End-to-end encryption protects a message on the wire and on disk. It does not protect the message while it sits on the screen. At that point the operating system can see it, and so can any AI agent the operating system lets in.

On November 20, Signal said it would block screenshots in its iOS 27 app by default, and turn on its "Screen security" setting on Android when it detects an AI assistant trying to read the screen. Signal's announcement names Gemini on Android and Siri AI's Onscreen Awareness on iOS, and calls OS-level AI agents "an existential threat" to its mission. TechCrunch covered it the next day, and the Hacker News thread passed 570 points.

Most of the coverage is about Signal. This article is about your app. If you build a banking app, a health app, a password manager, or a chat feature inside a bigger product, the same question applies to you: what can you actually stop, on which platform, and with which API? The answers below come from the official Android, Apple, Microsoft and Electron documentation, and from Signal's own posts.

How an OS agent sees your app

It helps to split the problem into three paths, because each one needs a different control.

Pixels. The agent takes a screenshot or reads a screen recording, then runs it through a model. Microsoft Recall works this way on Windows: Signal's footnote describes it as capturing the screen every few seconds and pulling text out with OCR (optical character recognition, turning an image of text into real text). Signal says screenshots are "how most agentic systems access data from applications like Signal."

Structure. The agent asks the OS for the view hierarchy (the tree of buttons, labels and text fields) instead of the image. On Android, the Assist API hands the active assistant an AssistStructure with the text and view tree of the current screen. The accessibility API gives a similar tree to any accessibility service the user has turned on. Signal's post names Meta's Muse as an example of a third-party agent that gets in through the deep permissions users grant during setup. In many cases, Signal says, those are accessibility settings, used as "a skeleton key."

Data that never reaches the screen. Notifications, files on disk, and other OS frameworks and APIs. Signal says plainly that screenshot blocking "does not address other more sneaky ways AI agents could potentially access application data, such as retrieving content already present on a user's device via the filesystem."

Screen protection only covers the first path fully, and the second path partly. Keep that in mind as you read the platform sections.

Android: the strongest toolkit

Android gives you the most controls, and they are documented. Here they are in the order you will probably need them.

1. FLAG_SECURE on the window

FLAG_SECURE is a window flag. The Android fraud-prevention guide says it "tells Android not to allow screenshots or to display the window view on a non-secure display (such as Casting the screen)." A screenshot of a secure window comes out blank.

It also matters for assistants. The Assist API guide says the system passes automatically collected screen content to the assistant "unless the current window is flagged as secure."

class ChatActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.setFlags(
            WindowManager.LayoutParams.FLAG_SECURE,
            WindowManager.LayoutParams.FLAG_SECURE
        )
        setContentView(R.layout.activity_chat)
    }
}
Enter fullscreen mode Exit fullscreen mode

Three details from the docs are easy to miss:

  • The flag is per window, not per app. The Assist guide says you "must set FLAG_SECURE explicitly for every window created by the activity, including dialogs," and that "there is no global (app-level) mechanism to exclude all views from the assistant." For a SurfaceView, use setSecure().
  • FLAG_SECURE does not stop the Assist callbacks. If your activity overrides onProvideAssistContent() or onProvideAssistData(), it can still hand data to the assistant itself. On a sensitive screen, do not put message text or account numbers into those callbacks.
  • On old devices it is weaker. The fraud-prevention guide notes that for Android 11 (API 30) and lower, FLAG_SECURE "is able to help around 70% of the devices reliably," because keyboard taps can be recorded on some devices.

The Android 14 screenshot guide also recommends a setting that lets users switch the flag. Signal does exactly that. To turn it off at runtime, call window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE).

2. Mark only the sensitive views (Android 15)

Blocking every screenshot of every screen is heavy. Android 15 (API 35) added View.setContentSensitivity(). The View reference says the system will "hide content drawn by a sensitive view from screen sharing and recording," and that "the window hosting a sensitive view will be marked as secure during an active media projection session."

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
    otpField.setContentSensitivity(View.CONTENT_SENSITIVITY_SENSITIVE)
}
Enter fullscreen mode Exit fullscreen mode

Note the scope: this kicks in during media projection, which means screen sharing and screen recording. It is a lighter option for login and payment forms. It is not a full replacement for FLAG_SECURE when your threat is a screenshot-based assistant.

3. Close the accessibility door (Android 14)

This is the closest thing Android has to an answer for the "skeleton key" problem. Android 14 (API 34) added View.setAccessibilityDataSensitive(). Per the View reference, it "specifies whether this view should only allow interactions from AccessibilityServices with the AccessibilityServiceInfo.isAccessibilityTool() property set to true."

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
    messageList.setAccessibilityDataSensitive(
        View.ACCESSIBILITY_DATA_SENSITIVE_YES
    )
}
Enter fullscreen mode Exit fullscreen mode

Who gets to set isAccessibilityTool? Google Play's accessibility API policy says: "Only services that are designed to help people with disabilities access their device or otherwise overcome challenges stemming from their disabilities are eligible to declare that they are accessibility tools."

So a screen reader built for people with disabilities can keep working, while a general-purpose service that is not a declared accessibility tool is shut out of that view. Two limits: it only protects the views you mark, and the flag is self-declared. Play's policy says it is set "using the isAccessibilityTool attribute in the service's metadata file," and the check on that claim is Google Play's review, not the API.

4. Detect capture and react

Sometimes you want to know when capture happens rather than block it. Android has two callbacks.

Screenshot detection arrived in Android 14. You declare the install-time permission android.permission.DETECT_SCREEN_CAPTURE, then register a callback per activity:

private val screenCaptureCallback = Activity.ScreenCaptureCallback {
    // Warn the user, or tell the other side of the chat.
}

override fun onStart() {
    super.onStart()
    registerScreenCaptureCallback(mainExecutor, screenCaptureCallback)
}

override fun onStop() {
    super.onStop()
    unregisterScreenCaptureCallback(screenCaptureCallback)
}
Enter fullscreen mode Exit fullscreen mode

Read the limits on the screenshot detection page before you rely on it. The callback fires only for screenshots taken with "a specific combination of hardware button presses." It does not fire for ADB or instrumentation test captures. It also does not give you the image. So it tells you about a person pressing buttons, not about an agent grabbing pixels in the background.

Screen recording detection arrived in Android 15. It needs the DETECT_SCREEN_RECORDING permission, and the callback runs whenever your app becomes visible or invisible in a recording:

private val recordingCallback = Consumer<Int> { state ->
    if (state == WindowManager.SCREEN_RECORDING_STATE_VISIBLE) {
        // Hide sensitive content or show a notice.
    }
}

override fun onStart() {
    super.onStart()
    val initialState =
        windowManager.addScreenRecordingCallback(mainExecutor, recordingCallback)
    recordingCallback.accept(initialState)
}

override fun onStop() {
    super.onStop()
    windowManager.removeScreenRecordingCallback(recordingCallback)
}
Enter fullscreen mode Exit fullscreen mode

Signal's footnote explains why it did not simply block screenshots everywhere on Android. Android ships in many vendor versions, and on many of them Signal has no reliable way to detect a screenshot attempt once screenshots are already disabled. Rather than make screenshots silently fail and confuse users, Signal turns on Screen security automatically when it detects an AI assistant trying to access the screen. Signal has not published how that detection works, so do not assume one of the public callbacks above is the whole story.

iOS: detection, not prevention

The documented iOS controls are thinner. In the UIKit APIs covered here, you can learn that capture is happening, but you cannot stop a screenshot.

After a screenshot. UIApplication.userDidTakeScreenshotNotification fires, but Apple's docs say it "posts after the screenshot is taken." Use it to warn or to notify the other party, not to protect anything.

NotificationCenter.default.addObserver(
    forName: UIApplication.userDidTakeScreenshotNotification,
    object: nil,
    queue: .main
) { _ in
    // The screenshot already exists. Warn or log here.
}
Enter fullscreen mode Exit fullscreen mode

During recording or mirroring. The old UIScreen.isCaptured property is marked deprecated as of iOS 27. Apple's docs point to sceneCaptureState, a trait available since iOS 17 that "represents whether a scene is currently being mirrored or recorded." Its values are .active, .inactive and .unspecified. When it turns .active, you can cover sensitive views with a placeholder.

registerForTraitChanges([UITraitSceneCaptureState.self]) { (self: Self, _: UITraitCollection) in
    let captured = self.traitCollection.sceneCaptureState == .active
    self.sensitiveContainer.isHidden = captured
}
Enter fullscreen mode Exit fullscreen mode

Signal does block screenshots in its iOS 27 app, with a "Block Siri AI" setting, but its post does not say which mechanism it uses. If you need the same result, treat it as an open question to test on real devices, not as a documented API.

The user-side switch. Since iOS 27.2 there is a per-app control. The EFF describes it as Settings > Siri > Excluded Apps. Once an app is excluded, "Siri AI cannot access the contents of the app," and even Onscreen Awareness stops working inside it. Neither Signal nor the EFF describes a way for an app to turn this on by itself. What you can do is tell users about it, for example in a privacy section of your settings screen or during onboarding.

Desktop: Windows works, macOS does not (yet)

Windows. The control is SetWindowDisplayAffinity with WDA_EXCLUDEFROMCAPTURE. The Win32 reference says the window is then shown only on a monitor and "everywhere else, the window does not appear at all." It is supported from Windows 10 version 2004. On older versions it behaves like WDA_MONITOR, which shows the window as empty in captures. Microsoft's Recall admin guide says that with this flag, "the window content won't show up in Recall or any other screenshot application." Signal Desktop has used this approach on Windows 11 by default since 2025, as its Recall post describes.

If your desktop app is built on Electron, you do not need Win32 code. The Electron BrowserWindow docs say win.setContentProtection(true) "prevents the window contents from being captured by other apps," and on Windows it calls SetWindowDisplayAffinity with WDA_EXCLUDEFROMCAPTURE.

const { app, BrowserWindow } = require('electron')

app.whenReady().then(() => {
  const win = new BrowserWindow({ width: 1000, height: 700 })
  win.setContentProtection(true)
  win.loadFile('index.html')
})
Enter fullscreen mode Exit fullscreen mode

The Electron docs add one timing detail: the change "takes effect with the next desktop composition, not when the call returns." Set protection when you create the window. Do not wait until sensitive data is on screen.

macOS. This is the gap Signal could not close. Electron's docs say that on macOS the same call sets the NSWindow sharingType to none, but "newer Mac applications that use ScreenCaptureKit will capture your window despite win.setContentProtection(true)." Signal's post goes further: protections against continuous screen capture exist on macOS, but Signal "cannot reliably block screenshots," which is how most agents read app data. Its only advice for macOS 27 users is the same user-side switch: add Signal to System Settings > Siri > Excluded Apps.

What no app can block today

Even with every control above in place, three paths stay open.

  • Notifications. The EFF notes that on Android, Gemini can read notifications if the "Device Assistance" connected app is enabled. A message preview in a notification never touches your secure window. If your notifications carry sensitive text, give users an option to hide the content and show only "New message."
  • Files on disk. Signal lists filesystem access as a gap it cannot cover. Screen flags do nothing here. Keep sensitive data encrypted at rest, with keys held by the platform keystore, so a file read returns ciphertext.
  • Everything the OS vendor itself controls. Signal's two requests to Apple, Google and Microsoft are an easy, documented way for apps to opt out of AI data access, covering "screen reading, filesystem access, notifications, APIs, and other OS frameworks," and real documentation of how these agents access data. Until those exist, every protection above is a workaround on top of the OS.

One commenter in the HN thread put the dependency simply: "Any protection against this requires OS support." (comment)

The trade-offs to plan for

Blocking capture has real costs, and Signal's own posts are open about them.

Accessibility users. In its Recall post, Signal noted that "some accessibility software (such as screen readers or magnification tools for people who are visually impaired) may not function correctly" with screen security on. Test your protected screens with TalkBack, VoiceOver and screen magnifiers. On Android, setAccessibilityDataSensitive is designed to keep declared accessibility tools working while shutting out other services, which is one reason to prefer it over blanket blocking for the accessibility path.

Users who need screenshots. Bug reports, receipts, and sharing a funny message are normal uses. Signal lets users disable the protection, and on Windows it shows a warning and asks for confirmation before turning it off. That is a good pattern to copy: protected by default, easy to change, hard to change by accident.

Silent failure. A screenshot that comes out black looks like a bug. Signal chose its Android approach partly to avoid "a poor user experience (where screenshots simply stop working, confusing users)." If you block screenshots, say so somewhere the user will see it.

A checklist for your next release

  1. List your sensitive screens: chats, account balances, health records, one-time codes, password fields.
  2. Android: set FLAG_SECURE on each of those windows, including dialogs. Add setAccessibilityDataSensitive (API 34+) to the views that hold the data, and setContentSensitivity (API 35+) to login and payment fields.
  3. Android: check your onProvideAssistContent() and onProvideAssistData() overrides so they do not hand sensitive data to the assistant.
  4. iOS: watch sceneCaptureState and hide sensitive views while the screen is recorded or mirrored. Handle userDidTakeScreenshotNotification if your product needs to warn people.
  5. iOS and macOS: tell users about Settings > Siri > Excluded Apps.
  6. Windows and Electron: call setContentProtection(true) or SetWindowDisplayAffinity with WDA_EXCLUDEFROMCAPTURE at window creation.
  7. Notifications: offer a "hide message content" option.
  8. Storage: encrypt sensitive data at rest with platform-held keys.
  9. Add a settings toggle with a clear warning, and test every protected screen with a screen reader.

Signal described itself as "the canary in the coal mine." By its own account it spent "considerable developer time" over the past few months on forensic investigations across Android and iOS, and it still could not cover macOS or every Android device. A smaller app will hit the same walls. The difference is whether you find out now, from the docs, or later, from a user.

Which screens in your app would you protect first, and has an OS assistant already read one of them?

Sources

[1] Signal: Signal is Serious About Protecting Your Privacy

[2] TechCrunch: Signal restricts mobile screenshots as it confronts "existential threat" of AI surveillance

[3] Hacker News discussion of Signal's post

[4] Android Developers: Secure sensitive activities

[5] Android Developers: Optimizing contextual content for the Assistant

[6] Android Developers: Detect when users take device screenshots

[7] Android Developers: Android 15 features and APIs

[8] Android Developers: View reference

[9] Google Play: Use of the AccessibilityService API

[10] Apple Developer: userDidTakeScreenshotNotification

[11] Apple Developer: sceneCaptureState

[12] Apple Developer: isCaptured

[13] EFF: Victory! You Can Now Exclude Apps from Siri AI

[14] Microsoft Learn: SetWindowDisplayAffinity function

[15] Microsoft Learn: Manage Recall

[16] Signal: By Default, Signal Doesn't Recall

[17] Electron: BrowserWindow

Top comments (0)