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

[7947] Feature: Blank out app preview screen when switching apps on m… #8009

Merged
merged 1 commit into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion android/app/src/main/java/im/status/ethereum/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import android.net.Uri;
import android.os.Build;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.WindowManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
Expand Down Expand Up @@ -109,7 +111,7 @@ protected void onCreate(Bundle savedInstanceState) {
final ActivityManager activityManager = getActivityManager();
Log.v("RNBootstrap", "Available system memory "+getAvailableMemory(activityManager).availMem + ", maximum usable application memory " + activityManager.getLargeMemoryClass()+"M");


setSecureFlag();
SplashScreen.show(this, true);
super.onCreate(savedInstanceState);

Expand Down Expand Up @@ -202,6 +204,16 @@ private void rejectRootedNotification() {
editor.commit();
}

private void setSecureFlag() {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
final boolean setSecure = sharedPrefs.getBoolean("BLANK_PREVIEW", false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && setSecure) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}

@TargetApi(Build.VERSION_CODES.M)
public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {
mPermissionListener = listener;
Expand Down
34 changes: 33 additions & 1 deletion ios/StatusIm/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"

@implementation AppDelegate
@implementation AppDelegate
{
UIView *_blankView;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Expand All @@ -47,13 +50,21 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
RCTSetLogThreshold(RCTLogLevelTrace);
}

NSDictionary *appDefaults = [NSDictionary
dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:@"BLANK_PREVIEW"];
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"StatusIm"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_blankView = [[UIView alloc]initWithFrame:self.window.frame];
_blankView.backgroundColor = [UIColor whiteColor];
_blankView.alpha = 0;

UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
Expand Down Expand Up @@ -101,4 +112,25 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
#endif
}

- (void)applicationWillResignActive:(UIApplication *)application {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"BLANK_PREVIEW"]) {
[self.window addSubview:_blankView];
[self.window bringSubviewToFront:_blankView];

[UIView animateWithDuration:0.5 animations:^{
_blankView.alpha = 1;
}];
}
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"BLANK_PREVIEW"]) {
[UIView animateWithDuration:0.5 animations:^{
_blankView.alpha = 0;
} completion:^(BOOL finished) {
[_blankView removeFromSuperview];
}];
}
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.v4.content.FileProvider;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
Expand Down Expand Up @@ -943,6 +945,32 @@ public void getDeviceUUID(final Callback callback) {
callback.invoke(uniqueID);
}

@ReactMethod
public void setBlankPreviewFlag(final Boolean blankPreview) {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.reactContext);
sharedPrefs.edit().putBoolean("BLANK_PREVIEW", blankPreview).commit();
setSecureFlag();
}

private void setSecureFlag() {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.reactContext);
final boolean setSecure = sharedPrefs.getBoolean("BLANK_PREVIEW", true);
final Activity activity = this.reactContext.getCurrentActivity();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
final Window window = activity.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && setSecure) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}
});
}
}

private Boolean is24Hour() {
return android.text.format.DateFormat.is24HourFormat(this.reactContext.getApplicationContext());
}
Expand Down
9 changes: 9 additions & 0 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ - (void)handleSignal:(NSString *)signal
callback(@[Identifier]);
}

RCT_EXPORT_METHOD(setBlankPreviewFlag:(BOOL *)newValue)
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

[userDefaults setBool:newValue forKey:@"BLANK_PREVIEW"];

[userDefaults synchronize];
}

- (bool) is24Hour
{
NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
Expand Down
13 changes: 13 additions & 0 deletions src/status_im/accounts/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
(fn [on]
(native-module/chaos-mode-update on (constantly nil))))

(re-frame/reg-fx
::blank-preview-flag-changed
(fn [flag]
(native-module/set-blank-preview-flag flag)))

(fx/defn show-mainnet-is-default-alert [{:keys [db]}]
(let [shown-version (get-in db [:account/account :mainnet-warning-shown-version])
current-version build/version]
Expand Down Expand Up @@ -98,6 +103,14 @@
(assoc settings :web3-opt-in? opt-in)
{})))

(fx/defn switch-preview-privacy-mode [{:keys [db] :as cofx} private?]
(let [settings (get-in db [:account/account :settings])]
(fx/merge cofx
{::blank-preview-flag-changed private?}
(accounts.update/update-settings
(assoc settings :preview-privacy? private?)
{}))))

(fx/defn update-recent-stickers [cofx stickers]
(accounts.update/account-update cofx
{:recent-stickers stickers}
Expand Down
1 change: 1 addition & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@

(defn default-account-settings []
{:web3-opt-in? true
:preview-privacy? false
:wallet {:visible-tokens {:testnet #{:STT :HND}
:mainnet #{:SNT}
:rinkeby #{:MOKSHA :KDO}
Expand Down
5 changes: 5 additions & 0 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@
(fn [cofx [_ opt-in]]
(accounts/switch-web3-opt-in-mode cofx opt-in)))

(handlers/register-handler-fx
:accounts.ui/preview-privacy-mode-switched
(fn [cofx [_ private?]]
(accounts/switch-preview-privacy-mode cofx private?)))

(handlers/register-handler-fx
:accounts.ui/wallet-set-up-confirmed
(fn [cofx [_ modal?]]
Expand Down
3 changes: 3 additions & 0 deletions src/status_im/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
(defn get-device-UUID [callback]
(native-module/get-device-UUID callback))

(defn set-blank-preview-flag [flag]
(native-module/set-blank-preview-flag flag))

(defn is24Hour []
(native-module/is24Hour))

Expand Down
3 changes: 3 additions & 0 deletions src/status_im/native_module/impl/module.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
(fn [UUID]
(callback (string/upper-case UUID)))))

(defn set-blank-preview-flag [flag]
(.setBlankPreviewFlag status flag))

(defn extract-group-membership-signatures [signature-pairs callback]
(when status
(.extractGroupMembershipSignatures status signature-pairs callback)))
Expand Down
7 changes: 6 additions & 1 deletion src/status_im/ui/screens/profile/user/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
:value value}]))

(defn- my-profile-settings [{:keys [seed-backed-up? mnemonic]}
account
{:keys [settings] :as account}
currency
logged-in?
extensions]
Expand Down Expand Up @@ -144,6 +144,11 @@
:action-fn #(re-frame/dispatch [:navigate-to :installations])
:accessibility-label :pairing-settings-button}]
[profile.components/settings-item-separator]
[profile.components/settings-switch-item
{:label-kw :t/preview-privacy
:value (boolean (:preview-privacy? settings))
:action-fn #(re-frame/dispatch [:accounts.ui/preview-privacy-mode-switched %])}]
[profile.components/settings-item-separator]
[profile.components/settings-item
{:label-kw :t/dapps-permissions
:accessibility-label :dapps-permissions-button
Expand Down
1 change: 1 addition & 0 deletions test/cljs/status_im/test/sign_in/data.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
:last-request nil
:desktop-notifications? false
:settings {:web3-opt-in? true
:preview-privacy? true
:fleet :eth.beta
:wallet {:visible-tokens {:testnet #{:STT
:HND}
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@
"currency-display-name-usd": "United States Dollar",
"currency-display-name-uah": "Ukraine Hryvnia",
"web3-opt-in": "Browser privacy mode",
"preview-privacy": "Preview privacy mode",
"recover-password-invalid": "This account already exists but passwords do not match",
"recover-keycard-account-not-supported": "Recovering keycard account with password is not supported",
"members-active-none": "no members",
Expand Down