已开启
add chr #2036
liuqian创建于 1 天前
add chr #2036
已开启
共 5 个文件变更+201-319
| @@ -14,12 +14,152 @@ | |||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | import resourceManager from '@ohos.resourceManager'; | 16 | import resourceManager from '@ohos.resourceManager'; |
| 17 | +import commonEventManager from '@ohos.commonEventManager'; | ||
| 17 | import type { BusinessError } from '@ohos.base'; | 18 | import type { BusinessError } from '@ohos.base'; |
| 18 | 19 | ||
| 19 | const TAG: string = 'CommonUtils: '; | 20 | const TAG: string = 'CommonUtils: '; |
| 21 | +const BT_TRANSACTION_EVENT: string = 'usual.event.bluetooth.REPORT.TRANSACTION'; | ||
| 22 | + | ||
| 23 | +const RESULT_SUCCESS: number = 0; | ||
| 24 | +const RESULT_ERROR_UNSUPPORTED_TYPE: number = 1; | ||
| 25 | +const RESULT_ERROR_BAD_REQUEST: number = 2; | ||
| 26 | +const RESULT_ERROR_NOT_ACCEPTABLE: number = 3; | ||
| 27 | +const RESULT_ERROR_CANCELED: number = 4; | ||
| 28 | +const RESULT_ERROR_CONNECTION_FAILED: number = 5; | ||
| 29 | +const RESULT_ERROR_TRANSFER_FAILED: number = 6; | ||
| 30 | + | ||
| 31 | +const TRANSACTION_RESULT_TOTAL: number = 1; | ||
| 32 | +const TRANSACTION_RESULT_SUCCESS: number = 2; | ||
| 33 | +const TRANSACTION_RESULT_FAIL: number = 3; | ||
| 34 | + | ||
| 35 | +const SCENECODE_NA: number = 0; | ||
| 36 | + | ||
| 37 | +export const btTransactionStatisticsType = { | ||
| 38 | + TRANSACTION_TYPE_OPP_SEND: 1, | ||
| 39 | + TRANSACTION_TYPE_OPP_RECEIVE: 2, | ||
| 40 | + TRANSACTION_TYPE_OPP_RECEIVE_MEDIA_TYPE: 7, | ||
| 41 | +}; | ||
| 42 | + | ||
| 43 | +export const btTransactionStatisticsResult = { | ||
| 44 | + TRANSACTION_RESULT_TOTAL: 1, | ||
| 45 | + TRANSACTION_RESULT_SUCCESS: 2, | ||
| 46 | + TRANSACTION_RESULT_FAIL: 3, | ||
| 47 | +}; | ||
| 48 | + | ||
| 49 | +export const btTransactionStatisticsSceneCode = { | ||
| 50 | + TRANSACTION_SCENECODE_NA: 0, | ||
| 51 | + TRANSACTION_SCENECODE_1: 1, | ||
| 52 | + TRANSACTION_SCENECODE_2: 2, | ||
| 53 | + TRANSACTION_SCENECODE_3: 3, | ||
| 54 | + TRANSACTION_SCENECODE_4: 4, | ||
| 55 | + TRANSACTION_SCENECODE_5: 5, | ||
| 56 | + TRANSACTION_SCENECODE_6: 6, | ||
| 57 | + TRANSACTION_SCENECODE_7: 7, | ||
| 58 | + TRANSACTION_SCENECODE_8: 8, | ||
| 59 | + TRANSACTION_SCENECODE_9: 9, | ||
| 60 | + TRANSACTION_SCENECODE_10: 10, | ||
| 61 | + TRANSACTION_SCENECODE_11: 11, | ||
| 62 | + TRANSACTION_SCENECODE_12: 12, | ||
| 63 | + TRANSACTION_SCENECODE_13: 13, | ||
| 64 | + TRANSACTION_SCENECODE_14: 14, | ||
| 65 | + TRANSACTION_SCENECODE_15: 15, | ||
| 66 | + TRANSACTION_SCENECODE_16: 16, | ||
| 67 | +}; | ||
| 20 | 68 | ||
| 21 | export class CommonUtils { | 69 | export class CommonUtils { |
| 22 | 70 | ||
| 71 | + /** | ||
| 72 | + * 上报蓝牙事务统计 | ||
| 73 | + * | ||
| 74 | + * @param transactionType 事务类型 | ||
| 75 | + * @param result 结果类型 | ||
| 76 | + * @param resultCount 结果数量 | ||
| 77 | + * @param sceneCode 场景码 | ||
| 78 | + * @param sceneCodeCount 场景码数量 | ||
| 79 | + */ | ||
| 80 | + reportBtTransactionChr(transactionType: number, result: number, resultCount: number, | ||
| 81 | + sceneCode: number, sceneCodeCount: number) { | ||
| 82 | + const options: commonEventManager.CommonEventPublishData = { | ||
| 83 | + code: 0, | ||
| 84 | + data: 'message', | ||
| 85 | + subscriberPermissions: ['ohos.permission.MANAGE_BLUETOOTH'], | ||
| 86 | + isOrdered: true, | ||
| 87 | + isSticky: false, | ||
| 88 | + parameters: { 'transactionType': transactionType, 'result': result, | ||
| 89 | + 'resultCount': resultCount, 'sceneCode': sceneCode, 'sceneCodeCount': sceneCodeCount} | ||
| 90 | + } | ||
| 91 | + commonEventManager.publish(BT_TRANSACTION_EVENT, options, (err) => { | ||
| 92 | + if (err) { | ||
| 93 | + console.info(TAG, 'get bt transaction event publish failed.' + JSON.stringify(err)); | ||
| 94 | + } else { | ||
| 95 | + console.info(TAG, 'get bt transaction event publish success.'); | ||
| 96 | + } | ||
| 97 | + }) | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 根据发送传输结果上报蓝牙事务统计数据 | ||
| 102 | + * | ||
| 103 | + * @param dataResult 传输结果 | ||
| 104 | + * @param totalCount 总数量 | ||
| 105 | + * @param successCount 成功数量 | ||
| 106 | + */ | ||
| 107 | + reportBtSendChrDataByResult(dataResult: number, totalCount: number, successCount: number) { | ||
| 108 | + let transactionType = btTransactionStatisticsType.TRANSACTION_TYPE_OPP_SEND; | ||
| 109 | + if (totalCount - successCount > totalCount) { | ||
| 110 | + return; | ||
| 111 | + } | ||
| 112 | + if (dataResult == RESULT_SUCCESS) { | ||
| 113 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_SUCCESS, | ||
| 114 | + 1, SCENECODE_NA, 0); | ||
| 115 | + } else if ((dataResult == RESULT_ERROR_UNSUPPORTED_TYPE || | ||
| 116 | + dataResult == RESULT_ERROR_BAD_REQUEST) && totalCount > 0) { | ||
| 117 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_FAIL, | ||
| 118 | + totalCount, dataResult, totalCount); | ||
| 119 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_TOTAL, | ||
| 120 | + totalCount - 1, SCENECODE_NA, 0); | ||
| 121 | + } else if (dataResult == RESULT_ERROR_CANCELED || | ||
| 122 | + dataResult == RESULT_ERROR_TRANSFER_FAILED) { | ||
| 123 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_FAIL, 1, dataResult, 1); | ||
| 124 | + } else { | ||
| 125 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_FAIL, 1, dataResult, 1); | ||
| 126 | + } | ||
| 127 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_TOTAL, | ||
| 128 | + 1, SCENECODE_NA, 0); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 根据接收传输结果上报蓝牙事务统计数据 | ||
| 133 | + * | ||
| 134 | + * @param dataResult 传输结果 | ||
| 135 | + * @param totalCount 总数量 | ||
| 136 | + * @param successCount 成功数量 | ||
| 137 | + */ | ||
| 138 | + reportBtReceiveChrDataByResult(dataResult: number, totalCount: number, successCount: number) { | ||
| 139 | + let transactionType = btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE; | ||
| 140 | + if (dataResult == RESULT_SUCCESS) { | ||
| 141 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_SUCCESS, | ||
| 142 | + 1, SCENECODE_NA, 0); | ||
| 143 | + } else if ((dataResult == RESULT_ERROR_NOT_ACCEPTABLE || | ||
| 144 | + dataResult == RESULT_ERROR_BAD_REQUEST) && totalCount > 0) { | ||
| 145 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_FAIL, | ||
| 146 | + totalCount, dataResult, totalCount); | ||
| 147 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_TOTAL, | ||
| 148 | + totalCount - 1, SCENECODE_NA, 0); | ||
| 149 | + } else if ((dataResult == RESULT_ERROR_CANCELED || | ||
| 150 | + dataResult == RESULT_ERROR_TRANSFER_FAILED) && | ||
| 151 | + totalCount - successCount >= 1) { | ||
| 152 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_FAIL, | ||
| 153 | + totalCount - successCount, dataResult, totalCount - successCount); | ||
| 154 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_TOTAL, | ||
| 155 | + totalCount - successCount - 1, SCENECODE_NA, 0); | ||
| 156 | + } else if (dataResult == RESULT_ERROR_CONNECTION_FAILED) { | ||
| 157 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_FAIL, 1, dataResult, 1); | ||
| 158 | + } | ||
| 159 | + this.reportBtTransactionChr(transactionType, TRANSACTION_RESULT_TOTAL, | ||
| 160 | + 1, SCENECODE_NA, 0); | ||
| 161 | + } | ||
| 162 | + | ||
| 23 | /** | 163 | /** |
| 24 | * 以同步方式获取string资源值 | 164 | * 以同步方式获取string资源值 |
| 25 | * | 165 | * |
| @@ -33,10 +33,11 @@ import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager' | |||
| 33 | import systemParameterEnhance from '@ohos.systemParameterEnhance'; | 33 | import systemParameterEnhance from '@ohos.systemParameterEnhance'; |
| 34 | import PermissionUtils from 'common/PermissionUtils'; | 34 | import PermissionUtils from 'common/PermissionUtils'; |
| 35 | import CommonUtils from 'common/CommonUtils'; | 35 | import CommonUtils from 'common/CommonUtils'; |
| 36 | +import { btTransactionStatisticsType, btTransactionStatisticsResult, | ||
| 37 | + btTransactionStatisticsSceneCode } from 'common/CommonUtils'; | ||
| 36 | 38 | ||
| 37 | const TAG: string = '[BT_RECEIVE_SERVICE]==>' | 39 | const TAG: string = '[BT_RECEIVE_SERVICE]==>' |
| 38 | const EVENT_TYPE_TRANSACTION: number = 6; | 40 | const EVENT_TYPE_TRANSACTION: number = 6; |
| 39 | -const BT_TRANSACTION_EVENT: string = 'usual.event.bluetooth.REPORT.TRANSACTION'; | ||
| 40 | 41 | ||
| 41 | const RESULT_SUCCESS: number = 0; | 42 | const RESULT_SUCCESS: number = 0; |
| 42 | const RESULT_ERROR_UNSUPPORTED_TYPE: number = 1; | 43 | const RESULT_ERROR_UNSUPPORTED_TYPE: number = 1; |
| @@ -59,37 +60,6 @@ const OPP_TRANSFER_USER_ACCEPT: number = 0; | |||
| 59 | const OPP_TRANSFER_AUTO_ACCEPT: number = 1; | 60 | const OPP_TRANSFER_AUTO_ACCEPT: number = 1; |
| 60 | const UNKNOWN_VALUE: number = -1; | 61 | const UNKNOWN_VALUE: number = -1; |
| 61 | 62 | ||
| 62 | -const btTransactionStatisticsType = { | ||
| 63 | - TRANSACTION_TYPE_OPP_SEND : 1, | ||
| 64 | - TRANSACTION_TYPE_OPP_RECEIVE : 2, | ||
| 65 | -}; | ||
| 66 | - | ||
| 67 | -const btTransactionStatisticsResult = { | ||
| 68 | - TRANSACTION_RESULT_TOTAL : 1, | ||
| 69 | - TRANSACTION_RESULT_SUCCESS : 2, | ||
| 70 | - TRANSACTION_RESULT_FAIL : 3, | ||
| 71 | -}; | ||
| 72 | - | ||
| 73 | -const btTransactionStatisticsSceneCode = { | ||
| 74 | - TRANSACTION_SCENECODE_NA : 0, | ||
| 75 | - TRANSACTION_SCENECODE_1 : 1, | ||
| 76 | - TRANSACTION_SCENECODE_2 : 2, | ||
| 77 | - TRANSACTION_SCENECODE_3 : 3, | ||
| 78 | - TRANSACTION_SCENECODE_4 : 4, | ||
| 79 | - TRANSACTION_SCENECODE_5 : 5, | ||
| 80 | - TRANSACTION_SCENECODE_6 : 6, | ||
| 81 | - TRANSACTION_SCENECODE_7 : 7, | ||
| 82 | - TRANSACTION_SCENECODE_8 : 8, | ||
| 83 | - TRANSACTION_SCENECODE_9 : 9, | ||
| 84 | - TRANSACTION_SCENECODE_10 : 10, | ||
| 85 | - TRANSACTION_SCENECODE_11 : 11, | ||
| 86 | - TRANSACTION_SCENECODE_12 : 12, | ||
| 87 | - TRANSACTION_SCENECODE_13 : 13, | ||
| 88 | - TRANSACTION_SCENECODE_14 : 14, | ||
| 89 | - TRANSACTION_SCENECODE_15 : 15, | ||
| 90 | - TRANSACTION_SCENECODE_16 : 16, | ||
| 91 | -}; | ||
| 92 | - | ||
| 93 | export default class BluetoothReceiveUIAbility extends UIAbility { | 63 | export default class BluetoothReceiveUIAbility extends UIAbility { |
| 94 | private subscriber: commonEventManager.CommonEventSubscriber | null = null; | 64 | private subscriber: commonEventManager.CommonEventSubscriber | null = null; |
| 95 | private subscribeinfo: commonEventManager.CommonEventSubscribeInfo = { | 65 | private subscribeinfo: commonEventManager.CommonEventSubscribeInfo = { |
| @@ -152,7 +122,8 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 152 | } | 122 | } |
| 153 | this.timerIdCreate = setTimeout(() => { | 123 | this.timerIdCreate = setTimeout(() => { |
| 154 | console.info(TAG, 'onCreate 1 second but nothing received'); | 124 | console.info(TAG, 'onCreate 1 second but nothing received'); |
| 155 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | 125 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 126 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 156 | 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_1, 1); | 127 | 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_1, 1); |
| 157 | this.handleTerminate(); | 128 | this.handleTerminate(); |
| 158 | }, 1000); | 129 | }, 1000); |
| @@ -179,50 +150,6 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 179 | this.context.terminateSelf(); | 150 | this.context.terminateSelf(); |
| 180 | } | 151 | } |
| 181 | 152 | ||
| 182 | - reportBtChrDataByResult(dataResult: number) { | ||
| 183 | - console.info(TAG, 'reportBtChrDataByResult dataResult ' + dataResult + | ||
| 184 | - ' totalCount' + this.totalCount + ' successCount' + this.successCount); | ||
| 185 | - if (dataResult == RESULT_SUCCESS) { | ||
| 186 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_SUCCESS, | ||
| 187 | - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 188 | - } else if ((dataResult == RESULT_ERROR_NOT_ACCEPTABLE || | ||
| 189 | - dataResult == RESULT_ERROR_BAD_REQUEST) && this.totalCount > 0) { | ||
| 190 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 191 | - this.totalCount, dataResult, this.totalCount); | ||
| 192 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 193 | - this.totalCount - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 194 | - } else if ((dataResult == RESULT_ERROR_CANCELED || dataResult == RESULT_ERROR_TRANSFER_FAILED) && | ||
| 195 | - this.totalCount - this.successCount >= 1) { | ||
| 196 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 197 | - this.totalCount - this.successCount, dataResult, this.totalCount - this.successCount); | ||
| 198 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 199 | - this.totalCount - this.successCount -1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 200 | - } else if (dataResult == RESULT_ERROR_CONNECTION_FAILED) { | ||
| 201 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, 1, dataResult, 1); | ||
| 202 | - } | ||
| 203 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 204 | - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 205 | - } | ||
| 206 | - | ||
| 207 | - reportBtTransactionChr(result: number, resultCount: number, sceneCode: number, sceneCodeCount: number) { | ||
| 208 | - const options: commonEventManager.CommonEventPublishData = { | ||
| 209 | - code: 0, | ||
| 210 | - data: 'message', | ||
| 211 | - subscriberPermissions: ['ohos.permission.MANAGE_BLUETOOTH'], | ||
| 212 | - isOrdered: true, | ||
| 213 | - isSticky: false, | ||
| 214 | - parameters: { 'transactionType': btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, 'result': result, | ||
| 215 | - 'resultCount': resultCount, 'sceneCode': sceneCode, 'sceneCodeCount': sceneCodeCount} | ||
| 216 | - } | ||
| 217 | - commonEventManager.publish(BT_TRANSACTION_EVENT, options, (err) => { | ||
| 218 | - if (err) { | ||
| 219 | - console.info(TAG, 'get bt transaction event publish failed.' + JSON.stringify(err)); | ||
| 220 | - } else { | ||
| 221 | - console.info(TAG, 'get bt transaction event publish success.'); | ||
| 222 | - } | ||
| 223 | - }) | ||
| 224 | - } | ||
| 225 | - | ||
| 226 | async readyReceiveEvent() { | 153 | async readyReceiveEvent() { |
| 227 | try { | 154 | try { |
| 228 | console.info(TAG, 'readyReceiveEvent'); | 155 | console.info(TAG, 'readyReceiveEvent'); |
| @@ -283,9 +210,11 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 283 | clearTimeout(this.timerIdReceive); | 210 | clearTimeout(this.timerIdReceive); |
| 284 | this.transfering = false; | 211 | this.transfering = false; |
| 285 | this.oppProfile.setIncomingFileConfirmation(false, -1); | 212 | this.oppProfile.setIncomingFileConfirmation(false, -1); |
| 286 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | 213 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 214 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 287 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_2, this.totalCount); | 215 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_2, this.totalCount); |
| 288 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | 216 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 217 | + btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 289 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | 218 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); |
| 290 | this.pullUpReceiveResultNotification(); | 219 | this.pullUpReceiveResultNotification(); |
| 291 | this.handleTerminate(); | 220 | this.handleTerminate(); |
| @@ -298,9 +227,11 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 298 | this.transfering = false; | 227 | this.transfering = false; |
| 299 | this.oppProfile.setIncomingFileConfirmation(false, -1); | 228 | this.oppProfile.setIncomingFileConfirmation(false, -1); |
| 300 | 229 | ||
| 301 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | 230 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 231 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 302 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_5, this.totalCount); | 232 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_5, this.totalCount); |
| 303 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | 233 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 234 | + btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 304 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | 235 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); |
| 305 | this.pullUpReceiveResultNotification(); | 236 | this.pullUpReceiveResultNotification(); |
| 306 | this.handleTerminate(); | 237 | this.handleTerminate(); |
| @@ -380,7 +311,8 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 380 | } else if (data.status == STATUS_FINISH) { | 311 | } else if (data.status == STATUS_FINISH) { |
| 381 | if (data.result != RESULT_SUCCESS_DISCONNECT) { | 312 | if (data.result != RESULT_SUCCESS_DISCONNECT) { |
| 382 | data.result == RESULT_SUCCESS ? this.successCount++ : this.failedCount++; | 313 | data.result == RESULT_SUCCESS ? this.successCount++ : this.failedCount++; |
| 383 | - this.reportBtChrDataByResult(data.result); | 314 | + CommonUtils.reportBtReceiveChrDataByResult(data.result, |
| 315 | + this.totalCount, this.successCount); | ||
| 384 | } | 316 | } |
| 385 | if (data.result != RESULT_SUCCESS && data.filePath != undefined && data.filePath.trim().length > 0) { | 317 | if (data.result != RESULT_SUCCESS && data.filePath != undefined && data.filePath.trim().length > 0) { |
| 386 | this.tapEventIsAllowed = true; | 318 | this.tapEventIsAllowed = true; |
| @@ -415,6 +347,15 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 415 | console.error(TAG, 'uri path is not access'); | 347 | console.error(TAG, 'uri path is not access'); |
| 416 | return; | 348 | return; |
| 417 | } | 349 | } |
| 350 | + if (data.parameters.fileType == 'files') { | ||
| 351 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE_MEDIA_TYPE, | ||
| 352 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 353 | + 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_2, 1); | ||
| 354 | + } else { | ||
| 355 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE_MEDIA_TYPE, | ||
| 356 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 357 | + 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_1, 1); | ||
| 358 | + } | ||
| 418 | this.sandBoxUri = uri.path + '/' + this.fileName; | 359 | this.sandBoxUri = uri.path + '/' + this.fileName; |
| 419 | let file = fs.openSync(this.sandBoxUri, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); | 360 | let file = fs.openSync(this.sandBoxUri, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); |
| 420 | this.fileFd = file.fd; | 361 | this.fileFd = file.fd; |
| @@ -28,11 +28,12 @@ import fs from '@ohos.file.fs'; | |||
| 28 | import systemParameterEnhance from '@ohos.systemParameterEnhance'; | 28 | import systemParameterEnhance from '@ohos.systemParameterEnhance'; |
| 29 | import PermissionUtils from 'common/PermissionUtils'; | 29 | import PermissionUtils from 'common/PermissionUtils'; |
| 30 | import CommonUtils from 'common/CommonUtils'; | 30 | import CommonUtils from 'common/CommonUtils'; |
| 31 | +import { btTransactionStatisticsType, btTransactionStatisticsResult, | ||
| 32 | + btTransactionStatisticsSceneCode } from 'common/CommonUtils'; | ||
| 31 | 33 | ||
| 32 | const TAG: string = '[BT_SEND_SERVICE]==>' | 34 | const TAG: string = '[BT_SEND_SERVICE]==>' |
| 33 | 35 | ||
| 34 | const EVENT_TYPE_TRANSACTION: number = 6; | 36 | const EVENT_TYPE_TRANSACTION: number = 6; |
| 35 | -const BT_TRANSACTION_EVENT: string = 'usual.event.bluetooth.REPORT.TRANSACTION'; | ||
| 36 | const RESULT_SUCCESS: number = 0; | 37 | const RESULT_SUCCESS: number = 0; |
| 37 | const RESULT_ERROR_UNSUPPORTED_TYPE: number = 1; | 38 | const RESULT_ERROR_UNSUPPORTED_TYPE: number = 1; |
| 38 | const RESULT_ERROR_BAD_REQUEST: number = 2; | 39 | const RESULT_ERROR_BAD_REQUEST: number = 2; |
| @@ -46,37 +47,6 @@ const STATUS_PENDING: number = 0; | |||
| 46 | const STATUS_RUNNING: number = 1; | 47 | const STATUS_RUNNING: number = 1; |
| 47 | const STATUS_FINISH: number = 2; | 48 | const STATUS_FINISH: number = 2; |
| 48 | 49 | ||
| 49 | -const btTransactionStatisticsType = { | ||
| 50 | - TRANSACTION_TYPE_OPP_SEND : 1, | ||
| 51 | - TRANSACTION_TYPE_OPP_RECEIVE : 2, | ||
| 52 | -}; | ||
| 53 | - | ||
| 54 | -const btTransactionStatisticsResult = { | ||
| 55 | - TRANSACTION_RESULT_TOTAL : 1, | ||
| 56 | - TRANSACTION_RESULT_SUCCESS : 2, | ||
| 57 | - TRANSACTION_RESULT_FAIL : 3, | ||
| 58 | -}; | ||
| 59 | - | ||
| 60 | -const btTransactionStatisticsSceneCode = { | ||
| 61 | - TRANSACTION_SCENECODE_NA : 0, | ||
| 62 | - TRANSACTION_SCENECODE_1 : 1, | ||
| 63 | - TRANSACTION_SCENECODE_2 : 2, | ||
| 64 | - TRANSACTION_SCENECODE_3 : 3, | ||
| 65 | - TRANSACTION_SCENECODE_4 : 4, | ||
| 66 | - TRANSACTION_SCENECODE_5 : 5, | ||
| 67 | - TRANSACTION_SCENECODE_6 : 6, | ||
| 68 | - TRANSACTION_SCENECODE_7 : 7, | ||
| 69 | - TRANSACTION_SCENECODE_8 : 8, | ||
| 70 | - TRANSACTION_SCENECODE_9 : 9, | ||
| 71 | - TRANSACTION_SCENECODE_10 : 10, | ||
| 72 | - TRANSACTION_SCENECODE_11 : 11, | ||
| 73 | - TRANSACTION_SCENECODE_12 : 12, | ||
| 74 | - TRANSACTION_SCENECODE_13 : 13, | ||
| 75 | - TRANSACTION_SCENECODE_14 : 14, | ||
| 76 | - TRANSACTION_SCENECODE_15 : 15, | ||
| 77 | - TRANSACTION_SCENECODE_16 : 16, | ||
| 78 | -}; | ||
| 79 | - | ||
| 80 | export default class BluetoothSendUIAbility extends UIAbility { | 50 | export default class BluetoothSendUIAbility extends UIAbility { |
| 81 | private oppProfile = opp.createOppServerProfile(); | 51 | private oppProfile = opp.createOppServerProfile(); |
| 82 | private timeInterval: number = 0; | 52 | private timeInterval: number = 0; |
| @@ -106,7 +76,8 @@ export default class BluetoothSendUIAbility extends UIAbility { | |||
| 106 | console.info(TAG, 'BluetoothSendUIAbility onCreate'); | 76 | console.info(TAG, 'BluetoothSendUIAbility onCreate'); |
| 107 | this.timerIdCreate = setTimeout(() => { | 77 | this.timerIdCreate = setTimeout(() => { |
| 108 | console.info(TAG, 'onCreate 51 seconds but nothing received'); | 78 | console.info(TAG, 'onCreate 51 seconds but nothing received'); |
| 109 | - this.reportBtChrDataByResult(RESULT_ERROR_NO_MESSAGE); | 79 | + CommonUtils.reportBtSendChrDataByResult(RESULT_ERROR_NO_MESSAGE, |
| 80 | + this.totalCount, this.successCount); | ||
| 110 | this.handleTerminate(); | 81 | this.handleTerminate(); |
| 111 | }, (this.userReceiveTimeout + 1) * 1000); | 82 | }, (this.userReceiveTimeout + 1) * 1000); |
| 112 | this.timerIdCreated = true; | 83 | this.timerIdCreated = true; |
| @@ -133,48 +104,6 @@ export default class BluetoothSendUIAbility extends UIAbility { | |||
| 133 | this.context.terminateSelf(); | 104 | this.context.terminateSelf(); |
| 134 | } | 105 | } |
| 135 | 106 | ||
| 136 | - reportBtChrDataByResult(dataResult: number) { | ||
| 137 | - if (this.successCount + this.failedCount > this.totalCount) { | ||
| 138 | - return; | ||
| 139 | - } | ||
| 140 | - if (dataResult == RESULT_SUCCESS) { | ||
| 141 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_SUCCESS, | ||
| 142 | - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 143 | - } else if ((dataResult == RESULT_ERROR_UNSUPPORTED_TYPE || | ||
| 144 | - dataResult == RESULT_ERROR_BAD_REQUEST) && this.totalCount > 0) { | ||
| 145 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 146 | - this.totalCount, dataResult, this.totalCount); | ||
| 147 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 148 | - this.totalCount - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 149 | - } else if (dataResult == RESULT_ERROR_CANCELED || | ||
| 150 | - dataResult == RESULT_ERROR_TRANSFER_FAILED) { | ||
| 151 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, 1, dataResult, 1); | ||
| 152 | - } else { | ||
| 153 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, 1, dataResult, 1); | ||
| 154 | - } | ||
| 155 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 156 | - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | - reportBtTransactionChr(result: number, resultCount: number, sceneCode: number, sceneCodeCount: number) { | ||
| 160 | - const options: commonEventManager.CommonEventPublishData = { | ||
| 161 | - code: 0, | ||
| 162 | - data: 'message', | ||
| 163 | - subscriberPermissions: ['ohos.permission.MANAGE_BLUETOOTH'], | ||
| 164 | - isOrdered: true, | ||
| 165 | - isSticky: false, | ||
| 166 | - parameters: { 'transactionType': btTransactionStatisticsType.TRANSACTION_TYPE_OPP_SEND, 'result': result, | ||
| 167 | - 'resultCount': resultCount, 'sceneCode': sceneCode, 'sceneCodeCount': sceneCodeCount} | ||
| 168 | - } | ||
| 169 | - commonEventManager.publish(BT_TRANSACTION_EVENT, options, (err) => { | ||
| 170 | - if (err) { | ||
| 171 | - console.info(TAG, 'get bt transaction event publish failed.' + JSON.stringify(err)); | ||
| 172 | - } else { | ||
| 173 | - console.info(TAG, 'get bt transaction event publish success.'); | ||
| 174 | - } | ||
| 175 | - }) | ||
| 176 | - } | ||
| 177 | - | ||
| 178 | readyReceiveEvent() { | 107 | readyReceiveEvent() { |
| 179 | try { | 108 | try { |
| 180 | console.info(TAG, 'readyReceiveEvent'); | 109 | console.info(TAG, 'readyReceiveEvent'); |
| @@ -231,7 +160,8 @@ export default class BluetoothSendUIAbility extends UIAbility { | |||
| 231 | this.currentCount = data.currentCount; | 160 | this.currentCount = data.currentCount; |
| 232 | } else if (data.status == STATUS_FINISH && data.totalCount > 0) { | 161 | } else if (data.status == STATUS_FINISH && data.totalCount > 0) { |
| 233 | data.result == RESULT_SUCCESS ? this.successCount++ : this.failedCount++; | 162 | data.result == RESULT_SUCCESS ? this.successCount++ : this.failedCount++; |
| 234 | - this.reportBtChrDataByResult(data.result); | 163 | + CommonUtils.reportBtSendChrDataByResult(data.result, |
| 164 | + this.totalCount, this.successCount); | ||
| 235 | if (data.currentCount == data.totalCount || data.result == RESULT_ERROR_UNSUPPORTED_TYPE) { | 165 | if (data.currentCount == data.totalCount || data.result == RESULT_ERROR_UNSUPPORTED_TYPE) { |
| 236 | this.currentCount++; | 166 | this.currentCount++; |
| 237 | this.cancelSendProgressNotification(); | 167 | this.cancelSendProgressNotification(); |
| @@ -33,10 +33,11 @@ import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager' | |||
| 33 | import systemParameterEnhance from '@ohos.systemParameterEnhance'; | 33 | import systemParameterEnhance from '@ohos.systemParameterEnhance'; |
| 34 | import PermissionUtils from 'common/PermissionUtils'; | 34 | import PermissionUtils from 'common/PermissionUtils'; |
| 35 | import CommonUtils from 'common/CommonUtils'; | 35 | import CommonUtils from 'common/CommonUtils'; |
| 36 | +import { btTransactionStatisticsType, btTransactionStatisticsResult, | ||
| 37 | + btTransactionStatisticsSceneCode } from 'common/CommonUtils'; | ||
| 36 | 38 | ||
| 37 | const TAG: string = '[BT_RECEIVE_SERVICE]==>' | 39 | const TAG: string = '[BT_RECEIVE_SERVICE]==>' |
| 38 | const EVENT_TYPE_TRANSACTION: number = 6; | 40 | const EVENT_TYPE_TRANSACTION: number = 6; |
| 39 | -const BT_TRANSACTION_EVENT: string = 'usual.event.bluetooth.REPORT.TRANSACTION'; | ||
| 40 | 41 | ||
| 41 | const RESULT_SUCCESS: number = 0; | 42 | const RESULT_SUCCESS: number = 0; |
| 42 | const RESULT_ERROR_UNSUPPORTED_TYPE: number = 1; | 43 | const RESULT_ERROR_UNSUPPORTED_TYPE: number = 1; |
| @@ -59,37 +60,6 @@ const OPP_TRANSFER_USER_ACCEPT: number = 0; | |||
| 59 | const OPP_TRANSFER_AUTO_ACCEPT: number = 1; | 60 | const OPP_TRANSFER_AUTO_ACCEPT: number = 1; |
| 60 | const UNKNOWN_VALUE: number = -1; | 61 | const UNKNOWN_VALUE: number = -1; |
| 61 | 62 | ||
| 62 | -const btTransactionStatisticsType = { | ||
| 63 | - TRANSACTION_TYPE_OPP_SEND : 1, | ||
| 64 | - TRANSACTION_TYPE_OPP_RECEIVE : 2, | ||
| 65 | -}; | ||
| 66 | - | ||
| 67 | -const btTransactionStatisticsResult = { | ||
| 68 | - TRANSACTION_RESULT_TOTAL : 1, | ||
| 69 | - TRANSACTION_RESULT_SUCCESS : 2, | ||
| 70 | - TRANSACTION_RESULT_FAIL : 3, | ||
| 71 | -}; | ||
| 72 | - | ||
| 73 | -const btTransactionStatisticsSceneCode = { | ||
| 74 | - TRANSACTION_SCENECODE_NA : 0, | ||
| 75 | - TRANSACTION_SCENECODE_1 : 1, | ||
| 76 | - TRANSACTION_SCENECODE_2 : 2, | ||
| 77 | - TRANSACTION_SCENECODE_3 : 3, | ||
| 78 | - TRANSACTION_SCENECODE_4 : 4, | ||
| 79 | - TRANSACTION_SCENECODE_5 : 5, | ||
| 80 | - TRANSACTION_SCENECODE_6 : 6, | ||
| 81 | - TRANSACTION_SCENECODE_7 : 7, | ||
| 82 | - TRANSACTION_SCENECODE_8 : 8, | ||
| 83 | - TRANSACTION_SCENECODE_9 : 9, | ||
| 84 | - TRANSACTION_SCENECODE_10 : 10, | ||
| 85 | - TRANSACTION_SCENECODE_11 : 11, | ||
| 86 | - TRANSACTION_SCENECODE_12 : 12, | ||
| 87 | - TRANSACTION_SCENECODE_13 : 13, | ||
| 88 | - TRANSACTION_SCENECODE_14 : 14, | ||
| 89 | - TRANSACTION_SCENECODE_15 : 15, | ||
| 90 | - TRANSACTION_SCENECODE_16 : 16, | ||
| 91 | -}; | ||
| 92 | - | ||
| 93 | export default class BluetoothReceiveUIAbility extends UIAbility { | 63 | export default class BluetoothReceiveUIAbility extends UIAbility { |
| 94 | private subscriber: commonEventManager.CommonEventSubscriber | null = null; | 64 | private subscriber: commonEventManager.CommonEventSubscriber | null = null; |
| 95 | private subscribeinfo: commonEventManager.CommonEventSubscribeInfo = { | 65 | private subscribeinfo: commonEventManager.CommonEventSubscribeInfo = { |
| @@ -153,7 +123,8 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 153 | } | 123 | } |
| 154 | this.timerIdCreate = setTimeout(() => { | 124 | this.timerIdCreate = setTimeout(() => { |
| 155 | console.info(TAG, 'onCreate 1 second but nothing received'); | 125 | console.info(TAG, 'onCreate 1 second but nothing received'); |
| 156 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | 126 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 127 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 157 | 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_1, 1); | 128 | 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_1, 1); |
| 158 | this.handleTerminate(); | 129 | this.handleTerminate(); |
| 159 | }, 1000); | 130 | }, 1000); |
| @@ -179,50 +150,6 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 179 | this.context.terminateSelf(); | 150 | this.context.terminateSelf(); |
| 180 | } | 151 | } |
| 181 | 152 | ||
| 182 | - reportBtChrDataByResult(dataResult: number) { | ||
| 183 | - console.info(TAG, 'reportBtChrDataByResult dataResult ' + dataResult + | ||
| 184 | - ' totalCount' + this.totalCount + ' successCount' + this.successCount); | ||
| 185 | - if (dataResult == RESULT_SUCCESS) { | ||
| 186 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_SUCCESS, | ||
| 187 | - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 188 | - } else if ((dataResult == RESULT_ERROR_NOT_ACCEPTABLE || | ||
| 189 | - dataResult == RESULT_ERROR_BAD_REQUEST) && this.totalCount > 0) { | ||
| 190 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 191 | - this.totalCount, dataResult, this.totalCount); | ||
| 192 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 193 | - this.totalCount - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 194 | - } else if ((dataResult == RESULT_ERROR_CANCELED || dataResult == RESULT_ERROR_TRANSFER_FAILED) && | ||
| 195 | - this.totalCount - this.successCount >= 1) { | ||
| 196 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 197 | - this.totalCount - this.successCount, dataResult, this.totalCount - this.successCount); | ||
| 198 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 199 | - this.totalCount - this.successCount -1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 200 | - } else if (dataResult == RESULT_ERROR_CONNECTION_FAILED) { | ||
| 201 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, 1, dataResult, 1); | ||
| 202 | - } | ||
| 203 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 204 | - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 205 | - } | ||
| 206 | - | ||
| 207 | - reportBtTransactionChr(result: number, resultCount: number, sceneCode: number, sceneCodeCount: number) { | ||
| 208 | - const options: commonEventManager.CommonEventPublishData = { | ||
| 209 | - code: 0, | ||
| 210 | - data: 'message', | ||
| 211 | - subscriberPermissions: ['ohos.permission.MANAGE_BLUETOOTH'], | ||
| 212 | - isOrdered: true, | ||
| 213 | - isSticky: false, | ||
| 214 | - parameters: { 'transactionType': btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, 'result': result, | ||
| 215 | - 'resultCount': resultCount, 'sceneCode': sceneCode, 'sceneCodeCount': sceneCodeCount} | ||
| 216 | - } | ||
| 217 | - commonEventManager.publish(BT_TRANSACTION_EVENT, options, (err) => { | ||
| 218 | - if (err) { | ||
| 219 | - console.info(TAG, 'get bt transaction event publish failed.' + JSON.stringify(err)); | ||
| 220 | - } else { | ||
| 221 | - console.info(TAG, 'get bt transaction event publish success.'); | ||
| 222 | - } | ||
| 223 | - }) | ||
| 224 | - } | ||
| 225 | - | ||
| 226 | unlinkFile() { | 153 | unlinkFile() { |
| 227 | try { | 154 | try { |
| 228 | this.tapEventIsAllowed = true; | 155 | this.tapEventIsAllowed = true; |
| @@ -304,9 +231,11 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 304 | clearTimeout(this.timerIdReceive); | 231 | clearTimeout(this.timerIdReceive); |
| 305 | this.transfering = false; | 232 | this.transfering = false; |
| 306 | this.oppProfile.setIncomingFileConfirmation(false, -1); | 233 | this.oppProfile.setIncomingFileConfirmation(false, -1); |
| 307 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | 234 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 235 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 308 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_2, this.totalCount); | 236 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_2, this.totalCount); |
| 309 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | 237 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 238 | + btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 310 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | 239 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); |
| 311 | this.pullUpReceiveResultNotification(); | 240 | this.pullUpReceiveResultNotification(); |
| 312 | this.handleTerminate(); | 241 | this.handleTerminate(); |
| @@ -318,9 +247,11 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 318 | clearTimeout(this.timerIdReceive); | 247 | clearTimeout(this.timerIdReceive); |
| 319 | this.transfering = false; | 248 | this.transfering = false; |
| 320 | this.oppProfile.setIncomingFileConfirmation(false, -1); | 249 | this.oppProfile.setIncomingFileConfirmation(false, -1); |
| 321 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | 250 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 251 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 322 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_5, this.totalCount); | 252 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_5, this.totalCount); |
| 323 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | 253 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 254 | + btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 324 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | 255 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); |
| 325 | this.tapEventIsAllowed = true; | 256 | this.tapEventIsAllowed = true; |
| 326 | this.handleTerminate(); | 257 | this.handleTerminate(); |
| @@ -354,9 +285,11 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 354 | clearTimeout(this.timerIdReceive); | 285 | clearTimeout(this.timerIdReceive); |
| 355 | this.transfering = false; | 286 | this.transfering = false; |
| 356 | this.oppProfile.setIncomingFileConfirmation(false, -1); | 287 | this.oppProfile.setIncomingFileConfirmation(false, -1); |
| 357 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | 288 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 289 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 358 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_5, this.totalCount); | 290 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_5, this.totalCount); |
| 359 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | 291 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE, |
| 292 | + btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 360 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | 293 | this.totalCount, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); |
| 361 | this.tapEventIsAllowed = true; | 294 | this.tapEventIsAllowed = true; |
| 362 | this.handleTerminate(); | 295 | this.handleTerminate(); |
| @@ -400,7 +333,8 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 400 | } else if (data.status == STATUS_FINISH) { | 333 | } else if (data.status == STATUS_FINISH) { |
| 401 | if (data.result != RESULT_SUCCESS_DISCONNECT) { | 334 | if (data.result != RESULT_SUCCESS_DISCONNECT) { |
| 402 | data.result == RESULT_SUCCESS ? this.successCount++ : this.failedCount++; | 335 | data.result == RESULT_SUCCESS ? this.successCount++ : this.failedCount++; |
| 403 | - this.reportBtChrDataByResult(data.result); | 336 | + CommonUtils.reportBtReceiveChrDataByResult(data.result, |
| 337 | + this.totalCount, this.successCount); | ||
| 404 | } | 338 | } |
| 405 | if (data.result != RESULT_SUCCESS && data.filePath != undefined && data.filePath.trim().length > 0) { | 339 | if (data.result != RESULT_SUCCESS && data.filePath != undefined && data.filePath.trim().length > 0) { |
| 406 | this.unlinkFile(); | 340 | this.unlinkFile(); |
| @@ -441,9 +375,15 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 441 | return; | 375 | return; |
| 442 | } | 376 | } |
| 443 | if (data.parameters.fileType == 'files') { | 377 | if (data.parameters.fileType == 'files') { |
| 378 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE_MEDIA_TYPE, | ||
| 379 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 380 | + 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_2, 1); | ||
| 444 | this.sandBoxUri = uri.path + '/' + this.fileName; | 381 | this.sandBoxUri = uri.path + '/' + this.fileName; |
| 445 | this.receiveDirectory = this.receiveDirectory + '/' + this.fileName; | 382 | this.receiveDirectory = this.receiveDirectory + '/' + this.fileName; |
| 446 | } else { | 383 | } else { |
| 384 | + CommonUtils.reportBtTransactionChr(btTransactionStatisticsType.TRANSACTION_TYPE_OPP_RECEIVE_MEDIA_TYPE, | ||
| 385 | + btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 386 | + 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_1, 1); | ||
| 447 | this.sandBoxUri = this.receiveDirectory; | 387 | this.sandBoxUri = this.receiveDirectory; |
| 448 | } | 388 | } |
| 449 | let file = fs.openSync(this.sandBoxUri, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); | 389 | let file = fs.openSync(this.sandBoxUri, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); |
| @@ -524,7 +464,8 @@ export default class BluetoothReceiveUIAbility extends UIAbility { | |||
| 524 | console.info(TAG, 'receive notification 50 seconds but no tap'); | 464 | console.info(TAG, 'receive notification 50 seconds but no tap'); |
| 525 | this.transfering = false; | 465 | this.transfering = false; |
| 526 | this.oppProfile.setIncomingFileConfirmation(false, -1); | 466 | this.oppProfile.setIncomingFileConfirmation(false, -1); |
| 527 | - this.reportBtChrDataByResult(RESULT_ERROR_NOT_ACCEPTABLE); | 467 | + CommonUtils.reportBtReceiveChrDataByResult(RESULT_ERROR_NOT_ACCEPTABLE, |
| 468 | + this.totalCount, this.successCount); | ||
| 528 | }, waitTime); | 469 | }, waitTime); |
| 529 | }).catch((err: Base.BusinessError) => { | 470 | }).catch((err: Base.BusinessError) => { |
| 530 | console.error(TAG, 'publishReceiveNotification fail'); | 471 | console.error(TAG, 'publishReceiveNotification fail'); |
| @@ -28,10 +28,11 @@ import fs from '@ohos.file.fs'; | |||
| 28 | import systemParameterEnhance from '@ohos.systemParameterEnhance'; | 28 | import systemParameterEnhance from '@ohos.systemParameterEnhance'; |
| 29 | import PermissionUtils from 'common/PermissionUtils'; | 29 | import PermissionUtils from 'common/PermissionUtils'; |
| 30 | import CommonUtils from 'common/CommonUtils'; | 30 | import CommonUtils from 'common/CommonUtils'; |
| 31 | +import { btTransactionStatisticsType, btTransactionStatisticsResult, | ||
| 32 | + btTransactionStatisticsSceneCode } from 'common/CommonUtils'; | ||
| 31 | 33 | ||
| 32 | const TAG: string = '[BT_SEND_SERVICE]==>' | 34 | const TAG: string = '[BT_SEND_SERVICE]==>' |
| 33 | const EVENT_TYPE_TRANSACTION: number = 6; | 35 | const EVENT_TYPE_TRANSACTION: number = 6; |
| 34 | -const BT_TRANSACTION_EVENT: string = 'usual.event.bluetooth.REPORT.TRANSACTION'; | ||
| 35 | 36 | ||
| 36 | const RESULT_SUCCESS: number = 0; | 37 | const RESULT_SUCCESS: number = 0; |
| 37 | const RESULT_ERROR_UNSUPPORTED_TYPE: number = 1; | 38 | const RESULT_ERROR_UNSUPPORTED_TYPE: number = 1; |
| @@ -47,37 +48,6 @@ const STATUS_PENDING: number = 0; | |||
| 47 | const STATUS_RUNNING: number = 1; | 48 | const STATUS_RUNNING: number = 1; |
| 48 | const STATUS_FINISH: number = 2; | 49 | const STATUS_FINISH: number = 2; |
| 49 | 50 | ||
| 50 | -const btTransactionStatisticsType = { | ||
| 51 | - TRANSACTION_TYPE_OPP_SEND : 1, | ||
| 52 | - TRANSACTION_TYPE_OPP_RECEIVE : 2, | ||
| 53 | -}; | ||
| 54 | - | ||
| 55 | -const btTransactionStatisticsResult = { | ||
| 56 | - TRANSACTION_RESULT_TOTAL : 1, | ||
| 57 | - TRANSACTION_RESULT_SUCCESS : 2, | ||
| 58 | - TRANSACTION_RESULT_FAIL : 3, | ||
| 59 | -}; | ||
| 60 | - | ||
| 61 | -const btTransactionStatisticsSceneCode = { | ||
| 62 | - TRANSACTION_SCENECODE_NA : 0, | ||
| 63 | - TRANSACTION_SCENECODE_1 : 1, | ||
| 64 | - TRANSACTION_SCENECODE_2 : 2, | ||
| 65 | - TRANSACTION_SCENECODE_3 : 3, | ||
| 66 | - TRANSACTION_SCENECODE_4 : 4, | ||
| 67 | - TRANSACTION_SCENECODE_5 : 5, | ||
| 68 | - TRANSACTION_SCENECODE_6 : 6, | ||
| 69 | - TRANSACTION_SCENECODE_7 : 7, | ||
| 70 | - TRANSACTION_SCENECODE_8 : 8, | ||
| 71 | - TRANSACTION_SCENECODE_9 : 9, | ||
| 72 | - TRANSACTION_SCENECODE_10 : 10, | ||
| 73 | - TRANSACTION_SCENECODE_11 : 11, | ||
| 74 | - TRANSACTION_SCENECODE_12 : 12, | ||
| 75 | - TRANSACTION_SCENECODE_13 : 13, | ||
| 76 | - TRANSACTION_SCENECODE_14 : 14, | ||
| 77 | - TRANSACTION_SCENECODE_15 : 15, | ||
| 78 | - TRANSACTION_SCENECODE_16 : 16, | ||
| 79 | -}; | ||
| 80 | - | ||
| 81 | export default class BluetoothSendUIAbility extends UIAbility { | 51 | export default class BluetoothSendUIAbility extends UIAbility { |
| 82 | private oppProfile = opp.createOppServerProfile(); | 52 | private oppProfile = opp.createOppServerProfile(); |
| 83 | private timeInterval: number = 0; | 53 | private timeInterval: number = 0; |
| @@ -107,7 +77,8 @@ export default class BluetoothSendUIAbility extends UIAbility { | |||
| 107 | console.info(TAG, 'BluetoothSendUIAbility onCreate'); | 77 | console.info(TAG, 'BluetoothSendUIAbility onCreate'); |
| 108 | this.timerIdCreate = setTimeout(() => { | 78 | this.timerIdCreate = setTimeout(() => { |
| 109 | console.info(TAG, 'onCreate 51 seconds but nothing received'); | 79 | console.info(TAG, 'onCreate 51 seconds but nothing received'); |
| 110 | - this.reportBtChrDataByResult(RESULT_ERROR_NO_MESSAGE); | 80 | + CommonUtils.reportBtSendChrDataByResult(RESULT_ERROR_NO_MESSAGE, |
| 81 | + this.totalCount, this.successCount); | ||
| 111 | this.handleTerminate(); | 82 | this.handleTerminate(); |
| 112 | }, (this.userReceiveTimeout + 1) * 1000); | 83 | }, (this.userReceiveTimeout + 1) * 1000); |
| 113 | this.timerIdCreated = true; | 84 | this.timerIdCreated = true; |
| @@ -134,48 +105,6 @@ export default class BluetoothSendUIAbility extends UIAbility { | |||
| 134 | this.context.terminateSelf(); | 105 | this.context.terminateSelf(); |
| 135 | } | 106 | } |
| 136 | 107 | ||
| 137 | - reportBtChrDataByResult(dataResult: number) { | ||
| 138 | - if (this.successCount + this.failedCount > this.totalCount) { | ||
| 139 | - return; | ||
| 140 | - } | ||
| 141 | - if (dataResult == RESULT_SUCCESS) { | ||
| 142 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_SUCCESS, | ||
| 143 | - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 144 | - } else if ((dataResult == RESULT_ERROR_UNSUPPORTED_TYPE || | ||
| 145 | - dataResult == RESULT_ERROR_BAD_REQUEST) && this.totalCount > 0) { | ||
| 146 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, | ||
| 147 | - this.totalCount, dataResult, this.totalCount); | ||
| 148 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 149 | - this.totalCount - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 150 | - } else if (dataResult == RESULT_ERROR_CANCELED || | ||
| 151 | - dataResult == RESULT_ERROR_TRANSFER_FAILED) { | ||
| 152 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, 1, dataResult, 1); | ||
| 153 | - } else { | ||
| 154 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_FAIL, 1, dataResult, 1); | ||
| 155 | - } | ||
| 156 | - this.reportBtTransactionChr(btTransactionStatisticsResult.TRANSACTION_RESULT_TOTAL, | ||
| 157 | - 1, btTransactionStatisticsSceneCode.TRANSACTION_SCENECODE_NA, 0); | ||
| 158 | - } | ||
| 159 | - | ||
| 160 | - reportBtTransactionChr(result: number, resultCount: number, sceneCode: number, sceneCodeCount: number) { | ||
| 161 | - const options: commonEventManager.CommonEventPublishData = { | ||
| 162 | - code: 0, | ||
| 163 | - data: 'message', | ||
| 164 | - subscriberPermissions: ['ohos.permission.MANAGE_BLUETOOTH'], | ||
| 165 | - isOrdered: true, | ||
| 166 | - isSticky: false, | ||
| 167 | - parameters: { 'transactionType': btTransactionStatisticsType.TRANSACTION_TYPE_OPP_SEND, 'result': result, | ||
| 168 | - 'resultCount': resultCount, 'sceneCode': sceneCode, 'sceneCodeCount': sceneCodeCount} | ||
| 169 | - } | ||
| 170 | - commonEventManager.publish(BT_TRANSACTION_EVENT, options, (err) => { | ||
| 171 | - if (err) { | ||
| 172 | - console.info(TAG, 'get bt transaction event publish failed.' + JSON.stringify(err)); | ||
| 173 | - } else { | ||
| 174 | - console.info(TAG, 'get bt transaction event publish success.'); | ||
| 175 | - } | ||
| 176 | - }) | ||
| 177 | - } | ||
| 178 | - | ||
| 179 | readyReceiveEvent() { | 108 | readyReceiveEvent() { |
| 180 | try { | 109 | try { |
| 181 | console.info(TAG, 'readyReceiveEvent'); | 110 | console.info(TAG, 'readyReceiveEvent'); |
| @@ -233,7 +162,8 @@ export default class BluetoothSendUIAbility extends UIAbility { | |||
| 233 | } else if (data.status == STATUS_FINISH && data.totalCount > 0) { | 162 | } else if (data.status == STATUS_FINISH && data.totalCount > 0) { |
| 234 | if (data.result != RESULT_SUCCESS_DISCONNECT) { | 163 | if (data.result != RESULT_SUCCESS_DISCONNECT) { |
| 235 | data.result == RESULT_SUCCESS ? this.successCount++ : this.failedCount++; | 164 | data.result == RESULT_SUCCESS ? this.successCount++ : this.failedCount++; |
| 236 | - this.reportBtChrDataByResult(data.result); | 165 | + CommonUtils.reportBtSendChrDataByResult(data.result, |
| 166 | + this.totalCount, this.successCount); | ||
| 237 | } | 167 | } |
| 238 | if (data.currentCount == data.totalCount || data.result == RESULT_ERROR_UNSUPPORTED_TYPE) { | 168 | if (data.currentCount == data.totalCount || data.result == RESULT_ERROR_UNSUPPORTED_TYPE) { |
| 239 | this.currentCount++; | 169 | this.currentCount++; |