18779efd5Sopenharmony_ci/**
28779efd5Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
38779efd5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48779efd5Sopenharmony_ci * you may not use this file except in compliance with the License.
58779efd5Sopenharmony_ci * You may obtain a copy of the License at
68779efd5Sopenharmony_ci *
78779efd5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88779efd5Sopenharmony_ci *
98779efd5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108779efd5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118779efd5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128779efd5Sopenharmony_ci * See the License for the specific language governing permissions and
138779efd5Sopenharmony_ci * limitations under the License.
148779efd5Sopenharmony_ci */
158779efd5Sopenharmony_ci
168779efd5Sopenharmony_ciimport { HiLog } from '../../../../../../common';
178779efd5Sopenharmony_ciimport commonEvent from '@ohos.commonEventManager';
188779efd5Sopenharmony_ciimport { PhoneNumber } from '../../../../../../feature/phonenumber';
198779efd5Sopenharmony_ci
208779efd5Sopenharmony_ciconst TAG = 'MissedCallManager'
218779efd5Sopenharmony_ci
228779efd5Sopenharmony_ciclass MissedCallManager {
238779efd5Sopenharmony_ci  requestMissedCallAction(action, data: any) {
248779efd5Sopenharmony_ci    if ('notification.event.message' == action) {
258779efd5Sopenharmony_ci      if (data && data.phoneNumber) {
268779efd5Sopenharmony_ci        PhoneNumber.fromString(data.phoneNumber).sendMessage();
278779efd5Sopenharmony_ci      }
288779efd5Sopenharmony_ci    }
298779efd5Sopenharmony_ci    HiLog.i(TAG, `requestMissedCallAction action: ${action}`);
308779efd5Sopenharmony_ci    this.cancelNotification(data);
318779efd5Sopenharmony_ci  }
328779efd5Sopenharmony_ci
338779efd5Sopenharmony_ci
348779efd5Sopenharmony_ci  cancelNotification(data?: any) {
358779efd5Sopenharmony_ci    commonEvent.publish('contact.event.CANCEL_MISSED', {
368779efd5Sopenharmony_ci      bundleName: 'com.ohos.contacts',
378779efd5Sopenharmony_ci      parameters: {
388779efd5Sopenharmony_ci        missedCallData: data
398779efd5Sopenharmony_ci      }
408779efd5Sopenharmony_ci    }, (err) => {
418779efd5Sopenharmony_ci      HiLog.w(TAG, JSON.stringify(err))
428779efd5Sopenharmony_ci    })
438779efd5Sopenharmony_ci  }
448779efd5Sopenharmony_ci}
458779efd5Sopenharmony_ci
468779efd5Sopenharmony_ciexport const missedCallManager: MissedCallManager = new MissedCallManager();