diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 4ff3d02b3503e7828477c8f57a2ccdf407d3a787..fd401fdc731dfb1e410f79cf4544035b3697ce2e 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -74,6 +74,7 @@ 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, }; const std::string TARGET_PKG_NAME_KEY = "targetPkgName"; 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}} +
+ + +
+
+ +
+
+ 请输入网络信息 +
+ SSID: + + {{wifiInfo.wifiSsid}} +
+
+ Key: + + {{wifiInfo.wifiPassword}} +
+
+ + +
+
+
+
+ {{ 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/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/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..645828e7d91f238bd1acb9c034cbc4352aed3bc1 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -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/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/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index ff50edcfa09da866a0c1a98a6c98cb279af32956..d72dcab4d9211b9430eb9f950244ac0b182f5031 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -435,7 +435,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 +443,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, @@ -745,7 +745,7 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) LOGE("Authenticate is not start"); return ERR_DM_AUTH_NOT_START; } - + dmAbilityMgr_->StartAbilityDone(); AbilityRole role = dmAbilityMgr_->GetAbilityRole(); authParam.direction = (int32_t)role; 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_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_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/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