From f27d877f819e157b59e3a863cd670ceb0895c62f Mon Sep 17 00:00:00 2001 From: William Swanson Date: Wed, 17 Apr 2024 12:39:44 -0700 Subject: [PATCH] Hide the app contents while in the background --- .../java/co/edgesecure/app/MainActivity.kt | 13 +++++++ ios/edge/AppDelegate.mm | 35 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/co/edgesecure/app/MainActivity.kt b/android/app/src/main/java/co/edgesecure/app/MainActivity.kt index 57be3f61588..b43b8af4c5d 100644 --- a/android/app/src/main/java/co/edgesecure/app/MainActivity.kt +++ b/android/app/src/main/java/co/edgesecure/app/MainActivity.kt @@ -1,7 +1,9 @@ package co.edgesecure.app import android.content.pm.ActivityInfo +import android.os.Build import android.os.Bundle +import android.view.WindowManager import com.facebook.react.ReactActivity import com.facebook.react.ReactActivityDelegate import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled @@ -34,6 +36,17 @@ class MainActivity : ReactActivity() { // Do not pass the saved state, as required by react-native-screens: super.onCreate(null) + // Hide app contents in the background: + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + setRecentsScreenshotEnabled(false); + } else { + getWindow() + .setFlags( + WindowManager.LayoutParams.FLAG_SECURE, + WindowManager.LayoutParams.FLAG_SECURE + ) ; + } + // Lock the app to portrait mode: if (resources.getBoolean(R.bool.portrait_only)) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT diff --git a/ios/edge/AppDelegate.mm b/ios/edge/AppDelegate.mm index 35b6c5cfb61..6f91ef2a94d 100644 --- a/ios/edge/AppDelegate.mm +++ b/ios/edge/AppDelegate.mm @@ -16,7 +16,10 @@ #import #import -@implementation AppDelegate +@implementation AppDelegate { + // Edge addition: + UIView *securityView; +} // From https://reactnative.dev/docs/0.71/linking#enabling-deep-links - (BOOL)application:(UIApplication *)application @@ -148,4 +151,34 @@ - (void)application:(UIApplication *)application }]; } +/** + * Hides the app when we go into the background. + * Edge addition. + */ +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil]; + UIViewController *launchScreen = [storyboard instantiateInitialViewController]; + if (launchScreen == nil) return; + UIView *launchView = launchScreen.view; + if (launchView == nil) return; + + launchView.frame = self.window.bounds; + [self.window addSubview:launchView]; + [self.window makeKeyAndVisible]; + securityView = launchView; +} + +/** + * Shows the app when we come into the foreground. + * Edge addition. + */ +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + if (securityView != nil) { + [securityView removeFromSuperview]; + securityView = nil; + } +} + @end