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" 17export const DataFlowType = { 18 DATA_FLOW_TYPE_NONE: 0, 19 DATA_FLOW_TYPE_DOWN: 1, 20 DATA_FLOW_TYPE_UP: 2, 21 DATA_FLOW_TYPE_UP_DOWN: 3, 22 DATA_FLOW_TYPE_DORMANT: 4, 23}; 24export const DataConnectState = { 25 DATA_STATE_UNKNOWN: -1, 26 DATA_STATE_DISCONNECTED: 0, 27 DATA_STATE_CONNECTING: 1, 28 DATA_STATE_CONNECTED: 2, 29 DATA_STATE_SUSPENDED: 3, 30}; 31export function mockData() { 32 const data = { 33 DataFlowType, 34 DataConnectState, 35 getDefaultCellularDataSlotId: function (...args) { 36 console.warn("telephony.data.getDefaultCellularDataSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + 37 " be different from that on a real device.") 38 const len = args.length 39 if (typeof args[len - 1] === 'function') { 40 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 41 } else { 42 return new Promise((resolve, reject) => { 43 resolve(paramMock.paramNumberMock); 44 }) 45 } 46 }, 47 setDefaultCellularDataSlotId: function (...args) { 48 console.warn("telephony.data.setDefaultCellularDataSlotId interface mocked in the Previewer. How this interface works on the Previewer may" + 49 " be different from that on a real device.") 50 const len = args.length 51 if (typeof args[len - 1] === 'function') { 52 args[len - 1].call(this, paramMock.businessErrorMock); 53 } else { 54 return new Promise((resolve, reject) => { 55 resolve(); 56 }) 57 } 58 }, 59 getCellularDataFlowType: function (...args) { 60 console.warn("telephony.data.getCellularDataFlowType interface mocked in the Previewer. How this interface works on the Previewer may" + 61 " be different from that on a real device.") 62 const len = args.length 63 if (typeof args[len - 1] === 'function') { 64 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 65 } else { 66 return new Promise((resolve, reject) => { 67 resolve(paramMock.paramNumberMock); 68 }) 69 } 70 }, 71 getCellularDataState: function (...args) { 72 console.warn("telephony.data.getCellularDataState 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 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 77 } else { 78 return new Promise((resolve, reject) => { 79 resolve(paramMock.paramNumberMock); 80 }) 81 } 82 }, 83 isCellularDataEnabled: function (...args) { 84 console.warn("telephony.data.isCellularDataEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + 85 " be different from that on a real device.") 86 const len = args.length 87 if (typeof args[len - 1] === 'function') { 88 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 89 } else { 90 return new Promise((resolve, reject) => { 91 resolve(paramMock.paramBooleanMock); 92 }) 93 } 94 }, 95 enableCellularData: function (...args) { 96 console.warn("telephony.data.enableCellularData interface mocked in the Previewer. How this interface works on the Previewer may" + 97 " be different from that on a real device.") 98 const len = args.length 99 if (typeof args[len - 1] === 'function') { 100 args[len - 1].call(this, paramMock.businessErrorMock); 101 } else { 102 return new Promise((resolve, reject) => { 103 resolve(); 104 }) 105 } 106 }, 107 disableCellularData: function (...args) { 108 console.warn("telephony.data.disableCellularData interface mocked in the Previewer. How this interface works on the Previewer may" + 109 " be different from that on a real device.") 110 const len = args.length 111 if (typeof args[len - 1] === 'function') { 112 args[len - 1].call(this, paramMock.businessErrorMock); 113 } else { 114 return new Promise((resolve, reject) => { 115 resolve(); 116 }) 117 } 118 }, 119 isCellularDataRoamingEnabled: function (...args) { 120 console.warn("telephony.data.isCellularDataRoamingEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + 121 " be different from that on a real device.") 122 const len = args.length 123 if (typeof args[len - 1] === 'function') { 124 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 125 } else { 126 return new Promise((resolve, reject) => { 127 resolve(paramMock.paramBooleanMock); 128 }) 129 } 130 }, 131 enableCellularDataRoaming: function (...args) { 132 console.warn("telephony.data.enableCellularDataRoaming interface mocked in the Previewer. How this interface works on the Previewer may" + 133 " be different from that on a real device.") 134 const len = args.length 135 if (typeof args[len - 1] === 'function') { 136 args[len - 1].call(this, paramMock.businessErrorMock); 137 } else { 138 return new Promise((resolve, reject) => { 139 resolve(); 140 }) 141 } 142 }, 143 disableCellularDataRoaming: function (...args) { 144 console.warn("telephony.data.disableCellularDataRoaming interface mocked in the Previewer. How this interface works on the Previewer may" + 145 " be different from that on a real device.") 146 const len = args.length 147 if (typeof args[len - 1] === 'function') { 148 args[len - 1].call(this, paramMock.businessErrorMock); 149 } else { 150 return new Promise((resolve, reject) => { 151 resolve(); 152 }) 153 } 154 } 155 } 156 return data 157}