Skip to content

feat: Separate Privacy Screen and Screenshot Protection#113

Open
jimcase wants to merge 1 commit intocapacitor-community:mainfrom
jimcase:feature/separate-privacy-screen-screenshots
Open

feat: Separate Privacy Screen and Screenshot Protection#113
jimcase wants to merge 1 commit intocapacitor-community:mainfrom
jimcase:feature/separate-privacy-screen-screenshots

Conversation

@jimcase
Copy link
Copy Markdown

@jimcase jimcase commented Dec 31, 2024

Feature Implementation Overview: Privacy Screen and Screenshot Protection in Android

The @capacitor-community/privacy-screen plugin has been enhanced to offer separate controls for privacy screen and screenshot protection. This modification allows for finer control over app security features, aligning with varied application requirements and user settings. Issue-112

Current Implementation:

  • Privacy Screen and Screenshot Protection: Initially, the plugin managed these features together, activating both simultaneously without separate controls.

Enhancements:

  • Separate Controls: Introduced distinct methods for managing these features:
    • enablePrivacyScreen(): Activates the privacy screen overlay without affecting screenshot capabilities.
    • disablePrivacyScreen(): Deactivates the privacy screen independently.
    • enableScreenshotProtection(): Activates screenshot protection without enabling the privacy screen.
    • disableScreenshotProtection(): Deactivates screenshot protection separately.

Technical Details:

  • Privacy Overlay Management: A transparent view monitors focus changes to dynamically add or remove a white privacy overlay based on window focus, enhancing user privacy during sensitive sessions.
plugin.getActivity().runOnUiThread(() -> {
    FrameLayout root = plugin.getActivity().findViewById(android.R.id.content);
    focusMonitorView = new View(plugin.getContext());
    focusMonitorView.setLayoutParams(new FrameLayout.LayoutParams(1, 1));
    focusMonitorView.setBackgroundColor(Color.TRANSPARENT);

    focusMonitorView.getViewTreeObserver().addOnWindowFocusChangeListener(hasFocus -> {
        if (!hasFocus) {
            addPrivacyOverlay();
            Log.d(TAG, "Window has lost focus, adding privacy overlay.");
        } else {
            removePrivacyOverlay();
            Log.d(TAG, "Window has gained focus, removing privacy overlay.");
        }
    });

    root.addView(focusMonitorView);
    focusMonitorView.requestFocus();
});
  • Screenshot Protection Flags: Utilizes WindowManager.LayoutParams.FLAG_SECURE just to handle/enable or disable screenshot and screen recording protection, providing robust security against unauthorized content capture.

This approach ensures developers can tailor the app’s behavior more precisely, depending on the specific needs for privacy and security, enhancing the plugin's versatility and usability in security-sensitive applications.

@jimcase jimcase changed the title feat: using focusMonitorView for privacy screen feat: Separate Privacy Screen and Screenshot Protection Dec 31, 2024
@jimcase jimcase marked this pull request as ready for review January 15, 2025 15:23
@IsAvaible
Copy link
Copy Markdown

Could we get traction on this? @robingenz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants