• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { paramMock } from "../utils"
17
18export function mockBatteryStatistics() {
19    const ConsumptionType = {
20        CONSUMPTION_TYPE_INVALID: -17,
21        CONSUMPTION_TYPE_APP: '[PC preview] unknow CONSUMPTION_TYPE_APP',
22        CONSUMPTION_TYPE_BLUETOOTH: '[PC preview] unknow CONSUMPTION_TYPE_BLUETOOTH',
23        CONSUMPTION_TYPE_IDLE: '[PC preview] unknow CONSUMPTION_TYPE_IDLE',
24        CONSUMPTION_TYPE_PHONE: '[PC preview] unknow CONSUMPTION_TYPE_PHONE',
25        CONSUMPTION_TYPE_RADIO: '[PC preview] unknow CONSUMPTION_TYPE_RADIO',
26        CONSUMPTION_TYPE_SCREEN: '[PC preview] unknow CONSUMPTION_TYPE_SCREEN',
27        CONSUMPTION_TYPE_USER: '[PC preview] unknow CONSUMPTION_TYPE_USER',
28        CONSUMPTION_TYPE_WIFI: '[PC preview] unknow CONSUMPTION_TYPE_WIFI'
29    }
30    const BatteryStatsInfo = {
31        uid: '[PC preview] unknow uid',
32        type: ConsumptionType,
33        power: '[PC preview] unknow power',
34    }
35    const batteryStats = {
36        ConsumptionType,
37        BatteryStatsInfo,
38        getBatteryStats: function (...args) {
39            console.warn("batteryStats.getBatteryStats interface mocked in the Previewer. How this interface works on the" +
40            " Previewer may be different from that on a real device.")
41            var batteryStatsInfos = new Array(BatteryStatsInfo)
42            const len = args.length
43            if (typeof args[len - 1] === 'function') {
44                args[len - 1].call(this, paramMock.businessErrorMock, batteryStatsInfos);
45            }else {
46                return new Promise((resolve, reject) => {
47                    resolve(batteryStatsInfos);
48                })
49            }
50        },
51        getAppPowerValue: function (...args) {
52            console.warn("batteryStats.getAppPowerValue interface mocked in the Previewer. How this interface works on the" +
53            " Previewer may be different from that on a real device.")
54            return paramMock.paramNumberMock;
55        },
56        getAppPowerPercent: function (...args) {
57            console.warn("batteryStats.getAppPowerPercent interface mocked in the Previewer. How this interface works on the" +
58            " Previewer may be different from that on a real device.")
59            return paramMock.paramNumberMock;
60        },
61        getHardwareUnitPowerValue: function (...args) {
62            console.warn("batteryStats.getHardwareUnitPowerValue interface mocked in the Previewer. How this interface works on the" +
63            " Previewer may be different from that on a real device.")
64            return paramMock.paramNumberMock;
65
66        },
67        getHardwareUnitPowerPercent: function (...args) {
68            console.warn("batteryStats.getHardwareUnitPowerPercent interface mocked in the Previewer. How this interface works on the" +
69            " Previewer may be different from that on a real device.")
70            return paramMock.paramNumberMock;
71        }
72    }
73    return batteryStats
74  }
75