Skip to content

Commit

Permalink
[7947] Feature: Blank out app preview screen when switching apps on m…
Browse files Browse the repository at this point in the history
…obile
  • Loading branch information
bitsikka committed May 9, 2019
1 parent 3469c4a commit 7497d68
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 1 deletion.
15 changes: 14 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 @@ -14,6 +14,7 @@
import android.os.Looper;
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 +110,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 +203,18 @@ private void rejectRootedNotification() {
editor.commit();
}

private static final String BLANK_PREVIEW = "BLANK_PREVIEW";

private void setSecureFlag() {
final SharedPreferences prefs = getSharedPreferences(BLANK_PREVIEW, Context.MODE_PRIVATE);
final boolean setSecure = prefs.getBoolean(BLANK_PREVIEW, true);
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
36 changes: 36 additions & 0 deletions ios/StatusIm/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
RCTSetLogThreshold(RCTLogLevelTrace);
}

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

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"StatusIm"
Expand Down Expand Up @@ -101,4 +105,36 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
#endif
}

- (void)applicationWillResignActive:(UIApplication *)application {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"BLANK_PREVIEW"]) {
// fill screen with our own colour
UIView *colourView = [[UIView alloc]initWithFrame:self.window.frame];
colourView.backgroundColor = [UIColor whiteColor];
colourView.tag = 2019;
colourView.alpha = 0;
[self.window addSubview:colourView];
[self.window bringSubviewToFront:colourView];

// fade in the view
[UIView animateWithDuration:0.5 animations:^{
colourView.alpha = 1;
}];
}
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"BLANK_PREVIEW"]) {
// grab a reference to our coloured view
UIView *colourView = [self.window viewWithTag:2019];

// fade away colour view from main view
[UIView animateWithDuration:0.5 animations:^{
colourView.alpha = 0;
} completion:^(BOOL finished) {
// remove when finished fading
[colourView removeFromSuperview];
}];
}
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Environment;
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 @@ -962,6 +963,34 @@ public void getDeviceUUID(final Callback callback) {
callback.invoke(uniqueID);
}

private static final String BLANK_PREVIEW = "BLANK_PREVIEW";

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

private void setSecureFlag() {
final SharedPreferences prefs = this.reactContext.getSharedPreferences(BLANK_PREVIEW, Context.MODE_PRIVATE);
final boolean setSecure = prefs.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 @@ -490,6 +490,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? true
: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 @@ -212,6 +212,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
5 changes: 5 additions & 0 deletions src/status_im/ui/screens/profile/user/views.cljs
Original file line number Diff line number Diff line change
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 (or (nil? (:preview-privacy? settings)) (: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 @@ -786,6 +786,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

0 comments on commit 7497d68

Please sign in to comment.