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 telephonySim from '@ohos.telephony.sim'; 178779efd5Sopenharmony_ciimport simCardState from './SimCardState' 188779efd5Sopenharmony_ciimport spn from './SimOpName' 198779efd5Sopenharmony_ciimport voLteState from './VoLteState' 208779efd5Sopenharmony_ci 218779efd5Sopenharmony_ciexport default class SimManager { 228779efd5Sopenharmony_ci supportSimCount: number = telephonySim.getMaxSimCount(); 238779efd5Sopenharmony_ci private onSimStateChange = () => { 248779efd5Sopenharmony_ci for (let index = 0; index < this.supportSimCount; index++) { 258779efd5Sopenharmony_ci if (simCardState.isSimReady(index)) { 268779efd5Sopenharmony_ci spn.initSimName(index); 278779efd5Sopenharmony_ci } else { 288779efd5Sopenharmony_ci spn.notifySimName(index, ''); 298779efd5Sopenharmony_ci } 308779efd5Sopenharmony_ci } 318779efd5Sopenharmony_ci } 328779efd5Sopenharmony_ci 338779efd5Sopenharmony_ci constructor() { 348779efd5Sopenharmony_ci if (this.supportSimCount > 1) { 358779efd5Sopenharmony_ci // support muti sim 368779efd5Sopenharmony_ci simCardState.setListener(this.onSimStateChange); 378779efd5Sopenharmony_ci } 388779efd5Sopenharmony_ci 398779efd5Sopenharmony_ci } 408779efd5Sopenharmony_ci 418779efd5Sopenharmony_ci init() { 428779efd5Sopenharmony_ci simCardState.init(); 438779efd5Sopenharmony_ci voLteState.init(); 448779efd5Sopenharmony_ci if (this.supportSimCount > 1) { 458779efd5Sopenharmony_ci // support muti sim 468779efd5Sopenharmony_ci spn.initSpnObserver(); 478779efd5Sopenharmony_ci } 488779efd5Sopenharmony_ci } 498779efd5Sopenharmony_ci 508779efd5Sopenharmony_ci /** 518779efd5Sopenharmony_ci * recycle 528779efd5Sopenharmony_ci */ 538779efd5Sopenharmony_ci public recycle() { 548779efd5Sopenharmony_ci if (this.supportSimCount > 1) { 558779efd5Sopenharmony_ci // support muti sim 568779efd5Sopenharmony_ci spn.unsubscribeSpnObserver(); 578779efd5Sopenharmony_ci } 588779efd5Sopenharmony_ci simCardState.removeSimChangeListener(); 598779efd5Sopenharmony_ci voLteState.removeVoLteListeners(); 608779efd5Sopenharmony_ci } 618779efd5Sopenharmony_ci}