• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import commonEvent from "@ohos.commonEventManager";
16import common from "../data/commonData";
17import mmsTable from "../data/tableData";
18import telephoneUtils from "../utils/TelephoneUtil";
19import HiLog from "../utils/HiLog";
20import particleAbility from "@ohos.ability.particleAbility";
21import MmsDatabaseHelper from "../utils/MmsDatabaseHelper";
22import ohosDataAbility from "@ohos.data.dataAbility";
23import telSim from "@ohos.telephony.sms";
24import ohosDataRdb from "@ohos.data.rdb";
25import commonService from "../service/CommonService";
26import http from "@ohos.net.http";
27import NotificationService from "../service/NotificationService";
28import LooseObject from "../data/LooseObject"
29import dataShare from "@ohos.data.dataShare";
30import dataSharePredicates from "@ohos.data.dataSharePredicates";
31import messageService from "../service/ConversationListService";
32
33
34const TAG = 'MmsStaticSubscriber'
35// database instance object
36var rdbStore = undefined;
37
38var StaticSubscriberExtensionAbility = globalThis.requireNapi('application.StaticSubscriberExtensionAbility');
39
40export default class MmsStaticSubscriber extends StaticSubscriberExtensionAbility {
41    onReceiveEvent(data) {
42        HiLog.i(TAG, 'onRecevieEvent, event:' );
43        // Initializing the Database
44        this.initRdb(data)
45
46    }
47
48    async dealSmsReceiveData(data) {
49        let netType = data.parameters.isCdma ? "3gpp2" : "3gpp";
50        // Synchronize wait operation
51        let promisesAll = [];
52        data.parameters.pdus.forEach(pdu => {
53            let promise = telSim.createMessage(this.convertStrArray(pdu), netType);
54            promisesAll.push(promise);
55        });
56
57        let result: LooseObject = {};
58        let createMessagePromise = Promise.all(promisesAll)
59        createMessagePromise.then((shortMsgList) => {
60            result.code = common.int.SUCCESS;
61            result.telephone = telephoneUtils.formatTelephone(shortMsgList[0].visibleRawAddress);
62            result.content = '';
63            shortMsgList.forEach(shortMessage => {
64                result.content += shortMessage.visibleMessageBody;
65            })
66        }).catch((err) => {
67            HiLog.e(TAG, "dealSmsReceiveData, err: " + JSON.stringify(err.message));
68            result.code = common.int.FAILURE;
69        });
70        await createMessagePromise;
71        let actionData = {
72            slotId: data.parameters.slotId,
73            telephone: result.telephone,
74            content: result.content,
75            isMms: false,
76            mmsSource: []
77        }
78        this.insertMessageDetailBy(actionData, res => {
79            this.sendNotification(result.telephone, res.initDatas[0].id, result.content);
80            this.publishData(result.telephone, result.content);
81        });
82    }
83
84    dealMmsReceiveData(data) {
85        let result = JSON.parse(data.data);
86        this.saveAttachment(result.mmsSource);
87        let content = commonService.getMmsContent(result.mmsSource);
88        let actionData: LooseObject = {};
89        actionData.telephone = result.telephone;
90        actionData.content = content;
91        actionData.isMms = true;
92        actionData.mmsSource = result.mmsSource;
93        actionData.slotId = data.parameters.slotId;
94        this.insertMessageDetailBy(actionData, res => {
95            let notificationContent = this.getNotificationContent(result.mmsSource, content);
96            this.sendNotification(result.telephone, res.initDatas[0].id, notificationContent);
97            this.publishData(result.telephone, result.content);
98        });
99    }
100
101    saveAttachment(mmsSource) {
102        for (let item of mmsSource) {
103            let baseUrl = item.msgUriPath;
104            let httpRequest = http.createHttp();
105            httpRequest.request(common.string.MMS_URL,
106                {
107                    method: http.RequestMethod.GET,
108                    header: {
109                        "Content-Type": "application/json",
110                    },
111                    extraData: baseUrl,
112                    readTimeout: 50000,
113                    connectTimeout: 50000
114                }, (err, data) => {
115                    HiLog.i(TAG, "saveAttachment, err: " + JSON.stringify(err.message));
116                }
117            );
118        }
119    }
120
121    getNotificationContent(mmsSource, themeContent) {
122        let content = common.string.EMPTY_STR;
123        if (mmsSource.length === 1) {
124            let item = mmsSource[0];
125            switch (item.msgType) {
126            // Subject
127                case 0:
128                    content = themeContent;
129                    break;
130            // Pictures
131                case 1:
132                    content = "(picture)" + themeContent;
133                    break;
134            // Video
135                case 2:
136                    content = "(video)" + themeContent;
137                    break;
138            // Audio
139                case 3:
140                    content = "(audio)" + themeContent;
141                    break;
142            }
143        } else {
144            content = "(slide)" + mmsSource[0].content;
145        }
146        return content;
147    }
148
149    // Insert Received Data
150    insertMessageDetailBy(param, callback) {
151        let sendResults = [];
152        let sendResult = {
153            slotId: param.slotId,
154            telephone: param.telephone,
155            content: param.content,
156            sendStatus: 0
157        }
158        sendResults.push(sendResult);
159        let hasAttachment = commonService.judgeIsAttachment(param.mmsSource);
160        let actionData: LooseObject = {};
161        actionData.slotId = param.slotId;
162        actionData.sendResults = sendResults;
163        actionData.isReceive = true;
164        actionData.ownNumber = common.string.EMPTY_STR;
165        actionData.isSender = true;
166        actionData.isMms = param.isMms;
167        actionData.mmsSource = param.mmsSource;
168        actionData.hasAttachment = hasAttachment;
169        this.insertSessionAndDetail(actionData, callback);
170    }
171
172    convertStrArray(sourceStr) {
173        let wby = sourceStr;
174        let length = wby.length;
175        let isDouble = (length % 2) == 0;
176        let halfSize = parseInt('' + length / 2);
177        HiLog.i(TAG, "convertStrArray, length=" + length + ", isDouble=" + isDouble);
178        if (isDouble) {
179            let number0xArray = new Array(halfSize);
180            for (let i = 0;i < halfSize; i++) {
181                number0xArray[i] = "0x" + wby.substr(i * 2, 2);
182            }
183            let numberArray = new Array(halfSize);
184            for (let i = 0;i < halfSize; i++) {
185                numberArray[i] = parseInt(number0xArray[i], 16);
186            }
187            return numberArray;
188        } else {
189            let number0xArray = new Array(halfSize + 1);
190            for (let i = 0;i < halfSize; i++) {
191                number0xArray[i] = "0x" + wby.substr(i * 2, 2);
192            }
193            number0xArray[halfSize] = "0x" + wby.substr((halfSize * 2) + 1, 1);
194            let numberArray = new Array(halfSize + 1);
195            for (let i = 0;i < halfSize; i++) {
196                numberArray[i] = parseInt(number0xArray[i], 16);
197            }
198            let last0x = "0x" + wby.substr(wby.length - 1, 1);
199            numberArray[halfSize] = parseInt(last0x);
200            return numberArray;
201        }
202    }
203
204    // Initializing the Database
205    async initRdb(data) {
206        HiLog.i(TAG, "initRdb, createRdbStore start: " );
207        // Creating a Database
208        rdbStore = await ohosDataRdb.getRdbStore(globalThis.AbilityStageConstant,
209            { name: mmsTable.DB.MMSSMS.config.name }, mmsTable.DB.MMSSMS.version);
210        // Creating Database Tables
211        await rdbStore.executeSql(mmsTable.table.session, null);
212
213        if (data.event === common.string.SUBSCRIBER_EVENT) {
214            this.dealSmsReceiveData(data);
215        } else {
216            // MMS message receiving
217            this.dealMmsReceiveData(data);
218        }
219
220    }
221
222    insertSessionAndDetail(actionData, callback) {
223        let sendResults = actionData.sendResults;
224        let isReceive = actionData.isReceive;
225        if (sendResults.length == 0) {
226            return;
227        }
228        let value = this.dealSendResults(sendResults);
229
230        // Check whether a session list has been created.
231        this.querySessionByTelephone(value.telephone, res => {
232            HiLog.i(TAG, " insertSessionAndDetail, querySessionByTelephone code=" + res.code);
233            let response = res.response;
234            HiLog.i(TAG, " insertSessionAndDetail, querySessionByTelephone response.id=" + response.id);
235            if (res.code == common.int.SUCCESS && response.id <= 0) {
236                this.insertNoExitingSession(isReceive, value, actionData, callback);
237            } else {
238                this.insertExitingSession(response, value, actionData, callback);
239            }
240        });
241    }
242
243    insertNoExitingSession(isReceive, value, actionData, callback) {
244        let unreadCount = 0;
245        if (isReceive) {
246            unreadCount = 1;
247        }
248        let valueBucket = {
249            "telephone": value.telephone,
250            "content": value.content,
251            "contacts_num": value.contractsNum,
252            "sms_type": value.smsType,
253            "unread_count": unreadCount,
254            "sending_status": value.sendStatus,
255            "has_draft": 0,
256            "time": value.timestamp,
257            "message_count": 1,
258            "has_mms": actionData.isMms ? 1 : 0,
259            "has_attachment": actionData.hasAttachment ? 1 : 0
260        }
261        this.insertSession(valueBucket, res => {
262            // Invoke the SMS database to insert SMS messages.
263            this.dealInsertMessageDetail(value, actionData, res.rowId, initDatas => {
264                let result = {
265                    rowId: res.rowId,
266                    initDatas: initDatas
267                }
268                callback(result);
269            });
270        });
271    }
272
273    insertExitingSession(response, param, actionData, callback) {
274        let sessionId = response.id;
275        // Invoke the SMS database to insert SMS messages.
276        let threadIds = [sessionId];
277        let time = new Date();
278        let unreadCount = 0;
279        if (actionData.isReceive) {
280            unreadCount = response.unreadCount;
281            unreadCount = unreadCount + 1;
282        }
283        let messageCount = response.messageCount;
284        messageCount = messageCount + 1;
285        let valueBucket = {
286            "content": param.content,
287            "unread_count": unreadCount,
288            "time": time.getTime(),
289            "sending_status": param.sendStatus,
290            "message_count": messageCount,
291            "has_mms": actionData.isMms ? 1 : 0,
292            "has_draft": 0,
293            "has_attachment": actionData.hasAttachment ? 1 : 0
294        };
295        this.updateById(threadIds, valueBucket, res => {
296            // Invoke the SMS database to insert SMS messages.
297            this.dealInsertMessageDetail(param, actionData, sessionId, initDatas => {
298                let result = {
299                    rowId: sessionId,
300                    initDatas: initDatas
301                }
302                callback(result);
303            });
304        });
305    }
306
307    querySessionByTelephone(telephone, callback) {
308        let result: LooseObject = {};
309        let queryPromise = this.querySessionByTelephoneRdb(telephone);
310        Promise.all([queryPromise]).then((res) => {
311            result.code = common.int.SUCCESS;
312            result.response = res[0];
313            callback(result);
314        }).catch((err) => {
315            HiLog.e(TAG, "querySessionByTelephone, error: " + JSON.stringify(err.message));
316            result.code = common.int.FAILURE;
317            callback(result);
318        });
319    }
320
321    // Obtains the session list based on the mobile number.
322    async querySessionByTelephoneRdb(telephone) {
323        // Creating a query condition object
324        let predicates = new ohosDataRdb.RdbPredicates(MmsDatabaseHelper.TABLE.SESSION);
325        // If this parameter is left blank, all list data is queried.
326        if (telephone) {
327            await predicates.equalTo(mmsTable.sessionField.telephone, telephone);
328        }
329        // Obtain the result set.
330        let resultSet = await rdbStore.query(predicates);
331        // Obtain the first entry.
332        resultSet.goToFirstRow();
333        let result: LooseObject = {};
334        result.id = await Number(resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.id)));
335        result.time = await Number(resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.time)));
336        result.telephone = await resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.telephone));
337        result.content = await resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.content));
338        result.contactsNum =
339            await Number(resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.contactsNum)));
340        result.smsType = await Number(resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.smsType)));
341        result.unreadCount =
342            await Number(resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.unreadCount)));
343        result.sendStatus =
344            await Number(resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.sendStatus)));
345        result.hasDraft = await Number(resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.hasDraft)));
346        result.messageCount =
347            await Number(resultSet.getString(resultSet.getColumnIndex(mmsTable.sessionField.messageCount)));
348        return result;
349    }
350
351    // insert
352    insertSession(valueBucket, callback) {
353        this.insertSessionRdb(valueBucket, callback);
354    }
355
356    insertSessionRdb(valueBucket, callback) {
357        HiLog.i(TAG, "insert session rdb 123");
358        let insertPromise = rdbStore.insert(MmsDatabaseHelper.TABLE.SESSION, valueBucket);
359        let result: LooseObject = {};
360        insertPromise.then((ret) => {
361            HiLog.i(TAG, "insert session rdb rowId: " + ret);
362            result.code = common.int.SUCCESS;
363            result.rowId = ret;
364            callback(result);
365        }).catch((err) => {
366            HiLog.e(TAG, "insert session rdb error: " + JSON.stringify(err.message));
367            result.code = common.int.FAILURE;
368            callback(result);
369        });
370    }
371
372    /**
373     * New data
374     */
375    async insert(tableName, valueBucket) {
376        let promise = await rdbStore.insert(tableName, valueBucket);
377        let rowId = 0;
378        promise.then((ret) => {
379            rowId = ret;
380            HiLog.i(TAG, "insert, first success: " + rowId);
381        }).catch((err) => {
382            HiLog.e(TAG, "insert, err: " + JSON.stringify(err.message));
383        })
384        await promise;
385        return rowId;
386    }
387
388    dealInsertMessageDetail(param, actionData, threadId, callback) {
389        // Get the largest groupId
390        this.queryMaxGroupId(actionData, res => {
391            let maxGroupId = res == common.string.EMPTY_STR ? 0 : parseInt(res);
392            maxGroupId = maxGroupId + 1;
393            this.insertMessageDetailByGroupId(param, threadId, maxGroupId, actionData, callback);
394        });
395    }
396
397    insertMessageDetailByGroupId(param, threadId, maxGroupId, actionData, callback) {
398        let initDatas = [];
399        let count = 0;
400        let sendResults = actionData.sendResults;
401        sendResults.forEach(sendResult => {
402            let insertDetail = {
403                slotId: actionData.slotId,
404                receiverNumber: common.string.EMPTY_STR,
405                senderNumber: common.string.EMPTY_STR,
406                smsType: param.smsType,
407                content: param.content,
408                sendStatus: 0,
409                sessionType: 0,
410                threadId: threadId,
411                isSender: actionData.isSender,
412                groupId: maxGroupId,
413                mmsSource: actionData.mmsSource,
414                isMms: actionData.isMms,
415                isRead: -1
416            };
417            if (actionData.isReceive) {
418                insertDetail.receiverNumber = actionData.ownNumber;
419                insertDetail.senderNumber = sendResult.telephone;
420                insertDetail.isRead = 0;
421            }
422            this.insertMessageDetail(insertDetail, result => {
423                count++;
424                HiLog.i(TAG, "insertMessageDetailByGroupId, result: " + result);
425                let initData = {
426                    id: result,
427                    telephone: sendResult.telephone
428                };
429                initDatas.push(initData);
430                if (count == sendResults.length) {
431                    callback(initDatas);
432                }
433            });
434        })
435    }
436
437    dealSendResults(sendResults) {
438        let contractsNum = sendResults.length;
439        let telephone = common.string.EMPTY_STR;
440        let content = common.string.EMPTY_STR;
441        // Sending succeeded.
442        let sendStatus = 0;
443        for (let sendResult of sendResults) {
444            telephone = telephone + sendResult.telephone + common.string.COMMA;
445            content = sendResult.content;
446            sendStatus = sendResult.sendStatus;
447        }
448        telephone = telephone.substring(0, telephone.length - 1);
449        let smsType = 0;
450        if (contractsNum == 1 && telephoneUtils.judgeIsInfoMsg(telephone)) {
451            smsType = 1;
452        }
453        let timestamp = new Date().getTime();
454        let result: LooseObject = {};
455        result.contractsNum = contractsNum;
456        result.telephone = telephoneUtils.dealTelephoneSort(telephone);
457        result.content = content;
458        result.sendStatus = sendStatus;
459        result.smsType = smsType;
460        result.timestamp = timestamp;
461        return result;
462    }
463
464    insertMessageDetail(value, callback) {
465        let actionData: LooseObject = {};
466        let time = new Date();
467        let timeStr = time.getTime() + common.string.EMPTY_STR;
468        var stringValue = {
469            "slot_id": common.int.SIM_ONE,
470            "receiver_number": value.receiverNumber,
471            "sender_number": value.senderNumber,
472            "start_time": timeStr,
473            "end_time": timeStr,
474            "msg_type": value.isMms ? "1" : "0",
475            "sms_type": value.smsType,
476            "msg_title": value.content,
477            "msg_content": value.content,
478            "msg_state": value.sendStatus,
479            "operator_service_number": common.string.EMPTY_STR,
480            "msg_code": common.string.EMPTY_STR,
481            "session_id": value.threadId,
482            "is_lock": "0",
483            "is_read": value.isRead,
484            "is_collect": "0",
485            "session_type": value.sessionType,
486            "is_subsection": "0",
487            "is_sender": value.isSender,
488            "is_send_report": 0,
489            "group_id": value.groupId
490        };
491        if (value.slotId != null) {
492            stringValue.slot_id = value.slotId;
493        }
494        actionData.stringValue = stringValue;
495        this.insertMessageDetailRdb(actionData, msgId => {
496            HiLog.i(TAG, "insertMessageDetail, msgId: " + msgId);
497            if (value.isMms) {
498                value.msgId = msgId;
499                this.batchInsertMmsPart(value);
500            }
501            callback(msgId);
502        });
503    }
504
505    batchInsertMmsPart(value) {
506        let bacthmsParts = [];
507        for (let source of value.mmsSource) {
508            let stringValue = {
509                "msg_id": value.msgId,
510                "group_id": value.groupId,
511                "type": source.msgType,
512                "location_path": source.msgUriPath,
513                "content": source.content,
514                "recording_time": source.time,
515                "part_size": source.fileSize
516            };
517            bacthmsParts.push(stringValue);
518        }
519        for (let stringValue of bacthmsParts) {
520            this.insertMmsPart(stringValue);
521        }
522    }
523
524    async insertMmsPart(stringValue) {
525        let dataAbilityHelper = await particleAbility.acquireDataAbilityHelper(this.context, common.string.URI_MESSAGE_LOG);
526        let managerUri = common.string.URI_MESSAGE_LOG + common.string.URI_MESSAGE_MMS_PART;
527        dataAbilityHelper.insert(managerUri, stringValue).then(data => {
528        }).catch(error => {
529            HiLog.e(TAG, "insertMmsPart, fail: " + JSON.stringify(error.meaasge));
530        });
531    }
532
533    // Inserting a single SMS message
534    async insertMessageDetailRdb(actionData, callback) {
535        // Obtains the DataAbilityHelper object.
536        let managerUri = common.string.URI_MESSAGE_LOG + common.string.URI_MESSAGE_INFO_TABLE;
537        let dataAbilityHelper = await particleAbility.acquireDataAbilityHelper(this.context, common.string.URI_MESSAGE_LOG);
538        let promise = dataAbilityHelper.insert(managerUri, actionData.stringValue);
539        await promise.then(data => {
540            callback(data);
541        }).catch(error => {
542            HiLog.e(TAG, "insertMessageDetailRdb, fail: " + JSON.stringify(error.message));
543        });
544    }
545
546    /**
547     * Update data based on the primary key ID.
548     * @param threadIds Session ID
549     * @return
550     */
551    async updateById(threadIds, valueBucket, callback) {
552        HiLog.i(TAG, "updateById, threadIds: " + JSON.stringify(threadIds));
553        if (threadIds.length != 0) {
554            for (let threadId of threadIds) {
555                // Creating a query condition object
556                let predicates = new ohosDataRdb.RdbPredicates(MmsDatabaseHelper.TABLE.SESSION);
557                await predicates.equalTo(mmsTable.sessionField.id, threadId);
558                this.update(predicates, valueBucket, res => {
559                    callback(res);
560                });
561            }
562
563        }
564    }
565
566    /**
567     * Update Interface
568     * @param predicates Update Condition
569     * @param predicates Update Value
570     * @return
571     */
572    async update(predicates, valueBucket, callback) {
573        let changedRows = await rdbStore.update(valueBucket, predicates);
574        callback(changedRows);
575    }
576
577    /**
578     * Query the maximum group ID.
579     * @param actionData
580     * @param callBack
581     * @return
582     */
583    queryMaxGroupId(actionData, callBack) {
584        this.queryMaxGroupIdDb(actionData, res => {
585            HiLog.i(TAG, "queryMaxGroupId, callback");
586            callBack(res.maxGroupId);
587        });
588    }
589
590    // Get the largest groupId
591    async queryMaxGroupIdDb(actionData, callback) {
592        let dataAbilityHelper = await particleAbility.acquireDataAbilityHelper(this.context, common.string.URI_MESSAGE_LOG);
593        let resultColumns = [
594            "maxGroupId"
595        ];
596        let condition = new ohosDataAbility.DataAbilityPredicates();
597        let managerUri = common.string.URI_MESSAGE_LOG + common.string.URI_MESSAGE_MAX_GROUP;
598        dataAbilityHelper.query(managerUri, resultColumns, condition).then( resultSet => {
599            let result: LooseObject = {};
600            if (resultSet != undefined) {
601                if (resultSet.goToLastRow()) {
602                    result.maxGroupId = resultSet.getString(0);
603                }
604            }
605            callback(result);
606        }).catch(error => {
607            HiLog.e(TAG, "queryMaxGroupIdDb, error: " + JSON.stringify(error.message));
608        });
609    }
610
611    /**
612     * commonEvent publish data
613     */
614    publishData(telephone, content) {
615        HiLog.i(TAG, "publishData, start");
616        let actionData = {
617            telephone: telephone,
618            content: content
619        };
620        commonEvent.publish(common.string.RECEIVE_TRANSMIT_EVENT, {
621            bundleName: common.string.BUNDLE_NAME,
622            subscriberPermissions: ['ohos.permission.RECEIVE_SMS'],
623            isOrdered: false,
624            data: JSON.stringify(actionData)
625        }, (res) => {
626        });
627    }
628
629    async sendNotification(telephone, msgId, content) {
630        let telephones = [telephone];
631        this.queryContactDataByTelephone(telephones, async (contracts) => {
632            HiLog.i(TAG, "sendNotification, callback");
633            let actionData = this.dealContactParams(contracts, telephone);
634            if (content.length > 15) {
635                content = content.substring(0, 15) + "...";
636            }
637            let title = telephone;
638            if(contracts.length > 0) {
639                title = contracts[0].displayName
640            }
641            let message = {
642                title: title,
643                text: content,
644            };
645            actionData.message = message;
646            actionData.msgId = msgId;
647            actionData.unreadTotal = 0;
648            let params: LooseObject = {
649                mmsContext: this.context
650            };
651            messageService.statisticalData(params, function (res) {
652                if (res.code == common.int.SUCCESS) {
653                    actionData.unreadTotal= res.response.totalListCount;
654                    HiLog.i(TAG, "sendNotification, callback actionData");
655                }
656                NotificationService.getInstance().sendNotify(actionData);
657            });
658        });
659    }
660
661    dealContactParams(contracts, telephone) {
662        let actionData: LooseObject = {};
663        let params = [];
664        if (contracts.length == 0) {
665            params.push({
666                telephone: telephone,
667            });
668        } else {
669            let contact = contracts[0];
670            params.push({
671                contactsName: contact.displayName,
672                telephone: telephone,
673                telephoneFormat: contact.detailInfo,
674            });
675        }
676        actionData.contactObjects = JSON.stringify(params);
677        return actionData;
678    }
679
680    async queryContactDataByTelephone(telephones, callback) {
681        let resultColumns = [
682            mmsTable.contactDataColumns.detailInfo,
683            mmsTable.contactDataColumns.displayName,
684        ];
685        let contactDataAbilityHelper =
686            await particleAbility.acquireDataAbilityHelper(this.context, common.string.URI_ROW_CONTACTS);
687        let condition = new ohosDataAbility.DataAbilityPredicates();
688        let contactDataUri = common.string.URI_ROW_CONTACTS + common.string.CONTACT_DATA_URI;
689        condition.in(mmsTable.contactDataColumns.detailInfo, telephones);
690        condition.and();
691        condition.equalTo(mmsTable.contactDataColumns.typeId, "5");
692        contactDataAbilityHelper.query(contactDataUri, resultColumns, condition).then(resultSet => {
693            let contracts = [];
694            if (resultSet != undefined) {
695                while (resultSet.goToNextRow()) {
696                    let contract = {
697                        detailInfo: resultSet.getString(0),
698                        displayName: resultSet.getString(1)
699                    };
700                    contracts.push(contract);
701                }
702            }
703            callback(contracts);
704        }).catch(error => {
705            HiLog.e(TAG, "queryContactDataByTelephone error: " + JSON.stringify(error.message));
706        });
707    }
708
709
710}
711