From 2c49c32b55a289a7d2d6bee96da8644f641c69d0 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Wed, 27 Dec 2023 18:28:23 +0100 Subject: [PATCH] Revert "feat(#677): add native version of privacy screen (still not happy with Android version)" This reverts commit e409089807467dc2cf91c8fcd00387b485365bbb. --- .../kotlin/de/hpi/frasecys/MainActivity.kt | 6 ++ .../main/kotlin/de/hpi/pharme/MainActivity.kt | 66 ------------------- app/ios/Runner/AppDelegate.swift | 56 ---------------- .../utilities/platform_channel_utils.dart | 29 -------- 4 files changed, 6 insertions(+), 151 deletions(-) create mode 100644 app/android/app/src/main/kotlin/de/hpi/frasecys/MainActivity.kt delete mode 100644 app/android/app/src/main/kotlin/de/hpi/pharme/MainActivity.kt delete mode 100644 app/lib/common/utilities/platform_channel_utils.dart diff --git a/app/android/app/src/main/kotlin/de/hpi/frasecys/MainActivity.kt b/app/android/app/src/main/kotlin/de/hpi/frasecys/MainActivity.kt new file mode 100644 index 000000000..f48fa7311 --- /dev/null +++ b/app/android/app/src/main/kotlin/de/hpi/frasecys/MainActivity.kt @@ -0,0 +1,6 @@ +package de.hpi.pharme + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/app/android/app/src/main/kotlin/de/hpi/pharme/MainActivity.kt b/app/android/app/src/main/kotlin/de/hpi/pharme/MainActivity.kt deleted file mode 100644 index aca0f34a1..000000000 --- a/app/android/app/src/main/kotlin/de/hpi/pharme/MainActivity.kt +++ /dev/null @@ -1,66 +0,0 @@ -package de.hpi.pharme - -import io.flutter.embedding.android.FlutterActivity -import io.flutter.embedding.engine.FlutterEngine -import io.flutter.plugin.common.MethodChannel -import android.view.WindowManager - -// Add privacy screen, based on -// https://articles.wesionary.team/securing-your-flutter-app-implementing-a-privacy-screen-61383ce09f0a - -class MainActivity: FlutterActivity() { - private val CHANNEL = "security" - - override fun configureFlutterEngine(flutterEngine: FlutterEngine) { - super.configureFlutterEngine(flutterEngine) - setupMethodChannel(flutterEngine) - } - - private fun setupMethodChannel(flutterEngine: FlutterEngine) { - MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result -> - when (call.method) { - "enableAppSecurity" -> { - enableAppSecurity() - result.success(null) - } - "disableAppSecurity" -> { - disableAppSecurity() - result.success(null) - } - else -> result.notImplemented() - } - } - } - - override fun onWindowFocusChanged(hasFocus: Boolean) { - super.onWindowFocusChanged(hasFocus) - toggleAppSecurity(hasFocus) - } - - override fun onPause() { - super.onPause() - enableAppSecurity() - } - - override fun onResume() { - super.onResume() - disableAppSecurity() - } - - private fun toggleAppSecurity(hasFocus: Boolean) { - if (hasFocus) { - disableAppSecurity() - } else { - enableAppSecurity() - } - } - - private fun enableAppSecurity() { - window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE) - - } - - private fun disableAppSecurity() { - window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) - } -} diff --git a/app/ios/Runner/AppDelegate.swift b/app/ios/Runner/AppDelegate.swift index c1c209613..70693e4a8 100644 --- a/app/ios/Runner/AppDelegate.swift +++ b/app/ios/Runner/AppDelegate.swift @@ -1,69 +1,13 @@ import UIKit import Flutter -// Add privacy screen, based on -// https://articles.wesionary.team/securing-your-flutter-app-implementing-a-privacy-screen-61383ce09f0a - @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { - private var flutterViewController: FlutterViewController! - private var securityChannel: FlutterMethodChannel! - private var blurEffectView: UIVisualEffectView? - private var isInBackground: Bool = false // Track whether app is in background - override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) - - setupFlutterCommunication() - return super.application(application, didFinishLaunchingWithOptions: launchOptions) } - - private func setupFlutterCommunication() { - flutterViewController = window?.rootViewController as? FlutterViewController - securityChannel = FlutterMethodChannel( - name: "security", - binaryMessenger: flutterViewController.binaryMessenger - ) - - securityChannel.setMethodCallHandler(handle) - } - - override func applicationWillResignActive(_ application: UIApplication) { - isInBackground = true // App will be inactive - enableAppSecurity() - } - - override func applicationDidBecomeActive(_ application: UIApplication) { - // Check if the app was in background before becoming active - if isInBackground { - disableAppSecurity() - isInBackground = false - } - } - - private func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - switch call.method { - case "enableAppSecurity": - result(nil) - case "disableAppSecurity": - result(nil) - default: - result(FlutterMethodNotImplemented) - } - } - - private func enableAppSecurity() { - let blurEffect = UIBlurEffect(style: .light) - blurEffectView = UIVisualEffectView(effect: blurEffect) - blurEffectView?.frame = window!.frame - window?.addSubview(blurEffectView!) - } - - private func disableAppSecurity() { - blurEffectView?.removeFromSuperview() - } } diff --git a/app/lib/common/utilities/platform_channel_utils.dart b/app/lib/common/utilities/platform_channel_utils.dart deleted file mode 100644 index a6ac3a842..000000000 --- a/app/lib/common/utilities/platform_channel_utils.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'dart:developer'; - -import 'package:flutter/services.dart'; - -abstract class IAppScreenPrivacy { - Future enableScreenPrivacy(); - Future disableScreenPrivacy(); -} - -class AppScreenPrivacyService extends IAppScreenPrivacy { - static const platform = MethodChannel('security'); - @override - Future disableScreenPrivacy() async { - try { - await platform.invokeMethod('disableAppSecurity'); - } on PlatformException catch (e) { - log('Failed to disable app security: "${e.message}"'); - } - } - - @override - Future enableScreenPrivacy() async { - try { - await platform.invokeMethod('enableAppSecurity'); - } on PlatformException catch (e) { - log('Failed to enable app security: "${e.message}"'); - } - } -} \ No newline at end of file