Skip to content

Commit 42ef11e

Browse files
authored
Merge pull request #4985 from EdgeApp/william/security-screen
Hide the app contents while in the background
2 parents 134801b + f27d877 commit 42ef11e

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

android/app/src/main/java/co/edgesecure/app/MainActivity.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package co.edgesecure.app
22

33
import android.content.pm.ActivityInfo
4+
import android.os.Build
45
import android.os.Bundle
6+
import android.view.WindowManager
57
import com.facebook.react.ReactActivity
68
import com.facebook.react.ReactActivityDelegate
79
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
@@ -34,6 +36,17 @@ class MainActivity : ReactActivity() {
3436
// Do not pass the saved state, as required by react-native-screens:
3537
super.onCreate(null)
3638

39+
// Hide app contents in the background:
40+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
41+
setRecentsScreenshotEnabled(false);
42+
} else {
43+
getWindow()
44+
.setFlags(
45+
WindowManager.LayoutParams.FLAG_SECURE,
46+
WindowManager.LayoutParams.FLAG_SECURE
47+
) ;
48+
}
49+
3750
// Lock the app to portrait mode:
3851
if (resources.getBoolean(R.bool.portrait_only)) {
3952
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

ios/edge/AppDelegate.mm

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
#import <sys/errno.h>
1717
#import <UserNotifications/UserNotifications.h>
1818

19-
@implementation AppDelegate
19+
@implementation AppDelegate {
20+
// Edge addition:
21+
UIView *securityView;
22+
}
2023

2124
// From https://reactnative.dev/docs/0.71/linking#enabling-deep-links
2225
- (BOOL)application:(UIApplication *)application
@@ -148,4 +151,34 @@ - (void)application:(UIApplication *)application
148151
}];
149152
}
150153

154+
/**
155+
* Hides the app when we go into the background.
156+
* Edge addition.
157+
*/
158+
- (void)applicationDidEnterBackground:(UIApplication *)application
159+
{
160+
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
161+
UIViewController *launchScreen = [storyboard instantiateInitialViewController];
162+
if (launchScreen == nil) return;
163+
UIView *launchView = launchScreen.view;
164+
if (launchView == nil) return;
165+
166+
launchView.frame = self.window.bounds;
167+
[self.window addSubview:launchView];
168+
[self.window makeKeyAndVisible];
169+
securityView = launchView;
170+
}
171+
172+
/**
173+
* Shows the app when we come into the foreground.
174+
* Edge addition.
175+
*/
176+
- (void)applicationWillEnterForeground:(UIApplication *)application
177+
{
178+
if (securityView != nil) {
179+
[securityView removeFromSuperview];
180+
securityView = nil;
181+
}
182+
}
183+
151184
@end

0 commit comments

Comments
 (0)