diff --git a/BUILD.gn b/BUILD.gn
index 3fc86faf..cb9b6a6f 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -24,4 +24,4 @@ if (defined(ohos_lite)) {
]
}
}
-}
\ No newline at end of file
+}
diff --git a/display/@ohos.distributedHardware.deviceManager.d.ts b/display/@ohos.distributedHardware.deviceManager.d.ts
new file mode 100644
index 00000000..604936a6
--- /dev/null
+++ b/display/@ohos.distributedHardware.deviceManager.d.ts
@@ -0,0 +1,476 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { AsyncCallback, Callback } from './basic';
+
+declare namespace deviceManager {
+ /**
+ * DeviceInfo
+ */
+ interface DeviceInfo {
+ /**
+ * DeviceId ID.
+ */
+ deviceId: string;
+
+ /**
+ * Device name of the device.
+ */
+ deviceName: string;
+
+ /**
+ * Device type of the device.
+ */
+ deviceType: DeviceType;
+ }
+
+ /**
+ * Device Type definitions
+ */
+ enum DeviceType {
+ /**
+ * Indicates an unknown device type.
+ */
+ UNKNOWN_TYPE = 0,
+
+ /**
+ * Indicates a speaker.
+ */
+ SPEAKER = 0x0A,
+
+ /**
+ * Indicates a smartphone.
+ */
+ PHONE = 0x0E,
+
+ /**
+ * Indicates a tablet.
+ */
+ TABLET = 0x11,
+
+ /**
+ * Indicates a smart watch.
+ */
+ WEARABLE = 0x6D,
+
+ /**
+ * Indicates a car.
+ */
+ CAR = 0x83,
+
+ /**
+ * Indicates a smart TV.
+ */
+ TV = 0x9C
+ }
+
+ /**
+ * Device state change event definition
+ */
+ enum DeviceStateChangeAction {
+ /**
+ * device online action
+ */
+ ONLINE = 0,
+
+ /**
+ * device ready action, the device information synchronization was completed.
+ */
+ READY = 1,
+
+ /**
+ * device offline action
+ */
+ OFFLINE = 2,
+
+ /**
+ * device change action
+ */
+ CHANGE = 3
+ }
+
+ /**
+ * Service subscribe info for device discover
+ *
+ * @systemapi this method can be used only by system applications.
+ */
+ interface SubscribeInfo {
+ /**
+ * Service subscribe ID, the value is in scope [0, 65535], should be unique for each discover process
+ */
+ subscribeId: number;
+
+ /**
+ * Discovery mode for service subscription.
+ */
+ mode: DiscoverMode;
+
+ /**
+ * Service subscription medium.
+ */
+ medium: ExchangeMedium;
+
+ /**
+ * Service subscription frequency.
+ */
+ freq: ExchangeFreq;
+
+ /**
+ * only find the device with the same account.
+ */
+ isSameAccount: boolean;
+
+ /**
+ * find the sleeping devices.
+ */
+ isWakeRemote: boolean;
+
+ /**
+ * Subscribe capability.
+ */
+ capability: SubscribeCap;
+ }
+
+ /**
+ * device discover mode
+ *
+ * @systemapi this method can be used only by system applications.
+ */
+ enum DiscoverMode {
+ /**
+ * Passive
+ */
+ DISCOVER_MODE_PASSIVE = 0x55,
+
+ /**
+ * Proactive
+ */
+ DISCOVER_MODE_ACTIVE = 0xAA
+ }
+
+ /**
+ * device discover medium
+ *
+ * @systemapi this method can be used only by system applications.
+ */
+ enum ExchangeMedium {
+ /**
+ * Automatic medium selection
+ */
+ AUTO = 0,
+
+ /**
+ * Bluetooth
+ */
+ BLE = 1,
+
+ /**
+ * Wi-Fi
+ */
+ COAP = 2,
+
+ /**
+ * USB
+ */
+ USB = 3
+ }
+
+ /**
+ * device discover freq
+ *
+ * @systemapi this method can be used only by system applications.
+ */
+ enum ExchangeFreq {
+ /**
+ * Low
+ */
+ LOW = 0,
+
+ /**
+ * Medium
+ */
+ MID = 1,
+
+ /**
+ * High
+ */
+ HIGH = 2,
+
+ /**
+ * Super-high
+ */
+ SUPER_HIGH = 3
+ }
+
+ /**
+ * device discover capability
+ *
+ * @systemapi this method can be used only by system applications.
+ */
+ enum SubscribeCap {
+ /**
+ * ddmpCapability
+ */
+ SUBSCRIBE_CAPABILITY_DDMP = 0
+ }
+
+ /**
+ * Device Authentication param
+ *
+ * @systemapi this method can be used only by system applications
+ */
+ interface AuthParam {
+ /**
+ * Authentication type, 1 for pin code.
+ */
+ authType: number;
+
+ /**
+ * App application Icon.
+ */
+ appIcon?: Uint8Array;
+
+ /**
+ * App application thumbnail.
+ */
+ appThumbnail?: Uint8Array;
+
+ /**
+ * Authentication extra infos.
+ */
+ extraInfo: {[key:string] : any};
+
+ }
+
+ /**
+ * Device auth info.
+ *
+ * @systemapi this method can be used only by system applications
+ */
+ interface AuthInfo {
+ /**
+ * Authentication type, 1 for pin code.
+ */
+ authType: number;
+
+ /**
+ * the token used for this authentication.
+ */
+ token: number;
+
+ /**
+ * Authentication extra infos.
+ */
+ extraInfo: {[key:string] : any};
+ }
+
+ /**
+ * User Operation Action from devicemanager Fa.
+ *
+ * @systemapi this method can be used only by system applications.
+ */
+ enum UserOperationAction {
+ /**
+ * allow authentication
+ */
+ ACTION_ALLOW_AUTH = 0,
+
+ /**
+ * cancel authentication
+ */
+ ACTION_CANCEL_AUTH = 1,
+
+ /**
+ * user operation timeout for authentication confirm
+ */
+ ACTION_AUTH_CONFIRM_TIMEOUT = 2,
+
+ /**
+ * cancel pincode display
+ */
+ ACTION_CANCEL_PINCODE_DISPLAY = 3,
+
+ /**
+ * cancel pincode input
+ */
+ ACTION_CANCEL_PINCODE_INPUT = 4,
+ }
+
+ /**
+ * Creates a {@code DeviceManager} instance.
+ *
+ *
To manage devices, you must first call this method to obtain a {@code DeviceManager} instance and then
+ * use this instance to call other device management methods.
+ *
+ * @param bundleName Indicates the bundle name of the application.
+ * @param callback Indicates the callback to be invoked upon {@code DeviceManager} instance creation.
+ */
+ function createDeviceManager(bundleName: string, callback: AsyncCallback): void;
+
+ /**
+ * Provides methods for managing devices.
+ */
+ interface DeviceManager {
+ /**
+ * Releases the {@code DeviceManager} instance after the methods for device management are no longer used.
+ */
+ release(): void;
+
+ /**
+ * Obtains a list of trusted devices.
+ *
+ * @param options Indicates the extra parameters to be passed to this method for device filtering or sorting.
+ * This parameter can be null. For details about available values, see {@link #TARGET_PACKAGE_NAME} and
+ * {@link #SORT_TYPE}.
+ * @return Returns a list of trusted devices.
+ */
+ getTrustedDeviceListSync(): Array;
+
+ /**
+ * Start to discover device.
+ *
+ * @param bundleName Indicates the bundle name of the application.
+ * @param subscribeInfo subscribe info to discovery device
+ * @systemapi this method can be used only by system applications.
+ */
+ startDeviceDiscovery(subscribeInfo: SubscribeInfo): void;
+
+ /**
+ * Stop to discover device.
+ *
+ * @param bundleName Indicates the bundle name of the application.
+ * @param subscribeId Service subscribe ID
+ * @systemapi this method can be used only by system applications.
+ */
+ stopDeviceDiscovery(subscribeId: number): void;
+
+ /**
+ * Authenticate the specified device.
+ *
+ * @param deviceInfo deviceInfo of device to authenticate
+ * @param authparam authparam of device to authenticate
+ * @param callback Indicates the callback to be invoked upon authenticateDevice
+ * @systemapi this method can be used only by system applications.
+ */
+ authenticateDevice(deviceInfo: DeviceInfo, authparam: AuthParam, callback: AsyncCallback<{deviceId: string, pinTone ?: number}>): void;
+
+ /**
+ * verify auth info, such as pin code.
+ *
+ * @param authInfo device auth info o verify
+ * @param callback Indicates the callback to be invoked upon verifyAuthInfo
+ * @systemapi this method can be used only by system applications.
+ */
+ verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void;
+
+ /**
+ * Get authenticate parameters for peer device, this interface can only used by devicemanager Fa.
+ *
+ * @param authParam authparam for peer device
+ * @systemapi this method can be used only by system applications.
+ */
+ getAuthenticationParam(): AuthParam;
+
+ /**
+ * Set user Operation from devicemanager Fa, this interface can only used by devicemanager Fa.
+ *
+ * @param operateAction User Operation Actions.
+ * @systemapi this method can be used only by system applications.
+ */
+ setUserOperation(operateAction: UserOperationAction): void;
+
+ /**
+ * Register a callback from deviceManager service so that the devicemanager Fa can be notified when some events happen.
+ * this interface can only used by devicemanager Fa.
+ *
+ * @param callback for devicemanager Fa to register.
+ * @systemapi this method can be used only by system applications.
+ */
+ on(type: 'dmFaCallback', callback: Callback<{ param: string}>): void;
+
+ /**
+ * UnRegister dmFaCallback, this interface can only used by devicemanager Fa.
+ *
+ * @param callback for devicemanager Fa to register.
+ * @systemapi this method can be used only by system applications.
+ */
+ off(type: 'dmFaCallback', callback?: Callback<{ param: string}>): void;
+
+ /**
+ * Register a device state callback so that the application can be notified upon device state changes based on
+ * the application bundle name.
+ *
+ * @param bundleName Indicates the bundle name of the application.
+ * @param callback Indicates the device state callback to register.
+ */
+ on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
+
+ /**
+ * UnRegister device state callback based on the application bundle name.
+ *
+ * @param bundleName Indicates the bundle name of the application.
+ * @param callback Indicates the device state callback to register.
+ */
+ off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
+
+ /**
+ * Register a device found callback so that the application can be notified when the device was found
+ *
+ * @param callback Indicates the device found callback to register.
+ * @systemapi this method can be used only by system applications.
+ */
+ on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
+
+ /**
+ * UnRegister a device found callback so that the application can be notified when the device was found
+ *
+ * @param callback Indicates the device found callback to register.
+ * @systemapi this method can be used only by system applications.
+ */
+ off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
+
+ /**
+ * Register a device found result callback so that the application can be notified when the device discover was failed
+ *
+ * @param callback Indicates the device found result callback to register.
+ * @systemapi this method can be used only by system applications.
+ */
+ on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void;
+
+ /**
+ * UnRegister a device found result callback so that the application can be notified when the device discover was failed
+ *
+ * @param callback Indicates the device found result callback to register.
+ * @systemapi this method can be used only by system applications.
+ */
+ off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void;
+
+ /**
+ * Register a serviceError callback so that the application can be notified when devicemanager service died
+ *
+ * @param callback Indicates the service error callback to register.
+ */
+ on(type: 'serviceDie', callback: () => void): void;
+
+ /**
+ * UnRegister a serviceError callback so that the application can be notified when devicemanager service died
+ *
+ * @param callback Indicates the service error callback to register.
+ */
+ off(type: 'serviceDie', callback?: () => void): void;
+ }
+}
+
+export default deviceManager;
diff --git a/display/build.gradle b/display/build.gradle
new file mode 100644
index 00000000..151e80b6
--- /dev/null
+++ b/display/build.gradle
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ // Top-level build file where you can add configuration options common to all sub-projects/modules.
+apply plugin: 'com.huawei.ohos.app'
+
+ohos {
+ compileSdkVersion 6
+ defaultConfig {
+ compatibleSdkVersion 6
+ }
+}
+
+buildscript {
+ repositories {
+ maven {
+ url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
+ }
+ maven {
+ url 'https://mirrors.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.huawei.ohos:hap:2.4.4.3-RC'
+ }
+}
+
+allprojects {
+ repositories {
+ maven {
+ url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
+ }
+ maven {
+ url 'https://mirrors.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
+ jcenter()
+ }
+}
\ No newline at end of file
diff --git a/display/entry/build.gradle b/display/entry/build.gradle
new file mode 100644
index 00000000..1f560cd4
--- /dev/null
+++ b/display/entry/build.gradle
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ apply plugin: 'com.huawei.ohos.hap'
+apply plugin: 'com.huawei.ohos.decctest'
+//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
+ohos {
+ compileSdkVersion 6
+ defaultConfig {
+ compatibleSdkVersion 6
+ }
+ buildTypes {
+ release {
+ proguardOpt {
+ proguardEnabled false
+ rulesFiles 'proguard-rules.pro'
+ }
+ }
+ }
+
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
+ testImplementation 'junit:junit:4.13'
+ ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.200'
+}
+decc {
+ supportType = ['html', 'xml']
+}
diff --git a/display/entry/src/main/config.json b/display/entry/src/main/config.json
new file mode 100644
index 00000000..946df5f4
--- /dev/null
+++ b/display/entry/src/main/config.json
@@ -0,0 +1,61 @@
+{
+ "app": {
+ "bundleName": "com.ohos.devicemanagerui",
+ "vendor": "ohos",
+ "version": {
+ "code": 1000000,
+ "name": "1.0.0"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "com.ohos.devicemanagerui",
+ "name": ".MyApplication",
+ "mainAbility": "com.ohos.devicemanagerui.MainAbility",
+ "deviceType": [
+ "phone",
+ "tablet",
+ "tv",
+ "wearable"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "entry",
+ "moduleType": "entry",
+ "installationFree": false
+ },
+ "abilities": [
+ {
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home"
+ ]
+ }
+ ],
+ "visible": true,
+ "name": "com.ohos.devicemanagerui.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "$string:entry_MainAbility",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ],
+ "js": [
+ {
+ "pages": [
+ "pages/index/index"
+ ],
+ "name": "default",
+ "window": {
+ "designWidth": 720,
+ "autoDesignWidth": true
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/default/app.js b/display/entry/src/main/js/default/app.js
new file mode 100644
index 00000000..8e47afff
--- /dev/null
+++ b/display/entry/src/main/js/default/app.js
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export default {
+ onCreate() {
+ console.info('AceApplication onCreate');
+ },
+ onDestroy() {
+ console.info('AceApplication onDestroy');
+ }
+};
diff --git a/display/entry/src/main/js/default/i18n/en-US.json b/display/entry/src/main/js/default/i18n/en-US.json
new file mode 100644
index 00000000..9e520910
--- /dev/null
+++ b/display/entry/src/main/js/default/i18n/en-US.json
@@ -0,0 +1,4 @@
+{
+ "strings": {
+ }
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/default/i18n/zh-CN.json b/display/entry/src/main/js/default/i18n/zh-CN.json
new file mode 100644
index 00000000..9e520910
--- /dev/null
+++ b/display/entry/src/main/js/default/i18n/zh-CN.json
@@ -0,0 +1,4 @@
+{
+ "strings": {
+ }
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/default/pages/index/index.css b/display/entry/src/main/js/default/pages/index/index.css
new file mode 100644
index 00000000..13230219
--- /dev/null
+++ b/display/entry/src/main/js/default/pages/index/index.css
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+.container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ opacity: 0.8;
+ background-color: azure;
+}
+
+.container > div {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+}
+
+.main-pin > .pin-numb {
+ flex-direction: row;
+ justify-content: space-around;
+ align-items: center;
+ padding: 15px 30px 10px 30px;
+}
+.main-pin > .pin-numb > .pin-numb-item {
+ font-size: 30px;
+ line-height: 30px;
+ height: 40px;
+ padding-bottom: 5px;
+ font-weight: 800;
+ width: 30px;
+ border-bottom-width: 2px;
+ border-bottom-color: darkgray;
+ text-align: center;
+}
+
+.main-pin > .input {
+ flex-direction: row;
+ justify-content: space-around;
+ align-items: center;
+ padding: 5px 30px 5px 30px;
+}
+
+.main-pin > .input > .numb {
+ text-color: black;
+ padding: 5px;
+ flex-shrink: 0;
+ flex-basis: 60px;
+ background-color: white;
+ border: 1px;
+}
+
+.join-auth {
+ padding-top: 30px;
+}
+.join-auth-image > image {
+ height: 170px;
+}
+.join-authorize {
+ padding-top: 10px;
+}
+.join-pin {
+ padding: 10px 0;
+}
+.join-pin > .pin {
+ font-size: 50px;
+ line-height: 90px;
+ font-weight: bolder;
+ color: #000000;
+}
+
+.join-auth > .title,
+.join-auth-image > .title,
+.join-authorize > .title {
+ font-size: 18px;
+ line-height: 80px;
+ font-weight: 800;
+ color: #000000;
+}
+.join-auth > .title {
+ line-height: 40px;
+}
+.join-auth-image > .title {
+ line-height: 26px;
+}
+.join-pin > .title {
+ font-size: 28px;
+ line-height: 60px;
+ font-weight: 800;
+}
+.main-pin > .title {
+ font-size: 30px;
+ line-height: 40px;
+ font-weight: bolder;
+}
+
+.join-auth > .title-tip,
+.join-auth-image > .title-tip,
+.main-pin > .title-tip,
+.join-authorize > .title-tip {
+ font-size: 15px;
+ line-height: 40px;
+ color: #5A5A5A;
+}
+.join-auth > .title-tip {
+ line-height: 40px;
+}
+.join-auth-image > .title-tip {
+ line-height: 24px;
+}
+.join-pin > .title-tip {
+ font-size: 20px;
+ line-height: 50px;
+ font-weight: 600;
+}
+.main-pin > .title-tip {
+ font-size: 18px;
+ line-height: 30px;
+ font-weight: 800;
+}
+
+.join-auth > .dialog-foot,
+.join-auth-image > .dialog-foot,
+.join-authorize > .dialog-foot {
+ flex-direction: row;
+ justify-content: center;
+ align-items: center;
+ justify-content: space-around;
+ margin: 80px 20px 30px 20px;
+}
+.join-authorize > .dialog-foot {
+ margin: 100px 20px 30px 20px;
+}
+.join-auth-image > .dialog-foot {
+ margin: 10px 20px 10px 20px;
+}
+.join-pin > .dialog-foot {
+ margin: 10px 20px 10px 20px;
+}
+
+.join-auth .button-cancel,
+.join-auth-image .button-cancel,
+.join-authorize .button-cancel {
+ width: 160px;
+ height: 36px;
+}
+.join-pin .button-cancel {
+ width: 100%;
+ font-size: 26px;
+ height: 50px;
+}
+
+.join-auth .button-ok,
+.join-auth-image .button-ok,
+.join-authorize .button-ok {
+ width: 150px;
+ height: 36px;
+}
\ No newline at end of file
diff --git a/display/entry/src/main/js/default/pages/index/index.hml b/display/entry/src/main/js/default/pages/index/index.hml
new file mode 100644
index 00000000..7f388b21
--- /dev/null
+++ b/display/entry/src/main/js/default/pages/index/index.hml
@@ -0,0 +1,98 @@
+
+
+
+
+
PIN码连接
+
请输入平板上显示的PIN码
+
+ {{pin[0]}}
+ {{pin[1]}}
+ {{pin[2]}}
+ {{pin[3]}}
+ {{pin[4]}}
+ {{pin[5]}}
+
+
+ 1
+ 2
+ 3
+ 4
+
+
+ 5
+ 6
+ 7
+ 8
+
+
+ 9
+ 0
+ 删除
+ 取消
+
+
+
+ 是否允许{{statusInfo.deviceName}}连接本机
+ 用于资源访问
+
+
+
+ {{ statusInfo.appName }}
+ 是否允许打开apply auth?
+ 来自{{statusInfo.deviceName}}
+
+
+
+
+ {{ statusInfo.appName }}
+ 是否允许打开apply auth?
+ 来自{{statusInfo.deviceName}}
+
+
+
+ PIN码连接
+ 请在主控端输入连接码进行验证
+ {{statusInfo.pinCode.split('').join(' ')}}
+
+
+
diff --git a/display/entry/src/main/js/default/pages/index/index.js b/display/entry/src/main/js/default/pages/index/index.js
new file mode 100644
index 00000000..0304a8d5
--- /dev/null
+++ b/display/entry/src/main/js/default/pages/index/index.js
@@ -0,0 +1,331 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import router from '@system.router';
+import deviceManager from '@ohos.distributedHardware.deviceManager';
+function uint8ArrayToBase64(array) {
+ array = new Uint8Array(array);
+ let table = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'],
+ base64Str = '', length = array.byteLength, i = 0;
+ for(i = 0; length - i >= 3; i += 3) {
+ let num1 = array[i], num2 = array[i + 1], num3 = array[i + 2];
+ base64Str += table[num1 >>> 2] + table[((num1 & 0b11) << 4) | (num2 >>> 4)] + table[((num2 & 0b1111) << 2) | (num3 >>> 6)] + table[num3 & 0b111111];
+ }
+ const lastByte = length - i;
+ if (lastByte === 1) {
+ const lastNum1 = array[i];
+ base64Str += table[lastNum1 >>> 2] + table[((lastNum1 & 0b11) << 4)] + '==';
+ } else if (lastByte === 2) {
+ const lastNum1 = array[i];
+ const lastNum2 = array[i + 1];
+ base64Str += table[lastNum1 >>> 2] + table[((lastNum1 & 0b11) << 4) | (lastNum2 >>> 4)] + table[(lastNum2 & 0b1111) << 2] + '=';
+ }
+ return 'data:image/png;base64,' + base64Str;
+}
+const TAG = "DeviceManagerUI:";
+let dmClass;
+
+export default {
+ data: {
+ // showType: ['main-pin','join-authorize','join-auth','join-auth-image','join-pin']
+ status: "",
+ // showInfo
+ statusInfo: {
+ deviceName: "AppName",
+ appName: 'PackageName',
+ appIcon: null,
+ pinCode: '',
+ pinToken: ''
+ },
+ // join: join-authorize timing
+ timeRemaining: 0,
+ // input pinCode
+ pin: ['','','','','',''],
+ // input pinCode next number
+ pinNumb: 0
+ },
+
+ log(m) {
+ console.info(TAG + m);
+ },
+
+ onDestroy() {
+ if (dmClass != null) {
+ dmClass.off('dmFaCallback');
+ dmClass.off('deviceStateChange');
+ dmClass.off('serviceDie');
+ dmClass.release();
+ dmClass = null
+ }
+ },
+
+ onShow() {
+ if (dmClass) {
+ this.initStatue()
+ } else {
+ this.log('createDeviceManager')
+ deviceManager.createDeviceManager('com.ohos.devicemanagerui', (err, dm) => {
+ this.log("createDeviceManager err:" + JSON.stringify(err) + ' --success:' + JSON.stringify(dm))
+ if (err) return;
+ dmClass = dm;
+ dmClass.on('dmFaCallback', () => router.back())
+ this.initStatue()
+ });
+ }
+ },
+
+ onHide() {
+ this.timeRemaining = 0
+ },
+
+ /**
+ * Get authentication param
+ */
+ initStatue() {
+ this.log('initStatue')
+ const data = dmClass.getAuthenticationParam()
+ this.log('getAuthenticationParam:' + JSON.stringify(data))
+ // Authentication type, 1 for pin code.
+ if (data && data.authType == 1) {
+ this.statusInfo = {
+ deviceName: data.extraInfo.PackageName,
+ appName: data.extraInfo.appName,
+ appIcon: uint8ArrayToBase64(data.appIcon),
+ pinCode: data.extraInfo.pinCode + '',
+ pinToken: data.extraInfo.pinToken
+ }
+ // direction: 1(main)/0(join)
+ if (data.extraInfo.direction == 1) {
+ this.mainPin()
+ } else if (data.appIcon) {
+ this.joinAuthImage()
+ } else if (data.extraInfo.business == 0) {
+ // business: 0(FA流转)/1(资源访问)
+ this.joinAuth()
+ } else {
+ this.joinAuthorize()
+ }
+ }
+ },
+
+ /**
+ * Set user Operation from devicemanager Fa, this interface can only used by devicemanager Fa.
+ *
+ * @param operateAction User Operation Actions.
+ * ACTION_ALLOW_AUTH = 0, allow authentication
+ * ACTION_CANCEL_AUTH = 1, cancel authentication
+ * ACTION_AUTH_CONFIRM_TIMEOUT = 2, user operation timeout for authentication confirm
+ * ACTION_CANCEL_PINCODE_DISPLAY = 3, cancel pinCode display
+ * ACTION_CANCEL_PINCODE_INPUT = 4, cancel pinCode input
+ */
+ setUserOperation(operation) {
+ this.log('setUserOperation: ' + operation)
+ if (dmClass != null) {
+ var data = dmClass.setUserOperation(operation);
+ this.log('setUserOperation result: ' + JSON.stringify(data))
+ } else {
+ this.log('deviceManagerObject not exit')
+ }
+ },
+
+ /**
+ * verify auth info, such as pin code.
+ * @param pinCode
+ * @return
+ */
+ verifyAuthInfo(pinCode) {
+ this.log('verifyAuthInfo: ' + pinCode)
+ if (dmClass != null) {
+ dmClass.verifyAuthInfo({
+ "authType": 1,
+ "token": this.statusInfo.pinToken,
+ "extraInfo": {
+ "pinCode": +pinCode
+ }
+ }, (err, data) => {
+ if (err) {
+ this.log("verifyAuthInfo err:" + JSON.stringify(err))
+ }
+ this.log("verifyAuthInfo result:" + JSON.stringify(data))
+ router.back()
+ });
+ } else {
+ this.log('deviceManagerObject not exit')
+ }
+ },
+
+ /**
+ * Input pinCode at the main control terminal
+ */
+ mainPin() {
+ this.status = 'main-pin'
+ },
+
+ /**
+ * Enter a number with the keyboard
+ * @param s
+ * @return
+ */
+ mainInputPin(s) {
+ this.log('mainInputPin input: ' + s + '-' + this.pin)
+ if (this.pinNumb == 6) return
+ if (this.pinNumb < 6) {
+ this.pin[this.pinNumb] = s
+ ++this.pinNumb
+ this.pin = [...this.pin]
+ }
+ this.log('mainInputPin pin: ' + this.pin + '-' + this.pin.join(''))
+ if (this.pinNumb == 6) {
+ // input end
+ this.log('mainInputPin end: ' + this.pin + '-' + this.pin.join(''))
+ this.verifyAuthInfo(this.pin.join(''))
+ }
+ },
+
+ /**
+ * Keyboard delete number
+ */
+ mainInputPinBack() {
+ if (this.pinNumb > 0) {
+ --this.pinNumb
+ this.pin[this.pinNumb] = ''
+ this.pin = [...this.pin]
+ }
+ },
+
+ /**
+ * Cancel pinCode input
+ */
+ mainInputPinCancel() {
+ this.setUserOperation(4)
+ },
+
+ /**
+ * Join end authorization, business(FA流转)/1(资源访问): 0
+ */
+ joinAuthorize() {
+ this.status = 'join-authorize'
+ this.timing(60, 'join-authorize', () => {
+ this.setUserOperation(2)
+ router.back()
+ })
+ },
+
+ /**
+ * Join end authorization, business(FA流转)/1(资源访问): 1
+ */
+ joinAuth() {
+ this.status = 'join-auth'
+ this.timing(60, 'join-auth', () => {
+ this.setUserOperation(2)
+ router.back()
+ })
+ },
+
+ /**
+ * Join end authorization, business(FA流转)/1(资源访问): 1, show application icon
+ */
+ joinAuthImage() {
+ this.status = 'join-auth-image'
+ this.timing(60, 'join-auth-image', () => {
+ this.setUserOperation(2)
+ router.back()
+ })
+ },
+
+ /**
+ * Display pinCode at join end
+ */
+ joinPin() {
+ this.status = 'join-pin'
+ },
+
+ /**
+ * Cancel authorization
+ */
+ joinAuthorizeCancel() {
+ this.setUserOperation(1)
+ router.back()
+ },
+
+ /**
+ * Confirm authorization
+ */
+ joinAuthorizeOk() {
+ this.setUserOperation(0)
+ this.joinPin()
+ },
+
+ /**
+ * Cancel authorization
+ */
+ joinAuthCancel() {
+ this.setUserOperation(1)
+ router.back()
+ },
+
+ /**
+ * Confirm authorization
+ */
+ joinAuthOk() {
+ this.setUserOperation(0)
+ this.joinPin()
+ },
+
+ /**
+ * Cancel authorization
+ */
+ joinAuthImageCancel() {
+ this.setUserOperation(1)
+ router.back()
+ },
+
+ /**
+ * Confirm authorization
+ */
+ joinAuthImageOk() {
+ this.setUserOperation(0)
+ this.joinPin()
+ },
+
+ /**
+ * Cancel authorization
+ */
+ joinPinCancel() {
+ this.setUserOperation(3)
+ router.back()
+ },
+
+ /**
+ * Pure function countdown
+ * @param numb second
+ * @param status
+ * @param callback
+ * @return
+ */
+ timing(numb, status, callback) {
+ this.timeRemaining = numb
+ const next = () => {
+ if (status != this.status) return
+ --this.timeRemaining
+ if (this.timeRemaining > 0) {
+ setTimeout(next, 1000)
+ } else {
+ callback()
+ }
+ }
+ next()
+ }
+}
diff --git a/display/entry/src/main/resources/base/element/string.json b/display/entry/src/main/resources/base/element/string.json
new file mode 100644
index 00000000..0bae6bd4
--- /dev/null
+++ b/display/entry/src/main/resources/base/element/string.json
@@ -0,0 +1,12 @@
+{
+ "string": [
+ {
+ "name": "entry_MainAbility",
+ "value": "entry_MainAbility"
+ },
+ {
+ "name": "mainability_description",
+ "value": "JS_Empty Ability"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/display/entry/src/main/resources/base/media/icon.png b/display/entry/src/main/resources/base/media/icon.png
new file mode 100644
index 00000000..ce307a88
Binary files /dev/null and b/display/entry/src/main/resources/base/media/icon.png differ
diff --git a/display/settings.gradle b/display/settings.gradle
new file mode 100644
index 00000000..4773db73
--- /dev/null
+++ b/display/settings.gradle
@@ -0,0 +1 @@
+include ':entry'
diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn
new file mode 100644
index 00000000..799bb65a
--- /dev/null
+++ b/services/devicemanagerservice/BUILD.gn
@@ -0,0 +1,202 @@
+# Copyright (C) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+if (defined(ohos_lite)) {
+ import("//build/lite/config/component/lite_component.gni")
+} else {
+ import("//build/ohos.gni")
+}
+
+import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
+
+if (defined(ohos_lite)) {
+ executable("devicemanagerservice") {
+ include_dirs = [
+ "include",
+ "include/adapter",
+ "include/authentication",
+ "include/ability",
+ "include/deviceinfo",
+ "include/devicestate",
+ "include/discovery",
+ "include/dependency/hichain",
+ "include/dependency/softbus",
+ "include/dependency/timer",
+ "include/ipc",
+ "include/ipc/lite",
+ "${common_path}/include",
+ "${common_path}/include/ipc",
+ "${common_path}/include/ipc/model",
+ "${utils_path}/include",
+ "${utils_path}/include/ipc/lite",
+ "${innerkits_path}/native_cpp/include",
+ "${innerkits_path}/native_cpp/include/ipc",
+ "${innerkits_path}/native_cpp/include/ipc/lite",
+ ]
+
+ include_dirs += [
+ "//base/security/deviceauth/interfaces/innerkits",
+ "//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include",
+ "//utils/native/lite/include",
+ "//utils/system/safwk/native/include",
+ "//third_party/json/include",
+ "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
+ "//third_party/bounds_checking_function/include",
+ "//foundation/communication/ipc_lite/interfaces/kits",
+ "//foundation/communication/dsoftbus/interfaces/kits/bus_center",
+ "//foundation/communication/dsoftbus/interfaces/kits/common",
+ "//foundation/communication/dsoftbus/interfaces/kits/discovery",
+ "//foundation/communication/dsoftbus/interfaces/kits/transport",
+ "//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
+ "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
+ ]
+
+ sources = [
+ "src/ability/lite/dm_ability_manager.cpp",
+ "src/adapter/lite/dm_adapter_manager.cpp",
+ "src/authentication/auth_message_processor.cpp",
+ "src/authentication/auth_request_state.cpp",
+ "src/authentication/auth_response_state.cpp",
+ "src/authentication/auth_ui.cpp",
+ "src/authentication/dm_auth_manager.cpp",
+ "src/dependency/hichain/hichain_connector.cpp",
+ "src/dependency/softbus/softbus_connector.cpp",
+ "src/dependency/softbus/softbus_session.cpp",
+ "src/dependency/timer/dm_timer.cpp",
+ "src/device_manager_service.cpp",
+ "src/device_manager_service_listener.cpp",
+ "src/deviceinfo/dm_device_info_manager.cpp",
+ "src/devicestate/dm_device_state_manager.cpp",
+ "src/discovery/dm_discovery_manager.cpp",
+ "src/ipc/lite/ipc_cmd_parser.cpp",
+ "src/ipc/lite/ipc_server_listener.cpp",
+ "src/ipc/lite/ipc_server_listenermgr.cpp",
+ "src/ipc/lite/ipc_server_main.cpp",
+ "src/ipc/lite/ipc_server_stub.cpp",
+ ]
+
+ defines = [
+ "LITE_DEVICE",
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"devicemanagerservice\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+ deps = [
+ "${innerkits_path}/native_cpp:devicemanagersdk",
+ "${utils_path}:devicemanagerutils",
+ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
+ "//base/security/deviceauth/services:deviceauth_sdk",
+ "//base/startup/syspara_lite/frameworks/parameter/src:sysparam",
+ "//foundation/communication/dsoftbus/sdk:softbus_client",
+ "//foundation/communication/ipc_lite:liteipc_adapter",
+ "//foundation/distributedschedule/samgr_lite/samgr:samgr",
+ "//utils/native/lite:utils",
+ ]
+ }
+} else {
+ ohos_shared_library("devicemanagerservice") {
+ include_dirs = [
+ "include",
+ "include/config",
+ "include/adapter",
+ "include/authentication",
+ "include/ability",
+ "include/deviceinfo",
+ "include/devicestate",
+ "include/discovery",
+ "include/dependency/commonevent",
+ "include/dependency/hichain",
+ "include/dependency/softbus",
+ "include/dependency/timer",
+ "include/ipc",
+ "include/ipc/standard",
+ "include/eventbus",
+ "${common_path}/include",
+ "${common_path}/include/ipc",
+ "${common_path}/include/ipc/model",
+ "${utils_path}/include",
+ "${utils_path}/include/ipc/standard",
+ "${innerkits_path}/native_cpp/include",
+ "${innerkits_path}/native_cpp/include/ipc",
+ "${innerkits_path}/native_cpp/include/ipc/standard",
+ "//utils/native/base/include",
+ "//utils/system/safwk/native/include",
+ "//base/notification/ces_standard/frameworks/core/include",
+ "//base/notification/ces_standard/interfaces/innerkits/native/include",
+ "//base/security/deviceauth/interfaces/innerkits",
+ "//base/startup/syspara_lite/interfaces/kits",
+ "//base/startup/syspara_lite/adapter/native/syspara/include",
+ "//third_party/json/include",
+ ]
+
+ sources = [
+ "src/ability/standard/dm_ability_manager.cpp",
+ "src/adapter/standard/dm_adapter_manager.cpp",
+ "src/authentication/auth_message_processor.cpp",
+ "src/authentication/auth_request_state.cpp",
+ "src/authentication/auth_response_state.cpp",
+ "src/authentication/auth_ui.cpp",
+ "src/authentication/dm_auth_manager.cpp",
+ "src/config/config_manager.cpp",
+ "src/dependency/commonevent/event_manager_adapt.cpp",
+ "src/dependency/hichain/hichain_connector.cpp",
+ "src/dependency/softbus/softbus_connector.cpp",
+ "src/dependency/softbus/softbus_session.cpp",
+ "src/dependency/timer/dm_timer.cpp",
+ "src/device_manager_service.cpp",
+ "src/device_manager_service_listener.cpp",
+ "src/deviceinfo/dm_device_info_manager.cpp",
+ "src/devicestate/dm_device_state_manager.cpp",
+ "src/discovery/dm_discovery_manager.cpp",
+ "src/ipc/standard/ipc_cmd_parser.cpp",
+ "src/ipc/standard/ipc_server_client_proxy.cpp",
+ "src/ipc/standard/ipc_server_listener.cpp",
+ "src/ipc/standard/ipc_server_stub.cpp",
+ ]
+
+ deps = [
+ "${innerkits_path}/native_cpp:devicemanagersdk",
+ "${utils_path}:devicemanagerutils",
+ "//base/security/deviceauth/services:deviceauth_sdk",
+ "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
+ "//foundation/aafwk/standard/interfaces/innerkits/want:want",
+ "//foundation/aafwk/standard/services/abilitymgr:abilityms",
+ "//utils/native/base:utils",
+ ]
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"devicemanagerservice\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+ external_deps = [
+ "appexecfwk_standard:appexecfwk_base",
+ "appexecfwk_standard:appexecfwk_core",
+ "appexecfwk_standard:libeventhandler",
+ "ces_standard:cesfwk_core",
+ "ces_standard:cesfwk_innerkits",
+ "dsoftbus_standard:softbus_client",
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ "startup_l2:syspara",
+ ]
+
+ subsystem_name = "distributedhardware"
+
+ part_name = "device_manager_base"
+ }
+}
\ No newline at end of file
diff --git a/services/devicemanagerservice/include/ability/dm_ability_manager.h b/services/devicemanagerservice/include/ability/dm_ability_manager.h
new file mode 100644
index 00000000..64c27a5e
--- /dev/null
+++ b/services/devicemanagerservice/include/ability/dm_ability_manager.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_ABILITY_MANAGER_H
+#define OHOS_DM_ABILITY_MANAGER_H
+
+#include
+
+#include
+#include
+#include
+
+#include "single_instance.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+enum AbilityRole { ABILITY_ROLE_PASSIVE = 0, ABILITY_ROLE_INITIATIVE = 1, ABILITY_ROLE_UNKNOWN = 2 };
+
+enum AbilityStatus { ABILITY_STATUS_FAILED = 0, ABILITY_STATUS_SUCCESS = 1, ABILITY_STATUS_START = 2 };
+
+enum FaAction {
+ USER_OPERATION_TYPE_ALLOW_AUTH = 0,
+ USER_OPERATION_TYPE_CANCEL_AUTH = 1,
+ USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT = 2,
+ USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY = 3,
+ USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT = 4
+};
+
+class DmAbilityManager {
+public:
+ AbilityRole GetAbilityRole();
+ AbilityStatus StartAbility(AbilityRole role);
+ void StartAbilityDone();
+
+private:
+ void waitForTimeout(uint32_t timeout_s);
+
+private:
+ sem_t mSem_;
+ AbilityStatus mStatus_;
+ AbilityRole mAbilityStatus_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif
diff --git a/services/devicemanagerservice/include/adapter/crypto_adapter.h b/services/devicemanagerservice/include/adapter/crypto_adapter.h
new file mode 100644
index 00000000..099107ed
--- /dev/null
+++ b/services/devicemanagerservice/include/adapter/crypto_adapter.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_CRYPTO_ADAPTER_H
+#define OHOS_DM_CRYPTO_ADAPTER_H
+
+#include
+
+namespace OHOS {
+namespace DistributedHardware {
+class ICryptoAdapter {
+public:
+ virtual ~ICryptoAdapter() = default;
+ virtual std::string GetName() = 0;
+ virtual std::string GetVersion() = 0;
+ virtual int32_t MbedTlsEncrypt(const uint8_t *plainText, int32_t plainTextLen, uint8_t *cipherText,
+ int32_t cipherTextLen, int32_t *outLen) = 0;
+ virtual int32_t MbedTlsDecrypt(const uint8_t *cipherText, int32_t cipherTextLen, uint8_t *plainText,
+ int32_t plainTextLen, int32_t *outLen) = 0;
+};
+
+using CreateICryptoAdapterFuncPtr = ICryptoAdapter *(*)(void);
+
+} // namespace DistributedHardware
+} // namespace OHOS
+
+#endif // OHOS_DM_CRYPTO_ADAPTER_H
diff --git a/services/devicemanagerservice/include/adapter/decision_adapter.h b/services/devicemanagerservice/include/adapter/decision_adapter.h
new file mode 100644
index 00000000..7e96a823
--- /dev/null
+++ b/services/devicemanagerservice/include/adapter/decision_adapter.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_DECISION_ADAPTER_H
+#define OHOS_DM_DECISION_ADAPTER_H
+
+#include
+#include
+
+#include "dm_device_info.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class IDecisionAdapter {
+public:
+ virtual ~IDecisionAdapter() = default;
+ virtual std::string GetName() = 0;
+ virtual std::string GetVersion() = 0;
+ virtual int32_t FilterDeviceList(std::vector &infoList, const std::string &filterOptions) = 0;
+ virtual int32_t SortDeviceList(std::vector &infoList, const std::string &sortOptions) = 0;
+};
+
+using CreateIDecisionAdapterFuncPtr = IDecisionAdapter *(*)(void);
+
+} // namespace DistributedHardware
+} // namespace OHOS
+
+#endif // OHOS_DM_DECISION_ADAPTER_H
diff --git a/services/devicemanagerservice/include/adapter/dm_adapter_manager.h b/services/devicemanagerservice/include/adapter/dm_adapter_manager.h
new file mode 100644
index 00000000..b290e836
--- /dev/null
+++ b/services/devicemanagerservice/include/adapter/dm_adapter_manager.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_ADAPTER_MANAGER_H
+#define OHOS_DM_ADAPTER_MANAGER_H
+
+#include
+
+#include "crypto_adapter.h"
+#include "decision_adapter.h"
+#include "profile_adapter.h"
+#include "single_instance.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class IProfileAdapter;
+class DmAdapterManager {
+ DECLARE_SINGLE_INSTANCE(DmAdapterManager);
+
+public:
+ std::shared_ptr GetDecisionAdapter(const std::string &soName);
+ std::shared_ptr GetProfileAdapter(const std::string &soName);
+ std::shared_ptr GetCryptoAdapter(const std::string &soName);
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_ADAPTER_MANAGER_H
diff --git a/services/devicemanagerservice/include/adapter/profile_adapter.h b/services/devicemanagerservice/include/adapter/profile_adapter.h
new file mode 100644
index 00000000..39f5a3de
--- /dev/null
+++ b/services/devicemanagerservice/include/adapter/profile_adapter.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_PROFILE_ADAPTER_H
+#define OHOS_DM_PROFILE_ADAPTER_H
+
+#include
+#include
+
+namespace OHOS {
+namespace DistributedHardware {
+class DmDeviceStateManager;
+class IProfileAdapter {
+public:
+ virtual ~IProfileAdapter() = default;
+ virtual int32_t RegisterProfileListener(const std::string &pkgName, const std::string &deviceId,
+ std::shared_ptr callback) = 0;
+ virtual int32_t UnRegisterProfileListener(const std::string &pkgName) = 0;
+};
+
+using CreateIProfileAdapterFuncPtr = IProfileAdapter *(*)(void);
+
+} // namespace DistributedHardware
+} // namespace OHOS
+
+#endif // OHOS_DM_PROFILE_ADAPTER_H
diff --git a/services/devicemanagerservice/include/authentication/auth_message_processor.h b/services/devicemanagerservice/include/authentication/auth_message_processor.h
new file mode 100644
index 00000000..73226f7a
--- /dev/null
+++ b/services/devicemanagerservice/include/authentication/auth_message_processor.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_AUTH_MESSAGE_PROCESSOR_H
+#define OHOS_DM_AUTH_MESSAGE_PROCESSOR_H
+
+#include
+#include
+
+#include "crypto_adapter.h"
+#include "dm_auth_manager.h"
+#include "nlohmann/json.hpp"
+
+namespace OHOS {
+namespace DistributedHardware {
+class DmAuthManager;
+struct DmAuthRequestContext;
+struct DmAuthResponseContext;
+class ICryptoAdapter;
+class AuthMessageProcessor {
+public:
+ AuthMessageProcessor(std::shared_ptr authMgr);
+ ~AuthMessageProcessor();
+ std::vector CreateAuthRequestMessage();
+ std::string CreateSimpleMessage(int32_t msgType);
+ int32_t ParseMessage(const std::string &message);
+ void SetRequestContext(std::shared_ptr authRequestContext);
+ void SetResponseContext(std::shared_ptr authResponseContext);
+ std::shared_ptr GetResponseContext();
+ std::shared_ptr GetRequestContext();
+
+private:
+ std::string CreateRequestAuthMessage(nlohmann::json &json);
+ void CreateNegotiateMessage(nlohmann::json &json);
+ void CreateSyncGroupMessage(nlohmann::json &json);
+ void CreateResponseAuthMessage(nlohmann::json &json);
+ void ParseAuthResponseMessage(nlohmann::json &json);
+ void ParseAuthRequestMessage();
+ void ParseNegotiateMessage(const nlohmann::json &json);
+ void CreateResponseFinishMessage(nlohmann::json &json);
+ void ParseResponseFinishMessage(nlohmann::json &json);
+
+private:
+ std::weak_ptr authMgr_;
+ std::shared_ptr cryptoAdapter_;
+ std::shared_ptr authRequestContext_;
+ std::shared_ptr authResponseContext_;
+ std::vector authSplitJsonList_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_AUTH_MESSAGE_PROCESSOR_H
diff --git a/services/devicemanagerservice/include/authentication/auth_request_state.h b/services/devicemanagerservice/include/authentication/auth_request_state.h
new file mode 100644
index 00000000..a1a3343e
--- /dev/null
+++ b/services/devicemanagerservice/include/authentication/auth_request_state.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_AUTH_REQUEST_STATE_H
+#define OHOS_DM_AUTH_REQUEST_STATE_H
+#include
+#include
+#include
+
+#include "dm_log.h"
+namespace OHOS {
+namespace DistributedHardware {
+class DmAuthManager;
+struct DmAuthRequestContext;
+class AuthRequestState : public std::enable_shared_from_this {
+public:
+ virtual ~AuthRequestState()
+ {
+ authManager_.reset();
+ LOGE("~AuthRequestState");
+ };
+ virtual int32_t GetStateType() = 0;
+ virtual void Enter() = 0;
+ void Leave();
+ void TransitionTo(std::shared_ptr state);
+ void SetAuthManager(std::shared_ptr authManager);
+ void SetAuthContext(std::shared_ptr context);
+ std::shared_ptr GetAuthContext();
+
+protected:
+ std::weak_ptr authManager_;
+ std::shared_ptr context_;
+};
+
+class AuthRequestInitState : public AuthRequestState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthRequestNegotiateState : public AuthRequestState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+class AuthRequestNegotiateDoneState : public AuthRequestState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthRequestReplyState : public AuthRequestState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthRequestInputState : public AuthRequestState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthRequestJoinState : public AuthRequestState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthRequestNetworkState : public AuthRequestState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthRequestFinishState : public AuthRequestState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_AUTH_REQUEST_STATE_H
diff --git a/services/devicemanagerservice/include/authentication/auth_response_state.h b/services/devicemanagerservice/include/authentication/auth_response_state.h
new file mode 100644
index 00000000..f84e54ba
--- /dev/null
+++ b/services/devicemanagerservice/include/authentication/auth_response_state.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_AUTH_RESPONSE_STATE_H
+#define OHOS_DM_AUTH_RESPONSE_STATE_H
+
+#include
+
+namespace OHOS {
+namespace DistributedHardware {
+
+class DmAuthManager;
+struct DmAuthResponseContext;
+class AuthResponseState : public std::enable_shared_from_this {
+public:
+ virtual ~AuthResponseState()
+ {
+ authManager_.reset();
+ };
+ virtual int32_t GetStateType() = 0;
+ virtual void Enter() = 0;
+ void Leave();
+ void TransitionTo(std::shared_ptr state);
+ void SetAuthManager(std::shared_ptr authManager);
+ void SetAuthContext(std::shared_ptr context);
+ std::shared_ptr GetAuthContext();
+
+protected:
+ std::weak_ptr authManager_;
+ std::shared_ptr context_;
+};
+
+class AuthResponseInitState : public AuthResponseState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthResponseNegotiateState : public AuthResponseState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthResponseConfirmState : public AuthResponseState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthResponseGroupState : public AuthResponseState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthResponseShowState : public AuthResponseState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+
+class AuthResponseFinishState : public AuthResponseState {
+public:
+ int32_t GetStateType() override;
+ void Enter() override;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_AUTH_RESPONSE_STATE_H
diff --git a/services/devicemanagerservice/include/authentication/auth_ui.h b/services/devicemanagerservice/include/authentication/auth_ui.h
new file mode 100644
index 00000000..4ba96cb5
--- /dev/null
+++ b/services/devicemanagerservice/include/authentication/auth_ui.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_AUTH_UI_H
+#define OHOS_DM_AUTH_UI_H
+
+#include
+
+#include "dm_ability_manager.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class AuthUi {
+public:
+ AuthUi();
+ int32_t ShowConfirmDialog(std::shared_ptr dmAbilityManager);
+
+private:
+ int32_t StartFaService();
+
+private:
+ std::shared_ptr dmAbilityMgr_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_AUTH_UI_H
\ No newline at end of file
diff --git a/services/devicemanagerservice/include/authentication/authentication.h b/services/devicemanagerservice/include/authentication/authentication.h
new file mode 100644
index 00000000..5783f111
--- /dev/null
+++ b/services/devicemanagerservice/include/authentication/authentication.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_AUTHENTICATION_H
+#define OHOS_DM_AUTHENTICATION_H
+
+#include "dm_ability_manager.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class IAuthentication {
+public:
+ virtual ~IAuthentication() = default;
+ virtual int32_t ShowAuthInfo() = 0;
+ virtual int32_t StartAuth(std::shared_ptr dmAbilityManager) = 0;
+ virtual int32_t VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) = 0;
+};
+
+using CreateIAuthAdapterFuncPtr = IAuthentication *(*)(void);
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_AUTHENTICATION_H
diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h
new file mode 100644
index 00000000..5bf2d4a0
--- /dev/null
+++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_AUTH_MANAGER_H
+#define OHOS_DM_AUTH_MANAGER_H
+
+#include
+#include
+
+#include "auth_message_processor.h"
+#include "auth_request_state.h"
+#include "auth_response_state.h"
+#include "auth_ui.h"
+#include "authentication.h"
+#include "device_manager_service_listener.h"
+#include "dm_ability_manager.h"
+#include "dm_adapter_manager.h"
+#include "dm_constants.h"
+#include "dm_device_info.h"
+#include "dm_timer.h"
+#include "hichain_connector.h"
+#include "softbus_connector.h"
+#include "softbus_session.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+
+typedef enum AuthState {
+ AUTH_REQUEST_INIT = 1,
+ AUTH_REQUEST_NEGOTIATE,
+ AUTH_REQUEST_NEGOTIATE_DONE,
+ AUTH_REQUEST_REPLY,
+ AUTH_REQUEST_INPUT,
+ AUTH_REQUEST_JOIN,
+ AUTH_REQUEST_NETWORK,
+ AUTH_REQUEST_FINISH,
+ AUTH_RESPONSE_INIT = 20,
+ AUTH_RESPONSE_NEGOTIATE,
+ AUTH_RESPONSE_CONFIRM,
+ AUTH_RESPONSE_GROUP,
+ AUTH_RESPONSE_SHOW,
+ AUTH_RESPONSE_FINISH,
+} AuthState;
+
+enum DmMsgType : int32_t {
+ MSG_TYPE_UNKNOWN = 0,
+ MSG_TYPE_NEGOTIATE = 80,
+ MSG_TYPE_RESP_NEGOTIATE = 90,
+ MSG_TYPE_REQ_AUTH = 100,
+ MSG_TYPE_INVITE_AUTH_INFO = 102,
+ MSG_TYPE_REQ_AUTH_TERMINATE = 104,
+ MSG_TYPE_RESP_AUTH = 200,
+ MSG_TYPE_JOIN_AUTH_INFO = 201,
+ MSG_TYPE_RESP_AUTH_TERMINATE = 205,
+ MSG_TYPE_CHANNEL_CLOSED = 300,
+ MSG_TYPE_SYNC_GROUP = 400,
+ MSG_TYPE_AUTH_BY_PIN = 500,
+};
+
+typedef struct DmAuthRequestContext {
+ int32_t authType;
+ std::string localDeviceId;
+ std::string deviceId;
+ std::string deviceName;
+ std::string deviceTypeId;
+ int32_t sessionId;
+ int32_t groupVisibility;
+ bool cryptoSupport;
+ std::string cryptoName;
+ std::string cryptoVer;
+ std::string hostPkgName;
+ std::string targetPkgName;
+ std::string appName;
+ std::string appDesc;
+ std::string appIcon;
+ std::string appThumbnail;
+ std::string token;
+ int32_t reason;
+ std::vector syncGroupList;
+} DmAuthRequestContext;
+
+typedef struct DmAuthResponseContext {
+ int32_t authType;
+ std::string deviceId;
+ std::string localDeviceId;
+ int32_t msgType;
+ int32_t sessionId;
+ bool cryptoSupport;
+ std::string cryptoName;
+ std::string cryptoVer;
+ int32_t reply;
+ std::string networkId;
+ std::string groupId;
+ std::string groupName;
+ std::string hostPkgName;
+ std::string targetPkgName;
+ std::string appName;
+ std::string appDesc;
+ std::string appIcon;
+ std::string appThumbnail;
+ std::string token;
+ int64_t requestId;
+ int32_t code;
+ std::vector syncGroupList;
+} DmAuthResponseContext;
+
+class AuthMessageProcessor;
+
+class DmAuthManager final : public ISoftbusSessionCallback,
+ public IHiChainConnectorCallback,
+ public std::enable_shared_from_this {
+public:
+ DmAuthManager(std::shared_ptr softbusConnector,
+ std::shared_ptr listener);
+ ~DmAuthManager();
+ int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
+ const std::string &extra);
+ int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId);
+ int32_t VerifyAuthentication(const std::string &authParam);
+ void OnSessionOpened(const std::string &pkgName, int32_t sessionId, int32_t sessionSide, int32_t result);
+ void OnSessionClosed(const std::string &pkgName, int32_t sessionId);
+ void OnDataReceived(const std::string &pkgName, int32_t sessionId, std::string message);
+ void OnGroupCreated(int64_t requestId, const std::string &groupId);
+ void OnMemberJoin(int64_t requestId, int32_t status);
+
+ // auth state machine
+ void EstablishAuthChannel(const std::string &deviceId);
+ void StartNegotiate(const int32_t &sessionId);
+ void RespNegotiate(const int32_t &sessionId);
+ void SendAuthRequest(const int32_t &sessionId);
+ void StartAuthProcess(const int32_t &authType);
+ void StartRespAuthProcess();
+ void CreateGroup();
+ void AddMember(const std::string &deviceId);
+ std::string GetConnectAddr(std::string deviceId);
+ void JoinNetwork();
+ void AuthenticateFinish();
+ void GetIsCryptoSupport(bool &isCryptoSupport);
+ void SetAuthRequestState(std::shared_ptr authRequestState);
+ void SetAuthResponseState(std::shared_ptr authResponseState);
+ int32_t GetPinCode();
+ std::string GenerateGroupName();
+ void HandleAuthenticateTimeout();
+ void CancelDisplay();
+ int32_t GeneratePincode();
+ void ShowConfigDialog();
+ void ShowAuthInfoDialog();
+ void ShowStartAuthDialog();
+ int32_t GetAuthenticationParam(DmAuthParam &authParam);
+ int32_t RegisterSessionCallback();
+ int32_t OnUserOperation(int32_t action);
+
+private:
+ std::shared_ptr softbusConnector_;
+ std::shared_ptr hiChainConnector_;
+ std::shared_ptr listener_;
+ std::shared_ptr adapterMgr_;
+ std::map> authenticationMap_;
+ std::shared_ptr authRequestState_ = nullptr;
+ std::shared_ptr authResponseState_ = nullptr;
+ std::shared_ptr authRequestContext_;
+ std::shared_ptr authResponseContext_;
+ std::shared_ptr authMessageProcessor_;
+ std::map> timerMap_;
+ std::shared_ptr dmAbilityMgr_;
+ bool isCryptoSupport_ = false;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_AUTH_MANAGER_H
diff --git a/services/devicemanagerservice/include/config/config_manager.h b/services/devicemanagerservice/include/config/config_manager.h
new file mode 100644
index 00000000..4a410a1e
--- /dev/null
+++ b/services/devicemanagerservice/include/config/config_manager.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_OHOS_DM_CONFIG_MANAGER_H
+#define OHOS_OHOS_DM_CONFIG_MANAGER_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "authentication.h"
+#include "crypto_adapter.h"
+#include "decision_adapter.h"
+#include "profile_adapter.h"
+#include "single_instance.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+typedef struct {
+ std::string name;
+ std::string type;
+ std::string version;
+ std::string funcName;
+ std::string soName;
+ std::string soPath;
+} AdapterSoLoadInfo;
+
+typedef struct {
+ int32_t authType;
+ std::string name;
+ std::string type;
+ std::string version;
+ std::string funcName;
+ std::string soName;
+ std::string soPath;
+} AuthSoLoadInfo;
+
+class DmConfigManager final {
+ DECLARE_SINGLE_INSTANCE_BASE(DmConfigManager);
+
+public:
+ ~DmConfigManager();
+ void GetAllAuthType(std::vector &allAuthType);
+ std::shared_ptr GetDecisionAdapter(const std::string &soName);
+ std::shared_ptr GetProfileAdapter(const std::string &soName);
+ std::shared_ptr GetCryptoAdapter(const std::string &soName);
+ void GetAuthAdapter(std::map> &authAdapter);
+
+private:
+ DmConfigManager();
+
+private:
+ std::mutex authAdapterMutex_;
+ std::mutex cryptoAdapterMutex_;
+ std::mutex decisionAdapterMutex_;
+ std::mutex profileAdapterMutex_;
+ std::map soAuthLoadInfo_;
+ std::map soAdapterLoadInfo_;
+ std::map> decisionAdapterPtr_;
+ std::map> profileAdapterPtr_;
+ std::map> cryptoAdapterPtr_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_OHOS_DM_CONFIG_MANAGER_H
\ No newline at end of file
diff --git a/services/devicemanagerservice/include/config/json_config.h b/services/devicemanagerservice/include/config/json_config.h
new file mode 100644
index 00000000..a1c495cc
--- /dev/null
+++ b/services/devicemanagerservice/include/config/json_config.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_OHOS_DM_JSON_CONFIG_H
+#define OHOS_OHOS_DM_JSON_CONFIG_H
+
+#include
+
+namespace OHOS {
+namespace DistributedHardware {
+const std::string adapterJsonConfigString =
+ R"({
+ "devicemanager_adapter_components": [
+ {
+ "name": "crypto_adapter",
+ "type": "CPYPTO",
+ "version": "1.0",
+ "funcName": "CreateCryptoAdapterObject",
+ "soName": "libdevicemanager_crypto_adapter.z.so",
+ "soPath": "/system/lib/"
+ },
+ {
+ "name": "device_profile",
+ "type": "PROFILE",
+ "version": "1.0",
+ "funcName": "CreateDeviceProfileObject",
+ "soName": "libdevicemanagerext_profile.z.so",
+ "soPath": "/system/lib/"
+ }
+ ]
+})";
+
+const std::string authJsonConfigString =
+ R"({
+ "devicemanager_auth_components": [
+ {
+ "name": "pin_auth",
+ "type": "AUTHENTICATE",
+ "version": "1.0",
+ "authType": 1,
+ "funcName": "CreatePinAuthObject",
+ "soName": "libdevicemanagerext_pin_auth.z.so",
+ "soPath": "/system/lib/"
+ },
+ {
+ "name": "QRcode_auth",
+ "type": "AUTHENTICATE",
+ "version": "1.0",
+ "authType": 2,
+ "funcName": "CreateQRcodeAuthObject",
+ "soName": "libdevicemanager_qrcodeauth.z.so",
+ "soPath": "/system/lib/"
+ },
+ {
+ "name": "nfc_auth",
+ "type": "AUTHENTICATE",
+ "version": "1.0",
+ "authType": 3,
+ "funcName": "CreateNfcAuthObject",
+ "soName": "libdevicemanager_nfcauth.z.so",
+ "soPath": "/system/lib/"
+ }
+ ]
+})";
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_OHOS_DM_JSON_CONFIG_H
\ No newline at end of file
diff --git a/services/devicemanagerservice/include/dependency/commonevent/event_manager_adapt.h b/services/devicemanagerservice/include/dependency/commonevent/event_manager_adapt.h
new file mode 100644
index 00000000..be733f98
--- /dev/null
+++ b/services/devicemanagerservice/include/dependency/commonevent/event_manager_adapt.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_EVENT_MANAGER_ADAPT_H
+#define OHOS_EVENT_MANAGER_ADAPT_H
+
+#include
+#include
+
+#include "common_event.h"
+#include "common_event_data.h"
+#include "common_event_manager.h"
+#include "common_event_subscribe_info.h"
+#include "common_event_subscriber.h"
+#include "dm_log.h"
+#include "matching_skills.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+
+using CommomEventCallback = void (*)(void);
+
+class DmCommonEventManager {
+public:
+ static DmCommonEventManager &GetInstance();
+
+public:
+ bool SubscribeServiceEvent(const std::string &event, CommomEventCallback callback);
+ bool UnsubscribeServiceEvent(const std::string &event);
+
+ class EventSubscriber : public EventFwk::CommonEventSubscriber {
+ public:
+ explicit EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
+ : EventFwk::CommonEventSubscriber(subscribeInfo)
+ {
+ }
+
+ void OnReceiveEvent(const EventFwk::CommonEventData &data);
+ void addEventCallback(const std::string &event, CommomEventCallback callback);
+ void deleteEventCallback(const std::string &event);
+
+ private:
+ std::mutex callbackLock_;
+ std::map dmEventCallback_;
+ };
+
+private:
+ DmCommonEventManager() = default;
+ virtual ~DmCommonEventManager();
+ DmCommonEventManager(const DmCommonEventManager &) = delete;
+ DmCommonEventManager &operator=(const DmCommonEventManager &) = delete;
+ DmCommonEventManager(DmCommonEventManager &&) = delete;
+ DmCommonEventManager &operator=(DmCommonEventManager &&) = delete;
+
+private:
+ static void DealCallback(void);
+ static void InitCallbackThread(void);
+
+private:
+ static std::once_flag onceFlag_;
+ static std::list callbackQueue_;
+ static std::mutex callbackQueueMutex_;
+ static std::condition_variable notEmpty_;
+ std::map> dmEventSubscriber_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+
+#endif // OHOS_EVENT_MANAGER_ADAPT_H
\ No newline at end of file
diff --git a/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h b/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h
new file mode 100644
index 00000000..895441bf
--- /dev/null
+++ b/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_HICHAIN_CONNECTOR_H
+#define OHOS_HICHAIN_CONNECTOR_H
+
+#include
+#include
+#include
+#include
+#include
+
+#include "device_auth.h"
+#include "hichain_connector_callback.h"
+#include "nlohmann/json.hpp"
+#include "single_instance.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+struct GroupInfo {
+ std::string groupName;
+ std::string groupId;
+ std::string groupOwner;
+ int32_t groupType;
+ int32_t groupVisibility;
+
+ GroupInfo() : groupName(""), groupId(""), groupOwner(""), groupType(0), groupVisibility(0)
+ {
+ }
+};
+
+void from_json(const nlohmann::json &jsonObject, GroupInfo &groupInfo);
+
+class HiChainConnector {
+public:
+ static bool onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen);
+ static void onFinish(int64_t requestId, int32_t operationCode, const char *returnData);
+ static void onError(int64_t requestId, int32_t operationCode, int32_t errorCode, const char *errorReturn);
+ static char *onRequest(int64_t requestId, int32_t operationCode, const char *reqParams);
+
+public:
+ HiChainConnector();
+ ~HiChainConnector();
+ int32_t RegisterHiChainCallback(const std::string &pkgName, std::shared_ptr callback);
+ int32_t UnRegisterHiChainCallback(const std::string &pkgName);
+ int32_t CreateGroup(int64_t requestId, const std::string &groupName);
+ int32_t AddMember(std::string deviceId, std::string &connectInfo);
+ int32_t DelMemberFromGroup(std::string groupId, std::string deviceId);
+ void DeleteGroup(std::string &groupId);
+ bool IsDevicesInGroup(std::string hostDevice, std::string peerDevice);
+ void GetRelatedGroups(std::string DeviceId, std::vector &groupList);
+
+private:
+ int64_t GenRequestId();
+ void SyncGroups(std::string deviceId, std::vector &remoteGroupIdList);
+ void GetSyncGroupList(std::vector &groupList, std::vector &syncGroupList);
+ int32_t GetGroupInfo(std::string queryParams, std::vector &groupList);
+ std::string GetConnectPara(std::string deviceId, std::string reqDeviceId);
+ bool IsGroupCreated(std::string groupName, GroupInfo &groupInfo);
+ bool IsGroupInfoInvalid(GroupInfo &group);
+
+private:
+ const DeviceGroupManager *deviceGroupManager_ = nullptr;
+ DeviceAuthCallback deviceAuthCallback_;
+ static std::map> hiChainConnectorCallbackMap_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_HICHAIN_CONNECTOR_H
diff --git a/services/devicemanagerservice/include/dependency/hichain/hichain_connector_callback.h b/services/devicemanagerservice/include/dependency/hichain/hichain_connector_callback.h
new file mode 100644
index 00000000..f6504949
--- /dev/null
+++ b/services/devicemanagerservice/include/dependency/hichain/hichain_connector_callback.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_HICHAIN_CONNECTOR_CALLBACK_H
+#define OHOS_DM_HICHAIN_CONNECTOR_CALLBACK_H
+
+namespace OHOS {
+namespace DistributedHardware {
+class IHiChainConnectorCallback {
+public:
+ virtual void OnGroupCreated(int64_t requestId, const std::string &groupId) = 0;
+ virtual void OnMemberJoin(int64_t requestId, int32_t status) = 0;
+ virtual std::string GetConnectAddr(std::string deviceId) = 0;
+ virtual int32_t GetPinCode() = 0;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_HICHAIN_CONNECTOR_CALLBACK_H
diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h b/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h
new file mode 100644
index 00000000..1e08a470
--- /dev/null
+++ b/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_SOFTBUS_CONNECTOR_H
+#define OHOS_DM_SOFTBUS_CONNECTOR_H
+
+#include
+#include
+#include
+#include
+#include
+
+#include "discovery_service.h"
+#include "dm_device_info.h"
+#include "dm_subscribe_info.h"
+#include "softbus_bus_center.h"
+#include "softbus_discovery_callback.h"
+#include "softbus_session.h"
+#include "softbus_state_callback.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class SoftbusConnector {
+public:
+ static void OnPublishSuccess(int32_t publishId);
+ static void OnPublishFail(int32_t publishId, PublishFailReason reason);
+ static void OnSoftBusDeviceOnline(NodeBasicInfo *info);
+ static void OnSoftbusDeviceOffline(NodeBasicInfo *info);
+ static void OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info);
+ static void OnSoftbusDeviceFound(const DeviceInfo *device);
+ static void OnSoftbusDiscoveryFailed(int32_t subscribeId, DiscoveryFailReason failReason);
+ static void OnSoftbusDiscoverySuccess(int32_t subscribeId);
+ static void OnParameterChgCallback(const char *key, const char *value, void *context);
+ static int32_t GetConnectionIpAddress(const std::string &deviceId, std::string &ipAddress);
+ static ConnectionAddr *GetConnectAddr(const std::string &deviceId, std::string &connectAddr);
+ static bool IsDeviceOnLine(const std::string &deviceId);
+ static int32_t GetUdidByNetworkId(const char *networkId, std::string &udid);
+ static int32_t GetUuidByNetworkId(const char *networkId, std::string &uuid);
+ static int32_t GetNodeKeyInfoByNetworkId(const char *networkId, NodeDeivceInfoKey key, uint8_t *info,
+ int32_t infoLen);
+
+public:
+ SoftbusConnector();
+ ~SoftbusConnector();
+ int32_t RegisterSoftbusStateCallback(const std::string &pkgName,
+ const std::shared_ptr callback);
+ int32_t UnRegisterSoftbusStateCallback(const std::string &pkgName);
+ int32_t RegisterSoftbusDiscoveryCallback(const std::string &pkgName,
+ const std::shared_ptr callback);
+ int32_t UnRegisterSoftbusDiscoveryCallback(const std::string &pkgName);
+ int32_t GetTrustedDeviceList(std::vector &deviceInfoList);
+ int32_t GetLocalDeviceInfo(DmDeviceInfo &deviceInfo);
+ int32_t StartDiscovery(const DmSubscribeInfo &subscribeInfo);
+ int32_t StopDiscovery(uint16_t subscribeId);
+ std::shared_ptr GetSoftbusSession();
+ bool HaveDeviceInMap(std::string deviceId);
+
+private:
+ int32_t Init();
+ static void CovertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeBasicInfo, DmDeviceInfo &dmDeviceInfo);
+ static void CovertDeviceInfoToDmDevice(const DeviceInfo &deviceInfo, DmDeviceInfo &dmDeviceInfo);
+ static ConnectionAddr *GetConnectAddrByType(DeviceInfo *deviceInfo, ConnectionAddrType type);
+
+private:
+ enum PulishStatus {
+ STATUS_UNKNOWN = 0,
+ ALLOW_BE_DISCOVERY = 1,
+ NOT_ALLOW_BE_DISCOVERY = 2,
+ };
+ static PulishStatus publishStatus;
+ static INodeStateCb softbusNodeStateCb_;
+ static IDiscoveryCallback softbusDiscoveryCallback_;
+ static IPublishCallback softbusPublishCallback_;
+ std::shared_ptr softbusSession_;
+ static std::map> discoveryDeviceInfoMap_;
+ static std::map> stateCallbackMap_;
+ static std::map> discoveryCallbackMap_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_SOFTBUS_CONNECTOR_H
diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_discovery_callback.h b/services/devicemanagerservice/include/dependency/softbus/softbus_discovery_callback.h
new file mode 100644
index 00000000..c8b1f57c
--- /dev/null
+++ b/services/devicemanagerservice/include/dependency/softbus/softbus_discovery_callback.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_SOFTBUS_DISCOVERY_CALLBACK_H
+#define OHOS_DM_SOFTBUS_DISCOVERY_CALLBACK_H
+
+namespace OHOS {
+namespace DistributedHardware {
+class ISoftbusDiscoveryCallback {
+public:
+ virtual void OnDeviceFound(const std::string &pkgName, const DmDeviceInfo &info) = 0;
+ virtual void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId) = 0;
+ virtual void OnDiscoveryFailed(const std::string &pkgName, int32_t subscribeId, int32_t failedReason) = 0;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_SOFTBUS_DISCOVERY_CALLBACK_H
diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_session.h b/services/devicemanagerservice/include/dependency/softbus/softbus_session.h
new file mode 100644
index 00000000..084df481
--- /dev/null
+++ b/services/devicemanagerservice/include/dependency/softbus/softbus_session.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_SOFTBUS_SESSION_H
+#define OHOS_DM_SOFTBUS_SESSION_H
+
+#include
+#include
+#include
+#include
+#include
+
+#include "inner_session.h"
+#include "session.h"
+#include "softbus_session_callback.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class SoftbusSession {
+public:
+ static int32_t OnSessionOpened(int32_t sessionId, int32_t result);
+ static void OnSessionClosed(int32_t sessionId);
+ static void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen);
+
+public:
+ SoftbusSession();
+ ~SoftbusSession();
+ int32_t RegisterSessionCallback(const std::string &pkgName, std::shared_ptr callback);
+ int32_t UnRegisterSessionCallback(const std::string &pkgName);
+ int32_t OpenAuthSession(const std::string &deviceId);
+ void CloseAuthSession(int32_t sessionId);
+ int32_t SendData(int32_t sessionId, std::string &message);
+ void GetPeerDeviceId(int32_t sessionId, std::string &peerDevId);
+
+private:
+ static std::map> sessionCallbackMap_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_SOFTBUS_SESSION_H
diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_session_callback.h b/services/devicemanagerservice/include/dependency/softbus/softbus_session_callback.h
new file mode 100644
index 00000000..9569a331
--- /dev/null
+++ b/services/devicemanagerservice/include/dependency/softbus/softbus_session_callback.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_SOFTBUS_SESSION_CALLBACK_H
+#define OHOS_DM_SOFTBUS_SESSION_CALLBACK_H
+
+namespace OHOS {
+namespace DistributedHardware {
+class ISoftbusSessionCallback {
+public:
+ virtual void OnSessionOpened(const std::string &pkgName, int32_t sessionId, int32_t sessionSide,
+ int32_t result) = 0;
+ virtual void OnSessionClosed(const std::string &pkgName, int32_t sessionId) = 0;
+ virtual void OnDataReceived(const std::string &pkgName, int32_t sessionId, std::string message) = 0;
+ virtual void GetIsCryptoSupport(bool &isCryptoSupport) = 0;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_SOFTBUS_SESSION_CALLBACK_H
diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_state_callback.h b/services/devicemanagerservice/include/dependency/softbus/softbus_state_callback.h
new file mode 100644
index 00000000..15a08a2e
--- /dev/null
+++ b/services/devicemanagerservice/include/dependency/softbus/softbus_state_callback.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_SOFTBUS_STATE_CALLBACK_H
+#define OHOS_DM_SOFTBUS_STATE_CALLBACK_H
+
+namespace OHOS {
+namespace DistributedHardware {
+class ISoftbusStateCallback {
+public:
+ virtual void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) = 0;
+ virtual void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &info) = 0;
+ virtual void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &info) = 0;
+ virtual void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &info) = 0;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_SOFTBUS_STATE_CALLBACK_H
diff --git a/services/devicemanagerservice/include/dependency/timer/dm_timer.h b/services/devicemanagerservice/include/dependency/timer/dm_timer.h
new file mode 100644
index 00000000..66a0adbf
--- /dev/null
+++ b/services/devicemanagerservice/include/dependency/timer/dm_timer.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIMER_H
+#define TIMER_H
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+#include "dm_log.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+
+typedef void (*TimeoutHandle)(void *data);
+
+#define MAXEVENTS 255
+
+enum DmTimerStatus : int32_t {
+ DM_STATUS_INIT = 0,
+ DM_STATUS_RUNNING = 1,
+ DM_STATUS_BUSY = 2,
+ DM_STATUS_CREATE_ERROR = 3,
+ DM_STATUS_FINISH = 6,
+};
+
+class DmTimer {
+public:
+ DmTimer(std::string &name);
+ ~DmTimer();
+ DmTimerStatus Start(uint32_t timeOut, TimeoutHandle handle, void *data);
+ void Stop(int32_t code);
+ void WaitForTimeout();
+
+private:
+ int32_t CreateTimeFd();
+ void Release();
+
+private:
+ DmTimerStatus mStatus_;
+ uint32_t mTimeOutSec_;
+ TimeoutHandle mHandle_;
+ void *mHandleData_;
+ int32_t mTimeFd_[2];
+ struct epoll_event mEv_;
+ struct epoll_event mEvents_[MAXEVENTS];
+ int32_t mEpFd_;
+ std::thread mThread_;
+ std::string mTimerName_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif
diff --git a/services/devicemanagerservice/include/device_manager_service.h b/services/devicemanagerservice/include/device_manager_service.h
new file mode 100644
index 00000000..53e33b1d
--- /dev/null
+++ b/services/devicemanagerservice/include/device_manager_service.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_SERVICE_H
+#define OHOS_DM_SERVICE_H
+
+#include
+#include
+
+#include "dm_ability_manager.h"
+#include "dm_auth_manager.h"
+#include "dm_device_info.h"
+#include "dm_device_info_manager.h"
+#include "dm_device_state_manager.h"
+#include "dm_discovery_manager.h"
+#include "single_instance.h"
+#include "softbus_connector.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class DeviceManagerService {
+ DECLARE_SINGLE_INSTANCE(DeviceManagerService);
+
+public:
+ int32_t Init();
+ int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
+ std::vector &deviceList);
+ int32_t GetLocalDeviceInfo(DmDeviceInfo &info);
+ int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid);
+ int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &uuid);
+ int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
+ const std::string &extra);
+ int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId);
+ int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
+ const std::string &extra);
+ int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId);
+ int32_t VerifyAuthentication(const std::string &authParam);
+ int32_t GetFaParam(std::string &pkgName, DmAuthParam &authParam);
+ int32_t SetUserOperation(std::string &pkgName, int32_t action);
+
+private:
+ bool intFlag_ = false;
+ std::shared_ptr authMgr_;
+ std::shared_ptr deviceInfoMgr_;
+ std::shared_ptr deviceStateMgr_;
+ std::shared_ptr discoveryMgr_;
+ std::shared_ptr softbusConnector_;
+ std::shared_ptr listener_;
+ std::shared_ptr abilityMgr_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_SERVICE_H
diff --git a/services/devicemanagerservice/include/device_manager_service_listener.h b/services/devicemanagerservice/include/device_manager_service_listener.h
new file mode 100644
index 00000000..4ad17f9f
--- /dev/null
+++ b/services/devicemanagerservice/include/device_manager_service_listener.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_SERVICE_LISTENER_H
+#define OHOS_DM_SERVICE_LISTENER_H
+
+#include
+#include
+
+#include "dm_device_info.h"
+#include "ipc_notify_dmfa_result_req.h"
+#include "ipc_server_listener.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class DeviceManagerServiceListener {
+public:
+ void OnDeviceStateChange(const std::string &pkgName, const DmDeviceState &state, const DmDeviceInfo &info);
+ void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &info);
+ void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason);
+ void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId);
+ void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, int32_t status,
+ const std::string &reason);
+ void OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode,
+ const std::string &flag);
+ void OnFaCall(std::string &pkgName, std::string ¶mJson);
+
+private:
+ IpcServerListener ipcServerListener_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+
+#endif // OHOS_DM_SERVICE_LISTENER_H
diff --git a/services/devicemanagerservice/include/deviceinfo/dm_device_info_manager.h b/services/devicemanagerservice/include/deviceinfo/dm_device_info_manager.h
new file mode 100644
index 00000000..9dfe5b15
--- /dev/null
+++ b/services/devicemanagerservice/include/deviceinfo/dm_device_info_manager.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_DEVICEINFO_MANAGER_H
+#define OHOS_DM_DEVICEINFO_MANAGER_H
+
+#include
+#include
+
+#include "dm_adapter_manager.h"
+#include "dm_device_info.h"
+#include "softbus_connector.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class DmDeviceInfoManager {
+public:
+ DmDeviceInfoManager(std::shared_ptr &softbusConnectorPtr);
+ int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
+ std::vector &deviceList);
+ int32_t GetLocalDeviceInfo(DmDeviceInfo &info);
+
+private:
+ std::shared_ptr softbusConnector_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+
+#endif // OHOS_DM_DEVICEINFO_MANAGER_H
diff --git a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h
new file mode 100644
index 00000000..a54ef47e
--- /dev/null
+++ b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_DEVICE_STATE_MANAGER_H
+#define OHOS_DM_DEVICE_STATE_MANAGER_H
+
+#include "device_manager_service_listener.h"
+#include "dm_adapter_manager.h"
+#include "softbus_connector.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class DmDeviceStateManager final : public ISoftbusStateCallback,
+ public std::enable_shared_from_this {
+public:
+ DmDeviceStateManager(std::shared_ptr softbusConnector,
+ std::shared_ptr listener);
+ ~DmDeviceStateManager();
+ void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info);
+ void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &info);
+ void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &info);
+ void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &info);
+ void OnProfileReady(const std::string &pkgName, const std::string deviceId);
+ int32_t RegisterSoftbusStateCallback();
+
+private:
+ std::shared_ptr softbusConnector_;
+ std::shared_ptr adapterMgr_;
+ std::shared_ptr listener_;
+ std::map deviceStateMap_;
+ std::map remoteDeviceInfos_;
+ std::string profileSoName_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_DEVICE_STATE_MANAGER_H
diff --git a/services/devicemanagerservice/include/discovery/dm_discovery_manager.h b/services/devicemanagerservice/include/discovery/dm_discovery_manager.h
new file mode 100644
index 00000000..20c30ec8
--- /dev/null
+++ b/services/devicemanagerservice/include/discovery/dm_discovery_manager.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_DISCOVERY_MANAGER_H
+#define OHOS_DM_DISCOVERY_MANAGER_H
+
+#include
+
+#include "device_manager_service_listener.h"
+#include "dm_timer.h"
+#include "softbus_connector.h"
+namespace OHOS {
+namespace DistributedHardware {
+
+typedef struct DmDiscoveryContext {
+ std::string pkgName;
+ std::string extra;
+ uint16_t subscribeId;
+} DmDiscoveryContext;
+
+class DmDiscoveryManager final : public ISoftbusDiscoveryCallback,
+ public std::enable_shared_from_this {
+public:
+ DmDiscoveryManager(std::shared_ptr softbusConnector,
+ std::shared_ptr listener);
+ ~DmDiscoveryManager();
+ int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
+ const std::string &extra);
+ int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId);
+ void OnDeviceFound(const std::string &pkgName, const DmDeviceInfo &info);
+ void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId);
+ void OnDiscoveryFailed(const std::string &pkgName, int32_t subscribeId, int32_t failedReason);
+ void HandleDiscoveryTimeout();
+
+private:
+ std::shared_ptr softbusConnector_;
+ std::shared_ptr listener_;
+ std::queue discoveryQueue_;
+ std::map discoveryContextMap_;
+ std::shared_ptr discoveryTimer_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_DISCOVERY_MANAGER_H
diff --git a/services/devicemanagerservice/include/ipc/lite/ipc_server_listener.h b/services/devicemanagerservice/include/ipc/lite/ipc_server_listener.h
new file mode 100644
index 00000000..4cf1b62c
--- /dev/null
+++ b/services/devicemanagerservice/include/ipc/lite/ipc_server_listener.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_IPC_SERVER_LISTENER_H
+#define OHOS_DM_IPC_SERVER_LISTENER_H
+
+#include
+
+#include "ipc_req.h"
+#include "ipc_rsp.h"
+#include "ipc_server_listenermgr.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class IpcServerListener {
+public:
+ IpcServerListener() = default;
+ virtual ~IpcServerListener() = default;
+
+public:
+ int32_t SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp);
+ int32_t SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp);
+
+private:
+ void CommonSvcToIdentity(CommonSvcId *svcId, SvcIdentity *identity);
+ int32_t GetIdentityByPkgName(std::string &name, SvcIdentity *svc);
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_IPC_SERVER_LISTENER_H
diff --git a/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h b/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h
new file mode 100644
index 00000000..2d0ed61c
--- /dev/null
+++ b/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_IPC_SERVER_LISTENER_MGR_H
+#define OHOS_DM_IPC_SERVER_LISTENER_MGR_H
+
+#include
+#include
+#include
+#include
+
+#include "liteipc_adapter.h"
+#include "single_instance.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+typedef struct CommonSvcId {
+ uint32_t handle;
+ uint32_t token;
+ uint32_t cookie;
+ IpcContext *ipcCtx;
+ uint32_t cbId;
+} CommonSvcId;
+
+class IpcServerListenermgr {
+ DECLARE_SINGLE_INSTANCE(IpcServerListenermgr);
+
+public:
+ int32_t RegisterListener(std::string &pkgName, const CommonSvcId *svcId);
+ int32_t GetListenerByPkgName(std::string &pkgName, CommonSvcId *svcId);
+ int32_t UnregisterListener(std::string &pkgName);
+ const std::map &GetAllListeners();
+
+private:
+ std::map dmListenerMap_;
+ std::mutex lock_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_IPC_SERVER_LISTENER_MGR_H
diff --git a/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h b/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h
new file mode 100644
index 00000000..fc22d947
--- /dev/null
+++ b/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_IPC_SERVER_STUB_H
+#define OHOS_DM_IPC_SERVER_STUB_H
+
+#include
+
+#include "liteipc_adapter.h"
+
+int32_t IpcServerStubInit(void);
+int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply);
+int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply);
+#endif // OHOS_DM_IPC_SERVER_STUB_H
diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h
new file mode 100644
index 00000000..f1fbd240
--- /dev/null
+++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_IPC_SERVER_CLIENT_PROXY_H
+#define OHOS_DM_IPC_SERVER_CLIENT_PROXY_H
+
+#include "ipc_remote_broker.h"
+#include "iremote_proxy.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class IpcServerClientProxy : public IRemoteProxy {
+public:
+ explicit IpcServerClientProxy(const sptr &impl) : IRemoteProxy(impl){};
+ ~IpcServerClientProxy(){};
+ int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override;
+
+private:
+ static inline BrokerDelegator delegator_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_IPC_SERVER_CLIENT_PROXY_H
diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h
new file mode 100644
index 00000000..1ee6680b
--- /dev/null
+++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_IPC_SERVER_LISTENER_H
+#define OHOS_DM_IPC_SERVER_LISTENER_H
+
+#include
+
+#include "ipc_req.h"
+#include "ipc_rsp.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class IpcServerListener {
+public:
+ IpcServerListener() = default;
+ virtual ~IpcServerListener() = default;
+
+public:
+ int32_t SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp);
+ int32_t SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp);
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_IPC_SERVER_LISTENER_H
diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h
new file mode 100644
index 00000000..93d0f787
--- /dev/null
+++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_IPC_SERVER_STUB_H
+#define OHOS_DM_IPC_SERVER_STUB_H
+
+#include
+#include
+#include
+#include
+#include
+
+#include "hichain_connector.h"
+#include "ipc_remote_broker.h"
+#include "iremote_stub.h"
+#include "nlohmann/json.hpp"
+#include "single_instance.h"
+#include "system_ability.h"
+#include "thread_pool.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
+
+class AppDeathRecipient : public IRemoteObject::DeathRecipient {
+public:
+ void OnRemoteDied(const wptr &remote) override;
+ AppDeathRecipient() = default;
+ ~AppDeathRecipient() = default;
+};
+
+class IpcServerStub : public SystemAbility, public IRemoteStub {
+ DECLARE_SYSTEM_ABILITY(IpcServerStub);
+ DECLARE_SINGLE_INSTANCE_BASE(IpcServerStub);
+
+public:
+ void OnStart() override;
+ void OnStop() override;
+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
+ int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override;
+ int32_t RegisterDeviceManagerListener(std::string &pkgName, sptr listener);
+ int32_t UnRegisterDeviceManagerListener(std::string &pkgName);
+ ServiceRunningState QueryServiceState() const;
+ const std::map> &GetDmListener();
+ const sptr GetDmListener(std::string pkgName) const;
+
+private:
+ IpcServerStub();
+ ~IpcServerStub() = default;
+ bool Init();
+
+private:
+ bool registerToService_;
+ ServiceRunningState state_;
+ std::mutex listenerLock_;
+ std::map> appRecipient_;
+ std::map> dmListener_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_IPC_SERVER_STUB_H
diff --git a/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp b/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp
new file mode 100644
index 00000000..e81442c7
--- /dev/null
+++ b/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dm_ability_manager.h"
+
+#include "dm_constants.h"
+#include "semaphore.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+AbilityRole DmAbilityManager::GetAbilityRole()
+{
+ return mAbilityStatus_;
+}
+
+AbilityStatus DmAbilityManager::StartAbility(AbilityRole role)
+{
+ // not support for L1 yet, do nothing. jsut save status and role
+ mAbilityStatus_ = role;
+ mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS;
+ return mStatus_;
+}
+
+void DmAbilityManager::waitForTimeout(uint32_t timeout_s)
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec += timeout_s;
+ sem_timedwait(&mSem_, &ts);
+}
+
+void DmAbilityManager::StartAbilityDone()
+{
+ mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS;
+ sem_post(&mSem_);
+}
+} // namespace DistributedHardware
+} // namespace OHOS
diff --git a/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp b/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp
new file mode 100644
index 00000000..ce077df9
--- /dev/null
+++ b/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dm_ability_manager.h"
+
+#include "ability_manager_client.h"
+#include "ability_manager_service.h"
+#include "ability_record.h"
+#include "dm_constants.h"
+#include "dm_log.h"
+#include "parameter.h"
+#include "semaphore.h"
+#include "single_instance.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+namespace {
+const int32_t ABILITY_START_TIMEOUT = 3; // 3 second
+const std::string bundleName = "com.ohos.devicemanagerui";
+const std::string abilityName = "com.ohos.devicemanagerui.MainAbility";
+} // namespace
+
+AbilityRole DmAbilityManager::GetAbilityRole()
+{
+ return mAbilityStatus_;
+}
+
+AbilityStatus DmAbilityManager::StartAbility(AbilityRole role)
+{
+ mAbilityStatus_ = role;
+ char localDeviceId[DEVICE_UUID_LENGTH] = {0};
+ GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
+ std::string deviceId = localDeviceId;
+ mStatus_ = AbilityStatus::ABILITY_STATUS_START;
+ AAFwk::Want want;
+ AppExecFwk::ElementName element(deviceId, bundleName, abilityName);
+ want.SetElement(element);
+ AAFwk::AbilityManagerClient::GetInstance()->Connect();
+ ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want);
+ if (result != OHOS::ERR_OK) {
+ LOGE("Start Ability faild");
+ mStatus_ = AbilityStatus::ABILITY_STATUS_FAILED;
+ return mStatus_;
+ }
+ waitForTimeout(ABILITY_START_TIMEOUT);
+ return mStatus_;
+}
+
+void DmAbilityManager::waitForTimeout(uint32_t timeout_s)
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec += timeout_s;
+ sem_timedwait(&mSem_, &ts);
+}
+
+void DmAbilityManager::StartAbilityDone()
+{
+ mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS;
+ sem_post(&mSem_);
+}
+} // namespace DistributedHardware
+} // namespace OHOS
diff --git a/services/devicemanagerservice/src/adapter/lite/dm_adapter_manager.cpp b/services/devicemanagerservice/src/adapter/lite/dm_adapter_manager.cpp
new file mode 100644
index 00000000..21900277
--- /dev/null
+++ b/services/devicemanagerservice/src/adapter/lite/dm_adapter_manager.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dm_adapter_manager.h"
+
+#include "dm_constants.h"
+#include "dm_log.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+
+DmAdapterManager &DmAdapterManager::GetInstance()
+{
+ static DmAdapterManager instance;
+ return instance;
+}
+
+DmAdapterManager::DmAdapterManager()
+{
+ LOGI("DmAdapterManager constructor");
+}
+
+DmAdapterManager::~DmAdapterManager()
+{
+ LOGI("DmAdapterManager destructor");
+}
+
+std::shared_ptr DmAdapterManager::GetDecisionAdapter()
+{
+ return decisionAdapterPtr_;
+}
+
+std::shared_ptr DmAdapterManager::GetProfileAdapter()
+{
+ return profileAdapterPtr_;
+}
+
+std::shared_ptr DmAdapterManager::GetCryptoAdapter()
+{
+ return cryptoAdapterPtr_;
+}
+
+} // namespace DistributedHardware
+} // namespace OHOS
diff --git a/services/devicemanagerservice/src/adapter/standard/dm_adapter_manager.cpp b/services/devicemanagerservice/src/adapter/standard/dm_adapter_manager.cpp
new file mode 100644
index 00000000..693656d5
--- /dev/null
+++ b/services/devicemanagerservice/src/adapter/standard/dm_adapter_manager.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dm_adapter_manager.h"
+
+#include
+
+#include "config_manager.h"
+#include "dm_constants.h"
+#include "dm_log.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+DmAdapterManager &DmAdapterManager::GetInstance()
+{
+ static DmAdapterManager instance;
+ return instance;
+}
+
+std::shared_ptr DmAdapterManager::GetDecisionAdapter(const std::string &soName)
+{
+ DmConfigManager &dmConfigManager = DmConfigManager::GetInstance();
+ return dmConfigManager.GetDecisionAdapter(soName);
+}
+
+std::shared_ptr DmAdapterManager::GetProfileAdapter(const std::string &soName)
+{
+ DmConfigManager &dmConfigManager = DmConfigManager::GetInstance();
+ return dmConfigManager.GetProfileAdapter(soName);
+}
+
+std::shared_ptr DmAdapterManager::GetCryptoAdapter(const std::string &soName)
+{
+ DmConfigManager &dmConfigManager = DmConfigManager::GetInstance();
+ return dmConfigManager.GetCryptoAdapter(soName);
+}
+} // namespace DistributedHardware
+} // namespace OHOS
diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp
new file mode 100644
index 00000000..1b547a60
--- /dev/null
+++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp
@@ -0,0 +1,291 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "auth_message_processor.h"
+
+#include "dm_auth_manager.h"
+#include "dm_constants.h"
+#include "dm_log.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+
+AuthMessageProcessor::AuthMessageProcessor(std::shared_ptr authMgr) : authMgr_(authMgr)
+{
+ LOGI("AuthMessageProcessor constructor");
+}
+
+AuthMessageProcessor::~AuthMessageProcessor()
+{
+ authMgr_.reset();
+}
+
+std::vector AuthMessageProcessor::CreateAuthRequestMessage()
+{
+ LOGI("AuthMessageProcessor::CreateAuthRequestMessage start.");
+ std::vector jsonStrVec;
+ int32_t thumbnailSize = authRequestContext_->appThumbnail.size();
+ int32_t thumbnailSlice = ((thumbnailSize / MSG_MAX_SIZE) + (thumbnailSize % MSG_MAX_SIZE) == 0 ? 0 : 1);
+ nlohmann::json jsonObj;
+ jsonObj[TAG_VER] = DM_ITF_VER;
+ jsonObj[TAG_TYPE] = MSG_TYPE_REQ_AUTH;
+ jsonObj[TAG_SLICE_NUM] = thumbnailSlice + 1;
+ jsonObj[TAG_INDEX] = 0;
+ jsonObj[TAG_REQUESTER] = authRequestContext_->deviceName;
+ jsonObj[TAG_DEVICE_ID] = authRequestContext_->deviceId;
+ jsonObj[TAG_DEVICE_TYPE] = authRequestContext_->deviceTypeId;
+ jsonObj[TAG_AUTH_TYPE] = authRequestContext_->authType;
+ jsonObj[TAG_TOKEN] = authRequestContext_->token;
+ jsonObj[TAG_VISIBILITY] = authRequestContext_->groupVisibility;
+ if (authRequestContext_->groupVisibility == GROUP_VISIBILITY_IS_PRIVATE) {
+ jsonObj[TAG_TARGET] = authRequestContext_->targetPkgName;
+ jsonObj[TAG_HOST] = authRequestContext_->hostPkgName;
+ }
+ jsonObj[TAG_APP_NAME] = authRequestContext_->appName;
+ jsonObj[TAG_APP_DESCRIPTION] = authRequestContext_->appDesc;
+ jsonObj[TAG_APP_ICON] = authRequestContext_->appIcon;
+ jsonObj[TAG_THUMBNAIL_SIZE] = thumbnailSize;
+ jsonStrVec.push_back(jsonObj.dump());
+
+ for (int32_t idx = 0; idx < thumbnailSlice; idx++) {
+ nlohmann::json jsonThumbnailObj;
+ jsonThumbnailObj[TAG_VER] = DM_ITF_VER;
+ jsonThumbnailObj[TAG_TYPE] = MSG_TYPE_REQ_AUTH;
+ jsonThumbnailObj[TAG_SLICE_NUM] = thumbnailSlice + 1;
+ jsonThumbnailObj[TAG_INDEX] = idx + 1;
+ jsonThumbnailObj[TAG_DEVICE_ID] = authRequestContext_->deviceId;
+ jsonThumbnailObj[TAG_THUMBNAIL_SIZE] = thumbnailSize;
+
+ int32_t leftLen = thumbnailSize - idx * MSG_MAX_SIZE;
+ int32_t sliceLen = (leftLen > MSG_MAX_SIZE) ? MSG_MAX_SIZE : leftLen;
+ LOGD("TAG_APP_THUMBNAIL encode, idx %d, sliceLen %d, thumbnailSize %d", idx, sliceLen, thumbnailSize);
+ jsonObj[TAG_APP_THUMBNAIL] = authRequestContext_->appThumbnail.substr(idx * MSG_MAX_SIZE, sliceLen);
+ jsonStrVec.push_back(jsonThumbnailObj.dump());
+ }
+ return jsonStrVec;
+}
+
+std::string AuthMessageProcessor::CreateSimpleMessage(int32_t msgType)
+{
+ LOGI("AuthMessageProcessor::CreateSimpleMessage start. msgType is %d", msgType);
+ nlohmann::json jsonObj;
+ jsonObj[TAG_VER] = DM_ITF_VER;
+ jsonObj[TAG_TYPE] = msgType;
+ switch (msgType) {
+ case MSG_TYPE_NEGOTIATE:
+ case MSG_TYPE_RESP_NEGOTIATE:
+ CreateNegotiateMessage(jsonObj);
+ break;
+ case MSG_TYPE_SYNC_GROUP:
+ CreateSyncGroupMessage(jsonObj);
+ break;
+ case MSG_TYPE_RESP_AUTH:
+ CreateResponseAuthMessage(jsonObj);
+ break;
+ case MSG_TYPE_REQ_AUTH_TERMINATE:
+ CreateResponseFinishMessage(jsonObj);
+ break;
+ default:
+ break;
+ }
+ return jsonObj.dump();
+}
+
+void AuthMessageProcessor::CreateNegotiateMessage(nlohmann::json &json)
+{
+ if (cryptoAdapter_ == nullptr) {
+ json[TAG_CRYPTO_SUPPORT] = false;
+ } else {
+ json[TAG_CRYPTO_SUPPORT] = true;
+ json[TAG_CRYPTO_NAME] = cryptoAdapter_->GetName();
+ json[TAG_CRYPTO_VERSION] = cryptoAdapter_->GetVersion();
+ json[TAG_DEVICE_ID] = authRequestContext_->deviceId;
+ }
+ json[TAG_REPLY] = authResponseContext_->reply;
+ json[TAG_LOCAL_DEVICE_ID] = authResponseContext_->localDeviceId;
+}
+
+void AuthMessageProcessor::CreateSyncGroupMessage(nlohmann::json &json)
+{
+ json[TAG_DEVICE_ID] = authRequestContext_->deviceId;
+ json[TAG_GROUPIDS] = authRequestContext_->syncGroupList;
+}
+
+void AuthMessageProcessor::CreateResponseAuthMessage(nlohmann::json &json)
+{
+ json[TAG_REPLY] = authResponseContext_->reply;
+ json[TAG_DEVICE_ID] = authResponseContext_->deviceId;
+ json[TAG_TOKEN] = authResponseContext_->token;
+ // json[TAG_GROUPIDS] = authResponseContext_->deviceId; //?
+ LOGI("AuthMessageProcessor::ParseAuthResponseMessage %d,%d", authResponseContext_->reply,
+ authResponseContext_->code);
+ LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s", authResponseContext_->deviceId.c_str());
+ if (authResponseContext_->reply == 0) {
+ std::string groupId = authResponseContext_->groupId;
+ LOGI("AuthMessageProcessor::CreateSimpleMessage groupId %d", groupId.c_str());
+ nlohmann::json jsonObject = nlohmann::json::parse(groupId, nullptr, false);
+ if (jsonObject.is_discarded()) {
+ LOGE("DecodeRequestAuth jsonStr error");
+ return;
+ }
+ groupId = jsonObject[TAG_GROUP_ID];
+ json[PIN_CODE_KEY] = authResponseContext_->code;
+ json[TAG_NET_ID] = authResponseContext_->networkId;
+ json[TAG_REQUEST_ID] = authResponseContext_->requestId;
+ json[TAG_GROUP_ID] = groupId;
+ json[TAG_GROUP_NAME] = authResponseContext_->groupName;
+ LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s,%s", groupId.c_str(),
+ authResponseContext_->groupName.c_str());
+ }
+}
+
+void AuthMessageProcessor::CreateResponseFinishMessage(nlohmann::json &json)
+{
+ json[TAG_REPLY] = authResponseContext_->reply;
+}
+
+int32_t AuthMessageProcessor::ParseMessage(const std::string &message)
+{
+ LOGE(" AuthMessageProcessor ParseMessage");
+ nlohmann::json jsonObject = nlohmann::json::parse(message, nullptr, false);
+ if (jsonObject.is_discarded()) {
+ LOGE("DecodeRequestAuth jsonStr error");
+ return DM_FAILED;
+ }
+ if (!jsonObject.contains(TAG_TYPE)) {
+ LOGE("err json string, first time");
+ return DM_FAILED;
+ }
+ int32_t sliceNum = 0;
+ int32_t msgType = jsonObject[TAG_TYPE];
+ authResponseContext_->msgType = msgType;
+ LOGI("AuthMessageProcessor::ParseAuthRequestMessage======== %d", authResponseContext_->msgType);
+ switch (msgType) {
+ case MSG_TYPE_NEGOTIATE:
+ ParseNegotiateMessage(jsonObject);
+ break;
+ case MSG_TYPE_REQ_AUTH:
+ if (!jsonObject.contains(TAG_INDEX) || !jsonObject.contains(TAG_DEVICE_ID) ||
+ !jsonObject.contains(TAG_SLICE_NUM)) {
+ LOGE("err json string, first time");
+ return DM_FAILED;
+ }
+ authResponseContext_->deviceId = jsonObject[TAG_DEVICE_ID];
+ authResponseContext_->authType = jsonObject[TAG_AUTH_TYPE];
+ authResponseContext_->appDesc = jsonObject[TAG_APP_DESCRIPTION];
+ authResponseContext_->token = jsonObject[TAG_TOKEN];
+ authResponseContext_->targetPkgName = jsonObject[TAG_TARGET];
+ authResponseContext_->appName = jsonObject[TAG_APP_NAME];
+ LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s", authResponseContext_->deviceId.c_str());
+ sliceNum = jsonObject[TAG_SLICE_NUM];
+ if ((int32_t)authSplitJsonList_.size() < sliceNum) {
+ authSplitJsonList_.push_back(message);
+ } else {
+ ParseAuthRequestMessage();
+ }
+ break;
+ case MSG_TYPE_RESP_AUTH:
+ ParseAuthResponseMessage(jsonObject);
+ break;
+ case MSG_TYPE_REQ_AUTH_TERMINATE:
+ ParseResponseFinishMessage(jsonObject);
+ break;
+ default:
+ break;
+ }
+ return DM_OK;
+}
+
+void AuthMessageProcessor::ParseResponseFinishMessage(nlohmann::json &json)
+{
+ authResponseContext_->reply = json[TAG_REPLY];
+}
+
+void AuthMessageProcessor::ParseAuthResponseMessage(nlohmann::json &json)
+{
+ LOGI("AuthMessageProcessor::ParseAuthResponseMessage ");
+ authResponseContext_->reply = json[TAG_REPLY];
+ authResponseContext_->deviceId = json[TAG_DEVICE_ID];
+ authResponseContext_->token = json[TAG_TOKEN];
+ // authResponseContext_->deviceId = json[TAG_GROUPIDS];
+ if (authResponseContext_->reply == 0) {
+ authResponseContext_->code = json[PIN_CODE_KEY];
+ authResponseContext_->networkId = json[TAG_NET_ID];
+ authResponseContext_->requestId = json[TAG_REQUEST_ID];
+ authResponseContext_->groupId = json[TAG_GROUP_ID];
+ authResponseContext_->groupName = json[TAG_GROUP_NAME];
+ LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s,%s", authResponseContext_->groupId.c_str(),
+ authResponseContext_->groupName.c_str());
+ }
+ LOGI("AuthMessageProcessor::ParseAuthResponseMessage ");
+}
+
+void AuthMessageProcessor::ParseAuthRequestMessage()
+{
+ nlohmann::json jsonObject = authSplitJsonList_.front();
+ authResponseContext_->deviceId = jsonObject[TAG_DEVICE_ID];
+ authResponseContext_->reply = jsonObject[TAG_REPLY];
+ // authResponseContext_->syncGroupList = jsonObject[TAG_GROUPIDS];
+ authResponseContext_->authType = jsonObject[TAG_AUTH_TYPE];
+ LOGI("AuthMessageProcessor::ParseAuthResponseMessage %d,%d", authResponseContext_->reply);
+ LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s", authResponseContext_->deviceId.c_str());
+ if (authResponseContext_->reply == AUTH_REPLY_ACCEPT) {
+ authResponseContext_->networkId = jsonObject[TAG_NET_ID];
+ authResponseContext_->groupId = jsonObject[TAG_GROUP_ID];
+ authResponseContext_->groupName = jsonObject[TAG_GROUP_NAME];
+ authResponseContext_->requestId = jsonObject[TAG_REQUEST_ID];
+ }
+ authSplitJsonList_.clear();
+}
+
+void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json)
+{
+ if (json.contains(TAG_CRYPTO_SUPPORT)) {
+ authResponseContext_->cryptoSupport = json[TAG_CRYPTO_SUPPORT];
+ }
+ if (json.contains(TAG_CRYPTO_NAME)) {
+ authResponseContext_->cryptoSupport = json[TAG_CRYPTO_NAME];
+ }
+ if (json.contains(TAG_CRYPTO_VERSION)) {
+ authResponseContext_->cryptoSupport = json[TAG_CRYPTO_VERSION];
+ }
+ if (json.contains(TAG_DEVICE_ID)) {
+ authResponseContext_->deviceId = json[TAG_DEVICE_ID];
+ }
+ authResponseContext_->localDeviceId = json[TAG_LOCAL_DEVICE_ID];
+ authResponseContext_->reply = json[TAG_REPLY];
+}
+
+void AuthMessageProcessor::SetRequestContext(std::shared_ptr authRequestContext)
+{
+ authRequestContext_ = authRequestContext;
+}
+
+void AuthMessageProcessor::SetResponseContext(std::shared_ptr authResponseContext)
+{
+ authResponseContext_ = authResponseContext;
+}
+
+std::shared_ptr AuthMessageProcessor::GetResponseContext()
+{
+ return authResponseContext_;
+}
+
+std::shared_ptr AuthMessageProcessor::GetRequestContext()
+{
+ return authRequestContext_;
+}
+} // namespace DistributedHardware
+} // namespace OHOS
\ No newline at end of file
diff --git a/services/devicemanagerservice/src/authentication/auth_request_state.cpp b/services/devicemanagerservice/src/authentication/auth_request_state.cpp
new file mode 100644
index 00000000..1323b4e6
--- /dev/null
+++ b/services/devicemanagerservice/src/authentication/auth_request_state.cpp
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "auth_request_state.h"
+
+#include
+
+#include "dm_auth_manager.h"
+#include "dm_constants.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+
+void AuthRequestState::Leave()
+{
+}
+
+void AuthRequestState::SetAuthManager(std::shared_ptr authManager)
+{
+ authManager_ = std::move(authManager);
+}
+
+// void AuthRequestState::SetLastState(std::shared_ptr state) {
+// lastState_ = state;
+// }
+
+void AuthRequestState::SetAuthContext(std::shared_ptr context)
+{
+ context_ = std::move(context);
+}
+
+std::shared_ptr AuthRequestState::GetAuthContext()
+{
+ return context_;
+}
+
+void AuthRequestState::TransitionTo(std::shared_ptr state)
+{
+ LOGE("AuthRequestState::TransitionTo");
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ state->SetAuthManager(stateAuthManager);
+ stateAuthManager->SetAuthRequestState(state);
+ state->SetAuthContext(context_);
+ this->Leave();
+ state->Enter();
+}
+
+int32_t AuthRequestInitState::GetStateType()
+{
+ return AuthState::AUTH_REQUEST_INIT;
+}
+
+void AuthRequestInitState::Enter()
+{
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->EstablishAuthChannel(context_->deviceId);
+}
+
+int32_t AuthRequestNegotiateState::GetStateType()
+{
+ return AuthState::AUTH_REQUEST_NEGOTIATE;
+}
+
+void AuthRequestNegotiateState::Enter()
+{
+ // //1. 检查加解密模块是否存在并获取加解密的名称和版本信息
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->StartNegotiate(context_->sessionId);
+}
+
+int32_t AuthRequestNegotiateDoneState::GetStateType()
+{
+ return AuthState::AUTH_REQUEST_NEGOTIATE_DONE;
+}
+
+void AuthRequestNegotiateDoneState::Enter()
+{
+ // //1. 获取对端加解密信息,并对比两端状态
+ //
+ // //2. 保存加解密状态,发送认证请求
+ // authMessageProcessor_->CreateMessage(MSG_TYPE_REQ_AUTH);
+ // std::string message;
+ // softbusSession_->SendData(context_.sessionId, message);
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->SendAuthRequest(context_->sessionId);
+}
+
+int32_t AuthRequestReplyState::GetStateType()
+{
+ return AuthState::AUTH_REQUEST_REPLY;
+}
+
+void AuthRequestReplyState::Enter()
+{
+ // 1. 收到请求响应,判断用户响应结果
+
+ // 2. 用户授权同意
+
+ // 3. 回调给认证实现模块,启动认证
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->StartRespAuthProcess();
+}
+
+int32_t AuthRequestInputState::GetStateType()
+{
+ return AuthState::AUTH_REQUEST_INPUT;
+}
+
+void AuthRequestInputState::Enter()
+{
+ // //1. 获取用户输入
+ //
+ // //2. 验证认证信息
+ LOGE("DmAuthManager::AuthRequestInputState");
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->ShowStartAuthDialog();
+}
+
+int32_t AuthRequestJoinState::GetStateType()
+{
+ return AuthState::AUTH_REQUEST_JOIN;
+}
+
+void AuthRequestJoinState::Enter()
+{
+ // 1. 加入群组
+ LOGE("DmAuthManager::AuthRequestJoinState");
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->AddMember(context_->deviceId);
+}
+
+int32_t AuthRequestNetworkState::GetStateType()
+{
+ return AuthState::AUTH_REQUEST_NETWORK;
+}
+
+void AuthRequestNetworkState::Enter()
+{
+ // 1. 进行组网
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->JoinNetwork();
+}
+
+int32_t AuthRequestFinishState::GetStateType()
+{
+ return AuthState::AUTH_REQUEST_FINISH;
+}
+
+void AuthRequestFinishState::Enter()
+{
+ // 1. 清理资源
+ // 2. 通知对端认证结束,并关闭认证通道
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->AuthenticateFinish();
+}
+} // namespace DistributedHardware
+} // namespace OHOS
diff --git a/services/devicemanagerservice/src/authentication/auth_response_state.cpp b/services/devicemanagerservice/src/authentication/auth_response_state.cpp
new file mode 100644
index 00000000..10c4c17f
--- /dev/null
+++ b/services/devicemanagerservice/src/authentication/auth_response_state.cpp
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "auth_response_state.h"
+
+#include "dm_auth_manager.h"
+#include "dm_constants.h"
+#include "dm_log.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+
+void AuthResponseState::Leave()
+{
+}
+
+void AuthResponseState::SetAuthContext(std::shared_ptr context)
+{
+ context_ = std::move(context);
+}
+
+std::shared_ptr AuthResponseState::GetAuthContext()
+{
+ return context_;
+}
+
+void AuthResponseState::SetAuthManager(std::shared_ptr authManager)
+{
+ authManager_ = std::move(authManager);
+}
+
+void AuthResponseState::TransitionTo(std::shared_ptr state)
+{
+ LOGI("AuthRequestState:: TransitionTo");
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ state->SetAuthManager(stateAuthManager);
+ stateAuthManager->SetAuthResponseState(state);
+ state->SetAuthContext(context_);
+ this->Leave();
+ state->Enter();
+}
+
+int32_t AuthResponseInitState::GetStateType()
+{
+ return AuthState::AUTH_RESPONSE_INIT;
+}
+
+void AuthResponseInitState::Enter()
+{
+ LOGI("AuthResponse:: AuthResponseInitState Enter");
+ // 1.认证通道建立后,进入该状态
+}
+
+int32_t AuthResponseNegotiateState::GetStateType()
+{
+ return AuthState::AUTH_RESPONSE_NEGOTIATE;
+}
+
+void AuthResponseNegotiateState::Enter()
+{
+ // 1.收到协商消息后进入
+
+ // 2. 获取本地加解密模块信息,并回复消
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->RespNegotiate(context_->sessionId);
+}
+
+int32_t AuthResponseConfirmState::GetStateType()
+{
+ return AuthState::AUTH_RESPONSE_CONFIRM;
+}
+
+void AuthResponseConfirmState::Enter()
+{
+ //委托授权UI模块进行用户交互
+ //如果交互成功
+ // TransitionTo(new AuthResponseGroupState());
+ LOGI("AuthResponse:: AuthResponseConfirmState Enter");
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->ShowConfigDialog();
+}
+
+int32_t AuthResponseGroupState::GetStateType()
+{
+ return AuthState::AUTH_RESPONSE_GROUP;
+}
+
+void AuthResponseGroupState::Enter()
+{
+ // //1.创建群组,
+ // authManagerPtr_->GetHiChainConnector()->CreateGroup();
+ LOGI("AuthResponse:: AuthResponseGroupState Enter");
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->CreateGroup();
+}
+
+int32_t AuthResponseShowState::GetStateType()
+{
+ return AuthState::AUTH_RESPONSE_SHOW;
+}
+
+void AuthResponseShowState::Enter()
+{
+ // 1.委托认证实现模块进行用户交互
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->ShowAuthInfoDialog();
+}
+
+int32_t AuthResponseFinishState::GetStateType()
+{
+ return AuthState::AUTH_RESPONSE_FINISH;
+}
+
+void AuthResponseFinishState::Enter()
+{
+ // 1.结束UI显示
+
+ // 2.清理资源,结束状态机
+ std::shared_ptr stateAuthManager = authManager_.lock();
+ if (stateAuthManager == nullptr) {
+ LOGE("AuthRequestState::authManager_ null");
+ return;
+ }
+ stateAuthManager->AuthenticateFinish();
+}
+} // namespace DistributedHardware
+} // namespace OHOS
diff --git a/services/devicemanagerservice/src/authentication/auth_ui.cpp b/services/devicemanagerservice/src/authentication/auth_ui.cpp
new file mode 100644
index 00000000..b3afce45
--- /dev/null
+++ b/services/devicemanagerservice/src/authentication/auth_ui.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "auth_ui.h"
+
+#include "dm_ability_manager.h"
+#include "dm_constants.h"
+#include "dm_log.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+AuthUi::AuthUi()
+{
+ LOGI("AuthUi constructor");
+}
+
+int32_t AuthUi::ShowConfirmDialog(std::shared_ptr dmAbilityManager)
+{
+ if (dmAbilityManager == nullptr) {
+ LOGE("AuthUi::dmAbilityManager is null");
+ return DM_FAILED;
+ }
+ dmAbilityMgr_ = dmAbilityManager;
+ return StartFaService();
+}
+
+int32_t AuthUi::StartFaService()
+{
+ AbilityStatus status = dmAbilityMgr_->StartAbility(AbilityRole::ABILITY_ROLE_PASSIVE);
+ if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) {
+ LOGE("AuthUi::StartFaService timeout");
+ return DM_FAILED;
+ }
+ return DM_OK;
+}
+} // namespace DistributedHardware
+} // namespace OHOS
diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp
new file mode 100644
index 00000000..dcce54d5
--- /dev/null
+++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp
@@ -0,0 +1,754 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dm_auth_manager.h"
+
+#include "auth_message_processor.h"
+#include "auth_ui.h"
+#include "config_manager.h"
+#include "dm_ability_manager.h"
+#include "dm_constants.h"
+#include "dm_log.h"
+#include "dm_random.h"
+#include "nlohmann/json.hpp"
+#include "parameter.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+namespace {
+std::string AUTHENTICATE_TIMEOUT_TASK = "authenticateTimeoutTask";
+std::string NEGOTIATE_TIMEOUT_TASK = "negotiateTimeoutTask";
+std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask";
+std::string SHOW_TIMEOUT_TASK = "showTimeoutTask";
+std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask";
+std::string ADD_TIMEOUT_TASK = "addTimeoutTask";
+std::string WAIT_NEGOTIATE_TIMEOUT_TASK = "waitNegotiateTimeoutTask";
+std::string WAIT_REQUEST_TIMEOUT_TASK = "waitRequestTimeoutTask";
+
+int32_t SESSION_CANCEL_TIMEOUT = 0;
+int32_t AUTHENTICATE_TIMEOUT = 120;
+int32_t CONFIRM_TIMEOUT = 60;
+int32_t NEGOTIATE_TIMEOUT = 10;
+int32_t INPUT_TIMEOUT = 60;
+int32_t ADD_TIMEOUT = 10;
+int32_t WAIT_NEGOTIATE_TIMEOUT = 10;
+int32_t WAIT_REQUEST_TIMEOUT = 10;
+int32_t CANCEL_PICODE_DISPLAY = 1;
+int32_t DEVICE_ID_HALF = 2;
+} // namespace
+
+static void TimeOut(void *data)
+{
+ LOGE("time out ");
+ DmAuthManager *authMgr = (DmAuthManager *)data;
+ if (authMgr == nullptr) {
+ LOGE("time out error");
+ return;
+ }
+ authMgr->HandleAuthenticateTimeout();
+}
+
+DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector,
+ std::shared_ptr listener)
+ : softbusConnector_(softbusConnector), listener_(listener)
+{
+ LOGI("DmAuthManager constructor");
+ // TODO: load library so for different auth type
+ hiChainConnector_ = std::make_shared();
+
+ DmConfigManager &dmConfigManager = DmConfigManager::GetInstance();
+ dmConfigManager.GetAuthAdapter(authenticationMap_);
+}
+
+DmAuthManager::~DmAuthManager()
+{
+ LOGI("DmAuthManager destructor");
+}
+
+int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
+ const std::string &extra)
+{
+ // TODO:检查pkgName的权限
+
+ // std::shared_ptr authentication = authenticationMap_[authType];
+ // if (authentication == nullptr) {
+ // LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authType);
+ // return DM_AUTH_NOT_SUPPORT;
+ // }
+ LOGE("DmAuthManager::AuthenticateDevice is");
+ if (authRequestState_ != nullptr && authResponseState_ != nullptr) {
+ LOGE("DmAuthManager::AuthenticateDevice %s is request authentication.",
+ authRequestState_->GetAuthContext()->hostPkgName.c_str());
+ listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT,
+ std::to_string(DM_AUTH_BUSINESS_BUSY));
+ return DM_AUTH_BUSINESS_BUSY;
+ }
+
+ if (!softbusConnector_->HaveDeviceInMap(deviceId)) {
+ LOGE("AuthenticateDevice failed, the discoveryDeviceInfoMap_ not have this device");
+ listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT,
+ std::to_string(DM_AUTH_INPUT_FAILED));
+ return DM_AUTH_INPUT_FAILED;
+ }
+ if (extra.empty()) {
+ LOGE("AuthenticateDevice failed, extra is empty");
+ listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT,
+ std::to_string(DM_AUTH_BUSINESS_BUSY));
+ return DM_INPUT_PARA_EMPTY;
+ }
+ if (authType != AUTH_TYPE_PIN && authType != AUTH_TYPE_SCAN && authType != AUTH_TYPE_TOUCH) {
+ LOGE("AuthenticateDevice failed, authType is not support");
+ listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT,
+ std::to_string(DM_AUTH_NOT_SUPPORT));
+ return DM_AUTH_NOT_SUPPORT;
+ }
+ softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback(pkgName);
+ softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(pkgName, shared_from_this());
+
+ authMessageProcessor_ = std::make_shared