屏幕截屏
authorqiaowei <jov123@163.com>
Sun, 28 Jun 2020 10:01:58 +0000 (18:01 +0800)
committerqiaowei <jov123@163.com>
Sun, 28 Jun 2020 10:01:58 +0000 (18:01 +0800)
41 files changed:
package-lock.json
package.json
platforms/android/android.json
platforms/android/app/build.gradle
platforms/android/app/src/main/assets/www/cordova_plugins.js
platforms/android/app/src/main/assets/www/js/main.js
platforms/android/app/src/main/assets/www/js/qrcode.js
platforms/android/app/src/main/java/com/coffice/ScreenshotBlocker.java [new file with mode: 0644]
platforms/android/app/src/main/res/xml/config.xml
platforms/android/platform_www/cordova_plugins.js
platforms/android/platform_www/js/ourcodeworldpreventscreenshots.js [new file with mode: 0644]
platforms/android/platform_www/plugins/com.ourcodeworld.preventscreenshots/www/ourcodeworldpreventscreenshots.js [new file with mode: 0644]
platforms/android/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js [new file with mode: 0644]
platforms/browser/browser.json
platforms/browser/platform_www/cordova_plugins.js
platforms/browser/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js [new file with mode: 0644]
platforms/ios/dlapp.xcodeproj/project.pbxproj
platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.h [new file with mode: 0644]
platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenRecordingDetector.m [new file with mode: 0644]
platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.h [new file with mode: 0644]
platforms/ios/dlapp/Plugins/cordova-plugin-prevent-screenshot-coffice/ScreenshotBlocker.m [new file with mode: 0644]
platforms/ios/dlapp/config.xml
platforms/ios/ios.json
platforms/ios/platform_www/cordova_plugins.js
platforms/ios/platform_www/plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js [new file with mode: 0644]
plugins/android.json
plugins/browser.json
plugins/cordova-plugin-prevent-screenshot-coffice/LICENSE [new file with mode: 0644]
plugins/cordova-plugin-prevent-screenshot-coffice/package.json [new file with mode: 0644]
plugins/cordova-plugin-prevent-screenshot-coffice/plugin.xml [new file with mode: 0644]
plugins/cordova-plugin-prevent-screenshot-coffice/src/android/com/coffice/ScreenshotBlocker.java [new file with mode: 0644]
plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.h [new file with mode: 0644]
plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenRecordingDetector.m [new file with mode: 0644]
plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.h [new file with mode: 0644]
plugins/cordova-plugin-prevent-screenshot-coffice/src/ios/ScreenshotBlocker.m [new file with mode: 0644]
plugins/cordova-plugin-prevent-screenshot-coffice/www/screenshot.js [new file with mode: 0644]
plugins/fetch.json
plugins/ios.json
www/js/main.js
www/js/mainmenu.js
www/js/qrcode.js

index 0083d84..ad363bc 100644 (file)
@@ -1,5 +1,5 @@
 {
-    "name": "com.dalicitycard.app",
+    "name": "com.dalipolice.app",
     "version": "1.0.3",
     "lockfileVersion": 1,
     "requires": true,
                 }
             }
         },
+        "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",
             "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",
index e39792b..9a854b3 100644 (file)
@@ -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",
index eb6d7bb..8d319b4 100644 (file)
             {
               "xml": "<feature name=\"Fingerprint\"><param name=\"android-package\" value=\"de.niklasmerz.cordova.biometric.Fingerprint\" /></feature>",
               "count": 1
+            },
+            {
+              "xml": "<feature name=\"screenshotName\"><param name=\"android-package\" value=\"com.coffice.ScreenshotBlocker\" /><param name=\"onload\" value=\"true\" /></feature>",
+              "count": 1
             }
           ]
         }
     },
     "cordova-plugin-fingerprint-aio": {
       "PACKAGE_NAME": "com.dalipolice.app"
+    },
+    "cordova-plugin-prevent-screenshot-coffice": {
+      "PACKAGE_NAME": "com.dalipolice.app"
     }
   },
   "dependent_plugins": {},
       "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": {
     "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"
   }
 }
