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 */
15
16import { HiLog } from '../../../../../../common';
17import commonEvent from '@ohos.commonEventManager';
18import { PhoneNumber } from '../../../../../../feature/phonenumber';
19
20const TAG = 'MissedCallManager'
21
22class MissedCallManager {
23  requestMissedCallAction(action, data: any) {
24    if ('notification.event.message' == action) {
25      if (data && data.phoneNumber) {
26        PhoneNumber.fromString(data.phoneNumber).sendMessage();
27      }
28    }
29    HiLog.i(TAG, `requestMissedCallAction action: ${action}`);
30    this.cancelNotification(data);
31  }
32
33
34  cancelNotification(data?: any) {
35    commonEvent.publish('contact.event.CANCEL_MISSED', {
36      bundleName: 'com.ohos.contacts',
37      parameters: {
38        missedCallData: data
39      }
40    }, (err) => {
41      HiLog.w(TAG, JSON.stringify(err))
42    })
43  }
44}
45
46export const missedCallManager: MissedCallManager = new MissedCallManager();