diff --git a/BUILD.gn b/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..8029a02d09bb9c83c5be29f81b9bf9efc6e23fc1
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,24 @@
+# Copyright (C) 2021 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.
+
+if (defined(ohos_lite)) {
+ import("//build/lite/config/component/lite_component.gni")
+ lite_component("devicemanager_lite") {
+ features = [
+ "utils:devicemanagerutils",
+ "services/devicemanagerservice:devicemanagerservice",
+ "interfaces/inner_kits/native_cpp:devicemanagersdk",
+ "interfaces/kits/js:devicemanager",
+ ]
+ }
+}
diff --git a/common/include/constants.h b/common/include/constants.h
index d9e21679c7b348b0f804cd5e313d2c047b677767..31e75813d53868e30dd9c4e7c4cf2ae8c1ad0df5 100644
--- a/common/include/constants.h
+++ b/common/include/constants.h
@@ -104,6 +104,7 @@ namespace DistributedHardware {
const int32_t SESSION_REPLY_UNKNOWN = -1;
const int32_t SESSION_REPLY_ACCEPT = 0;
const int32_t SESSION_REPLY_CANCEL = 1;
+ const int32_t SESSION_REPLY_TIMEOUT = 2;
const int32_t SESSION_REPLY_AUTH_CONFIRM_TIMEOUT = 2;
const int32_t SESSION_REPLY_CANCEL_PINCODE_DISPLAY = 3;
const int32_t SESSION_REPLY_CANCEL_PINCODE_INPUT = 4;
@@ -136,6 +137,9 @@ namespace DistributedHardware {
const int32_t SLICE_NUM_INVALID = -1;
const int32_t AUTH_TYPE_QR = 0;
const int32_t AUTH_TYPE_PIN = 1;
+ const std::string DISPLAY_OWNER = "displayOwner";
+ const int32_t DISPLAY_OWNER_SYSTEM = 0;
+ const int32_t DISPLAY_OWNER_OTHER = 1;
// DmService constants
const int32_t MSG_MAX_SIZE = 45 * 1024;
diff --git a/common/include/ipc/model/ipc_notify_dmfa_result_req.h b/common/include/ipc/model/ipc_notify_dmfa_result_req.h
index b76d26ba7c18dd1cf142584692d520658f7fd5c8..e6012aa7af825489250a554935e2985a2ce55ab4 100644
--- a/common/include/ipc/model/ipc_notify_dmfa_result_req.h
+++ b/common/include/ipc/model/ipc_notify_dmfa_result_req.h
@@ -25,16 +25,6 @@ namespace DistributedHardware {
class IpcNotifyDMFAResultReq : public IpcReq {
DECLARE_IPC_MODEL(IpcNotifyDMFAResultReq);
public:
- std::string GetPkgName() const
- {
- return PackageName_;
- }
-
- void SetPkgName(std::string& pkgName)
- {
- PackageName_ = pkgName;
- }
-
std::string GetJsonParam() const
{
return JsonParam_;
@@ -45,7 +35,6 @@ public:
JsonParam_ = JsonParam;
}
private:
- std::string PackageName_;
std::string JsonParam_;
};
} // namespace DistributedHardware
diff --git a/display/README_zh.md b/display/README_zh.md
new file mode 100644
index 0000000000000000000000000000000000000000..4d2c7a6e71034cc682980175f17ab01b0c8dd986
--- /dev/null
+++ b/display/README_zh.md
@@ -0,0 +1,28 @@
+# 设备管理交互
+
+- [简介](#section11660541593)
+ - [交互](#section78574815486)
+
+- [目录](#section161941989596)
+
+## 简介
+
+为设备管理提供用户交互功能。
+
+### 交互
+
+主控端pin码输入、被控端授权(资源流转/FA流转)、被控端pin码展示。
+
+## 目录
+
+```
+/
+├── entry # 主Ability
+│ └── src
+│ └── main
+│ ├── config.json # 全局配置文件
+│ ├── js # js代码目录
+│ └── resources # 资源配置文件存放目录
+├── interface # 接口文件
+├── signature # 证书文件目录
+```
diff --git a/display/build.gradle b/display/build.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..151e80b67a03ddf9df7f7f3ad9e78826244b994c
--- /dev/null
+++ b/display/build.gradle
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+ // Top-level build file where you can add configuration options common to all sub-projects/modules.
+apply plugin: 'com.huawei.ohos.app'
+
+ohos {
+ compileSdkVersion 6
+ defaultConfig {
+ compatibleSdkVersion 6
+ }
+}
+
+buildscript {
+ repositories {
+ maven {
+ url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
+ }
+ maven {
+ url 'https://mirrors.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.huawei.ohos:hap:2.4.4.3-RC'
+ }
+}
+
+allprojects {
+ repositories {
+ maven {
+ url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
+ }
+ maven {
+ url 'https://mirrors.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
+ jcenter()
+ }
+}
\ No newline at end of file
diff --git a/display/entry/build.gradle b/display/entry/build.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..1f560cd47c2b0a5ce96a574a892a6d06ceb4e6f9
--- /dev/null
+++ b/display/entry/build.gradle
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+ apply plugin: 'com.huawei.ohos.hap'
+apply plugin: 'com.huawei.ohos.decctest'
+//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
+ohos {
+ compileSdkVersion 6
+ defaultConfig {
+ compatibleSdkVersion 6
+ }
+ buildTypes {
+ release {
+ proguardOpt {
+ proguardEnabled false
+ rulesFiles 'proguard-rules.pro'
+ }
+ }
+ }
+
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
+ testImplementation 'junit:junit:4.13'
+ ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.200'
+}
+decc {
+ supportType = ['html', 'xml']
+}
diff --git a/display/entry/src/main/config.json b/display/entry/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..af3dfe5c6aac83feb599f0c2e4ebf86fdaaafda6
--- /dev/null
+++ b/display/entry/src/main/config.json
@@ -0,0 +1,60 @@
+{
+ "app": {
+ "bundleName": "com.ohos.devicemanagerui",
+ "vendor": "ohos",
+ "version": {
+ "code": 1000000,
+ "name": "1.0.0"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "com.ohos.devicemanagerui",
+ "name": ".MyApplication",
+ "mainAbility": "com.ohos.devicemanagerui.MainAbility",
+ "deviceType": [
+ "phone",
+ "tablet",
+ "tv",
+ "wearable"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "entry",
+ "moduleType": "entry",
+ "installationFree": false
+ },
+ "abilities": [
+ {
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home"
+ ]
+ }
+ ],
+ "name": "com.ohos.devicemanagerui.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "$string:entry_MainAbility",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ],
+ "js": [
+ {
+ "pages": [
+ "pages/index/index"
+ ],
+ "name": "default",
+ "window": {
+ "designWidth": 720,
+ "autoDesignWidth": true
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/default/app.js b/display/entry/src/main/js/default/app.js
new file mode 100644
index 0000000000000000000000000000000000000000..8e47afff13e928a74fdcc01a108e4422404b9ac9
--- /dev/null
+++ b/display/entry/src/main/js/default/app.js
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021 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 {
+ onCreate() {
+ console.info('AceApplication onCreate');
+ },
+ onDestroy() {
+ console.info('AceApplication onDestroy');
+ }
+};
diff --git a/display/entry/src/main/js/default/i18n/en-US.json b/display/entry/src/main/js/default/i18n/en-US.json
new file mode 100644
index 0000000000000000000000000000000000000000..9e520910199bb533ab191d0c00063c4b4ce97fe9
--- /dev/null
+++ b/display/entry/src/main/js/default/i18n/en-US.json
@@ -0,0 +1,4 @@
+{
+ "strings": {
+ }
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/default/i18n/zh-CN.json b/display/entry/src/main/js/default/i18n/zh-CN.json
new file mode 100644
index 0000000000000000000000000000000000000000..9e520910199bb533ab191d0c00063c4b4ce97fe9
--- /dev/null
+++ b/display/entry/src/main/js/default/i18n/zh-CN.json
@@ -0,0 +1,4 @@
+{
+ "strings": {
+ }
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/default/pages/index/index.css b/display/entry/src/main/js/default/pages/index/index.css
new file mode 100644
index 0000000000000000000000000000000000000000..13230219750e97e15bf1d33645ec471e4ca41e60
--- /dev/null
+++ b/display/entry/src/main/js/default/pages/index/index.css
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+.container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ opacity: 0.8;
+ background-color: azure;
+}
+
+.container > div {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+}
+
+.main-pin > .pin-numb {
+ flex-direction: row;
+ justify-content: space-around;
+ align-items: center;
+ padding: 15px 30px 10px 30px;
+}
+.main-pin > .pin-numb > .pin-numb-item {
+ font-size: 30px;
+ line-height: 30px;
+ height: 40px;
+ padding-bottom: 5px;
+ font-weight: 800;
+ width: 30px;
+ border-bottom-width: 2px;
+ border-bottom-color: darkgray;
+ text-align: center;
+}
+
+.main-pin > .input {
+ flex-direction: row;
+ justify-content: space-around;
+ align-items: center;
+ padding: 5px 30px 5px 30px;
+}
+
+.main-pin > .input > .numb {
+ text-color: black;
+ padding: 5px;
+ flex-shrink: 0;
+ flex-basis: 60px;
+ background-color: white;
+ border: 1px;
+}
+
+.join-auth {
+ padding-top: 30px;
+}
+.join-auth-image > image {
+ height: 170px;
+}
+.join-authorize {
+ padding-top: 10px;
+}
+.join-pin {
+ padding: 10px 0;
+}
+.join-pin > .pin {
+ font-size: 50px;
+ line-height: 90px;
+ font-weight: bolder;
+ color: #000000;
+}
+
+.join-auth > .title,
+.join-auth-image > .title,
+.join-authorize > .title {
+ font-size: 18px;
+ line-height: 80px;
+ font-weight: 800;
+ color: #000000;
+}
+.join-auth > .title {
+ line-height: 40px;
+}
+.join-auth-image > .title {
+ line-height: 26px;
+}
+.join-pin > .title {
+ font-size: 28px;
+ line-height: 60px;
+ font-weight: 800;
+}
+.main-pin > .title {
+ font-size: 30px;
+ line-height: 40px;
+ font-weight: bolder;
+}
+
+.join-auth > .title-tip,
+.join-auth-image > .title-tip,
+.main-pin > .title-tip,
+.join-authorize > .title-tip {
+ font-size: 15px;
+ line-height: 40px;
+ color: #5A5A5A;
+}
+.join-auth > .title-tip {
+ line-height: 40px;
+}
+.join-auth-image > .title-tip {
+ line-height: 24px;
+}
+.join-pin > .title-tip {
+ font-size: 20px;
+ line-height: 50px;
+ font-weight: 600;
+}
+.main-pin > .title-tip {
+ font-size: 18px;
+ line-height: 30px;
+ font-weight: 800;
+}
+
+.join-auth > .dialog-foot,
+.join-auth-image > .dialog-foot,
+.join-authorize > .dialog-foot {
+ flex-direction: row;
+ justify-content: center;
+ align-items: center;
+ justify-content: space-around;
+ margin: 80px 20px 30px 20px;
+}
+.join-authorize > .dialog-foot {
+ margin: 100px 20px 30px 20px;
+}
+.join-auth-image > .dialog-foot {
+ margin: 10px 20px 10px 20px;
+}
+.join-pin > .dialog-foot {
+ margin: 10px 20px 10px 20px;
+}
+
+.join-auth .button-cancel,
+.join-auth-image .button-cancel,
+.join-authorize .button-cancel {
+ width: 160px;
+ height: 36px;
+}
+.join-pin .button-cancel {
+ width: 100%;
+ font-size: 26px;
+ height: 50px;
+}
+
+.join-auth .button-ok,
+.join-auth-image .button-ok,
+.join-authorize .button-ok {
+ width: 150px;
+ height: 36px;
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/default/pages/index/index.hml b/display/entry/src/main/js/default/pages/index/index.hml
new file mode 100644
index 0000000000000000000000000000000000000000..7f388b21204e991f72ba51fe0b3f3a1c6d668d46
--- /dev/null
+++ b/display/entry/src/main/js/default/pages/index/index.hml
@@ -0,0 +1,98 @@
+
+
+
+
+
PIN码连接
+
请输入平板上显示的PIN码
+
+ {{pin[0]}}
+ {{pin[1]}}
+ {{pin[2]}}
+ {{pin[3]}}
+ {{pin[4]}}
+ {{pin[5]}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 是否允许{{statusInfo.deviceName}}连接本机
+ 用于资源访问
+
+
+
+ {{ statusInfo.appName }}
+ 是否允许打开apply auth?
+ 来自{{statusInfo.deviceName}}
+
+
+
+
+ {{ statusInfo.appName }}
+ 是否允许打开apply auth?
+ 来自{{statusInfo.deviceName}}
+
+
+
+ PIN码连接
+ 请在主控端输入连接码进行验证
+ {{statusInfo.pinCode.split('').join(' ')}}
+
+
+
diff --git a/display/entry/src/main/js/default/pages/index/index.js b/display/entry/src/main/js/default/pages/index/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..0304a8d5277a1108e143e24b9af20c91fd2f580f
--- /dev/null
+++ b/display/entry/src/main/js/default/pages/index/index.js
@@ -0,0 +1,331 @@
+/*
+ * Copyright (c) 2021 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 router from '@system.router';
+import deviceManager from '@ohos.distributedHardware.deviceManager';
+function uint8ArrayToBase64(array) {
+ array = new Uint8Array(array);
+ let table = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'],
+ base64Str = '', length = array.byteLength, i = 0;
+ for(i = 0; length - i >= 3; i += 3) {
+ let num1 = array[i], num2 = array[i + 1], num3 = array[i + 2];
+ base64Str += table[num1 >>> 2] + table[((num1 & 0b11) << 4) | (num2 >>> 4)] + table[((num2 & 0b1111) << 2) | (num3 >>> 6)] + table[num3 & 0b111111];
+ }
+ const lastByte = length - i;
+ if (lastByte === 1) {
+ const lastNum1 = array[i];
+ base64Str += table[lastNum1 >>> 2] + table[((lastNum1 & 0b11) << 4)] + '==';
+ } else if (lastByte === 2) {
+ const lastNum1 = array[i];
+ const lastNum2 = array[i + 1];
+ base64Str += table[lastNum1 >>> 2] + table[((lastNum1 & 0b11) << 4) | (lastNum2 >>> 4)] + table[(lastNum2 & 0b1111) << 2] + '=';
+ }
+ return 'data:image/png;base64,' + base64Str;
+}
+const TAG = "DeviceManagerUI:";
+let dmClass;
+
+export default {
+ data: {
+ // showType: ['main-pin','join-authorize','join-auth','join-auth-image','join-pin']
+ status: "",
+ // showInfo
+ statusInfo: {
+ deviceName: "AppName",
+ appName: 'PackageName',
+ appIcon: null,
+ pinCode: '',
+ pinToken: ''
+ },
+ // join: join-authorize timing
+ timeRemaining: 0,
+ // input pinCode
+ pin: ['','','','','',''],
+ // input pinCode next number
+ pinNumb: 0
+ },
+
+ log(m) {
+ console.info(TAG + m);
+ },
+
+ onDestroy() {
+ if (dmClass != null) {
+ dmClass.off('dmFaCallback');
+ dmClass.off('deviceStateChange');
+ dmClass.off('serviceDie');
+ dmClass.release();
+ dmClass = null
+ }
+ },
+
+ onShow() {
+ if (dmClass) {
+ this.initStatue()
+ } else {
+ this.log('createDeviceManager')
+ deviceManager.createDeviceManager('com.ohos.devicemanagerui', (err, dm) => {
+ this.log("createDeviceManager err:" + JSON.stringify(err) + ' --success:' + JSON.stringify(dm))
+ if (err) return;
+ dmClass = dm;
+ dmClass.on('dmFaCallback', () => router.back())
+ this.initStatue()
+ });
+ }
+ },
+
+ onHide() {
+ this.timeRemaining = 0
+ },
+
+ /**
+ * Get authentication param
+ */
+ initStatue() {
+ this.log('initStatue')
+ const data = dmClass.getAuthenticationParam()
+ this.log('getAuthenticationParam:' + JSON.stringify(data))
+ // Authentication type, 1 for pin code.
+ if (data && data.authType == 1) {
+ this.statusInfo = {
+ deviceName: data.extraInfo.PackageName,
+ appName: data.extraInfo.appName,
+ appIcon: uint8ArrayToBase64(data.appIcon),
+ pinCode: data.extraInfo.pinCode + '',
+ pinToken: data.extraInfo.pinToken
+ }
+ // direction: 1(main)/0(join)
+ if (data.extraInfo.direction == 1) {
+ this.mainPin()
+ } else if (data.appIcon) {
+ this.joinAuthImage()
+ } else if (data.extraInfo.business == 0) {
+ // business: 0(FA流转)/1(资源访问)
+ this.joinAuth()
+ } else {
+ this.joinAuthorize()
+ }
+ }
+ },
+
+ /**
+ * Set user Operation from devicemanager Fa, this interface can only used by devicemanager Fa.
+ *
+ * @param operateAction User Operation Actions.
+ * ACTION_ALLOW_AUTH = 0, allow authentication
+ * ACTION_CANCEL_AUTH = 1, cancel authentication
+ * ACTION_AUTH_CONFIRM_TIMEOUT = 2, user operation timeout for authentication confirm
+ * ACTION_CANCEL_PINCODE_DISPLAY = 3, cancel pinCode display
+ * ACTION_CANCEL_PINCODE_INPUT = 4, cancel pinCode input
+ */
+ setUserOperation(operation) {
+ this.log('setUserOperation: ' + operation)
+ if (dmClass != null) {
+ var data = dmClass.setUserOperation(operation);
+ this.log('setUserOperation result: ' + JSON.stringify(data))
+ } else {
+ this.log('deviceManagerObject not exit')
+ }
+ },
+
+ /**
+ * verify auth info, such as pin code.
+ * @param pinCode
+ * @return
+ */
+ verifyAuthInfo(pinCode) {
+ this.log('verifyAuthInfo: ' + pinCode)
+ if (dmClass != null) {
+ dmClass.verifyAuthInfo({
+ "authType": 1,
+ "token": this.statusInfo.pinToken,
+ "extraInfo": {
+ "pinCode": +pinCode
+ }
+ }, (err, data) => {
+ if (err) {
+ this.log("verifyAuthInfo err:" + JSON.stringify(err))
+ }
+ this.log("verifyAuthInfo result:" + JSON.stringify(data))
+ router.back()
+ });
+ } else {
+ this.log('deviceManagerObject not exit')
+ }
+ },
+
+ /**
+ * Input pinCode at the main control terminal
+ */
+ mainPin() {
+ this.status = 'main-pin'
+ },
+
+ /**
+ * Enter a number with the keyboard
+ * @param s
+ * @return
+ */
+ mainInputPin(s) {
+ this.log('mainInputPin input: ' + s + '-' + this.pin)
+ if (this.pinNumb == 6) return
+ if (this.pinNumb < 6) {
+ this.pin[this.pinNumb] = s
+ ++this.pinNumb
+ this.pin = [...this.pin]
+ }
+ this.log('mainInputPin pin: ' + this.pin + '-' + this.pin.join(''))
+ if (this.pinNumb == 6) {
+ // input end
+ this.log('mainInputPin end: ' + this.pin + '-' + this.pin.join(''))
+ this.verifyAuthInfo(this.pin.join(''))
+ }
+ },
+
+ /**
+ * Keyboard delete number
+ */
+ mainInputPinBack() {
+ if (this.pinNumb > 0) {
+ --this.pinNumb
+ this.pin[this.pinNumb] = ''
+ this.pin = [...this.pin]
+ }
+ },
+
+ /**
+ * Cancel pinCode input
+ */
+ mainInputPinCancel() {
+ this.setUserOperation(4)
+ },
+
+ /**
+ * Join end authorization, business(FA流转)/1(资源访问): 0
+ */
+ joinAuthorize() {
+ this.status = 'join-authorize'
+ this.timing(60, 'join-authorize', () => {
+ this.setUserOperation(2)
+ router.back()
+ })
+ },
+
+ /**
+ * Join end authorization, business(FA流转)/1(资源访问): 1
+ */
+ joinAuth() {
+ this.status = 'join-auth'
+ this.timing(60, 'join-auth', () => {
+ this.setUserOperation(2)
+ router.back()
+ })
+ },
+
+ /**
+ * Join end authorization, business(FA流转)/1(资源访问): 1, show application icon
+ */
+ joinAuthImage() {
+ this.status = 'join-auth-image'
+ this.timing(60, 'join-auth-image', () => {
+ this.setUserOperation(2)
+ router.back()
+ })
+ },
+
+ /**
+ * Display pinCode at join end
+ */
+ joinPin() {
+ this.status = 'join-pin'
+ },
+
+ /**
+ * Cancel authorization
+ */
+ joinAuthorizeCancel() {
+ this.setUserOperation(1)
+ router.back()
+ },
+
+ /**
+ * Confirm authorization
+ */
+ joinAuthorizeOk() {
+ this.setUserOperation(0)
+ this.joinPin()
+ },
+
+ /**
+ * Cancel authorization
+ */
+ joinAuthCancel() {
+ this.setUserOperation(1)
+ router.back()
+ },
+
+ /**
+ * Confirm authorization
+ */
+ joinAuthOk() {
+ this.setUserOperation(0)
+ this.joinPin()
+ },
+
+ /**
+ * Cancel authorization
+ */
+ joinAuthImageCancel() {
+ this.setUserOperation(1)
+ router.back()
+ },
+
+ /**
+ * Confirm authorization
+ */
+ joinAuthImageOk() {
+ this.setUserOperation(0)
+ this.joinPin()
+ },
+
+ /**
+ * Cancel authorization
+ */
+ joinPinCancel() {
+ this.setUserOperation(3)
+ router.back()
+ },
+
+ /**
+ * Pure function countdown
+ * @param numb second
+ * @param status
+ * @param callback
+ * @return
+ */
+ timing(numb, status, callback) {
+ this.timeRemaining = numb
+ const next = () => {
+ if (status != this.status) return
+ --this.timeRemaining
+ if (this.timeRemaining > 0) {
+ setTimeout(next, 1000)
+ } else {
+ callback()
+ }
+ }
+ next()
+ }
+}
diff --git a/display/entry/src/main/resources/base/element/string.json b/display/entry/src/main/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..0bae6bd40f7360d5d818998221b199d3ec0f69c0
--- /dev/null
+++ b/display/entry/src/main/resources/base/element/string.json
@@ -0,0 +1,12 @@
+{
+ "string": [
+ {
+ "name": "entry_MainAbility",
+ "value": "entry_MainAbility"
+ },
+ {
+ "name": "mainability_description",
+ "value": "JS_Empty Ability"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/display/entry/src/main/resources/base/media/icon.png b/display/entry/src/main/resources/base/media/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/display/entry/src/main/resources/base/media/icon.png differ
diff --git a/display/settings.gradle b/display/settings.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07
--- /dev/null
+++ b/display/settings.gradle
@@ -0,0 +1 @@
+include ':entry'
diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h
index 5b8572dbf534eb9e1ad48c40d5d8e60f599385e9..96f507d8175d874c31111ee4fea2749b992cddd5 100644
--- a/interfaces/inner_kits/native_cpp/include/device_manager.h
+++ b/interfaces/inner_kits/native_cpp/include/device_manager.h
@@ -27,7 +27,7 @@ namespace OHOS {
namespace DistributedHardware {
class DeviceManager {
public:
- static DeviceManager& GetInstance();
+ static DeviceManager &GetInstance();
public:
virtual int32_t InitDeviceManager(std::string &pkgName, std::shared_ptr dmInitCallback) = 0;
virtual int32_t UnInitDeviceManager(std::string &pkgName) = 0;
diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h
index a8ea7fb6a525368526febc02bc9a580f47aa42f7..786e8ca850fc4f068c007bfa59dd0a9a664009ca 100644
--- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h
+++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h
@@ -60,7 +60,7 @@ public:
class DeviceManagerFaCallback {
public:
- virtual ~DeviceManagerFaCallback(){}
+ virtual ~DeviceManagerFaCallback() {}
virtual void OnCall(std::string ¶mJson) = 0;
};
} // namespace DistributedHardware
diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h
index d49118a88f80b9a2a5b5c18aac532fa7c759ab6e..a22cae427d621f13594cc9a550f82716ce326a90 100644
--- a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h
+++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h
@@ -65,7 +65,7 @@ private:
std::map> deviceStateCallback_;
std::map>> deviceDiscoverCallbacks_;
std::map>> authenticateCallback_;
- std::map>> checkauthcallback_;
+ std::map> checkauthcallback_;
std::map> dmInitCallback_;
std::map> dmFaCallback_;
};
diff --git a/interfaces/inner_kits/native_cpp/src/device_manager.cpp b/interfaces/inner_kits/native_cpp/src/device_manager.cpp
index baececb7b1ffadaf5c2b595873a5b54dd1128fd1..4bedc0a57c5f4e940be45cea53e9c6db7b95a1f7 100644
--- a/interfaces/inner_kits/native_cpp/src/device_manager.cpp
+++ b/interfaces/inner_kits/native_cpp/src/device_manager.cpp
@@ -19,7 +19,7 @@
namespace OHOS {
namespace DistributedHardware {
-DeviceManager& DeviceManager::GetInstance()
+DeviceManager &DeviceManager::GetInstance()
{
return DeviceManagerImpl::GetInstance();
}
diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp
index 9ae99e19ad64562299b40306c2629e6927d14cdd..c24231546ac2c9e70a85d6dead2751dcdec04a64 100644
--- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp
+++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp
@@ -36,8 +36,12 @@ static int32_t ClientIpcInterfaceMsgHandle(const IpcContext *ctx, void *ipcMsg,
uint32_t code = 0;
GetCode(ipcMsg, &code);
- DMLOG(DM_LOG_INFO, "receive ipc transact code(%u)", code);
- return IpcCmdRegister::GetInstance().OnIpcCmd(code, *io, *ctx, ipcMsg);
+ int32_t errCode = DEVICEMANAGER_OK;
+
+ errCode = IpcCmdRegister::GetInstance().OnIpcCmd(code, *io, *ctx, ipcMsg);
+ DMLOG(DM_LOG_INFO, "receive ipc transact code:%u, retCode=%d", code, errCode);
+ FreeBuffer(ctx, ipcMsg);
+ return errCode;
}
int32_t IpcClientStub::Init()
diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp
index 79dc594be56cfba0f8237e5200ea8797163d6000..1ae50f777fa1dc15205c1fdb49d1ee5821b4bf30 100644
--- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp
+++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp
@@ -16,6 +16,8 @@
#include "ipc_cmd_register.h"
#include "ipc_def.h"
+#include "securec.h"
+#include "constants.h"
#include "device_manager_errno.h"
#include "device_manager_log.h"
#include "device_manager_notify.h"
@@ -30,6 +32,8 @@
#include "ipc_get_trustdevice_rsp.h"
#include "ipc_authenticate_device_req.h"
#include "ipc_check_authenticate_req.h"
+#include "ipc_get_authenticationparam_rsp.h"
+#include "ipc_set_useroperation_req.h"
namespace OHOS {
namespace DistributedHardware {
@@ -191,7 +195,6 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply, const IpcContext &ctx, void
const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size);
if (pkgName == "" || len == 0 || deviceInfo == NULL) {
DMLOG(DM_LOG_ERROR, "OnDeviceOnline, get para failed");
- FreeBuffer(&ctx, ipcMsg);
return;
}
switch (deviceState) {
@@ -208,7 +211,6 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply, const IpcContext &ctx, void
DMLOG(DM_LOG_ERROR, "unknown device state:%d", deviceState);
break;
}
- FreeBuffer(&ctx, ipcMsg);
}
ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply, const IpcContext &ctx, void *ipcMsg)
@@ -220,11 +222,9 @@ ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply, const IpcContext &ctx, void *ipcMs
const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size);
if (pkgName == "" || len == 0 || deviceInfo == NULL) {
DMLOG(DM_LOG_ERROR, "OnDeviceChanged, get para failed");
- FreeBuffer(&ctx, ipcMsg);
return;
}
DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, *deviceInfo);
- FreeBuffer(&ctx, ipcMsg);
}
ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ipcMsg)
@@ -236,7 +236,6 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ip
if (pkgName == "" || len == 0) {
DMLOG(DM_LOG_ERROR, "OnDiscoverySuccess, get para failed");
- FreeBuffer(&ctx, ipcMsg);
return;
}
if (failedReason == DEVICEMANAGER_OK) {
@@ -244,7 +243,6 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ip
} else {
DeviceManagerNotify::GetInstance().OnDiscoverFailed(pkgName, subscribeId, failedReason);
}
- FreeBuffer(&ctx, ipcMsg);
}
ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg)
@@ -259,11 +257,9 @@ ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg
if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) {
DMLOG(DM_LOG_ERROR, "OnAuthResult, get para failed");
- FreeBuffer(&ctx, ipcMsg);
return;
}
DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, pinToken, status, reason);
- FreeBuffer(&ctx, ipcMsg);
}
ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg)
@@ -277,10 +273,86 @@ ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *
if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) {
DMLOG(DM_LOG_ERROR, "OnAuthResult, get para failed");
- FreeBuffer(&ctx, ipcMsg);
return;
}
DeviceManagerNotify::GetInstance().OnCheckAuthResult(pkgName, deviceId, resultCode, flag);
+}
+
+ON_IPC_SET_REQUEST(SERVER_GET_AUTHENTCATION_INFO, std::shared_ptr pBaseReq, IpcIo& request,
+ uint8_t *buffer, size_t buffLen)
+{
+ std::shared_ptr pReq = std::static_pointer_cast(pBaseReq);
+ std::string packagename = pReq->GetPkgName();
+
+ IpcIoInit(&request, buffer, buffLen, 0);
+ IpcIoPushString(&request, packagename.c_str());
+ return DEVICEMANAGER_OK;
+}
+
+ON_IPC_READ_RESPONSE(SERVER_GET_AUTHENTCATION_INFO, IpcIo& reply, std::shared_ptr pBaseRsp)
+{
+ std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp);
+ DmAuthParam authParam = {0};
+ authParam.direction = IpcIoPopInt32(&reply);
+ authParam.authType = IpcIoPopInt32(&reply);
+ if (authParam.direction == AUTH_SESSION_SIDE_CLIENT) {
+ authParam.pinToken = IpcIoPopInt32(&reply);
+ pRsp->SetAuthParam(authParam);
+ return DEVICEMANAGER_OK;
+ }
+ size_t PackagerNamelen = 0;
+ authParam.packageName = strdup((const char *)IpcIoPopString(&reply, &PackagerNamelen));
+ size_t appNameLen = 0;
+ authParam.appName = strdup((const char *)IpcIoPopString(&reply, &appNameLen));
+ size_t appDesLen = 0;
+ authParam.appDescription = strdup((const char *)IpcIoPopString(&reply, &appDesLen));
+ authParam.business = IpcIoPopInt32(&reply);
+ authParam.pincode = IpcIoPopInt32(&reply);
+
+ uint32_t appIconLen = IpcIoPopInt32(&reply);
+ uint8_t *appIconBuffer = nullptr;
+ uint32_t appThumbnailLen = IpcIoPopInt32(&reply);
+ uint8_t *appThumbBuffer = nullptr;
+
+ if (appIconLen > 0) {
+ appIconBuffer = (uint8_t *)IpcIoPopFlatObj(&reply, &appIconLen);
+ }
+ if (appThumbnailLen > 0) {
+ appThumbBuffer = (uint8_t *)IpcIoPopFlatObj(&reply, &appThumbnailLen);
+ }
+
+ authParam.imageinfo.Reset(appIconBuffer, appIconLen, appThumbBuffer, appThumbnailLen);
+ pRsp->SetAuthParam(authParam);
+ return DEVICEMANAGER_OK;
+}
+
+ON_IPC_SET_REQUEST(SERVER_USER_AUTHORIZATION_OPERATION, std::shared_ptr pBaseReq, IpcIo& request,
+ uint8_t *buffer, size_t buffLen)
+{
+ std::shared_ptr pReq = std::static_pointer_cast(pBaseReq);
+ std::string pkgName= pReq->GetPkgName();
+ int32_t action = pReq->GetOperation();
+
+ IpcIoInit(&request, buffer, buffLen, 0);
+ IpcIoPushString(&request, pkgName.c_str());
+ IpcIoPushInt32(&request, action);
+ return DEVICEMANAGER_OK;
+}
+
+ON_IPC_READ_RESPONSE(SERVER_USER_AUTHORIZATION_OPERATION, IpcIo& reply, std::shared_ptr pBaseRsp)
+{
+ pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
+ return DEVICEMANAGER_OK;
+}
+
+ON_IPC_CMD(SERVER_DEVICEMANAGER_FA_NOTIFY, IpcIo &reply, const IpcContext &ctx, void *ipcMsg)
+{
+ size_t len = 0;
+ std::string packagename = (const char *)IpcIoPopString(&reply, &len);
+ size_t jsonLen = 0;
+ std::string paramJson = (const char *)IpcIoPopString(&reply, &jsonLen);
+ DeviceManagerNotify::GetInstance().OnFaCall(packagename, paramJson);
+ IpcIoPushInt32(&reply, DEVICEMANAGER_OK);
FreeBuffer(&ctx, ipcMsg);
}
} // namespace DistributedHardware
diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp
index 88217e1bdb3b46a853798da114819cb9d67c1b54..45b3f02a9f164d369ebd9a34f07e51e4f913558b 100644
--- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp
+++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp
@@ -101,7 +101,7 @@ ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_pt
pRsp->SetErrCode(DEVICEMANAGER_IPC_TRANSACTION_FAILED);
return DEVICEMANAGER_IPC_TRANSACTION_FAILED;
}
- for (int32_t i = 0; i < deviceTotalSize; ++i) {
+ for (int32_t i = 0; i < deviceNum; ++i) {
pDmDeviceinfo = pDmDeviceinfo + i;
deviceInfoVec.emplace_back(*pDmDeviceinfo);
}
@@ -303,7 +303,7 @@ ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, MessageParcel &data, MessageParcel &reply)
return DEVICEMANAGER_OK;
}
-ON_IPC_SET_REQUEST(SERVER_GET_AUTHENTCATION_INFO, std::shared_ptr pBaseReq, MessageParcel& data)
+ON_IPC_SET_REQUEST(SERVER_GET_AUTHENTCATION_INFO, std::shared_ptr pBaseReq, MessageParcel &data)
{
std::shared_ptr pReq = std::static_pointer_cast(pBaseReq);
std::string packagename = pReq->GetPkgName();
@@ -314,7 +314,7 @@ ON_IPC_SET_REQUEST(SERVER_GET_AUTHENTCATION_INFO, std::shared_ptr pBaseR
return DEVICEMANAGER_OK;
}
-ON_IPC_READ_RESPONSE(SERVER_GET_AUTHENTCATION_INFO, MessageParcel& reply, std::shared_ptr pBaseRsp)
+ON_IPC_READ_RESPONSE(SERVER_GET_AUTHENTCATION_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp)
{
std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp);
DmAuthParam authParam;
@@ -347,7 +347,7 @@ ON_IPC_READ_RESPONSE(SERVER_GET_AUTHENTCATION_INFO, MessageParcel& reply, std::s
return DEVICEMANAGER_OK;
}
-ON_IPC_SET_REQUEST(SERVER_USER_AUTHORIZATION_OPERATION, std::shared_ptr pBaseReq, MessageParcel& data)
+ON_IPC_SET_REQUEST(SERVER_USER_AUTHORIZATION_OPERATION, std::shared_ptr pBaseReq, MessageParcel &data)
{
std::shared_ptr pReq = std::static_pointer_cast(pBaseReq);
std::string pkgName = pReq->GetPkgName();
@@ -365,7 +365,7 @@ ON_IPC_SET_REQUEST(SERVER_USER_AUTHORIZATION_OPERATION, std::shared_ptr
return DEVICEMANAGER_OK;
}
-ON_IPC_READ_RESPONSE(SERVER_USER_AUTHORIZATION_OPERATION, MessageParcel& reply, std::shared_ptr pBaseRsp)
+ON_IPC_READ_RESPONSE(SERVER_USER_AUTHORIZATION_OPERATION, MessageParcel &reply, std::shared_ptr pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DEVICEMANAGER_OK;
diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp
index 4144e3ac6030defbf74d06bb1457f6968258642e..94f03d156c6ebb0bf6af5ede84182ed7a19389fc 100644
--- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp
+++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp
@@ -106,19 +106,12 @@ void DeviceManagerNotify::RegisterCheckAuthenticationCallback(std::string &pkgNa
std::shared_ptr callback)
{
std::lock_guard autoLock(lock_);
- if (checkauthcallback_.count(pkgName) == 0) {
- checkauthcallback_[pkgName] = std::map>();
- }
- checkauthcallback_[pkgName][authPara] = callback;
+ checkauthcallback_[pkgName] = callback;
}
void DeviceManagerNotify::UnRegisterCheckAuthenticationCallback(std::string &pkgName)
{
std::lock_guard autoLock(lock_);
- deviceStateCallback_.erase(pkgName);
- deviceDiscoverCallbacks_.erase(pkgName);
- authenticateCallback_.erase(pkgName);
- dmInitCallback_.erase(pkgName);
checkauthcallback_.erase(pkgName);
}
@@ -187,7 +180,7 @@ void DeviceManagerNotify::OnDeviceFound(std::string &pkgName, uint16_t subscribe
DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceFound: no register discoverCallback for this package");
return;
}
- std::map>& discoverCallMap = deviceDiscoverCallbacks_[pkgName];
+ std::map> &discoverCallMap = deviceDiscoverCallbacks_[pkgName];
auto iter = discoverCallMap.find(subscribeId);
if (iter == discoverCallMap.end()) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceFound: no register discoverCallback for subscribeId %d",
@@ -206,7 +199,7 @@ void DeviceManagerNotify::OnDiscoverFailed(std::string &pkgName, uint16_t subscr
DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverFailed: no register discoverCallback for this package");
return;
}
- std::map>& discoverCallMap = deviceDiscoverCallbacks_[pkgName];
+ std::map> &discoverCallMap = deviceDiscoverCallbacks_[pkgName];
auto iter = discoverCallMap.find(subscribeId);
if (iter == discoverCallMap.end()) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverFailed: no register discoverCallback for subscribeId %d",
@@ -225,7 +218,7 @@ void DeviceManagerNotify::OnDiscoverySuccess(std::string &pkgName, uint16_t subs
DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverySuccess: no register discoverCallback for this package");
return;
}
- std::map>& discoverCallMap = deviceDiscoverCallbacks_[pkgName];
+ std::map> &discoverCallMap = deviceDiscoverCallbacks_[pkgName];
auto iter = discoverCallMap.find(subscribeId);
if (iter == discoverCallMap.end()) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverySuccess: no register discoverCallback for subscribeId %d",
@@ -245,7 +238,7 @@ void DeviceManagerNotify::OnAuthResult(std::string &pkgName, std::string &device
DMLOG(DM_LOG_ERROR, "DeviceManager OnAuthResult: no register authCallback for this package");
return;
}
- std::map>& authCallMap = authenticateCallback_[pkgName];
+ std::map> &authCallMap = authenticateCallback_[pkgName];
auto iter = authCallMap.find(deviceId);
if (iter == authCallMap.end()) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnAuthResult: no register authCallback for deviceID ");
@@ -268,17 +261,9 @@ void DeviceManagerNotify::OnCheckAuthResult(std::string &pkgName, std::string &d
DMLOG(DM_LOG_ERROR, "DeviceManager OnCheckAuthResult: no register authCallback for this package");
return;
}
- std::map>& CheckAuthCallmap = checkauthcallback_[pkgName];
- auto iter = CheckAuthCallmap.find(deviceId);
- if (iter == CheckAuthCallmap.end()) {
- DMLOG(DM_LOG_ERROR, "DeviceManager OnCheckAuthResult: no register CheckAuthCallmap for deviceID");
- return;
- }
- iter->second->OnCheckAuthResult(deviceId, resultCode, flag);
- checkauthcallback_[pkgName].erase(deviceId);
- if (checkauthcallback_[pkgName].empty()) {
- checkauthcallback_.erase(pkgName);
- }
+
+ checkauthcallback_[pkgName]->OnCheckAuthResult(deviceId, resultCode, flag);
+ checkauthcallback_.erase(pkgName);
}
void DeviceManagerNotify::OnFaCall(std::string &pkgName, std::string ¶mJson)
diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn
index 5c67772074611715ef11ffe03784a1318d1b537c..b82cf50ab0c1d97895fad10b1e26d8bcd3635dc4 100644
--- a/interfaces/kits/js/BUILD.gn
+++ b/interfaces/kits/js/BUILD.gn
@@ -11,58 +11,115 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import("//build/ohos.gni")
+if (defined(ohos_lite)) {
+ import("//build/lite/config/component/lite_component.gni")
+} else {
+ import("//build/ohos.gni")
+}
import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
-ohos_shared_library("devicemanager") {
- include_dirs = [
- "//third_party/node/src",
- "//third_party/json/include",
- "${common_path}/include",
- "//foundation/ace/napi/native_engine",
- "//foundation/ace/napi/interfaces/kits",
- "//utils/native/base/include",
- "include",
- "${utils_path}/include/log",
- "${common_path}/include/ipc",
- "${innerkits_path}/native_cpp/include",
- "${innerkits_path}/native_cpp/include/standard",
- ]
+if (defined(ohos_lite)) {
+ shared_library("devicemanager") {
+ include_dirs = [
+ "//third_party/node/src",
+ "//third_party/json/include",
+ "${common_path}/include",
+ "//foundation/ace/napi/native_engine",
+ "//foundation/ace/napi/interfaces/kits",
+ "//utils/native/base/include",
+ "include",
+ "${utils_path}/include/log",
+ "${common_path}/include/ipc",
+ "${common_path}/include/ipc/model",
+ "${common_path}/include/ipc/lite",
+ "${innerkits_path}/native_cpp/include",
+ ]
+ include_dirs += [
+ "//utils/native/lite/include",
+ "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
+ "//third_party/bounds_checking_function/include",
+ "//foundation/communication/ipc_lite/interfaces/kits",
+ "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
+ ]
- sources = [
- "src/dm_native_event.cpp",
- "src/native_devicemanager_js.cpp",
- ]
+ sources = [
+ "src/dm_native_event.cpp",
+ "src/native_devicemanager_js.cpp",
+ ]
- deps = [
- "${utils_path}:devicemanagerutils",
- "//foundation/ace/napi:ace_napi",
- "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
- "//utils/native/base:utils",
- ]
+ deps = [
+ "${utils_path}:devicemanagerutils",
+ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
+ "//foundation/communication/ipc_lite:liteipc_adapter",
+ "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
+ "//foundation/distributedschedule/samgr_lite/samgr:samgr",
+ "//third_party/bounds_checking_function:libsec_shared",
+ "//utils/native/lite:utils",
+ ]
- cflags_cc = build_flags
+ cflags_cc = build_flags
- defines = [
- "HI_LOG_ENABLE",
- "DH_LOG_TAG=\"devicemanagerkit_js\"",
- "LOG_DOMAIN=0xD004100",
- ]
+ defines = [
+ "LITE_DEVICE",
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"devicemanagerkit_js\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+ }
+ group("devicemanager_native_js") {
+ deps = [ ":devicemanager" ]
+ }
+} else {
+ ohos_shared_library("devicemanager") {
+ include_dirs = [
+ "//third_party/node/src",
+ "//third_party/json/include",
+ "${common_path}/include",
+ "//foundation/ace/napi/native_engine",
+ "//foundation/ace/napi/interfaces/kits",
+ "//utils/native/base/include",
+ "include",
+ "${utils_path}/include/log",
+ "${common_path}/include/ipc",
+ "${innerkits_path}/native_cpp/include",
+ "${innerkits_path}/native_cpp/include/standard",
+ ]
- external_deps = [
- "appexecfwk_standard:appexecfwk_base",
- "appexecfwk_standard:appexecfwk_core",
- "hiviewdfx_hilog_native:libhilog",
- "ipc:ipc_core",
- "safwk:system_ability_fwk",
- "samgr_L2:samgr_proxy",
- ]
+ sources = [
+ "src/dm_native_event.cpp",
+ "src/native_devicemanager_js.cpp",
+ ]
- subsystem_name = "distributedhardware"
- relative_install_dir = "module/distributedhardware"
- part_name = "device_manager_base"
-}
+ deps = [
+ "${utils_path}:devicemanagerutils",
+ "//foundation/ace/napi:ace_napi",
+ "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
+ "//utils/native/base:utils",
+ ]
+
+ cflags_cc = build_flags
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"devicemanagerkit_js\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+ external_deps = [
+ "appexecfwk_standard:appexecfwk_base",
+ "appexecfwk_standard:appexecfwk_core",
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_L2:samgr_proxy",
+ ]
+
+ subsystem_name = "distributedhardware"
+ relative_install_dir = "module/distributedhardware"
+ part_name = "device_manager_base"
+ }
-group("devicemanager_native_js") {
- deps = [ ":devicemanager" ]
+ group("devicemanager_native_js") {
+ deps = [ ":devicemanager" ]
+ }
}
diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp
index 1120fa8054556b2decf7c35405e26f80e3312cf9..a555fc5828538984db65c5cc7c6aa189e7a8c7a3 100644
--- a/interfaces/kits/js/src/native_devicemanager_js.cpp
+++ b/interfaces/kits/js/src/native_devicemanager_js.cpp
@@ -49,6 +49,7 @@ const int32_t DM_AUTH_TYPE_PINCODE = 1;
const int32_t DM_AUTH_DIRECTION_CLIENT = 1;
const int32_t DM_NAPI_SUBSCRIBE_CAPABILITY_DDMP = 0;
+const int32_t DM_NAPI_SUBSCRIBE_CAPABILITY_OSD = 1;
std::map g_deviceManagerMap;
std::map> g_initCallbackMap;
@@ -389,9 +390,9 @@ void DeviceManagerNapi::DmAuthParamToJsAuthParamy(const napi_env &env,
void *appIcon = nullptr;
napi_value appIconBuffer = nullptr;
napi_create_arraybuffer(env, appIconLen, &appIcon, &appIconBuffer);
- int32_t ret = memcpy_s(appIcon, appIconLen, reinterpret_cast(authParam.imageinfo.GetAppIcon()),
- appIconLen);
- if (appIcon != nullptr && ret == 0) {
+ if (appIcon != nullptr &&
+ memcpy_s(appIcon, appIconLen, reinterpret_cast(authParam.imageinfo.GetAppIcon()),
+ appIconLen) == 0) {
napi_value appIconArray = nullptr;
napi_create_typedarray(env, napi_uint8_array, appIconLen, appIconBuffer, 0, &appIconArray);
napi_set_named_property(env, paramResult, "appIcon", appIconArray);
@@ -525,7 +526,7 @@ int32_t DeviceManagerNapi::JsToDmSubscribeInfo(const napi_env &env, const napi_v
int32_t capability = -1;
JsObjectToInt(env, object, "capability", capability);
- if (capability == DM_NAPI_SUBSCRIBE_CAPABILITY_DDMP) {
+ if (capability == DM_NAPI_SUBSCRIBE_CAPABILITY_DDMP || capability == DM_NAPI_SUBSCRIBE_CAPABILITY_OSD) {
(void)strncpy_s(info.capability, sizeof(info.capability), DM_CAPABILITY_OSD, strlen(DM_CAPABILITY_OSD));
}
return 0;
@@ -632,6 +633,7 @@ void DeviceManagerNapi::JsToJsonObject(const napi_env &env, const napi_value &ob
uint32_t jsProCount = 0;
napi_get_property_names(env, jsonField, &jsProNameList);
napi_get_array_length(env, jsProNameList, &jsProCount);
+ DMLOG(DM_LOG_INFO, "Property size=%d.", jsProCount);
napi_value jsProName = nullptr;
napi_value jsProValue = nullptr;
@@ -642,12 +644,15 @@ void DeviceManagerNapi::JsToJsonObject(const napi_env &env, const napi_value &ob
napi_typeof(env, jsProValue, &jsValueType);
switch (jsValueType) {
case napi_string: {
- jsonObj[strProName] = JsObjectToString(env, jsProValue);
+ std::string natValue = JsObjectToString(env, jsProValue);
+ DMLOG(DM_LOG_INFO, "Property name=%s, string, value=%s", strProName.c_str(), natValue.c_str());
+ jsonObj[strProName] = natValue;
break;
}
case napi_boolean: {
bool elementValue = false;
napi_get_value_bool(env, jsProValue, &elementValue);
+ DMLOG(DM_LOG_INFO, "Property name=%s, boolean, value=%d.", strProName.c_str(), elementValue);
jsonObj[strProName] = elementValue;
break;
}
@@ -657,11 +662,14 @@ void DeviceManagerNapi::JsToJsonObject(const napi_env &env, const napi_value &ob
DMLOG(DM_LOG_ERROR, "Property name=%s, Property int32_t parse error", strProName.c_str());
} else {
jsonObj[strProName] = elementValue;
+ DMLOG(DM_LOG_INFO, "Property name=%s, number, value=%d.", strProName.c_str(), elementValue);
}
break;
}
- default:
+ default: {
+ DMLOG(DM_LOG_ERROR, "Property name=%s, value type not support.", strProName.c_str());
break;
+ }
}
}
}
@@ -1043,10 +1051,11 @@ napi_value DeviceManagerNapi::JsOn(napi_env env, napi_callback_info info)
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen);
NAPI_ASSERT(env, typeLen > 0, "typeLen == 0");
- std::unique_ptr type = std::make_unique(typeLen + 1);
- napi_get_value_string_utf8(env, argv[0], type.get(), typeLen + 1, &typeLen);
+ NAPI_ASSERT(env, typeLen < DM_NAPI_BUF_LENGTH, "typeLen >= MAXLEN");
+ char type[DM_NAPI_BUF_LENGTH] = {0};
+ napi_get_value_string_utf8(env, argv[0], type, typeLen + 1, &typeLen);
- std::string eventType = type.get();
+ std::string eventType = type;
DeviceManagerNapi *deviceManagerWrapper = nullptr;
napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper));
@@ -1081,10 +1090,11 @@ napi_value DeviceManagerNapi::JsOff(napi_env env, napi_callback_info info)
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen);
NAPI_ASSERT(env, typeLen > 0, "typeLen == 0");
- std::unique_ptr type = std::make_unique(typeLen + 1);
- napi_get_value_string_utf8(env, argv[0], type.get(), typeLen + 1, &typeLen);
+ NAPI_ASSERT(env, typeLen < DM_NAPI_BUF_LENGTH, "typeLen >= MAXLEN");
+ char type[DM_NAPI_BUF_LENGTH] = {0};
+ napi_get_value_string_utf8(env, argv[0], type, typeLen + 1, &typeLen);
- std::string eventType = type.get();
+ std::string eventType = type;
DeviceManagerNapi *deviceManagerWrapper = nullptr;
napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper));
@@ -1161,6 +1171,7 @@ void DeviceManagerNapi::HandleCreateDmCallBack(const napi_env &env, AsyncCallbac
asCallbackInfo->status = -1;
}
if (asCallbackInfo->status == 0) {
+ DMLOG(DM_LOG_INFO, "InitDeviceManager for bunderName %s success", asCallbackInfo->bundleName);
napi_get_undefined(env, &result[0]);
napi_value callback = nullptr;
napi_value callResult = nullptr;
@@ -1168,13 +1179,13 @@ void DeviceManagerNapi::HandleCreateDmCallBack(const napi_env &env, AsyncCallbac
napi_call_function(env, nullptr, callback, DM_NAPI_ARGS_TWO, &result[0], &callResult);
napi_delete_reference(env, asCallbackInfo->callback);
} else {
+ DMLOG(DM_LOG_INFO, "InitDeviceManager for bunderName %s failed", asCallbackInfo->bundleName);
napi_value message = nullptr;
napi_create_object(env, &result[0]);
napi_create_int32(env, asCallbackInfo->status, &message);
napi_set_named_property(env, result[0], "code", message);
napi_get_undefined(env, &result[1]);
}
- DMLOG(DM_LOG_INFO, "bunderName %s, status:%d", asCallbackInfo->bundleName, asCallbackInfo->status);
napi_delete_async_work(env, asCallbackInfo->asyncWork);
delete asCallbackInfo;
}, (void *)asCallbackInfo, &asCallbackInfo->asyncWork);
diff --git a/ohos.build b/ohos.build
index a5ba6d594b9857ffab7df616ab56be84a433177a..eeead16d4e580bc2ea1981776019babd0d790451 100644
--- a/ohos.build
+++ b/ohos.build
@@ -19,7 +19,7 @@
}
],
"module_list": [
- "//foundation/distributedhardware/devicemanager/utils:devicemanagerutils",
+ "//foundation/distributedhardware/devicemanager/utils:devicemanagerutils",
"//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
"//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager_native_js",
"//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice",
diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn
index a4aeac7b83a4576ff957ee1be9fad82e65cbdfd1..cdc51d98361228a4080979c3fa9898fc973eae53 100644
--- a/services/devicemanagerservice/BUILD.gn
+++ b/services/devicemanagerservice/BUILD.gn
@@ -28,6 +28,7 @@ if (defined(ohos_lite)) {
"include/requestauth",
"include/auth",
"include/ipc",
+ "include/timer",
"include/message",
"include/ipc/lite",
"${utils_path}/include/cipher",
@@ -59,7 +60,7 @@ if (defined(ohos_lite)) {
]
sources = [
- "src/ability/dm_ability_manager.cpp",
+ "src/ability/lite/dm_ability_manager.cpp",
"src/auth/hichain_connector.cpp",
"src/ipc/ipc_server_adapter.cpp",
"src/ipc/ipc_server_listener_adapter.cpp",
@@ -78,6 +79,7 @@ if (defined(ohos_lite)) {
"src/requestauth/response_session.cpp",
"src/softbus/softbus_adapter.cpp",
"src/softbus/softbus_session.cpp",
+ "src/timer/dm_timer.cpp",
]
defines = [
@@ -90,13 +92,11 @@ if (defined(ohos_lite)) {
cflags_cc = build_flags
deps = [
+ "${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//base/security/deviceauth/services:deviceauth_sdk",
"//base/startup/syspara_lite/frameworks/parameter/src:sysparam",
- "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
- "//foundation/aafwk/standard/interfaces/innerkits/want:want",
- "//foundation/aafwk/standard/services/abilitymgr:abilityms",
"//foundation/communication/dsoftbus/sdk:softbus_client",
"//foundation/communication/ipc_lite:liteipc_adapter",
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
@@ -117,6 +117,7 @@ if (defined(ohos_lite)) {
"include/auth",
"include/ipc",
"include/message",
+ "include/timer",
"include/ipc/standard",
"${utils_path}/include/cipher",
"${utils_path}/include/log",
@@ -133,7 +134,7 @@ if (defined(ohos_lite)) {
]
sources = [
- "src/ability/dm_ability_manager.cpp",
+ "src/ability/standard/dm_ability_manager.cpp",
"src/auth/hichain_connector.cpp",
"src/ipc/ipc_server_adapter.cpp",
"src/ipc/ipc_server_listener_adapter.cpp",
@@ -151,9 +152,11 @@ if (defined(ohos_lite)) {
"src/requestauth/response_session.cpp",
"src/softbus/softbus_adapter.cpp",
"src/softbus/softbus_session.cpp",
+ "src/timer/dm_timer.cpp",
]
deps = [
+ "${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
"//base/security/deviceauth/services:deviceauth_sdk",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
diff --git a/services/devicemanagerservice/include/auth/hichain_connector.h b/services/devicemanagerservice/include/auth/hichain_connector.h
index 61534df59442378978dc88dadc2b957617620b9a..b1cec9bd52605366febde82b4ceffbb64c446034 100644
--- a/services/devicemanagerservice/include/auth/hichain_connector.h
+++ b/services/devicemanagerservice/include/auth/hichain_connector.h
@@ -48,9 +48,10 @@ struct GroupInfo {
void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo);
-class GroupCreateCallback {
+class HichainConnectorCallback {
public:
virtual void OnGroupCreated(int64_t requestId, const std::string &groupId) = 0;
+ virtual void OnMemberJoin(int64_t requestId, int32_t status) = 0;
};
class HichainAuthenCallBack {
@@ -68,24 +69,23 @@ public:
int32_t Init();
bool OnTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen);
int64_t GenRequestId();
- void RegisterConnectorCallback(std::shared_ptr callback);
+ void RegisterConnectorCallback(std::shared_ptr callback);
int32_t CreateGroup(int64_t requestId, const std::string &groupName);
int32_t AddMemeber(std::string deviceId, std::shared_ptr msgResponseAuth);
- void NotifyHostOnCheckAuthResult(int errorCode);
void GetRelatedGroups(std::string DeviceId, std::vector &groupList);
void SyncGroups(std::string deviceId, std::vector &remoteGroupIdList);
int32_t DelMemberFromGroup(std::string groupId, std::string deviceId);
void DeleteGroup(std::string &groupId);
void OnGroupCreated(int64_t requestId, const std::string &returnData);
void GetSyncGroupList(std::vector &groupList, std::vector &syncGroupList);
-
+ void OnMemberJoin(int64_t requestId, int32_t status);
private:
std::string GetConnectPara(std::string deviceId, std::shared_ptr msgResponseAuth);
bool IsGroupInfoInvalid(GroupInfo &group);
private:
std::atomic requestIdIndex_ {0};
- std::shared_ptr groupCreateCallback_ = nullptr;
+ std::shared_ptr hichainConnectorCallback_ = nullptr;
const DeviceGroupManager *deviceGroupManager_ = nullptr;
DeviceAuthCallback deviceAuthCallback_ = {
.onTransmit = nullptr,
diff --git a/services/devicemanagerservice/include/ipc/ipc_server_adapter.h b/services/devicemanagerservice/include/ipc/ipc_server_adapter.h
index b371e03a4ed47b5e49e57f829c4305d5f13fed23..deec8bfeef5a3b54cb4be23625f6b43e8b51fa10 100644
--- a/services/devicemanagerservice/include/ipc/ipc_server_adapter.h
+++ b/services/devicemanagerservice/include/ipc/ipc_server_adapter.h
@@ -26,9 +26,6 @@
#include "single_instance.h"
#include "softbus_adapter.h"
-#include "ability_manager_interface.h"
-#include "want.h"
-#include "ipc_server_adapter.h"
namespace OHOS {
namespace DistributedHardware {
diff --git a/services/devicemanagerservice/include/ipc/ipc_server_listener_adapter.h b/services/devicemanagerservice/include/ipc/ipc_server_listener_adapter.h
index e4b3e357d703f97a289c2bb8595694c6976b691a..b812eca27533737f19037793342a3fbbf40e96e3 100644
--- a/services/devicemanagerservice/include/ipc/ipc_server_listener_adapter.h
+++ b/services/devicemanagerservice/include/ipc/ipc_server_listener_adapter.h
@@ -33,7 +33,7 @@ public:
void OnDiscoverFailed(std::string &pkgName, uint16_t originId, DiscoveryFailReason failReason);
void OnDiscoverySuccess(std::string &pkgName, uint16_t originId);
void OnAuthResult(std::string &pkgName, std::string &deviceId, int32_t pinToken, uint32_t status, uint32_t reason);
- void OnCheckAuthResult(std::string &pkgName, std::string &deviceId, int32_t resultCode, int32_t flag);
+ void OnCheckAuthResult(std::string &deviceId, int32_t resultCode, int32_t flag);
void OnFaCall(std::string &pkgName, std::string ¶mJson);
private:
IpcServerListener ipcServerListener_;
diff --git a/services/devicemanagerservice/include/requestauth/auth_manager.h b/services/devicemanagerservice/include/requestauth/auth_manager.h
index 8778a44bcfe70554cad1c1acdd84be80cdda5210..0fb99a70f6283102378b2295a4f916b9750693bd 100644
--- a/services/devicemanagerservice/include/requestauth/auth_manager.h
+++ b/services/devicemanagerservice/include/requestauth/auth_manager.h
@@ -40,6 +40,8 @@ public:
void OnUserOperate(int32_t action);
int32_t GetPincode(int64_t requestId);
std::string GetAuthPara();
+ int32_t GetDisplayOwner();
+ void NotifyHostOnCheckAuthResult(int64_t requestId, int errorCode);
private:
void SyncDmPrivateGroup(std::string &message);
@@ -53,6 +55,7 @@ private:
private:
std::string authParam_ = "";
+ int32_t displayOwner_ = 0;
std::shared_ptr mPendingReqSessionPtr_ {nullptr};
std::shared_ptr mPendingRespSessionPtr {};
std::map> mWaitScanReqSessionMap_ = {};
diff --git a/services/devicemanagerservice/include/requestauth/request_session.h b/services/devicemanagerservice/include/requestauth/request_session.h
index 4daec9e3844b853bb0a45ff5358ff4dddc934567..22bbbf4515cba44382d958efc850499f53f18b47 100644
--- a/services/devicemanagerservice/include/requestauth/request_session.h
+++ b/services/devicemanagerservice/include/requestauth/request_session.h
@@ -44,6 +44,8 @@ public:
void OnReceivePinCode(int32_t pinCode);
void NotifyHostAppAuthResult(int32_t errorCode);
void OnUserOperate(int32_t action);
+ int64_t GetRequestId();
+ std::string GetRequestDeviceId();
private:
int32_t StartFaService();
diff --git a/services/devicemanagerservice/include/requestauth/response_session.h b/services/devicemanagerservice/include/requestauth/response_session.h
index 87462daba0faac8f8038aafa4dab37340e2ac16f..ee80835b22514654ab7a691349e20d9d9037ea93 100644
--- a/services/devicemanagerservice/include/requestauth/response_session.h
+++ b/services/devicemanagerservice/include/requestauth/response_session.h
@@ -25,6 +25,7 @@
#include "msg_response_auth.h"
#include "msg_request_auth.h"
#include "hichain_connector.h"
+#include "dm_timer.h"
namespace OHOS {
namespace DistributedHardware {
@@ -35,27 +36,29 @@ enum ResponseSessionStatus : int32_t {
SESSION_WAITTING_PIN_CODE = 3
};
-class ResponseSession : public GroupCreateCallback, public std::enable_shared_from_this {
+class ResponseSession : public HichainConnectorCallback, public std::enable_shared_from_this {
public:
ResponseSession();
virtual ~ResponseSession() {};
int32_t SendResponseMessage(int32_t reply);
void OnUserOperate(int32_t action);
void OnGroupCreated(int64_t requestId, const std::string &groupId) override;
+ void OnMemberJoin(int64_t requestId, int32_t status) override;
void BuildAuthenticationInfo(DmAuthParam &authParam);
void OnReceiveMsg(long long channelId, std::string &message);
int64_t GetRequestId();
int32_t GetPinCodeByReqId(int64_t requestId);
bool IsMyChannelId(long long channelId);
+ void Release();
+ void CancelDisplay();
+ int32_t GetStatus();
private:
- void Release();
int32_t DecodeReqMsg(std::string &message);
int32_t StartFaService();
std::string GenerateGroupName();
void OnUserConfirm();
void OnUserReject(int32_t errorCode);
- void CancelDisplay();
int32_t GeneratePincode();
private:
@@ -68,6 +71,8 @@ private:
int64_t mChannelId_;
int32_t mPincode_;
int32_t mSessionStatus_;
+ std::shared_ptr mReceiveTimerPtr_;
+ std::shared_ptr mMemberJoinTimerPtr_;
};
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/services/devicemanagerservice/include/timer/dm_timer.h b/services/devicemanagerservice/include/timer/dm_timer.h
new file mode 100644
index 0000000000000000000000000000000000000000..f0deba4a7288ea167d3a120582e66a7102b0ecac
--- /dev/null
+++ b/services/devicemanagerservice/include/timer/dm_timer.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef TIMER_H
+#define TIMER_H
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "device_manager_log.h"
+
+
+namespace OHOS {
+namespace DistributedHardware {
+
+typedef void (*TimeoutHandle)(void *data);
+
+#define MAXEVENTS 255
+
+enum DmTimerStatus : int32_t {
+ DM_STATUS_INIT = 0,
+ DM_STATUS_RUNNING = 1,
+ DM_STATUS_BUSY = 2,
+ DM_STATUS_CREATE_ERROR = 3,
+ DM_STATUS_FINISH = 6,
+};
+
+class DmTimer {
+public:
+ DmTimer(std::string &name);
+ ~DmTimer();
+ DmTimerStatus Start(uint32_t timeOut, TimeoutHandle handle, void *data);
+ void Stop(int32_t code);
+ void WiteforTimeout();
+
+private:
+ int32_t CreateTimeFd();
+ void Release();
+
+private:
+ DmTimerStatus mStatus_;
+ uint32_t mTimeOutSec_;
+ TimeoutHandle mHandle_;
+ void *mHandleData_;
+ int32_t mTimeFd_[2];
+ struct epoll_event mEv_;
+ struct epoll_event mEvents_[MAXEVENTS];
+ int32_t mEpFd_;
+ std::thread mThread_;
+ std::string mTimerName_;
+};
+}
+}
+#endif
+
diff --git a/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp b/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3b588515998fa03b574b1b292fe359f18d88c9ba
--- /dev/null
+++ b/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#include "dm_ability_manager.h"
+
+#include "semaphore.h"
+
+#include "constants.h"
+#include "device_manager_log.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+IMPLEMENT_SINGLE_INSTANCE(DmAbilityManager);
+
+AbilityRole DmAbilityManager::GetAbilityRole()
+{
+ return mAbilityStatus_;
+}
+
+AbilityStatus DmAbilityManager::StartAbility(AbilityRole role)
+{
+ // not support for L1 yet, do nothing. jsut save status and role
+ mAbilityStatus_ = role;
+ mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS;
+ return mStatus_;
+}
+
+void DmAbilityManager::waitForTimeout(uint32_t timeout_s)
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec += timeout_s;
+ sem_timedwait(&mSem_, &ts);
+}
+
+void DmAbilityManager::StartAbilityDone()
+{
+ mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS;
+ sem_post(&mSem_);
+}
+}
+}
diff --git a/services/devicemanagerservice/src/ability/dm_ability_manager.cpp b/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp
similarity index 90%
rename from services/devicemanagerservice/src/ability/dm_ability_manager.cpp
rename to services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp
index b9d310e3ae7d119914680541fcb32e29797188ee..8cf00ecccdd3a6bbc0123256a019f05babbf7860 100644
--- a/services/devicemanagerservice/src/ability/dm_ability_manager.cpp
+++ b/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp
@@ -15,7 +15,7 @@
#include "dm_ability_manager.h"
-
+#include "auth_manager.h"
#include "ability_manager_client.h"
#include "ability_record.h"
#include "ability_manager_service.h"
@@ -57,12 +57,16 @@ AbilityStatus DmAbilityManager::StartAbility(AbilityRole role)
std::string deviceId = localDeviceId;
std::string bundleName = "com.ohos.devicemanagerui";
std::string abilityName = "com.ohos.devicemanagerui.MainAbility";
+ int32_t displayOwner = (role == AbilityRole::ABILITY_ROLE_INITIATIVE) ?
+ AuthManager::GetInstance().GetDisplayOwner() : DISPLAY_OWNER_SYSTEM;
mStatus_ = AbilityStatus::ABILITY_STATUS_START;
AAFwk::Want want;
AppExecFwk::ElementName element(deviceId, bundleName, abilityName);
want.SetElement(element);
-
+ if (displayOwner == DISPLAY_OWNER_OTHER) {
+ return AbilityStatus::ABILITY_STATUS_SUCCESS;
+ }
AAFwk::AbilityManagerClient::GetInstance()->Connect();
ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want);
if (result == OHOS::ERR_OK) {
@@ -72,7 +76,6 @@ AbilityStatus DmAbilityManager::StartAbility(AbilityRole role)
mStatus_ = AbilityStatus::ABILITY_STATUS_FAILED;
return mStatus_;
}
-
waitForTimeout(ABILITY_START_TIMEOUT);
return mStatus_;
}
diff --git a/services/devicemanagerservice/src/auth/hichain_connector.cpp b/services/devicemanagerservice/src/auth/hichain_connector.cpp
index afb7695acc97fd73820900cdceecdb921f04c8d0..a023019fa8c11ff625d524ae3c478141625a4f23 100644
--- a/services/devicemanagerservice/src/auth/hichain_connector.cpp
+++ b/services/devicemanagerservice/src/auth/hichain_connector.cpp
@@ -33,6 +33,8 @@
#include "ipc_check_authenticate_req.h"
#include "softbus_session.h"
#include "auth_manager.h"
+#include "ipc_server_stub.h"
+#include "dm_ability_manager.h"
namespace OHOS {
namespace DistributedHardware {
@@ -125,34 +127,51 @@ int32_t HichainConnector::CreateGroup(int64_t requestId, const std::string &grou
return SUCCESS;
}
-void HichainConnector::RegisterConnectorCallback(std::shared_ptr callback)
+void HichainConnector::RegisterConnectorCallback(std::shared_ptr callback)
{
- groupCreateCallback_ = callback;
+ hichainConnectorCallback_ = callback;
}
void HichainConnector::OnGroupCreated(int64_t requestId, const std::string &returnData)
{
- if (groupCreateCallback_ == nullptr) {
- DMLOG(DM_LOG_ERROR, "HichainConnector::OnGroupCreated groupCreateCallback_ not registe.");
+ if (hichainConnectorCallback_ == nullptr) {
+ DMLOG(DM_LOG_ERROR, "HichainConnector::OnGroupCreated hichainConnectorCallback_ not registe.");
return;
}
nlohmann::json jsonObject = nlohmann::json::parse(returnData);
if (jsonObject.is_discarded()) {
DMLOG(DM_LOG_ERROR, "HichainConnector::OnGroupCreated returnData not json.");
- groupCreateCallback_->OnGroupCreated(requestId, "");
+ hichainConnectorCallback_->OnGroupCreated(requestId, "");
return;
}
if (jsonObject.find(FIELD_GROUP_ID) == jsonObject.end()) {
DMLOG(DM_LOG_ERROR, "HichainConnector::OnGroupCreated failed to get groupId.");
- groupCreateCallback_->OnGroupCreated(requestId, "");
+ hichainConnectorCallback_->OnGroupCreated(requestId, "");
return;
}
std::string groupId = jsonObject.at(FIELD_GROUP_ID).get();
DMLOG(DM_LOG_INFO, "group create success, groupId:%s.", GetAnonyString(groupId).c_str());
- groupCreateCallback_->OnGroupCreated(requestId, groupId);
+ hichainConnectorCallback_->OnGroupCreated(requestId, groupId);
+}
+
+void HichainConnector::OnMemberJoin(int64_t requestId, int32_t status)
+{
+ AbilityRole role = DmAbilityManager::GetInstance().GetAbilityRole();
+ DMLOG(DM_LOG_INFO, "HichainConnector::OnMemberJoin:: role = %d", (int32_t)role);
+
+ if (role == AbilityRole::ABILITY_ROLE_INITIATIVE) {
+ AuthManager::GetInstance().NotifyHostOnCheckAuthResult(requestId, status);
+ return;
+ }
+
+ if (hichainConnectorCallback_ == nullptr) {
+ DMLOG(DM_LOG_ERROR, "HichainConnector::OnMemberJoin hichainConnectorCallback_ not registe.");
+ return;
+ }
+ hichainConnectorCallback_->OnMemberJoin(requestId, status);
}
int32_t HichainConnector::AddMemeber(std::string deviceId, std::shared_ptr msgResponseAuth)
@@ -335,7 +354,7 @@ void HichainAuthenCallBack::onFinish(int64_t requestId, int32_t operationCode, c
DMLOG(DM_LOG_INFO, "HichainAuthenCallBack::onFinish reqId:%lld, operation:%d", requestId, operationCode);
if (operationCode == GroupOperationCode::MEMBER_JOIN) {
DMLOG(DM_LOG_INFO, "Add Member To Group success");
- HichainConnector::GetInstance().NotifyHostOnCheckAuthResult(SUCCESS);
+ HichainConnector::GetInstance().OnMemberJoin(requestId, SUCCESS);
}
if (operationCode == GroupOperationCode::GROUP_CREATE) {
@@ -362,12 +381,12 @@ void HichainAuthenCallBack::onError(int64_t requestId, int32_t operationCode, in
if (operationCode == GroupOperationCode::MEMBER_JOIN) {
DMLOG(DM_LOG_ERROR, "Add Member To Group failed");
- HichainConnector::GetInstance().NotifyHostOnCheckAuthResult(FAIL);
+ HichainConnector::GetInstance().OnMemberJoin(requestId, FAIL);
}
if (operationCode == GroupOperationCode::GROUP_CREATE) {
DMLOG(DM_LOG_ERROR, "Create group failed");
- HichainConnector::GetInstance().NotifyHostOnCheckAuthResult(FAIL);
+ HichainConnector::GetInstance().OnGroupCreated(requestId, "{}");
}
if (operationCode == GroupOperationCode::MEMBER_DELETE) {
@@ -402,16 +421,5 @@ char *HichainAuthenCallBack::onRequest(int64_t requestId, int32_t operationCode,
char *buffer = strdup(jsonStr.c_str());
return buffer;
}
-
-void HichainConnector::NotifyHostOnCheckAuthResult(int errorCode)
-{
- DMLOG(DM_LOG_INFO, "notify host result, errorcode: %d", errorCode);
- std::string hostPkgName = "com.ohos.devicemanagerui";
- char localDeviceId[DEVICE_UUID_LENGTH] = {0};
- GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
-
- std::string authParam = AuthManager::GetInstance().GetAuthPara();
- IpcServerListenerAdapter::GetInstance().OnCheckAuthResult(hostPkgName, authParam, errorCode, 0);
-}
}
}
diff --git a/services/devicemanagerservice/src/ipc/ipc_server_listener_adapter.cpp b/services/devicemanagerservice/src/ipc/ipc_server_listener_adapter.cpp
index fe29635d25d6059c16d0f9af01d42132f7aabe7e..2fd07e261d0ddb585ea8a93ef51e5b95c3f7057e 100644
--- a/services/devicemanagerservice/src/ipc/ipc_server_listener_adapter.cpp
+++ b/services/devicemanagerservice/src/ipc/ipc_server_listener_adapter.cpp
@@ -100,7 +100,7 @@ void IpcServerListenerAdapter::OnAuthResult(std::string &pkgName, std::string &d
ipcServerListener_.SendRequest(SERVER_AUTH_RESULT, pReq, pRsp);
}
-void IpcServerListenerAdapter::OnCheckAuthResult(std::string &pkgName, std::string &authParam, int32_t resultCode,
+void IpcServerListenerAdapter::OnCheckAuthResult(std::string &authParam, int32_t resultCode,
int32_t flag)
{
DMLOG(DM_LOG_INFO, "OnCheckResult, authParam: %s, errorCode: %d",
@@ -108,16 +108,15 @@ void IpcServerListenerAdapter::OnCheckAuthResult(std::string &pkgName, std::stri
std::shared_ptr pReq = std::make_shared();
std::shared_ptr pRsp = std::make_shared();
- pReq->SetPkgName(pkgName);
pReq->SetDeviceId(authParam);
pReq->SetResult(resultCode);
pReq->SetFlag(flag);
- ipcServerListener_.SendRequest(SERVER_CHECK_AUTH_RESULT, pReq, pRsp);
+ ipcServerListener_.SendAll(SERVER_CHECK_AUTH_RESULT, pReq, pRsp);
}
void IpcServerListenerAdapter::OnFaCall(std::string &pkgName, std::string ¶mJson)
{
- DMLOG(DM_LOG_INFO, "OnFaCallSuccess");
+ DMLOG(DM_LOG_INFO, "OnFaCall in");
std::shared_ptr pReq = std::make_shared();
std::shared_ptr pRsp = std::make_shared();
diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp
index b4e185050bc6fee98770598afd4a61f5370033f3..b71b3edfd6f95e21d45cdc533a3ddd9024f23eff 100644
--- a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp
+++ b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp
@@ -13,6 +13,7 @@
* limitations under the License.
*/
+#include "constants.h"
#include "ipc_cmd_register.h"
#include "device_manager_errno.h"
@@ -24,6 +25,7 @@
#include "ipc_notify_device_found_req.h"
#include "ipc_notify_device_state_req.h"
#include "ipc_notify_discover_result_req.h"
+#include "ipc_notify_dmfa_result_req.h"
#include "ipc_server_adapter.h"
#include "ipc_server_stub.h"
@@ -159,12 +161,14 @@ ON_IPC_SERVER_CMD(GET_TRUST_DEVICE_LIST, IpcIo &req, IpcIo &reply)
ON_IPC_SERVER_CMD(REGISTER_DEVICE_MANAGER_LISTENER, IpcIo &req, IpcIo &reply)
{
- RegisterDeviceManagerListener(&req, &reply);
+ int32_t errCode = RegisterDeviceManagerListener(&req, &reply);
+ IpcIoPushInt32(&reply, errCode);
}
ON_IPC_SERVER_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER, IpcIo &req, IpcIo &reply)
{
- UnRegisterDeviceManagerListener(&req, &reply);
+ int32_t errCode = UnRegisterDeviceManagerListener(&req, &reply);
+ IpcIoPushInt32(&reply, errCode);
}
ON_IPC_SERVER_CMD(START_DEVICE_DISCOVER, IpcIo &req, IpcIo &reply)
@@ -211,5 +215,69 @@ ON_IPC_SERVER_CMD(CHECK_AUTHENTICATION, IpcIo &req, IpcIo &reply)
int32_t ret = IpcServerAdapter::GetInstance().CheckAuthentication(authPara);
IpcIoPushInt32(&reply, ret);
}
+
+ON_IPC_SERVER_CMD(SERVER_GET_AUTHENTCATION_INFO, IpcIo &req, IpcIo &reply)
+{
+ size_t len = 0;
+ std::string packName = (const char *)IpcIoPopString(&req, &len);
+ DmAuthParam authParam = {0};
+ DMLOG(DM_LOG_ERROR, "DeviceManagerStub:: GET_AUTHENTCATION_INFO:pkgName:%s", packName.c_str());
+ IpcServerAdapter::GetInstance().GetAuthenticationParam(packName, authParam);
+ if (authParam.direction == AUTH_SESSION_SIDE_CLIENT) {
+ IpcIoPushInt32(&reply, authParam.direction);
+ IpcIoPushInt32(&reply, authParam.authType);
+ IpcIoPushInt32(&reply, authParam.pinToken);
+ DMLOG(DM_LOG_DEBUG, "DeviceManagerStub::is Client so just return direction");
+ return;
+ }
+
+ int32_t appIconLen = authParam.imageinfo.GetAppIconLen();
+ int32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen();
+
+ IpcIoPushInt32(&reply, authParam.direction);
+ IpcIoPushInt32(&reply, authParam.authType);
+ IpcIoPushString(&reply, authParam.packageName.c_str());
+ IpcIoPushString(&reply, authParam.appName.c_str());
+ IpcIoPushString(&reply, authParam.appDescription.c_str());
+ IpcIoPushInt32(&reply, authParam.business);
+ IpcIoPushInt32(&reply, authParam.pincode);
+ IpcIoPushInt32(&reply, appIconLen);
+ IpcIoPushInt32(&reply, appThumbnailLen);
+
+ if (appIconLen > 0 && authParam.imageinfo.GetAppIcon() != nullptr) {
+ IpcIoPushFlatObj(&reply, authParam.imageinfo.GetAppIcon(), appIconLen);
+ }
+
+ if (appThumbnailLen > 0 && authParam.imageinfo.GetAppThumbnail() != nullptr) {
+ IpcIoPushFlatObj(&reply, authParam.imageinfo.GetAppThumbnail(), appThumbnailLen);
+ }
+}
+
+ON_IPC_SERVER_CMD(SERVER_USER_AUTHORIZATION_OPERATION, IpcIo &req, IpcIo &reply)
+{
+ size_t len = 0;
+ std::string packName = (const char *)IpcIoPopString(&req, &len);
+ int32_t action = IpcIoPopInt32(&reply);
+ IpcServerAdapter::GetInstance().SetUserOperation(packName, action);
+
+ IpcIoPushInt32(&reply, action);
+}
+
+ON_IPC_SET_REQUEST(SERVER_DEVICEMANAGER_FA_NOTIFY, std::shared_ptr pBaseReq, IpcIo& request,
+ uint8_t *buffer, size_t buffLen)
+{
+ std::shared_ptr pReq = std::static_pointer_cast(pBaseReq);
+ std::string packagname = pReq->GetPkgName();
+ std::string paramJson = pReq->GetJsonParam();
+ IpcIoPushString(&request, packagname.c_str());
+ IpcIoPushString(&request, paramJson.c_str());
+ return DEVICEMANAGER_OK;
+}
+
+ON_IPC_READ_RESPONSE(SERVER_DEVICEMANAGER_FA_NOTIFY, IpcIo& reply, std::shared_ptr pBaseRsp)
+{
+ pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
+ return DEVICEMANAGER_OK;
+}
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp
index 775245f592f02b38ba945b9cae2b319024d530e3..1cb044337f0a9fd37d5e9b333e8352fb62f7ff4d 100644
--- a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp
+++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp
@@ -77,7 +77,6 @@ static int32_t DeathCb(const IpcContext *context, void *ipcMsg, IpcIo *data, voi
sid.token = svcId.token;
sid.cookie = svcId.cookie;
UnregisterDeathCallback(sid, svcId.cbId);
-
return DEVICEMANAGER_OK;
}
@@ -85,13 +84,11 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply)
{
DMLOG(DM_LOG_INFO, "register service listener.");
size_t len = 0;
- int32_t ret = DEVICEMANAGER_OK;
uint8_t *name = IpcIoPopString(req, &len);
SvcIdentity *svc = IpcIoPopSvc(req);
if (name == NULL || svc == NULL || len == 0) {
DMLOG(DM_LOG_ERROR, "get para failed");
- IpcIoPushInt32(reply, ret);
- return DEVICEMANAGER_OK;
+ return DEVICEMANAGER_INVALID_PARAM;
}
CommonSvcId svcId = {0};
@@ -106,26 +103,21 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply)
free(svc);
svc = NULL;
#endif
-
char *pkgName = (char *)malloc(len + 1);
if (pkgName == NULL) {
DMLOG(DM_LOG_ERROR, "malloc failed!");
- IpcIoPushInt32(reply, DEVICEMANAGER_FAILED);
- return DEVICEMANAGER_FAILED;
+ return DEVICEMANAGER_MALLOC_ERROR;
}
if (strcpy_s(pkgName, len + 1, (const char *)name) != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "strcpy_s failed!");
free(pkgName);
- IpcIoPushInt32(reply, DEVICEMANAGER_FAILED);
- return DEVICEMANAGER_FAILED;
+ return DEVICEMANAGER_COPY_FAILED;
}
uint32_t cbId = 0;
RegisterDeathCallback(NULL, sid, DeathCb, pkgName, &cbId);
svcId.cbId = cbId;
std::string strPkgName = (const char *)name;
- ret = IpcServerListenermgr::GetInstance().RegisterListener(strPkgName, &svcId);
- IpcIoPushInt32(reply, ret);
- return DEVICEMANAGER_OK;
+ return IpcServerListenermgr::GetInstance().RegisterListener(strPkgName, &svcId);
}
int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply)
@@ -138,24 +130,23 @@ int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply)
return DEVICEMANAGER_FAILED;
}
- CommonSvcId svcId = {0};
- if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DEVICEMANAGER_OK) {
- DMLOG(DM_LOG_ERROR, "not found listener by package name.");
- return DEVICEMANAGER_FAILED;
- }
int32_t ret = IpcServerListenermgr::GetInstance().UnregisterListener(pkgName);
if (ret == DEVICEMANAGER_OK) {
+ CommonSvcId svcId;
+ if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DEVICEMANAGER_OK) {
+ DMLOG(DM_LOG_ERROR, "not found listener by package name.");
+ return DEVICEMANAGER_FAILED;
+ }
#ifdef __LINUX__
BinderRelease(svcId.ipcCtx, svcId.handle);
#endif
- SvcIdentity sid = {0};
+ SvcIdentity sid;
sid.handle = svcId.handle;
sid.token = svcId.token;
sid.cookie = svcId.cookie;
ret = UnregisterDeathCallback(sid, svcId.cbId);
}
- IpcIoPushInt32(reply, ret);
- return DEVICEMANAGER_OK;
+ return ret;
}
static const char *GetName(Service *service)
diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp
index f19028cf6835ebe0b44655bd2f7708bd715b3265..9df2dadcda9bdc336d91ab78cbc4088ce6499f54 100644
--- a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp
+++ b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp
@@ -285,13 +285,12 @@ ON_IPC_CMD(SERVER_GET_AUTHENTCATION_INFO, MessageParcel &data, MessageParcel &re
std::string packName = data.ReadString();
DmAuthParam authParam;
int32_t ret = DEVICEMANAGER_OK;
- DMLOG(DM_LOG_ERROR, "GET_AUTHENTCATION_INFO:pkgName:%s", packName.c_str());
+ DMLOG(DM_LOG_ERROR, "DeviceManagerStub:: GET_AUTHENTCATION_INFO:pkgName:%s", packName.c_str());
IpcServerAdapter::GetInstance().GetAuthenticationParam(packName, authParam);
if (authParam.direction == AUTH_SESSION_SIDE_CLIENT) {
- if (!reply.WriteInt32(authParam.direction) ||
- !reply.WriteInt32(authParam.authType) ||
+ if (!reply.WriteInt32(authParam.direction) || !reply.WriteInt32(authParam.authType) ||
!reply.WriteInt32(authParam.pinToken)) {
- DMLOG(DM_LOG_ERROR, "wirte client fail");
+ DMLOG(DM_LOG_ERROR, "DeviceManagerStub::wirte client fail");
ret = DEVICEMANAGER_WRITE_FAILED;
}
return ret;
@@ -309,7 +308,7 @@ ON_IPC_CMD(SERVER_GET_AUTHENTCATION_INFO, MessageParcel &data, MessageParcel &re
}
if (appIconLen > 0 && authParam.imageinfo.GetAppIcon() != nullptr) {
- if (!reply.WriteRawData(authParam.imageinfo.GetAppIcon(), appIconLen)){
+ if (!reply.WriteRawData(authParam.imageinfo.GetAppIcon(), appIconLen)) {
DMLOG(DM_LOG_ERROR, "write appIcon failed");
return DEVICEMANAGER_WRITE_FAILED;
}
@@ -321,6 +320,7 @@ ON_IPC_CMD(SERVER_GET_AUTHENTCATION_INFO, MessageParcel &data, MessageParcel &re
return DEVICEMANAGER_WRITE_FAILED;
}
}
+
return DEVICEMANAGER_OK;
}
@@ -328,7 +328,7 @@ ON_IPC_CMD(SERVER_USER_AUTHORIZATION_OPERATION, MessageParcel &data, MessageParc
{
std::string packageName = data.ReadString();
int32_t action = data.ReadInt32();
- int32_t result = IpcServerAdapter::GetInstance().SetUserOperation(packageName, action);
+ int result = IpcServerAdapter::GetInstance().SetUserOperation(packageName, action);
if (!reply.WriteInt32(action)) {
DMLOG(DM_LOG_ERROR, "write result failed");
@@ -336,6 +336,7 @@ ON_IPC_CMD(SERVER_USER_AUTHORIZATION_OPERATION, MessageParcel &data, MessageParc
}
return result;
}
+
ON_IPC_SET_REQUEST(SERVER_DEVICEMANAGER_FA_NOTIFY, std::shared_ptr pBaseReq, MessageParcel& data)
{
DMLOG(DM_LOG_INFO, "OnFaCallBack");
diff --git a/services/devicemanagerservice/src/message/msg_response_auth.cpp b/services/devicemanagerservice/src/message/msg_response_auth.cpp
index 59e09643073a9d81f9af7b8c292bc2831483127b..b1b18492b885418bd463070c82bd1a2b5df5d4b9 100644
--- a/services/devicemanagerservice/src/message/msg_response_auth.cpp
+++ b/services/devicemanagerservice/src/message/msg_response_auth.cpp
@@ -69,7 +69,7 @@ void MsgResponseAuth::Encode(nlohmann::json &jsonObj)
DMLOG(DM_LOG_INFO, "encode mReply_ is : %d", mReply_);
DMLOG(DM_LOG_INFO, "encode deviceId is : %s", GetAnonyString(mDeviceId_).c_str());
DMLOG(DM_LOG_INFO, "encode netId is : %s", GetAnonyString(mNetId_).c_str());
- DMLOG(DM_LOG_INFO, "encode mGroupId_ is %s", mGroupId_.c_str());
+ DMLOG(DM_LOG_INFO, "encode mGroupId_ is %s", GetAnonyString(mGroupId_).c_str());
DMLOG(DM_LOG_INFO, "encode mGroupName_ is %s", mGroupName_.c_str());
DMLOG(DM_LOG_INFO, "encode mRequestId_ is %d", mRequestId_);
}
@@ -103,8 +103,8 @@ int32_t MsgResponseAuth::Decode(nlohmann::json &jsonObj)
mRequestId_ = jsonObj[TAG_REQUEST_ID];
}
DMLOG(DM_LOG_INFO, "decode mReply_ is : %d", mReply_);
- DMLOG(DM_LOG_INFO, "decode mGroupId_ is %s", mGroupId_.c_str());
- DMLOG(DM_LOG_INFO, "decode mGroupName_ is %s", mGroupName_.c_str());
+ DMLOG(DM_LOG_INFO, "decode mGroupId_ is %s", GetAnonyString(mGroupId_).c_str());
+ DMLOG(DM_LOG_INFO, "decode mGroupName_ is %s", GetAnonyString(mGroupName_).c_str());
DMLOG(DM_LOG_INFO, "decode deviceId is : %s", GetAnonyString(mDeviceId_).c_str());
DMLOG(DM_LOG_INFO, "decode netId is : %s", GetAnonyString(mNetId_).c_str());
DMLOG(DM_LOG_INFO, "decode mRequestId_ is %d", mRequestId_);
diff --git a/services/devicemanagerservice/src/requestauth/auth_manager.cpp b/services/devicemanagerservice/src/requestauth/auth_manager.cpp
index dda87829713d366171a7eb9b048cc756f05a131c..2a01cd06084a813fc5977b60910be30d02471c0c 100644
--- a/services/devicemanagerservice/src/requestauth/auth_manager.cpp
+++ b/services/devicemanagerservice/src/requestauth/auth_manager.cpp
@@ -23,6 +23,7 @@
#include "device_manager_errno.h"
#include "softbus_session.h"
#include "encrypt_utils.h"
+#include "ipc_server_listener_adapter.h"
namespace OHOS {
namespace DistributedHardware {
@@ -64,6 +65,13 @@ void AuthManager::AuthAppGroup(std::string &hostPkgName, const DmDeviceInfo &dev
return;
}
+ if (!jsonObject.contains(DISPLAY_OWNER)) {
+ DMLOG(DM_LOG_WARN, "AuthAppGroup DISPLAY_OWNER error");
+ displayOwner_ = DISPLAY_OWNER_SYSTEM;
+ } else {
+ displayOwner_ = jsonObject[DISPLAY_OWNER];
+ }
+
if (!CanStartNewSession()) {
DMLOG(DM_LOG_ERROR, "previous session not completed yet");
mPendingReqSessionPtr_->NotifyHostAppAuthResult(ERROR_DUPLICATE_REQUEST);
@@ -165,17 +173,34 @@ int32_t AuthManager::CheckAuthentication(std::string &authPara)
return CheckAuthenticationByPin(authJson);
}
+void AuthManager::NotifyHostOnCheckAuthResult(int64_t requestId, int errorCode)
+{
+ DMLOG(DM_LOG_INFO, "notify host checkResult, requestId: %lld, errorcode: %d", requestId, errorCode);
+ for (auto iter = mWaitScanReqSessionMap_.begin(); iter != mWaitScanReqSessionMap_.end(); iter++) {
+ auto requestSessionPtr = iter->second;
+ if (requestSessionPtr != nullptr && requestSessionPtr->GetRequestId() == requestId) {
+ std::string deviceId = requestSessionPtr->GetRequestDeviceId();
+ DMLOG(DM_LOG_INFO, "notify host checkResult, deviceId: %s, requestId: %lld",
+ GetAnonyString(deviceId).c_str(), requestId);
+ IpcServerListenerAdapter::GetInstance().OnCheckAuthResult(deviceId, errorCode, 0);
+ return;
+ }
+ }
+
+ DMLOG(DM_LOG_ERROR, "notify host checkResult error, requestId: %lld", requestId);
+}
+
int32_t AuthManager::CheckAuthenticationByPin(nlohmann::json &authJson)
{
int32_t pinCode = authJson.contains(PIN_CODE_KEY) ? (int32_t)authJson[PIN_CODE_KEY] : DEFAULT_PIN_CODE;
int32_t pinToken = authJson.contains(PIN_TOKEN) ? (int32_t)authJson[PIN_TOKEN] : DEFAULT_PIN_TOKEN;
if (pinCode < MIN_PIN_CODE || pinCode >= (MIN_PIN_CODE + MAX_PIN_CODE)) {
- DMLOG(DM_LOG_ERROR, "pinCode err, pinCode is :%s", GetAnonyInt32(pinCode).c_str());
+ DMLOG(DM_LOG_ERROR, "pinCode err, please check pinCode");
return PIN_CODE_CHECK_FAILED;
}
if (pinToken < MIN_PIN_TOKEN || pinToken >= (MIN_PIN_TOKEN + MAX_PIN_TOKEN)) {
- DMLOG(DM_LOG_ERROR, "pinToken err, pinToken is :%s", GetAnonyInt32(pinToken).c_str());
+ DMLOG(DM_LOG_ERROR, "pinToken err, please check pinToken.");
return PIN_TOKEN_CHECK_FAILED;
}
OnPinInputResult(pinCode, pinToken);
@@ -234,5 +259,10 @@ std::string AuthManager::GetAuthPara()
{
return authParam_;
}
+
+int32_t AuthManager::GetDisplayOwner()
+{
+ return displayOwner_;
+}
}
}
diff --git a/services/devicemanagerservice/src/requestauth/request_session.cpp b/services/devicemanagerservice/src/requestauth/request_session.cpp
index 937be386b37a3147efc0838d9d2810d33575721d..bd8ab35d79ec310cff12471f2942f06a623026b1 100644
--- a/services/devicemanagerservice/src/requestauth/request_session.cpp
+++ b/services/devicemanagerservice/src/requestauth/request_session.cpp
@@ -113,10 +113,21 @@ void RequestSession::OnReceivePinCode(int32_t pinCode)
void RequestSession::OnUserOperate(int32_t action)
{
if (action == FaAction::USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT) {
+ Release();
return;
}
}
+int64_t RequestSession::GetRequestId()
+{
+ return mRequestId_;
+}
+
+std::string RequestSession::GetRequestDeviceId()
+{
+ return mRemoteDeviceId_;
+}
+
int32_t RequestSession::StartFaService()
{
DMLOG(DM_LOG_INFO, "RequestSession::StartFaService in");
@@ -237,19 +248,24 @@ void RequestSession::SyncDmPrivateGroup(std::vector &remoteGroupLis
void RequestSession::NotifyHostAppAuthResult(int32_t errorCode)
{
- if (mSessionType_ == SESSION_TYPE_IS_APP_AUTH) {
- std::string deviceId = mDevInfo_.deviceId;
- if (StartFaService() != SUCCESS) {
- DMLOG(DM_LOG_INFO, "RequestSession::StartFaService failed");
- return;
- }
- DMLOG(DM_LOG_INFO, "RequestSession::StartFaService success");
- int32_t status = (errorCode == 0) ? 0 : -1;
- IpcServerListenerAdapter::GetInstance().OnAuthResult(mHostPkgName_, deviceId, mPinToken_, status, errorCode);
+ if (mSessionType_ != SESSION_TYPE_IS_APP_AUTH) {
+ DMLOG(DM_LOG_ERROR, "wrong session type: %d", mSessionType_);
+ return;
+ }
+
+ std::string deviceId = mDevInfo_.deviceId;
+ if (errorCode != SESSION_REPLY_ACCEPT) {
+ IpcServerListenerAdapter::GetInstance().OnAuthResult(mHostPkgName_, deviceId, mPinToken_, FAIL, errorCode);
DMLOG(DM_LOG_INFO, "notify host result, errorcode: %d", errorCode);
- } else {
- DMLOG(DM_LOG_ERROR, "wrong session type: %d", errorCode);
+ return;
+ }
+
+ if (StartFaService() != SUCCESS) {
+ DMLOG(DM_LOG_INFO, "RequestSession::StartFaService failed");
+ return;
}
+ DMLOG(DM_LOG_INFO, "RequestSession::StartFaService success");
+ IpcServerListenerAdapter::GetInstance().OnAuthResult(mHostPkgName_, deviceId, mPinToken_, SUCCESS, errorCode);
}
}
}
diff --git a/services/devicemanagerservice/src/requestauth/response_session.cpp b/services/devicemanagerservice/src/requestauth/response_session.cpp
index d343c56dbd9ca4d082381ebb3e6f6c9c67179cbf..ff71485c368ac96783388c7660e0fea4dfef1084 100644
--- a/services/devicemanagerservice/src/requestauth/response_session.cpp
+++ b/services/devicemanagerservice/src/requestauth/response_session.cpp
@@ -37,21 +37,20 @@
namespace OHOS {
namespace DistributedHardware {
namespace {
-// const int32_t RECEIVE_MESSAGE_TIMEOUT = 3; // 3 second
-// const int32_t WAIT_NEXT_PACKAGE_TIMEOUT = 3; // 3 second
-// const int32_t WAIT_ENTER_PINCODE_TIMEOUT = 3; // 3 second
+const int32_t SESSION_CANCEL_TIMEOUT = 0;
+const int32_t SESSION_MSG_RECEIVE_TIMEOUT = 5;
+const int32_t SESSION_WAIT_MEMBER_JOIN_TIMEOUT = 120;
+const int32_t CANCEL_PICODE_DISPLAY = 1;
+const int32_t DEVICE_ID_HALF = 2;
}
-#define PINCODE_LEN 6
-
ResponseSession::ResponseSession()
{
mSessionStatus_ = ResponseSessionStatus::SESSION_INIT;
sem_init(&mSem_, 0, 0);
- // need to update
}
-int64_t ResponseSession::GetRequestId(void)
+int64_t ResponseSession::GetRequestId()
{
return mRequestId_;
}
@@ -128,28 +127,66 @@ bool ResponseSession::IsMyChannelId(long long channelId)
return channelId == mChannelId_ && mChannelId_ > 0;
}
+void OnReceiveTimeOut(void *data)
+{
+ DMLOG(DM_LOG_ERROR, "OnReceiveTimeOut TimeOut called");
+ ResponseSession *respSess = (ResponseSession*)data;
+ if (respSess == nullptr || respSess->GetStatus() == ResponseSessionStatus::SESSION_INIT) {
+ DMLOG(DM_LOG_ERROR, "respSess Status is INIT");
+ return;
+ }
+
+ respSess->Release();
+}
+
+void OnMemberJoinTimeOut(void *data)
+{
+ DMLOG(DM_LOG_ERROR, "OnMemberJoinTimeOut TimeOut caled");
+ ResponseSession *respSess = (ResponseSession*)data;
+ if (respSess == nullptr || respSess->GetStatus() == ResponseSessionStatus::SESSION_INIT) {
+ DMLOG(DM_LOG_ERROR, "respSess Status is INIT");
+ return;
+ }
+
+ respSess->SendResponseMessage(SESSION_REPLY_TIMEOUT);
+ respSess->CancelDisplay();
+ respSess->Release();
+}
+
void ResponseSession::OnReceiveMsg(long long channelId, std::string &message)
{
int32_t ret = DecodeReqMsg(message);
if (ret != SUCCESS) {
+ DMLOG(DM_LOG_ERROR, "DecodeReqMsg failed");
return;
}
+ if (!mReceiveTimerPtr_) {
+ std::string mReceiveTimerName = "mReceiveTimer";
+ mReceiveTimerPtr_ = std::make_shared(mReceiveTimerName);
+ }
+
+ mReceiveTimerPtr_->Start(SESSION_MSG_RECEIVE_TIMEOUT, OnReceiveTimeOut, this);
if (mMsgRequestAuthPtr_->GetMsgCnt() != mMsgRequestAuthPtr_->GetMsgSlice()) {
return;
}
- // 正常业务逻辑
+ mReceiveTimerPtr_->Stop(SESSION_CANCEL_TIMEOUT);
mReqDeviceId_ = mMsgRequestAuthPtr_->GetRequestDeviceId();
mChannelId_ = channelId;
mPincode_ = GeneratePincode();
if (StartFaService() != SUCCESS) {
- // 拉起界面失败,直接回复拒绝,清理session状态
OnUserReject(ERROR_FA_START_FAIL);
return;
}
mSessionStatus_ = ResponseSessionStatus::SESSION_WAITTING_USER_CONFIRM;
+ if (!mMemberJoinTimerPtr_) {
+ std::string mMemberJoinTimerName = "mMemberJoinTimer";
+ mMemberJoinTimerPtr_ = std::make_shared(mMemberJoinTimerName);
+ }
+
+ mMemberJoinTimerPtr_->Start(SESSION_WAIT_MEMBER_JOIN_TIMEOUT, OnMemberJoinTimeOut, this);
}
int32_t ResponseSession::GetPinCodeByReqId(int64_t requestId)
@@ -163,7 +200,13 @@ int32_t ResponseSession::GetPinCodeByReqId(int64_t requestId)
void ResponseSession::BuildAuthenticationInfo(DmAuthParam &authParam)
{
+ DMLOG(DM_LOG_INFO, "ResponseSession::BuildAuthenticationInfo in");
authParam.direction = (int32_t)DmAbilityManager::GetInstance().GetAbilityRole();
+ if (mMsgRequestAuthPtr_ == nullptr) {
+ DMLOG(DM_LOG_ERROR, "ResponseSession::BuildAuthenticationInfo mMsgRequestAuthPtr_ is nullptr");
+ return;
+ }
+
authParam.packageName = mMsgRequestAuthPtr_->mTargetPkg_;
authParam.appName = mMsgRequestAuthPtr_->mAppName_;
authParam.appDescription = mMsgRequestAuthPtr_->mAppDescription_;
@@ -206,7 +249,7 @@ void ResponseSession::OnGroupCreated(int64_t requestId, const std::string &group
DMLOG(DM_LOG_INFO, "ResponseSession OnGroupCreated in requestId= %lld groupId = %s ", requestId, groupId.c_str());
if (requestId != mRequestId_ || groupId.length() == 0) {
- DMLOG(DM_LOG_ERROR, "ResponseSession::OnGroupCreated failed, requestId %d, requestId %d, groupId %s",
+ DMLOG(DM_LOG_ERROR, "ResponseSession::OnGroupCreated failed, requestId %lld, requestId %lld, groupId %s",
requestId, mRequestId_, groupId.c_str());
SendResponseMessage(SESSION_REPLY_CREAT_GROUP_FAILED);
CancelDisplay();
@@ -228,13 +271,21 @@ void ResponseSession::OnGroupCreated(int64_t requestId, const std::string &group
mSessionStatus_ = ResponseSessionStatus::SESSION_WAITTING_PIN_CODE;
}
+void ResponseSession::OnMemberJoin(int64_t requestId, int32_t status)
+{
+ DMLOG(DM_LOG_INFO, "ResponseSession::OnMemberJoin, result: %d", status);
+ CancelDisplay();
+ mMemberJoinTimerPtr_->Stop(SESSION_CANCEL_TIMEOUT);
+ Release();
+}
+
std::string ResponseSession::GenerateGroupName()
{
char localDeviceId[DEVICE_UUID_LENGTH] = {0};
GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
std::string sLocalDeviceID = localDeviceId;
std::string groupName = mMsgRequestAuthPtr_->mTargetPkg_ + mMsgRequestAuthPtr_->mHostPkg_ +
- sLocalDeviceID.substr(0, sLocalDeviceID.size() / 2);
+ sLocalDeviceID.substr(0, sLocalDeviceID.size() / DEVICE_ID_HALF);
return groupName;
}
@@ -265,6 +316,7 @@ void ResponseSession::OnUserReject(int32_t errorCode)
void ResponseSession::Release()
{
DMLOG(DM_LOG_INFO, "ResponseSession::Release in");
+ mSessionStatus_ = ResponseSessionStatus::SESSION_INIT;
mRequestId_ = -1;
mGroupId_ = "";
mGroupName_ = "";
@@ -272,15 +324,22 @@ void ResponseSession::Release()
mMsgRequestAuthPtr_ = nullptr;
mChannelId_ = -1;
mPincode_ = -1;
- mSessionStatus_ = ResponseSessionStatus::SESSION_INIT;
}
void ResponseSession::CancelDisplay()
{
+ DMLOG(DM_LOG_INFO, "Cancel PinCode Display in");
nlohmann::json jsonObj;
- jsonObj[CANCEL_DISPLAY_KEY] = 1;
- std::string jsonObjTmp = jsonObj.dump();
- IpcServerListenerAdapter::GetInstance().OnFaCall(mMsgRequestAuthPtr_->mTargetPkg_, jsonObjTmp);
+ jsonObj[CANCEL_DISPLAY_KEY] = CANCEL_PICODE_DISPLAY;
+ std::string paramJson = jsonObj.dump();
+ std::string pkgName = "com.ohos.devicemanagerui";
+ IpcServerListenerAdapter::GetInstance().OnFaCall(pkgName, paramJson);
+ DMLOG(DM_LOG_INFO, "Cancel PinCode Display success");
+}
+
+int32_t ResponseSession::GetStatus()
+{
+ return mSessionStatus_;
}
int32_t ResponseSession::GeneratePincode()
diff --git a/services/devicemanagerservice/src/timer/dm_timer.cpp b/services/devicemanagerservice/src/timer/dm_timer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8dcd7a703fa18f325a402f719461b685c2b1b4d1
--- /dev/null
+++ b/services/devicemanagerservice/src/timer/dm_timer.cpp
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#include "dm_timer.h"
+
+#include
+
+namespace OHOS {
+namespace DistributedHardware {
+namespace {
+const int32_t MILL_SECONDS_PER_SECOND = 1000;
+}
+DmTimer::DmTimer(std::string &name)
+{
+ mStatus_ = DmTimerStatus::DM_STATUS_INIT;
+ mTimerName_ = name;
+}
+
+DmTimer::~DmTimer()
+{
+ DMLOG(DM_LOG_INFO, "DmTimer %s Destory in", mTimerName_.c_str());
+ Release();
+}
+
+DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data)
+{
+ DMLOG(DM_LOG_INFO, "DmTimer %s start timeout(%d)", mTimerName_.c_str(), timeOut);
+ if (mStatus_ != DmTimerStatus::DM_STATUS_INIT) {
+ return DmTimerStatus::DM_STATUS_BUSY;
+ }
+
+ mTimeOutSec_ = timeOut;
+ mHandle_ = handle;
+ mHandleData_ = data;
+
+ if (CreateTimeFd()) {
+ return DmTimerStatus::DM_STATUS_CREATE_ERROR;
+ }
+
+ mStatus_ = DmTimerStatus::DM_STATUS_RUNNING;
+ mThread_ = std::thread(&DmTimer::WiteforTimeout, this);
+ mThread_.detach();
+
+ return mStatus_;
+}
+
+void DmTimer::Stop(int32_t code)
+{
+ DMLOG(DM_LOG_INFO, "DmTimer %s Stop code (%d)", mTimerName_.c_str(), code);
+ if (mTimeFd_[1]) {
+ char event = 'S';
+ if (write(mTimeFd_[1], &event, 1) < 0) {
+ DMLOG(DM_LOG_ERROR, "DmTimer %s Stop timer failed, errno %d", mTimerName_.c_str(), errno);
+ return;
+ }
+ DMLOG(DM_LOG_INFO, "DmTimer %s Stop success", mTimerName_.c_str());
+ }
+
+ return;
+}
+
+void DmTimer::WiteforTimeout()
+{
+ DMLOG(DM_LOG_INFO, "DmTimer %s start timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_);
+
+ int32_t nfds = epoll_wait(mEpFd_, mEvents_, MAXEVENTS, mTimeOutSec_ * MILL_SECONDS_PER_SECOND);
+ if (nfds < 0) {
+ DMLOG(DM_LOG_ERROR, "DmTimer %s epoll_wait returned n=%d, error: %d", mTimerName_.c_str(), nfds, errno);
+ }
+
+ char event = 0;
+ if (nfds > 0) {
+ if (mEvents_[0].events & EPOLLIN) {
+ int num = read(mTimeFd_[0], &event, 1);
+ if (num > 0) {
+ DMLOG(DM_LOG_INFO, "DmTimer %s exit with event %d", mTimerName_.c_str(), event);
+ } else {
+ DMLOG(DM_LOG_ERROR, "DmTimer %s exit with errno %d", mTimerName_.c_str(), errno);
+ }
+ }
+ Release();
+ return;
+ }
+
+ mHandle_(mHandleData_);
+ Release();
+
+ DMLOG(DM_LOG_ERROR, "DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_);
+ return;
+}
+
+int32_t DmTimer::CreateTimeFd()
+{
+ DMLOG(DM_LOG_INFO, "DmTimer %s creatTimeFd", mTimerName_.c_str());
+ int ret = 0;
+
+ ret = pipe(mTimeFd_);
+ if (ret < 0) {
+ DMLOG(DM_LOG_ERROR, "DmTimer %s CreateTimeFd fail:(%d) errno(%d)", mTimerName_.c_str(), ret, errno);
+ return ret;
+ }
+
+ mEv_.data.fd = mTimeFd_[0];
+ mEv_.events = EPOLLIN | EPOLLET;
+ mEpFd_ = epoll_create(MAXEVENTS);
+ ret = epoll_ctl(mEpFd_, EPOLL_CTL_ADD, mTimeFd_[0], &mEv_);
+ if (ret != 0) {
+ Release();
+ }
+
+ return ret;
+}
+
+void DmTimer::Release()
+{
+ DMLOG(DM_LOG_INFO, "DmTimer %s Release in", mTimerName_.c_str());
+ if (mStatus_ == DmTimerStatus::DM_STATUS_INIT) {
+ DMLOG(DM_LOG_INFO, "DmTimer %s already Release", mTimerName_.c_str());
+ return;
+ }
+ mStatus_ = DmTimerStatus::DM_STATUS_INIT;
+ close(mTimeFd_[0]);
+ close(mTimeFd_[1]);
+ close(mEpFd_);
+ mTimeFd_[0] = 0;
+ mTimeFd_[1] = 0;
+ mEpFd_ = 0;
+}
+}
+}