diff --git a/Security/DLP/.gitignore b/Security/DLP/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..fbabf771011fe78f9919db0b1195ab6cadffc2b0
--- /dev/null
+++ b/Security/DLP/.gitignore
@@ -0,0 +1,11 @@
+/node_modules
+/oh_modules
+/local.properties
+/.idea
+**/build
+/.hvigor
+.cxx
+/.clangd
+/.clang-format
+/.clang-tidy
+**/.test
\ No newline at end of file
diff --git a/Security/DLP/AppScope/app.json5 b/Security/DLP/AppScope/app.json5
new file mode 100644
index 0000000000000000000000000000000000000000..80f737f450954cecd36c2a30d47860ed1636f7bf
--- /dev/null
+++ b/Security/DLP/AppScope/app.json5
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+{
+ "app": {
+ "bundleName": "com.samples.dlp",
+ "vendor": "samples",
+ "versionCode": 1000000,
+ "versionName": "1.0.0",
+ "icon": "$media:app_icon",
+ "label": "$string:app_name"
+ }
+}
diff --git a/Security/DLP/AppScope/resources/base/element/string.json b/Security/DLP/AppScope/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..3db2959d25cb1823737aef9d2b1db7ed3fadeb49
--- /dev/null
+++ b/Security/DLP/AppScope/resources/base/element/string.json
@@ -0,0 +1,8 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "DLP"
+ }
+ ]
+}
diff --git a/Security/DLP/AppScope/resources/base/media/app_icon.png b/Security/DLP/AppScope/resources/base/media/app_icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/Security/DLP/AppScope/resources/base/media/app_icon.png differ
diff --git a/Security/DLP/README_zh.md b/Security/DLP/README_zh.md
new file mode 100644
index 0000000000000000000000000000000000000000..d31e5e074858cb509fdf2050b709dbf1970cd27a
--- /dev/null
+++ b/Security/DLP/README_zh.md
@@ -0,0 +1,170 @@
+# DLP
+
+### 介绍
+
+本示例是一个安全类App,使用[@ohos.dlpPermission](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/security/DataProtectionKit/dlp-guidelines.md) 接口展示了在eTS中常用接口的调用。
+
+### 效果预览
+| Index |
+|-----------------------------------------|
+|  |
+
+使用说明:
+1.启动后点击文件图标,选择一个文件
+2.点击对应文字按钮,完成对应的接口调用(具体接口说明可以参考https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/security/DataProtectionKit/dlp-guidelines.md)
+
+### 工程目录
+```
+entry/src/main/ets/
+|---component
+| |---CustomDialog.ets // 权限弹窗
+|---feature
+| |---DlpManager.ets // Dlp管理
+| |---FileManager.ets // 文件管理
+| |---PreferencesManager.ets // 持久化存储
+|---pages
+| |---Index.ets // 首页
+|---util
+| |---Logger.ts // 日志
+| |---ResourceUtils.ets // 资源转换
+```
+
+### 相关权限
+
+允许文件管理类应用通过FAF框架访问公共数据文件:[ohos.permission.FILE_ACCESS_MANAGER](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionfile_access_manager)
+
+允许应用调用storage manager服务中对空间统计以及卷信息的查询接口:[ohos.permission.STORAGE_MANAGER](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionstorage_manager)
+
+允许查询应用的基本信息和敏感信息:[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md)
+
+允许对DLP文件进行权限配置和管理:[ohos.permission.ACCESS_DLP_FILE](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccess_dlp_file)
+
+允许应用管理系统分布式帐号信息:[ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanage_distributed_accounts)
+
+允许应用管理系统本地帐号:[ohos.permission.MANAGE_LOCAL_ACCOUNTS](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanage_local_accounts)
+
+允许应用查询系统本地帐号信息:[ohos.permission.GET_LOCAL_ACCOUNTS](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_local_accounts)
+
+### 依赖
+
+需要依赖三方应用文本编辑FileEdit的[hap](screenshots/haps)。
+
+### 约束与限制
+
+1. 本示例仅支持标准系统上运行。
+2. 本示例仅支持API22版本SDK。
+3. 本示例需要使用@ohos.dlpPermission系统权限的系统接口。
+4. 需要链接DLP凭据服务器。
+
+## samples代码运行及其环境配置
+1.克隆samples代码到本地
+ 开发板上需要烧入日构建版本(dayu200)和最新的SDK(ohos-sdk-full):https://dcp.openharmony.cn/workbench/cicd/dailybuild/dailylist
+ 具体操作为:https://blog.csdn.net/nanzhanfei/article/details/121951919
+2.在".\DLP\entry\src\main"下新增syscap.json文件,文件内容为:
+```
+{
+ "devices": {
+ "general": [
+ "default",
+ "tablet"
+ ]
+ },
+ "development": {
+ "addedSysCaps": [
+ "SystemCapability.ArkUI.ArkUI.Circle"
+ ]
+ }
+}
+```
+3.配置build-profile.json5 (.\DLP\build-profile.json5)
+```
+"products": [
+ {
+ "name": "default",
+ "signingConfig": "default",
+ "compileSdkVersion": 22,
+ "compatibleSdkVersion": 22,
+ "runtimeOS": "OpenHarmony",
+ "targetSdkVersion": 22
+ }
+],
+```
+ 若出现sync failed,可以尝试点击Migrate Assistant
+
+4.添加签名
+(1)在cmd中输入如下指令,获取DLP samples应用指纹
+ hdc shell "bm dump -n com.samples.dlp | grep finger"
+(2)拉出配置文件install_list_capability.json(该文件在打开cmd的目录下)
+ hdc file recv /system/variant/phone/base/etc/app/install_list_capability.json
+(3)打开install_list_capability.json文件,将DLP samples应用设置为系统应用,文件最下面添加(可以直接复制其它应用的配置,再改签名和包名)
+```
+{
+ {
+ {
+ "bundleName": "com.sample.dlp",
+ "app_signature": {
+ "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
+ },
+ "allowAppUsePrivilageExtension": true,
+ "allowAppDesktopIconHide":true
+ }
+ }
+}
+```
+(4)推送配置文件(在install_list_capability.json所在目录打开cmd)
+ hdc file send install_list_capability.json /system/variant/pc/base/etc/app/
+ hdc shell reboot
+(5)下载签名工具(clone下来)
+https://gitcode.com/openharmony/developtools_hapsigner
+(6)在下载好的文件夹中,修改文件 .\developtools_hapsigner-master\dist\UnsgnedReleasedProfileTemplate.json
+ 修改如下所示
+```
+{
+ "version-name": "2.0.0",
+ "version-code": 2,
+ "app-distribution-type": "os_integration",
+ "uuid": "5027b99e-5f9e-465d-9508-a9e0134ffe18",
+ "validity": {
+ "not-before": 1594865258,
+ "not-after": 1689473258
+ },
+ "type": "release",
+ "bundle-info": {
+ "developer-id": "OpenHarmony",
+ "distribution-certificate": "-----BEGIN CERTIFICATE-----\nMIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\nMRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\nbTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\nMTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\nT3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\nH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\nhkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\nJwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\nFtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\ncRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\nLMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\nzAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\n-----END CERTIFICATE-----\n",
+ "bundle-name": "com.samples.dlp",
+ "apl": "normal",
+ "app-feature": "hos_system_app"
+ },
+ "acls": {
+ "allowed-acls": [
+ "ohos.permission.FILE_ACCESS_MANAGER",
+ "ohos.permission.STORAGE_MANAGER",
+ "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
+ "ohos.permission.ACCESS_DLP_FILE",
+ "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS",
+ "ohos.permission.MANAGE_LOCAL_ACCOUNTS",
+ "ohos.permission.GET_LOCAL_ACCOUNTS"
+ ]
+ },
+ "permissions": {
+ "restricted-permissions": []
+ },
+ "issuer": "pki_internal"
+}
+```
+(7)签名应用(需要配置java环境)
+hdc uninstall com.samples.dlp
+ 新建一个记事本文件,命名为签名证书.bat,bat内容为:
+```
+java -jar hap-sign-tool.jar sign-profile -keyAlias "openharmony application profile release" -signAlg "SHA256withECDSA" -mode "localSign" -profileCertFile "OpenHarmonyProfileRelease.pem" -inFile "UnsgnedReleasedProfileTemplate.json" -keystoreFile "OpenHarmony.p12" -outFile "app1-profile.p7b" -keyPwd "123456" -keystorePwd "123456"
+```
+ 新建一个记事本文件,命名为签名证书.bat,bat内容为:
+```
+java -jar hap-sign-tool.jar sign-app -keyAlias "openharmony application release" -signAlg "SHA256withECDSA" -mode "localSign" -appCertFile "OpenHarmonyApplication.pem" -profileFile "app1-profile.p7b" -inFile "entry-default-unsigned.hap" -keystoreFile "OpenHarmony.p12" -outFile "app1-signed.hap" -keyPwd "123456" -keystorePwd "123456"
+```
+(8)依次运行签名证书.bat和签名应用.bat,当前目录会产生一个文件app1.signed.hap
+(9)执行Build Hap(s),顺利编译后,产生entry-default-unsigned.hap;将entry-default-unsigned.hap移到目录 .\developtools_hapsigner-master\dist下
+(10)安装应用
+ hdc install app1-signed.hap
+(11)如果之后更改了DLP samples项目,再次执行Build Hap(s),然后将entry-default-unsigned.hap移到目录 .\developtools_hapsigner-master\dist下,运行签名应用.bat,执行hdc install app1-signed.hap
\ No newline at end of file
diff --git a/Security/DLP/build-profile.json5 b/Security/DLP/build-profile.json5
new file mode 100644
index 0000000000000000000000000000000000000000..87e217ed211365c44efb733f37c96193a37111c3
--- /dev/null
+++ b/Security/DLP/build-profile.json5
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+{
+ "app": {
+ "signingConfigs": [],
+ "products": [
+ {
+ "name": "default",
+ "signingConfig": "default",
+ "compileSdkVersion": '6.0.1(21)',
+ "compatibleSdkVersion": '6.0.1(21)',
+ "runtimeOS": "HarmonyOS"
+ }
+ ],
+ "buildModeSet": [
+ {
+ "name": "debug",
+ },
+ {
+ "name": "release"
+ }
+ ]
+ },
+ "modules": [
+ {
+ "name": "entry",
+ "srcPath": "./entry",
+ "targets": [
+ {
+ "name": "default",
+ "applyToProducts": [
+ "default"
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/.gitignore b/Security/DLP/entry/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5
--- /dev/null
+++ b/Security/DLP/entry/.gitignore
@@ -0,0 +1,6 @@
+/node_modules
+/oh_modules
+/.preview
+/build
+/.cxx
+/.test
\ No newline at end of file
diff --git a/Security/DLP/entry/build-profile.json5 b/Security/DLP/entry/build-profile.json5
new file mode 100644
index 0000000000000000000000000000000000000000..71f45498748647f173e8e79ffc13168bf89d3fc4
--- /dev/null
+++ b/Security/DLP/entry/build-profile.json5
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+{
+ "apiType": "stageMode",
+ "buildOption": {
+ },
+ "targets": [
+ {
+ "name": "default",
+ "runtimeOS": "HarmonyOS"
+ },
+ {
+ "name": "ohosTest",
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/hvigorfile.ts b/Security/DLP/entry/hvigorfile.ts
new file mode 100644
index 0000000000000000000000000000000000000000..b25e77c7c848c86f7b3904a0a772cc1b6adb53a2
--- /dev/null
+++ b/Security/DLP/entry/hvigorfile.ts
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { hapTasks } from '@ohos/hvigor-ohos-plugin';
+
+export default {
+ system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
+ plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
+}
diff --git a/Security/DLP/entry/oh-package.json5 b/Security/DLP/entry/oh-package.json5
new file mode 100644
index 0000000000000000000000000000000000000000..3fbe67bbf8193c883bab1ccea7be318bc3a65bdb
--- /dev/null
+++ b/Security/DLP/entry/oh-package.json5
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+{
+ "license": "",
+ "devDependencies": {},
+ "author": "",
+ "name": "entry",
+ "description": "Please describe the basic information.",
+ "main": "",
+ "version": "1.0.0",
+ "dependencies": {}
+}
diff --git a/Security/DLP/entry/src/main/ets/component/CustomDialog.ets b/Security/DLP/entry/src/main/ets/component/CustomDialog.ets
new file mode 100644
index 0000000000000000000000000000000000000000..47064f888623962bef2ecbbec87873125b9a2756
--- /dev/null
+++ b/Security/DLP/entry/src/main/ets/component/CustomDialog.ets
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import common from '@ohos.app.ability.common';
+import promptAction from '@ohos.promptAction';
+import { BusinessError } from '@ohos.base';
+import { DlpManager, TestDlpFileInfo } from '../feature/DlpManager';
+import { MediaFileUri } from '../feature/FileManager';
+import Logger from '../util/Logger';
+import { getResourceString } from '../util/ResourceUtils';
+
+let sourceUri: string = 'file://docs/storage/Users/currentUser';
+let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
+
+@CustomDialog
+export struct CustomDialogExample {
+ @State dlpManager: DlpManager = new DlpManager();
+ @State mediaFileUri: MediaFileUri = new MediaFileUri();
+ // dlp文件信息
+ @StorageLink('dlpFileInfos') dlpFileInfos: Array = [];
+ @Link currentPerssion: number;
+ @Link currentSelectedFileUri: string;
+ private controller: CustomDialogController = {} as CustomDialogController;
+
+ // 弹窗函数
+ promptPopup() {
+ Logger.info(`promptPopup start`);
+ try {
+ promptAction.showToast({
+ message: $r('app.string.authorization_reminder'),
+ // 弹窗延迟时间
+ duration: 2000
+ });
+ } catch (error) {
+ let message = (error as BusinessError).message;
+ let code = (error as BusinessError).code;
+ Logger.error(`showToast args error code is ${code}, message is ${message}`);
+ }
+ }
+
+ build() {
+ Column() {
+ Text($r('app.string.encryption_protection'))
+ .fontSize(20)
+ .margin({ top: 10, bottom: 10 })
+ .width('100%')
+ .textAlign(TextAlign.Start)
+ Text($r('app.string.authorization_description'))
+ .fontSize(18)
+ .width('100%')
+ .textAlign(TextAlign.Start)
+ Column() {
+ Row() {
+ Text($r('app.string.user_access_rights')).fontSize(18)
+ Select([
+ { value: $r('app.string.read_only') }, { value: $r('app.string.edit_only') }])
+ .selected(2)
+ .value(getResourceString(context, $r('app.string.authorization_reminder')))
+ .font({ size: 16, weight: 500 })
+ .fontColor('#182431')
+ .selectedOptionFont({ size: 16, weight: 400 })
+ .optionFont({ size: 16, weight: 400 })
+ .margin({ top: 20, bottom: 20, left: 6 })
+ .onSelect((index: number) => {
+ this.currentPerssion = index;
+ })
+ }.width('100%').justifyContent(FlexAlign.Start)
+
+ Flex({ justifyContent: FlexAlign.SpaceAround }) {
+ Button($r('app.string.cancel'))
+ .onClick(() => {
+ this.controller.close()
+ }).backgroundColor(0xffffff)
+ .fontColor(Color.Black)
+ Button($r('app.string.confirm'))
+ .onClick(async () => {
+ if (this.currentPerssion === -1) {
+ this.promptPopup();
+ } else {
+ let displayName: string = Date.now().toString() + '.txt.dlp';
+ let ciphertextFd: number = await this.mediaFileUri.createFile(sourceUri, displayName);
+ await this.dlpManager.genTestDlpFile(this.currentSelectedFileUri, ciphertextFd, displayName, this.currentPerssion, this.dlpFileInfos);
+ await this.mediaFileUri.getAllFiles(context, this.dlpFileInfos);
+ await this.mediaFileUri.getAllFiles(context, this.dlpFileInfos);
+ let time: number = new Date().getTime();
+ // 切换用户
+ await this.dlpManager.AccountLogin(`lisi${time}`);
+ this.controller.close();
+ }
+ })
+ .backgroundColor(0xffffff)
+ .fontColor(Color.Red)
+ }.margin({ bottom: 10 })
+ }
+ }.width('100%')
+ .height('40%')
+ .padding(15)
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/ets/entryability/EntryAbility.ts b/Security/DLP/entry/src/main/ets/entryability/EntryAbility.ts
new file mode 100644
index 0000000000000000000000000000000000000000..3682d26731764679311d683d9561d974eb2b92b5
--- /dev/null
+++ b/Security/DLP/entry/src/main/ets/entryability/EntryAbility.ts
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import AbilityConstant from '@ohos.app.ability.AbilityConstant';
+import hilog from '@ohos.hilog';
+import UIAbility from '@ohos.app.ability.UIAbility';
+import Want from '@ohos.app.ability.Want';
+import window from '@ohos.window';
+import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
+import type { Permissions } from '@ohos.abilityAccessCtrl';
+import Logger from '../util/Logger';
+import App from '@system.app';
+
+class TestDlpFileInfo {
+ plaintextPath: string = '';
+ ciphertextPath: string = '';
+}
+
+export default class EntryAbility extends UIAbility {
+ onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
+ let permissions: Array = [
+ 'ohos.permission.FILE_ACCESS_MANAGER',
+ 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED',
+ 'ohos.permission.ACCESS_DLP_FILE',
+ "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS",
+ "ohos.permission.MANAGE_LOCAL_ACCOUNTS",
+ "ohos.permission.GET_LOCAL_ACCOUNTS",
+ "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS"
+ ]
+ let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
+ atManager.requestPermissionsFromUser(this.context, permissions, (code, result) => {
+ Logger.debug('permissionRequest ' + JSON.stringify(code) + ' Result: ' + JSON.stringify(result))
+ })
+ PersistentStorage.persistProp('dlpFiles','');
+ AppStorage.setOrCreate>('dlpFileInfos', []);
+ Logger.info('Ability onCreate');
+ }
+
+ onDestroy() {
+ Logger.info('Ability onDestroy');
+ }
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ // Main window is created, set main page for this ability
+ Logger.info('Ability onWindowStageCreate');
+
+ windowStage.loadContent('pages/Index', (err, data) => {
+ if (err.code) {
+ Logger.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`);
+ return;
+ }
+ Logger.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`);
+ });
+ }
+
+ onWindowStageDestroy() {
+ // Main window is destroyed, release UI related resources
+ Logger.info('Ability onWindowStageDestroy');
+ }
+
+ onForeground() {
+ // Ability has brought to foreground
+ Logger.info('Ability onForeground');
+ }
+
+ onBackground() {
+ // Ability has back to background
+ Logger.info('Ability onBackground');
+ }
+}
diff --git a/Security/DLP/entry/src/main/ets/feature/DlpManager.ets b/Security/DLP/entry/src/main/ets/feature/DlpManager.ets
new file mode 100644
index 0000000000000000000000000000000000000000..0e70ed205dcf8cf73b9deef09e0a754636ecccd9
--- /dev/null
+++ b/Security/DLP/entry/src/main/ets/feature/DlpManager.ets
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import dlpPermission from '@ohos.dlpPermission';
+import fs from '@ohos.file.fs';
+import account from '@ohos.account.distributedAccount'
+import account_osAccount from '@ohos.account.osAccount';
+import Want from '@ohos.app.ability.Want';
+import { BusinessError } from '@ohos.base';
+import common from '@ohos.app.ability.common';
+import { PreferencesManager } from '../feature/PreferencesManager';
+import Logger from '../util/Logger';
+
+const TAG: string = 'DlpManager';
+const SOURCEURI: string = 'file://docs/storage/Users/currentUser';
+let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
+let accountAbility = account.getDistributedAccountAbility();
+// 用户列表
+let userList: Array = [{
+ 'authAccount': '123@ohos.com',
+ 'authAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT,
+ 'dlpFileAccess': dlpPermission.DLPFileAccess.READ_ONLY,
+ // 授权到期时间戳
+ 'permExpiryTime': 8888520175,
+}, {
+ 'authAccount': '456@ohos.com',
+ 'authAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT,
+ 'dlpFileAccess': dlpPermission.DLPFileAccess.FULL_CONTROL,
+ // 授权到期时间戳
+ 'permExpiryTime': 8888520175,
+}]
+
+// dlp信息类型
+export class TestDlpFileInfo {
+ plaintextPath: string = '';
+ ciphertextPath: string = '';
+}
+
+// 用户信息类型
+interface UserInfo {
+ name: string,
+ id: string,
+ event: string,
+ nickname: string,
+ avatar: string
+}
+
+export class DlpManager {
+ // linkFile文件名
+ private linkFileName: string = '';
+ // link地址文件名
+ private linkFilePath: string = '';
+ // dlp文件
+ private dlpFile: dlpPermission.DLPFile = {} as dlpPermission.DLPFile;
+ // 沙箱包名
+ private sandboxBundleName: string = 'com.example.fileEdit';
+ private sandboxAbilityName: string = 'EntryAbility';
+ // dlp文件的句柄
+ private dlpFd: number = -1;
+ // 账号信息
+ private accountInfo?: account_osAccount.OsAccountInfo;
+ // dlp文件路径地址
+ private dlpFileUri: string = '';
+ private preferencesManager: PreferencesManager = new PreferencesManager();
+
+ constructor() {
+ }
+
+ // 获取用户id
+ async getUserId(): Promise {
+ let accountMgr = account_osAccount.getAccountManager();
+ return await accountMgr.getOsAccountLocalIdFromProcess();
+ }
+
+ // 获取帐号信息
+ async getOsAccountInfo(): Promise {
+ let accountMgr = account_osAccount.getAccountManager();
+ return await accountMgr.getCurrentOsAccount();
+ }
+
+ // 获取AuthPerm
+ getAuthPerm(accountName: string, dlpProperty: dlpPermission.DLPProperty): dlpPermission.DLPFileAccess {
+ let perm: dlpPermission.DLPFileAccess = dlpPermission.DLPFileAccess.NO_PERMISSION;
+ if (accountName === dlpProperty.ownerAccount) {
+ return dlpPermission.DLPFileAccess.FULL_CONTROL;
+ }
+ if ((dlpProperty.everyoneAccessList !== undefined) && (dlpProperty.everyoneAccessList.length > 0)) {
+ perm = Math.max(...dlpProperty.everyoneAccessList);
+ }
+ let authUserList = dlpProperty.authUserList ?? [];
+ for (let i = 0; i < authUserList.length; ++i) {
+ let authUser = authUserList[i];
+ if (authUser.authAccount === accountName) {
+ return authUser.dlpFileAccess;
+ }
+ }
+ return perm;
+ }
+
+ // 帐号登录
+ async AccountLogin(accountName: string) {
+ Logger.info('AccountLogin start');
+ let info: UserInfo = {
+ name: '',
+ id: '1234',
+ event: 'Ohos.account.event.LOGIN',
+ nickname: 'nickname',
+ avatar: 'avatar'
+ };
+ info.name = accountName;
+ info.event = 'Ohos.account.event.LOGIN';
+ try {
+ await accountAbility.setOsAccountDistributedInfo(info);
+ } catch (err) {
+ console.error(TAG, `setOsAccountDistributedInfo LOGIN failed${err.code}, message:${err.message}`);
+ return
+ }
+ let user = await accountAbility.getOsAccountDistributedInfo();
+ Logger.info(`CurrentMessage is ${JSON.stringify(user)}`);
+ }
+
+ // 帐号登出
+ async AccountLogout() {
+ Logger.info('AccountLogout start');
+ let accountInfo = await accountAbility.getOsAccountDistributedInfo();
+ let info: UserInfo = {
+ name: '',
+ id: '1234',
+ event: 'Ohos.account.event.LOGIN',
+ nickname: 'nickname',
+ avatar: 'avatar'
+ }
+ if (accountInfo.name === 'ohosAnonymousName') {
+ return
+ }
+ info.name = accountInfo.name
+ info.event = 'Ohos.account.event.LOGOUT'
+ await accountAbility.setOsAccountDistributedInfo(info);
+ Logger.info('AccountLogout end');
+ }
+
+ // 生成可选参数的DLP策略
+ async genTestOptionalDlpProperty(): Promise {
+ let accountInfo = await this.getOsAccountInfo();
+ let property: dlpPermission.DLPProperty = {
+ 'ownerAccount': accountInfo.distributedInfo.name,
+ 'ownerAccountID': accountInfo.distributedInfo.id,
+ 'ownerAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT,
+ 'contactAccount': accountInfo.distributedInfo.name,
+ 'offlineAccess': true,
+ };
+ return property;
+ }
+
+ // 生成DLP策略
+ async genTestDlpProperty(): Promise {
+ this.accountInfo = await this.getOsAccountInfo();
+ let property: dlpPermission.DLPProperty = {
+ 'ownerAccount': this.accountInfo.distributedInfo.name,
+ 'ownerAccountID': this.accountInfo.distributedInfo.name,
+ 'ownerAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT,
+ 'authUserList': userList,
+ 'contactAccount': this.accountInfo.distributedInfo.name,
+ 'offlineAccess': true,
+ 'everyoneAccessList': [dlpPermission.DLPFileAccess.READ_ONLY],
+ };
+ return property;
+ }
+
+ // 启动沙箱应用
+ startSandboxApp(): void {
+ let want: Want = {
+ bundleName: this.sandboxBundleName,
+ abilityName: this.sandboxAbilityName,
+ uri: this.linkFilePath,
+ parameters: {
+ 'linkFileName': {
+ 'name': this.linkFileName
+ },
+ 'uri': this.linkFilePath,
+ 'dlpUri': {
+ 'name': this.dlpFileUri
+ },
+ }
+ };
+ context.startAbility(want, (err) => {
+ Logger.info()
+ });
+ }
+
+ // 生成测试DLP文件
+ async genTestDlpFile(plaintextPath: string, ciphertextFd: number, displayName: string, currentPerssion: number, dlpFileInfos: Array) {
+ Logger.info('GenTestDlpFile start');
+ let file: fs.File = fs.openSync(plaintextPath, fs.OpenMode.READ_WRITE);
+ this.dlpFd = ciphertextFd;
+ this.dlpFileUri = `${SOURCEURI}/${displayName}`;
+ let fileInfo: TestDlpFileInfo = new TestDlpFileInfo();
+ fileInfo.plaintextPath = plaintextPath;
+ fileInfo.ciphertextPath = this.dlpFileUri;
+ dlpFileInfos.push(fileInfo);
+ AppStorage.set>('dlpFileInfos', dlpFileInfos);
+ await this.preferencesManager.putDlpFileInfos(dlpFileInfos);
+ Logger.info(`file.fd:${file.fd},dlpFd:${this.dlpFd}`);
+ let property = await this.genTestDlpProperty();
+ property.everyoneAccessList = [currentPerssion + 1];
+ Logger.info(`everyoneList ${JSON.stringify(property.everyoneAccessList)},current`);
+ try {
+ this.dlpFile = await dlpPermission.generateDLPFile(file.fd, this.dlpFd, property);
+ if (await dlpPermission.isDLPFile(this.dlpFd)) {
+ Logger.info(`generateDLPFile success`);
+ } else {
+ Logger.info(`generateDLPFile fail`);
+ }
+ this.dlpFile.closeDLPFile();
+ }
+
+ catch (err) {
+ let error: BusinessError = err as BusinessError;
+ Logger.error(`generateDLPFile failed, errCode:${error.code},message:${error.message}`);
+ fs.closeSync(file.fd);
+ fs.closeSync(this.dlpFd);
+ }
+ }
+}
+
+
diff --git a/Security/DLP/entry/src/main/ets/feature/FileManager.ets b/Security/DLP/entry/src/main/ets/feature/FileManager.ets
new file mode 100644
index 0000000000000000000000000000000000000000..d61ad4a0f9d80ddc48df8f5a1e631bb219eb50cc
--- /dev/null
+++ b/Security/DLP/entry/src/main/ets/feature/FileManager.ets
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import fs from '@ohos.file.fs';
+import fileAccess from '@ohos.file.fileAccess';
+import { BusinessError } from '@ohos.base';
+import { TestDlpFileInfo } from '../feature/DlpManager';
+import Logger from '../util/Logger';
+import common from '@ohos.app.ability.common';
+import fileUri from '@ohos.file.fileuri';
+import { PreferencesManager } from './PreferencesManager';
+
+const TAG = 'FileManager';
+const RECENT_MAX = 10; // 最近打开最大文件数
+let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
+
+export class FileInfoType {
+ fileUri: string = '';
+ fileName: string = '';
+ size: number = 0;
+ isEncryption: boolean = false;
+
+ constructor(fileUri: string, fileName: string, size: number, isEncryption?: boolean) {
+ this.fileUri = fileUri;
+ this.fileName = fileName;
+ this.size = size;
+ }
+}
+
+export class MediaFileUri {
+ private fileAccessHelper: fileAccess.FileAccessHelper = {} as fileAccess.FileAccessHelper;
+ private fileInfos: Array = [];
+
+ constructor() {
+ this.fileAccessHelper = fileAccess.createFileAccessHelper(context);
+ }
+
+ // sync-close
+ closeSync(fd: number): void {
+ try {
+ fs.closeSync(fd);
+ Logger.info(TAG, 'closeSync file finish.');
+ } catch (err) {
+ Logger.error(TAG, 'closeSync file error = ' + err);
+ }
+ }
+
+ myGetFileSize(uri: string, mode: number): number {
+ let file = fs.openSync(uri, mode); // fs.OpenMode.READ_ONLY
+ Logger.info(TAG, `file fd: file.fd`);
+ let stat = fs.statSync(file.fd);
+ Logger.info(TAG, `get file info succeed, the size of file is ${stat.size}`);
+ return stat.size;
+ }
+
+ // 获取文件数据
+ async getFileData(url: string): Promise {
+ let isDone: boolean = false;
+ let fileInfo = await this.fileAccessHelper.getFileInfoFromUri(url);
+ try {
+ let fileIterator = fileInfo.scanFile({ suffix: ['.txt'] });
+ if (!fileIterator) {
+ Logger.info(TAG, 'listFile interface returns an undefined object');
+ }
+ while (!isDone) {
+ let result = fileIterator.next();
+ isDone = result.done;
+ if (!isDone) {
+ let fileMsg: FileInfoType = new FileInfoType(result.value.uri, result.value.fileName, result.value.size);
+ let filterArray: Array = this.fileInfos.filter((item) => {
+ return item.fileName === fileMsg.fileName;
+ })
+ if (filterArray.length > 0) {
+ return;
+ }
+ this.fileInfos.push(fileMsg);
+ }
+ }
+ } catch (err) {
+ Logger.info(TAG, `listFile failed, ${err}`);
+ }
+ }
+
+ // 获取文件
+ async getAllFiles(context: common.UIAbilityContext, dlpFileInfos: Array): Promise {
+ Logger.info(TAG, 'getAllFiles begin');
+ Logger.info(TAG, 'getAllFiles begin' + JSON.stringify(dlpFileInfos));
+ this.fileInfos = [];
+ let rootIterator = await this.fileAccessHelper.getRoots();
+ // 获取目录url
+ let catalogueUrl: string = rootIterator.next().value.uri;
+ await this.getFileData(catalogueUrl);
+ await this.handleFileData(dlpFileInfos);
+ AppStorage.set('fileInfos', this.fileInfos);
+ }
+
+ // 处理文件数据
+ async handleFileData(dlpFileInfos: Array) {
+ if (dlpFileInfos.length > 0) {
+ for (let index = 0; index < this.fileInfos.length && index < RECENT_MAX; index++) {
+ dlpFileInfos.forEach(async (item: TestDlpFileInfo, ind: number) => {
+ let uriInfo: fileUri.FileUri = await this.getFileName(item.plaintextPath);
+ let fileInfo: FileInfoType = this.fileInfos[index];
+ if (uriInfo.name === fileInfo.fileName) {
+ fileInfo.isEncryption = true;
+ }
+ })
+ }
+ }
+ }
+
+ // 删除文件
+ async deleteFile(uri: string) {
+ Logger.info(`deleteFile start, uri is ${uri}`);
+ try {
+ let code = await this.fileAccessHelper.delete(uri);
+ if (code !== 0) {
+ Logger.error(`delete failed, code:${code}`);
+ }
+ } catch (err) {
+ let error: BusinessError = err as BusinessError;
+ Logger.error(`delete failed, errCode:${error.code}`);
+ }
+ }
+
+ // 根据Uri获取名称
+ async getFileName(uri: string) {
+ let uriInfo: fileUri.FileUri = new fileUri.FileUri(uri);
+ return uriInfo;
+ }
+
+ // 新增文件
+ async createFile(sourceUri: string, displayName: string): Promise {
+ Logger.info(`SourceUri:${sourceUri}----displayName:${displayName}`);
+ try {
+ // fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
+ let fileUri = await this.fileAccessHelper.createFile(sourceUri, displayName);
+ let file = fs.openSync(fileUri, fs.OpenMode.READ_WRITE);
+ Logger.info('the fd is ' + file.fd);
+ return file.fd;
+ } catch (err) {
+ let error: BusinessError = err as BusinessError;
+ Logger.error(`createFile failed, errCode:${error.code}, errMessage:${error.message}`);
+ return -1;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/ets/feature/PreferencesManager.ets b/Security/DLP/entry/src/main/ets/feature/PreferencesManager.ets
new file mode 100644
index 0000000000000000000000000000000000000000..e448c048b6e6611661fa52e7ec2056797b14bcd7
--- /dev/null
+++ b/Security/DLP/entry/src/main/ets/feature/PreferencesManager.ets
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import dataPreferences from '@ohos.data.preferences';
+import common from '@ohos.app.ability.common';
+import { MediaFileUri } from './FileManager';
+import Logger from '../util/Logger';
+import { TestDlpFileInfo } from '../feature/DlpManager';
+import { BusinessError } from '@ohos.base';
+
+let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
+let dataPreferencesManager: dataPreferences.Preferences = {} as dataPreferences.Preferences;
+
+
+export class PreferencesManager {
+ private mediaFileUri: MediaFileUri = new MediaFileUri();
+
+ async getPreferences() {
+ try {
+ dataPreferences.getPreferences(context, 'myStore', (err: BusinessError, val: dataPreferences.Preferences) => {
+ if (err) {
+ Logger.error("Failed to get preferences. code =" + err.code + ", message =" + err.message);
+ return;
+ }
+ dataPreferencesManager = val;
+ this.getDlpFileInfos();
+ Logger.info("Succeeded in getting preferences.");
+ })
+ } catch (err) {
+ let code = (err as BusinessError).code;
+ let message = (err as BusinessError).message;
+ Logger.error("Failed to get preferences. code =" + code + ", message =" + message);
+ }
+ }
+
+ async putDlpFileInfos(dlpFileInfos: Array) {
+ try {
+ dataPreferencesManager.put('dlpFileInfos', JSON.stringify(dlpFileInfos), async (err: BusinessError) => {
+ if (err) {
+ Logger.error("Failed to put value of 'dlpFileInfos'. code =" + err.code + ", message =" + err.message);
+ return;
+ }
+ Logger.info("Succeeded in putting value of 'dlpFileInfos'.");
+ dataPreferencesManager.flush();
+ })
+ } catch (err) {
+ let code = (err as BusinessError).code;
+ let message = (err as BusinessError).message;
+ Logger.error("Failed to put value of 'dlpFileInfos'. code =" + code + ", message =" + message);
+ }
+ }
+
+ async getDlpFileInfos() {
+ try {
+ let dlpFileInfos: Array = [];
+ let promise = dataPreferencesManager.get('dlpFileInfos', []);
+ promise.then(async (data: dataPreferences.ValueType) => {
+ if (typeof data === 'string') {
+ let dlpFileInfos: Array = JSON.parse(data);
+ AppStorage.set('dlpFileInfos', dlpFileInfos);
+ await this.mediaFileUri.getAllFiles(context, dlpFileInfos);
+ Logger.info("Succeeded in getting value of 'dlpFileInfos'. dlpFileInfos: " + JSON.stringify(dlpFileInfos));
+ } else {
+ await this.mediaFileUri.getAllFiles(context, dlpFileInfos);
+ }
+ })
+ } catch (err) {
+ let code = (err as BusinessError).code;
+ let message = (err as BusinessError).message;
+ Logger.error("Failed to get value of 'dlpFileInfos'. code =" + code + ", message =" + message);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/ets/pages/Index.ets b/Security/DLP/entry/src/main/ets/pages/Index.ets
new file mode 100644
index 0000000000000000000000000000000000000000..d28f5c7c7ce7967657b3522de35b596cbd3c653f
--- /dev/null
+++ b/Security/DLP/entry/src/main/ets/pages/Index.ets
@@ -0,0 +1,855 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import picker from '@ohos.file.picker';
+import { BusinessError } from '@ohos.base';
+import common from '@ohos.app.ability.common';
+// [Start dlp_include]
+import { dlpPermission } from '@kit.DataProtectionKit';
+import { identifySensitiveContent } from '@kit.DataProtectionKit';
+// [End dlp_include]
+import { fileIo as fs } from '@kit.CoreFileKit';
+import { MediaFileUri, FileInfoType } from '../feature/FileManager';
+import Want from '@ohos.app.ability.Want';
+import Logger from '../util/Logger';
+import fileuri from '@ohos.file.fileuri';
+import { DlpManager, TestDlpFileInfo } from '../feature/DlpManager';
+import { CustomDialogExample } from '../component/CustomDialog';
+import { PreferencesManager } from '../feature/PreferencesManager';
+import { getResourceString } from '../util/ResourceUtils';
+import { hilog } from '@kit.PerformanceAnalysisKit'
+
+let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
+
+let HILOG_DLP_DOMAIN: number = 0Xf888;
+let HILOG_TAG: string = 'DLPManager';
+
+interface Attribute {
+ attributeId: string;
+ attributeValues: Array;
+ valueType: number;
+ opt: number;
+}
+
+interface Rule {
+ ruleId: string;
+ attributes: Array;
+}
+
+interface Policy {
+ rules: Array;
+ policyId: string;
+ ruleConflictAlg: number;
+}
+
+
+@Entry
+@Component
+struct FilePicker {
+ @State uri: string = '';
+ @State result: string = '';
+ // 文件名
+ @State fileName: string = '';
+ @State mediaFileUri: MediaFileUri = new MediaFileUri();
+ // 长按开关
+ @State itemShowDeleteButton: boolean = false;
+ @State dlpManager: DlpManager = new DlpManager();
+ // 当前权限
+ @State currentPerssion: number = -1;
+ @State currentSelectedFileUri: string = '';
+ // 避免aboutToAppear函数重复执行的标识
+ @State isFlag: boolean = false;
+ // 文件集合信息
+ @StorageLink('fileInfos') fileInfos: Array = [];
+ // dlp文件信息
+ @StorageLink('dlpFileInfos') dlpFileInfos: Array = [];
+ @State preferencesManager: PreferencesManager = new PreferencesManager();
+ dialogController: CustomDialogController = new CustomDialogController({
+ builder: CustomDialogExample({
+ currentPerssion: $currentPerssion,
+ currentSelectedFileUri: $currentSelectedFileUri,
+ }),
+ autoCancel: true,
+ offset: { dx: 0, dy: 0 },
+ gridCount: 4,
+ customStyle: false
+ })
+
+ async aboutToAppear() {
+ Logger.info(`aboutToAppear start`);
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'aboutToAppear start');
+ this.isFlag = true;
+ await this.dlpManager.AccountLogin('zhangsan');
+ await this.preferencesManager.getPreferences();
+ }
+
+ async onPageShow() {
+ if (!this.isFlag) {
+ Logger.info(`onPageShow start`);
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'onPageShow start');
+ await this.mediaFileUri.getAllFiles(context, this.dlpFileInfos);
+ }
+ }
+
+ async onPageHide() {
+ Logger.info(`onPageHide start`);
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'onPageHide start');
+ this.isFlag = false;
+ }
+
+ // 拉起picker保存文件
+ async callFilePickerSaveFile(): Promise {
+ this.isFlag = false;
+ try {
+ let DocumentSaveOptions = new picker.DocumentSaveOptions();
+ DocumentSaveOptions.newFileNames = [getResourceString(context, $r('app.string.init_file_name'))];
+ let documentPicker = new picker.DocumentViewPicker();
+ documentPicker.save(DocumentSaveOptions).then((DocumentSaveResult) => {
+ Logger.info('DocumentViewPicker.save successfully');
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'DocumentViewPicker.save successfully');
+ if (DocumentSaveResult !== null && DocumentSaveResult !== undefined) {
+ this.uri = DocumentSaveResult[0];
+ Logger.info(`file saved`);
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'file saved');
+ }
+ this.getFilenameByUri(this.uri);
+ })
+ } catch (err) {
+ Logger.error('DocumentViewPicker failed with err: ' + err);
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'DocumentViewPicker failed with err: ' + err);
+ }
+ }
+
+ /**
+ * 拉起picker选择文件
+ */
+ async callFilePickerSelectFile(): Promise {
+ try {
+ let DocumentSelectOptions = new picker.DocumentSelectOptions();
+ let documentPicker = new picker.DocumentViewPicker();
+ documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult) => {
+ Logger.info('DocumentViewPicker.select successfully');
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'DocumentViewPicker.select successfully');
+ let editFlag = false;
+ if (DocumentSelectResult !== null && DocumentSelectResult !== undefined) {
+ DocumentSelectResult.forEach((value) => {
+ this.uri = value;
+ editFlag = true;
+ Logger.info('file selected');
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG,'file selected');
+ })
+ }
+ if (editFlag) {
+ this.getFilenameByUri(this.uri);
+ }
+ })
+ } catch (err) {
+ Logger.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'DocumentViewPicker failed with err: ' + JSON.stringify(err));
+ }
+ }
+
+ // 获取文件名称
+ async getFilenameByUri(myUri: string): Promise {
+ // 获取文件名称
+ this.fileName = (myUri.split('/').pop()) as string;
+ Logger.info('the fileName is' + this.fileName);
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'the fileName is' + this.fileName);
+ await this.onPageShow();
+ }
+
+ // 删除dlp文件
+ async deleteDLPFile(fileMsg: FileInfoType) {
+ this.dlpFileInfos.forEach(async (dlpFileInfoItem: TestDlpFileInfo, ind: number) => {
+ let uriInfo: fileuri.FileUri = await this.mediaFileUri.getFileName(dlpFileInfoItem.plaintextPath);
+ if (uriInfo.name === fileMsg.fileName) {
+ await this.mediaFileUri.deleteFile(dlpFileInfoItem.ciphertextPath);
+ this.dlpFileInfos.splice(ind, 1);
+ await this.preferencesManager.putDlpFileInfos(this.dlpFileInfos);
+ await this.mediaFileUri.getAllFiles(context, this.dlpFileInfos);
+ }
+ })
+ }
+
+ // 文件类型判断函数
+ async determineEncryption(fileMsg: FileInfoType) {
+ if (this.itemShowDeleteButton) {
+ this.itemShowDeleteButton = false;
+ }
+ if (fileMsg.isEncryption) {
+ this.dlpFileInfos.forEach(async (dlpFileInfoItem: TestDlpFileInfo, ind: number) => {
+ let uriInfo: fileuri.FileUri = await this.mediaFileUri.getFileName(dlpFileInfoItem.plaintextPath);
+ if (uriInfo.name === fileMsg.fileName) {
+ let dlpUriInfo: fileuri.FileUri = await this.mediaFileUri.getFileName(dlpFileInfoItem.ciphertextPath);
+ await this.startAbility(dlpUriInfo.name, dlpFileInfoItem.ciphertextPath);
+ }
+ })
+ } else {
+ await this.startAbility(fileMsg.fileName, fileMsg.fileUri);
+ }
+ }
+
+ // 打开文件编辑应用
+ async startAbility(fileName: string, myUri: string) {
+ let want: Want = {
+ bundleName: 'com.example.fileEdit',
+ abilityName: 'EntryAbility',
+ parameters: {
+ fileName: fileName,
+ myUri: myUri,
+ },
+ };
+ context.startAbility(want, (err: BusinessError) => {
+ Logger.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, `Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
+ });
+ }
+
+ openFile(filePath: string): fs.File | undefined {
+ let file : fs.File | undefined = undefined;
+ try {
+ file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
+ } catch (error) {
+ Logger.error(`OpenSync failed. Code: ${error.code}, message : ${error.message}`);
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, `OpenSync failed. Code: ${error.code}, message : ${error.message}`);
+ }
+ return file;
+ }
+ // 2,打开Dlp文件
+ // [Start dlp_prepareForOpenDlpFile]
+ openDlpFile(dlpUri: string, fileName: string, fd: number) {
+ let want:Want = {
+ 'action': 'ohos.want.action.viewData',
+ 'uri': dlpUri,
+ 'parameters' : {
+ 'fileName': {
+ 'name': fileName
+ },
+ 'keyFd': {
+ 'type': 'FD',
+ 'value': fd
+ }
+ }
+ }
+
+ let context = getContext() as common.UIAbilityContext; // 获取当前UIAbilityContext
+
+ try {
+ console.log('openDLPFile:' + JSON.stringify(want));
+ console.log('openDLPFile: delegator:' + JSON.stringify(context));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'openDLPFile:' + JSON.stringify(want));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'openDLPFile: delegator:' + JSON.stringify(context));
+ context.startAbility(want);
+ } catch (err) {
+ console.error('openDLPFile startAbility failed' + (err as BusinessError).code);
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'openDLPFile startAbility failed' + (err as BusinessError).code);
+ this.result = 'openDLPFile startAbility failed' + (err as BusinessError).code;
+ return;
+ }
+ }
+
+ prepareForOpenDlpFile() {
+ let file = this.openFile(this.uri);
+ if (!file) {
+ return;
+ }
+ this.openDlpFile(this.uri, this.fileName, file.fd);
+
+ }
+ // [End dlp_prepareForOpenDlpFile]
+
+ //3,生成DLP文件
+ // [Start dlp_generateDlpFiles]
+ generateDlpFiles() {
+ try {
+ let fileUri: string = this.uri;
+ let fileName: string = this.fileName;
+ let context = getContext() as common.UIAbilityContext; // 获取当前UIAbilityContext
+ let want: Want = {
+ 'uri': fileUri,
+ 'parameters': {
+ 'displayName': fileName
+ }
+ };// 请求参数
+ dlpPermission.startDLPManagerForResult(context, want).then((res: dlpPermission.DLPManagerResult) => {
+ this.result = 'startDLPManagerForResult result.resultCode:' + res.resultCode;
+ console.info('startDLPManagerForResult res.resultCode:' + res.resultCode);
+ console.info('startDLPManagerForResult res.want:' + JSON.stringify(res.want));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'startDLPManagerForResult res.resultCode:' + res.resultCode);
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'startDLPManagerForResult res.want:' + JSON.stringify(res.want));
+ });
+ } catch (err) {
+ this.result = 'startDLPManagerForResult error:' + (err as BusinessError).code + (err as BusinessError).message;
+ console.error('startDLPManagerForResult error:' + (err as BusinessError).code + (err as BusinessError).message);
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'startDLPManagerForResult error:' + (err as BusinessError).code + (err as BusinessError).message);
+ }
+ }
+ // [End dlp_generateDlpFiles]
+
+ // 4,查询当前应用是否在沙箱中
+ // [Start dlp_isInSandBox]
+ isInSandbox() {
+ dlpPermission.isInSandbox().then((data) => {
+ this.result = 'isInSandbox result: ' + JSON.stringify(data);
+ console.log('isInSandbox result: ' + JSON.stringify(data));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'isInSandbox result: ' + JSON.stringify(data));
+ }).catch((err:BusinessError) => {
+ this.result = 'isInSandbox error: ' + JSON.stringify(err);
+ console.error('isInSandbox error: ' + JSON.stringify(err));
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'isInSandbox error: ' + JSON.stringify(err));
+ });
+ }
+ // [End dlp_isInSandBox]
+
+ // 5,查询当前编辑的文件权限
+ // [Start dlp_getDLPPermissionInfo]
+ getDLPPermissionInfo() {
+ dlpPermission.getDLPPermissionInfo().then((data) => {
+ this.result = 'getDLPPermissionInfo result: ' + JSON.stringify(data);
+ console.log('getDLPPermissionInfo, result: ' + JSON.stringify(data));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'getDLPPermissionInfo result: ' + JSON.stringify(data));
+ }).catch((err:BusinessError) => {
+ this.result = 'getDLPPermissionInfo error: ' + JSON.stringify(err);
+ console.error('getDLPPermissionInfo: ' + JSON.stringify(err));
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'getDLPPermissionInfo error: ' + JSON.stringify(err));
+ });
+ }
+ // [End dlp_getDLPPermissionInfo]
+
+ //6,获取当前可支持DLP方案的文件拓展名类型列表
+ // [Start dlp_getDLPSupportedFileTypes]
+ getDLPSupportedFileTypes() {
+ dlpPermission.getDLPSupportedFileTypes((err, result) => {
+ console.log('getDLPSupportedFileTypes: ' + JSON.stringify(err));
+ console.log('getDLPSupportedFileTypes: ' + JSON.stringify(result));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'getDLPSupportedFileTypes: ' + JSON.stringify(err));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'getDLPSupportedFileTypes: ' + JSON.stringify(result));
+ this.result = 'getDLPSupportedFileTypes result: ' + JSON.stringify(result);
+ });
+ }
+ // [End dlp_getDLPSupportedFileTypes]
+
+ //7,判断当前打开文件是否是DLP文件
+ // [Start dlp_isCurrentDlpFile]
+ isCurrentDlpFile() {
+ let file = this.openFile(this.uri);
+ if(!file) {
+ this.result = '请打开一个文件!';
+ return;
+ }
+ dlpPermission.isDLPFile(file.fd).then((res) => {
+ if (res.valueOf()) {
+ this.result = 'isDLPFile result: ' + JSON.stringify(res);
+ } else {
+ this.result = '请打开一个dlp文件! ';
+ }
+ console.info('res', res);
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'res' + res);
+ }).catch((err:BusinessError) => {
+ this.result = 'isDLPFile error: ' + (err as BusinessError).code + (err as BusinessError).message;
+ console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ }).finally(() => {
+ fs.closeSync(file);
+ });
+ }
+ // [End dlp_isCurrentDlpFile]
+
+ // 8,订阅、取消订阅DLP打开事件
+ // [Start dlp_subscribe]
+ event(info: dlpPermission.AccessedDLPFileInfo) {
+ console.info('openDlpFile event', info.uri, info.lastOpenTime);
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'openDlpFile event' + info.uri + info.lastOpenTime);
+ }
+
+ unSubscribe() {
+ try {
+ dlpPermission.off('openDLPFile', this.event); // 取消订阅
+ this.result = 'unSubscribe result: 已取消注册';
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'unSubscribe result: 已取消注册');
+ } catch (err) {
+ console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ this.result = 'unSubscribe error: 取消注册失败';
+ }
+ }
+
+ subscribe() {
+ try {
+ dlpPermission.on('openDLPFile', this.event); // 订阅
+ this.result = 'subscribe result: 已注册';
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'subscribe result: 已注册');
+ } catch (err) {
+ console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ this.result = 'subscribe error: 注册失败';
+ }
+ }
+ // [End dlp_subscribe]
+
+ // 9,获取DLP文件打开记录
+ // [Start dlp_getDLPFileAccessRecords]
+ getDLPFileAccessRecords() {
+ dlpPermission.getDLPFileAccessRecords().then((res) => {
+ this.result = 'getDLPFileAccessRecords result: ' + JSON.stringify(res);
+ console.info('res', JSON.stringify(res));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'res' + JSON.stringify(res));
+ }).catch((err: BusinessError) => {
+ this.result = 'getDLPFileAccessRecords error: ' + (err as BusinessError).code + (err as BusinessError).message;
+ console.error('error: ', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ });
+ }
+ // [End dlp_getDLPFileAccessRecords]
+
+ // 10,获取DLP文件保留沙箱记录
+ // [Start dlp_getRetentionSandboxList]
+ getRetentionSandboxList() {
+ dlpPermission.getRetentionSandboxList().then((res) => {
+ this.result = 'getRetentionSandboxList result: ' + JSON.stringify(res);
+ console.info('res', JSON.stringify(res));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'res' + JSON.stringify(res));
+ }).catch((err: BusinessError) => {
+ this.result = 'getRetentionSandboxList error' + (err as BusinessError).code + (err as BusinessError).message;
+ console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ });
+ }
+ // [End dlp_getRetentionSandboxList]
+
+ // 11,设置沙箱应用配置
+ // [Start dlp_setSandboxAppConfig]
+ setSandboxAppConfig() {
+ dlpPermission.setSandboxAppConfig('configInfo').then(() => {
+ this.result = 'setSandboxAppConfig result: 设置沙箱应用配置信息成功';
+ console.info('res', '设置沙箱应用配置信息成功');
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'setSandboxAppConfig result: 设置沙箱应用配置信息成功');
+ }).catch((err: BusinessError) => {
+ this.result = 'setSandboxAppConfig error: ' + (err as BusinessError).code + (err as BusinessError).message;
+ console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ });
+ }
+ // [End dlp_setSandboxAppConfig]
+
+ // 12,清理沙箱应用配置信息
+ // [Start dlp_cleanSandboxAppConfig]
+ cleanSandboxAppConfig() {
+ dlpPermission.cleanSandboxAppConfig().then(() => {
+ this.result = 'cleanSandboxAppConfig result: 清理沙箱成功';
+ console.info('res', '清理沙箱成功');
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'cleanSandboxAppConfig result: 清理沙箱成功');
+ }).catch((err: BusinessError) => {
+ this.result = 'cleanSandboxAppConfig error: ' + (err as BusinessError).code + (err as BusinessError).message;
+ console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ });
+ }
+ // [End dlp_cleanSandboxAppConfig]
+
+ // 13,获取DLP文件保留沙箱记录
+ // [Start dlp_getSandboxAppConfig]
+ getSandboxAppConfig() {
+ dlpPermission.getSandboxAppConfig().then((res) => {
+ this.result = 'getSandboxAppConfig result: ' + JSON.stringify(res);
+ console.info('res', JSON.stringify(res));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'getSandboxAppConfig result: ' + JSON.stringify(res));
+ }).catch((err: BusinessError) => {
+ this.result = 'getSandboxAppConfig error: ' + (err as BusinessError).code + (err as BusinessError).message;
+ console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ });
+ }
+ // [End dlp_getSandboxAppConfig]
+
+ // 14,以无边框形式打开DLP权限管理应用
+ // [Start dlp_startDLPManagerForResult]
+ startDLPManagerForResult() {
+ try {
+ let context = getContext() as common.UIAbilityContext; // 获取当前UIAbilityContext
+ let want:Want = {
+ 'uri': this.uri,
+ 'parameters' : {
+ 'displayName': this.fileName
+ }
+ }; // 请求参数
+ dlpPermission.startDLPManagerForResult(context, want).then((res) => {
+ this.result = 'startDLPManagerForResult resultCode: ' + res.resultCode;
+ console.info('res.resultCode', res.resultCode);
+ console.info('res.want', JSON.stringify(res.want));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'res.resultCode' + res.resultCode);
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'res.want' + JSON.stringify(res.want));
+ }); // 打开DLP权限管理应用
+ } catch (err) {
+ this.result = 'startDLPManagerForResult error' + err.code + err.message;
+ console.error('error', err.code, err.message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ }
+ }
+ // [End dlp_startDLPManagerForResult]
+
+ // 15,查询当前系统是否提供DLP特性
+ // [Start dlp_isDLPFeature]
+ isDLPFeature() {
+ dlpPermission.isDLPFeatureProvided().then((res) => {
+ this.result = 'isDLPFeatureProvided result: ' + JSON.stringify(res.valueOf());
+ console.info('res', JSON.stringify(res.valueOf()));
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'isDLPFeatureProvided result: ' + JSON.stringify(res.valueOf()));
+ }).catch((err: BusinessError) => {
+ this.result = 'isDLPFeatureProvided error: ' + (err as BusinessError).code + (err as BusinessError).message;
+ console.error('error: ', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ });
+ }
+ // [End dlp_isDLPFeature]
+
+ // 16,设置企业应用防护策略
+ // [Start dlp_setDLPProtectPolicy]
+ setDLPProtectPolicy() {
+ try {
+ let attributeValues: string[] = [ '1' ];
+ let attribute: Attribute = {
+ attributeId: 'DeviceHealthyStatus',
+ attributeValues: attributeValues,
+ valueType: 0,
+ opt: 2
+ }; // 属性信息。
+ let rule: Rule = {
+ ruleId: 'ruleId',
+ attributes: [ attribute ]
+ }; // 规则。
+ let policy: Policy = {
+ rules: [ rule ],
+ policyId: 'policyId',
+ ruleConflictAlg: 0
+ }; // 策略。
+ let enterprisePolicy: dlpPermission.EnterprisePolicy = {
+ policyString: JSON.stringify(policy)
+ };
+ dlpPermission.setEnterprisePolicy(enterprisePolicy);
+ console.info('set enterprise policy success');
+ this.result = 'set enterprise policy success';
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'set enterprise policy success');
+ } catch (err) {
+ console.error('error:' + err.code + err.message); // 失败报错。
+ this.result = 'error:' + err.code + err.message;
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error' + (err as BusinessError).code + (err as BusinessError).message);
+ }
+ }
+ // [End dlp_setDLPProtectPolicy]
+
+ // 17,识别指定文件中的敏感内容
+ // [Start dlp_scanSensitiveInfo]
+ scanSensitiveInfo() {
+ let filepath = this.uri;
+ let policies: identifySensitiveContent.Policy[] = [
+ {'sensitiveLabel':'1', 'keywords':[], 'regex':''}
+ ];
+ try {
+ identifySensitiveContent.scanFile(filepath, policies).then(records => {
+ console.info('scanFile finish');
+ this.result = 'scanFile finish';
+ hilog.info(HILOG_DLP_DOMAIN, HILOG_TAG, 'scanFile finish');
+ }).catch((err:Error) => {
+ console.error('error message', err.message);
+ this.result = 'error message' + err.message;
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error message' + err.message);
+ })
+ } catch (err) {
+ console.error('error message', err.message);
+ this.result = 'error message' + err.message;
+ hilog.error(HILOG_DLP_DOMAIN, HILOG_TAG, 'error message' + err.message);
+ }
+ }
+ // [End dlp_scanSensitiveInfo]
+
+ build() {
+ Column() {
+ Row() {
+ Text($r('app.string.file_list'))
+ .fontFamily('HarmonyHeiTi-Bold')
+ .fontSize(30)
+ .fontWeight(700)
+ .fontColor(Color.Black)
+ Row() {
+ Image($r('app.media.ic_saveas'))
+ .width(25)
+ .height(25)
+ .id('newFile')
+ .onClick(() => {
+ // 使用默认预览打开文件
+ this.prepareForOpenDlpFile();
+ })
+ Image($r('app.media.ic_folder'))
+ .width(25)
+ .height(25)
+ .id('folder')
+ .margin({ left: 30 })
+ .onClick(() => {
+ // 读入文件的基本信息
+ this.callFilePickerSelectFile();
+ })
+ }
+ }.justifyContent(FlexAlign.SpaceBetween)
+ .width('100%')
+ Row() {
+ Text('3, 生成DLP文件')
+ .id('generateDlpFiles')
+ .width(50)
+ .backgroundColor(Color.Blue)
+ .onClick(() => {
+ this.generateDlpFiles();
+ })
+ Text('')
+ .width(10)
+ Text('4, 是否在沙箱中')
+ .id('isInSandBox')
+ .width(50)
+ .backgroundColor(Color.Green)
+ .onClick(() => {
+ this.isInSandbox();
+ })
+ Text('')
+ .width(10)
+ Text('5, 查询当前编辑的文件权限')
+ .id('getDLPPermissionInfo')
+ .width(50)
+ .backgroundColor(Color.Pink)
+ .onClick(() => {
+ this.getDLPPermissionInfo();
+ })
+ Text('')
+ .width(10)
+ Text('6, 查看支持加密的文件类型')
+ .id('getDLPSupportedFileTypes')
+ .width(50)
+ .backgroundColor(Color.Gray)
+ .onClick(() => {
+ this.getDLPSupportedFileTypes();
+ })
+ Text('')
+ .width(10)
+ Text('7, 判断当前打开文件是否是DLP文件')
+ .id('isCurrentDlpFile')
+ .width(50)
+ .backgroundColor(Color.Red)
+ .onClick(() => {
+ this.isCurrentDlpFile();
+ })
+ }
+ Row() {
+ Text('8, 订阅DLP打开事件')
+ .id('subscribe')
+ .width(50)
+ .backgroundColor(Color.Gray)
+ .onClick(() => {
+ this.subscribe();
+ })
+ Text('')
+ .width(5)
+ Text('8, 取消订阅DLP打开事件')
+ .id('unSubscribe')
+ .width(50)
+ .backgroundColor(Color.Gray)
+ .onClick(() => {
+ this.unSubscribe();
+ })
+ Text('')
+ .width(10)
+ Text('9, 获取DLP文件打开记录')
+ .id('getDLPFileAccessRecords')
+ .width(50)
+ .backgroundColor(Color.Pink)
+ .onClick(() => {
+ this.getDLPFileAccessRecords();
+ })
+ Text('')
+ .width(10)
+ Text('10, 获取DLP文件保留沙箱记录')
+ .id('getRetentionSandboxList')
+ .width(50)
+ .backgroundColor(Color.Orange)
+ .onClick(() => {
+ this.getRetentionSandboxList();
+ })
+ Text('')
+ .width(10)
+ Text('11, 设置沙箱应用配置信息')
+ .id('setSandboxAppConfig')
+ .width(50)
+ .backgroundColor(Color. Blue)
+ .onClick(() => {
+ this.setSandboxAppConfig();
+ })
+ }
+ Row() {
+ Text('12, 清理沙箱应用配置信息')
+ .id('cleanSandboxAppConfig')
+ .width(50)
+ .backgroundColor(Color.Green)
+ .onClick(() => {
+ this.cleanSandboxAppConfig();
+ })
+ Text('')
+ .width(10)
+ Text('13, 查询沙箱应用配置信息')
+ .id('getSandboxAppConfig')
+ .width(50)
+ .backgroundColor(Color.Pink)
+ .onClick(() => {
+ this.getSandboxAppConfig();
+ })
+ Text('')
+ .width(10)
+ Text('14, 以无边框形式打开DLP权限管理应用')
+ .id('startDLPManagerForResult')
+ .width(50)
+ .backgroundColor(Color.Red)
+ .onClick(() => {
+ this.startDLPManagerForResult();
+ })
+ Text('')
+ .width(10)
+ Text('15, 查询提供DLP特性')
+ .id('isDLPFeature')
+ .width(50)
+ .backgroundColor(Color.Orange)
+ .onClick(() => {
+ this.isDLPFeature();
+ })
+ Text('')
+ .width(10)
+ Text('16, 设置企业应用防护策略')
+ .id('setDLPProtectPolicy')
+ .width(50)
+ .backgroundColor(Color.Gray)
+ .onClick(() => {
+ this.setDLPProtectPolicy();
+ })
+ Text('')
+ .width(10)
+ Text('17, 识别指定文件中的敏感内容')
+ .id('scanSensitiveInfo')
+ .width(50)
+ .backgroundColor(Color.Green)
+ .onClick(() => {
+ this.scanSensitiveInfo();
+ })
+ }
+ Row() {
+ Text('运行结果: ' + `${this.result}`)
+ }
+
+ // 文件列表
+ List({ space: 12, initialIndex: 0 }) {
+ ForEach(this.fileInfos, (item: FileInfoType, index: number) => {
+ ListItem() {
+ Row() {
+ Row() {
+ Image($r('app.media.ic_files_grid_txt'))
+ .width(30)
+ .height(30)
+ .margin({ left: 15, right: 19 })
+
+ Text(item.fileName)
+ .fontSize(16)
+ .fontFamily('HarmonyHeiTi-Medium')
+ .fontColor('#182431')
+ .lineHeight(22)
+ .fontWeight(500)
+ .textAlign(TextAlign.Start)
+ .margin({ left: 0, right: 16 })
+ .width('50%')
+ }
+
+ if (!this.itemShowDeleteButton) {
+ Text(`Size: 0B`)
+ .fontSize(14)
+ .fontFamily('HarmonyHeiTi-Medium')
+ .lineHeight(19)
+ .fontColor('#182431')
+ .textAlign(TextAlign.End)
+ .opacity(0.6)
+ .width('20.8%')
+ .margin({ left: 0, right: 12 })
+ } else {
+ Row() {
+ Image($r('app.media.delete'))
+ .width(30)
+ .height(30)
+ .id('deleteBtn')
+ .margin({ left: 15, right: 19 })
+ .onClick(() => {
+ let currentIndex: number = -1;
+ this.fileInfos.forEach((fileInfoItem: FileInfoType, ind: number) => {
+ if (item.fileName === fileInfoItem.fileName) {
+ currentIndex = ind;
+ }
+ });
+ this.mediaFileUri.deleteFile(this.fileInfos[currentIndex].fileUri).then(async () => {
+ this.fileInfos.splice(currentIndex, 1);
+ this.itemShowDeleteButton = false;
+ await this.deleteDLPFile(item);
+ this.mediaFileUri.getAllFiles(context, this.dlpFileInfos);
+ })
+ })
+ Image(item.isEncryption ? $r('app.media.ic_public_unlock_filled') : $r('app.media.ic_public_lock_filled'))
+ .width(30)
+ .height(30)
+ .id('encryption')
+ .onClick(async () => {
+ if (item.isEncryption) {
+ item.isEncryption = false;
+ this.itemShowDeleteButton = false;
+ await this.deleteDLPFile(item);
+ } else {
+ this.currentSelectedFileUri = item.fileUri;
+ this.dialogController.open();
+ this.itemShowDeleteButton = false;
+ }
+ })
+ }
+ }
+
+ }
+ .justifyContent(FlexAlign.SpaceBetween)
+ .borderRadius(24)
+ .width('100%')
+ .height(64)
+ .padding({ right: 12 })
+ .backgroundColor('#FFFFFF')
+ }
+ .id('fileItem')
+ .onClick(async () => {
+ await this.determineEncryption(item);
+ })
+ .gesture(LongPressGesture({ repeat: true })
+ .onAction((event?: GestureEvent) => {
+ this.itemShowDeleteButton = true;
+ })
+ )
+ })
+ }
+ .listDirection(Axis.Vertical) // 排列方向
+ .edgeEffect(EdgeEffect.Spring) // 滑动到边缘无效果
+ .scrollBar(BarState.Auto)
+ .alignListItem(ListItemAlign.Center)
+ .margin({ top: '1%', left: 12, right: 12 })
+ }.width('100%')
+ .height('100%')
+ .padding(12)
+ .backgroundColor('#f1f3f5')
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/ets/util/Logger.ts b/Security/DLP/entry/src/main/ets/util/Logger.ts
new file mode 100644
index 0000000000000000000000000000000000000000..ab4fc6047955e72292fc5858d66481f58813a929
--- /dev/null
+++ b/Security/DLP/entry/src/main/ets/util/Logger.ts
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import hilog from '@ohos.hilog'
+
+class Logger {
+ private domain: number;
+ private prefix: string;
+ private format: string = '%{public}s, %{public}s';
+
+ constructor(prefix: string) {
+ this.prefix = prefix;
+ this.domain = 0xFF00;
+ }
+
+ debug(...args: string[]) {
+ hilog.debug(this.domain, this.prefix, this.format, args);
+ }
+
+ info(...args: string[]) {
+ hilog.info(this.domain, this.prefix, this.format, args);
+ }
+
+ warn(...args: string[]) {
+ hilog.warn(this.domain, this.prefix, this.format, args);
+ }
+
+ error(...args: string[]) {
+ hilog.error(this.domain, this.prefix, this.format, args);
+ }
+}
+
+export default new Logger('Sample_DLP');
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/ets/util/ResourceUtils.ets b/Security/DLP/entry/src/main/ets/util/ResourceUtils.ets
new file mode 100644
index 0000000000000000000000000000000000000000..95ea48f5c32d5603b8bb61787045d3bb4d7fac5b
--- /dev/null
+++ b/Security/DLP/entry/src/main/ets/util/ResourceUtils.ets
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import common from '@ohos.app.ability.common';
+
+/**
+ * getResourceString将Resource类型的数据转换成string类型的数据
+ * @param context
+ * @param ResourceData
+ */
+export function getResourceString(context: common.UIAbilityContext, resourceData: Resource): string {
+ let stringData: string = context.resourceManager.getStringSync(resourceData.id);
+ return stringData;
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/module.json5 b/Security/DLP/entry/src/main/module.json5
new file mode 100644
index 0000000000000000000000000000000000000000..daaa9a68886c98a224c25540d33700fe59f69550
--- /dev/null
+++ b/Security/DLP/entry/src/main/module.json5
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+{
+ "module": {
+ "name": "entry",
+ "type": "entry",
+ "description": "$string:module_desc",
+ "mainElement": "EntryAbility",
+ "deviceTypes": [
+ "default",
+ "tablet"
+ ],
+ "deliveryWithInstall": true,
+ "installationFree": false,
+ "pages": "$profile:main_pages",
+ "abilities": [
+ {
+ "name": "EntryAbility",
+ "srcEntry": "./ets/entryability/EntryAbility.ts",
+ "description": "$string:EntryAbility_desc",
+ "icon": "$media:icon",
+ "label": "$string:EntryAbility_label",
+ "startWindowIcon": "$media:icon",
+ "startWindowBackground": "$color:start_window_background",
+ "exported": true,
+ // [Start dlp_configurationModule]
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home",
+ "ohos.want.action.viewData"
+ ]
+ }
+ ]
+ // [End dlp_configurationModule]
+ }
+ ],
+ "requestPermissions": [
+ {
+ "name": "ohos.permission.FILE_ACCESS_MANAGER",
+ },
+ {
+ "name": "ohos.permission.STORAGE_MANAGER",
+ },
+ {
+ "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
+ },
+ {
+ "name": "ohos.permission.ACCESS_DLP_FILE"
+ },
+ {
+ "name": "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS"
+ },
+ {
+ "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS"
+ },
+ {
+ "name": "ohos.permission.GET_LOCAL_ACCOUNTS"
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/element/color.json b/Security/DLP/entry/src/main/resources/base/element/color.json
new file mode 100644
index 0000000000000000000000000000000000000000..47ff61743b20fe3a1edc8525409ee3b7b2e040d0
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/element/color.json
@@ -0,0 +1,16 @@
+{
+ "color": [
+ {
+ "name": "start_window_background",
+ "value": "#FFFFFF"
+ },
+ {
+ "name": "folder_color_99182431",
+ "value": "#99182431"
+ },
+ {
+ "name": "modified_time_font_color",
+ "value": "#A3A7AD"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/element/string.json b/Security/DLP/entry/src/main/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..5ddf9dac183288618b08e797b22129e567ff9a8b
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/element/string.json
@@ -0,0 +1,64 @@
+{
+ "string": [
+ {
+ "name": "module_desc",
+ "value": "module description"
+ },
+ {
+ "name": "EntryAbility_desc",
+ "value": "description"
+ },
+ {
+ "name": "EntryAbility_label",
+ "value": "label"
+ },
+ {
+ "name": "file_list",
+ "value": "File List"
+ },
+ {
+ "name": "date",
+ "value": "Today 9:00"
+ },
+ {
+ "name": "document_type",
+ "value": "work"
+ },
+ {
+ "name": "authorization_reminder",
+ "value": "Please select authorization."
+ },
+ {
+ "name": "encryption_protection",
+ "value": "Encryption protection."
+ },
+ {
+ "name": "authorization_description",
+ "value": "Authorize users to access permissions while restricting their permissions such as no file permissions, read-only, and editing."
+ },
+ {
+ "name": "user_access_rights",
+ "value": "User Access Rights."
+ },
+ {
+ "name": "read_only",
+ "value": "Read only"
+ },
+ {
+ "name": "edit_only",
+ "value": "Edit only"
+ },
+ {
+ "name": "cancel",
+ "value": "cancel"
+ },
+ {
+ "name": "confirm",
+ "value": "confirm"
+ },
+ {
+ "name": "init_file_name",
+ "value": "xxx_contract.txt"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/back.svg b/Security/DLP/entry/src/main/resources/base/media/back.svg
new file mode 100644
index 0000000000000000000000000000000000000000..95e1f5dcafef66bc67faefd4f4236d967fb2bf1e
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/back.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/delete.svg b/Security/DLP/entry/src/main/resources/base/media/delete.svg
new file mode 100644
index 0000000000000000000000000000000000000000..2f1c1fb0fe0a5f265cb70d4a5f5163c9360b934d
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/delete.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/ic_docs.svg b/Security/DLP/entry/src/main/resources/base/media/ic_docs.svg
new file mode 100644
index 0000000000000000000000000000000000000000..1e10662cd8510642ac606e4f7a78181715bfc3f4
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/ic_docs.svg
@@ -0,0 +1,13 @@
+
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/ic_files_grid_txt.svg b/Security/DLP/entry/src/main/resources/base/media/ic_files_grid_txt.svg
new file mode 100644
index 0000000000000000000000000000000000000000..a1c16748273cd6660b44f2b76d98ab10ad19a1de
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/ic_files_grid_txt.svg
@@ -0,0 +1,16 @@
+
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/ic_folder.svg b/Security/DLP/entry/src/main/resources/base/media/ic_folder.svg
new file mode 100644
index 0000000000000000000000000000000000000000..9b39e709bbd0424fb83e1e9ba73da002293916b8
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/ic_folder.svg
@@ -0,0 +1,13 @@
+
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/ic_public_detail.svg b/Security/DLP/entry/src/main/resources/base/media/ic_public_detail.svg
new file mode 100644
index 0000000000000000000000000000000000000000..2cfaa231a3eb4548e917ede327fed9d2968bd580
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/ic_public_detail.svg
@@ -0,0 +1,13 @@
+
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/ic_public_lock_filled.svg b/Security/DLP/entry/src/main/resources/base/media/ic_public_lock_filled.svg
new file mode 100644
index 0000000000000000000000000000000000000000..58182d5f47502c63fd3703ebecaa841b4a855828
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/ic_public_lock_filled.svg
@@ -0,0 +1,13 @@
+
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/ic_public_spinner_small.svg b/Security/DLP/entry/src/main/resources/base/media/ic_public_spinner_small.svg
new file mode 100644
index 0000000000000000000000000000000000000000..3a724d3cbcc3144951b7fd9d538b55982ba81681
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/ic_public_spinner_small.svg
@@ -0,0 +1,13 @@
+
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/ic_public_unlock_filled.svg b/Security/DLP/entry/src/main/resources/base/media/ic_public_unlock_filled.svg
new file mode 100644
index 0000000000000000000000000000000000000000..c8783337416058126ee56585364b049af8776f22
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/ic_public_unlock_filled.svg
@@ -0,0 +1,13 @@
+
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/ic_saveas.svg b/Security/DLP/entry/src/main/resources/base/media/ic_saveas.svg
new file mode 100644
index 0000000000000000000000000000000000000000..19b2892ca2facb351ee1c6f8710799dfeac9b443
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/ic_saveas.svg
@@ -0,0 +1,13 @@
+
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/icon.png b/Security/DLP/entry/src/main/resources/base/media/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/Security/DLP/entry/src/main/resources/base/media/icon.png differ
diff --git a/Security/DLP/entry/src/main/resources/base/media/more_list.svg b/Security/DLP/entry/src/main/resources/base/media/more_list.svg
new file mode 100644
index 0000000000000000000000000000000000000000..beaecc56efd1efef11052740cd383fdd96be8e8d
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/more_list.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/save.svg b/Security/DLP/entry/src/main/resources/base/media/save.svg
new file mode 100644
index 0000000000000000000000000000000000000000..78d5245d0c330a3710bdec6ae4be026b454e1508
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/save.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/base/media/triangle.svg b/Security/DLP/entry/src/main/resources/base/media/triangle.svg
new file mode 100644
index 0000000000000000000000000000000000000000..6bd84c78e21a55703c5625c0d881eb4ffb112c4f
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/media/triangle.svg
@@ -0,0 +1,11 @@
+
+
+
diff --git a/Security/DLP/entry/src/main/resources/base/profile/main_pages.json b/Security/DLP/entry/src/main/resources/base/profile/main_pages.json
new file mode 100644
index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/base/profile/main_pages.json
@@ -0,0 +1,5 @@
+{
+ "src": [
+ "pages/Index"
+ ]
+}
diff --git a/Security/DLP/entry/src/main/resources/en_US/element/string.json b/Security/DLP/entry/src/main/resources/en_US/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..9895010a4e2069c34aed0fff463f1eca6d7bfa1a
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/en_US/element/string.json
@@ -0,0 +1,68 @@
+{
+ "string": [
+ {
+ "name": "module_desc",
+ "value": "module description"
+ },
+ {
+ "name": "EntryAbility_desc",
+ "value": "description"
+ },
+ {
+ "name": "EntryAbility_label",
+ "value": "label"
+ },
+ {
+ "name": "file_list",
+ "value": "File List"
+ },
+ {
+ "name": "date",
+ "value": "Today 9:00"
+ },
+ {
+ "name": "document_type",
+ "value": "work"
+ },
+ {
+ "name": "encryption_reminder",
+ "value": "This file is already encrypted. Please select an unencrypted file for encryption."
+ },
+ {
+ "name": "encryption_protection",
+ "value": "Encryption protection."
+ },
+ {
+ "name": "authorization_description",
+ "value": "Authorize users to access permissions while restricting their permissions such as no file permissions, read-only, and editing."
+ },
+ {
+ "name": "user_access_rights",
+ "value": "User Access Rights."
+ },
+ {
+ "name": "read_only",
+ "value": "Read only"
+ },
+ {
+ "name": "edit_only",
+ "value": "Edit only"
+ },
+ {
+ "name": "cancel",
+ "value": "cancel"
+ },
+ {
+ "name": "confirm",
+ "value": "confirm"
+ },
+ {
+ "name": "init_file_name",
+ "value": "xxx_contract.txt"
+ },
+ {
+ "name": "authorization_reminder",
+ "value": "Please select authorization."
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/resources/zh_CN/element/string.json b/Security/DLP/entry/src/main/resources/zh_CN/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..9193868336b56d107bcc1bd983fcb2a5d187d44f
--- /dev/null
+++ b/Security/DLP/entry/src/main/resources/zh_CN/element/string.json
@@ -0,0 +1,68 @@
+{
+ "string": [
+ {
+ "name": "module_desc",
+ "value": "模块描述"
+ },
+ {
+ "name": "EntryAbility_desc",
+ "value": "description"
+ },
+ {
+ "name": "EntryAbility_label",
+ "value": "label"
+ },
+ {
+ "name": "file_list",
+ "value": "文件列表"
+ },
+ {
+ "name": "date",
+ "value": "今天 9:00"
+ },
+ {
+ "name": "document_type",
+ "value": "工作"
+ },
+ {
+ "name": "encryption_reminder",
+ "value": "此文件已是加密文件,请选择未加密文件进行加密!"
+ },
+ {
+ "name": "encryption_protection",
+ "value": "加密保护"
+ },
+ {
+ "name": "authorization_description",
+ "value": "授权用户访问权限,同时限制其只读、编辑等权限"
+ },
+ {
+ "name": "user_access_rights",
+ "value": "用户访问权限:"
+ },
+ {
+ "name": "read_only",
+ "value": "只读"
+ },
+ {
+ "name": "edit_only",
+ "value": "编辑"
+ },
+ {
+ "name": "cancel",
+ "value": "取消"
+ },
+ {
+ "name": "confirm",
+ "value": "确定"
+ },
+ {
+ "name": "init_file_name",
+ "value": "xxx合同.txt"
+ },
+ {
+ "name": "authorization_reminder",
+ "value": "请选择权限"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/main/syscap.json b/Security/DLP/entry/src/main/syscap.json
new file mode 100644
index 0000000000000000000000000000000000000000..318404e26878e2a3cef1fd979502e4ff6d86d22f
--- /dev/null
+++ b/Security/DLP/entry/src/main/syscap.json
@@ -0,0 +1,13 @@
+{
+ "devices": {
+ "general": [
+ "default",
+ "tablet"
+ ]
+ },
+ "development": {
+ "addedSysCaps": [
+ "SystemCapability.ArkUI.ArkUI.Circle"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/ohosTest/ets/test/Ability.test.ets b/Security/DLP/entry/src/ohosTest/ets/test/Ability.test.ets
new file mode 100644
index 0000000000000000000000000000000000000000..f4937c1d4563eef67882be73e1b754906335c9df
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/ets/test/Ability.test.ets
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, it, expect, beforeAll } from '@ohos/hypium';
+import Logger from './Logger';
+import { Driver, ON } from '@ohos.UiTest';
+import Want from '@ohos.app.ability.Want';
+import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
+import inputMethod from '@ohos.inputMethod';
+import resourceManager from '@ohos.resourceManager';
+
+const BUNDLE = 'DLP';
+const TAG = '[Sample_DLP_TEST]';
+const delegator = abilityDelegatorRegistry.getAbilityDelegator();
+
+async function getResourceString(resource: T): Promise {
+ let manage = delegator.getAppContext().resourceManager;
+ let text = await manage.getStringValue(resource);
+ return text;
+}
+
+export default function abilityTest() {
+ describe('ActsAbilityTest', () => {
+ beforeAll(async () => {
+ let want: Want = {
+ bundleName: 'com.samples.dlp',
+ abilityName: "EntryAbility"
+ }
+ await delegator.startAbility(want);
+ })
+ /**
+ * 允许
+ */
+ it(BUNDLE + 'authorization', 0, async () => {
+ Logger.info(TAG, BUNDLE + 'authorization begin')
+ let driver = Driver.create();
+ await driver.delayMs(5000);
+ // 点击聊天列表
+ await driver.assertComponentExist(ON.text('允许'));
+ let authorizateBtn = await driver.findComponent(ON.text('允许'));
+ await driver.delayMs(1000);
+ await authorizateBtn.click();
+ await driver.delayMs(1000);
+ })
+ /**
+ * 添加普通文件
+ */
+ it(BUNDLE + 'AddFiles', 0, async () => {
+ Logger.info(TAG, BUNDLE + 'AddFiles begin');
+ let driver = Driver.create();
+ await driver.delayMs(1000);
+ // 添加普通文件
+ await driver.assertComponentExist(ON.id('newFile'));
+ let addBtn = await driver.findComponent(ON.id('newFile'));
+ await driver.delayMs(1000);
+ await addBtn.click();
+ await driver.delayMs(1000);
+ let authorizateBtn = await driver.findComponent(ON.text(await getResourceString($r('app.string.text_content'))));
+ await driver.delayMs(1000);
+ if(authorizateBtn) {
+ await authorizateBtn.click();
+ await driver.delayMs(1000);
+ }
+ let authorizateBtn2 = await driver.findComponent(ON.text(await getResourceString($r('app.string.text_content'))));
+ await driver.delayMs(1000);
+ if(authorizateBtn2) {
+ await authorizateBtn2.click();
+ await driver.delayMs(1000);
+ }
+ let timestamp = new Date().getTime();
+ let textInput = await driver.findComponent(ON.type('TextInput'));
+ await driver.delayMs(1000);
+ await textInput.inputText(`xxx合同${timestamp}.txt`);
+ await driver.delayMs(1000);
+ let inputMethodController = inputMethod.getController();
+ inputMethodController.hideTextInput();
+ await driver.delayMs(1000);
+ let ImageArray = await driver.findComponents(ON.type('Image'));
+ Logger.info(TAG, `ImageArray lenth:${ImageArray.length}`);
+ let finishBtn = ImageArray[2];
+ await finishBtn.click();
+ Logger.info(TAG, BUNDLE + 'AddFiles end');
+ })
+ /**
+ * 加密操作
+ */
+ it(BUNDLE + 'AddOrdinaryFiles', 0, async () => {
+ Logger.info(TAG, BUNDLE + 'AddOrdinaryFiles begin');
+ let driver = Driver.create();
+ await driver.delayMs(1000);
+ // 点击聊天列表
+ await driver.assertComponentExist(ON.id('fileItem'));
+ let fileItem = await driver.findComponent(ON.id('fileItem'));
+ await driver.delayMs(1000);
+ await fileItem.longClick();
+ await driver.delayMs(1000);
+ await driver.assertComponentExist(ON.id('encryption'));
+ let encryptionBtn = await driver.findComponent(ON.id('encryption'));
+ await driver.delayMs(1000);
+ await encryptionBtn.click();
+ await driver.delayMs(1000);
+ // 设置编辑权限
+ let selectBtn = await driver.findComponent(ON.text('请选择权限'));
+ await selectBtn.click();
+ await driver.delayMs(1000);
+ let editBtn = await driver.findComponent(ON.text('编辑'));
+ await editBtn.click();
+ await driver.delayMs(1000);
+ let confirm = await driver.findComponent(ON.text('确定'));
+ await driver.delayMs(1000);
+ await confirm.click();
+ await driver.delayMs(1000);
+ })
+ /**
+ * 保存
+ */
+ it(BUNDLE + 'SaveContent', 0, async () => {
+ Logger.info(TAG, BUNDLE + 'SaveContent begin');
+ let driver = Driver.create();
+ await driver.delayMs(1000);
+ // 点击进入编辑页面
+ let authorizateBtn = await driver.findComponent(ON.text(await getResourceString($r('app.string.text_content'))));
+ await driver.delayMs(1000);
+ if (authorizateBtn) {
+ authorizateBtn.click();
+ await driver.delayMs(1000);
+ }
+ let fileItem = await driver.findComponent(ON.id('fileItem'));
+ await fileItem.click();
+ await driver.delayMs(3000);
+ let webBtn = await driver.findComponent(ON.id('webComponent'));
+ await driver.delayMs(1000);
+ await webBtn.click();
+ await webBtn.inputText('hello');
+ await driver.delayMs(3000);
+ // 点击保存
+ let saveBtn = await driver.findComponent(ON.id('saveBtn'));
+ await saveBtn.click();
+ await driver.delayMs(1000);
+ // 返回Home页面
+ let want: Want = {
+ bundleName: 'com.samples.dlp',
+ abilityName: "EntryAbility"
+ }
+ await delegator.startAbility(want);
+ Logger.info(TAG, BUNDLE + 'SaveContent end');
+ })
+ /**
+ * 只读权限
+ */
+ it(BUNDLE + 'OnlyRead', 0, async () => {
+ Logger.info(TAG, BUNDLE + 'OnlyRead begin');
+ let driver = Driver.create();
+ await driver.delayMs(3000);
+ // 点击进入编辑页面
+ let fileItem = await driver.findComponent(ON.id('fileItem'));
+ await fileItem.longClick();
+ await driver.delayMs(1000);
+ let encryptionBtn = await driver.findComponent(ON.id('encryption'));
+ await driver.delayMs(1000);
+ await encryptionBtn.click();
+ await driver.delayMs(1000);
+ let file = await driver.findComponent(ON.id('fileItem'));
+ await driver.delayMs(1000);
+ await file.longClick();
+ await driver.delayMs(1000);
+ let encryption = await driver.findComponent(ON.id('encryption'));
+ await encryption.click();
+ await driver.delayMs(1000);
+ // 设置只读权限
+ let selectBtn = await driver.findComponent(ON.text('请选择权限'));
+ await selectBtn.click();
+ await driver.delayMs(1000);
+ let readBtn = await driver.findComponent(ON.text('只读'));
+ await readBtn.click();
+ await driver.delayMs(1000);
+ let confirm = await driver.findComponent(ON.text('确定'));
+ await driver.delayMs(1000);
+ await confirm.click();
+ await driver.delayMs(1000);
+ Logger.info(TAG, BUNDLE + 'OnlyRead end');
+ })
+ /**
+ * 验证只读权限
+ */
+ it(BUNDLE + 'CheckOnlyRead', 0, async () => {
+ Logger.info(TAG, BUNDLE + 'CheckOnlyRead begin');
+ let driver = Driver.create();
+ await driver.delayMs(1000);
+ // 点击进入编辑页面
+ let fileItem = await driver.findComponent(ON.id('fileItem'));
+ await fileItem.click();
+ await driver.delayMs(1000);
+ Logger.info(TAG, BUNDLE + 'CheckOnlyRead end');
+ })
+ })
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/ohosTest/ets/test/List.test.ets b/Security/DLP/entry/src/ohosTest/ets/test/List.test.ets
new file mode 100644
index 0000000000000000000000000000000000000000..657d194164f932396390ddb56c59cbd65c7d1259
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/ets/test/List.test.ets
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import abilityTest from './Ability.test';
+
+export default function testsuite() {
+ abilityTest();
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/ohosTest/ets/test/Logger.ts b/Security/DLP/entry/src/ohosTest/ets/test/Logger.ts
new file mode 100644
index 0000000000000000000000000000000000000000..90c9e4074ae5ca0ba64357877d17ab76fe8f64f8
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/ets/test/Logger.ts
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import hilog from '@ohos.hilog';
+
+class Logger {
+ // 日志对应的领域标识
+ private domain: number = 0xF811;
+ // tag日志标识
+ private prefix: string = '[Samples_AuthorizedControl]';
+ // 格式字符串,用于日志的格式化输出
+ private format: string = '%{public}s, %{public}s';
+
+ constructor(prefix: string) {
+ this.prefix = prefix;
+ }
+
+ debug(...args: string[]): void {
+ hilog.debug(this.domain, this.prefix, this.format, args);
+ }
+
+ info(...args: string[]): void {
+ hilog.info(this.domain, this.prefix, this.format, args);
+ }
+
+ warn(...args: string[]): void {
+ hilog.warn(this.domain, this.prefix, this.format, args);
+ }
+
+ error(...args: string[]): void {
+ hilog.error(this.domain, this.prefix, this.format, args);
+ }
+}
+
+export default new Logger('[Samples_DLP]');
\ No newline at end of file
diff --git a/Security/DLP/entry/src/ohosTest/ets/testability/TestAbility.ets b/Security/DLP/entry/src/ohosTest/ets/testability/TestAbility.ets
new file mode 100644
index 0000000000000000000000000000000000000000..53e4446e5100ee4689d39d9fca650a40a28abd32
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/ets/testability/TestAbility.ets
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import UIAbility from '@ohos.app.ability.UIAbility';
+import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
+import hilog from '@ohos.hilog';
+import { Hypium } from '@ohos/hypium';
+import testsuite from '../test/List.test';
+import window from '@ohos.window';
+import Want from '@ohos.app.ability.Want';
+import AbilityConstant from '@ohos.app.ability.AbilityConstant';
+
+export default class TestAbility extends UIAbility {
+ onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
+ hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
+ hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
+ let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator
+ abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator()
+ let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs
+ abilityDelegatorArguments = abilityDelegatorRegistry.getArguments()
+ hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
+ Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
+ }
+
+ onDestroy() {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
+ }
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
+ windowStage.loadContent('testability/pages/Index', (err, data) => {
+ if (err.code) {
+ hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
+ return;
+ }
+ hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
+ JSON.stringify(data) ?? '');
+ });
+ }
+
+ onWindowStageDestroy() {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
+ }
+
+ onForeground() {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
+ }
+
+ onBackground() {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/ohosTest/ets/testability/pages/Index.ets b/Security/DLP/entry/src/ohosTest/ets/testability/pages/Index.ets
new file mode 100644
index 0000000000000000000000000000000000000000..e91baaf849736366acab7c54a1901943a480a1d2
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/ets/testability/pages/Index.ets
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import hilog from '@ohos.hilog';
+
+@Entry
+@Component
+struct Index {
+ aboutToAppear() {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
+ }
+
+ @State message: string = 'Hello World'
+
+ build() {
+ Row() {
+ Column() {
+ Text(this.message)
+ .fontSize(50)
+ .fontWeight(FontWeight.Bold)
+ Button() {
+ Text('next page')
+ .fontSize(20)
+ .fontWeight(FontWeight.Bold)
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .backgroundColor('#0D9FFB')
+ .width('35%')
+ .height('5%')
+ .onClick(() => {
+ })
+ }
+ .width('100%')
+ }
+ .height('100%')
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/Security/DLP/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts
new file mode 100644
index 0000000000000000000000000000000000000000..d9f862c2e09f9b021645449659f938ae0c87922f
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import hilog from '@ohos.hilog';
+import TestRunner from '@ohos.application.testRunner';
+import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
+
+var abilityDelegator = undefined
+var abilityDelegatorArguments = undefined
+
+async function onAbilityCreateCallback() {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
+}
+
+async function addAbilityMonitorCallback(err: any) {
+ hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
+}
+
+export default class OpenHarmonyTestRunner implements TestRunner {
+ constructor() {
+ }
+
+ onPrepare() {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
+ }
+
+ async onRun() {
+ hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
+ abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
+ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
+ const bundleName = abilityDelegatorArguments.bundleName;
+ const testAbilityName = 'TestAbility';
+ let lMonitor = {
+ abilityName: testAbilityName,
+ onAbilityCreate: onAbilityCreateCallback,
+ };
+ abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
+ const want = {
+ bundleName: bundleName,
+ abilityName: testAbilityName
+ };
+ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
+ abilityDelegator.startAbility(want, (err: any, data: any) => {
+ hilog.info(0x0000, 'testTag', 'startAbility : err : %{public}s', JSON.stringify(err) ?? '');
+ hilog.info(0x0000, 'testTag', 'startAbility : data : %{public}s', JSON.stringify(data) ?? '');
+ })
+ hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/ohosTest/module.json5 b/Security/DLP/entry/src/ohosTest/module.json5
new file mode 100644
index 0000000000000000000000000000000000000000..e6a499c49efe53f1a5bab25638ce6b00f612a7d8
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/module.json5
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+{
+ "module": {
+ "name": "entry_test",
+ "type": "feature",
+ "description": "$string:module_test_desc",
+ "mainElement": "TestAbility",
+ "deviceTypes": [
+ "default",
+ "tablet"
+ ],
+ "deliveryWithInstall": true,
+ "installationFree": false,
+ "pages": "$profile:test_pages",
+ "abilities": [
+ {
+ "name": "TestAbility",
+ "srcEntry": "./ets/testability/TestAbility.ets",
+ "description": "$string:TestAbility_desc",
+ "icon": "$media:icon",
+ "label": "$string:TestAbility_label",
+ "exported": true,
+ "startWindowIcon": "$media:icon",
+ "startWindowBackground": "$color:start_window_background",
+ "skills": [
+ {
+ "actions": [
+ "action.system.home"
+ ],
+ "entities": [
+ "entity.system.home"
+ ]
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/Security/DLP/entry/src/ohosTest/resources/base/element/color.json b/Security/DLP/entry/src/ohosTest/resources/base/element/color.json
new file mode 100644
index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/resources/base/element/color.json
@@ -0,0 +1,8 @@
+{
+ "color": [
+ {
+ "name": "start_window_background",
+ "value": "#FFFFFF"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/ohosTest/resources/base/element/string.json b/Security/DLP/entry/src/ohosTest/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..530112a76974db2856aed199cab476c09d99ece9
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/resources/base/element/string.json
@@ -0,0 +1,24 @@
+{
+ "string": [
+ {
+ "name": "module_test_desc",
+ "value": "test ability description"
+ },
+ {
+ "name": "TestAbility_desc",
+ "value": "the test ability"
+ },
+ {
+ "name": "TestAbility_label",
+ "value": "test label"
+ },
+ {
+ "name": "file_name",
+ "value": "xxx合同.txt"
+ },
+ {
+ "name": "text_content",
+ "value": "允许"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Security/DLP/entry/src/ohosTest/resources/base/media/icon.png b/Security/DLP/entry/src/ohosTest/resources/base/media/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/Security/DLP/entry/src/ohosTest/resources/base/media/icon.png differ
diff --git a/Security/DLP/entry/src/ohosTest/resources/base/profile/test_pages.json b/Security/DLP/entry/src/ohosTest/resources/base/profile/test_pages.json
new file mode 100644
index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe
--- /dev/null
+++ b/Security/DLP/entry/src/ohosTest/resources/base/profile/test_pages.json
@@ -0,0 +1,5 @@
+{
+ "src": [
+ "testability/pages/Index"
+ ]
+}
diff --git a/Security/DLP/hvigor/hvigor-config.json5 b/Security/DLP/hvigor/hvigor-config.json5
new file mode 100644
index 0000000000000000000000000000000000000000..61c774aac8c68d7663928699c499fd57f8278aae
--- /dev/null
+++ b/Security/DLP/hvigor/hvigor-config.json5
@@ -0,0 +1,17 @@
+{
+ "modelVersion": "5.1.1",
+ "dependencies": {
+ },
+ "execution": {
+ // "daemon": true, /* Enable daemon compilation. Default: true */
+ // "incremental": true, /* Enable incremental compilation. Default: true */
+ // "parallel": true, /* Enable parallel compilation. Default: true */
+ // "typeCheck": false, /* Enable typeCheck. Default: false */
+ },
+ "logging": {
+ // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
+ },
+ "debugging": {
+ // "stacktrace": false /* Disable stacktrace compilation. Default: false */
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/hvigorfile.ts b/Security/DLP/hvigorfile.ts
new file mode 100644
index 0000000000000000000000000000000000000000..2a4a8343e9944f8f8148d7c1be20d593f26e9ff3
--- /dev/null
+++ b/Security/DLP/hvigorfile.ts
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { appTasks } from '@ohos/hvigor-ohos-plugin';
+
+export default {
+ system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
+ plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
+}
diff --git a/Security/DLP/oh-package-lock.json5 b/Security/DLP/oh-package-lock.json5
new file mode 100644
index 0000000000000000000000000000000000000000..5f129da7043bcb321271e74dd5a22f5acf1af04c
--- /dev/null
+++ b/Security/DLP/oh-package-lock.json5
@@ -0,0 +1,21 @@
+{
+ "meta": {
+ "stableOrder": true,
+ "enableUnifiedLockfile": false
+ },
+ "lockfileVersion": 3,
+ "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
+ "specifiers": {
+ "@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6"
+ },
+ "packages": {
+ "@ohos/hypium@1.0.6": {
+ "name": "@ohos/hypium",
+ "version": "1.0.6",
+ "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==",
+ "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz",
+ "shasum": "3f5fed65372633233264b3447705b0831dfe7ea1",
+ "registryType": "ohpm"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Security/DLP/oh-package.json5 b/Security/DLP/oh-package.json5
new file mode 100644
index 0000000000000000000000000000000000000000..82cd4f5c4554d6865052776c28244f081d31b288
--- /dev/null
+++ b/Security/DLP/oh-package.json5
@@ -0,0 +1,13 @@
+{
+ "modelVersion": "5.1.1",
+ "license": "",
+ "devDependencies": {
+ "@ohos/hypium": "1.0.6"
+ },
+ "author": "",
+ "name": "dlp",
+ "description": "Please describe the basic information.",
+ "main": "",
+ "version": "1.0.0",
+ "dependencies": {}
+}
\ No newline at end of file
diff --git a/Security/DLP/ohosTest.md b/Security/DLP/ohosTest.md
new file mode 100644
index 0000000000000000000000000000000000000000..3f2c8b5e0f9e418ed07b0fb5634eec1eac40bcaf
--- /dev/null
+++ b/Security/DLP/ohosTest.md
@@ -0,0 +1,12 @@
+# 数据防泄漏测试用例归档
+
+## 用例表
+
+| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 |测试结果|
+|--------|-------------|----------------------|-------------------------------|--------------------------------|--------------------------------|
+| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 |Pass|
+| 新增普通文件 | 页面显示正常 | 点击新增按钮,输入文件名称,点击确定 | 拉起picker页面,文件命名成功,DLP页面显示新增文件 | 是 |Pass|
+| 加密授权 | 长按点击加密按钮 | | 弹出提示框 | 是 |Pass|
+| 验证编辑文件 | 文件已设置编辑权限 | 点击加密文件 | 成功跳转编辑应用 | 是 | Pass|
+| 编辑数据保存 | 编辑页面 | 输入文本数据 | 数据保存成功 | 是 | Pass|
+| 验证只读权限 | 文件已设置只读权限 | 点击文件 | 跳转编辑页面,页面置灰 | 是 | Pass|
\ No newline at end of file
diff --git a/Security/DLP/screenshots/devices/Encrypted.jpeg b/Security/DLP/screenshots/devices/Encrypted.jpeg
new file mode 100644
index 0000000000000000000000000000000000000000..178e6291c58c103e31522af69ee7e992262b2feb
Binary files /dev/null and b/Security/DLP/screenshots/devices/Encrypted.jpeg differ
diff --git a/Security/DLP/screenshots/devices/Encryption.jpeg b/Security/DLP/screenshots/devices/Encryption.jpeg
new file mode 100644
index 0000000000000000000000000000000000000000..18a643bec53705e9b391f2abbc89713c81c52aa0
Binary files /dev/null and b/Security/DLP/screenshots/devices/Encryption.jpeg differ
diff --git a/Security/DLP/screenshots/devices/FileEditPage.jpeg b/Security/DLP/screenshots/devices/FileEditPage.jpeg
new file mode 100644
index 0000000000000000000000000000000000000000..8ded28f2915398a1650577317846280118bb0b35
Binary files /dev/null and b/Security/DLP/screenshots/devices/FileEditPage.jpeg differ
diff --git a/Security/DLP/screenshots/devices/Index.jpeg b/Security/DLP/screenshots/devices/Index.jpeg
new file mode 100644
index 0000000000000000000000000000000000000000..b1ea54baa04f26f4d2679ccf229850dc720def3d
Binary files /dev/null and b/Security/DLP/screenshots/devices/Index.jpeg differ
diff --git a/Security/DLP/screenshots/devices/index_pages.jpg b/Security/DLP/screenshots/devices/index_pages.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..fc2eba597d81c83c2ad2d6c7ce1b56727a8e83b1
Binary files /dev/null and b/Security/DLP/screenshots/devices/index_pages.jpg differ
diff --git "a/Security/DLP/screenshots/devices/syn\345\207\272\351\224\231.png" "b/Security/DLP/screenshots/devices/syn\345\207\272\351\224\231.png"
new file mode 100644
index 0000000000000000000000000000000000000000..f01c3130d4141d8079ddf8e295725b3a3d9f5267
Binary files /dev/null and "b/Security/DLP/screenshots/devices/syn\345\207\272\351\224\231.png" differ
diff --git a/Security/DLP/screenshots/haps/DlpManager.hap b/Security/DLP/screenshots/haps/DlpManager.hap
new file mode 100644
index 0000000000000000000000000000000000000000..529679eed602fb1c15837ce412a9ae26267d6c03
Binary files /dev/null and b/Security/DLP/screenshots/haps/DlpManager.hap differ
diff --git a/Security/DLP/screenshots/haps/FileEdit.hap b/Security/DLP/screenshots/haps/FileEdit.hap
new file mode 100644
index 0000000000000000000000000000000000000000..ea95a31e3104837a9a0f982b1fe3c0507aaa023c
Binary files /dev/null and b/Security/DLP/screenshots/haps/FileEdit.hap differ
diff --git a/Security/DLP/screenshots/haps/FileEdit.tgz b/Security/DLP/screenshots/haps/FileEdit.tgz
new file mode 100644
index 0000000000000000000000000000000000000000..cc9254863427964293b5e0fadddff79786082b40
--- /dev/null
+++ b/Security/DLP/screenshots/haps/FileEdit.tgz
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5dcf30e40c826750500b947fc83c467bc07cc8847d7550556268ed1c2f8c2a4e
+size 81713