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 16/** 17 * @import import network from '@system.network'; 18 * @since 3 19 * @syscap SystemCapability.Communication.NetManager.Core 20 */ 21export interface NetworkResponse { 22 /** 23 * Network type. The values can be 2G, 3G, 4G, WiFi, or none. 24 * @since 3 25 */ 26 type: string; 27 28 /** 29 * Whether the billing is based on the data volume. 30 * @since 3 31 */ 32 metered: boolean; 33 } 34 35 /** 36 * @import import network from '@system.network'; 37 * @since 3 38 * @syscap SystemCapability.Communication.NetManager.Core 39 */ 40 export default class Network { 41 /** 42 * Obtains the network type. 43 * @param options 44 */ 45 static getType(options?: { 46 /** 47 * Called when the network type is obtained. 48 * @since 3 49 */ 50 success?: (data: NetworkResponse) => void; 51 52 /** 53 * Called when the network type fails to be obtained. 54 * @since 3 55 */ 56 fail?: (data: any, code: number) => void; 57 58 /** 59 * Called when the execution is completed. 60 * @since 3 61 */ 62 complete?: () => void; 63 }): void; 64 65 /** 66 * Listens to the network connection state. If this method is called multiple times, the last call takes effect. 67 * @param options 68 */ 69 static subscribe(options?: { 70 /** 71 * Called when the network connection state changes. 72 * @since 3 73 */ 74 success?: (data: NetworkResponse) => void; 75 76 /** 77 * Called when the listening fails. 78 * @since 3 79 */ 80 fail?: (data: any, code: number) => void; 81 }): void; 82 83 /** 84 * Cancels listening to the network connection state. 85 * @param options 86 */ 87 static unsubscribe(): void; 88 } 89