Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
FabriBertani committed May 19, 2023
1 parent 67d8085 commit 4449fae
Show file tree
Hide file tree
Showing 49 changed files with 2,345 additions and 1 deletion.
Binary file added Assets/plugin.maui.screensecurity_128x128.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/plugin.maui.screensecurity_template.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions Plugin.Maui.ScreenSecurity.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.Maui.ScreenSecurity", "Plugin.Maui.ScreenSecurity\Plugin.Maui.ScreenSecurity.csproj", "{C9913AAB-598A-43EF-93E9-6FA4AE4CCAEC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{F0127D89-F3B5-4C88-9016-5CCA2DBF3F59}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenSecuritySample", "samples\ScreenSecuritySample\ScreenSecuritySample.csproj", "{479D2E8B-47FB-4F0D-B1AB-3DF4CC7D28A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9913AAB-598A-43EF-93E9-6FA4AE4CCAEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9913AAB-598A-43EF-93E9-6FA4AE4CCAEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9913AAB-598A-43EF-93E9-6FA4AE4CCAEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9913AAB-598A-43EF-93E9-6FA4AE4CCAEC}.Release|Any CPU.Build.0 = Release|Any CPU
{479D2E8B-47FB-4F0D-B1AB-3DF4CC7D28A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{479D2E8B-47FB-4F0D-B1AB-3DF4CC7D28A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{479D2E8B-47FB-4F0D-B1AB-3DF4CC7D28A5}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{479D2E8B-47FB-4F0D-B1AB-3DF4CC7D28A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{479D2E8B-47FB-4F0D-B1AB-3DF4CC7D28A5}.Release|Any CPU.Build.0 = Release|Any CPU
{479D2E8B-47FB-4F0D-B1AB-3DF4CC7D28A5}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{479D2E8B-47FB-4F0D-B1AB-3DF4CC7D28A5} = {F0127D89-F3B5-4C88-9016-5CCA2DBF3F59}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FB29A9B4-E0B3-4C0E-9E67-D98FC2F3E4EB}
EndGlobalSection
EndGlobal
93 changes: 93 additions & 0 deletions Plugin.Maui.ScreenSecurity/IScreenSecurity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#if IOS
using Plugin.Maui.ScreenSecurity.Platforms.iOS;
#endif

namespace Plugin.Maui.ScreenSecurity;

public interface IScreenSecurity
{
#if ANDROID
/// <summary>
/// Prevent screen content from being exposed when the app
/// is sent to <b>Background</b> or the <b>Recents screen</b>.
/// Also prevents app <b>screenshots</b> or <b>recording</b> to be taken.
/// </summary>
/// <remarks>Supported for <b><c>Android</c></b> only.</remarks>
void EnableScreenSecurityProtection();

/// <summary>
/// Re-enables screen content exposure.
/// </summary>
/// <remarks>Supported for <b><c>Android</c></b> only.</remarks>
void DisableScreenSecurityProtection();
#elif IOS
/// <summary>
/// Prevent screen content from being exposed by
/// using a <b>Blur layer</b> when the app is sent to
/// <b>Background</b> or the <b>App Switcher</b>.
/// </summary>
/// <param name="style">
/// Choose between a <b><c>Light</c></b> or <b><c>Dark</c></b> theme for the Blur layer.
/// <b><c>Light</c></b> by default.
/// </param>
/// <remarks>Supported for <b><c>iOS</c></b> only.</remarks>
void EnableBlurScreenProtection(ThemeStyle style);

/// <summary>
/// Removes the <b>Blur layer</b> and re-enables screen content exposure.
/// </summary>
/// <remarks>Supported for <b><c>iOS</c></b> only.</remarks>
void DisableBlurScreenProtection();

/// <summary>
/// Prevent screen content from being exposed by
/// using a <b>Color layer</b> when the app is sent to
/// <b>Background</b> or the <b>App Switcher</b>.
/// </summary>
/// <param name="hexColor">Hexadecimal color as <b><c>string</c></b> in the form of
/// <b><c>#RGB</c></b>, <b><c>#RGBA</c></b>, <b><c>#RRGGBB</c></b> or <b><c>#RRGGBBAA</c></b>.
/// <b>#FFFFFF</b> by default.</param>
/// <remarks>Supported for <b><c>iOS</c></b> only.</remarks>
void EnableColorScreenProtection(string hexColor);

/// <summary>
/// Removes the <b>Color layer</b> and re-enables screen content exposure.
/// </summary>
/// <remarks>Supported for <b><c>iOS</c></b> only.</remarks>
void DisableColorScreenProtection();

/// <summary>
/// Prevent screen content from being exposed by
/// using an <b>Image</b> when the app is sent to
/// <b>Background</b> or the <b>App Switcher</b>.
/// </summary>
/// <param name="image">Name with extension of the image to use.</param>
/// <remarks>Supported for <b><c>iOS</c></b> only.</remarks>
void EnableImageScreenProtection(string image);

/// <summary>
/// Removes the <b>Image</b> and re-enables screen content exposure.
/// </summary>
/// <remarks>Supported for <b><c>iOS</c></b> only.</remarks>
void DisableImageScreenProtection();

/// <summary>
/// Prevent screen content from <b>being recorded</b>
/// by the system or external app. <b>It uses the
/// Blur layer by default.</b>
/// </summary>
/// <param name="withColor">Hexadecimal color as <b><c>string</c></b> in the form of
/// <b><c>#RGB</c></b>, <b><c>#RGBA</c></b>, <b><c>#RRGGBB</c></b> or <b><c>#RRGGBBAA</c></b>.
/// It can be mixed with <paramref name="withBlur"/>.</param>
/// <param name="withBlur">Set it to <b><c>false</c></b> to deactivate screen protection with Blur.
/// It can be mixed with <paramref name="withColor"/>. <b><c>True</c> by default.</b></param>
/// <remarks>Supported for <b><c>iOS</c></b> only.</remarks>
void EnableScreenRecordingProtection(string withColor = "", bool withBlur = true);

/// <summary>
/// Turn off the screen recording protection.
/// </summary>
/// <remarks>Supported for <b><c>iOS</c></b> only.</remarks>
void DisableScreenRecordingProtection();
#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Android.Views;

namespace Plugin.Maui.ScreenSecurity;

partial class ScreenSecurityImplementation : IScreenSecurity
{
/// <summary>
/// Prevent screen content from being exposed when the app
/// is sent to <b>Background</b> or the <b>Recents screen</b>.
/// Also prevents app <b>screenshots</b> or <b>recording</b> to be taken.
/// </summary>
public void EnableScreenSecurityProtection()
{
try
{
var activity = Platform.CurrentActivity;

activity?.Window?.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
}
catch (Exception ex)
{
Console.WriteLine($"EnableScreenSecurityProtection failed with Exception message: {ex.Message}");
Console.WriteLine($"Exception Stacktrace: {ex.StackTrace}");
if (ex.InnerException != null)
Console.WriteLine($"With InnerException: {ex.InnerException}");
}
}

/// <summary>
/// Re-enables screen content exposure.
/// </summary>
public void DisableScreenSecurityProtection()
{
try
{
var activity = Platform.CurrentActivity;

activity?.Window?.ClearFlags(WindowManagerFlags.Secure);
}
catch (Exception ex)
{
Console.WriteLine($"DisableScreenSecurityProtection failed with Exception message: {ex.Message}");
Console.WriteLine($"Exception Stacktrace: {ex.StackTrace}");
if (ex.InnerException != null)
Console.WriteLine($"With InnerException: {ex.InnerException}");
}
}
}

0 comments on commit 4449fae

Please sign in to comment.