• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 { paramMock } from "../utils"
17import { CardType, SimState } from "./ohos_telephony_sim"
18export const LockReason = {
19  SIM_NONE: "[PC Preview] unknow SIM_NONE",
20  SIM_PIN: "[PC Preview] unknow SIM_PIN",
21  SIM_PUK: "[PC Preview] unknow SIM_PUK",
22  SIM_PN_PIN: "[PC Preview] unknow SIM_PN_PIN",
23  SIM_PN_PUK: "[PC Preview] unknow SIM_PN_PUK",
24  SIM_PU_PIN: "[PC Preview] unknow SIM_PU_PIN",
25  SIM_PU_PUK: "[PC Preview] unknow SIM_PU_PUK",
26  SIM_PP_PIN: "[PC Preview] unknow SIM_PP_PIN",
27  SIM_PP_PUK: "[PC Preview] unknow SIM_PP_PUK",
28  SIM_PC_PIN: "[PC Preview] unknow SIM_PC_PIN",
29  SIM_PC_PUK: "[PC Preview] unknow SIM_PC_PUK",
30  SIM_SIM_PIN: "[PC Preview] unknow SIM_SIM_PIN",
31  SIM_SIM_PUK: "[PC Preview] unknow SIM_SIM_PUK",
32};
33export const SimStateData = {
34  type: CardType,
35  state: SimState,
36  reason: LockReason,
37}
38export function mockObserver() {
39  const observer = {
40    LockReason,
41    on: function (...args) {
42      console.warn("telephony.observer.on interface mocked in the Previewer. How this interface works on the Previewer may " +
43        "be different from that on a real device.")
44      const len = args.length
45      if (typeof args[len - 1] === 'function') {
46        if (args[0] === 'networkStateChange') {
47          args[len - 1].call(this, NetworkState);
48        } else if (args[0] === 'signalInfoChange') {
49          args[len - 1].call(this, [SignalInformation]);
50        } else if (args[0] === 'cellInfoChange') {
51          args[len - 1].call(this, [CellInformation]);
52        } else if (args[0] === 'cellularDataConnectionStateChange') {
53          args[len - 1].call(this, paramMock.businessErrorMock, {
54            state: "[PC Preview] unknow state",
55            network: "[PC Preview] unknow network"
56          });
57        } else if (args[0] === 'cellularDataFlowChange') {
58          args[len - 1].call(this, DataFlowType);
59        } else if (args[0] === 'callStateChange') {
60          args[len - 1].call(this, paramMock.businessErrorMock, {
61            state: "[PC Preview] unknow state",
62            number: "[PC Preview] unknow number"
63          });
64        } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') {
65          args[len - 1].call(this, paramMock.paramBooleanMock);
66        } else if (args[0] === 'simStateChange') {
67          args[len - 1].call(this, SimStateData);
68        }
69      }
70    },
71    off: function (...args) {
72      console.warn("telephony.observer.off interface mocked in the Previewer. How this interface works on the Previewer may " +
73        "be different from that on a real device.")
74      const len = args.length
75      if (typeof args[len - 1] === 'function') {
76        if (args[0] === 'networkStateChange') {
77          args[len - 1].call(this, NetworkState);
78        } else if (args[0] === 'signalInfoChange') {
79          args[len - 1].call(this, [SignalInformation]);
80        } else if (args[0] === 'cellInfoChange') {
81          args[len - 1].call(this, [CellInformation]);
82        } else if (args[0] === 'cellularDataConnectionStateChange') {
83          args[len - 1].call(this, paramMock.businessErrorMock, {
84            state: "[PC Preview] unknow state",
85            network: "[PC Preview] unknow network"
86          });
87        } else if (args[0] === 'cellularDataFlowChange') {
88          args[len - 1].call(this, DataFlowType);
89        } else if (args[0] === 'callStateChange') {
90          args[len - 1].call(this, paramMock.businessErrorMock, {
91            state: "[PC Preview] unknow state",
92            number: "[PC Preview] unknow number"
93          });
94        } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') {
95          args[len - 1].call(this, paramMock.paramBooleanMock);
96        } else if (args[0] === 'simStateChange') {
97          args[len - 1].call(this, SimStateData);
98        }
99      }
100    },
101    once: function (...args) {
102      console.warn("telephony.observer.once interface mocked in the Previewer. How this interface works on the Previewer may " +
103        "be different from that on a real device.")
104      const len = args.length
105      if (typeof args[len - 1] === 'function') {
106        if (args[0] === 'networkStateChange') {
107          args[len - 1].call(this, NetworkState);
108        } else if (args[0] === 'signalInfoChange') {
109          args[len - 1].call(this, [SignalInformation]);
110        } else if (args[0] === 'cellInfoChange') {
111          args[len - 1].call(this, [CellInformation]);
112        } else if (args[0] === 'cellularDataConnectionStateChange') {
113          args[len - 1].call(this, paramMock.businessErrorMock, {
114            state: "[PC Preview] unknow state",
115            network: "[PC Preview] unknow network"
116          });
117        } else if (args[0] === 'cellularDataFlowChange') {
118          args[len - 1].call(this, DataFlowType);
119        } else if (args[0] === 'callStateChange') {
120          args[len - 1].call(this, paramMock.businessErrorMock, {
121            state: "[PC Preview] unknow state",
122            number: "[PC Preview] unknow number"
123          });
124        } else if (args[0] === 'cfuIndicatorChange' || 'voiceMailMsgIndicatorChange') {
125          args[len - 1].call(this, paramMock.paramBooleanMock);
126        } else if (args[0] === 'simStateChange') {
127          args[len - 1].call(this, SimStateData);
128        }
129      }
130    }
131  }
132  return observer
133}