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

feat: Separate Privacy Screen and Screenshot Protection #113

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jimcase
Copy link

@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
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.

1 participant