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" 17 18export function mockBundleState() { 19 const BundleStateInfo = { 20 abilityInFgTotalTime: '[PC preview] unknown abilityInFgTotalTime', 21 abilityPrevAccessTime: '[PC preview] unknown abilityPrevAccessTime', 22 abilityPrevSeenTime: '[PC preview] unknown abilityPrevSeenTime', 23 abilitySeenTotalTime: '[PC preview] unknown abilitySeenTotalTime', 24 bundleName: "[PC preview] unknown bundle name", 25 fgAbilityAccessTotalTime: '[PC preview] unknown fgAbilityAccessTotalTime', 26 fgAbilityPrevAccessTime: '[PC preview] unknown fgAbilityPrevAccessTime', 27 id: '[PC preview] unknown id', 28 infosBeginTime: '[PC preview] unknown infosBeginTime', 29 infosEndTime: '[PC preview] unknown infosEndTime', 30 31 merge: function (...args) { 32 console.warn("bundleState.merge interface mocked in the Previewer. How this interface works on the" + 33 " Previewer may be different from that on a real device."); 34 }, 35 } 36 const BundleStateInfoArray = [BundleStateInfo] 37 const BundleActiveState = { 38 appUsagePriorityGroup: '[PC preview] unknown appUsagePriorityGroup', 39 bundleName: '[PC preview] unknown bundleName', 40 indexOfLink: '[PC preview] unknown indexOfLink', 41 nameOfClass: '[PC preview] unknown nameOfClass', 42 stateOccurredTime: '[PC preview] unknown stateOccurredTime', 43 stateType: '[PC preview] unknown stateType', 44 } 45 const BundleActiveStateArray = [BundleActiveState] 46 const BundleActiveEventState = { 47 name: '[PC preview] unknown name', 48 eventId: '[PC preview] unknown eventId', 49 count: '[PC preview] unknown count', 50 } 51 const BundleActiveEventStateArray = [BundleActiveEventState] 52 const BundleActiveInfoResponse = { 53 "key": BundleStateInfo 54 } 55 const BundleActiveGroupCallbackInfo = { 56 appUsageOldGroup : '[PC preview] unknown appUsageOldGroup', 57 appUsageNewGroup : '[PC preview] unknown appUsageNewGroup', 58 userId : '[PC preview] unknown userId', 59 changeReason : '[PC preview] unknown changeReason', 60 bundleName : '[PC preview] unknown bundleName', 61 } 62 const BundleActiveFormInfo = { 63 count : '[PC preview] unknown count', 64 formLastUsedTime : '[PC preview] unknown formLastUsedTime', 65 formId : '[PC preview] unknown formId', 66 formDimension : '[PC preview] unknown formDimension', 67 formName : '[PC preview] unknown formName', 68 } 69 const BundleActiveModuleInfo = { 70 deviceId : '[PC preview] unknown deviceId', 71 bundleName : '[PC preview] unknown bundleName', 72 moduleName : '[PC preview] unknown moduleName', 73 abilityName : '[PC preview] unknown abilityName', 74 appLabelId : '[PC preview] unknown appLabelId', 75 labelId : '[PC preview] unknown labelId', 76 descriptionId : '[PC preview] unknown descriptionId', 77 abilityLableId : '[PC preview] unknown abilityLableId', 78 abilityDescriptionId : '[PC preview] unknown abilityDescriptionId', 79 abilityIconId : '[PC preview] unknown abilityIconId', 80 launchedCount : '[PC preview] unknown launchedCount', 81 lastModuleUsedTime : '[PC preview] unknown lastModuleUsedTime', 82 formRecords : [BundleActiveFormInfo], 83 } 84 const IntervalType = { 85 BY_OPTIMIZED: 0, 86 BY_DAILY: 1, 87 BY_WEEKLY: 2, 88 BY_MONTHLY: 3, 89 BY_ANNUALLY: 4 90 } 91 const GroupType = { 92 ACTIVE_GROUP_ALIVE : 10, 93 ACTIVE_GROUP_DAILY : 20, 94 ACTIVE_GROUP_FIXED : 30, 95 ACTIVE_GROUP_RARE : 40, 96 ACTIVE_GROUP_LIMIT : 50, 97 ACTIVE_GROUP_NEVER : 60, 98 } 99 const bundleState = { 100 isIdleState: function (...args) { 101 console.warn("bundleState.isIdleState interface mocked in the Previewer. How this interface works on the" + 102 " Previewer may be different from that on a real device."); 103 const len = args.length; 104 if (typeof args[len - 1] === 'function') { 105 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 106 } else { 107 return new Promise((resolve) => { 108 resolve(paramMock.paramBooleanMock) 109 }); 110 } 111 }, 112 queryAppUsagePriorityGroup: function (...args) { 113 console.warn("bundleState.queryAppUsagePriorityGroup interface mocked in the Previewer. How this interface works on the" + 114 " Previewer may be different from that on a real device."); 115 const len = args.length; 116 if (typeof args[len - 1] === 'function') { 117 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 118 } else { 119 return new Promise((resolve) => { 120 resolve(paramMock.paramNumberMock) 121 }); 122 } 123 }, 124 queryBundleStateInfos: function (...args) { 125 console.warn("bundleState.queryBundleStateInfos interface mocked in the Previewer. How this interface works on the" + 126 " Previewer may be different from that on a real device."); 127 const len = args.length; 128 if (typeof args[len - 1] === 'function') { 129 args[len - 1].call(this, paramMock.businessErrorMock, BundleActiveInfoResponse); 130 } else { 131 return new Promise((resolve) => { 132 resolve(BundleActiveInfoResponse) 133 }); 134 } 135 }, 136 queryBundleStateInfoByInterval: function (...args) { 137 console.warn("bundleState.queryBundleStateInfoByInterval interface mocked in the Previewer. How this interface works on the" + 138 " Previewer may be different from that on a real device."); 139 const len = args.length; 140 if (typeof args[len - 1] === 'function') { 141 args[len - 1].call(this, paramMock.businessErrorMock, BundleStateInfoArray); 142 } else { 143 return new Promise((resolve) => { 144 resolve(BundleStateInfoArray) 145 }); 146 } 147 }, 148 queryBundleActiveStates: function (...args) { 149 console.warn("bundleState.queryBundleActiveStates interface mocked in the Previewer. How this interface works on the" + 150 " Previewer may be different from that on a real device."); 151 const len = args.length; 152 if (typeof args[len - 1] === 'function') { 153 args[len - 1].call(this, paramMock.businessErrorMock, BundleActiveStateArray); 154 } else { 155 return new Promise((resolve) => { 156 resolve(BundleActiveStateArray) 157 }); 158 } 159 }, 160 queryCurrentBundleActiveStates: function (...args) { 161 console.warn("bundleState.queryCurrentBundleActiveStates interface mocked in the Previewer. How this interface works on the" + 162 " Previewer may be different from that on a real device."); 163 const len = args.length; 164 if (typeof args[len - 1] === 'function') { 165 args[len - 1].call(this, paramMock.businessErrorMock, BundleActiveStateArray); 166 } else { 167 return new Promise((resolve) => { 168 resolve(BundleActiveStateArray) 169 }); 170 } 171 }, 172 queryBundleActiveEventStates: function (...args) { 173 console.warn("bundleState.queryBundleActiveEventStates interface mocked in the Previewer. How this interface works on the" + 174 " Previewer may be different from that on a real device."); 175 const len = args.length; 176 if (typeof args[len - 1] === 'function') { 177 args[len - 1].call(this, paramMock.businessErrorMock, BundleActiveEventStateArray); 178 } else { 179 return new Promise((resolve) => { 180 resolve(BundleActiveEventStateArray) 181 }); 182 } 183 }, 184 queryAppNotificationNumber: function (...args) { 185 console.warn("bundleState.queryAppNotificationNumber interface mocked in the Previewer. How this interface works on the" + 186 " Previewer may be different from that on a real device."); 187 const len = args.length; 188 if (typeof args[len - 1] === 'function') { 189 args[len - 1].call(this, paramMock.businessErrorMock, BundleActiveEventStateArray); 190 } else { 191 return new Promise((resolve) => { 192 resolve(BundleActiveEventStateArray) 193 }); 194 } 195 }, 196 setBundleGroup: function (...args) { 197 console.warn("bundleState.setBundleGroup interface mocked in the Previewer. How this interface works on the" + 198 " Previewer may be different from that on a real device."); 199 const len = args.length; 200 if (typeof args[len - 1] === 'function') { 201 args[len - 1].call(this, paramMock.businessErrorMock); 202 } else { 203 return new Promise((resolve) => { 204 resolve() 205 }); 206 } 207 }, 208 registerGroupCallBack: function (...args) { 209 console.warn("bundleState.registerGroupCallBack interface mocked in the Previewer. How this interface works on the" + 210 " Previewer may be different from that on a real device."); 211 const len = args.length; 212 if (typeof args[len - 1] === 'function') { 213 args[len - 1].call(this, paramMock.businessErrorMock); 214 } else { 215 return new Promise((resolve) => { 216 resolve() 217 }); 218 } 219 }, 220 unRegisterGroupCallBack: function (...args) { 221 console.warn("bundleState.unRegisterGroupCallBack interface mocked in the Previewer. How this interface works on the" + 222 " Previewer may be different from that on a real device."); 223 const len = args.length; 224 if (typeof args[len - 1] === 'function') { 225 args[len - 1].call(this, paramMock.businessErrorMock); 226 } else { 227 return new Promise((resolve) => { 228 resolve() 229 }); 230 } 231 }, 232 getRecentlyUsedModules: function (...args) { 233 console.warn("bundleState.getRecentlyUsedModules interface mocked in the Previewer. How this interface works on the" + 234 " Previewer may be different from that on a real device."); 235 const len = args.length; 236 if (typeof args[len - 1] === 'function') { 237 args[len - 1].call(this, paramMock.businessErrorMock, BundleActiveModuleInfo); 238 } else { 239 return new Promise((resolve) => { 240 resolve(BundleActiveModuleInfo) 241 }); 242 } 243 }, 244 } 245 return bundleState 246}