diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h
index 4ff3d02b3503e7828477c8f57a2ccdf407d3a787..58c26ce3991061569ef79ef824b98cf21212a621 100755
--- a/common/include/dm_constants.h
+++ b/common/include/dm_constants.h
@@ -74,6 +74,8 @@ enum {
ERR_DM_AUTH_NOT_START = -20026,
ERR_DM_AUTH_MESSAGE_INCOMPLETE = -20027,
ERR_DM_CREATE_GROUP_FAILED = -20028,
+ ERR_DM_IPC_READ_TOKEN_FAILED = -20029,
+ ERR_DM_AUTH_INPUT_PARAMETER_FAILED = -20030,
};
const std::string TARGET_PKG_NAME_KEY = "targetPkgName";
@@ -135,11 +137,13 @@ const std::string PIN_CODE_KEY = "pinCode";
const std::string NFC_CODE_KEY = "nfcCode";
const std::string QR_CODE_KEY = "qrCode";
const std::string TAG_AUTH_TOKEN = "authToken";
+const std::string VERIFY_FAILED = "verifyFailed";
const int32_t AUTH_TYPE_PIN = 1;
const int32_t AUTH_TYPE_SCAN = 2;
const int32_t AUTH_TYPE_TOUCH = 3;
const int32_t DEFAULT_PIN_CODE = 0;
const int32_t DEFAULT_PIN_TOKEN = 0;
+const int32_t DEFAULT_PIN_CODE_LENGTH = 6;
// Softbus
const int32_t SOFTBUS_CHECK_INTERVAL = 100000; // 100ms
@@ -171,8 +175,8 @@ const std::string ETH_PORT = "ETH_PORT";
// ACE
const int32_t ACE_X = 50;
const int32_t ACE_Y = 300;
-const int32_t ACE_WIDTH = 450;
-const int32_t ACE_HEIGHT = 400;
+const int32_t ACE_WIDTH = 580;
+const int32_t ACE_HEIGHT = 520;
const std::string EVENT_CONFIRM = "EVENT_CONFIRM";
const std::string EVENT_CANCEL = "EVENT_CANCEL";
const std::string EVENT_INIT = "EVENT_INIT";
diff --git a/display/entry/build.gradle b/display/entry/build.gradle
index f83acd766b18a865db22f77f9d9ff6611f27b73c..60fc1dd8eb045354953a8e3e11f201df1640c8f0 100644
--- a/display/entry/build.gradle
+++ b/display/entry/build.gradle
@@ -14,11 +14,11 @@
*/
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
+ compileSdkVersion 8
defaultConfig {
- compatibleSdkVersion 6
+ compatibleSdkVersion 7
}
buildTypes {
release {
@@ -28,14 +28,9 @@ ohos {
}
}
}
-
}
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']
+ testImplementation 'junit:junit:4.13.1'
}
diff --git a/display/entry/src/main/config.json b/display/entry/src/main/config.json
index 946df5f473995fef4fb85e1ec0a6565594868a82..b73d3a31903d600e02e858f331a7e7f67bb6965e 100644
--- a/display/entry/src/main/config.json
+++ b/display/entry/src/main/config.json
@@ -11,12 +11,10 @@
"module": {
"package": "com.ohos.devicemanagerui",
"name": ".MyApplication",
- "mainAbility": "com.ohos.devicemanagerui.MainAbility",
+ "mainAbility": ".MainAbility",
+ "srcPath": "",
"deviceType": [
- "phone",
- "tablet",
- "tv",
- "wearable"
+ "phone"
],
"distro": {
"deliveryWithInstall": true,
@@ -36,10 +34,14 @@
]
}
],
+ "orientation": "unspecified",
"visible": true,
- "name": "com.ohos.devicemanagerui.MainAbility",
+ "srcPath": "MainAbility",
+ "name": ".MainAbility",
+ "srcLanguage": "js",
"icon": "$media:icon",
- "description": "$string:mainability_description",
+ "description": "$string:description_mainability",
+ "formsEnabled": false,
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
@@ -48,12 +50,13 @@
"js": [
{
"pages": [
- "pages/index/index"
+ "pages/index/index",
+ "pages/second/second"
],
- "name": "default",
+ "name": ".MainAbility",
"window": {
"designWidth": 720,
- "autoDesignWidth": true
+ "autoDesignWidth": false
}
}
]
diff --git a/display/entry/src/main/js/MainAbility/app.js b/display/entry/src/main/js/MainAbility/app.js
new file mode 100644
index 0000000000000000000000000000000000000000..4aa26e97db9a4d3bc968eb070305e3867d4ac344
--- /dev/null
+++ b/display/entry/src/main/js/MainAbility/app.js
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+export default {
+ onCreate() {
+ console.info("Application onCreate");
+ },
+ onDestroy() {
+ console.info("Application onDestroy");
+ }
+};
diff --git a/display/entry/src/main/js/MainAbility/i18n/en-US.json b/display/entry/src/main/js/MainAbility/i18n/en-US.json
new file mode 100644
index 0000000000000000000000000000000000000000..328519b858b570f91c86108db71c86a29e4793f6
--- /dev/null
+++ b/display/entry/src/main/js/MainAbility/i18n/en-US.json
@@ -0,0 +1,22 @@
+{
+ "strings": {
+ "pinCodeConnection": "Pin connection",
+ "enterThePinCode": "Please enter the displayed pin code",
+ "delete": "Del",
+ "off": "Off",
+
+ "toConnectToThisComputer": " connection",
+ "resourceAccess": "Resource access",
+ "cancel": "Cancel",
+ "parenthesesLeft": "(",
+ "parenthesesRight": ")",
+ "allow": "Allow",
+
+ "applyAuth": "Allow open apply auth?",
+ "from": "From ",
+
+ "enterDisplayPinCode": "Please enter the displayed pin code"
+ },
+ "Files": {
+ }
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/MainAbility/i18n/zh-CN.json b/display/entry/src/main/js/MainAbility/i18n/zh-CN.json
new file mode 100644
index 0000000000000000000000000000000000000000..254f9c12c314bca4c61125eaa389407485941483
--- /dev/null
+++ b/display/entry/src/main/js/MainAbility/i18n/zh-CN.json
@@ -0,0 +1,22 @@
+{
+ "strings": {
+ "pinCodeConnection": "PIN码连接",
+ "enterThePinCode": "请输入PIN码",
+ "delete": "删除",
+ "off": "关闭",
+
+ "toConnectToThisComputer": "想要连接本机",
+ "resourceAccess": "用于资源访问",
+ "cancel": "取消",
+ "parenthesesLeft": "(",
+ "parenthesesRight": ")",
+ "allow": "允许",
+
+ "applyAuth": "是否允许连接?",
+ "from": "来自",
+
+ "enterDisplayPinCode": "请在主控端输入连接码进行验证"
+ },
+ "Files": {
+ }
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/MainAbility/pages/index/index.css b/display/entry/src/main/js/MainAbility/pages/index/index.css
new file mode 100644
index 0000000000000000000000000000000000000000..56a0c2ee9dfd11cd87b7ebc2503c29474dd4ecda
--- /dev/null
+++ b/display/entry/src/main/js/MainAbility/pages/index/index.css
@@ -0,0 +1,285 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+.container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ opacity: 0.8;
+ width: 100%;
+ background-color: azure;
+}
+
+.container > div {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+}
+
+.main-pin {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ opacity: 0.8;
+ width: 100%;
+ padding: 3% 0;
+ background-color: azure;
+}
+.main-pin > .pin-numb {
+ flex-direction: row;
+ justify-content: space-around;
+ align-items: center;
+ padding: 0 0px 3% 0px;
+}
+.main-pin > .pin-numb > .pin-numb-item {
+ font-size: 30px;
+ height: 14%;
+ margin: 0 5px;
+ padding-bottom: 2%;
+ 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: 2%;
+}
+
+.main-pin > .input > .numb {
+ text-color: black;
+ padding: 2%;
+ flex-shrink: 0;
+ margin: 0 5px;
+ flex-basis: 72px;
+ background-color: white;
+ border: 1px;
+}
+
+.join-auth {
+ padding-top: 10%;
+}
+.join-auth-image > image {
+ height: 50%;
+}
+.join-authorize {
+ padding-top: 4%;
+}
+.join-pin {
+ padding: 4% 0;
+}
+.join-pin > .pin {
+ font-size: 50px;
+ height: 31%;
+ font-weight: bolder;
+ color: #000000;
+}
+
+.join-auth > .title,
+.join-auth-image > .title,
+.join-authorize > .title {
+ font-size: 18px;
+ height: 28%;
+ font-weight: 800;
+ color: #000000;
+}
+.join-auth > .title {
+ height: 14%;
+}
+.join-auth-image > .title {
+ height: 9%;
+}
+.join-pin > .title {
+ font-size: 28px;
+ height: 20%;
+ font-weight: 800;
+}
+.main-pin > .title {
+ font-size: 30px;
+ height: 14%;
+ font-weight: bolder;
+}
+
+.join-auth > .title-tip,
+.join-auth-image > .title-tip,
+.main-pin > .title-tip,
+.join-authorize > .title-tip {
+ font-size: 15px;
+ height: 14%;
+ color: #5A5A5A;
+}
+.join-auth > .title-tip {
+ height: 14%;
+}
+.join-auth-image > .title-tip {
+ height: 8%;
+}
+.join-auth-image > .title-tip > image {
+ width: 30px;
+ height: 10%;
+ margin: 5px 10px 0 0;
+}
+.join-pin > .title-tip {
+ font-size: 20px;
+ height: 17%;
+ font-weight: 600;
+}
+.main-pin > .title-tip {
+ font-size: 18px;
+ height: 10%;
+ 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: 28% 20px 10% 20px;
+}
+.join-authorize > .dialog-foot {
+ margin: 35% 20px 10% 20px;
+}
+.join-auth-image > .dialog-foot {
+ margin: 3% 20px;
+}
+.join-pin > .dialog-foot {
+ margin: 3% 20px;
+}
+
+.join-auth .button-cancel,
+.join-auth-image .button-cancel,
+.join-authorize .button-cancel {
+ width: 160px;
+ height: 12%;
+}
+.join-pin .button-cancel {
+ width: 100%;
+ font-size: 26px;
+ height: 17%;
+}
+
+.join-auth .button-ok,
+.join-auth-image .button-ok,
+.join-authorize .button-ok {
+ width: 150px;
+ height: 12%;
+}
+
+/* css of wifi page*/
+.join-wifi-container,
+.main-wifi {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 100%;
+}
+
+.input-container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ height: 50%;
+ width: 100%;
+ padding: 2% 15% 2% 15%;
+}
+
+.keyboard-container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ height: 50%;
+ width: 100%;
+ padding: 1%;
+}
+
+.input-title {
+ height: 15%;
+ font-size: 16px;
+ font-weight: bold;
+}
+
+.input-area {
+ border: 1px solid darkgrey;
+ border-radius: 5px;
+ width: 100%;
+ height: 25%;
+ margin-top: 5%;
+}
+
+.button-area {
+ flex-direction: row;
+ justify-content: space-around;
+ align-items: center;
+ height: 25%;
+ margin-top: 5%;
+ width: 80%;
+}
+
+.input-label {
+ width: 20%;
+ font-size: 14px;
+ text-align: center;
+}
+
+.input-text {
+ width: 60%;
+ font-size: 14px;
+ text-align: start;
+ padding-start: 5%;
+ max-lines: 1;
+}
+
+.input-divider {
+ color: darkgrey;
+}
+
+.button-row {
+ flex-direction: row;
+ justify-content: center;
+ height: 23%;
+ width: 100%;
+ margin: 1% 0;
+}
+
+.wifi-button {
+ height: 100%;
+ font-size: 14px;
+}
+
+.keyboard-button {
+ width: 9%;
+ margin: 0 1%;
+ height: 100%;
+ border: 1px solid darkgrey;
+ border-radius: 3px;
+ font-size: 12px;
+ text-align: center;
+}
+
+.join-wifi-text {
+ width: 80%;
+ font-size: 16px;
+ text-align: center;
+ height: 33%;
+}
+
diff --git a/display/entry/src/main/js/MainAbility/pages/index/index.hml b/display/entry/src/main/js/MainAbility/pages/index/index.hml
new file mode 100644
index 0000000000000000000000000000000000000000..fc25d7c0a642b8b71e5d492ad5aded3da45ab7a7
--- /dev/null
+++ b/display/entry/src/main/js/MainAbility/pages/index/index.hml
@@ -0,0 +1,149 @@
+
+
+
+
+
{{ $t('strings.pinCodeConnection') }}
+
{{ $t('strings.enterThePinCode') }}
+
+ {{pin[0]}}
+ {{pin[1]}}
+ {{pin[2]}}
+ {{pin[3]}}
+ {{pin[4]}}
+ {{pin[5]}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{statusInfo.deviceName}}{{ $t('strings.toConnectToThisComputer') }}
+ {{ $t( 'strings.resourceAccess' ) }}
+
+
+
+
+ {{ statusInfo.appName }}
+ {{ $t('strings.applyAuth') }}
+ {{ $t('strings.from') }}{{statusInfo.deviceName}}
+
+
+
+
+
+
+
+ {{ item }}
+ Del
+
+
+ {{ item }}
+ Aa
+
+
+ {{ item }}
+
+
+ {{ item }}
+
+
+
+
+
+ {{wifiInfo.wifiSsid}}
+ 配网成功
+ 配网失败
+
+
+
+
+
+
+
+ {{ statusInfo.appName }}
+
+
{{ $t('strings.applyAuth') }}
+
{{ $t('strings.from') }}{{statusInfo.deviceName}}
+
+
+
+ {{ $t('strings.pinCodeConnection') }}
+ {{ $t('strings.enterDisplayPinCode') }}
+ {{statusInfo.pinCode.split('').join(' ')}}
+
+
+
+
diff --git a/display/entry/src/main/js/MainAbility/pages/index/index.js b/display/entry/src/main/js/MainAbility/pages/index/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..c10c5475c736cdab2d1d3c36728c6183865c3956
--- /dev/null
+++ b/display/entry/src/main/js/MainAbility/pages/index/index.js
@@ -0,0 +1,523 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import 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:";
+
+const AUTH_TYPE_PIN = 1
+const AUTH_TYPE_WIFI = 2
+
+const LOWER_CASE_KEYS = {
+ line1 : ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
+ line2 : ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
+ line3 : [',', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '.'],
+ line4 : [';', '*', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '-', '_'],
+}
+const UPPER_CASE_KEYS = {
+ line1 : ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
+ line2 : ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
+ line3 : [',', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '.'],
+ line4 : [';', '*', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '-', '_'],
+}
+
+const CURRENT_FOCUS_SSID = 0
+const CURRENT_FOCUS_KEY = 1
+
+const USER_WIFI_CANCEL_CODE = 5
+
+const ACTIVE_COLOR = '#fff'
+const INACTIVE_COLOR = '#ddd'
+
+const WIFI_CONFIGURE_SUCCESS = 0
+const WIFI_CONFIGURE_FAILED = 1
+const WIFI_CONFIGURE_DOING = 2
+const WIFI_CONFIGURE_DEFAULT = -1
+
+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,
+ appThumbnail: null,
+ pinCode: '',
+ pinToken: ''
+ },
+ // join: join-authorize timing
+ timeRemaining: 0,
+ // input pinCode
+ pin: ['','','','','',''],
+ // input pinCode next number
+ pinNumb: 0,
+ wifiInfo: {
+ wifiSsid: '',
+ wifiPassword: ''
+ },
+ keyboardItem : LOWER_CASE_KEYS,
+ isSSidFocus : false,
+ isKeyFocus : false,
+ currentSsidColor : INACTIVE_COLOR,
+ currentKeyColor : INACTIVE_COLOR,
+ configureResult : WIFI_CONFIGURE_DEFAULT
+ },
+
+ log(m) {
+ console.info(TAG + m);
+ },
+
+ onDestroy() {
+ this.log("onDestroy")
+ if (dmClass != null) {
+ dmClass.off('dmFaCallback');
+ dmClass.off('deviceStateChange');
+ dmClass.off('serviceDie');
+ dmClass.release();
+ dmClass = null
+ }
+ },
+
+ onShow() {
+ if (dmClass) {
+ this.log('deviceManager exist')
+ 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', () => {
+ this.log("dmFaCallback executed, dialog closed")
+ router.back()
+ })
+ this.initStatue()
+ });
+ }
+ },
+
+ onHide() {
+ this.log('onHide')
+ this.timeRemaining = 0
+ },
+
+ /**
+ * Get authentication param
+ */
+ initStatue() {
+ this.log('initStatue')
+ const data = dmClass.getFaParam();
+ this.log('getFaParam:' + JSON.stringify(data))
+ // const data = dmClas icationParam:' + JSON.stringify(data))
+ // Authentication type, 1 for pin code.
+ if(data&&!data.FaType){
+ return;
+ }
+ if (data && data.FaType == 1) {
+ this.log('initStatue:data.FaType == 1' )
+ let authParam = data.authParam
+ this.log('initStatue authParam: ' +authParam )
+ this.statusInfo = {
+ deviceName: authParam.extraInfo.PackageName,
+ appName: authParam.extraInfo.appName,
+ appIcon: uint8ArrayToBase64(authParam.appIcon),
+ appThumbnail: uint8ArrayToBase64(authParam.appThumbnail),
+ pinCode: authParam.extraInfo.pinCode + '',
+ pinToken: authParam.extraInfo.pinToken
+ }
+ this.log('initStatue statusInfo: ' +this.statusInfo )
+ // direction: 1(main)/0(join)
+ if (authParam.extraInfo.direction == 1) {
+ this.log('initStatue statusInfo: authParam.extraInfo.direction == 1')
+ this.mainPin()
+ } else if (authParam.appIcon) {
+ this.log('initStatue statusInfo:authParam.appIcon == 1')
+ this.joinAuthImage()
+ } else if (authParam.extraInfo.business == 0) {
+ // business: 0(FA流转)/1(资源访问)
+ this.log('initStatue statusInfo:authParam.extraInfo.business == 0')
+ this.joinAuth()
+ } else {
+ this.log('initStatue join')
+ this.joinAuthorize()
+ }
+ }
+ this.log('initStatue wifi start')
+ if (data && data.FaType == AUTH_TYPE_WIFI && data.ConWifiParam == WIFI_CONFIGURE_DOING) {
+ this.log("show main wifi page")
+ this.mainWifi()
+ }
+
+ if (data && data.FaType == AUTH_TYPE_WIFI && data.ConWifiParam != WIFI_CONFIGURE_DOING) {
+ this.log("show join wifi page")
+ let wifiParam = data.conWifiParam
+ this.wifiInfo.wifiSsid = wifiParam.wifiSsid;
+ this.configureResult = wifiParam.configureResult
+ this.joinWifi()
+ }
+ },
+
+ /**
+ * 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'
+ this.log("mainPin")
+ },
+
+ /**
+ * 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] =
+ ++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(''))
+ router.back()
+ }
+ this.log("mainInputPin")
+ },
+
+ /**
+ * Keyboard delete number
+ */
+ mainInputPinBack() {
+ if (this.pinNumb > 0) {
+ --this.pinNumb
+ this.pin[this.pinNumb] = ''
+ this.pin = [...this.pin]
+ }
+ this.log("mainInputPinBack")
+ },
+
+ /**
+ * Cancel pinCode input
+ */
+ mainInputPinCancel() {
+ this.setUserOperation(4)
+ router.back()
+ this.log("mainInputPinCancel")
+ },
+
+ /**
+ * Main end wifiInfo input Page display
+ */
+ mainWifi() {
+ this.status = 'main-wifi'
+ this.log(" this.status = 'main-wifi'")
+ },
+
+ /**
+ * Join end presents wifi configure result
+ */
+ joinWifi() {
+ this.status = 'join-wifi'
+ this.log(" this.status = 'join-wifi'")
+ },
+
+ /**
+ * Cancel current operation
+ */
+ mainWifiCancel() {
+ this.log(' mainWifiCancel')
+ this.setUserOperation(USER_WIFI_CANCEL_CODE)
+ router.back()
+ },
+
+ /**
+ * main end wifi ssid and pwd confirm
+ */
+ mainWifiConfirm() {
+ this.log(' mainWifiConfirm')
+ dmClass.configureWifiInfo(this.wifiInfo, (err, data) => {
+ this.log('configureWifiInfo callback err = ' + err)
+ this.log('mainWifiConfirm + wifiSsid = ' + this.wifiInfo.wifiSsid)
+ })
+ router.back();
+ },
+
+ /**
+ * Cancel result dialog
+ */
+ joinWifiCancel() {
+ this.log("joinWifiCancel")
+ router.back()
+ },
+
+ /**
+ * 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.log("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.log("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.log("timing")
+ this.timeRemaining = numb
+ const next = () => {
+ if (status != this.status) return
+ --this.timeRemaining
+ if (this.timeRemaining > 0) {
+ setTimeout(next, 1000)
+ } else {
+ callback()
+ }
+ }
+ next()
+ },
+
+ /**
+ * Change keyboard focus in wifi page
+ * @param currentArea - area that user clicked
+ */
+ changeFocus(currentArea) {
+ this.log("changeFocus" )
+ if (currentArea == CURRENT_FOCUS_SSID) {
+ this.isSSidFocus = true
+ this.currentSsidColor = ACTIVE_COLOR
+
+ this.isKeyFocus = false
+ this.currentKeyColor = INACTIVE_COLOR
+ }
+ if (currentArea == CURRENT_FOCUS_KEY) {
+ this.isSSidFocus = false
+ this.currentSsidColor = INACTIVE_COLOR
+
+ this.isKeyFocus = true
+ this.currentKeyColor = ACTIVE_COLOR
+ }
+ },
+
+ /**
+ * Change input case to upper case or lower case
+ */
+ changeCase() {
+ this.log("changeCase" )
+ if (this.keyboardItem == LOWER_CASE_KEYS) {
+ this.keyboardItem = UPPER_CASE_KEYS;
+ } else {
+ this.keyboardItem = LOWER_CASE_KEYS;
+ }
+ },
+
+ /**
+ * Add char to the selected input area
+ * @param itemChar - the char in the button that user clicked
+ */
+ inputChar(itemChar) {
+ this.log("inputChar :"+itemChar)
+ if (this.isSSidFocus == true) {
+ this.ssidString = this.ssidString + itemChar
+ }
+ if (this.isKeyFocus == true) {
+ this.keyString = this.keyString + itemChar
+ }
+ },
+
+ /**
+ * Remove the first char of the selected input area
+ */
+ deleteChar() {
+ this.log("deleteChar")
+ if (this.isSSidFocus == true && this.ssidString.length > 0) {
+ this.ssidString = this.ssidString.substring(0, this.ssidString.length - 1)
+ }
+ if (this.isKeyFocus == true && this.keyString.length > 0) {
+ this.keyString = this.keyString.substring(0, this.keyString.length - 1)
+ }
+ },
+}
diff --git a/display/entry/src/main/resources/base/element/string.json b/display/entry/src/main/resources/base/element/string.json
index 0bae6bd40f7360d5d818998221b199d3ec0f69c0..a1f1955bd73dedf20dda7d9c0d1404c4591429fb 100644
--- a/display/entry/src/main/resources/base/element/string.json
+++ b/display/entry/src/main/resources/base/element/string.json
@@ -2,10 +2,10 @@
"string": [
{
"name": "entry_MainAbility",
- "value": "entry_MainAbility"
+ "value": "DeviceManagerUI"
},
{
- "name": "mainability_description",
+ "name": "description_mainability",
"value": "JS_Empty Ability"
}
]
diff --git a/ext/no_interaction_auth/BUILD.gn b/ext/no_interaction_auth/BUILD.gn
index b56f7543ae81b6cfb310f221f1328314c7b88b9c..76d847f9fc356958e9d465eafa41e2812f8bd699 100644
--- a/ext/no_interaction_auth/BUILD.gn
+++ b/ext/no_interaction_auth/BUILD.gn
@@ -66,7 +66,6 @@ if (defined(ohos_lite)) {
deps = [
"${aainnerkits_path}/ability_manager:ability_manager",
- "${aainnerkits_path}/want:want",
"${aaservices_path}/abilitymgr:abilityms",
"${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
@@ -76,6 +75,7 @@ if (defined(ohos_lite)) {
]
external_deps = [
+ "ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"common_event_service:cesfwk_core",
diff --git a/ext/no_interaction_auth/include/no_interaction_auth.h b/ext/no_interaction_auth/include/no_interaction_auth.h
index 3675a0650ae45c590bdc0e48ede1622606f76ecf..30d91dab848ec3edf06626db809d75802324caec 100644
--- a/ext/no_interaction_auth/include/no_interaction_auth.h
+++ b/ext/no_interaction_auth/include/no_interaction_auth.h
@@ -33,6 +33,7 @@ public:
int32_t StartAuth(std::string &authToken, std::shared_ptr authManager) override;
int32_t VerifyAuthentication(std::string &authToken, const std::string &authParam) override;
int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) override;
+ int32_t UpdateAuthInfo(const int32_t &pageId) override;
};
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/ext/no_interaction_auth/src/no_interaction_auth.cpp b/ext/no_interaction_auth/src/no_interaction_auth.cpp
index 93b78304754e7b67e502221365b7db543aab7ecc..2dff14318e5a64ed792fd76f007cdd237e52bf7e 100644
--- a/ext/no_interaction_auth/src/no_interaction_auth.cpp
+++ b/ext/no_interaction_auth/src/no_interaction_auth.cpp
@@ -52,6 +52,11 @@ int32_t NoInteractionAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptr<
return DM_OK;
}
+int32_t NoInteractionAuth::UpdateAuthInfo(const int32_t &pageId)
+{
+ return DM_OK;
+}
+
extern "C" IAuthentication *CreatePinAuthObject(void)
{
return new NoInteractionAuth;
diff --git a/ext/pin_auth/BUILD.gn b/ext/pin_auth/BUILD.gn
index 7040cf99135c99d0ffc5866265c96187909f7c94..90d93114ee147b4338460400941cb8ff88578d6f 100644
--- a/ext/pin_auth/BUILD.gn
+++ b/ext/pin_auth/BUILD.gn
@@ -135,7 +135,6 @@ if (defined(ohos_lite)) {
deps = [
"${aainnerkits_path}/ability_manager:ability_manager",
- "${aainnerkits_path}/want:want",
"${aaservices_path}/abilitymgr:abilityms",
"${ext_path}/pin_auth/input_pin_dialog/dialog_ui/js:dialog_js_files_etc",
"${ext_path}/pin_auth/show_pin_dialog/dialog_ui/js:dialog_js_files_etc",
@@ -148,6 +147,7 @@ if (defined(ohos_lite)) {
]
external_deps = [
+ "ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"common_event_service:cesfwk_core",
diff --git a/ext/pin_auth/include/lite/pin_auth_ui.h b/ext/pin_auth/include/lite/pin_auth_ui.h
index aad43c50587766bf4a8966f6e809183f71ece39d..3337829c43a22377fd825a47b46e47df1781cfd2 100644
--- a/ext/pin_auth/include/lite/pin_auth_ui.h
+++ b/ext/pin_auth/include/lite/pin_auth_ui.h
@@ -42,7 +42,7 @@ public:
* @tc.desc: Show Input PinDialog
* @tc.type: FUNC
*/
- int32_t InputPinDialog(int32_t code, std::shared_ptr authManager);
+ int32_t InputPinDialog(std::shared_ptr authManager);
/**
* @tc.name: PinAuthUi::ClosePage
* @tc.desc: Close Page
@@ -50,6 +50,13 @@ public:
*/
int32_t ClosePage(const int32_t &pageId, std::shared_ptr authManager);
+ /**
+ * @tc.name: PinAuth::UpdateAuthInfo
+ * @tc.desc: Update the page information
+ * @tc.type: FUNC
+ */
+ int32_t UpdatePinDialog(int32_t pageId);
+
private:
int32_t StartFaUiService(std::shared_ptr dmAbilityManager);
};
diff --git a/ext/pin_auth/include/pin_auth.h b/ext/pin_auth/include/pin_auth.h
index 13afc8cd2fc88a00c76b421c4719689a5183865d..4e2b0b4ac507249c4dece22e1ae3dedb1ef8c37d 100644
--- a/ext/pin_auth/include/pin_auth.h
+++ b/ext/pin_auth/include/pin_auth.h
@@ -58,6 +58,14 @@ public:
* @tc.type: FUNC
*/
int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) override;
+
+ /**
+ * @tc.name: PinAuth::UpdateAuthInfo
+ * @tc.desc: Update Auth Info of the PinAuth
+ * @tc.type: FUNC
+ */
+ int32_t UpdateAuthInfo(const int32_t &pageId) override;
+
private:
int32_t times_ = 0;
std::shared_ptr pinAuthUi_;
diff --git a/ext/pin_auth/include/standard/pin_auth_ui.h b/ext/pin_auth/include/standard/pin_auth_ui.h
index 7c59415265145e81512e62186f69f0c099a77e0e..bb9e2742c2aacd7af10b0877e5656df2a7959ba5 100644
--- a/ext/pin_auth/include/standard/pin_auth_ui.h
+++ b/ext/pin_auth/include/standard/pin_auth_ui.h
@@ -27,9 +27,9 @@ class PinAuthUi {
public:
PinAuthUi();
int32_t ShowPinDialog(int32_t code, std::shared_ptr authManager);
- int32_t InputPinDialog(int32_t code, std::shared_ptr authManager);
+ int32_t InputPinDialog(std::shared_ptr authManager);
int32_t ClosePage(const int32_t &pageId, std::shared_ptr authManager);
-
+ int32_t UpdatePinDialog(int32_t pageId);
private:
int32_t StartFaUiService(std::shared_ptr dmAbilityManager);
};
diff --git a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml
index 0d0451017fefa6eac27d3bbaba14c4e150fc837c..a82024d3bd4a47d7e7566cf7037c5d89e6845fa0 100644
--- a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml
+++ b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml
@@ -22,7 +22,7 @@
请输入另一个设备显示的PIN码进行验证
-
+
PIN码输入错误,请重新输入(3次:还有{{isTimes}}次机会)
diff --git a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js
index 48a242f2dc32917aa39b17556c37cfa62439a60f..c897f8794d6d3781bfca299abf31a4d04ed20c1d 100644
--- a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js
+++ b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js
@@ -15,51 +15,37 @@
import router from '@ohos.router';
-var numbs = 0;
-var code = 0;
-var inputVal = 0;
+var inputValue;
var EVENT_CONFIRM = "EVENT_CONFIRM";
var EVENT_CANCEL = "EVENT_CANCEL";
var EVENT_INIT = "EVENT_INIT";
-var EVENT_CONFIRM_CODE = "0";
var EVENT_CANCEL_CODE = "1";
var EVENT_INIT_CODE = "2";
+
export default {
data: {
- pincode: router.getParams().pinCode,
- isShow:false,
- isTimes:3,
+ inputValue: "",
+ isShow: false,
+ isTimes: 3,
},
onInit() {
- code = router.getParams().pinCode;
callNativeHandler(EVENT_INIT, EVENT_INIT_CODE);
},
- onChange(e){
- inputVal = e.value;
- },
+ onChange(e){
+ inputValue = e.value;
+ },
onConfirm() {
- numbs = numbs + 1;
- if(numbs <= 3){
- console.info('click confirm numbs < 3 ');
- if(code == inputVal){
- console.info('click confirm code == inputVal');
- callNativeHandler(EVENT_CONFIRM, EVENT_CONFIRM_CODE);
- }else{
- if(numbs == 3){
- console.info('click confirm code != inputVal and numbs == 3');
- callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE);
- }
- console.info('click confirm code != inputVal');
- this.isShow = true;
- this.isTimes = 3 - numbs;
- }
- }else{
- console.info('click confirm numbs > 3 ');
- callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE);
- }
+ if ((inputValue == null) || (inputValue == "")) {
+ return;
+ }
+ this.isTimes--;
+ callNativeHandler(EVENT_CONFIRM, inputValue);
},
onCancel() {
console.info('click cancel');
callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE);
+ },
+ onDialogUpdatedd(param) {
+ this.isShow = param.verifyFailed;
}
}
\ No newline at end of file
diff --git a/ext/pin_auth/src/lite/pin_auth_ui.cpp b/ext/pin_auth/src/lite/pin_auth_ui.cpp
index 205d32762cd7d63a0ec16e463657fd81a68dc671..70a59406323baad054d243b47291acd7223c7fa1 100644
--- a/ext/pin_auth/src/lite/pin_auth_ui.cpp
+++ b/ext/pin_auth/src/lite/pin_auth_ui.cpp
@@ -33,7 +33,7 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au
return DM_OK;
}
-int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager)
+int32_t PinAuthUi::InputPinDialog(std::shared_ptr authManager)
{
LOGI("InputPinDialog start");
std::shared_ptr dmAbilityManager_ = std::make_shared();
@@ -66,5 +66,10 @@ int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityM
}
return DM_OK;
}
+
+int32_t PinAuthUi::UpdatePinDialog(int32_t pageId)
+{
+ return DM_OK;
+}
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp
index a746406f9513d27e0ae937bd81183b15efca4116..5ae4f09a8518e0a603b12378feb2b8ca1fac3181 100644
--- a/ext/pin_auth/src/pin_auth.cpp
+++ b/ext/pin_auth/src/pin_auth.cpp
@@ -51,16 +51,7 @@ int32_t PinAuth::ShowAuthInfo(std::string &authToken, std::shared_ptr authManager)
{
- nlohmann::json jsonObject = nlohmann::json::parse(authToken, nullptr, false);
- if (jsonObject.is_discarded()) {
- LOGE("DecodeRequestAuth jsonStr error");
- return ERR_DM_FAILED;
- }
- if (!jsonObject.contains(PIN_CODE_KEY)) {
- LOGE("err json string, first time");
- return ERR_DM_FAILED;
- }
- return pinAuthUi_->InputPinDialog(jsonObject[PIN_CODE_KEY], authManager);
+ return pinAuthUi_->InputPinDialog(authManager);
}
int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam)
@@ -106,6 +97,11 @@ int32_t PinAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptrClosePage(pageId, authManager);
}
+int32_t PinAuth::UpdateAuthInfo(const int32_t &pageId)
+{
+ return pinAuthUi_->UpdatePinDialog(pageId);
+}
+
extern "C" IAuthentication *CreatePinAuthObject(void)
{
return new PinAuth;
diff --git a/ext/pin_auth/src/standard/pin_auth_ui.cpp b/ext/pin_auth/src/standard/pin_auth_ui.cpp
index 6e349747a3a763b568e6c41aa26daa0edd979185..d702ca37a644b065d003db1d7a04d8a87b924304 100644
--- a/ext/pin_auth/src/standard/pin_auth_ui.cpp
+++ b/ext/pin_auth/src/standard/pin_auth_ui.cpp
@@ -58,7 +58,7 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au
return DM_OK;
}
-int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager)
+int32_t PinAuthUi::InputPinDialog(std::shared_ptr authManager)
{
LOGI("InputPinDialog start");
if (authManager == nullptr) {
@@ -66,7 +66,7 @@ int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr a
return ERR_DM_FAILED;
}
nlohmann::json jsonObj;
- jsonObj[PIN_CODE_KEY] = code;
+ jsonObj[VERIFY_FAILED] = false;
jsonObj.dump();
const std::string params = jsonObj.dump();
@@ -76,13 +76,21 @@ int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr a
OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT,
[authManager](int32_t id, const std::string& event, const std::string& params) {
- if (params == EVENT_INIT_CODE) {
- authManager->SetPageId(id);
- }
- if (params == EVENT_CANCEL_CODE || params == EVENT_CONFIRM_CODE) {
- Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id);
- LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str());
- authManager->VerifyAuthentication(params.c_str());
+ switch (event) {
+ case EVENT_INIT:
+ authManager->SetPageId(id);
+ break;
+ case EVENT_CONFIRM:
+ LOGI("On confirm event for page id:%d, parms:%s", id, params.c_str());
+ if (params.length() == DEFAULT_PIN_CODE_LENGTH) {
+ authManager->AddMember(std::stoi(params));
+ } else {
+ UpdatePinDialog(id);
+ }
+ break;
+ default:
+ authManager->SetReasonAndFinish(ERR_DM_AUTH_INPUT_PARAMETER_FAILED, AuthState::AUTH_REQUEST_JOIN);
+ break;
}
});
LOGI("ShowConfigDialog end");
@@ -97,6 +105,18 @@ int32_t PinAuthUi::ClosePage(const int32_t &pageId, std::shared_ptrUpdateDialog(pageId, params);
+ LOGI("UpdatePinDialog end");
+ return DM_OK;
+}
+
int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityManager)
{
AbilityStatus status = dmAbilityManager->StartAbility(AbilityRole::ABILITY_ROLE_INITIATIVE);
diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp
index 379dd0ef65388f807d2154d36bf850d8418e2abb..b330c97f4c8ca1df75f0e1670388c3c1980c761b 100644
--- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp
+++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp
@@ -29,7 +29,7 @@ int32_t IpcClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa
auto remoteDescriptor = data.ReadInterfaceToken();
if (GetDescriptor() != remoteDescriptor) {
LOGI("ReadInterfaceToken fail!");
- return ERR_INVALID_STATE;
+ return ERR_DM_IPC_READ_TOKEN_FAILED;
}
if (IpcCmdRegister::GetInstance().OnIpcCmd((int32_t)code, data, reply) == DM_OK) {
diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h
index 8db0b602289e72159620283e76511310c2349748..3efde146310b50444df7a5a5163b74f9ab270169 100644
--- a/interfaces/kits/js/include/native_devicemanager_js.h
+++ b/interfaces/kits/js/include/native_devicemanager_js.h
@@ -25,6 +25,7 @@
#include "dm_native_event.h"
#include "dm_subscribe_info.h"
#include "dm_anonymous.h"
+#include "dm_error_message.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "nlohmann/json.hpp"
diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp
index f057d9cf68b7795166752c27fd12e80b38aa5852..b52d5b277ed1c4a3a94530d3c9f3c531d7b7d8dd 100644
--- a/interfaces/kits/js/src/native_devicemanager_js.cpp
+++ b/interfaces/kits/js/src/native_devicemanager_js.cpp
@@ -46,7 +46,7 @@ const int32_t DM_NAPI_ARGS_TWO = 2;
const int32_t DM_NAPI_ARGS_THREE = 3;
const int32_t DM_NAPI_SUB_ID_MAX = 65535;
const int32_t DM_AUTH_DIRECTION_CLIENT = 1;
-const int32_t DM_AUTH_REQUEST_SUCCESS_STATUS = 8;
+const int32_t DM_AUTH_REQUEST_SUCCESS_STATUS = 7;
napi_ref deviceTypeEnumConstructor_ = nullptr;
napi_ref deviceStateChangeActionEnumConstructor_ = nullptr;
@@ -93,15 +93,13 @@ void DmNapiInitCallback::OnRemoteDied()
return;
}
deviceManagerNapi->OnEvent("serviceDie", 0, nullptr);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnRemoteDied work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
@@ -129,15 +127,13 @@ void DmNapiDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo &deviceInfo)
return;
}
deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::ONLINE, callback->deviceInfo_);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnDeviceOnline work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
@@ -165,15 +161,13 @@ void DmNapiDeviceStateCallback::OnDeviceReady(const DmDeviceInfo &deviceInfo)
return;
}
deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::READY, callback->deviceInfo_);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnDeviceReady work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
@@ -201,15 +195,13 @@ void DmNapiDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo &deviceInfo)
return;
}
deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::OFFLINE, callback->deviceInfo_);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnDeviceOffline work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
@@ -227,7 +219,9 @@ void DmNapiDeviceStateCallback::OnDeviceChanged(const DmDeviceInfo &deviceInfo)
}
jsCallback_ = std::make_unique(bundleName_, 0, 0, deviceInfo);
- work->data = reinterpret_cast(jsCallback_.get());
+ if (work != nullptr) {
+ work->data = reinterpret_cast(jsCallback_.get());
+ }
int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) {
DmNapiStateJsCallback *callback = reinterpret_cast(work->data);
@@ -237,15 +231,13 @@ void DmNapiDeviceStateCallback::OnDeviceChanged(const DmDeviceInfo &deviceInfo)
return;
}
deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::CHANGE, callback->deviceInfo_);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnDeviceChanged work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
@@ -275,15 +267,13 @@ void DmNapiDiscoveryCallback::OnDeviceFound(uint16_t subscribeId, const DmDevice
return;
}
deviceManagerNapi->OnDeviceFound(callback->subscribeId_, callback->deviceInfo_);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnDeviceFound work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
@@ -314,15 +304,13 @@ void DmNapiDiscoveryCallback::OnDiscoveryFailed(uint16_t subscribeId, int32_t fa
return;
}
deviceManagerNapi->OnDiscoveryFailed(callback->subscribeId_, callback->reason_);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnDiscoveryFailed work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
@@ -376,15 +364,13 @@ void DmNapiAuthenticateCallback::OnAuthResult(const std::string &deviceId, const
return;
}
deviceManagerNapi->OnAuthResult(callback->deviceId_, callback->token_, callback->status_, callback->reason_);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnAuthResult work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
@@ -412,15 +398,13 @@ void DmNapiVerifyAuthCallback::OnVerifyAuthResult(const std::string &deviceId, i
return;
}
deviceManagerNapi->OnVerifyResult(callback->deviceId_, callback->resultCode_, callback->flag_);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnVerifyAuthResult work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
@@ -489,6 +473,8 @@ void DeviceManagerNapi::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedRe
napi_create_object(env_, &result);
SetValueInt32(env_, "subscribeId", (int)subscribeId, result);
SetValueInt32(env_, "reason", (int)failedReason, result);
+ std::string errCodeInfo = OHOS::DistributedHardware::GetErrorString((int)failedReason);
+ SetValueUtf8String(env_, "errInfo", errCodeInfo, result);
OnEvent("discoverFail", DM_NAPI_ARGS_ONE, &result);
}
@@ -510,6 +496,8 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str
napi_create_object(env_, &result[0]);
SetValueInt32(env_, "code", status, result[0]);
SetValueInt32(env_, "reason", reason, result[0]);
+ std::string errCodeInfo = OHOS::DistributedHardware::GetErrorString((int)reason);
+ SetValueUtf8String(env_, "errInfo", errCodeInfo, result[0]);
napi_get_undefined(env_, &result[1]);
}
@@ -1152,15 +1140,13 @@ void DmNapiDeviceManagerFaCallback::OnCall(const std::string ¶mJson)
return;
}
deviceManagerNapi->OnDmfaCall(callback->token_);
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
});
if (ret != 0) {
LOGE("Failed to execute OnCall work queue");
- if (work != nullptr) {
- delete work;
- }
+ delete work;
+ work = nullptr;
}
}
diff --git a/interfaces/kits/js_mini/include/native_devicemanager_js.h b/interfaces/kits/js_mini/include/native_devicemanager_js.h
index c161d694157d9c754ca07cf51beb058642e2f5b8..a786bc7d38947f997dd3ca7096e24e22d4056945 100644
--- a/interfaces/kits/js_mini/include/native_devicemanager_js.h
+++ b/interfaces/kits/js_mini/include/native_devicemanager_js.h
@@ -32,7 +32,7 @@
namespace OHOS {
namespace ACELite {
#define DM_JSI_BUF_LENGTH (256)
-#define DM_JSI_AUTH_REQUEST_FINISH (8)
+#define DM_JSI_AUTH_REQUEST_FINISH (7)
struct AuthFuncParams {
JSIValue handlerRef = JSI::CreateUndefined();
diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn
index 23a42d80d2a43dbe6eac49555dde6314e6fb5db3..1c748cc3797d73608240f693bfbccc9a2f76f82c 100755
--- a/services/devicemanagerservice/BUILD.gn
+++ b/services/devicemanagerservice/BUILD.gn
@@ -300,7 +300,6 @@ if (defined(ohos_lite)) {
deps = [
"${aainnerkits_path}/ability_manager:ability_manager",
- "${aainnerkits_path}/want:want",
"${aaservices_path}/abilitymgr:abilityms",
"${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
@@ -320,6 +319,7 @@ if (defined(ohos_lite)) {
defines += [ "SUPPORT_GRAPHICS" ]
}
external_deps = [
+ "ability_base:want",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
diff --git a/services/devicemanagerservice/include/authentication/auth_request_state.h b/services/devicemanagerservice/include/authentication/auth_request_state.h
index 35d5cfde1541c6f297af9109bc18b2a4a6d4170b..647ce7db1dd9fbb41a13b49d9e23f4ce7c791ac0 100644
--- a/services/devicemanagerservice/include/authentication/auth_request_state.h
+++ b/services/devicemanagerservice/include/authentication/auth_request_state.h
@@ -131,23 +131,6 @@ public:
int32_t Enter() override;
};
-class AuthRequestInputState : public AuthRequestState {
-public:
- /**
- * @tc.name: AuthRequestInputState::GetStateType
- * @tc.desc: Get State Type of the AuthRequest Input State
- * @tc.type: FUNC
- */
- int32_t GetStateType() override;
-
- /**
- * @tc.name: AuthRequestInputState::Enter
- * @tc.desc: Enter of the AuthRequest Input State
- * @tc.type: FUNC
- */
- int32_t Enter() override;
-};
-
class AuthRequestJoinState : public AuthRequestState {
public:
/**
diff --git a/services/devicemanagerservice/include/authentication/authentication.h b/services/devicemanagerservice/include/authentication/authentication.h
index b5f8db04489c53e8706954b64fb009856869598a..3017683796352f4b80a71eeb2a9745460ce743d9 100644
--- a/services/devicemanagerservice/include/authentication/authentication.h
+++ b/services/devicemanagerservice/include/authentication/authentication.h
@@ -28,6 +28,7 @@ public:
virtual int32_t StartAuth(std::string &authToken, std::shared_ptr authManager) = 0;
virtual int32_t VerifyAuthentication(std::string &authToken, const std::string &authParam) = 0;
virtual int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) = 0;
+ virtual int32_t UpdateAuthInfo(const int32_t &pageId) = 0;
};
using CreateIAuthAdapterFuncPtr = IAuthentication *(*)(void);
diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h
index c5f69a69c6b8ec6253a3bbdc5b4111061ec301d2..83726a5f8f684b6f7c8b270bd7bfa3d45e23ec3a 100644
--- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h
+++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h
@@ -39,7 +39,6 @@ typedef enum AuthState {
AUTH_REQUEST_NEGOTIATE,
AUTH_REQUEST_NEGOTIATE_DONE,
AUTH_REQUEST_REPLY,
- AUTH_REQUEST_INPUT,
AUTH_REQUEST_JOIN,
AUTH_REQUEST_NETWORK,
AUTH_REQUEST_FINISH,
@@ -238,7 +237,7 @@ public:
* @tc.desc: Add Member of the DeviceManager Authenticate Manager
* @tc.type: FUNC
*/
- int32_t AddMember(const std::string &deviceId);
+ int32_t AddMember(int32_t pinCode);
/**
* @tc.name: DmAuthManager::GetConnectAddr
@@ -367,11 +366,11 @@ public:
int32_t SetPageId(int32_t pageId);
/**
- * @tc.name: DmAuthManager::SetReason
+ * @tc.name: DmAuthManager::SetReasonAndFinish
* @tc.desc: Set Reason of the DeviceManager Authenticate Manager
* @tc.type: FUNC
*/
- int32_t SetReason(int32_t reason, int32_t state);
+ int32_t SetReasonAndFinish(int32_t reason, int32_t state);
private:
std::shared_ptr softbusConnector_;
@@ -388,6 +387,8 @@ private:
std::shared_ptr dmAbilityMgr_;
bool isCryptoSupport_ = false;
bool isFinishOfLocal_ = true;
+ int32_t authTimes_ = 0;
+ std::shared_ptr authPtr_;
};
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/services/devicemanagerservice/include/discovery/dm_discovery_manager.h b/services/devicemanagerservice/include/discovery/dm_discovery_manager.h
index 135be035c0b3435d1f085e5b45cb7ef252e58cd9..7234c97a157c25adb38c927114ed5f4feab8261d 100644
--- a/services/devicemanagerservice/include/discovery/dm_discovery_manager.h
+++ b/services/devicemanagerservice/include/discovery/dm_discovery_manager.h
@@ -85,6 +85,7 @@ private:
std::queue discoveryQueue_;
std::map discoveryContextMap_;
std::shared_ptr timer_;
+ std::mutex locks_;
};
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/services/devicemanagerservice/src/authentication/auth_request_state.cpp b/services/devicemanagerservice/src/authentication/auth_request_state.cpp
index 7163671855bc15d4ad2876b6d516fbfa100b2ccd..94ea2544ae0b04f9c7d2f02e5a59ad324cea2313 100644
--- a/services/devicemanagerservice/src/authentication/auth_request_state.cpp
+++ b/services/devicemanagerservice/src/authentication/auth_request_state.cpp
@@ -122,23 +122,6 @@ int32_t AuthRequestReplyState::Enter()
return DM_OK;
}
-int32_t AuthRequestInputState::GetStateType()
-{
- return AuthState::AUTH_REQUEST_INPUT;
-}
-
-int32_t AuthRequestInputState::Enter()
-{
- LOGI("DmAuthManager::AuthRequestInputState");
- std::shared_ptr stateAuthManager = authManager_.lock();
- if (stateAuthManager == nullptr) {
- LOGE("AuthRequestState::authManager_ null");
- return ERR_DM_FAILED;
- }
- stateAuthManager->ShowStartAuthDialog();
- return DM_OK;
-}
-
int32_t AuthRequestJoinState::GetStateType()
{
return AuthState::AUTH_REQUEST_JOIN;
@@ -152,7 +135,7 @@ int32_t AuthRequestJoinState::Enter()
LOGE("AuthRequestState::authManager_ null");
return ERR_DM_FAILED;
}
- stateAuthManager->AddMember(context_->deviceId);
+ stateAuthManager->ShowStartAuthDialog();
return DM_OK;
}
diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp
index ff50edcfa09da866a0c1a98a6c98cb279af32956..450829e4e5e3f645e022352474acee17d961fca9 100644
--- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp
+++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp
@@ -40,6 +40,7 @@ const int32_t WAIT_NEGOTIATE_TIMEOUT = 10;
const int32_t WAIT_REQUEST_TIMEOUT = 10;
const int32_t CANCEL_PIN_CODE_DISPLAY = 1;
const int32_t DEVICE_ID_HALF = 2;
+const int32_t MAX_AUTH_TIMES = 3;
DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector,
std::shared_ptr listener,
@@ -84,6 +85,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au
return ERR_DM_INPUT_PARAMETER_EMPTY;
}
+ authPtr_ = authenticationMap_[authType];
if (timer_ == nullptr) {
timer_ = std::make_shared();
}
@@ -160,14 +162,8 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam)
LOGE("authResponseContext_ is not init");
return ERR_DM_AUTH_NOT_START;
}
- std::shared_ptr ptr;
- if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
- LOGE("DmAuthManager::authenticationMap_ is null");
- return ERR_DM_FAILED;
- }
timer_->DeleteTimer(INPUT_TIMEOUT_TASK);
- ptr = authenticationMap_[authResponseContext_->authType];
- int32_t ret = ptr->VerifyAuthentication(authResponseContext_->authToken, authParam);
+ int32_t ret = authPtr_->VerifyAuthentication(authResponseContext_->authToken, authParam);
switch (ret) {
case DM_OK:
authRequestState_->TransitionTo(std::make_shared());
@@ -314,7 +310,7 @@ void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string me
void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId)
{
- LOGI("DmAuthManager::OnGroupCreated start");
+ LOGI("DmAuthManager::OnGroupCreated start group id %s", groupId.c_str());
if (authResponseState_ == nullptr) {
LOGE("DmAuthManager::AuthenticateDevice end");
return;
@@ -329,11 +325,11 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId
int32_t pinCode = GeneratePincode();
nlohmann::json jsonObj;
- jsonObj[PIN_CODE_KEY] = pinCode;
jsonObj[PIN_TOKEN] = authResponseContext_->token;
jsonObj[QR_CODE_KEY] = GenerateGroupName();
jsonObj[NFC_CODE_KEY] = GenerateGroupName();
authResponseContext_->authToken = jsonObj.dump();
+ LOGI("DmAuthManager::OnGroupCreated start group id %s", groupId.c_str());
authResponseContext_->groupId = groupId;
authResponseContext_->code = pinCode;
authMessageProcessor_->SetResponseContext(authResponseContext_);
@@ -344,24 +340,31 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId
void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status)
{
- LOGI("DmAuthManager OnMemberJoin start");
+ LOGI("DmAuthManager OnMemberJoin start authTimes %d", authTimes_);
if (authRequestState_ != nullptr) {
+ authTimes_++;
timer_->DeleteTimer(ADD_TIMEOUT_TASK);
if (status != DM_OK || authResponseContext_->requestId != requestId) {
- if (authRequestState_ != nullptr) {
+ if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) {
authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN;
authRequestContext_->reason = ERR_DM_INPUT_PARAMETER_EMPTY;
authRequestState_->TransitionTo(std::make_shared());
- return;
+ } else {
+ timer_->StartTimer(INPUT_TIMEOUT_TASK, INPUT_TIMEOUT,
+ [this] (std::string name) {
+ DmAuthManager::HandleAuthenticateTimeout(name);
+ });
+ authPtr_->UpdateAuthInfo(authResponseContext_->pageId);
}
+ } else {
+ authRequestState_->TransitionTo(std::make_shared());
}
- authRequestState_->TransitionTo(std::make_shared());
}
}
void DmAuthManager::HandleAuthenticateTimeout(std::string name)
{
- LOGI("DmAuthManager::HandleAuthenticateTimeout start");
+ LOGI("DmAuthManager::HandleAuthenticateTimeout start timer name %s", name.c_str());
if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) {
if (authResponseContext_ == nullptr) {
authResponseContext_ = std::make_shared();
@@ -427,6 +430,8 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId)
if (authentication == nullptr) {
LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authResponseContext_->authType);
authResponseContext_->reply = ERR_DM_UNSUPPORTED_AUTH_TYPE;
+ } else {
+ authPtr_ = authenticationMap_[authResponseContext_->authType];
}
std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE);
@@ -435,7 +440,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId)
softbusConnector_->GetSoftbusSession()->SendData(sessionId, message);
}
authResponseContext_ = authResponseState_->GetAuthContext();
- if (jsonObject[TAG_CRYPTO_SUPPORT] == "true" && authResponseContext_->cryptoSupport) {
+ if (jsonObject[TAG_CRYPTO_SUPPORT] == true && authResponseContext_->cryptoSupport) {
if (jsonObject[TAG_CRYPTO_NAME] == authResponseContext_->cryptoName &&
jsonObject[TAG_CRYPTO_VERSION] == authResponseContext_->cryptoVer) {
isCryptoSupport_ = true;
@@ -443,7 +448,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId)
return;
}
}
- jsonObject[TAG_CRYPTO_SUPPORT] = "false";
+ jsonObject[TAG_CRYPTO_SUPPORT] = false;
message = jsonObject.dump();
softbusConnector_->GetSoftbusSession()->SendData(sessionId, message);
timer_->StartTimer(WAIT_REQUEST_TIMEOUT_TASK, WAIT_REQUEST_TIMEOUT,
@@ -502,7 +507,7 @@ void DmAuthManager::StartRespAuthProcess()
[this] (std::string name) {
DmAuthManager::HandleAuthenticateTimeout(name);
});
- authRequestState_->TransitionTo(std::make_shared());
+ authRequestState_->TransitionTo(std::make_shared());
} else {
LOGE("do not accept");
authResponseContext_->state = AuthState::AUTH_REQUEST_REPLY;
@@ -520,19 +525,14 @@ int32_t DmAuthManager::CreateGroup()
return DM_OK;
}
-int32_t DmAuthManager::AddMember(const std::string &deviceId)
+int32_t DmAuthManager::AddMember(int32_t pinCode)
{
- LOGI("DmAuthManager::AddMember start");
- nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false);
- if (jsonObj.is_discarded()) {
- LOGE("DecodeRequestAuth jsonStr error");
- return ERR_DM_FAILED;
- }
-
+ LOGI("DmAuthManager::AddMember start group id %s", authResponseContext_->groupId.c_str());
+ timer_->DeleteTimer(INPUT_TIMEOUT_TASK);
nlohmann::json jsonObject;
jsonObject[TAG_GROUP_ID] = authResponseContext_->groupId;
jsonObject[TAG_GROUP_NAME] = authResponseContext_->groupName;
- jsonObject[PIN_CODE_KEY] = jsonObj[PIN_CODE_KEY];
+ jsonObject[PIN_CODE_KEY] = pinCode;
jsonObject[TAG_REQUEST_ID] = authResponseContext_->requestId;
jsonObject[TAG_DEVICE_ID] = authResponseContext_->deviceId;
std::string connectInfo = jsonObject.dump();
@@ -540,18 +540,10 @@ int32_t DmAuthManager::AddMember(const std::string &deviceId)
[this] (std::string name) {
DmAuthManager::HandleAuthenticateTimeout(name);
});
- int32_t ret = hiChainConnector_->AddMember(deviceId, connectInfo);
+ int32_t ret = hiChainConnector_->AddMember(authRequestContext_->deviceId, connectInfo);
if (ret != 0) {
return ERR_DM_FAILED;
}
- LOGI("DmAuthManager::authRequestContext CancelDisplay start");
- std::shared_ptr ptr;
- if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
- LOGE("DmAuthManager::authenticationMap_ is null");
- return ERR_DM_FAILED;
- }
- ptr = authenticationMap_[authResponseContext_->authType];
- ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
return DM_OK;
}
@@ -578,13 +570,7 @@ void DmAuthManager::AuthenticateFinish()
LOGI("DmAuthManager::AuthenticateFinish start");
if (authResponseState_ != nullptr) {
if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) {
- std::shared_ptr ptr;
- if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
- LOGE("DmAuthManager::authenticationMap_ is null");
- return ;
- }
- ptr = authenticationMap_[authResponseContext_->authType];
- ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
+ authPtr_->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
}
if (isFinishOfLocal_) {
authMessageProcessor_->SetResponseContext(authResponseContext_);
@@ -596,6 +582,7 @@ void DmAuthManager::AuthenticateFinish()
authResponseContext_ = nullptr;
authResponseState_ = nullptr;
authMessageProcessor_ = nullptr;
+ authPtr_ = nullptr;
} else if (authRequestState_ != nullptr) {
if (isFinishOfLocal_) {
authMessageProcessor_->SetResponseContext(authResponseContext_);
@@ -604,14 +591,9 @@ void DmAuthManager::AuthenticateFinish()
} else {
authRequestContext_->reason = authResponseContext_->reply;
}
- if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) {
- std::shared_ptr ptr;
- if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
- LOGE("DmAuthManager::authenticationMap_ is null");
- return ;
- }
- ptr = authenticationMap_[authResponseContext_->authType];
- ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
+ if (authResponseContext_->state == AuthState::AUTH_REQUEST_JOIN ||
+ authResponseContext_->state == AuthState::AUTH_REQUEST_FINISH) {
+ authPtr_->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
}
listener_->OnAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId,
authRequestContext_->token, authResponseContext_->state, authRequestContext_->reason);
@@ -622,6 +604,8 @@ void DmAuthManager::AuthenticateFinish()
authResponseContext_ = nullptr;
authRequestState_ = nullptr;
authMessageProcessor_ = nullptr;
+ authPtr_ = nullptr;
+ authTimes_ = 0;
}
LOGI("DmAuthManager::AuthenticateFinish complete");
}
@@ -686,12 +670,8 @@ int32_t DmAuthManager::SetAuthResponseState(std::shared_ptr a
int32_t DmAuthManager::GetPinCode()
{
- nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false);
- if (jsonObj.is_discarded()) {
- LOGE("DecodeRequestAuth jsonStr error");
- return ERR_DM_FAILED;
- }
- return jsonObj[PIN_CODE_KEY];
+ LOGI("ShowConfigDialog start add member pin code %d", authResponseContext_->code);
+ return authResponseContext_->code;
}
void DmAuthManager::ShowConfigDialog()
@@ -711,27 +691,17 @@ void DmAuthManager::ShowConfigDialog()
void DmAuthManager::ShowAuthInfoDialog()
{
- LOGI("DmAuthManager::ShowAuthInfoDialog start");
- std::shared_ptr ptr;
- if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
- LOGE("DmAuthManager::authenticationMap_ is null");
- return;
- }
- ptr = authenticationMap_[authResponseContext_->authType];
- LOGI("ShowAuthInfoDialog authToken:%s", authResponseContext_->authToken.c_str());
- ptr->ShowAuthInfo(authResponseContext_->authToken, shared_from_this());
+ LOGI("DmAuthManager::ShowAuthInfoDialog start %d", authResponseContext_->code);
+ nlohmann::json jsonObj;
+ jsonObj[PIN_CODE_KEY] = authResponseContext_->code;
+ std::string authParam = jsonObj.dump();
+ authPtr_->ShowAuthInfo(authParam, shared_from_this());
}
void DmAuthManager::ShowStartAuthDialog()
{
LOGI("DmAuthManager::ShowStartAuthDialog start");
- std::shared_ptr ptr;
- if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
- LOGE("DmAuthManager::authenticationMap_ is null");
- return;
- }
- ptr = authenticationMap_[authResponseContext_->authType];
- ptr->StartAuth(authResponseContext_->authToken, shared_from_this());
+ authPtr_->StartAuth(authResponseContext_->authToken, shared_from_this());
}
int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam)
@@ -835,17 +805,20 @@ int32_t DmAuthManager::SetPageId(int32_t pageId)
return DM_OK;
}
-int32_t DmAuthManager::SetReason(int32_t reason, int32_t state)
+int32_t DmAuthManager::SetReasonAndFinish(int32_t reason, int32_t state)
{
if (authResponseContext_ == nullptr) {
LOGE("Authenticate is not start");
return ERR_DM_AUTH_NOT_START;
}
- if (state < AuthState::AUTH_REQUEST_FINISH) {
- authRequestContext_->reason = reason;
- }
authResponseContext_->state = state;
authResponseContext_->reply = reason;
+ if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) {
+ authRequestContext_->reason = reason;
+ authRequestState_->TransitionTo(std::make_shared());
+ } else if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) {
+ authResponseState_->TransitionTo(std::make_shared());
+ }
return DM_OK;
}
} // namespace DistributedHardware
diff --git a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp
index 6d49b0439c089b98d56d513314b1c3fe6030cbcd..659d5a1f4ac305cae2dde0acb088667e5b3fa669 100644
--- a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp
+++ b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp
@@ -39,6 +39,7 @@ DmDiscoveryManager::~DmDiscoveryManager()
int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
const std::string &extra)
{
+ std::lock_guard autoLock(locks_);
if (!discoveryQueue_.empty()) {
if (pkgName == discoveryQueue_.front()) {
LOGE("DmDiscoveryManager::StartDeviceDiscovery repeated, pkgName:%s", pkgName.c_str());
@@ -66,6 +67,7 @@ int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, con
int32_t DmDiscoveryManager::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId)
{
+ std::lock_guard autoLock(locks_);
if (!discoveryQueue_.empty()) {
discoveryQueue_.pop();
}
@@ -105,7 +107,18 @@ void DmDiscoveryManager::OnDiscoverySuccess(const std::string &pkgName, int32_t
void DmDiscoveryManager::HandleDiscoveryTimeout(std::string name)
{
LOGI("DmDiscoveryManager::HandleDiscoveryTimeout");
- StopDeviceDiscovery(discoveryQueue_.front(), discoveryContextMap_[discoveryQueue_.front()].subscribeId);
+ if (discoveryQueue_.empty()) {
+ LOGE("HandleDiscoveryTimeout: discovery queue is empty.");
+ return;
+ }
+
+ std::string pkgName = discoveryQueue_.front();
+ auto iter = discoveryContextMap_.find(pkgName);
+ if (iter == discoveryContextMap_.end()) {
+ LOGE("HandleDiscoveryTimeout: subscribeId not found by pkgName %s", GetAnonyString(pkgName).c_str());
+ return;
+ }
+ StopDeviceDiscovery(pkgName, discoveryContextMap_[pkgName].subscribeId);
}
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp
index bc054bedc0e45d42e2e9c65f0a33ccf337421dd3..014125c2ec9e93e0cb5e5ac101378f5f6f41b935 100644
--- a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp
+++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp
@@ -84,7 +84,7 @@ int32_t IpcServerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa
auto remoteDescriptor = data.ReadInterfaceToken();
if (GetDescriptor() != remoteDescriptor) {
LOGI("ReadInterfaceToken fail!");
- return ERR_INVALID_STATE;
+ return ERR_DM_IPC_READ_TOKEN_FAILED;
}
int32_t ret = IpcCmdRegister::GetInstance().OnIpcCmd((int32_t)code, data, reply);
diff --git a/test/BUILD.gn b/test/BUILD.gn
index a3b75ab3436e0280f9b8fb8e0c657060801fda28..da8df87ea6e939e3405067cd439255e1eafc3858 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -17,6 +17,7 @@ group("test") {
deps = []
if (support_jsapi) {
deps += [
+ "benchmarktest:benchmarktest",
"fuzztest:fuzztest",
"unittest:unittest",
]
diff --git a/test/benchmarktest/BUILD.gn b/test/benchmarktest/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..4897663fb97eefd1cc6ab10a0a96cc9f3c3904f8
--- /dev/null
+++ b/test/benchmarktest/BUILD.gn
@@ -0,0 +1,23 @@
+# Copyright (c) 2022 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
+
+group("benchmarktest") {
+ testonly = true
+
+ deps = [
+ "device_manager_fa_test:benchmarktest",
+ "device_manager_test:benchmarktest",
+ ]
+}
diff --git a/test/benchmarktest/device_manager_fa_test/BUILD.gn b/test/benchmarktest/device_manager_fa_test/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..0d540c543f8954bce742277e8bf82c2c3d0cd54c
--- /dev/null
+++ b/test/benchmarktest/device_manager_fa_test/BUILD.gn
@@ -0,0 +1,65 @@
+# Copyright (c) 2022 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/test.gni")
+import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
+
+module_output_path = "device_manager_base/devicemanager"
+
+ohos_benchmarktest("DeviceManagerFaTest") {
+ module_out_path = module_output_path
+ sources = [ "device_manager_fa_test.cpp" ]
+
+ include_dirs = [
+ "${common_path}/include",
+ "${innerkits_path}/native_cpp/include/notify",
+ ]
+
+ cflags = []
+ if (target_cpu == "arm") {
+ cflags += [ "-DBINDER_IPC_32BIT" ]
+ }
+
+ deps = [
+ "${utils_path}:devicemanagerutils",
+ "${utils_path}:devicemanagerutils",
+ "//foundation/arkui/napi:ace_napi",
+ "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
+ "//third_party/benchmark:benchmark",
+ "//third_party/bounds_checking_function:libsec_shared",
+ "//third_party/googletest:gtest_main",
+ "//utils/native/base:utils",
+ ]
+
+ external_deps = [
+ "bundle_framework:appexecfwk_base",
+ "bundle_framework:appexecfwk_core",
+ "eventhandler:libeventhandler",
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ "startup_l2:syspara",
+ ]
+}
+
+group("benchmarktest") {
+ testonly = true
+ deps = []
+
+ deps += [
+ # deps file
+ ":DeviceManagerFaTest",
+ ]
+}
diff --git a/test/benchmarktest/device_manager_fa_test/device_manager_fa_test.cpp b/test/benchmarktest/device_manager_fa_test/device_manager_fa_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bada243b3c891874e2d1abd59aa797bb6b57c20c
--- /dev/null
+++ b/test/benchmarktest/device_manager_fa_test/device_manager_fa_test.cpp
@@ -0,0 +1,300 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+
+#include "device_manager.h"
+#include "dm_app_image_info.h"
+#include "dm_subscribe_info.h"
+#include "device_manager_callback.h"
+#include "dm_constants.h"
+
+using namespace std;
+using namespace OHOS;
+using namespace OHOS::DistributedHardware;
+
+namespace {
+class DeviceDiscoveryCallbackTest : public DiscoveryCallback {
+public:
+ DeviceDiscoveryCallbackTest() : DiscoveryCallback() {}
+ virtual ~DeviceDiscoveryCallbackTest() {}
+ virtual void OnDiscoverySuccess(uint16_t subscribeId) override {}
+ virtual void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) override {}
+ virtual void OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) override {}
+};
+
+class DmInitCallbackTest : public DmInitCallback {
+public:
+ DmInitCallbackTest() : DmInitCallback() {}
+ virtual ~DmInitCallbackTest() override {}
+ virtual void OnRemoteDied() override {}
+};
+
+class DeviceStateCallbackTest : public DeviceStateCallback {
+public:
+ DeviceStateCallbackTest() : DeviceStateCallback() {}
+ virtual ~DeviceStateCallbackTest() override {}
+ virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) override {}
+ virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override {}
+ virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override {}
+ virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override {}
+};
+
+class DeviceManagerFaCallbackTest : public DeviceManagerFaCallback {
+public:
+ DeviceManagerFaCallbackTest() : DeviceManagerFaCallback() {}
+ virtual ~DeviceManagerFaCallbackTest() override {}
+ virtual void OnCall(const std::string ¶mJson) override {}
+};
+
+class DeviceManagerFaTest : public benchmark::Fixture {
+public:
+ DeviceManagerFaTest()
+ {
+ Iterations(iterations);
+ Repetitions(repetitions);
+ ReportAggregatesOnly();
+ }
+
+ ~DeviceManagerFaTest() override = default;
+
+ void SetUp(const ::benchmark::State &state) override
+ {
+ }
+
+ void TearDown(const ::benchmark::State &state) override
+ {
+ }
+protected:
+ const int32_t repetitions = 3;
+ const int32_t iterations = 1000;
+ // sleep 1000ms
+ const int32_t usleepTime = 1000 * 1000;
+ const string pkgName = "com.ohos.devicemanager";
+ const string extra = "";
+ const string bundleName = "";
+ const string extraString = "";
+ const string packageName = "";
+ const int32_t authType = 0;
+};
+
+class GetTrustedDeviceListTest : public DeviceManagerFaTest {
+public:
+ void SetUp(const ::benchmark::State &state) override {}
+ void TearDown(const ::benchmark::State &state) override {}
+};
+
+class DeviceDiscoveryTest : public DeviceManagerFaTest {
+public:
+ void SetUp(const ::benchmark::State &state) override
+ {
+ DeviceManager::GetInstance().StopDeviceDiscovery(bundleName, subscribeId);
+ usleep(usleepTime);
+ }
+ void TearDown(const ::benchmark::State &state) override
+ {
+ DeviceManager::GetInstance().StopDeviceDiscovery(bundleName, subscribeId);
+ usleep(usleepTime);
+ }
+protected:
+ const int16_t subscribeId = 0;
+};
+
+class AuthenticateDeviceTest : public DeviceManagerFaTest {
+public:
+ void TearDown(const ::benchmark::State &state) override
+ {
+ DmDeviceInfo deviceInfo;
+ DeviceManager::GetInstance().UnAuthenticateDevice(bundleName, deviceInfo);
+ usleep(usleepTime);
+ }
+};
+
+class UnAuthenticateDeviceTest : public DeviceManagerFaTest {
+public:
+ void SetUp(const ::benchmark::State &state) override
+ {
+ DmDeviceInfo deviceInfo;
+ std::shared_ptr callback = nullptr;
+ DeviceManager::GetInstance().AuthenticateDevice(pkgName,
+ authType, deviceInfo, extraString, callback);
+ usleep(usleepTime);
+ }
+};
+
+class RegisterDeviceManagerFaTest : public DeviceManagerFaTest {
+public:
+ void TearDown(const ::benchmark::State &state) override
+ {
+ DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
+ usleep(usleepTime);
+ }
+};
+
+class UnRegisterDeviceManagerFaTest : public DeviceManagerFaTest {
+public:
+ void SetUp(const ::benchmark::State &state) override
+ {
+ std::shared_ptr callback = std::make_shared();
+ DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(pkgName, callback);
+ usleep(usleepTime);
+ }
+};
+
+class RegisterDevStateTest : public DeviceManagerFaTest {
+public:
+ void TearDown(const ::benchmark::State &state) override
+ {
+ DeviceManager::GetInstance().UnRegisterDevStateCallback(bundleName);
+ usleep(usleepTime);
+ }
+};
+
+// GetTrustedDeviceList
+BENCHMARK_F(GetTrustedDeviceListTest, GetTrustedDeviceListTestCase)(
+ benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ std::vector devList {};
+ int32_t ret = DeviceManager::GetInstance().GetTrustedDeviceList(bundleName, extra, devList);
+ if (ret != DM_OK) {
+ state.SkipWithError("GetTrustedDeviceListTestCase failed.");
+ }
+ }
+}
+
+// StartDeviceDiscovery
+BENCHMARK_F(DeviceDiscoveryTest, StartDeviceDiscoveryTestCase)(
+ benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ DmSubscribeInfo subInfo;
+ std::shared_ptr callback = std::make_shared();
+ int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(bundleName,
+ subInfo, extra, callback);
+ if (ret != DM_OK) {
+ state.SkipWithError("StartDeviceDiscoveryTestCase faild.");
+ }
+ }
+}
+
+// StopDeviceDiscovery
+BENCHMARK_F(DeviceDiscoveryTest, StoptDeviceDiscoveryTestCase)(
+ benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ state.PauseTiming();
+ DmSubscribeInfo subInfo;
+ std::shared_ptr callback = std::make_shared();
+ int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(bundleName,
+ subInfo, extra, callback);
+ if (ret != DM_OK) {
+ state.SkipWithError("StopDeviceDiscoveryTestCase faild.");
+ }
+ state.ResumeTiming();
+ ret =DeviceManager::GetInstance().StopDeviceDiscovery(bundleName, subscribeId);
+ if (ret != DM_OK) {
+ state.SkipWithError("StopDeviceDiscoveryTestCase faild.");
+ }
+ }
+}
+
+// AuthenticateDevice
+BENCHMARK_F(AuthenticateDeviceTest, AuthenticateDeviceTestCase)(
+ benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ DmDeviceInfo deviceInfo;
+ std::shared_ptr callback = nullptr;
+ int32_t ret = DeviceManager::GetInstance().AuthenticateDevice(pkgName,
+ authType, deviceInfo, extraString, callback);
+
+ if (ret != DM_OK) {
+ state.SkipWithError("AuthenticateDeviceTestCase faild.");
+ }
+ }
+}
+
+// UnAuthenticateDevice
+BENCHMARK_F(UnAuthenticateDeviceTest, UnAuthenticateDeviceTestCase)(
+ benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ state.PauseTiming();
+ DmDeviceInfo deviceInfo;
+ std::shared_ptr callback = nullptr;
+ int32_t ret = DeviceManager::GetInstance().AuthenticateDevice(pkgName,
+ authType, deviceInfo, extraString, callback);
+ if (ret != DM_OK) {
+ state.SkipWithError("UnAuthenticateDeviceTestCase faild.");
+ }
+ state.ResumeTiming();
+ ret = DeviceManager::GetInstance().UnAuthenticateDevice(bundleName, deviceInfo);
+ if (ret != DM_OK) {
+ state.SkipWithError("UnAuthenticateDeviceTestCase faild.");
+ }
+ }
+}
+
+// RegisterDeviceManagerFaCallback
+BENCHMARK_F(RegisterDeviceManagerFaTest, RegisterDeviceManagerFaCallbackTestCase)(
+ benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ std::shared_ptr callback = std::make_shared();
+ int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packageName, callback);
+ if (ret != DM_OK) {
+ state.SkipWithError("AuthenticateDeviceTestCase faild.");
+ }
+ }
+}
+
+// UnRegisterDeviceManagerFaCallback
+BENCHMARK_F(UnRegisterDeviceManagerFaTest, UnRegisterDeviceManagerFaCallbackTestCase)(
+ benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ state.PauseTiming();
+ std::shared_ptr callback = std::make_shared();
+ int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packageName, callback);
+ if (ret != DM_OK) {
+ state.SkipWithError("AuthenticateDeviceTestCase faild.");
+ }
+ state.ResumeTiming();
+ ret = DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
+ if (ret != DM_OK) {
+ state.SkipWithError("UnRegisterDeviceManagerFaCallbackTestCase faild.");
+ }
+ }
+}
+
+// RegisterDevStateCallback
+BENCHMARK_F(RegisterDevStateTest, RegisterDevStateCallbackTestCase)(
+ benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(bundleName, extra);
+ if (ret != DM_OK) {
+ state.SkipWithError("RegisterDevStateCallbackTestCase faild.");
+ }
+ }
+}
+}
+
+// Run the benchmark
+BENCHMARK_MAIN();
+
diff --git a/test/benchmarktest/device_manager_test/BUILD.gn b/test/benchmarktest/device_manager_test/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..27fd9ddd246680467e9f35f7168ab8b4c39b32cb
--- /dev/null
+++ b/test/benchmarktest/device_manager_test/BUILD.gn
@@ -0,0 +1,61 @@
+# Copyright (c) 2022 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/test.gni")
+import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
+
+module_output_path = "device_manager_base/devicemanager"
+
+ohos_benchmarktest("DeviceManagerTest") {
+ module_out_path = module_output_path
+ sources = [ "device_manager_test.cpp" ]
+
+ include_dirs = [ "${common_path}/include" ]
+
+ cflags = []
+ if (target_cpu == "arm") {
+ cflags += [ "-DBINDER_IPC_32BIT" ]
+ }
+
+ deps = [
+ "${utils_path}:devicemanagerutils",
+ "${utils_path}:devicemanagerutils",
+ "//foundation/arkui/napi:ace_napi",
+ "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
+ "//third_party/benchmark:benchmark",
+ "//third_party/bounds_checking_function:libsec_shared",
+ "//third_party/googletest:gtest_main",
+ "//utils/native/base:utils",
+ ]
+
+ external_deps = [
+ "bundle_framework:appexecfwk_base",
+ "bundle_framework:appexecfwk_core",
+ "eventhandler:libeventhandler",
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ "startup_l2:syspara",
+ ]
+}
+
+group("benchmarktest") {
+ testonly = true
+ deps = []
+
+ deps += [
+ # deps file
+ ":DeviceManagerTest",
+ ]
+}
diff --git a/test/benchmarktest/device_manager_test/device_manager_test.cpp b/test/benchmarktest/device_manager_test/device_manager_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3c321387619186f975dc23eaae1004962355a89e
--- /dev/null
+++ b/test/benchmarktest/device_manager_test/device_manager_test.cpp
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+
+#include "device_manager.h"
+#include "dm_app_image_info.h"
+#include "dm_constants.h"
+
+using namespace std;
+using namespace OHOS;
+using namespace OHOS::DistributedHardware;
+
+namespace {
+class BenchmarkDmInit : public DmInitCallback {
+public:
+ BenchmarkDmInit() : DmInitCallback() {}
+ virtual ~BenchmarkDmInit() override {}
+ virtual void OnRemoteDied() override {}
+};
+class DeviceManagerTest : public benchmark::Fixture {
+public:
+ DeviceManagerTest()
+ {
+ Iterations(iterations);
+ Repetitions(repetitions);
+ ReportAggregatesOnly();
+ }
+
+ ~DeviceManagerTest() override = default;
+
+ void SetUp(const ::benchmark::State &state) override
+ {
+ }
+
+ void TearDown(const ::benchmark::State &state) override
+ {
+ }
+protected:
+ const string pkgName = "ohos.distributedhardware.devicemanager";
+ const int32_t repetitions = 16;
+ const int32_t iterations = 1;
+};
+
+// InitDeviceManager
+BENCHMARK_F(DeviceManagerTest, InitDeviceManagerTestCase)(benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ std::shared_ptr callback = std::make_shared();
+ int32_t ret = DeviceManager::GetInstance().InitDeviceManager(pkgName, callback);
+ if (ret != DM_OK) {
+ state.SkipWithError("InitDeviceManagerTestCase failed.");
+ }
+ }
+}
+
+// GetFaParam
+BENCHMARK_F(DeviceManagerTest, GetFaParamTestCase)(benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ DmAuthParam authParam;
+ int32_t ret = DeviceManager::GetInstance().GetFaParam(pkgName, authParam);
+ if (ret != DM_OK) {
+ state.SkipWithError("GetFaParamTestCase. faild");
+ }
+ }
+}
+
+// SetUserOperation
+BENCHMARK_F(DeviceManagerTest, SetUserOperationTestCase)(benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ int32_t action = 0;
+ int32_t ret = DeviceManager::GetInstance().SetUserOperation(pkgName, action);
+ if (ret != DM_OK) {
+ state.SkipWithError("SetUserOperationTestCase failed.");
+ }
+ }
+}
+
+// GetUdidByNetworkId
+BENCHMARK_F(DeviceManagerTest, GetUdidByNetworkIdTestCase)(benchmark::State &state)
+{
+ while (state.KeepRunning()) {
+ std::string netWorkId = "";
+ std::string uuid = "";
+ int32_t ret = DeviceManager::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid);
+ if (ret != DM_OK) {
+ state.SkipWithError("SetUserOperationTestCase failed.");
+ }
+ }
+}
+}
+
+// Run the benchmark
+BENCHMARK_MAIN();
diff --git a/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn b/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn
index 5e07aa17567b9ca6b90c3c1f87ecc7f1d6bff708..1721e4366098f318c91eb01f813250e8e0d2db33 100644
--- a/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn
+++ b/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn
@@ -88,7 +88,6 @@ ohos_fuzztest("IpcClientManagerFuzzTest") {
deps = [
"${aainnerkits_path}/ability_manager:ability_manager",
- "${aainnerkits_path}/want:want",
"${aaservices_path}/abilitymgr:abilityms",
"${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
@@ -105,6 +104,7 @@ ohos_fuzztest("IpcClientManagerFuzzTest") {
]
external_deps = [
+ "ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"common_event_service:cesfwk_core",
diff --git a/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn b/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn
index ba39d03e23a988a394181e595490f30b540d4c05..e8b189b6367e15db2788d50dbd4262058d86688d 100644
--- a/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn
+++ b/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn
@@ -89,7 +89,6 @@ ohos_fuzztest("IpcCmdRegisterFuzzTest") {
deps = [
"${aainnerkits_path}/ability_manager:ability_manager",
- "${aainnerkits_path}/want:want",
"${aaservices_path}/abilitymgr:abilityms",
"${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
@@ -106,6 +105,7 @@ ohos_fuzztest("IpcCmdRegisterFuzzTest") {
]
external_deps = [
+ "ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"common_event_service:cesfwk_core",
diff --git a/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn b/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn
index 8ecc8590f7d0a47a5e7d84608836b0e79b405995..e34f0969bf294bc675e3afc02bd8cb4aaa0cdf36 100644
--- a/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn
+++ b/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn
@@ -88,7 +88,6 @@ ohos_fuzztest("IpcServerClientProxyFuzzTest") {
deps = [
"${aainnerkits_path}/ability_manager:ability_manager",
- "${aainnerkits_path}/want:want",
"${aaservices_path}/abilitymgr:abilityms",
"${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
@@ -105,6 +104,7 @@ ohos_fuzztest("IpcServerClientProxyFuzzTest") {
]
external_deps = [
+ "ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"common_event_service:cesfwk_core",
diff --git a/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn b/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn
index f7cab81e7b0572f67aafb3ff7fc7b19e1b324941..47052b68061a61d75ff57d89ee0d430844088384 100644
--- a/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn
+++ b/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn
@@ -88,7 +88,6 @@ ohos_fuzztest("IpcServerListenerFuzzTest") {
deps = [
"${aainnerkits_path}/ability_manager:ability_manager",
- "${aainnerkits_path}/want:want",
"${aaservices_path}/abilitymgr:abilityms",
"${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
@@ -105,6 +104,7 @@ ohos_fuzztest("IpcServerListenerFuzzTest") {
]
external_deps = [
+ "ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"common_event_service:cesfwk_core",
diff --git a/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn b/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn
index 1bfae7dcaafdae1bb911bd13d1e794d44eba1d29..7fa5a7e3d9b9e7d5ff8ae41f7cdc2ab5efab70f5 100644
--- a/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn
+++ b/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn
@@ -88,7 +88,6 @@ ohos_fuzztest("IpcServerStubFuzzTest") {
deps = [
"${aainnerkits_path}/ability_manager:ability_manager",
- "${aainnerkits_path}/want:want",
"${aaservices_path}/abilitymgr:abilityms",
"${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
@@ -105,6 +104,7 @@ ohos_fuzztest("IpcServerStubFuzzTest") {
]
external_deps = [
+ "ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"common_event_service:cesfwk_core",
diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn
index c784979ea4c322d4b95bc69a5296d5c1e72f1ab0..1efeecb78d7af07d60fcdfd2962fbc24c1a4c259 100644
--- a/test/unittest/BUILD.gn
+++ b/test/unittest/BUILD.gn
@@ -621,7 +621,6 @@ ohos_static_library("device_manager_test") {
deps = [
"${aainnerkits_path}/ability_manager:ability_manager",
- "${aainnerkits_path}/want:want",
"${aaservices_path}/abilitymgr:abilityms",
"${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
@@ -634,6 +633,7 @@ ohos_static_library("device_manager_test") {
}
external_deps = [
+ "ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"common_event_service:cesfwk_core",
diff --git a/test/unittest/UTTest_auth_request_state.cpp b/test/unittest/UTTest_auth_request_state.cpp
index 9aad181667c17b6534bae99ba6dcc8f7d87b4be6..9d0b6b0dcd1439f2f5dad4e602e6863833c81912 100644
--- a/test/unittest/UTTest_auth_request_state.cpp
+++ b/test/unittest/UTTest_auth_request_state.cpp
@@ -439,57 +439,6 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0)
ASSERT_EQ(ret, DM_OK);
}
-/**
- * @tc.name: AuthRequestInputState::GetStateType_005
- * @tc.desc: 1 call AuthRequestInputState::GetStateType
- * 2 check ret is AuthState::AUTH_REQUEST_INPUT
- * @tc.type: FUNC
- * @tc.require: AR000GHSJK
- */
-HWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0)
-{
- std::shared_ptr authRequestState = std::make_shared();
- int32_t ret = authRequestState->GetStateType();
- ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INPUT);
-}
-
-/**
- * @tc.name: AuthRequestInputState::Enter_009
- * @tc.desc: 1 set authManager to null
- * 2 call AuthRequestInputState::Enter with authManager = null
- * 3 check ret is ERR_DM_FAILED
- * @tc.type: FUNC
- * @tc.require: AR000GHSJK
- */
-HWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0)
-{
- std::shared_ptr authManager =
- std::make_shared(softbusConnector, listener, hiChainConnector);
- std::shared_ptr authRequestState = std::make_shared();
- authRequestState->SetAuthManager(nullptr);
- int32_t ret = authRequestState->Enter();
- ASSERT_EQ(ret, ERR_DM_FAILED);
-}
-
-/**
- * @tc.name: AuthRequestInputState::Enter_010
- * @tc.desc: 1 set authManager not null
- * 2 call AuthRequestInputState::Enter with authManager != null
- * 3 check ret is DM_OK
- * @tc.type: FUNC
- * @tc.require: AR000GHSJK
- */
-HWTEST_F(AuthRequestStateTest, Enter_010, testing::ext::TestSize.Level0)
-{
- std::shared_ptr authManager =
- std::make_shared(softbusConnector, listener, hiChainConnector);
- authManager->authResponseContext_ = std::make_shared();
- std::shared_ptr authRequestState = std::make_shared();
- authRequestState->SetAuthManager(authManager);
- int32_t ret = authRequestState->Enter();
- ASSERT_EQ(ret, DM_OK);
-}
-
/**
* @tc.name: AuthRequestJoinState::GetStateType_006
* @tc.desc: 1 call AuthRequestJoinState::GetStateType
@@ -538,6 +487,7 @@ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0)
authManager->authRequestContext_ = std::make_shared();
authManager->authMessageProcessor_ = std::make_shared(authManager);
authManager->authResponseContext_ = std::make_shared();
+ authManager->authPtr_ = authManager->authenticationMap_[1];
authManager->authResponseContext_->groupId = "111";
authManager->authResponseContext_->groupName = "222";
authManager->authResponseContext_->code = 123;
@@ -660,6 +610,7 @@ HWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0)
std::make_shared(softbusConnector, listener, hiChainConnector);
std::shared_ptr authRequestState = std::make_shared();
authManager->timer_ = std::make_shared();
+ authManager->authPtr_ = authManager->authenticationMap_[1];
authManager->authMessageProcessor_ = std::make_shared(authManager);
authManager->authResponseContext_ = std::make_shared();
authManager->authRequestContext_ = std::make_shared();
diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp
index 9ddcb2be60cf87feee8143f7502ff86eb1c2a852..51ef19ee7821a3c0945f587c349a5fe80070962f 100644
--- a/test/unittest/UTTest_auth_response_state.cpp
+++ b/test/unittest/UTTest_auth_response_state.cpp
@@ -235,6 +235,7 @@ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0)
authManager->authRequestState_ = std::make_shared();
authManager->authResponseContext_->deviceId = "111";
authManager->authResponseContext_->localDeviceId = "222";
+ authManager->authPtr_ = authManager->authenticationMap_[1];
authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_);
authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_);
authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager);
@@ -397,6 +398,8 @@ HWTEST_F(AuthResponseStateTest, Enter_009, testing::ext::TestSize.Level0)
std::make_shared(softbusConnector, listener, hiChainConnector);
authManager->authResponseContext_ = std::make_shared();
std::shared_ptr authResponseState = std::make_shared();
+ authManager->authPtr_ = authManager->authenticationMap_[1];
+ authManager->authResponseContext_->code = 123456;
authResponseState->SetAuthManager(authManager);
int32_t ret = authResponseState->Enter();
ASSERT_EQ(ret, DM_OK);
@@ -453,6 +456,7 @@ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0)
authManager->authRequestContext_ = std::make_shared();
authManager->authMessageProcessor_ = std::make_shared(authManager);
authManager->listener_ = std::make_shared();
+ authManager->authPtr_ = authManager->authenticationMap_[1];
authManager->authResponseContext_->sessionId = 1;
authManager->authRequestContext_->deviceId = "2";
authManager->authRequestContext_->hostPkgName = "3";
diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp
index 353bbe6a58a4930d921f98d74ff17aa9750f78ad..8cf5ff118b1b7f339dd2223f63fd237ed01a432c 100644
--- a/test/unittest/UTTest_device_manager_impl.cpp
+++ b/test/unittest/UTTest_device_manager_impl.cpp
@@ -1307,6 +1307,7 @@ HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_002, testing::ext::TestSize
// 1. set packName = null
std::string packName = "com.ohos.helloworld";
DmDeviceInfo deviceInfo;
+ deviceInfo.deviceId[0] = '\0';
// 2. call DeviceManagerImpl::AuthenticateDevice with parameter
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceInfo);
// 3. check ret is DEVICEMANAGER_INVALID_VALUE
diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp
index 764c8322f0f15fd191fca78b6d0a5d9d90416f60..a6c76070a747674594d5085d05aa03d7554ead8f 100644
--- a/test/unittest/UTTest_dm_auth_manager.cpp
+++ b/test/unittest/UTTest_dm_auth_manager.cpp
@@ -208,10 +208,10 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0)
authManager->authResponseContext_->code = 123;
authManager->authResponseContext_->requestId = 234;
authManager->authResponseContext_->deviceId = "234";
- std::string deviceId = "44444";
+ int32_t pinCode = 444444;
authManager->hiChainConnector_->RegisterHiChainCallback(authManager);
authManager->SetAuthResponseState(authResponseState);
- int32_t ret = authManager->AddMember(deviceId);
+ int32_t ret = authManager->AddMember(pinCode);
ASSERT_EQ(ret, ERR_DM_FAILED);
}
diff --git a/test/unittest/UTTest_dm_discovery_manager.cpp b/test/unittest/UTTest_dm_discovery_manager.cpp
index 764b1621cb197e659e7c7ff6c336c9700b0281d5..27b40b4ebe16ae1d3c77a482402c011fc02eeb15 100644
--- a/test/unittest/UTTest_dm_discovery_manager.cpp
+++ b/test/unittest/UTTest_dm_discovery_manager.cpp
@@ -225,21 +225,6 @@ HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_002, testing::ext::TestSize.
std ::string ret = pReq->GetPkgName();
EXPECT_EQ(ret, pkgName);
}
-
-/**
- * @tc.name: HandleDiscoveryTimeout_001
- * @tc.desc: set pkgName not null and return 1(true)
- * @tc.type: FUNC
- * @tc.require: AR000GHSJK
- */
-HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_001, testing::ext::TestSize.Level0)
-{
- std::string name = "test";
- std::string pkgName = "com.ohos.helloworld";
- discoveryMgr_->HandleDiscoveryTimeout(name);
- int ret = discoveryMgr_->discoveryContextMap_.count(pkgName);
- EXPECT_EQ(ret, 1);
-}
} // namespace
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/test/unittest/UTTest_ipc_client_stub.cpp b/test/unittest/UTTest_ipc_client_stub.cpp
index 30715f4bcbcf712c28bf7b69f31f0a9ea0ebae23..7b5e68f463afab4d62ebdf057ce8b34b52b60562 100644
--- a/test/unittest/UTTest_ipc_client_stub.cpp
+++ b/test/unittest/UTTest_ipc_client_stub.cpp
@@ -87,7 +87,7 @@ HWTEST_F(IpcClientStubTest, OnRemoteRequest_001, testing::ext::TestSize.Level0)
* set MessageParcel not null
* 2. set set code is SERVER_DEVICE_FA_NOTIFY
* 3. call IpcClientStub OnRemoteRequest with parameter
- * 4. check result is ERR_INVALID_STATE
+ * 4. check result is ERR_DM_IPC_READ_TOKEN_FAILED
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
@@ -104,8 +104,8 @@ HWTEST_F(IpcClientStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0)
sptr instance = new IpcClientStub();
// 3. call IpcClientStub OnRemoteRequest with parameter
int ret = instance->OnRemoteRequest(code, data, reply, option);
- // 4. check result is ERR_INVALID_STATE
- ASSERT_EQ(ret, ERR_INVALID_STATE);
+ // 4. check result is ERR_DM_IPC_READ_TOKEN_FAILED
+ ASSERT_EQ(ret, ERR_DM_IPC_READ_TOKEN_FAILED);
}
/**
diff --git a/test/unittest/UTTest_ipc_server_stub.cpp b/test/unittest/UTTest_ipc_server_stub.cpp
index a4686000dec8d4bc8e3aaf4051bc90c893bf5005..1e929f94d8244fe6cd56692dbd153e3053b829a9 100644
--- a/test/unittest/UTTest_ipc_server_stub.cpp
+++ b/test/unittest/UTTest_ipc_server_stub.cpp
@@ -168,8 +168,8 @@ HWTEST_F(IpcServerStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0)
int ret = 0;
// 2. Call IpcServerStub OnRemoteRequest with param
ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data, reply, option);
- // 3. check ret not ERR_INVALID_STATE
- ASSERT_EQ(ret, ERR_INVALID_STATE);
+ // 3. check ret not ERR_DM_IPC_READ_TOKEN_FAILED
+ ASSERT_EQ(ret, ERR_DM_IPC_READ_TOKEN_FAILED);
}
/**
diff --git a/test/unittest/UTTest_pin_auth_ui.cpp b/test/unittest/UTTest_pin_auth_ui.cpp
index 448854f0d2a60ba1e2d5f14f2c3de177fcfeb8c9..b1055473db954642ec7bf65bd483f28137ac923b 100644
--- a/test/unittest/UTTest_pin_auth_ui.cpp
+++ b/test/unittest/UTTest_pin_auth_ui.cpp
@@ -86,8 +86,7 @@ HWTEST_F(PinAuthUiTest, ShowPinDialog_002, testing::ext::TestSize.Level0)
HWTEST_F(PinAuthUiTest, InputPinDialog_001, testing::ext::TestSize.Level0)
{
std::shared_ptr pinAuthUi = std::make_shared();
- int32_t code = 123456;
- int32_t ret = pinAuthUi->InputPinDialog(code, nullptr);
+ int32_t ret = pinAuthUi->InputPinDialog(nullptr);
ASSERT_EQ(ret, DM_OK);
}
@@ -100,8 +99,7 @@ HWTEST_F(PinAuthUiTest, InputPinDialog_001, testing::ext::TestSize.Level0)
HWTEST_F(PinAuthUiTest, InputPinDialog_002, testing::ext::TestSize.Level0)
{
std::shared_ptr pinAuthUi = std::make_shared();
- int32_t code = 123456;
- int32_t ret = pinAuthUi->InputPinDialog(code, authManager);
+ int32_t ret = pinAuthUi->InputPinDialog(authManager);
ASSERT_EQ(ret, DM_OK);
}
}
diff --git a/test/unittest/UTTest_softbus_connector.cpp b/test/unittest/UTTest_softbus_connector.cpp
index 03ef0babb6ddfd56731d2b1bb42992c6a8f776d4..01b7976d23038af0ac4885d12a71aea554eadb72 100644
--- a/test/unittest/UTTest_softbus_connector.cpp
+++ b/test/unittest/UTTest_softbus_connector.cpp
@@ -66,7 +66,7 @@ HWTEST_F(SoftbusConnectorTest, DeviceOnLine_001, testing::ext::TestSize.Level0)
{
std::string pkgName = "123";
DmDeviceInfo info;
- strncpy(info.deviceId, "123", sizeof(info.deviceId));
+ strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
deviceStateMgr->RegisterSoftbusStateCallback();
DeviceOnLine(SoftbusConnector::stateCallbackMap_, info);
bool ret = false;
@@ -88,7 +88,7 @@ HWTEST_F(SoftbusConnectorTest, DeviceOnLine_002, testing::ext::TestSize.Level0)
{
std::string pkgName = "123";
DmDeviceInfo info;
- strncpy(info.deviceId, "123", sizeof(info.deviceId));
+ strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
DeviceOnLine(SoftbusConnector::stateCallbackMap_, info);
bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) {
@@ -109,7 +109,7 @@ HWTEST_F(SoftbusConnectorTest, DeviceOffLine_001, testing::ext::TestSize.Level0)
{
std::string pkgName = "123";
DmDeviceInfo info;
- strncpy(info.deviceId, "123", sizeof(info.deviceId));
+ strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
deviceStateMgr->RegisterSoftbusStateCallback();
DeviceOffLine(SoftbusConnector::stateCallbackMap_, info);
bool ret = false;
@@ -131,7 +131,7 @@ HWTEST_F(SoftbusConnectorTest, DeviceOffLine_002, testing::ext::TestSize.Level0)
{
std::string pkgName = "123";
DmDeviceInfo info;
- strncpy(info.deviceId, "123", sizeof(info.deviceId));
+ strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
DeviceOffLine(SoftbusConnector::stateCallbackMap_, info);
bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) {
@@ -346,8 +346,8 @@ HWTEST_F(SoftbusConnectorTest, IsDeviceOnLine_001, testing::ext::TestSize.Level0
HWTEST_F(SoftbusConnectorTest, IsDeviceOnLine_002, testing::ext::TestSize.Level0)
{
std::string deviceId = "145677";
- NodeBasicInfo Info;
- strncpy(Info.networkId, "145677", sizeof(Info.networkId));
+ NodeBasicInfo info;
+ strcpy_s(info.networkId, DM_MAX_DEVICE_ID_LEN, "145677");
bool ret = softbusConnector->IsDeviceOnLine(deviceId);
EXPECT_EQ(ret, false);
}
diff --git a/test/unittest/auth_request_state.cpp b/test/unittest/auth_request_state.cpp
index 7163671855bc15d4ad2876b6d516fbfa100b2ccd..d3fdd78ec137ce827e66880375719405600368f3 100644
--- a/test/unittest/auth_request_state.cpp
+++ b/test/unittest/auth_request_state.cpp
@@ -122,23 +122,6 @@ int32_t AuthRequestReplyState::Enter()
return DM_OK;
}
-int32_t AuthRequestInputState::GetStateType()
-{
- return AuthState::AUTH_REQUEST_INPUT;
-}
-
-int32_t AuthRequestInputState::Enter()
-{
- LOGI("DmAuthManager::AuthRequestInputState");
- std::shared_ptr stateAuthManager = authManager_.lock();
- if (stateAuthManager == nullptr) {
- LOGE("AuthRequestState::authManager_ null");
- return ERR_DM_FAILED;
- }
- stateAuthManager->ShowStartAuthDialog();
- return DM_OK;
-}
-
int32_t AuthRequestJoinState::GetStateType()
{
return AuthState::AUTH_REQUEST_JOIN;
diff --git a/utils/BUILD.gn b/utils/BUILD.gn
index 45e102e991dfe866b4ea55213f1aaa185852f775..ff1b48427aa2dd87c8ae43b7471b74c240fc6b3f 100644
--- a/utils/BUILD.gn
+++ b/utils/BUILD.gn
@@ -41,6 +41,7 @@ if (defined(ohos_lite)) {
sources = [
"${utils_path}/src/dm_anonymous.cpp",
+ "${utils_path}/src/dm_error_message.cpp",
"${utils_path}/src/dm_log.cpp",
"${utils_path}/src/dm_random.cpp",
"${utils_path}/src/permission/lite/permission_manager.cpp",
@@ -91,6 +92,7 @@ if (defined(ohos_lite)) {
]
sources = [
"src/dm_anonymous.cpp",
+ "src/dm_error_message.cpp",
"src/dm_log.cpp",
"src/dm_random.cpp",
"src/fwkload/lite/dm_distributed_hardware_load.cpp",
@@ -131,6 +133,7 @@ if (defined(ohos_lite)) {
ohos_shared_library("devicemanagerutils") {
sources = [
"src/dm_anonymous.cpp",
+ "src/dm_error_message.cpp",
"src/dm_hash.cpp",
"src/dm_log.cpp",
"src/dm_random.cpp",
@@ -151,10 +154,7 @@ if (defined(ohos_lite)) {
"LOG_DOMAIN=0xD004100",
]
- deps = [
- "${aainnerkits_path}/want:want",
- "//third_party/mbedtls:mbedtls_shared",
- ]
+ deps = [ "//third_party/mbedtls:mbedtls_shared" ]
external_deps = [
"access_token:libaccesstoken_sdk",
@@ -166,6 +166,7 @@ if (defined(ohos_lite)) {
]
if (support_jsapi) {
external_deps += [
+ "ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
]
diff --git a/utils/include/dm_error_message.h b/utils/include/dm_error_message.h
new file mode 100644
index 0000000000000000000000000000000000000000..ba5dfe8ef55fb4ca20ee2138d1a2c56d4d357bf0
--- /dev/null
+++ b/utils/include/dm_error_message.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_ERROMSG_H
+#define OHOS_DM_ERROMSG_H
+
+#include "dm_log.h"
+#include "dm_constants.h"
+
+#include
+
+namespace OHOS {
+namespace DistributedHardware {
+std::string GetErrorString(int failedReason);
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_ERROMSG_H
diff --git a/utils/src/dm_error_message.cpp b/utils/src/dm_error_message.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..400081967283c59c62dd7421d0d64dd06fa22b56
--- /dev/null
+++ b/utils/src/dm_error_message.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dm_error_message.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+typedef struct ERROR_INFO {
+ int errCode;
+ std::string errMsg;
+} ERROR_INFO;
+
+static ERROR_INFO g_errorMessages[] = {
+ {ERR_DM_FAILED, "dm process execution failed."},
+ {ERR_DM_TIME_OUT, "dm process execution timeout."},
+ {ERR_DM_NOT_INIT, "dm service is not initialized, please try again later."},
+ {ERR_DM_INIT_REPEATED, "dm service repeated initialization."},
+ {ERR_DM_INIT_FAILED, "dm service initialize failed."},
+ {ERR_DM_UNINIT_FAILED, "dm Service uninitialization failed."},
+ {ERR_DM_POINT_NULL, "dm service null pointer exception occurred."},
+ {ERR_DM_INPUT_PARAMETER_EMPTY, "the function call input parameter is empty."},
+ {ERR_DM_NO_PERMISSION, "no permission for function call."},
+ {ERR_DM_MALLOC_FAILED, "memory allocation failed."},
+ {ERR_DM_DISCOVERY_FAILED, "device discovery failed."},
+ {ERR_DM_MAP_KEY_ALREADY_EXISTS, "map key already exists."},
+ {DM_PROFILE_EVENTS_FAILED, "process profile events failed."},
+ {ERR_DM_IPC_WRITE_FAILED, "ipc write object failed."},
+ {ERR_DM_IPC_COPY_FAILED, "ipc copy data failed."},
+ {ERR_DM_IPC_SEND_REQUEST_FAILED, "ipc send request failed."},
+ {ERR_DM_UNSUPPORTED_IPC_COMMAND, "ipc command not supported."},
+ {ERR_DM_IPC_RESPOND_FAILED, "ipc process failed to receive response."},
+ {ERR_DM_IPC_WRITE_TOKEN_FAILED, "ipc write token failed."},
+ {ERR_DM_DISCOVERY_REPEATED, "repeat device discovery warning."},
+ {ERR_DM_UNSUPPORTED_AUTH_TYPE, "auth type not supported."},
+ {ERR_DM_AUTH_BUSINESS_BUSY, "authentication service is busy."},
+ {ERR_DM_AUTH_OPEN_SESSION_FAILED, "open auth session failed."},
+ {ERR_DM_AUTH_PEER_REJECT, "remote device refused to authorization."},
+ {ERR_DM_AUTH_REJECT, "local device refused to authorization."},
+ {ERR_DM_AUTH_FAILED, "authentication failed."},
+ {ERR_DM_AUTH_NOT_START, "auth process not started."},
+ {ERR_DM_AUTH_MESSAGE_INCOMPLETE, "authentication message is incomplete."},
+ {ERR_DM_CREATE_GROUP_FAILED, "create group failed."},
+};
+
+std::string GetErrorString(int failedReason)
+{
+ std::string errorMessage = "undefined error code.";
+ for (int32_t i = 0; i < sizeof(g_errorMessages); i++) {
+ if (failedReason == g_errorMessages[i].errCode) {
+ errorMessage = g_errorMessages[i].errMsg;
+ break;
+ }
+ }
+ return errorMessage;
+}
+} // namespace DistributedHardware
+} // namespace OHOS