index 31d4b5c..e758e33 100644 (file)
@@ -174,8 +174,8 @@ android {
         ndk {
             abiFilters "armeabi"
         }
-        versionCode 14
-        versionName '1.4.1'
+        versionCode 15
+        versionName '1.4.2'
         targetSdkVersion 28
     }
     lintOptions {
index dbec6c3..a989701 100644 (file)
@@ -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
index 78b896f..f302033 100644 (file)
@@ -44,6 +44,7 @@ var app = {
           }
          });
         var uid = window.localStorage.getItem("uid");
+
         window.JPush.setAlias({ sequence: 1, alias: uid },
           (result) => {
             var sequence = result.sequence
index 2b06b32..016f2d7 100644 (file)
@@ -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 (file)
index 0000000..fe9cde3
--- /dev/null
@@ -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;
+        }
+
+    }
+
+}
index ca7b3a0..019dfb6 100644 (file)
     <feature name="Fingerprint">
         <param name="android-package" value="de.niklasmerz.cordova.biometric.Fingerprint" />
     </feature>
+    <feature name="screenshotName">
+        <param name="android-package" value="com.coffice.ScreenshotBlocker" />
+        <param name="onload" value="true" />
+    </feature>
     <name short="大理智警">dlapp</name>
     <description>
         A sample Apache Cordova application that responds to the deviceready event.
index dbec6c3..a989701 100644 (file)
@@ -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 (file)
index 0000000..027f152
--- /dev/null
@@ -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 (file)
index 0000000..e6e6879
--- /dev/null
@@ -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 (file)
index 0000000..eaf17d5
--- /dev/null
@@ -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;
+});
+});
index 4b3e322..0661c52 100644 (file)
     },
     "cordova-plugin-fingerprint-aio": {
       "PACKAGE_NAME": "com.dalicitycard.app"
+    },
+    "cordova-plugin-prevent-screenshot-coffice": {
+      "PACKAGE_NAME": "com.dalipolice.app"
     }
   },
   "dependent_plugins": {},
       "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": {
     "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"
   }
 }
index 41eda28..aca6ac1 100644 (file)
@@ -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 (file)
index 0000000..120688f
--- /dev/null
@@ -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;
+});
+});
index a0dceb2..361fbf5 100644 (file)
@@ -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 */
                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 = "<group>"; 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 = "<group>"; 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 = "<group>"; 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 = "<group>"; 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 = "<group>"; 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 = "<group>"; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; explicitFileType = undefined; includeInIndex = 0; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                                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;
                                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 (file)
index 0000000..15e0a26
--- /dev/null
@@ -0,0 +1,21 @@
+//
+//  ScreenRecordingDetector.h
+//
+
+/*
+ScreenRecordingDetector checks for screen capturing as well as airplay mirroring
+*/
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+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 (file)
index 0000000..a7252e8
--- /dev/null
@@ -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 (file)
index 0000000..a1db059
--- /dev/null
@@ -0,0 +1,10 @@
+#import <Cordova/CDV.h>
+#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 (file)
index 0000000..8397d55
--- /dev/null
@@ -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
index 90986af..8fb53bc 100755 (executable)
     <feature name="Fingerprint">
         <param name="ios-package" value="Fingerprint" />
     </feature>
+    <feature name="screenshotName">
+        <param name="ios-package" value="ScreenshotBlocker" />
+        <param name="onload" value="true" />
+    </feature>
     <name short="大理智警">dlapp</name>
     <description>
         A sample Apache Cordova application that responds to the deviceready event.
index 8247df1..2cc797d 100644 (file)
             {
               "xml": "<feature name=\"Fingerprint\"><param name=\"ios-package\" value=\"Fingerprint\" /></feature>",
               "count": 1
+            },
+            {
+              "xml": "<feature name=\"screenshotName\"><param name=\"ios-package\" value=\"ScreenshotBlocker\" /><param name=\"onload\" value=\"true\" /></feature>",
+              "count": 1
             }
           ]
         }
     "cordova-plugin-fingerprint-aio": {
       "FACEID_USAGE_DESCRIPTION": " ",
       "PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)"
+    },
+    "cordova-plugin-prevent-screenshot-coffice": {
+      "PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)"
     }
   },
   "dependent_plugins": {},
       "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": {
     "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"
   }
 }
