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