From 896e52afbfae72e8bd126c664e6be4cc4b59199c Mon Sep 17 00:00:00 2001 From: qiaowei Date: Sun, 28 Jun 2020 18:01:58 +0800 Subject: [PATCH] =?utf8?q?=E5=B1=8F=E5=B9=95=E6=88=AA=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- package-lock.json | 10 +- package.json | 5 +- platforms/android/android.json | 18 ++- platforms/android/app/build.gradle | 4 +- .../src/main/assets/www/cordova_plugins.js | 11 +- .../app/src/main/assets/www/js/main.js | 1 + .../app/src/main/assets/www/js/qrcode.js | 2 + .../java/com/coffice/ScreenshotBlocker.java | 63 ++++++++++ .../android/app/src/main/res/xml/config.xml | 4 + .../android/platform_www/cordova_plugins.js | 11 +- .../js/ourcodeworldpreventscreenshots.js | 42 +++++++ .../www/ourcodeworldpreventscreenshots.js | 45 +++++++ .../www/screenshot.js | 40 ++++++ platforms/browser/browser.json | 14 ++- .../browser/platform_www/cordova_plugins.js | 11 +- .../www/screenshot.js | 39 ++++++ platforms/ios/dlapp.xcodeproj/project.pbxproj | 12 ++ .../ScreenRecordingDetector.h | 21 ++++ .../ScreenRecordingDetector.m | 80 ++++++++++++ .../ScreenshotBlocker.h | 10 ++ .../ScreenshotBlocker.m | 119 ++++++++++++++++++ platforms/ios/dlapp/config.xml | 4 + platforms/ios/ios.json | 18 ++- platforms/ios/platform_www/cordova_plugins.js | 11 +- .../www/screenshot.js | 40 ++++++ plugins/android.json | 3 + plugins/browser.json | 3 + .../LICENSE | 21 ++++ .../package.json | 60 +++++++++ .../plugin.xml | 48 +++++++ .../com/coffice/ScreenshotBlocker.java | 63 ++++++++++ .../src/ios/ScreenRecordingDetector.h | 21 ++++ .../src/ios/ScreenRecordingDetector.m | 80 ++++++++++++ .../src/ios/ScreenshotBlocker.h | 10 ++ .../src/ios/ScreenshotBlocker.m | 119 ++++++++++++++++++ .../www/screenshot.js | 38 ++++++ plugins/fetch.json | 8 ++ plugins/ios.json | 3 + www/js/main.js | 1 - www/js/mainmenu.js | 1 - www/js/qrcode.js | 2 + 41 files changed, 1103 insertions(+), 13 deletions(-) create mode 100644 platforms/android/app/src/main/java/com/coffice/ScreenshotBlocker.java create mode 100644 platforms/android/platform_www/js/ourcodeworldpreventscreenshots.js create mode 100644 platforms/android/platform_www/plugins/com.ourcodeworld.preventscreenshots/www/ourcodeworldpreventscreenshots.js create mode 100644 platforms/android/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js create mode 100644 platforms/browser/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js create mode 100644 platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.h create mode 100644 platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.m create mode 100644 platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.h create mode 100644 platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.m create mode 100644 platforms/ios/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js create mode 100644 plugins/cordova-plugin-prevent-screenshot-coffice/LICENSE create mode 100644 plugins/cordova-plugin-prevent-screenshot-coffice/package.json create mode 100644 plugins/cordova-plugin-prevent-screenshot-coffice/plugin.xml create mode 100644 plugins/cordova-plugin-prevent-screenshot-coffice/src/android/com/coffice/ScreenshotBlocker.java create mode 100644 plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.h create mode 100644 plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.m create mode 100644 plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.h create mode 100644 plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.m create mode 100644 plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js diff --git a/package-lock.json b/package-lock.json index 0083d84..ad363bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "com.dalicitycard.app", + "name": "com.dalipolice.app", "version": "1.0.3", "lockfileVersion": 1, "requires": true, @@ -275,6 +275,10 @@ } } }, + "cordova-ourcodeworld-preventscreenshots": { + "version": "git+https://github.com/sdkcarlos/cordova-ourcodeworld-preventscreenshots.git#d96f8657cc2bc44bb23be5db68f4307a0d7d10c5", + "from": "git+https://github.com/sdkcarlos/cordova-ourcodeworld-preventscreenshots.git" + }, "cordova-plugin-add-swift-support": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/cordova-plugin-add-swift-support/-/cordova-plugin-add-swift-support-2.0.2.tgz", @@ -338,6 +342,10 @@ "resolved": "https://registry.npmjs.org/cordova-plugin-jcore/-/cordova-plugin-jcore-1.3.0.tgz", "integrity": "sha512-QmkdABlkIHFaMUBsrjPqhpaWS7wuboRPeeVEUNoc4FlZNRoQgw35v0MaW+SbOk4SzVsEGvN6IFSVqa4106ljUw==" }, + "cordova-plugin-prevent-screenshot-coffice": { + "version": "git+https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git#705e0bd6ee9029fadcfd5520bb38dc3fa408e950", + "from": "git+https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git" + }, "cordova-plugin-qrscanner": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/cordova-plugin-qrscanner/-/cordova-plugin-qrscanner-3.0.1.tgz", diff --git a/package.json b/package.json index e39792b..9a854b3 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "cordova-android": "^8.0.0", "cordova-browser": "^6.0.0", "cordova-ios": "^5.0.1", + "cordova-ourcodeworld-preventscreenshots": "git+https://github.com/sdkcarlos/cordova-ourcodeworld-preventscreenshots.git", "cordova-plugin-advanced-http": "^2.1.1", "cordova-plugin-app-version": "^0.1.9", "cordova-plugin-brightness": "^0.2.0", @@ -26,6 +27,7 @@ "cordova-plugin-fingerprint-aio": "3.0.1", "cordova-plugin-inappbrowser": "^3.0.0", "cordova-plugin-jcore": "^1.3.0", + "cordova-plugin-prevent-screenshot-coffice": "git+https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git", "cordova-plugin-qrscanner": "^3.0.1", "cordova-plugin-statusbar": "^2.4.2", "cordova-plugin-themeablebrowser": "^0.2.18", @@ -58,7 +60,8 @@ "cordova-plugin-file": {}, "cordova-plugin-fingerprint-aio": { "FACEID_USAGE_DESCRIPTION": " " - } + }, + "cordova-plugin-prevent-screenshot-coffice": {} }, "platforms": [ "android", diff --git a/platforms/android/android.json b/platforms/android/android.json index eb6d7bb..8d319b4 100644 --- a/platforms/android/android.json +++ b/platforms/android/android.json @@ -63,6 +63,10 @@ { "xml": "", "count": 1 + }, + { + "xml": "", + "count": 1 } ] } @@ -322,6 +326,9 @@ }, "cordova-plugin-fingerprint-aio": { "PACKAGE_NAME": "com.dalipolice.app" + }, + "cordova-plugin-prevent-screenshot-coffice": { + "PACKAGE_NAME": "com.dalipolice.app" } }, "dependent_plugins": {}, @@ -669,6 +676,14 @@ "clobbers": [ "Fingerprint" ] + }, + { + "id": "cordova-plugin-prevent-screenshot-coffice.screenshot", + "file": "plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js", + "pluginId": "cordova-plugin-prevent-screenshot-coffice", + "clobbers": [ + "window.plugins.preventscreenshot" + ] } ], "plugin_metadata": { @@ -689,6 +704,7 @@ "cordova-plugin-app-version": "0.1.9", "cordova-plugin-wkwebview-engine": "1.2.1", "cordova-plugin-brightness": "0.1.5", - "cordova-plugin-fingerprint-aio": "3.0.1" + "cordova-plugin-fingerprint-aio": "3.0.1", + "cordova-plugin-prevent-screenshot-coffice": "1.0.1" } } diff --git a/platforms/android/app/build.gradle b/platforms/android/app/build.gradle index 31d4b5c..e758e33 100644 --- a/platforms/android/app/build.gradle +++ b/platforms/android/app/build.gradle @@ -174,8 +174,8 @@ android { ndk { abiFilters "armeabi" } - versionCode 14 - versionName '1.4.1' + versionCode 15 + versionName '1.4.2' targetSdkVersion 28 } lintOptions { diff --git a/platforms/android/app/src/main/assets/www/cordova_plugins.js b/platforms/android/app/src/main/assets/www/cordova_plugins.js index dbec6c3..a989701 100644 --- a/platforms/android/app/src/main/assets/www/cordova_plugins.js +++ b/platforms/android/app/src/main/assets/www/cordova_plugins.js @@ -343,6 +343,14 @@ cordova.define('cordova/plugin_list', function(require, exports, module) { "clobbers": [ "Fingerprint" ] + }, + { + "id": "cordova-plugin-prevent-screenshot-coffice.screenshot", + "file": "plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js", + "pluginId": "cordova-plugin-prevent-screenshot-coffice", + "clobbers": [ + "window.plugins.preventscreenshot" + ] } ]; module.exports.metadata = { @@ -363,6 +371,7 @@ cordova.define('cordova/plugin_list', function(require, exports, module) { "cordova-plugin-app-version": "0.1.9", "cordova-plugin-wkwebview-engine": "1.2.1", "cordova-plugin-brightness": "0.1.5", - "cordova-plugin-fingerprint-aio": "3.0.1" + "cordova-plugin-fingerprint-aio": "3.0.1", + "cordova-plugin-prevent-screenshot-coffice": "1.0.1" }; }); \ No newline at end of file diff --git a/platforms/android/app/src/main/assets/www/js/main.js b/platforms/android/app/src/main/assets/www/js/main.js index 78b896f..f302033 100644 --- a/platforms/android/app/src/main/assets/www/js/main.js +++ b/platforms/android/app/src/main/assets/www/js/main.js @@ -44,6 +44,7 @@ var app = { } }); var uid = window.localStorage.getItem("uid"); + window.JPush.setAlias({ sequence: 1, alias: uid }, (result) => { var sequence = result.sequence diff --git a/platforms/android/app/src/main/assets/www/js/qrcode.js b/platforms/android/app/src/main/assets/www/js/qrcode.js index 2b06b32..016f2d7 100644 --- a/platforms/android/app/src/main/assets/www/js/qrcode.js +++ b/platforms/android/app/src/main/assets/www/js/qrcode.js @@ -26,6 +26,8 @@ var app = { e.preventDefault(); app.backTo(); }, false); + + window.plugins.preventscreenshot.disable(function(ret){}, function(ret){}); }, loadQrcode: function() { $.showLoading("加载中"); diff --git a/platforms/android/app/src/main/java/com/coffice/ScreenshotBlocker.java b/platforms/android/app/src/main/java/com/coffice/ScreenshotBlocker.java new file mode 100644 index 0000000..fe9cde3 --- /dev/null +++ b/platforms/android/app/src/main/java/com/coffice/ScreenshotBlocker.java @@ -0,0 +1,63 @@ +package com.coffice; + +import android.app.Activity; +import android.view.WindowManager; + +import org.apache.cordova.*; +import org.json.JSONArray; +import org.json.JSONException; + +public class ScreenshotBlocker extends CordovaPlugin{ + private com.coffice.ScreenshotBlocker mContext; + + @Override + public void initialize(CordovaInterface cordova, CordovaWebView webView) { + super.initialize(cordova, webView); + Activity activity = this.cordova.getActivity(); + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + + @Override + public boolean execute(String action, JSONArray data, final CallbackContext callbackContext) throws JSONException { + mContext = this; + if (action.equals("enable")) { + mContext.cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + try{ + // Allow to make screenshots removing the FLAG_SECURE + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { + mContext.cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + callbackContext.success("Success"); + }catch(Exception e){ + callbackContext.error(e.toString()); + } + } + }); + + return true; + }else if (action.equals("disable")) { + mContext.cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + try{ + // Allow to make screenshots removing the FLAG_SECURE + // Disable the creation of screenshots adding the FLAG_SECURE to the window + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { + mContext.cordova.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, + WindowManager.LayoutParams.FLAG_SECURE); + } + callbackContext.success("Success"); + }catch(Exception e){ + callbackContext.error(e.toString()); + } + } + }); + return true; + } + else{ + return false; + } + + } + +} diff --git a/platforms/android/app/src/main/res/xml/config.xml b/platforms/android/app/src/main/res/xml/config.xml index ca7b3a0..019dfb6 100644 --- a/platforms/android/app/src/main/res/xml/config.xml +++ b/platforms/android/app/src/main/res/xml/config.xml @@ -43,6 +43,10 @@ + + + + dlapp A sample Apache Cordova application that responds to the deviceready event. diff --git a/platforms/android/platform_www/cordova_plugins.js b/platforms/android/platform_www/cordova_plugins.js index dbec6c3..a989701 100644 --- a/platforms/android/platform_www/cordova_plugins.js +++ b/platforms/android/platform_www/cordova_plugins.js @@ -343,6 +343,14 @@ cordova.define('cordova/plugin_list', function(require, exports, module) { "clobbers": [ "Fingerprint" ] + }, + { + "id": "cordova-plugin-prevent-screenshot-coffice.screenshot", + "file": "plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js", + "pluginId": "cordova-plugin-prevent-screenshot-coffice", + "clobbers": [ + "window.plugins.preventscreenshot" + ] } ]; module.exports.metadata = { @@ -363,6 +371,7 @@ cordova.define('cordova/plugin_list', function(require, exports, module) { "cordova-plugin-app-version": "0.1.9", "cordova-plugin-wkwebview-engine": "1.2.1", "cordova-plugin-brightness": "0.1.5", - "cordova-plugin-fingerprint-aio": "3.0.1" + "cordova-plugin-fingerprint-aio": "3.0.1", + "cordova-plugin-prevent-screenshot-coffice": "1.0.1" }; }); \ No newline at end of file diff --git a/platforms/android/platform_www/js/ourcodeworldpreventscreenshots.js b/platforms/android/platform_www/js/ourcodeworldpreventscreenshots.js new file mode 100644 index 0000000..027f152 --- /dev/null +++ b/platforms/android/platform_www/js/ourcodeworldpreventscreenshots.js @@ -0,0 +1,42 @@ +/*global cordova, module*/ +(function(module){ + function PreventScreenshots(){ + var core = {}; + var isEnabled = true; + + var callFunctionIfExists = function(fn,params){ + if(typeof(fn) !== "function"){ + return false; + } + + fn.call(); + return true; + }; + + core.enable = function(success,error){ + cordova.exec(function(data){ + isEnabled = true; + callFunctionIfExists(success); + }, function(err){ + callFunctionIfExists(error); + }, "OurCodeWorldpreventscreenshots", "enable", []); + }; + + core.disable = function(success,error){ + cordova.exec(function(data){ + isEnabled = false; + callFunctionIfExists(success); + }, function(err){ + callFunctionIfExists(error); + }, "OurCodeWorldpreventscreenshots", "disable", []); + }; + + core.isEnabled = function(){ + return isEnabled; + }; + + return core; + } + + module.exports = new PreventScreenshots(); +})(module); diff --git a/platforms/android/platform_www/plugins/com.ourcodeworld.preventscreenshots/www/ourcodeworldpreventscreenshots.js b/platforms/android/platform_www/plugins/com.ourcodeworld.preventscreenshots/www/ourcodeworldpreventscreenshots.js new file mode 100644 index 0000000..e6e6879 --- /dev/null +++ b/platforms/android/platform_www/plugins/com.ourcodeworld.preventscreenshots/www/ourcodeworldpreventscreenshots.js @@ -0,0 +1,45 @@ +cordova.define("com.ourcodeworld.preventscreenshots.OurCodeWorldpreventscreenshots", function(require, exports, module) { +/*global cordova, module*/ +(function(module){ + function PreventScreenshots(){ + var core = {}; + var isEnabled = true; + + var callFunctionIfExists = function(fn,params){ + if(typeof(fn) !== "function"){ + return false; + } + + fn.call(); + return true; + }; + + core.enable = function(success,error){ + cordova.exec(function(data){ + isEnabled = true; + callFunctionIfExists(success); + }, function(err){ + callFunctionIfExists(error); + }, "OurCodeWorldpreventscreenshots", "enable", []); + }; + + core.disable = function(success,error){ + cordova.exec(function(data){ + isEnabled = false; + callFunctionIfExists(success); + }, function(err){ + callFunctionIfExists(error); + }, "OurCodeWorldpreventscreenshots", "disable", []); + }; + + core.isEnabled = function(){ + return isEnabled; + }; + + return core; + } + + module.exports = new PreventScreenshots(); +})(module); + +}); diff --git a/platforms/android/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js b/platforms/android/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js new file mode 100644 index 0000000..eaf17d5 --- /dev/null +++ b/platforms/android/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js @@ -0,0 +1,40 @@ +cordova.define("cordova-plugin-prevent-screenshot-coffice.screenshot", function(require, exports, module) { +var screenshot = { + enable: function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, 'screenshotName', 'enable', []); + }, + disable: function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, 'screenshotName', 'disable', []); + }, + registerListener : function(callback) { + cordova.exec(callback, callback, 'screenshotName', 'listen', []); + + } +} + +cordova.addConstructor(function () { + if (!window.plugins) {window.plugins = {};} + + window.plugins.preventscreenshot = screenshot; + document.addEventListener("onTookScreenshot",function(){ + console.log('tookScreenshot'); + }); + document.addEventListener("onGoingBackground",function(){ + console.log('BackgroundCalled'); + }); + screenshot.registerListener(function(me) { + console.log('received listener:',me); + if(me === "background") { + var event = new Event('onGoingBackground'); + document.dispatchEvent(event); + return; + } + if(me === "tookScreenshot") { + var event = new Event('onTookScreenshot'); + document.dispatchEvent(event); + return; + } + }); + return window.plugins.preventscreenshot; +}); +}); diff --git a/platforms/browser/browser.json b/platforms/browser/browser.json index 4b3e322..0661c52 100644 --- a/platforms/browser/browser.json +++ b/platforms/browser/browser.json @@ -105,6 +105,9 @@ }, "cordova-plugin-fingerprint-aio": { "PACKAGE_NAME": "com.dalicitycard.app" + }, + "cordova-plugin-prevent-screenshot-coffice": { + "PACKAGE_NAME": "com.dalipolice.app" } }, "dependent_plugins": {}, @@ -478,6 +481,14 @@ "clobbers": [ "Fingerprint" ] + }, + { + "file": "plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js", + "id": "cordova-plugin-prevent-screenshot-coffice.screenshot", + "pluginId": "cordova-plugin-prevent-screenshot-coffice", + "clobbers": [ + "window.plugins.preventscreenshot" + ] } ], "plugin_metadata": { @@ -498,6 +509,7 @@ "cordova-plugin-app-version": "0.1.9", "cordova-plugin-wkwebview-engine": "1.2.1", "cordova-plugin-brightness": "0.1.5", - "cordova-plugin-fingerprint-aio": "3.0.1" + "cordova-plugin-fingerprint-aio": "3.0.1", + "cordova-plugin-prevent-screenshot-coffice": "1.0.1" } } diff --git a/platforms/browser/platform_www/cordova_plugins.js b/platforms/browser/platform_www/cordova_plugins.js index 41eda28..aca6ac1 100644 --- a/platforms/browser/platform_www/cordova_plugins.js +++ b/platforms/browser/platform_www/cordova_plugins.js @@ -369,6 +369,14 @@ module.exports = [ "clobbers": [ "Fingerprint" ] + }, + { + "file": "plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js", + "id": "cordova-plugin-prevent-screenshot-coffice.screenshot", + "pluginId": "cordova-plugin-prevent-screenshot-coffice", + "clobbers": [ + "window.plugins.preventscreenshot" + ] } ]; module.exports.metadata = @@ -391,7 +399,8 @@ module.exports.metadata = "cordova-plugin-app-version": "0.1.9", "cordova-plugin-wkwebview-engine": "1.2.1", "cordova-plugin-brightness": "0.1.5", - "cordova-plugin-fingerprint-aio": "3.0.1" + "cordova-plugin-fingerprint-aio": "3.0.1", + "cordova-plugin-prevent-screenshot-coffice": "1.0.1" } // BOTTOM OF METADATA }); \ No newline at end of file diff --git a/platforms/browser/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js b/platforms/browser/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js new file mode 100644 index 0000000..120688f --- /dev/null +++ b/platforms/browser/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js @@ -0,0 +1,39 @@ +cordova.define("cordova-plugin-prevent-screenshot-coffice.screenshot", function(require, exports, module) { var screenshot = { + enable: function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, 'screenshotName', 'enable', []); + }, + disable: function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, 'screenshotName', 'disable', []); + }, + registerListener : function(callback) { + cordova.exec(callback, callback, 'screenshotName', 'listen', []); + + } +} + +cordova.addConstructor(function () { + if (!window.plugins) {window.plugins = {};} + + window.plugins.preventscreenshot = screenshot; + document.addEventListener("onTookScreenshot",function(){ + console.log('tookScreenshot'); + }); + document.addEventListener("onGoingBackground",function(){ + console.log('BackgroundCalled'); + }); + screenshot.registerListener(function(me) { + console.log('received listener:',me); + if(me === "background") { + var event = new Event('onGoingBackground'); + document.dispatchEvent(event); + return; + } + if(me === "tookScreenshot") { + var event = new Event('onTookScreenshot'); + document.dispatchEvent(event); + return; + } + }); + return window.plugins.preventscreenshot; +}); +}); diff --git a/platforms/ios/dlapp.xcodeproj/project.pbxproj b/platforms/ios/dlapp.xcodeproj/project.pbxproj index a0dceb2..361fbf5 100644 --- a/platforms/ios/dlapp.xcodeproj/project.pbxproj +++ b/platforms/ios/dlapp.xcodeproj/project.pbxproj @@ -65,6 +65,8 @@ F939AD8D22BB769B006B371B /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = F939AD8C22BB769B006B371B /* libsqlite3.0.tbd */; }; FDE92C386167415E8040F8AB /* AFURLResponseSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = FDEE8379D7A34C55A616F700 /* AFURLResponseSerialization.m */; }; 81B8C05354704A02AE1560A0 /* Fingerprint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39BDB5993A0D495C9E97E995 /* Fingerprint.swift */; }; + F70AC332CD71455D9E103429 /* ScreenshotBlocker.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD5959A12D340C3AB8685C0 /* ScreenshotBlocker.m */; }; + 1ED02270B4D74F8BB970350D /* ScreenRecordingDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = E806644FDDDD4DB9B0A7D6E4 /* ScreenRecordingDetector.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -198,6 +200,10 @@ FE0B455916A4481681D59FE0 /* WebKit.framework */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 39BDB5993A0D495C9E97E995 /* Fingerprint.swift */ = {isa = PBXFileReference; name = "Fingerprint.swift"; path = "cordova-plugin-fingerprint-aio/Fingerprint.swift"; sourceTree = ""; fileEncoding = 4; lastKnownFileType = sourcecode.swift; explicitFileType = undefined; includeInIndex = 0; }; 705239B1B7D9402DA8A9FDA7 /* Bridging-Header.h */ = {isa = PBXFileReference; name = "Bridging-Header.h"; path = "cordova-plugin-fingerprint-aio/Bridging-Header.h"; sourceTree = ""; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; explicitFileType = undefined; includeInIndex = 0; }; + 8BD5959A12D340C3AB8685C0 /* ScreenshotBlocker.m */ = {isa = PBXFileReference; name = "ScreenshotBlocker.m"; path = "cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.m"; sourceTree = ""; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; explicitFileType = undefined; includeInIndex = 0; }; + E806644FDDDD4DB9B0A7D6E4 /* ScreenRecordingDetector.m */ = {isa = PBXFileReference; name = "ScreenRecordingDetector.m"; path = "cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.m"; sourceTree = ""; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; explicitFileType = undefined; includeInIndex = 0; }; + 5FA4467FDA284333A275FA08 /* ScreenshotBlocker.h */ = {isa = PBXFileReference; name = "ScreenshotBlocker.h"; path = "cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.h"; sourceTree = ""; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; explicitFileType = undefined; includeInIndex = 0; }; + 6C8C62629761432796084184 /* ScreenRecordingDetector.h */ = {isa = PBXFileReference; name = "ScreenRecordingDetector.h"; path = "cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.h"; sourceTree = ""; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; explicitFileType = undefined; includeInIndex = 0; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -409,6 +415,10 @@ 817A61F7D48245FA9567B115 /* Brightness.h */, 39BDB5993A0D495C9E97E995 /* Fingerprint.swift */, 705239B1B7D9402DA8A9FDA7 /* Bridging-Header.h */, + 8BD5959A12D340C3AB8685C0 /* ScreenshotBlocker.m */, + E806644FDDDD4DB9B0A7D6E4 /* ScreenRecordingDetector.m */, + 5FA4467FDA284333A275FA08 /* ScreenshotBlocker.h */, + 6C8C62629761432796084184 /* ScreenRecordingDetector.h */, ); name = Plugins; path = dlapp/Plugins; @@ -602,6 +612,8 @@ 1F969D21D7EF4CF1A547A1DF /* CDVWKProcessPoolFactory.m in Sources */, C0A6FD40F47B434496535606 /* Brightness.m in Sources */, 81B8C05354704A02AE1560A0 /* Fingerprint.swift in Sources */, + F70AC332CD71455D9E103429 /* ScreenshotBlocker.m in Sources */, + 1ED02270B4D74F8BB970350D /* ScreenRecordingDetector.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.h b/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.h new file mode 100644 index 0000000..15e0a26 --- /dev/null +++ b/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.h @@ -0,0 +1,21 @@ +// +// ScreenRecordingDetector.h +// + +/* +ScreenRecordingDetector checks for screen capturing as well as airplay mirroring +*/ + +#import +#import + +extern NSString *kScreenRecordingDetectorRecordingStatusChangedNotification; + +@interface ScreenRecordingDetector : NSObject + ++(instancetype)sharedInstance; ++ (void)triggerDetectorTimer; ++ (void)stopDetectorTimer; +- (BOOL)isRecording; + +@end \ No newline at end of file diff --git a/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.m b/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.m new file mode 100644 index 0000000..a7252e8 --- /dev/null +++ b/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.m @@ -0,0 +1,80 @@ +// +// ScreenRecordingDetector.m +// ScreenCaptureDetector +// +// + +#import "ScreenRecordingDetector.h" +float const kScreenRecordingDetectorTimerInterval = 1.0; +NSString *kScreenRecordingDetectorRecordingStatusChangedNotification = @"kScreenRecordingDetectorRecordingStatusChangedNotification"; + +@interface ScreenRecordingDetector() + +@property BOOL lastRecordingState; +@property NSTimer *timer; + +@end +@implementation ScreenRecordingDetector + + ++ (instancetype)sharedInstance { + static ScreenRecordingDetector *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[self alloc] init]; + }); + return sharedInstance; +} +- (id)init { + if (self = [super init]) { + // do some init stuff here.. + self.lastRecordingState = NO; // initially the recording state is 'NO'. This is the default state. + self.timer = NULL; + } + return self; +} +- (BOOL)isRecording { + for (UIScreen *screen in UIScreen.screens) { + if ([screen respondsToSelector:@selector(isCaptured)]) { + // iOS 11+ has isCaptured method. + if ([screen performSelector:@selector(isCaptured)]) { + return YES; // screen capture is active + } else if (screen.mirroredScreen) { + return YES; // mirroring is active + } + } else { + // iOS version below 11.0 + if (screen.mirroredScreen) + return YES; + } + } + return NO; +} ++ (void)triggerDetectorTimer { + + ScreenRecordingDetector *detector = [ScreenRecordingDetector sharedInstance]; + if (detector.timer) { + [self stopDetectorTimer]; + } + detector.timer = [NSTimer scheduledTimerWithTimeInterval:kScreenRecordingDetectorTimerInterval + target:detector + selector:@selector(checkCurrentRecordingStatus:) + userInfo:nil + repeats:YES]; +} +- (void)checkCurrentRecordingStatus:(NSTimer *)timer { + BOOL isRecording = [self isRecording]; + if (isRecording != self.lastRecordingState) { + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center postNotificationName: kScreenRecordingDetectorRecordingStatusChangedNotification object:nil]; + } + self.lastRecordingState = isRecording; +} ++ (void)stopDetectorTimer { + ScreenRecordingDetector *detector = [ScreenRecordingDetector sharedInstance]; + if (detector.timer) { + [detector.timer invalidate]; + detector.timer = NULL; + } +} +@end \ No newline at end of file diff --git a/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.h b/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.h new file mode 100644 index 0000000..a1db059 --- /dev/null +++ b/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.h @@ -0,0 +1,10 @@ +#import +#import "ScreenRecordingDetector.h" + + +@interface ScreenshotBlocker : CDVPlugin + +- (void)enable:(CDVInvokedUrlCommand*)command; +-(void)listen:(CDVInvokedUrlCommand*)command; + +@end diff --git a/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.m b/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.m new file mode 100644 index 0000000..8397d55 --- /dev/null +++ b/platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.m @@ -0,0 +1,119 @@ +#import "ScreenshotBlocker.h" +@interface ScreenshotBlocker() { + CDVInvokedUrlCommand * _eventCommand; +} +@end + +@implementation ScreenshotBlocker +UIImageView* cover; +- (void)pluginInitialize { + NSLog(@"Starting ScreenshotBlocker plugin"); + + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(appDidBecomeActive) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(applicationWillResignActive) + name:UIApplicationWillResignActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(tookScreeshot) + name:UIApplicationUserDidTakeScreenshotNotification + object:nil]; + + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(goingBackground) + name:UIApplicationWillResignActiveNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(screenCaptureStatusChanged) + name:kScreenRecordingDetectorRecordingStatusChangedNotification + object:nil]; + + /* + userDidTakeScreenshotNotification + */ + +} + +- (void)enable:(CDVInvokedUrlCommand *)command +{ + CDVPluginResult* pluginResult = nil; + NSLog(@"Abilita observers"); + /* + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(appDidBecomeActive) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(applicationWillResignActive) + name:UIApplicationWillResignActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(screenCaptureStatusChanged) + name:kScreenRecordingDetectorRecordingStatusChangedNotification + object:nil]; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + */ +} +-(void)listen:(CDVInvokedUrlCommand*)command { + _eventCommand = command; +} + + +-(void) goingBackground { + NSLog(@"Me la scattion in bck"); + if(_eventCommand!=nil) { + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"background"]; + [pluginResult setKeepCallbackAsBool:YES]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:_eventCommand.callbackId]; + } +} +-(void)tookScreeshot { + NSLog(@"fatta la foto?"); + if(_eventCommand!=nil) { + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"tookScreenshot"]; + [pluginResult setKeepCallbackAsBool:YES]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:_eventCommand.callbackId]; + } + +} + +-(void)setupView { + BOOL isCaptured = [[UIScreen mainScreen] isCaptured]; + NSLog(@"Is screen captured? %@", (isCaptured?@"SI":@"NO")); + + if ([[ScreenRecordingDetector sharedInstance] isRecording]) { + [self webView].alpha = 0.f; + NSLog(@"Registro o prendo screenshots"); + } else { + [self webView].alpha = 1.f; + NSLog(@"Non registro"); + + } +} + +-(void)appDidBecomeActive { + [ScreenRecordingDetector triggerDetectorTimer]; + if(cover!=nil) { + [cover removeFromSuperview]; + cover = nil; + } +} +-(void)applicationWillResignActive { + [ScreenRecordingDetector stopDetectorTimer]; + if(cover == nil) { + cover = [[UIImageView alloc] initWithFrame:[self.webView frame]]; + cover.backgroundColor = [UIColor blackColor]; + [self.webView addSubview:cover]; + } +} +-(void)screenCaptureStatusChanged { + [self setupView]; +} + + +@end diff --git a/platforms/ios/dlapp/config.xml b/platforms/ios/dlapp/config.xml index 90986af..8fb53bc 100755 --- a/platforms/ios/dlapp/config.xml +++ b/platforms/ios/dlapp/config.xml @@ -67,6 +67,10 @@ + + + + dlapp A sample Apache Cordova application that responds to the deviceready event. diff --git a/platforms/ios/ios.json b/platforms/ios/ios.json index 8247df1..2cc797d 100644 --- a/platforms/ios/ios.json +++ b/platforms/ios/ios.json @@ -83,6 +83,10 @@ { "xml": "", "count": 1 + }, + { + "xml": "", + "count": 1 } ] } @@ -209,6 +213,9 @@ "cordova-plugin-fingerprint-aio": { "FACEID_USAGE_DESCRIPTION": " ", "PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)" + }, + "cordova-plugin-prevent-screenshot-coffice": { + "PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)" } }, "dependent_plugins": {}, @@ -572,6 +579,14 @@ "clobbers": [ "Fingerprint" ] + }, + { + "id": "cordova-plugin-prevent-screenshot-coffice.screenshot", + "file": "plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js", + "pluginId": "cordova-plugin-prevent-screenshot-coffice", + "clobbers": [ + "window.plugins.preventscreenshot" + ] } ], "plugin_metadata": { @@ -592,6 +607,7 @@ "cordova-plugin-app-version": "0.1.9", "cordova-plugin-wkwebview-engine": "1.2.1", "cordova-plugin-brightness": "0.1.5", - "cordova-plugin-fingerprint-aio": "3.0.1" + "cordova-plugin-fingerprint-aio": "3.0.1", + "cordova-plugin-prevent-screenshot-coffice": "1.0.1" } } diff --git a/platforms/ios/platform_www/cordova_plugins.js b/platforms/ios/platform_www/cordova_plugins.js index ed613ac..b4d865e 100644 --- a/platforms/ios/platform_www/cordova_plugins.js +++ b/platforms/ios/platform_www/cordova_plugins.js @@ -359,6 +359,14 @@ cordova.define('cordova/plugin_list', function(require, exports, module) { "clobbers": [ "Fingerprint" ] + }, + { + "id": "cordova-plugin-prevent-screenshot-coffice.screenshot", + "file": "plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js", + "pluginId": "cordova-plugin-prevent-screenshot-coffice", + "clobbers": [ + "window.plugins.preventscreenshot" + ] } ]; module.exports.metadata = { @@ -379,6 +387,7 @@ cordova.define('cordova/plugin_list', function(require, exports, module) { "cordova-plugin-app-version": "0.1.9", "cordova-plugin-wkwebview-engine": "1.2.1", "cordova-plugin-brightness": "0.1.5", - "cordova-plugin-fingerprint-aio": "3.0.1" + "cordova-plugin-fingerprint-aio": "3.0.1", + "cordova-plugin-prevent-screenshot-coffice": "1.0.1" }; }); \ No newline at end of file diff --git a/platforms/ios/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js b/platforms/ios/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js new file mode 100644 index 0000000..eaf17d5 --- /dev/null +++ b/platforms/ios/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js @@ -0,0 +1,40 @@ +cordova.define("cordova-plugin-prevent-screenshot-coffice.screenshot", function(require, exports, module) { +var screenshot = { + enable: function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, 'screenshotName', 'enable', []); + }, + disable: function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, 'screenshotName', 'disable', []); + }, + registerListener : function(callback) { + cordova.exec(callback, callback, 'screenshotName', 'listen', []); + + } +} + +cordova.addConstructor(function () { + if (!window.plugins) {window.plugins = {};} + + window.plugins.preventscreenshot = screenshot; + document.addEventListener("onTookScreenshot",function(){ + console.log('tookScreenshot'); + }); + document.addEventListener("onGoingBackground",function(){ + console.log('BackgroundCalled'); + }); + screenshot.registerListener(function(me) { + console.log('received listener:',me); + if(me === "background") { + var event = new Event('onGoingBackground'); + document.dispatchEvent(event); + return; + } + if(me === "tookScreenshot") { + var event = new Event('onTookScreenshot'); + document.dispatchEvent(event); + return; + } + }); + return window.plugins.preventscreenshot; +}); +}); diff --git a/plugins/android.json b/plugins/android.json index 638fa31..9a8f6c7 100644 --- a/plugins/android.json +++ b/plugins/android.json @@ -57,6 +57,9 @@ }, "cordova-plugin-fingerprint-aio": { "PACKAGE_NAME": "com.dalicitycard.app" + }, + "cordova-plugin-prevent-screenshot-coffice": { + "PACKAGE_NAME": "com.dalipolice.app" } }, "dependent_plugins": { diff --git a/plugins/browser.json b/plugins/browser.json index 34b89f7..238e803 100644 --- a/plugins/browser.json +++ b/plugins/browser.json @@ -56,6 +56,9 @@ }, "cordova-plugin-fingerprint-aio": { "PACKAGE_NAME": "com.dalicitycard.app" + }, + "cordova-plugin-prevent-screenshot-coffice": { + "PACKAGE_NAME": "com.dalipolice.app" } }, "dependent_plugins": { diff --git a/plugins/cordova-plugin-prevent-screenshot-coffice/LICENSE b/plugins/cordova-plugin-prevent-screenshot-coffice/LICENSE new file mode 100644 index 0000000..2562c37 --- /dev/null +++ b/plugins/cordova-plugin-prevent-screenshot-coffice/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 flotrugliocoffice + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/plugins/cordova-plugin-prevent-screenshot-coffice/package.json b/plugins/cordova-plugin-prevent-screenshot-coffice/package.json new file mode 100644 index 0000000..ef61742 --- /dev/null +++ b/plugins/cordova-plugin-prevent-screenshot-coffice/package.json @@ -0,0 +1,60 @@ +{ + "_from": "git+https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git", + "_id": "cordova-plugin-prevent-screenshot-coffice@1.0.1", + "_inBundle": false, + "_integrity": "", + "_location": "/cordova-plugin-prevent-screenshot-coffice", + "_phantomChildren": {}, + "_requested": { + "type": "git", + "raw": "https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git", + "rawSpec": "https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git", + "saveSpec": "git+https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git", + "fetchSpec": "https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git", + "gitCommittish": null + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "git+https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git#705e0bd6ee9029fadcfd5520bb38dc3fa408e950", + "_spec": "https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git", + "_where": "/Users/shuwei/works2/cordova/dlapp", + "author": { + "name": "Francesco Lo Truglio", + "email": "flotruglio@cofficegroup.com", + "url": "https://www.cofficegroup.com" + }, + "bugs": { + "url": "https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice/issues" + }, + "bundleDependencies": false, + "cordova": { + "id": "cordova-plugin-prevent-screenshot-coffice", + "platforms": [ + "ios", + "android" + ] + }, + "deprecated": false, + "description": "Cordova plugin for prevent screenCapture", + "homepage": "https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice#readme", + "keywords": [ + "cordova", + "screencapture", + "ecosystem:cordova", + "cordova-android", + "cordova-ios" + ], + "license": "MIT", + "name": "cordova-plugin-prevent-screenshot-coffice", + "repository": { + "type": "git", + "url": "git+https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git" + }, + "scripts": { + "postversion": "git push && git push --tags", + "version": "replace -s 'version=\"(.+)(?=\">)' 'version=\"'$npm_package_version plugin.xml && git add plugin.xml" + }, + "version": "1.0.1" +} diff --git a/plugins/cordova-plugin-prevent-screenshot-coffice/plugin.xml b/plugins/cordova-plugin-prevent-screenshot-coffice/plugin.xml new file mode 100644 index 0000000..df73cab --- /dev/null +++ b/plugins/cordova-plugin-prevent-screenshot-coffice/plugin.xml @@ -0,0 +1,48 @@ + + + cordova-plugin-prevent-screenshot-coffice + Cordova plugin for prevent screenCapture + MIT + cordova + https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice + https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice/issues + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/cordova-plugin-prevent-screenshot-coffice/src/android/com/coffice/ScreenshotBlocker.java b/plugins/cordova-plugin-prevent-screenshot-coffice/src/android/com/coffice/ScreenshotBlocker.java new file mode 100644 index 0000000..fe9cde3 --- /dev/null +++ b/plugins/cordova-plugin-prevent-screenshot-coffice/src/android/com/coffice/ScreenshotBlocker.java @@ -0,0 +1,63 @@ +package com.coffice; + +import android.app.Activity; +import android.view.WindowManager; + +import org.apache.cordova.*; +import org.json.JSONArray; +import org.json.JSONException; + +public class ScreenshotBlocker extends CordovaPlugin{ + private com.coffice.ScreenshotBlocker mContext; + + @Override + public void initialize(CordovaInterface cordova, CordovaWebView webView) { + super.initialize(cordova, webView); + Activity activity = this.cordova.getActivity(); + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + + @Override + public boolean execute(String action, JSONArray data, final CallbackContext callbackContext) throws JSONException { + mContext = this; + if (action.equals("enable")) { + mContext.cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + try{ + // Allow to make screenshots removing the FLAG_SECURE + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { + mContext.cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + callbackContext.success("Success"); + }catch(Exception e){ + callbackContext.error(e.toString()); + } + } + }); + + return true; + }else if (action.equals("disable")) { + mContext.cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + try{ + // Allow to make screenshots removing the FLAG_SECURE + // Disable the creation of screenshots adding the FLAG_SECURE to the window + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { + mContext.cordova.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, + WindowManager.LayoutParams.FLAG_SECURE); + } + callbackContext.success("Success"); + }catch(Exception e){ + callbackContext.error(e.toString()); + } + } + }); + return true; + } + else{ + return false; + } + + } + +} diff --git a/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.h b/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.h new file mode 100644 index 0000000..15e0a26 --- /dev/null +++ b/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.h @@ -0,0 +1,21 @@ +// +// ScreenRecordingDetector.h +// + +/* +ScreenRecordingDetector checks for screen capturing as well as airplay mirroring +*/ + +#import +#import + +extern NSString *kScreenRecordingDetectorRecordingStatusChangedNotification; + +@interface ScreenRecordingDetector : NSObject + ++(instancetype)sharedInstance; ++ (void)triggerDetectorTimer; ++ (void)stopDetectorTimer; +- (BOOL)isRecording; + +@end \ No newline at end of file diff --git a/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.m b/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.m new file mode 100644 index 0000000..a7252e8 --- /dev/null +++ b/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.m @@ -0,0 +1,80 @@ +// +// ScreenRecordingDetector.m +// ScreenCaptureDetector +// +// + +#import "ScreenRecordingDetector.h" +float const kScreenRecordingDetectorTimerInterval = 1.0; +NSString *kScreenRecordingDetectorRecordingStatusChangedNotification = @"kScreenRecordingDetectorRecordingStatusChangedNotification"; + +@interface ScreenRecordingDetector() + +@property BOOL lastRecordingState; +@property NSTimer *timer; + +@end +@implementation ScreenRecordingDetector + + ++ (instancetype)sharedInstance { + static ScreenRecordingDetector *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[self alloc] init]; + }); + return sharedInstance; +} +- (id)init { + if (self = [super init]) { + // do some init stuff here.. + self.lastRecordingState = NO; // initially the recording state is 'NO'. This is the default state. + self.timer = NULL; + } + return self; +} +- (BOOL)isRecording { + for (UIScreen *screen in UIScreen.screens) { + if ([screen respondsToSelector:@selector(isCaptured)]) { + // iOS 11+ has isCaptured method. + if ([screen performSelector:@selector(isCaptured)]) { + return YES; // screen capture is active + } else if (screen.mirroredScreen) { + return YES; // mirroring is active + } + } else { + // iOS version below 11.0 + if (screen.mirroredScreen) + return YES; + } + } + return NO; +} ++ (void)triggerDetectorTimer { + + ScreenRecordingDetector *detector = [ScreenRecordingDetector sharedInstance]; + if (detector.timer) { + [self stopDetectorTimer]; + } + detector.timer = [NSTimer scheduledTimerWithTimeInterval:kScreenRecordingDetectorTimerInterval + target:detector + selector:@selector(checkCurrentRecordingStatus:) + userInfo:nil + repeats:YES]; +} +- (void)checkCurrentRecordingStatus:(NSTimer *)timer { + BOOL isRecording = [self isRecording]; + if (isRecording != self.lastRecordingState) { + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center postNotificationName: kScreenRecordingDetectorRecordingStatusChangedNotification object:nil]; + } + self.lastRecordingState = isRecording; +} ++ (void)stopDetectorTimer { + ScreenRecordingDetector *detector = [ScreenRecordingDetector sharedInstance]; + if (detector.timer) { + [detector.timer invalidate]; + detector.timer = NULL; + } +} +@end \ No newline at end of file diff --git a/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.h b/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.h new file mode 100644 index 0000000..a1db059 --- /dev/null +++ b/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.h @@ -0,0 +1,10 @@ +#import +#import "ScreenRecordingDetector.h" + + +@interface ScreenshotBlocker : CDVPlugin + +- (void)enable:(CDVInvokedUrlCommand*)command; +-(void)listen:(CDVInvokedUrlCommand*)command; + +@end diff --git a/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.m b/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.m new file mode 100644 index 0000000..8397d55 --- /dev/null +++ b/plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.m @@ -0,0 +1,119 @@ +#import "ScreenshotBlocker.h" +@interface ScreenshotBlocker() { + CDVInvokedUrlCommand * _eventCommand; +} +@end + +@implementation ScreenshotBlocker +UIImageView* cover; +- (void)pluginInitialize { + NSLog(@"Starting ScreenshotBlocker plugin"); + + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(appDidBecomeActive) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(applicationWillResignActive) + name:UIApplicationWillResignActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(tookScreeshot) + name:UIApplicationUserDidTakeScreenshotNotification + object:nil]; + + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(goingBackground) + name:UIApplicationWillResignActiveNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(screenCaptureStatusChanged) + name:kScreenRecordingDetectorRecordingStatusChangedNotification + object:nil]; + + /* + userDidTakeScreenshotNotification + */ + +} + +- (void)enable:(CDVInvokedUrlCommand *)command +{ + CDVPluginResult* pluginResult = nil; + NSLog(@"Abilita observers"); + /* + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(appDidBecomeActive) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(applicationWillResignActive) + name:UIApplicationWillResignActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(screenCaptureStatusChanged) + name:kScreenRecordingDetectorRecordingStatusChangedNotification + object:nil]; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + */ +} +-(void)listen:(CDVInvokedUrlCommand*)command { + _eventCommand = command; +} + + +-(void) goingBackground { + NSLog(@"Me la scattion in bck"); + if(_eventCommand!=nil) { + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"background"]; + [pluginResult setKeepCallbackAsBool:YES]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:_eventCommand.callbackId]; + } +} +-(void)tookScreeshot { + NSLog(@"fatta la foto?"); + if(_eventCommand!=nil) { + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"tookScreenshot"]; + [pluginResult setKeepCallbackAsBool:YES]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:_eventCommand.callbackId]; + } + +} + +-(void)setupView { + BOOL isCaptured = [[UIScreen mainScreen] isCaptured]; + NSLog(@"Is screen captured? %@", (isCaptured?@"SI":@"NO")); + + if ([[ScreenRecordingDetector sharedInstance] isRecording]) { + [self webView].alpha = 0.f; + NSLog(@"Registro o prendo screenshots"); + } else { + [self webView].alpha = 1.f; + NSLog(@"Non registro"); + + } +} + +-(void)appDidBecomeActive { + [ScreenRecordingDetector triggerDetectorTimer]; + if(cover!=nil) { + [cover removeFromSuperview]; + cover = nil; + } +} +-(void)applicationWillResignActive { + [ScreenRecordingDetector stopDetectorTimer]; + if(cover == nil) { + cover = [[UIImageView alloc] initWithFrame:[self.webView frame]]; + cover.backgroundColor = [UIColor blackColor]; + [self.webView addSubview:cover]; + } +} +-(void)screenCaptureStatusChanged { + [self setupView]; +} + + +@end diff --git a/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js b/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js new file mode 100644 index 0000000..279f371 --- /dev/null +++ b/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js @@ -0,0 +1,38 @@ +var screenshot = { + enable: function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, 'screenshotName', 'enable', []); + }, + disable: function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, 'screenshotName', 'disable', []); + }, + registerListener : function(callback) { + cordova.exec(callback, callback, 'screenshotName', 'listen', []); + + } +} + +cordova.addConstructor(function () { + if (!window.plugins) {window.plugins = {};} + + window.plugins.preventscreenshot = screenshot; + document.addEventListener("onTookScreenshot",function(){ + console.log('tookScreenshot'); + }); + document.addEventListener("onGoingBackground",function(){ + console.log('BackgroundCalled'); + }); + screenshot.registerListener(function(me) { + console.log('received listener:',me); + if(me === "background") { + var event = new Event('onGoingBackground'); + document.dispatchEvent(event); + return; + } + if(me === "tookScreenshot") { + var event = new Event('onTookScreenshot'); + document.dispatchEvent(event); + return; + } + }); + return window.plugins.preventscreenshot; +}); \ No newline at end of file diff --git a/plugins/fetch.json b/plugins/fetch.json index 99f7154..ab50405 100644 --- a/plugins/fetch.json +++ b/plugins/fetch.json @@ -151,5 +151,13 @@ }, "is_top_level": true, "variables": {} + }, + "cordova-plugin-prevent-screenshot-coffice": { + "source": { + "type": "registry", + "id": "https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice.git" + }, + "is_top_level": true, + "variables": {} } } \ No newline at end of file diff --git a/plugins/ios.json b/plugins/ios.json index 523315b..a11cf1d 100644 --- a/plugins/ios.json +++ b/plugins/ios.json @@ -58,6 +58,9 @@ "cordova-plugin-fingerprint-aio": { "FACEID_USAGE_DESCRIPTION": " ", "PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)" + }, + "cordova-plugin-prevent-screenshot-coffice": { + "PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)" } }, "dependent_plugins": { diff --git a/www/js/main.js b/www/js/main.js index 9009475..f302033 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -59,7 +59,6 @@ var app = { onDeviceReady: function() { var uid = window.localStorage.getItem("token"); - console.log("1."+window.localStorage.getItem("uid")) this.initJpush(); $('#scanBtn').click(function() { //window.location = "scan.html"; diff --git a/www/js/mainmenu.js b/www/js/mainmenu.js index 7a98ae0..eacec44 100644 --- a/www/js/mainmenu.js +++ b/www/js/mainmenu.js @@ -58,7 +58,6 @@ var app = { onDeviceReady: function() { var uid = window.localStorage.getItem("token"); - console.log("1."+window.localStorage.getItem("uid")) this.initJpush(); $('#scanBtn').click(function() { //window.location = "scan.html"; diff --git a/www/js/qrcode.js b/www/js/qrcode.js index 2b06b32..016f2d7 100644 --- a/www/js/qrcode.js +++ b/www/js/qrcode.js @@ -26,6 +26,8 @@ var app = { e.preventDefault(); app.backTo(); }, false); + + window.plugins.preventscreenshot.disable(function(ret){}, function(ret){}); }, loadQrcode: function() { $.showLoading("加载中"); -- 2.17.1