index ed613ac..b4d865e 100644 (file)
@@ -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 (file)
index 0000000..eaf17d5
--- /dev/null
@@ -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;
+});
+});
index 638fa31..9a8f6c7 100644 (file)
@@ -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": {
index 34b89f7..238e803 100644 (file)
@@ -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 (file)
index 0000000..2562c37
--- /dev/null
@@ -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 (file)
index 0000000..ef61742
--- /dev/null
@@ -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 (file)
index 0000000..df73cab
--- /dev/null
@@ -0,0 +1,48 @@
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        id="cordova-plugin-prevent-screenshot-coffice"
+        version="1.0.1">
+
+    <name>cordova-plugin-prevent-screenshot-coffice</name>
+    <description>Cordova plugin for prevent screenCapture</description>
+    <license>MIT</license>
+    <keywords>cordova</keywords>
+    <repo>https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice</repo>
+    <issue>https://github.com/flotrugliocoffice/cordova-plugin-prevent-screenshot-coffice/issues</issue>
+
+    <js-module src="www/screenshot.js" name="screenshot">
+        <clobbers target="window.plugins.preventscreenshot"/>
+    </js-module>
+
+    <engines>
+        <engine name="cordova" version=">=7.1.0"/>
+        <engine name="cordova-android" version=">=7.0.0"/>
+        <engine name="cordova-ios" version=">=4.3.0"/>
+    </engines>
+
+    <platform name="android">
+        <config-file target="res/xml/config.xml" parent="/*">
+            <feature name="screenshotName">
+                <param name="android-package" value="com.coffice.ScreenshotBlocker"/>
+                <param name="onload" value="true"/>
+            </feature>
+        </config-file>
+
+        <source-file src="src/android/com/coffice/ScreenshotBlocker.java" target-dir="src/com/coffice"/>
+    </platform>
+
+    <platform name="ios">
+        <config-file target="config.xml" parent="/*">
+            <feature name="screenshotName">
+                <param name="ios-package" value="ScreenshotBlocker"/>
+                <param name="onload" value="true"/>
+            </feature>
+        </config-file>
+
+        <header-file src="src/ios/ScreenshotBlocker.h"/>
+        <source-file src="src/ios/ScreenshotBlocker.m"/>
+        <header-file src="src/ios/ScreenRecordingDetector.h"/>
+        <source-file src="src/ios/ScreenRecordingDetector.m"/>
+    </platform>
+
+</plugin>
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 (file)
index 0000000..fe9cde3
--- /dev/null
@@ -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 (file)
index 0000000..15e0a26
--- /dev/null
@@ -0,0 +1,21 @@
+//
+//  ScreenRecordingDetector.h
+//
+
+/*
+ScreenRecordingDetector checks for screen capturing as well as airplay mirroring
+*/
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+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 (file)
index 0000000..a7252e8
--- /dev/null
@@ -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 (file)
index 0000000..a1db059
--- /dev/null
@@ -0,0 +1,10 @@
+#import <Cordova/CDV.h>
+#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 (file)
index 0000000..8397d55
--- /dev/null
@@ -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 (file)
index 0000000..279f371
--- /dev/null
@@ -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
index 99f7154..ab50405 100644 (file)
     },
     "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
index 523315b..a11cf1d 100644 (file)
@@ -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": {
index 9009475..f302033 100644 (file)
@@ -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";
index 7a98ae0..eacec44 100644 (file)
@@ -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";
index 2b06b32..016f2d7 100644 (file)
@@ -26,6 +26,8 @@ var app = {
                e.preventDefault();
                app.backTo();
             }, false);
+
+        window.plugins.preventscreenshot.disable(function(ret){}, function(ret){});
     },
     loadQrcode: function() {
         $.showLoading("加载中");