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 telephonySim from '@ohos.telephony.sim';
17import simCardState from './SimCardState'
18import spn from './SimOpName'
19import voLteState from './VoLteState'
20
21export default class SimManager {
22  supportSimCount: number = telephonySim.getMaxSimCount();
23  private onSimStateChange = () => {
24    for (let index = 0; index < this.supportSimCount; index++) {
25      if (simCardState.isSimReady(index)) {
26        spn.initSimName(index);
27      } else {
28        spn.notifySimName(index, '');
29      }
30    }
31  }
32
33  constructor() {
34    if (this.supportSimCount > 1) {
35      // support muti sim
36      simCardState.setListener(this.onSimStateChange);
37    }
38
39  }
40
41  init() {
42    simCardState.init();
43    voLteState.init();
44    if (this.supportSimCount > 1) {
45      // support muti sim
46      spn.initSpnObserver();
47    }
48  }
49
50  /**
51   * recycle
52   */
53  public recycle() {
54    if (this.supportSimCount > 1) {
55      // support muti sim
56      spn.unsubscribeSpnObserver();
57    }
58    simCardState.removeSimChangeListener();
59    voLteState.removeVoLteListeners();
60  }
61}