-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
362 additions
and
435 deletions.
There are no files selected for viewing
97 changes: 85 additions & 12 deletions
97
...oid/src/main/kotlin/dz/alex/screen_protection/screen_protection/ScreenProtectionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,108 @@ | ||
package dz.alex.screen_protection.screen_protection | ||
|
||
/** Needed Android libraries **/ | ||
import android.app.Activity | ||
import android.util.Log | ||
import androidx.annotation.NonNull | ||
import android.view.WindowManager | ||
|
||
/** Flutter related **/ | ||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler | ||
import io.flutter.plugin.common.MethodChannel.Result | ||
import io.flutter.plugin.common.BinaryMessenger | ||
import io.flutter.embedding.engine.plugins.activity.ActivityAware | ||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding | ||
|
||
/** ScreenProtectionPlugin */ | ||
class ScreenProtectionPlugin: FlutterPlugin, MethodCallHandler { | ||
/// The MethodChannel that will the communication between Flutter and native Android | ||
/// | ||
/// This local reference serves to register the plugin with the Flutter Engine and unregister it | ||
/// when the Flutter Engine is detached from the Activity | ||
class ScreenProtectionPlugin: FlutterPlugin, ActivityAware { | ||
|
||
private lateinit var channel : MethodChannel | ||
private var pluginBinding: FlutterPlugin.FlutterPluginBinding? = null | ||
private var activity: FlutterActivity? = null | ||
private var binaryMessenger: BinaryMessenger? = null | ||
|
||
override fun onAttachedToActivity(binding: ActivityPluginBinding) { | ||
activity = binding.activity as FlutterActivity | ||
Log.d(TAG, "onAttachedToActivity: channel.setMethodCallHandler") | ||
channel.setMethodCallHandler { call, result -> | ||
when(call.method) { | ||
"secureScreen" -> { | ||
secureScreen() | ||
result.success(true) | ||
} | ||
"unsecureScreen" -> { | ||
unsecureScreen() | ||
result.success(true) | ||
} | ||
"toggleScreenSecurity" -> { | ||
toggleScreenSecurity() | ||
result.success(true) | ||
} | ||
"isScreenSecured" -> { | ||
result.success(isScreenSecured()) | ||
} | ||
else -> result.notImplemented() | ||
} | ||
} | ||
} | ||
|
||
override fun onDetachedFromActivityForConfigChanges() {} | ||
|
||
override fun onDetachedFromActivity() {} | ||
|
||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {} | ||
|
||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { | ||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "screen_protection") | ||
channel.setMethodCallHandler(this) | ||
binaryMessenger = flutterPluginBinding.binaryMessenger | ||
} | ||
|
||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | ||
channel.setMethodCallHandler(null) | ||
} | ||
|
||
/*override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | ||
channel.setMethodCallHandler(null) | ||
} | ||
override fun onMethodCall(call: MethodCall, result: Result) { | ||
if (call.method == "getPlatformVersion") { | ||
result.success("Android ${android.os.Build.VERSION.RELEASE}") | ||
} else { | ||
result.notImplemented() | ||
when(call.method) { | ||
"secureScreen" -> { | ||
secureScreen() | ||
result.success(true) | ||
} | ||
"unsecureScreen" -> { | ||
unsecureScreen() | ||
result.success(true) | ||
} | ||
"toggleScreenSecurity" -> { | ||
toggleScreenSecurity() | ||
result.success(true) | ||
} | ||
"isScreenSecured" -> { | ||
result.success(isScreenSecured()) | ||
} | ||
else -> result.notImplemented() | ||
} | ||
}*/ | ||
|
||
fun secureScreen() { | ||
activity?.window?.addFlags(WindowManager.LayoutParams.FLAG_SECURE) | ||
} | ||
|
||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | ||
channel.setMethodCallHandler(null) | ||
fun unsecureScreen() { | ||
activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) | ||
} | ||
|
||
fun toggleScreenSecurity() { | ||
val isFlagSecureSet = (activity?.window?.attributes?.flags ?: 0) and WindowManager.LayoutParams.FLAG_SECURE != 0 | ||
if(isFlagSecureSet) unsecureScreen() else secureScreen() | ||
} | ||
|
||
fun isScreenSecured(): Boolean { | ||
return (activity?.window?.attributes?.flags ?: 0) and WindowManager.LayoutParams.FLAG_SECURE != 0 | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
#include "Generated.xcconfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
#include "Generated.xcconfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Uncomment this line to define a global platform for your project | ||
# platform :ios, '11.0' | ||
|
||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency. | ||
ENV['COCOAPODS_DISABLE_STATS'] = 'true' | ||
|
||
project 'Runner', { | ||
'Debug' => :debug, | ||
'Profile' => :release, | ||
'Release' => :release, | ||
} | ||
|
||
def flutter_root | ||
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) | ||
unless File.exist?(generated_xcode_build_settings_path) | ||
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" | ||
end | ||
|
||
File.foreach(generated_xcode_build_settings_path) do |line| | ||
matches = line.match(/FLUTTER_ROOT\=(.*)/) | ||
return matches[1].strip if matches | ||
end | ||
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" | ||
end | ||
|
||
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) | ||
|
||
flutter_ios_podfile_setup | ||
|
||
target 'Runner' do | ||
use_frameworks! | ||
use_modular_headers! | ||
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) | ||
end | ||
|
||
post_install do |installer| | ||
installer.pods_project.targets.each do |target| | ||
flutter_additional_ios_build_settings(target) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
PODS: | ||
- Flutter (1.0.0) | ||
- screen_protection (0.0.1): | ||
- Flutter | ||
|
||
DEPENDENCIES: | ||
- Flutter (from `Flutter`) | ||
- screen_protection (from `.symlinks/plugins/screen_protection/ios`) | ||
|
||
EXTERNAL SOURCES: | ||
Flutter: | ||
:path: Flutter | ||
screen_protection: | ||
:path: ".symlinks/plugins/screen_protection/ios" | ||
|
||
SPEC CHECKSUMS: | ||
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 | ||
screen_protection: f94a6e8a06598ea276003a5cf6b4bcd641bd7802 | ||
|
||
PODFILE CHECKSUM: bfd8cb9c5a07b05028ccd5e7d27153963d4bba14 | ||
|
||
COCOAPODS: 1.12.0 |
Oops, something went wrong.