Description:build dlp_manager hap
Match-id-baeee53e221c72a6e9e87b1b3372ac4670fdae66
329
@ohos.dlpPermission.d.ts
vendored
Normal file
@ -0,0 +1,329 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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 { AsyncCallback } from "./basic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
*/
|
||||||
|
declare namespace dlpPermission {
|
||||||
|
export enum AuthPermType {
|
||||||
|
/**
|
||||||
|
* Read only access to DLP file.
|
||||||
|
* @since 9
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
*/
|
||||||
|
READ_ONLY = 1,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full control access to DLP file.
|
||||||
|
* @since 9
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
*/
|
||||||
|
FULL_CONTROL = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query access to DLP file from dlp permission service.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @return The access to a DLP file.
|
||||||
|
*/
|
||||||
|
function queryFileAccess(): Promise<AuthPermType>;
|
||||||
|
function queryFileAccess(callback: AsyncCallback<AuthPermType>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether current application is in DLP sandbox.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @return whether or not.
|
||||||
|
*/
|
||||||
|
function isInSandbox(): Promise<boolean>;
|
||||||
|
function isInSandbox(callback: AsyncCallback<boolean>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get support DLP file type.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @return The list of supported DLP file type.
|
||||||
|
*/
|
||||||
|
function getDlpSupportFileType(): Promise<Array<string>>;
|
||||||
|
function getDlpSupportFileType(callback: AsyncCallback<Array<string>>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install an application in DLP sandbox.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param bundleName Indicates the bundle name of the application.
|
||||||
|
* @param access Indicates the access to DLP file.
|
||||||
|
* @param userId Indicates the user ID.
|
||||||
|
* @return the appIndex installed application.
|
||||||
|
*/
|
||||||
|
function installDlpSandbox(bundleName: string, access: AuthPermType, userId: number): Promise<number>;
|
||||||
|
function installDlpSandbox(bundleName: string, access: AuthPermType, userId: number, callback: AsyncCallback<number>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uninstall an application in DLP sandbox.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param bundleName Indicates the bundle name of the application.
|
||||||
|
* @param userId Indicates the user ID.
|
||||||
|
* @param appIndex Indicates the index of dlp sandbox.
|
||||||
|
* @return -
|
||||||
|
*/
|
||||||
|
function uninstallDlpSandbox(bundleName: string, userId: number, appIndex: number): Promise<void>;
|
||||||
|
function uninstallDlpSandbox(bundleName: string, userId: number, appIndex: number, callback: AsyncCallback<void>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* register to the death of dlp permission service.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param type Type of the death event of service.
|
||||||
|
* @return -
|
||||||
|
*/
|
||||||
|
function on(type: "serviceDie", callback: Callback<void>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listen the state of DLP sandbox.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param bundleName Indicates the bundle name of the application.
|
||||||
|
* @param userId Indicates the user ID.
|
||||||
|
* @param appIndex Indicates the index of DLP sandbox.
|
||||||
|
* @return -
|
||||||
|
*/
|
||||||
|
export interface DlpSandboxStateParam {
|
||||||
|
bundleName: string;
|
||||||
|
userId: number;
|
||||||
|
appIndex: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribe the event reported when dlp sandbox uninstall.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param type Type of the uninstall sandbox event.
|
||||||
|
* @param listener Indicates the listenner of dlp sandbox state.
|
||||||
|
* @return -
|
||||||
|
*/
|
||||||
|
function on(type: "uninstallDlpSandbox", listener: Callback<DlpSandboxStateParam>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsubscribe the event reported when dlp sandbox uninstall.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param type Type of the uninstall sandbox event.
|
||||||
|
* @param listener Indicates the listenner of dlp sandbox state.
|
||||||
|
* @return -
|
||||||
|
*/
|
||||||
|
function off(type: "uninstallDlpSandbox", listener?: Callback<DlpSandboxStateParam>): void;
|
||||||
|
|
||||||
|
export enum AccountType {
|
||||||
|
/**
|
||||||
|
* Cloud account type, type of the account for granting permissions to the DLP file.
|
||||||
|
* @since 9
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
*/
|
||||||
|
CLOUD_ACCOUNT = 1,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Domain account type, type of the account for granting permissions to the DLP file.
|
||||||
|
* @since 9
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
*/
|
||||||
|
DOMAIN_ACCOUNT = 2,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application account type, type of the account for granting permissions to the DLP file.
|
||||||
|
* @since 9
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
*/
|
||||||
|
APPLICATION_ACCOUNT = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AuthUser {
|
||||||
|
/**
|
||||||
|
* Access authorized account
|
||||||
|
* @since 9
|
||||||
|
*/
|
||||||
|
authAccount: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access authorized type
|
||||||
|
* @since 9
|
||||||
|
*/
|
||||||
|
authPerm: AuthPermType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permission expiry time
|
||||||
|
* @since 9
|
||||||
|
*/
|
||||||
|
permExpiryTime: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access authorized account type
|
||||||
|
* @since 9
|
||||||
|
*/
|
||||||
|
authAccountType: AccountType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DlpProperty {
|
||||||
|
/**
|
||||||
|
* Dlp file owner account
|
||||||
|
* @since 9
|
||||||
|
*/
|
||||||
|
ownerAccount: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dlp file authorized user list
|
||||||
|
* @since 9
|
||||||
|
*/
|
||||||
|
authUsers?: Array<AuthUser>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dlp file authorizer contact information
|
||||||
|
* @since 9
|
||||||
|
*/
|
||||||
|
contractAccount: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access authorized account type
|
||||||
|
* @since 9
|
||||||
|
*/
|
||||||
|
ownerAccountType: AccountType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DlpFile {
|
||||||
|
/**
|
||||||
|
* Dlp file property
|
||||||
|
* @since 9
|
||||||
|
*/
|
||||||
|
dlpProperty: DlpProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add the link file of origin dlp file, the link file is implemented through the fuse file system.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param linkFileName Indicates the name of link file.
|
||||||
|
* @return -
|
||||||
|
*/
|
||||||
|
addDlpLinkFile(linkFileName: string): Promise<void>;
|
||||||
|
addDlpLinkFile(linkFileName: string, callback: AsyncCallback<void>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete the link file of origin dlp file, the link file is implemented through the fuse file system.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param linkFileName Indicates the name of link file.
|
||||||
|
* @return -
|
||||||
|
*/
|
||||||
|
deleteDlpLinkFile(linkFileName: string): Promise<void>;
|
||||||
|
deleteDlpLinkFile(linkFileName: string, callback: AsyncCallback<void>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* recover the origin plain file from dlp file.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param plainFd Indicates the file descriptor of the origin plain file.
|
||||||
|
* @return -
|
||||||
|
*/
|
||||||
|
recoverDlpFile(plainFd: number): Promise<void>;
|
||||||
|
recoverDlpFile(plainFd: number, callback: AsyncCallback<void>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* close the dlp file, when the object never be used.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @return -
|
||||||
|
*/
|
||||||
|
closeDlpFile(): Promise<void>;
|
||||||
|
closeDlpFile(callback: AsyncCallback<void>): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generate the dlp file
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param plainTextFd Indicates the file descriptor of the origin plain file.
|
||||||
|
* @param cipherTextFd Indicates the file descriptor of the dlp file.
|
||||||
|
* @param property Indicates the property of the dlp file.
|
||||||
|
* @return dlpFile object
|
||||||
|
*/
|
||||||
|
function generateDlpFile(plainTextFd: number, cipherTextFd: number, property: DlpProperty): Promise<DlpFile>
|
||||||
|
function generateDlpFile(plainTextFd: number, cipherTextFd: number, property: DlpProperty, callback: AsyncCallback<DlpFile>): void
|
||||||
|
|
||||||
|
/**
|
||||||
|
* open the dlp file, and parse it.
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param cipherTextFd Indicates the file descriptor of the dlp file.
|
||||||
|
* @return dlpFile object
|
||||||
|
*/
|
||||||
|
function openDlpFile(cipherTextFd: number): Promise<DlpFile>
|
||||||
|
function openDlpFile(cipherTextFd: number, callback: AsyncCallback<DlpFile>): void
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check whether is dlp file
|
||||||
|
*
|
||||||
|
* @since 9
|
||||||
|
* @systemapi Hide this for inner system use.
|
||||||
|
* @permission ohos.permission.ACCESS_DLP_FILE
|
||||||
|
* @syscap SystemCapability.Security.DlpPermissionService
|
||||||
|
* @param cipherTextFd Indicates the file descriptor of the dlp file.
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function isDlpFile(cipherTextFd: number): Promise<boolean>
|
||||||
|
function isDlpFile(cipherTextFd: number, callback: AsyncCallback<boolean>): void
|
||||||
|
}
|
||||||
|
export default dlpPermission;
|
13
AppScope/app.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"app": {
|
||||||
|
"bundleName": "com.ohos.dlpmanager",
|
||||||
|
"vendor": "example",
|
||||||
|
"versionCode": 1000000,
|
||||||
|
"versionName": "1.0.0",
|
||||||
|
"icon": "$media:app_icon",
|
||||||
|
"label": "$string:app_name",
|
||||||
|
"minAPIVersion": 9,
|
||||||
|
"targetAPIVersion": 9,
|
||||||
|
"distributedNotificationEnabled": true
|
||||||
|
}
|
||||||
|
}
|
8
AppScope/resources/base/element/string.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "app_name",
|
||||||
|
"value": "DLPManager"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
BIN
AppScope/resources/base/media/app_icon.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
56
BUILD.gn
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# Copyright (c) 2022 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("//build/ohos.gni")
|
||||||
|
|
||||||
|
|
||||||
|
ohos_copy("dlp_permission_api") {
|
||||||
|
sources = [ "@ohos.dlpPermission.d.ts" ]
|
||||||
|
outputs = [ root_out_dir + "/ohos_declaration/ohos_declaration_ets/@ohos.dlpPermission.d.ts" ]
|
||||||
|
module_install_name = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
ohos_hap("dlp_manager") {
|
||||||
|
hap_profile = "entry/src/main/module.json"
|
||||||
|
deps = [
|
||||||
|
":dlp_permission_api",
|
||||||
|
":dlp_manager_js_assets",
|
||||||
|
":dlp_manager_resources",
|
||||||
|
]
|
||||||
|
js_build_mode = "debug"
|
||||||
|
certificate_profile = "signature/dlpmanager.p7b"
|
||||||
|
hap_name = "dlp_manager"
|
||||||
|
part_name = "prebuilt_hap"
|
||||||
|
subsystem_name = "applications"
|
||||||
|
module_install_dir = "app/com.ohos.dlpmanager"
|
||||||
|
}
|
||||||
|
|
||||||
|
ohos_app_scope("dlp_manager_app_profile") {
|
||||||
|
app_profile = "AppScope/app.json"
|
||||||
|
sources = [ "AppScope/resources" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
ohos_js_assets("dlp_manager_js_assets") {
|
||||||
|
ets2abc = true
|
||||||
|
source_dir = "entry/src/main/ets"
|
||||||
|
}
|
||||||
|
|
||||||
|
ohos_resources("dlp_manager_resources") {
|
||||||
|
sources = [
|
||||||
|
"entry/src/main/resources",
|
||||||
|
]
|
||||||
|
deps = [
|
||||||
|
":dlp_manager_app_profile",
|
||||||
|
]
|
||||||
|
hap_profile = "entry/src/main/module.json"
|
||||||
|
}
|
40
build-profile.json5
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"app": {
|
||||||
|
"signingConfigs": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"material": {
|
||||||
|
"certpath": "C:/Users/l00699231/Desktop/dlpnew/DLPManager3/dlpmanager.cer",
|
||||||
|
"storePassword": "0000001921869AB129053291395B5CACC3FF7D7583EA01AE0D6E71E7BE1229027F0847C4BF7DE075AD",
|
||||||
|
"keyAlias": "dlpKey",
|
||||||
|
"keyPassword": "00000019A811E802679AF61F9AD9C5C5FB15482C580234A8DB6E69A0514503A8945591A3FB3AB353CA",
|
||||||
|
"profile": "C:/Users/l00699231/Desktop/dlpnew/DLPManager3/dlpmanager.p7b",
|
||||||
|
"signAlg": "SHA256withECDSA",
|
||||||
|
"storeFile": "C:/Users/l00699231/Desktop/dlpnew/DLPManager3/dlpmanager.p12"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"compileSdkVersion": 9,
|
||||||
|
"compatibleSdkVersion": 8,
|
||||||
|
"products": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"signingConfig": "default",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"modules": [
|
||||||
|
{
|
||||||
|
"name": "entry",
|
||||||
|
"srcPath": "./entry",
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"applyToProducts": [
|
||||||
|
"default"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
3
entry/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/node_modules
|
||||||
|
/.preview
|
||||||
|
/build
|
13
entry/build-profile.json5
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"apiType": 'stageMode',
|
||||||
|
"buildOption": {
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohosTest",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
2
entry/hvigorfile.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||||
|
module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks
|
5
entry/package-lock.json
generated
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "entry",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 1
|
||||||
|
}
|
14
entry/package.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"license":"ISC",
|
||||||
|
"devDependencies":{},
|
||||||
|
"name":"entry",
|
||||||
|
"ohos":{
|
||||||
|
"org":"huawei",
|
||||||
|
"directoryLevel":"module",
|
||||||
|
"buildTool":"hvigor"
|
||||||
|
},
|
||||||
|
"description":"example description",
|
||||||
|
"repository":{},
|
||||||
|
"version":"1.0.0",
|
||||||
|
"dependencies":{}
|
||||||
|
}
|
7
entry/src/main/ets/Application/AbilityStage.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import AbilityStage from "@ohos.application.AbilityStage"
|
||||||
|
|
||||||
|
export default class MyAbilityStage extends AbilityStage {
|
||||||
|
onCreate() {
|
||||||
|
console.log("[Demo] MyAbilityStage onCreate")
|
||||||
|
}
|
||||||
|
}
|
77
entry/src/main/ets/DataAbility/DataAbility.ts
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import ServiceExtensionAbility from '@ohos.application.ServiceExtensionAbility'
|
||||||
|
import commonEvent from '@ohos.commonEvent'
|
||||||
|
import Want from '@ohos.application.Want'
|
||||||
|
import fileio from '@ohos.fileio';
|
||||||
|
import dlpPermission from '@ohos.dlpPermission'
|
||||||
|
|
||||||
|
var TAG = "[DLPManager DataAbility]"
|
||||||
|
var DATAEVENT = "usual.event.SANDBOX_PACKAGE_REMOVED"
|
||||||
|
export default class DataAbility extends ServiceExtensionAbility {
|
||||||
|
sandbox2linkFile: {[key: string]: [number, dlpPermission.DlpFile, string]} = {}
|
||||||
|
subscriber = null
|
||||||
|
subscribeCallback(err, data) {
|
||||||
|
if (err.code) {
|
||||||
|
console.error("subscribe failed " + JSON.stringify(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (data.event != DATAEVENT) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var bundleName = data.bundleName
|
||||||
|
var sandboxAppIndex = data.parameters["sandbox_app_index"]
|
||||||
|
var key = bundleName + sandboxAppIndex
|
||||||
|
try {
|
||||||
|
if (key in globalThis.sandbox2linkFile) {
|
||||||
|
var linkFile = globalThis.sandbox2linkFile[key]
|
||||||
|
fileio.closeSync(linkFile[0])
|
||||||
|
var dlpFile = linkFile[1]
|
||||||
|
dlpFile.deleteDlpLinkFile(linkFile[2])
|
||||||
|
dlpFile.closeDlpFile()
|
||||||
|
delete globalThis.sandbox2linkFile[key]
|
||||||
|
console.error(TAG + "release resource successfully")
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "release resource error: " + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createSubscriber() {
|
||||||
|
var subscribeInfo = {
|
||||||
|
events: ["usual.event.SANDBOX_PACKAGE_REMOVED"],
|
||||||
|
}
|
||||||
|
|
||||||
|
commonEvent.createSubscriber(subscribeInfo, (err, subscriber) => {
|
||||||
|
if (err.code) {
|
||||||
|
console.error(TAG + `CreateSubscriberCallBack err = ${JSON.stringify(err)}`)
|
||||||
|
} else {
|
||||||
|
console.log(TAG + "CreateSubscriber")
|
||||||
|
this.subscriber = subscriber
|
||||||
|
commonEvent.subscribe(this.subscriber, this.subscribeCallback)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onCreate(want) {
|
||||||
|
globalThis.context = this.context
|
||||||
|
}
|
||||||
|
|
||||||
|
onRequest(want: Want, startId: number) {
|
||||||
|
if(this.subscriber == null) {
|
||||||
|
this.createSubscriber()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy() {
|
||||||
|
console.log(TAG + "onDestroy")
|
||||||
|
if (this.subscriber != null) {
|
||||||
|
commonEvent.unsubscribe(this.subscriber, (err) => {
|
||||||
|
if (err.code) {
|
||||||
|
console.error(TAG, `[CommonEvent]UnsubscribeCallBack err= = ${JSON.stringify(err)}`)
|
||||||
|
} else {
|
||||||
|
console.info(TAG, "[CommonEvent]Unsubscribe")
|
||||||
|
this.subscriber = null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
entry/src/main/ets/MainAbility/MainAbility.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import Ability from '@ohos.application.Ability'
|
||||||
|
import window from '@ohos.window';
|
||||||
|
|
||||||
|
var TAG = "[DLPManager]"
|
||||||
|
let permissionList: Array<string> = [
|
||||||
|
"ohos.permission.READ_MEDIA",
|
||||||
|
"ohos.permission.WRITE_MEDIA",
|
||||||
|
"ohos.permission.FILE_ACCESS_MANAGER"
|
||||||
|
]
|
||||||
|
|
||||||
|
export default class MainAbility extends Ability {
|
||||||
|
async onCreate(want, launchParam) {
|
||||||
|
console.log("[DLPManager] MainAbility onCreate")
|
||||||
|
globalThis.abilityWant = want;
|
||||||
|
globalThis.context = this.context
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy() {
|
||||||
|
console.log("[DLPManager] MainAbility onDestroy")
|
||||||
|
}
|
||||||
|
|
||||||
|
async onWindowStageCreate(windowStage) {
|
||||||
|
console.log("[DLPManager] MainAbility onWindowStageCreate")
|
||||||
|
globalThis.context.requestPermissionsFromUser(permissionList)
|
||||||
|
windowStage.setUIContent(this.context, "pages/index", null)
|
||||||
|
windowStage.getMainWindow().then((win) => {
|
||||||
|
win.setBackgroundColor("#00FFFFFF")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onWindowStageDestroy() {
|
||||||
|
console.log(TAG + "MainAbility onWindowStageDestroy")
|
||||||
|
}
|
||||||
|
|
||||||
|
onForeground() {
|
||||||
|
console.log(TAG + "[DLPManager] MainAbility onForeground")
|
||||||
|
}
|
||||||
|
|
||||||
|
onBackground() {
|
||||||
|
console.log(TAG + "[DLPManager] MainAbility onBackground")
|
||||||
|
}
|
||||||
|
};
|
139
entry/src/main/ets/ViewAbility/ViewAbility.ts
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
import ServiceExtensionAbility from '@ohos.application.ServiceExtensionAbility'
|
||||||
|
import dlpPermission from '@ohos.dlpPermission'
|
||||||
|
import { getOsAccountInfo, getUserId, getAuthPerm, startAlertAbility } from '../common/utils'
|
||||||
|
import fileio from '@ohos.fileio';
|
||||||
|
import Want from '@ohos.application.Want';
|
||||||
|
import commonEvent from '@ohos.commonEvent';
|
||||||
|
import Constants from '../common/constant'
|
||||||
|
|
||||||
|
var TAG = "[DLPManager ViewAbility]"
|
||||||
|
export default class ViewAbility extends ServiceExtensionAbility {
|
||||||
|
linkFd: number = -1
|
||||||
|
linkFileName: string = ''
|
||||||
|
linkFilePath: string = ''
|
||||||
|
sandboxIndex: number = -1
|
||||||
|
dlpFile: dlpPermission.DlpFile = null
|
||||||
|
authPerm: dlpPermission.AuthPermType = dlpPermission.AuthPermType.READ_ONLY
|
||||||
|
sandboxBundleName: string = ''
|
||||||
|
sandboxAbilityName: string = ''
|
||||||
|
sandboxModuleName: string = ''
|
||||||
|
isCreated: boolean = false
|
||||||
|
|
||||||
|
async onCreate(want) {
|
||||||
|
globalThis.context = this.context
|
||||||
|
if (!globalThis.sandbox2linkFile) {
|
||||||
|
globalThis.sandbox2linkFile = {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async startDataAbility() {
|
||||||
|
let want = {
|
||||||
|
bundleName: "com.ohos.dlpmanager",
|
||||||
|
abilityName: "DataAbility"
|
||||||
|
}
|
||||||
|
await globalThis.context.startAbility(want)
|
||||||
|
}
|
||||||
|
|
||||||
|
startSandboxApp() {
|
||||||
|
let want: Want = {
|
||||||
|
bundleName: this.sandboxBundleName,
|
||||||
|
abilityName: this.sandboxAbilityName,
|
||||||
|
parameters: {
|
||||||
|
keyFd: {
|
||||||
|
type: "FD", value: this.linkFd
|
||||||
|
},
|
||||||
|
"ohos.dlp.params.index": this.sandboxIndex,
|
||||||
|
"ohos.dlp.params.moduleName": this.sandboxModuleName,
|
||||||
|
"ohos.dlp.params.securityFlag": this.authPerm ==
|
||||||
|
dlpPermission.AuthPermType.FULL_CONTROL ? false : true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
globalThis.context.startAbility(want, async (err, data) => {
|
||||||
|
if (err && err.code != 0) {
|
||||||
|
console.error(TAG + "startSandboxApp failed, error" + JSON.stringify(err))
|
||||||
|
try {
|
||||||
|
fileio.closeSync(this.linkFd)
|
||||||
|
await this.dlpFile.deleteDlpLinkFile(this.linkFileName)
|
||||||
|
this.dlpFile.closeDlpFile()
|
||||||
|
startAlertAbility(Constants.APP_ERROR, Constants.APP_SANDBOX_ERROR)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(TAG + "deleteDlpLinkFile failed, error" + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
globalThis.sandbox2linkFile[this.sandboxBundleName + this.sandboxIndex] =
|
||||||
|
[this.linkFd, this.dlpFile, this.linkFileName]
|
||||||
|
await this.startDataAbility()
|
||||||
|
}
|
||||||
|
globalThis.context.terminateSelf()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async onRequest(want: Want, startId: number) {
|
||||||
|
try {
|
||||||
|
var srcFd = want.parameters.keyFd.value
|
||||||
|
this.sandboxBundleName = want.parameters["ohos.dlp.params.bundleName"]
|
||||||
|
this.sandboxAbilityName = want.parameters["ohos.dlp.params.abilityName"]
|
||||||
|
this.sandboxModuleName = want.parameters["ohos.dlp.params.moduleName"]
|
||||||
|
} catch (err) {
|
||||||
|
console.log(TAG + "parse parameters failed, error: " + JSON.stringify(err))
|
||||||
|
startAlertAbility(Constants.APP_ERROR, Constants.APP_PARAM_ERROR)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var accountInfo = await getOsAccountInfo()
|
||||||
|
var userId = await getUserId()
|
||||||
|
console.log(TAG + "account name: " +
|
||||||
|
accountInfo.distributedInfo.name + ", userId: " + userId)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(TAG + "get account info failed, error: " + JSON.stringify(err))
|
||||||
|
startAlertAbility(Constants.APP_ERROR, Constants.APP_GET_ACCOUNT_ERROR)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.dlpFile = await dlpPermission.openDlpFile(srcFd)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(TAG + "openDlpFile failed, error: " + JSON.stringify(err))
|
||||||
|
if (err.code == 1 && err.extra != undefined) {
|
||||||
|
startAlertAbility(Constants.APP_VISIT_FILE_ERROR,
|
||||||
|
Constants.APP_NOT_HAVE_PERM_VISIT + err.extra)
|
||||||
|
} else {
|
||||||
|
startAlertAbility(Constants.APP_DLP_ERROR,Constants.APP_FILE_PARAM_ERROR )
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.authPerm = getAuthPerm(accountInfo.distributedInfo.name, this.dlpFile.dlpProperty)
|
||||||
|
try {
|
||||||
|
this.sandboxIndex = await dlpPermission.installDlpSandbox(this.sandboxBundleName,
|
||||||
|
this.authPerm, userId)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(TAG + "installDlpSandbox failed, error: " + JSON.stringify(err))
|
||||||
|
this.dlpFile.closeDlpFile()
|
||||||
|
if (err.code == 8519807) {
|
||||||
|
startAlertAbility(Constants.APP_ERROR, Constants.APP_SANDBOX_LIMIT_MAX)
|
||||||
|
} else {
|
||||||
|
startAlertAbility(Constants.APP_ERROR, Constants.APP_INSTALL_SANDBOX_ERROR)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var date = new Date()
|
||||||
|
var timestamp = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(),
|
||||||
|
date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getMilliseconds()).getTime()
|
||||||
|
this.linkFileName = this.sandboxBundleName + this.sandboxIndex + timestamp + ".dlp.link"
|
||||||
|
try {
|
||||||
|
await this.dlpFile.addDlpLinkFile(this.linkFileName)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(TAG + "addDlpLinkFile failed, error: " + JSON.stringify(err))
|
||||||
|
this.dlpFile.closeDlpFile()
|
||||||
|
startAlertAbility(Constants.APP_ERROR, Constants.APP_LINK_FILE_ERROR)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.linkFilePath = "/data/fuse/" + this.linkFileName
|
||||||
|
if (this.authPerm == dlpPermission.AuthPermType.READ_ONLY) {
|
||||||
|
this.linkFd = fileio.openSync(this.linkFilePath, 0o100, 0o666)
|
||||||
|
}
|
||||||
|
else if (this.authPerm == dlpPermission.AuthPermType.FULL_CONTROL) {
|
||||||
|
this.linkFd = fileio.openSync(this.linkFilePath, 0o102, 0o666)
|
||||||
|
}
|
||||||
|
this.startSandboxApp()
|
||||||
|
}
|
||||||
|
}
|
193
entry/src/main/ets/common/components/authorizer_panel.ets
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
import dlpPermission from '@ohos.dlpPermission'
|
||||||
|
import {DlpAlertDialog} from '../components/dlp_alert_dialog'
|
||||||
|
import Constants from'../constant'
|
||||||
|
|
||||||
|
var TAG = "DLPManager: "
|
||||||
|
@Component
|
||||||
|
struct AuthorizerPanel {
|
||||||
|
scroller: Scroller = new Scroller()
|
||||||
|
contactToAdd : string = ''
|
||||||
|
dlpAlertDialog : CustomDialogController
|
||||||
|
@Link authPerm : number
|
||||||
|
@Link isChanged : boolean
|
||||||
|
@State showContacts : boolean = true
|
||||||
|
@State contacts: { [key: string]: string} = {}
|
||||||
|
@Link dlpFile : dlpPermission.DlpFile
|
||||||
|
@State contactList: string[] = []
|
||||||
|
|
||||||
|
updateContactList () {
|
||||||
|
this.contactList = []
|
||||||
|
for (var item in this.contacts) {
|
||||||
|
this.contactList.push(item)
|
||||||
|
}
|
||||||
|
this.dlpFile.dlpProperty.contractAccount = this.contactList.join(";")
|
||||||
|
}
|
||||||
|
|
||||||
|
aboutToAppear() {
|
||||||
|
if (this.dlpFile.dlpProperty.contractAccount.length == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.contactList = this.dlpFile.dlpProperty.contractAccount.split(';')
|
||||||
|
for (var i = 0; i < this.contactList.length; ++i) {
|
||||||
|
this.contacts[this.contactList[i]] = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder ListItemLayout(item: string) {
|
||||||
|
ListItem() {
|
||||||
|
Column() {
|
||||||
|
Row() {
|
||||||
|
Text(item)
|
||||||
|
.maxLines(Constants.AP_TEXT_MAX_LINE)
|
||||||
|
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||||
|
.fontSize(Constants.AP_TEXT_FONT_SIZE)
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.lineHeight(Constants.AP_TEXT_LINE_HEIGHT)
|
||||||
|
.width(Constants.AP_TEXT_WIDTH)
|
||||||
|
.padding({right: Constants.AP_TEXT_PAD_RIGHT})
|
||||||
|
.align(Alignment.Start)
|
||||||
|
Image($r('app.media.ic_public_delete'))
|
||||||
|
.enabled(this.authPerm == 2 ? true : false)
|
||||||
|
.width(Constants.PP_IMAGE_WIDTH)
|
||||||
|
.height(Constants.PP_IMAGE_HEIGHT)
|
||||||
|
.padding(Constants.PP_IMAGE_PAD)
|
||||||
|
.onClick((event) => {
|
||||||
|
delete this.contacts[item]
|
||||||
|
this.updateContactList()
|
||||||
|
this.isChanged = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.height(Constants.PP_ROW_HEIGHT)
|
||||||
|
Line()
|
||||||
|
.width(Constants.PP_LINE_WIDTH)
|
||||||
|
.height(Constants.PP_LINE_HEIGHT)
|
||||||
|
.backgroundColor($r('app.color.pp_line_background_color'))
|
||||||
|
}
|
||||||
|
.height(Constants.AP_COLUMN_HEIGHT)
|
||||||
|
.alignItems(HorizontalAlign.Start)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
Row() {
|
||||||
|
Text($r('app.string.authorizer_panel_title'))
|
||||||
|
.fontColor($r("app.color.text_color"))
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Regular)
|
||||||
|
.fontSize(Constants.AP_TEXT_FONT_SIZE)
|
||||||
|
.lineHeight(Constants.AP_TEXT_LINE_HEIGHT)
|
||||||
|
.margin({top: Constants.AP_MARGIN_TOP})
|
||||||
|
.width(Constants.PP_TEXT_WIDTH_FULL)
|
||||||
|
.align(Alignment.Start)
|
||||||
|
}
|
||||||
|
.height(Constants.AP_COLUMN_HEIGHT)
|
||||||
|
.opacity(Constants.AP_COLUMN_OPACITY)
|
||||||
|
if (this.showContacts) {
|
||||||
|
if (this.contactList.length > 0) {
|
||||||
|
Scroll(this.scroller) {
|
||||||
|
List() {
|
||||||
|
ForEach(this.contactList, (item) => {
|
||||||
|
this.ListItemLayout(item)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.height(Constants.AP_LIST_HEIGHT)
|
||||||
|
.width(Constants.PP_TEXT_WIDTH_FULL)
|
||||||
|
.scrollable(ScrollDirection.Vertical)
|
||||||
|
.scrollBar(BarState.On)
|
||||||
|
.scrollBarWidth(Constants.AP_LIST_BAR_WIDTH)
|
||||||
|
}
|
||||||
|
Row() {
|
||||||
|
Button($r('app.string.button_add_user'))
|
||||||
|
.enabled(this.authPerm == 2 ? true : false)
|
||||||
|
.fontSize(Constants.AP_TEXT_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.button_color'))
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.focusable(false)
|
||||||
|
.height(Constants.AP_BUTTON_HEIGHT)
|
||||||
|
.backgroundColor($r('app.color.pp_button_background_color'))
|
||||||
|
.padding(Constants.AP_BUTTON_PAD)
|
||||||
|
.onClick((event) => {
|
||||||
|
this.showContacts = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.align(Alignment.Start)
|
||||||
|
.width(Constants.PP_TEXT_WIDTH_FULL)
|
||||||
|
.height(Constants.AP_ROW_HEIGHT)
|
||||||
|
} else {
|
||||||
|
Row() {
|
||||||
|
TextInput()
|
||||||
|
.height(Constants.AP_TEXT_INPUT_HEIGHT)
|
||||||
|
.padding({top: Constants.AP_TEXT_PAD_TOP, bottom: Constants.AP_TEXT_PAD_BOTTOM})
|
||||||
|
.fontSize(Constants.AP_TEXT_FONT_SIZE)
|
||||||
|
.borderRadius(Constants.AP_ROW_RADIUS)
|
||||||
|
.backgroundColor($r('app.color.pp_row_background_color'))
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Regular)
|
||||||
|
.onChange((value: string) => {
|
||||||
|
this.contactToAdd = value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.padding({right: Constants.AP_ROW_PAD_RIGHT})
|
||||||
|
Line()
|
||||||
|
.width(Constants.AP_LINE_WIDTH)
|
||||||
|
.height(Constants.AP_LINE_HEIGHT)
|
||||||
|
.backgroundColor($r('app.color.pp_line_background_color'))
|
||||||
|
Row() {
|
||||||
|
Button($r('app.string.add'))
|
||||||
|
.fontSize(Constants.AP_TEXT_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.button_color'))
|
||||||
|
.fontFamily('app.string.HarmonyHeiTi')
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.height(Constants.AP_BUTTON_HEIGHT)
|
||||||
|
.padding(Constants.AP_BUTTON_PAD)
|
||||||
|
.backgroundColor($r('app.color.button_background_color'))
|
||||||
|
.onClick((event) => {
|
||||||
|
if (this.contactToAdd.length > 1024) {
|
||||||
|
this.dlpAlertDialog = new CustomDialogController({
|
||||||
|
builder: DlpAlertDialog({
|
||||||
|
title: Constants.PP_TITLE,
|
||||||
|
message: Constants.PP_MESSAGE,
|
||||||
|
}),
|
||||||
|
autoCancel: false,
|
||||||
|
customStyle: true
|
||||||
|
})
|
||||||
|
this.dlpAlertDialog.open()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.contactToAdd.length != 0) {
|
||||||
|
this.contacts[this.contactToAdd] = ""
|
||||||
|
this.updateContactList()
|
||||||
|
}
|
||||||
|
this.contactToAdd = ''
|
||||||
|
this.showContacts = true
|
||||||
|
this.isChanged = true
|
||||||
|
})
|
||||||
|
Button($r('app.string.cancel'))
|
||||||
|
.fontSize(Constants.AP_BUTTON_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.button_color'))
|
||||||
|
.fontFamily('app.string.HarmonyHeiTi')
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.height(Constants.AP_BUTTON_HEIGHT)
|
||||||
|
.padding(Constants.AP_BUTTON_PAD)
|
||||||
|
.margin({left: Constants.AP_BUTTON_MARGIN_LEFT})
|
||||||
|
.focusable(false)
|
||||||
|
.backgroundColor($r('app.color.pp_button_background_color'))
|
||||||
|
.onClick((event) => {
|
||||||
|
this.showContacts = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.width(Constants.PP_TEXT_WIDTH_FULL)
|
||||||
|
.height(Constants.AP_ROW_HEIGHT)
|
||||||
|
.align(Alignment.Start)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding({left: Constants.AP_COLUMN_PAD_LEFT, right:Constants.AP_COLUMN_PAD_RIGHT})
|
||||||
|
.alignItems(HorizontalAlign.Start)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {AuthorizerPanel}
|
78
entry/src/main/ets/common/components/del_user_alert.ets
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import Constants from'../constant'
|
||||||
|
|
||||||
|
@CustomDialog
|
||||||
|
struct DelUserAlertDialog {
|
||||||
|
controller : CustomDialogController
|
||||||
|
cancel: () => void
|
||||||
|
confirm: () => void
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
Row() {
|
||||||
|
Text($r('app.string.del_usr'))
|
||||||
|
.lineHeight(Constants.DU_TEXT_LINE_HEIGHT)
|
||||||
|
.width(Constants.DU_WIDTH_FULL)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontSize(Constants.DU_TEXT_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.pp_text_fontcolor'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
}
|
||||||
|
.height(Constants.DU_ROW_HEIGHT)
|
||||||
|
.width(Constants.DU_ROW_WIDTH)
|
||||||
|
Row() {
|
||||||
|
Scroll() {
|
||||||
|
Text($r('app.string.del_text1'))
|
||||||
|
.lineHeight(Constants.DU_SCROLL_LINE_HEIGHT)
|
||||||
|
.width(Constants.DU_WIDTH_FULL)
|
||||||
|
.fontFamily('app.string.HarmonyHeiTi')
|
||||||
|
.fontSize(Constants.DU_SCROLL_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.del_scroll_font_color'))
|
||||||
|
.fontWeight(FontWeight.Regular)
|
||||||
|
}
|
||||||
|
.scrollBarColor(Color.Gray).scrollBarWidth(Constants.DU_SCROLL_BAR_WIDTH)
|
||||||
|
.constraintSize({maxHeight: Constants.DU_CONS_MAX_HEIGHT})
|
||||||
|
}
|
||||||
|
.margin({top: Constants.DU_MARGIN_TOP})
|
||||||
|
.width(Constants.DU_ROW_WIDTH)
|
||||||
|
Row() {
|
||||||
|
Button($r('app.string.cancel'))
|
||||||
|
.width(Constants.DU_WIDTH_SPE)
|
||||||
|
.height(Constants.DU_BUTTON_HEIGHT)
|
||||||
|
.fontSize(Constants.DU_BUTTON_FONT_SIZE)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.fontColor($r("app.color.button_color"))
|
||||||
|
.backgroundColor($r('app.color.pp_button_background_color'))
|
||||||
|
.onClick(() => {
|
||||||
|
this.controller.close()
|
||||||
|
})
|
||||||
|
Line()
|
||||||
|
.width(Constants.DU_LINE_WIDTH)
|
||||||
|
.height(Constants.DU_LINE_HEIGHT)
|
||||||
|
.margin({top: Constants.DU_LINE_MARGIN_TOP})
|
||||||
|
.backgroundColor($r('app.color.pp_line_background_color'))
|
||||||
|
Button($r('app.string.button_del'))
|
||||||
|
.width(Constants.DU_BUTTON_WIDTH)
|
||||||
|
.height(Constants.DU_BUTTON_HEIGHT)
|
||||||
|
.fontSize(Constants.DU_BUTTON_FONT_SIZE)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.fontColor($r('app.color.del_button_font_color'))
|
||||||
|
.backgroundColor($r('app.color.pp_button_background_color'))
|
||||||
|
.onClick(() => {
|
||||||
|
this.controller.close()
|
||||||
|
this.confirm()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.width(Constants.DU_ROW_WIDTH2)
|
||||||
|
.alignItems(VerticalAlign.Top)
|
||||||
|
.margin({ top: Constants.DU_LINE_MARGIN_TOP2 })
|
||||||
|
.height(Constants.DU_ROW_HEIGHT)
|
||||||
|
}
|
||||||
|
.width(Constants.DU_ROW_WIDTH3)
|
||||||
|
.backgroundColor($r('app.color.pp_row_background_color'))
|
||||||
|
.borderRadius(Constants.DU_BORDER_RADIUS)
|
||||||
|
.alignItems(HorizontalAlign.Center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {DelUserAlertDialog}
|
66
entry/src/main/ets/common/components/dlp_alert_dialog.ets
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import Constants from'../constant'
|
||||||
|
|
||||||
|
@CustomDialog
|
||||||
|
struct DlpAlertDialog {
|
||||||
|
controller : CustomDialogController
|
||||||
|
title: string
|
||||||
|
message: string
|
||||||
|
action: () => void = null
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
Row() {
|
||||||
|
Text(this.title)
|
||||||
|
.lineHeight(Constants.DA_TEXT_LINE_HEIGHT)
|
||||||
|
.width(Constants.DU_WIDTH_FULL)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontSize(Constants.DA_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.da_font_color'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
}
|
||||||
|
.height(Constants.DA_ROW_HEIGHT)
|
||||||
|
.width(Constants.DA_ROW_WIDTH)
|
||||||
|
Row() {
|
||||||
|
Scroll() {
|
||||||
|
Text(this.message)
|
||||||
|
.lineHeight(Constants.DA_SCROLL_LINE_HEIGHT)
|
||||||
|
.width(Constants.DU_WIDTH_FULL)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontSize(Constants.DA_SCROLL_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.da_scroll_font_color'))
|
||||||
|
.fontWeight(FontWeight.Regular)
|
||||||
|
}
|
||||||
|
.scrollBarColor(Color.Gray).scrollBarWidth(Constants.DA_SCROLL_BAR_WIDTH)
|
||||||
|
.constraintSize({maxHeight: Constants.DA_STRAIN_SIZE_MA_HEIGHT})
|
||||||
|
}
|
||||||
|
.margin({top: Constants.DA_MARGIN_TOP})
|
||||||
|
.width(Constants.DA_SCROLL_WIDTH);
|
||||||
|
Row() {
|
||||||
|
Button($r('app.string.da_buttion'))
|
||||||
|
.width(Constants.ROW_BUTTON_WIDTH)
|
||||||
|
.height(Constants.ROW_BUTTON_HEIGHT)
|
||||||
|
.fontSize(Constants.ROW_FONT_SIZE)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.fontColor($r("app.color.button_color"))
|
||||||
|
.backgroundColor($r('app.color.da_background_color'))
|
||||||
|
.onClick(() => {
|
||||||
|
this.controller.close()
|
||||||
|
if (this.action != null) {
|
||||||
|
this.action()
|
||||||
|
} else {
|
||||||
|
globalThis.context.terminateSelf()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.alignItems(VerticalAlign.Top)
|
||||||
|
.margin({ top: Constants.ROW_MARGIN_TOP })
|
||||||
|
.height(Constants.DA_ROW_HEIGHT)
|
||||||
|
}
|
||||||
|
.width(Constants.DA_COLOUM_WIDTH)
|
||||||
|
.backgroundColor($r('app.color.da_background_color'))
|
||||||
|
.borderRadius(Constants.DA_COLOUM_RADIUS)
|
||||||
|
.alignItems(HorizontalAlign.Center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {DlpAlertDialog}
|
173
entry/src/main/ets/common/components/footer.ets
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
import dlpPermission from '@ohos.dlpPermission'
|
||||||
|
import fileio from "@ohos.fileio";
|
||||||
|
import dataShare from '@ohos.data.dataShare';
|
||||||
|
import datafile from '@ohos.data.fileAccess';
|
||||||
|
import Constants from '../constant'
|
||||||
|
|
||||||
|
var TAG: string = "DLPManager: "
|
||||||
|
|
||||||
|
var filePickerWant = {
|
||||||
|
bundleName: "com.ohos.filepicker",
|
||||||
|
abilityName: "MainAbility",
|
||||||
|
parameters: {
|
||||||
|
'startMode': 'save',
|
||||||
|
'saveFile': '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var filePickerOptions = {
|
||||||
|
windowMode: 102
|
||||||
|
}
|
||||||
|
var suffix_length = 4;
|
||||||
|
@Component
|
||||||
|
struct Footer {
|
||||||
|
srcFilename: string
|
||||||
|
srcFd: number
|
||||||
|
isDlpFile: boolean
|
||||||
|
@Link isChanged: boolean
|
||||||
|
@Link dlpFile: dlpPermission.DlpFile
|
||||||
|
@Link needProtect: boolean
|
||||||
|
|
||||||
|
async postProcessForSetting() {
|
||||||
|
var filename = this.srcFilename.substr(0, this.srcFilename.length - suffix_length)
|
||||||
|
if (this.needProtect) {
|
||||||
|
try {
|
||||||
|
var filePath = globalThis.context.filesDir + "/" + filename + (new Date().getTime())
|
||||||
|
var tempFd = fileio.openSync(filePath, 0o102, 0o666)
|
||||||
|
await this.dlpFile.recoverDlpFile(tempFd)
|
||||||
|
console.info(TAG + "filePath" + filePath + ", DlpProperty: " + JSON.stringify(this.dlpFile.dlpProperty))
|
||||||
|
await this.dlpFile.closeDlpFile()
|
||||||
|
this.dlpFile = await dlpPermission.generateDlpFile(tempFd, this.srcFd, this.dlpFile.dlpProperty)
|
||||||
|
fileio.closeSync(tempFd)
|
||||||
|
fileio.unlinkSync(filePath)
|
||||||
|
await this.dlpFile.closeDlpFile()
|
||||||
|
globalThis.context.terminateSelf()
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "error: " + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filePickerWant.parameters.saveFile = filename
|
||||||
|
globalThis.context.startAbilityForResult(filePickerWant, filePickerOptions, async (error, data) => {
|
||||||
|
console.log(TAG + JSON.stringify(error) + ", data: " + JSON.stringify(data))
|
||||||
|
var uri = data.want.parameters.result
|
||||||
|
try {
|
||||||
|
var dsHelper = await datafile.createFileAccessHelper(globalThis.context)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "createFileAccessHelper error: " + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var dstFd = await dsHelper.openFile(uri, 0o2)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "openFile error: " + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.dlpFile.recoverDlpFile(dstFd)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "recoverDlpFile error: " + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.dlpFile.closeDlpFile()
|
||||||
|
globalThis.context.terminateSelf()
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "closeDlpFile error: " + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
postProcessForEncrypting() {
|
||||||
|
if (!this.needProtect || this.srcFilename == undefined || this.srcFilename.length == 0) {
|
||||||
|
console.log("DlpManager no need to be protected")
|
||||||
|
globalThis.context.terminateSelf()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
filePickerWant.parameters.saveFile = this.srcFilename + '.dlp'
|
||||||
|
globalThis.context.startAbilityForResult(filePickerWant, filePickerOptions, async (error, data) => {
|
||||||
|
console.log(TAG + JSON.stringify(error) + ", data: " + JSON.stringify(data))
|
||||||
|
var uri: string = data.want.parameters.result
|
||||||
|
if (uri.length == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var dsHelper = await datafile.createFileAccessHelper(globalThis.context)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "createFileAccessHelper error: " + JSON.stringify(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var dstFd = await dsHelper.openFile(uri, 0o2)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "openFile error: " + JSON.stringify(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.dlpFile = await dlpPermission.generateDlpFile(this.srcFd, dstFd, this.dlpFile.dlpProperty)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "generateDlpFile error: " + JSON.stringify(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.dlpFile.closeDlpFile()
|
||||||
|
globalThis.context.terminateSelf()
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "closeDlpFile error: " + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
Row() {
|
||||||
|
Button($r('app.string.ban'), { type: ButtonType.Normal })
|
||||||
|
.fontColor($r('app.color.button_color'))
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.backgroundColor($r("app.color.button_background_color"))
|
||||||
|
.width(Constants.FOOTER_WIDTH)
|
||||||
|
.focusable(false)
|
||||||
|
.height(Constants.FOOTER_HEIGHT)
|
||||||
|
.onClick(async (event) => {
|
||||||
|
if (this.isDlpFile) {
|
||||||
|
try {
|
||||||
|
await this.dlpFile.closeDlpFile()
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "error: " + JSON.stringify(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
globalThis.context.terminateSelf()
|
||||||
|
})
|
||||||
|
Line()
|
||||||
|
.width(Constants.FOOTER_LINE_WIDTH)
|
||||||
|
.height(Constants.FOOTER_LINE_HEIGHT)
|
||||||
|
.backgroundColor($r('app.color.footer_line_background_color'))
|
||||||
|
Button(this.needProtect ? $r('app.string.save') : $r('app.string.sure'), { type: ButtonType.Normal })
|
||||||
|
.fontColor($r('app.color.button_color'))
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.backgroundColor($r("app.color.button_background_color"))
|
||||||
|
.width(Constants.FOOTER_BUTTON_WIDTH)
|
||||||
|
.focusable(false)
|
||||||
|
.enabled((this.needProtect || this.isDlpFile))
|
||||||
|
.opacity((this.needProtect || this.isDlpFile) ?
|
||||||
|
Constants.FOOTER_OPACITY_ONE : Constants.FOOTER_OPACITY_SEPC)
|
||||||
|
.height(Constants.FOOTER_BUTTON_HEIGHT)
|
||||||
|
.onClick((event) => {
|
||||||
|
if (this.dlpFile.dlpProperty.contractAccount.length == 0) {
|
||||||
|
this.dlpFile.dlpProperty.contractAccount = globalThis.accountInfo.distributedInfo.name
|
||||||
|
}
|
||||||
|
if (this.isDlpFile) {
|
||||||
|
this.postProcessForSetting()
|
||||||
|
} else {
|
||||||
|
this.postProcessForEncrypting()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.width(Constants.FOOTER_ROW_WIDTH)
|
||||||
|
.height(Constants.FOOTER_ROW_HEIGHT)
|
||||||
|
.margin({ top: Constants.FOOTER_ROW_MARGIN })
|
||||||
|
.padding({
|
||||||
|
bottom: Constants.FOOTER_ROW_PAD_BOTTOM,
|
||||||
|
left: Constants.FOOTER_ROW_PAD_LEFT,
|
||||||
|
right: Constants.FOOTER_ROW_PAD_RIGHT
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Footer }
|
53
entry/src/main/ets/common/components/header.ets
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import dlpPermission from '@ohos.dlpPermission'
|
||||||
|
import Constants from '../constant'
|
||||||
|
|
||||||
|
@Component
|
||||||
|
struct Header {
|
||||||
|
@Link authPerm : number
|
||||||
|
@Link needProtect : boolean
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
Column({}) {
|
||||||
|
Text($r('app.string.header_title'))
|
||||||
|
.fontWeight(FontWeight.Bold)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontColor($r('app.color.text_color'))
|
||||||
|
.fontSize(Constants.HEADER_TEXT_FRONT_SIZE)
|
||||||
|
.lineHeight(Constants.HEADER_TEXT_LINE_HEIGHT)
|
||||||
|
.margin({top: Constants.HEADER_TEXT_MARGIN_TOP})
|
||||||
|
.width(Constants.HEADER_TEXT_WIDTH)
|
||||||
|
.align(Alignment.Start)
|
||||||
|
}
|
||||||
|
.width(Constants.HEADER_COLUMN_WIDTH)
|
||||||
|
.height(Constants.HEADER_COLUMN_HEIGHT)
|
||||||
|
.padding({left: Constants.HEADER_COLUMN_PAD_LEFT, right: Constants.HEADER_COLUMN_PAD_RIGHT})
|
||||||
|
Row() {
|
||||||
|
Flex({justifyContent: FlexAlign.SpaceBetween}) {
|
||||||
|
Row() {
|
||||||
|
Text($r('app.string.toggle_title'))
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.fontColor($r('app.color.text_color'))
|
||||||
|
.fontSize(Constants.HEADER_ROW_FONT_SIZE)
|
||||||
|
.lineHeight(Constants.HEADER_ROW_LINE_HEIGHT)
|
||||||
|
}
|
||||||
|
.alignItems(VerticalAlign.Center)
|
||||||
|
Toggle({ type: ToggleType.Switch, isOn: this.needProtect})
|
||||||
|
.enabled(this.authPerm == 2 ? true : false)
|
||||||
|
.selectedColor($r("app.color.toggle_color"))
|
||||||
|
.width(Constants.HEADER_TOGGLE_WIDTH)
|
||||||
|
.height(Constants.HEADER_TOGGLE_HEIGHT)
|
||||||
|
.focusable(false)
|
||||||
|
.onChange((isOn) => {
|
||||||
|
this.needProtect = isOn ? true : false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.height(Constants.HEADER_ROW_HEIGHT)
|
||||||
|
.margin({top: Constants.HEADER_ROW_MARGIN_TOP})
|
||||||
|
.padding({left: Constants.HEADER_ROW_PAD_LEFT, right: Constants. HEADER_ROW_PAD_RIGHT})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {Header}
|
273
entry/src/main/ets/common/components/permission_panel.ets
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
import dlpPermission from '@ohos.dlpPermission'
|
||||||
|
import {DelUserAlertDialog} from '../components/del_user_alert'
|
||||||
|
import {DlpAlertDialog} from '../components/dlp_alert_dialog'
|
||||||
|
import Constants from'../constant'
|
||||||
|
|
||||||
|
var TAG = "DLPManager: "
|
||||||
|
@Component
|
||||||
|
struct PermissionPanel {
|
||||||
|
scroller: Scroller = new Scroller()
|
||||||
|
account : string = ''
|
||||||
|
radioImg = [$r('app.media.radiodefault'), $r('app.media.radio_selected')]
|
||||||
|
delUserDialogController: CustomDialogController
|
||||||
|
dlpAlertDialog: CustomDialogController
|
||||||
|
@Link authPerm: number
|
||||||
|
@Link isChanged: boolean
|
||||||
|
@Link dlpFile: dlpPermission.DlpFile
|
||||||
|
@State authUserMap: { [key: string] : dlpPermission.AuthUser } = {}
|
||||||
|
@State authUsers: Array<dlpPermission.AuthUser> = []
|
||||||
|
@State showAuthUsers : boolean = true
|
||||||
|
|
||||||
|
updateAuthUsers() {
|
||||||
|
this.authUsers = []
|
||||||
|
this.dlpFile.dlpProperty.authUsers = []
|
||||||
|
for (var item in this.authUserMap) {
|
||||||
|
let authUser = this.authUserMap[item]
|
||||||
|
this.authUsers.push(authUser)
|
||||||
|
this.dlpFile.dlpProperty.authUsers.push(authUser)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aboutToAppear() {
|
||||||
|
this.authUsers = this.dlpFile.dlpProperty.authUsers
|
||||||
|
for (var i = 0; i < this.authUsers.length; ++i) {
|
||||||
|
var authUser = this.authUsers[i]
|
||||||
|
this.authUserMap[authUser.authAccount] = authUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder ListItemLayout(item: dlpPermission.AuthUser) {
|
||||||
|
ListItem() {
|
||||||
|
Column() {
|
||||||
|
Row() {
|
||||||
|
Text(item.authAccount)
|
||||||
|
.maxLines(Constants.PP_TEXT_MAX_LINE)
|
||||||
|
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||||
|
.fontSize(Constants.PP_TEXT_FONT_SIZE)
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.lineHeight(Constants.PP_TEXT_LINE_HEIGHT)
|
||||||
|
.width(Constants.PP_TEXT_WIDTH)
|
||||||
|
.padding({right: Constants.PP_TEXT_PAD_RIGHT})
|
||||||
|
Image(this.radioImg[2 - item.authPerm])
|
||||||
|
.enabled(this.authPerm == 2 ? true : false)
|
||||||
|
.width(Constants.PP_IMAGE_WIDTH)
|
||||||
|
.height(Constants.PP_IMAGE_HEIGHT)
|
||||||
|
.padding(Constants.PP_IMAGE_PAD)
|
||||||
|
.onClick((event) => {
|
||||||
|
var authUser = this.authUserMap[item.authAccount]
|
||||||
|
authUser.authPerm = dlpPermission.AuthPermType.READ_ONLY
|
||||||
|
authUser.permExpiryTime = Date.UTC(2023, 1, 1)
|
||||||
|
this.updateAuthUsers()
|
||||||
|
})
|
||||||
|
Column() {
|
||||||
|
Image(this.radioImg[item.authPerm - 1])
|
||||||
|
.enabled(this.authPerm == 2 ? true : false)
|
||||||
|
.width(Constants.PP_IMAGE_WIDTH)
|
||||||
|
.height(Constants.PP_IMAGE_HEIGHT)
|
||||||
|
.padding(Constants.PP_IMAGE_PAD)
|
||||||
|
.onClick((event) => {
|
||||||
|
var authUser = this.authUserMap[item.authAccount]
|
||||||
|
authUser.authPerm = dlpPermission.AuthPermType.FULL_CONTROL
|
||||||
|
authUser.permExpiryTime = Date.UTC(2023, 1, 1)
|
||||||
|
this.updateAuthUsers()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.alignItems(HorizontalAlign.Center)
|
||||||
|
.width(Constants.PP_COLUMN_WIDTH)
|
||||||
|
.margin({ left: Constants.PP_COLUMN_MARGIN_LEFT, right: Constants.PP_COLUMN_MARGIN_RIGHT })
|
||||||
|
Image($r('app.media.ic_public_delete'))
|
||||||
|
.enabled(this.authPerm == 2 ? true : false)
|
||||||
|
.width(Constants.PP_IMAGE_WIDTH)
|
||||||
|
.height(Constants.PP_IMAGE_HEIGHT)
|
||||||
|
.padding(Constants.PP_IMAGE_PAD)
|
||||||
|
.onClick((event) => {
|
||||||
|
this.delUserDialogController = new CustomDialogController({
|
||||||
|
builder: DelUserAlertDialog({ cancel: null, confirm: () => {
|
||||||
|
delete this.authUserMap[item.authAccount]
|
||||||
|
this.updateAuthUsers()
|
||||||
|
this.isChanged = true
|
||||||
|
} }),
|
||||||
|
autoCancel: true,
|
||||||
|
customStyle: true
|
||||||
|
})
|
||||||
|
this.delUserDialogController.open()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.height(Constants.PP_ROW_HEIGHT)
|
||||||
|
Line()
|
||||||
|
.width(Constants.PP_LINE_WIDTH)
|
||||||
|
.height(Constants.PP_LINE_HEIGHT)
|
||||||
|
.backgroundColor($r('app.color.pp_line_background_color'))
|
||||||
|
}
|
||||||
|
.alignItems(HorizontalAlign.Start)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
Row() {
|
||||||
|
Text($r('app.string.toggle_tip'))
|
||||||
|
.fontColor($r("app.color.text_color"))
|
||||||
|
.fontWeight(FontWeight.Regular)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontSize(Constants.PP_TEXT_FONT_SIZE)
|
||||||
|
.lineHeight(Constants.PP_TEXT_LINE_HEIGHT)
|
||||||
|
.align(Alignment.Start)
|
||||||
|
.width(Constants.PP_TEXT_WIDTH_FULL)
|
||||||
|
}
|
||||||
|
.height(Constants.PP_TEXT_HEIGHT)
|
||||||
|
.opacity(Constants.PP_TEXT_OPACITY)
|
||||||
|
Row () {
|
||||||
|
Text($r('app.string.perm_panel_title'))
|
||||||
|
.fontColor($r("app.color.text_color"))
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Regular)
|
||||||
|
.width(Constants.PP_TEXT_WIDTH_FULL)
|
||||||
|
.lineHeight(Constants.PP_TEXT_LINE_HEIGHT)
|
||||||
|
.margin({top: Constants.PP_TEXT_MARGIN_TOP})
|
||||||
|
.align(Alignment.Start)
|
||||||
|
.fontSize(Constants.PP_TEXT_FONT_SIZE)
|
||||||
|
}
|
||||||
|
.margin({top: Constants.PP_ROW_MARGIN_TOP})
|
||||||
|
.height(Constants.PP_ROW_HEIGHT2)
|
||||||
|
.opacity(Constants.PP_TEXT_OPACITY)
|
||||||
|
if (this.showAuthUsers) {
|
||||||
|
if (this.authUsers.length > 0) {
|
||||||
|
Row() {
|
||||||
|
Text($r('app.string.perm_list_title_user_name'))
|
||||||
|
.fontSize(Constants.PP_TEXT_FONT_SIZE2)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.lineHeight(Constants.PP_TEXT_LINE_HEIGHT2)
|
||||||
|
.width(Constants.PP_TEXT_WIDTH)
|
||||||
|
Text($r('app.string.perm_list_title_read_only'))
|
||||||
|
.fontSize(Constants.PP_TEXT_FONT_SIZE2)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.fontColor($r('app.color.pp_text_fontcolor'))
|
||||||
|
.lineHeight(Constants.PP_TEXT_LINE_HEIGHT2)
|
||||||
|
.width(Constants.PP_IMAGE_WIDTH)
|
||||||
|
Text($r('app.string.perm_list_title_full_control'))
|
||||||
|
.fontSize(Constants.PP_TEXT_FONT_SIZE2)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.fontColor($r('app.color.pp_text_fontcolor'))
|
||||||
|
.lineHeight(Constants.PP_TEXT_LINE_HEIGHT2)
|
||||||
|
.width(Constants.PP_TEXT_WIDTH2)
|
||||||
|
.margin({ left: Constants.PP_TEXT_MARGIN_LEFT, right: Constants.PP_TEXT_MARGIN_RIGHT })
|
||||||
|
Text()
|
||||||
|
.width(Constants.PP_TEXT_WIDTH3)
|
||||||
|
}
|
||||||
|
.height(Constants.PP_ROW_HEIGHT3)
|
||||||
|
}
|
||||||
|
Scroll(this.scroller) {
|
||||||
|
List() {
|
||||||
|
ForEach(this.authUsers, (item) => {
|
||||||
|
this.ListItemLayout(item)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.width(Constants.PP_TEXT_WIDTH_FULL)
|
||||||
|
.align(Alignment.Top)
|
||||||
|
.scrollable(ScrollDirection.Vertical)
|
||||||
|
.scrollBar(BarState.On)
|
||||||
|
.scrollBarWidth(Constants.PP_SCROLL_BAR_WIDTH)
|
||||||
|
.constraintSize({maxHeight: Constants.PP_SCROLL_MAX_HEIGHT})
|
||||||
|
Row() {
|
||||||
|
Button($r('app.string.button_add_user'))
|
||||||
|
.enabled(this.authPerm == 2 ? true : false)
|
||||||
|
.fontSize(Constants.PP_BUTTON_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.button_color'))
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.height(Constants.PP_BUTTON_HEIGHT)
|
||||||
|
.padding(Constants.PP_BUTTON_PAD)
|
||||||
|
.focusable(false)
|
||||||
|
.backgroundColor($r('app.color.pp_button_background_color'))
|
||||||
|
.onClick((event) => {
|
||||||
|
this.showAuthUsers = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.align(Alignment.Start)
|
||||||
|
.width(Constants.PP_TEXT_WIDTH_FULL)
|
||||||
|
.height(Constants.PP_ROW_HEIGHT2)
|
||||||
|
} else {
|
||||||
|
Row() {
|
||||||
|
TextInput()
|
||||||
|
.height(Constants.PP_TEXT_INPUT)
|
||||||
|
.padding({top: Constants.PP_ROW_PAD_TOP, bottom: Constants.PP_ROW_PAD_BOTTOM})
|
||||||
|
.fontSize(Constants.PP_TEXT_FONT_SIZE)
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Regular)
|
||||||
|
.borderRadius(Constants.PP_ROW_RADIUS)
|
||||||
|
.backgroundColor($r('app.color.pp_row_background_color'))
|
||||||
|
.onChange((value: string) => {
|
||||||
|
this.account = value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.padding({right: Constants.PP_ROW_PAD_RIGHT})
|
||||||
|
Line()
|
||||||
|
.width(Constants.PP_LINE_WIDTH)
|
||||||
|
.height(Constants.PP_LINE_HEIGHT2)
|
||||||
|
.backgroundColor($r('app.color.pp_text_fontcolor'))
|
||||||
|
Row() {
|
||||||
|
Button($r('app.string.add'))
|
||||||
|
.fontSize(Constants.PP_BUTTON_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.button_color'))
|
||||||
|
.fontFamily($r('app.string.typeface'))
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.height(Constants.PP_BUTTON_HEIGHT)
|
||||||
|
.padding(Constants.PP_BUTTON_PAD)
|
||||||
|
.backgroundColor($r('app.color.pp_button_background_color'))
|
||||||
|
.onClick((event) => {
|
||||||
|
if (this.account.length > Constants.ACCOUNT_LENGTH_MAX ) {
|
||||||
|
this.dlpAlertDialog = new CustomDialogController({
|
||||||
|
builder: DlpAlertDialog({
|
||||||
|
title:Constants.PP_TITLE,
|
||||||
|
message: Constants.PP_MESSAGE,
|
||||||
|
}),
|
||||||
|
autoCancel: false,
|
||||||
|
customStyle: true
|
||||||
|
})
|
||||||
|
this.dlpAlertDialog.open()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.account.length != 0 && this.authUserMap[this.account] == undefined) {
|
||||||
|
this.authUserMap[this.account] = {
|
||||||
|
authAccount: this.account,
|
||||||
|
authPerm: dlpPermission.AuthPermType.READ_ONLY,
|
||||||
|
permExpiryTime: Date.UTC(2023, 1, 1),
|
||||||
|
authAccountType: dlpPermission.AccountType.CLOUD_ACCOUNT
|
||||||
|
}
|
||||||
|
this.updateAuthUsers()
|
||||||
|
this.isChanged = true
|
||||||
|
}
|
||||||
|
this.account = ''
|
||||||
|
this.showAuthUsers = true
|
||||||
|
})
|
||||||
|
Button($r('app.string.cancel'))
|
||||||
|
.fontSize(Constants.PP_BUTTON_FONT_SIZE)
|
||||||
|
.fontColor($r('app.color.button_color'))
|
||||||
|
.fontFamily('app.string.HarmonyHeiTi')
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
.height(Constants.PP_BUTTON_HEIGHT)
|
||||||
|
.padding(Constants.PP_BUTTON_PAD)
|
||||||
|
.margin({left: Constants.PP_BUTTON_MARGIN_LEFT})
|
||||||
|
.focusable(false)
|
||||||
|
.backgroundColor($r('app.color.pp_button_background_color'))
|
||||||
|
.onClick((event) => {
|
||||||
|
this.showAuthUsers = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.align(Alignment.Start)
|
||||||
|
.width(Constants.PP_TEXT_WIDTH_FULL)
|
||||||
|
.height(Constants.PP_ROW_HEIGHT2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding({left: Constants.PP_COLUMN_MARGIN_LEFT2, right: Constants.PP_COLUMN_MARGIN_RIGHT2})
|
||||||
|
.alignItems(HorizontalAlign.Start)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {PermissionPanel}
|
165
entry/src/main/ets/common/constant.ets
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021-2022 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default class Constants {
|
||||||
|
static INDEX_COLUMN_WIDTH = 360;
|
||||||
|
static INDEX_BORDER_RADIUS = 24;
|
||||||
|
static FOOTER_WIDTH = '49%';
|
||||||
|
static FOOTER_HEIGHT = 40;
|
||||||
|
static FOOTER_LINE_WIDTH= 0.5;
|
||||||
|
static FOOTER_LINE_HEIGHT= 24;
|
||||||
|
static FOOTER_BUTTON_WIDTH = '50%';
|
||||||
|
static FOOTER_BUTTON_HEIGHT = 40;
|
||||||
|
static FOOTER_ROW_WIDTH= '100%';
|
||||||
|
static FOOTER_ROW_HEIGHT= 56;
|
||||||
|
static FOOTER_ROW_MARGIN = 8;
|
||||||
|
static FOOTER_ROW_PAD_BOTTOM= 16;
|
||||||
|
static FOOTER_ROW_PAD_LEFT= 16;
|
||||||
|
static FOOTER_ROW_PAD_RIGHT= 16;
|
||||||
|
static HEADER_TEXT_FRONT_SIZE= 20;
|
||||||
|
static HEADER_TEXT_LINE_HEIGHT = 28;
|
||||||
|
static HEADER_TEXT_MARGIN_TOP = 18;
|
||||||
|
static HEADER_TEXT_WIDTH= '100%';
|
||||||
|
static HEADER_COLUMN_WIDTH= '100%';
|
||||||
|
static HEADER_COLUMN_HEIGHT= 56;
|
||||||
|
static HEADER_COLUMN_PAD_LEFT= 20;
|
||||||
|
static HEADER_COLUMN_PAD_RIGHT= 20;
|
||||||
|
static HEADER_ROW_FONT_SIZE = 16 ;
|
||||||
|
static HEADER_ROW_LINE_HEIGHT = 22 ;
|
||||||
|
static HEADER_TOGGLE_WIDTH= 36;
|
||||||
|
static HEADER_TOGGLE_HEIGHT= 20;
|
||||||
|
static HEADER_ROW_HEIGHT= 48;
|
||||||
|
static HEADER_ROW_MARGIN_TOP = 12;
|
||||||
|
static HEADER_ROW_PAD_LEFT= 22;
|
||||||
|
static HEADER_ROW_PAD_RIGHT= 22;
|
||||||
|
static PP_TEXT_MAX_LINE = 1;
|
||||||
|
static PP_TEXT_FONT_SIZE = 16;
|
||||||
|
static PP_TEXT_LINE_HEIGHT = 22;
|
||||||
|
static PP_TEXT_WIDTH = 200;
|
||||||
|
static PP_TEXT_PAD_RIGHT= 4;
|
||||||
|
static PP_IMAGE_WIDTH = 24;
|
||||||
|
static PP_IMAGE_HEIGHT = 24;
|
||||||
|
static PP_IMAGE_PAD = 2;
|
||||||
|
static PP_COLUMN_WIDTH = 48;
|
||||||
|
static PP_COLUMN_MARGIN_LEFT= 9;
|
||||||
|
static PP_COLUMN_MARGIN_RIGHT= 9;
|
||||||
|
static PP_ROW_HEIGHT = 47.5;
|
||||||
|
static PP_LINE_WIDTH = 312;
|
||||||
|
static PP_LINE_HEIGHT = 0.5;
|
||||||
|
static PP_TEXT_WIDTH_FULL = '100%';
|
||||||
|
static PP_TEXT_HEIGHT = 44;
|
||||||
|
static PP_TEXT_OPACITY= 0.6;
|
||||||
|
static PP_TEXT_MARGIN_TOP= 19;
|
||||||
|
static PP_ROW_MARGIN_TOP = 12;
|
||||||
|
static PP_ROW_HEIGHT2 = 48;
|
||||||
|
static PP_TEXT_FONT_SIZE2= 12;
|
||||||
|
static PP_TEXT_LINE_HEIGHT2= 17;
|
||||||
|
static PP_TEXT_WIDTH2= 48;
|
||||||
|
static PP_TEXT_MARGIN_LEFT = 8 ;
|
||||||
|
static PP_TEXT_MARGIN_RIGHT = 8;
|
||||||
|
static PP_TEXT_WIDTH3= 24;
|
||||||
|
static PP_ROW_HEIGHT3= 19;
|
||||||
|
static PP_SCROLL_BAR_WIDTH= 4;
|
||||||
|
static PP_SCROLL_MAX_HEIGHT= 144;
|
||||||
|
static PP_BUTTON_FONT_SIZE = 16;
|
||||||
|
static PP_BUTTON_HEIGHT= 22;
|
||||||
|
static PP_BUTTON_PAD= 0;
|
||||||
|
static PP_TEXT_INPUT= 47;
|
||||||
|
static PP_ROW_PAD_TOP= 13;
|
||||||
|
static PP_ROW_PAD_BOTTOM = 12;
|
||||||
|
static PP_ROW_RADIUS= 0;
|
||||||
|
static PP_ROW_PAD_RIGHT= 14;
|
||||||
|
static PP_LINE_HEIGHT2= 1;
|
||||||
|
static PP_TITLE = "帐号名不合法";
|
||||||
|
static PP_MESSAGE = "帐号长度应小于等于1024";
|
||||||
|
static PP_BUTTON_MARGIN_LEFT = 16;
|
||||||
|
static PP_COLUMN_MARGIN_LEFT2= 24;
|
||||||
|
static PP_COLUMN_MARGIN_RIGHT2 = 10;
|
||||||
|
static AP_TEXT_MAX_LINE = 1;
|
||||||
|
static AP_TEXT_FONT_SIZE = 16;
|
||||||
|
static AP_TEXT_LINE_HEIGHT = 22;
|
||||||
|
static AP_TEXT_WIDTH = 290;
|
||||||
|
static AP_TEXT_PAD_RIGHT = 4;
|
||||||
|
static AP_COLUMN_HEIGHT= 48;
|
||||||
|
static AP_MARGIN_TOP = 19;
|
||||||
|
static AP_COLUMN_OPACITY= 0.6;
|
||||||
|
static AP_LIST_HEIGHT = 48;
|
||||||
|
static AP_LIST_BAR_WIDTH= 4;
|
||||||
|
static AP_BUTTON_HEIGHT = 22;
|
||||||
|
static AP_BUTTON_PAD= 0;
|
||||||
|
static AP_ROW_HEIGHT= 48;
|
||||||
|
static AP_TEXT_INPUT_HEIGHT = 47;
|
||||||
|
static AP_TEXT_PAD_TOP= 13;
|
||||||
|
static AP_TEXT_PAD_BOTTOM= 12;
|
||||||
|
static AP_ROW_RADIUS= 0;
|
||||||
|
static AP_ROW_PAD_RIGHT= 14;
|
||||||
|
static AP_LINE_WIDTH = 312;
|
||||||
|
static AP_LINE_HEIGHT = 1;
|
||||||
|
static AP_BUTTON_FONT_SIZE= 16;
|
||||||
|
static AP_BUTTON_MARGIN_LEFT= 16;
|
||||||
|
static AP_COLUMN_PAD_LEFT= 24;
|
||||||
|
static AP_COLUMN_PAD_RIGHT= 10;
|
||||||
|
static DU_TEXT_LINE_HEIGHT = 28;
|
||||||
|
static DU_WIDTH_FULL= '100%';
|
||||||
|
static DU_TEXT_FONT_SIZE = 20;
|
||||||
|
static DU_ROW_HEIGHT= 56;
|
||||||
|
static DU_ROW_WIDTH= 288;
|
||||||
|
static DU_SCROLL_LINE_HEIGHT = 16;
|
||||||
|
static DU_SCROLL_FONT_SIZE = 14;
|
||||||
|
static DU_SCROLL_BAR_WIDTH = 5;
|
||||||
|
static DU_CONS_MAX_HEIGHT = 500;
|
||||||
|
static DU_MARGIN_TOP = 12;
|
||||||
|
static DU_WIDTH_SPE= '49%';
|
||||||
|
static DU_BUTTON_HEIGHT= 40;
|
||||||
|
static DU_BUTTON_FONT_SIZE = 16
|
||||||
|
static DU_LINE_WIDTH= 0.5;
|
||||||
|
static DU_LINE_HEIGHT = 22;
|
||||||
|
static DU_LINE_MARGIN_TOP = 9;
|
||||||
|
static DU_BUTTON_WIDTH = '50%';
|
||||||
|
static DU_ROW_WIDTH2= 304;
|
||||||
|
static DU_LINE_MARGIN_TOP2 = 8;
|
||||||
|
static DU_ROW_WIDTH3 = 336;
|
||||||
|
static DU_BORDER_RADIUS = 24;
|
||||||
|
static DA_FONT_SIZE= 20;
|
||||||
|
static DA_ROW_HEIGHT = 56;
|
||||||
|
static DA_ROW_WIDTH = 288;
|
||||||
|
static DA_TEXT_LINE_HEIGHT = 28;
|
||||||
|
static DA_SCROLL_LINE_HEIGHT = 16;
|
||||||
|
static DA_SCROLL_FONT_SIZE = 14;
|
||||||
|
static DA_SCROLL_BAR_WIDTH = 5;
|
||||||
|
static DA_STRAIN_SIZE_MA_HEIGHT = 500;
|
||||||
|
static DA_MARGIN_TOP = 12;
|
||||||
|
static DA_SCROLL_WIDTH = 288;
|
||||||
|
static ROW_BUTTON_WIDTH = 304;
|
||||||
|
static ROW_BUTTON_HEIGHT = 40;
|
||||||
|
static ROW_FONT_SIZE = 16;
|
||||||
|
static ROW_MARGIN_TOP= 8;
|
||||||
|
static DA_COLOUM_WIDTH = 336;
|
||||||
|
static DA_COLOUM_RADIUS = 24;
|
||||||
|
static APP_PARAM_ERROR = '参数异常,请重试。';
|
||||||
|
static APP_ERROR = '应用异常';
|
||||||
|
static APP_GET_ACCOUNT_ERROR = '获取帐号信息失败,请重试。';
|
||||||
|
static APP_SANDBOX_ERROR= '启动应用沙箱失败,请重试。';
|
||||||
|
static APP_VISIT_FILE_ERROR= '无法访问此文件';
|
||||||
|
static APP_NOT_HAVE_PERM_VISIT = '您没有访问权限。请向下列用户申请授权:\n';
|
||||||
|
static APP_DLP_ERROR = 'DLP格式错误';
|
||||||
|
static APP_FILE_PARAM_ERROR = '您打开的文档格式不正确,请重试。';
|
||||||
|
static APP_SANDBOX_LIMIT_MAX = '沙箱应用数量超出上限,请卸载后重试。';
|
||||||
|
static APP_INSTALL_SANDBOX_ERROR = '安装沙箱应用失败,请重试。';
|
||||||
|
static APP_LINK_FILE_ERROR = '添加链接文件失败,请重试。';
|
||||||
|
static FOOTER_OPACITY_ONE = 1;
|
||||||
|
static FOOTER_OPACITY_SEPC= 0.6;
|
||||||
|
static ACCOUNT_LENGTH_MAX = 1024;
|
||||||
|
}
|
65
entry/src/main/ets/common/utils.ets
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import account_distributedAccount from '@ohos.account.distributedAccount';
|
||||||
|
import account_osAccount from '@ohos.account.osAccount';
|
||||||
|
import dlpPermission from '@ohos.dlpPermission';
|
||||||
|
|
||||||
|
var TAG = "[DLPManager]"
|
||||||
|
async function getDistributedAccountInfo() : Promise<account_distributedAccount.DistributedInfo> {
|
||||||
|
var distAbility = account_distributedAccount.getDistributedAccountAbility()
|
||||||
|
return distAbility.queryOsAccountDistributedInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getOsAccountInfo() : Promise<account_osAccount.OsAccountInfo> {
|
||||||
|
var accountMgr = account_osAccount.getAccountManager()
|
||||||
|
return accountMgr.queryCurrentOsAccount()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getUserId() : Promise<number> {
|
||||||
|
var accountMgr = account_osAccount.getAccountManager()
|
||||||
|
return accountMgr.getOsAccountLocalIdFromProcess()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDomainId() : Promise<account_osAccount.OsAccountInfo> {
|
||||||
|
var accountMgr = account_osAccount.getAccountManager()
|
||||||
|
return accountMgr.queryCurrentOsAccount()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAuthPerm(accountName, dlpProperty) : number {
|
||||||
|
if (accountName == dlpProperty.ownerAccount) {
|
||||||
|
return dlpPermission.AuthPermType.FULL_CONTROL
|
||||||
|
}
|
||||||
|
for (var i = 0; i < dlpProperty.authUsers.length; ++i) {
|
||||||
|
var authUser = dlpProperty.authUsers[i]
|
||||||
|
if (authUser.authAccount == accountName) {
|
||||||
|
return authUser.authPerm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
function terminateSelfWithResult(resultCode: number, result: string) : void {
|
||||||
|
var abilityResult = {
|
||||||
|
resultCode: resultCode,
|
||||||
|
want: {
|
||||||
|
parameters: {
|
||||||
|
result: result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
globalThis.context.terminateSelfWithResult(abilityResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
function startAlertAbility(title, message) {
|
||||||
|
globalThis.context.startAbility({
|
||||||
|
bundleName: "com.ohos.dlpmanager",
|
||||||
|
abilityName: "AlertAbility",
|
||||||
|
parameters: {
|
||||||
|
title: title,
|
||||||
|
message: message,
|
||||||
|
}
|
||||||
|
}, async (err, data) => {
|
||||||
|
console.log(TAG + "start AlertAbility err: " + JSON.stringify(err))
|
||||||
|
globalThis.context.terminateSelf()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export {getDistributedAccountInfo, getOsAccountInfo, getUserId, getAuthPerm, terminateSelfWithResult, startAlertAbility}
|
24
entry/src/main/ets/pages/alert.ets
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import {DlpAlertDialog} from '../common/components/dlp_alert_dialog'
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
struct Index {
|
||||||
|
alertDialogController: CustomDialogController = new CustomDialogController({
|
||||||
|
builder: DlpAlertDialog({
|
||||||
|
title: globalThis.abilityWant.parameters.title,
|
||||||
|
message: globalThis.abilityWant.parameters.message
|
||||||
|
}),
|
||||||
|
autoCancel: false,
|
||||||
|
cancel: () => {
|
||||||
|
globalThis.context.terminateSelf()
|
||||||
|
},
|
||||||
|
alignment: DialogAlignment.Center,
|
||||||
|
customStyle: true
|
||||||
|
})
|
||||||
|
|
||||||
|
aboutToAppear() {
|
||||||
|
this.alertDialogController.open()
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {}
|
||||||
|
}
|
147
entry/src/main/ets/pages/index.ets
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
import { Header } from '../common/components/header'
|
||||||
|
import { PermissionPanel } from '../common/components/permission_panel'
|
||||||
|
import { AuthorizerPanel } from '../common/components/authorizer_panel'
|
||||||
|
import { Footer } from '../common/components/footer'
|
||||||
|
import dlpPermission from '@ohos.dlpPermission'
|
||||||
|
import { getAuthPerm } from '../common/utils'
|
||||||
|
import { DlpAlertDialog } from '../common/components/dlp_alert_dialog'
|
||||||
|
import { KeyCode } from '@ohos.multimodalInput.keyCode'
|
||||||
|
import { getOsAccountInfo, terminateSelfWithResult } from '../common/utils'
|
||||||
|
import Constants from '../common/constant'
|
||||||
|
|
||||||
|
var TAG = "[DLPManager]"
|
||||||
|
|
||||||
|
var defaultDlpProperty: dlpPermission.DlpProperty = {
|
||||||
|
ownerAccount: '',
|
||||||
|
ownerAccountType: 1,
|
||||||
|
authUsers: [],
|
||||||
|
contractAccount: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultDlpFile: dlpPermission.DlpFile = {
|
||||||
|
dlpProperty: defaultDlpProperty,
|
||||||
|
recoverDlpFile: null,
|
||||||
|
closeDlpFile: null,
|
||||||
|
addDlpLinkFile: null,
|
||||||
|
deleteDlpLinkFile: null
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component
|
||||||
|
struct DlpDialog {
|
||||||
|
isDlpFile: boolean = false
|
||||||
|
dlpAlertDialog: CustomDialogController
|
||||||
|
@State authPerm: number = 2
|
||||||
|
@State isShow: boolean = false
|
||||||
|
@State isChanged: boolean = false
|
||||||
|
@State dlpFile: dlpPermission.DlpFile = defaultDlpFile
|
||||||
|
@State needProtect: boolean = false
|
||||||
|
|
||||||
|
showDlpAlertDialog(title, message) {
|
||||||
|
this.dlpAlertDialog = new CustomDialogController({
|
||||||
|
builder: DlpAlertDialog({
|
||||||
|
title: title,
|
||||||
|
message: message
|
||||||
|
}),
|
||||||
|
autoCancel: false,
|
||||||
|
customStyle: true
|
||||||
|
})
|
||||||
|
this.dlpAlertDialog.open()
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkAndOpenDlpFile(filename: string, fd: number): Promise<void> {
|
||||||
|
console.info(TAG + "checkAndOpenDlpFile")
|
||||||
|
this.dlpFile.dlpProperty.ownerAccount = globalThis.accountInfo.distributedInfo.name
|
||||||
|
this.dlpFile.dlpProperty.contractAccount = globalThis.accountInfo.distributedInfo.name
|
||||||
|
var isDlpSuffix: boolean = filename.endsWith(".dlp")
|
||||||
|
if (!isDlpSuffix) {
|
||||||
|
console.info(TAG + "input file is not a dlp file")
|
||||||
|
this.isShow = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.dlpFile = await dlpPermission.openDlpFile(fd)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "openDlpFile error: " + JSON.stringify(err))
|
||||||
|
if (err.code == 1 && err.extra != undefined) {
|
||||||
|
this.showDlpAlertDialog(Constants.APP_VISIT_FILE_ERROR, Constants.APP_NOT_HAVE_PERM_VISIT + err.extra)
|
||||||
|
} else {
|
||||||
|
this.showDlpAlertDialog(Constants.APP_DLP_ERROR, Constants.APP_FILE_PARAM_ERROR)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.authPerm = getAuthPerm(globalThis.accountInfo.distributedInfo.name, this.dlpFile.dlpProperty)
|
||||||
|
this.isDlpFile = true
|
||||||
|
this.needProtect = true
|
||||||
|
this.isShow = true
|
||||||
|
}
|
||||||
|
|
||||||
|
async aboutToAppear() {
|
||||||
|
console.info(TAG + "aboutToAppear")
|
||||||
|
try {
|
||||||
|
globalThis.accountInfo = await getOsAccountInfo()
|
||||||
|
console.log(TAG + "accountInfo: " + JSON.stringify(globalThis.accountInfo))
|
||||||
|
} catch (err) {
|
||||||
|
console.info(TAG + "getOsAccountInfo error: " + JSON.stringify(err))
|
||||||
|
terminateSelfWithResult(100, "get account info failed")
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
globalThis.srcFilename = globalThis.abilityWant.parameters.fileName.name
|
||||||
|
globalThis.srcFd = globalThis.abilityWant.parameters.keyFd.value
|
||||||
|
console.log(TAG + "srcFilename: " + globalThis.srcFilename + ", srcFd: " + globalThis.srcFd)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(TAG + "get parameters error")
|
||||||
|
terminateSelfWithResult(100, "get parameters failed, fileName and keyFd is required")
|
||||||
|
}
|
||||||
|
this.checkAndOpenDlpFile(globalThis.srcFilename, globalThis.srcFd)
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
if (this.isShow) {
|
||||||
|
Column() {
|
||||||
|
Row() {
|
||||||
|
Header({ authPerm: $authPerm, needProtect: $needProtect })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.needProtect) {
|
||||||
|
Row() {
|
||||||
|
PermissionPanel({ authPerm: $authPerm, dlpFile: $dlpFile, isChanged: $isChanged })
|
||||||
|
}
|
||||||
|
|
||||||
|
Row() {
|
||||||
|
AuthorizerPanel({ authPerm: $authPerm, dlpFile: $dlpFile, isChanged: $isChanged })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row() {
|
||||||
|
Footer({
|
||||||
|
srcFilename: globalThis.srcFilename,
|
||||||
|
srcFd: globalThis.srcFd,
|
||||||
|
isDlpFile: this.isDlpFile,
|
||||||
|
isChanged: $isChanged,
|
||||||
|
dlpFile: $dlpFile,
|
||||||
|
needProtect: $needProtect
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.width(Constants.INDEX_COLUMN_WIDTH)
|
||||||
|
.backgroundColor($r('app.color.index_background_color'))
|
||||||
|
.borderRadius(Constants.INDEX_BORDER_RADIUS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
struct Index {
|
||||||
|
aboutToAppear() {
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center,
|
||||||
|
direction: FlexDirection.Column }) {
|
||||||
|
Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center,
|
||||||
|
direction: FlexDirection.Row }) {
|
||||||
|
DlpDialog()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
entry/src/main/module.json
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"module": {
|
||||||
|
"name": "entry",
|
||||||
|
"type": "entry",
|
||||||
|
"srcEntrance": "./ets/Application/AbilityStage.ts",
|
||||||
|
"description": "$string:entry_desc",
|
||||||
|
"mainElement": "MainAbility",
|
||||||
|
"deviceTypes": [
|
||||||
|
"default",
|
||||||
|
"tablet"
|
||||||
|
],
|
||||||
|
"deliveryWithInstall": true,
|
||||||
|
"installationFree": false,
|
||||||
|
"pages": "$profile:main_pages",
|
||||||
|
"uiSyntax": "ets",
|
||||||
|
"abilities": [
|
||||||
|
{
|
||||||
|
"name": "MainAbility",
|
||||||
|
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
|
||||||
|
"description": "$string:MainAbility_desc",
|
||||||
|
"icon": "$media:icon",
|
||||||
|
"label": "$string:MainAbility_label",
|
||||||
|
"startWindowIcon": "$media:icon",
|
||||||
|
"startWindowBackground": "$color:white",
|
||||||
|
"visible": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extensionAbilities": [
|
||||||
|
{
|
||||||
|
"name": "ViewAbility",
|
||||||
|
"srcEntrance": "./ets/ViewAbility/ViewAbility.ts",
|
||||||
|
"icon": "$media:icon",
|
||||||
|
"description": "$string:ViewAbility_desc",
|
||||||
|
"type": "service",
|
||||||
|
"visible": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "DataAbility",
|
||||||
|
"srcEntrance": "./ets/DataAbility/DataAbility.ts",
|
||||||
|
"icon": "$media:icon",
|
||||||
|
"description": "$string:ViewAbility_desc",
|
||||||
|
"type": "service"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"requestPermissions": [
|
||||||
|
{
|
||||||
|
"name": "ohos.permission.READ_MEDIA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohos.permission.WRITE_MEDIA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohos.permission.ACCESS_DLP_FILE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"ohos.permission.FILE_ACCESS_MANAGER"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
76
entry/src/main/resources/base/element/color.json
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
{
|
||||||
|
"color": [
|
||||||
|
{
|
||||||
|
"name": "white",
|
||||||
|
"value": "#FFFFFF"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "text_color",
|
||||||
|
"value": "#182431"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "divider_color",
|
||||||
|
"value": "#f3f4f6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "default_background_color",
|
||||||
|
"value": "#ffffff"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "button_color",
|
||||||
|
"value": "#FF007DFF"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "button_background_color",
|
||||||
|
"value": "#FFF"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "toggle_color",
|
||||||
|
"value": "#007DFF"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_background_color",
|
||||||
|
"value": "#FFF"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "footer_line_background_color",
|
||||||
|
"value": "#18243133"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pp_line_background_color",
|
||||||
|
"value": "#18243133"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pp_text_fontcolor",
|
||||||
|
"value": "#182431"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pp_button_background_color",
|
||||||
|
"value": "#fff"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pp_row_background_color",
|
||||||
|
"value": "#fff"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "del_scroll_font_color",
|
||||||
|
"value": "#E6000000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "del_button_font_color",
|
||||||
|
"value": "#FA2A2D"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "da_font_color",
|
||||||
|
"value": "#182431"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "da_scroll_font_color",
|
||||||
|
"value": "#E6000000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "da_background_color",
|
||||||
|
"value": "#fff"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
104
entry/src/main/resources/base/element/string.json
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "entry_desc",
|
||||||
|
"value": "description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MainAbility_desc",
|
||||||
|
"value": "DLPManager"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MainAbility_label",
|
||||||
|
"value": "DLPManager"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ViewAbility_desc",
|
||||||
|
"value": "DLPViewer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "AlertAbility_desc",
|
||||||
|
"value": "description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "AlertAbility_label",
|
||||||
|
"value": "label"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ban",
|
||||||
|
"value": "取消"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "typeface",
|
||||||
|
"value": "HarmonyHeiTi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "save",
|
||||||
|
"value": "保存"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "sure",
|
||||||
|
"value": "确定"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "header_title",
|
||||||
|
"value": "加密保护"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "toggle_title",
|
||||||
|
"value": "保护此文件"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "toggle_tip",
|
||||||
|
"value": "开启保护后,将在您选择的位置生成一个新的\".dlp\"格式加密文件。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "perm_panel_title",
|
||||||
|
"value": "授权其他用户可访问:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "perm_list_title_user_name",
|
||||||
|
"value": "用户名"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "perm_list_title_read_only",
|
||||||
|
"value": "只读"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "perm_list_title_full_control",
|
||||||
|
"value": "完全控制"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "button_add_user",
|
||||||
|
"value": "添加用户"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "add",
|
||||||
|
"value": "添加"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cancel",
|
||||||
|
"value": "取消"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "authorizer_panel_title",
|
||||||
|
"value": "允许向以下用户申请权限:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "del_usr",
|
||||||
|
"value": "删除用户"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "del_text1",
|
||||||
|
"value": "删除后此用户将无法访问这个文件,如需恢复请重新添加此用户。是否删除?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "button_del",
|
||||||
|
"value": "删除"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "da_buttion",
|
||||||
|
"value": "知道了"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
BIN
entry/src/main/resources/base/media/ic_public_delete.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
entry/src/main/resources/base/media/ic_radio_unselected.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
entry/src/main/resources/base/media/icon.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
entry/src/main/resources/base/media/radio_selected.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
entry/src/main/resources/base/media/radioactive.jpg
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
entry/src/main/resources/base/media/radiodefault.jpg
Normal file
After Width: | Height: | Size: 1.3 KiB |
6
entry/src/main/resources/base/profile/main_pages.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"src": [
|
||||||
|
"pages/index",
|
||||||
|
"pages/alert"
|
||||||
|
]
|
||||||
|
}
|
2
hvigorfile.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||||
|
module.exports = require('@ohos/hvigor-ohos-plugin').appTasks
|
1227
package-lock.json
generated
Normal file
18
package.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"license":"ISC",
|
||||||
|
"devDependencies":{},
|
||||||
|
"name":"dlpmanager",
|
||||||
|
"ohos":{
|
||||||
|
"org":"huawei",
|
||||||
|
"directoryLevel":"project",
|
||||||
|
"buildTool":"hvigor"
|
||||||
|
},
|
||||||
|
"description":"example description",
|
||||||
|
"repository":{},
|
||||||
|
"version":"1.0.0",
|
||||||
|
"dependencies":{
|
||||||
|
"@ohos/hypium":"1.0.0",
|
||||||
|
"@ohos/hvigor-ohos-plugin":"1.1.5-rc2",
|
||||||
|
"@ohos/hvigor":"1.1.5-rc2"
|
||||||
|
}
|
||||||
|
}
|