1b1b8bc3fSopenharmony_ci/* 2b1b8bc3fSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3b1b8bc3fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4b1b8bc3fSopenharmony_ci * you may not use this file except in compliance with the License. 5b1b8bc3fSopenharmony_ci * You may obtain a copy of the License at 6b1b8bc3fSopenharmony_ci * 7b1b8bc3fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8b1b8bc3fSopenharmony_ci * 9b1b8bc3fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10b1b8bc3fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11b1b8bc3fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12b1b8bc3fSopenharmony_ci * See the License for the specific language governing permissions and 13b1b8bc3fSopenharmony_ci * limitations under the License. 14b1b8bc3fSopenharmony_ci */ 15b1b8bc3fSopenharmony_ci 16b1b8bc3fSopenharmony_ci/** 17b1b8bc3fSopenharmony_ci * @import import network from '@system.network'; 18b1b8bc3fSopenharmony_ci * @since 3 19b1b8bc3fSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 20b1b8bc3fSopenharmony_ci */ 21b1b8bc3fSopenharmony_ciexport interface NetworkResponse { 22b1b8bc3fSopenharmony_ci /** 23b1b8bc3fSopenharmony_ci * Network type. The values can be 2G, 3G, 4G, WiFi, or none. 24b1b8bc3fSopenharmony_ci * @since 3 25b1b8bc3fSopenharmony_ci */ 26b1b8bc3fSopenharmony_ci type: string; 27b1b8bc3fSopenharmony_ci 28b1b8bc3fSopenharmony_ci /** 29b1b8bc3fSopenharmony_ci * Whether the billing is based on the data volume. 30b1b8bc3fSopenharmony_ci * @since 3 31b1b8bc3fSopenharmony_ci */ 32b1b8bc3fSopenharmony_ci metered: boolean; 33b1b8bc3fSopenharmony_ci } 34b1b8bc3fSopenharmony_ci 35b1b8bc3fSopenharmony_ci /** 36b1b8bc3fSopenharmony_ci * @import import network from '@system.network'; 37b1b8bc3fSopenharmony_ci * @since 3 38b1b8bc3fSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 39b1b8bc3fSopenharmony_ci */ 40b1b8bc3fSopenharmony_ci export default class Network { 41b1b8bc3fSopenharmony_ci /** 42b1b8bc3fSopenharmony_ci * Obtains the network type. 43b1b8bc3fSopenharmony_ci * @param options 44b1b8bc3fSopenharmony_ci */ 45b1b8bc3fSopenharmony_ci static getType(options?: { 46b1b8bc3fSopenharmony_ci /** 47b1b8bc3fSopenharmony_ci * Called when the network type is obtained. 48b1b8bc3fSopenharmony_ci * @since 3 49b1b8bc3fSopenharmony_ci */ 50b1b8bc3fSopenharmony_ci success?: (data: NetworkResponse) => void; 51b1b8bc3fSopenharmony_ci 52b1b8bc3fSopenharmony_ci /** 53b1b8bc3fSopenharmony_ci * Called when the network type fails to be obtained. 54b1b8bc3fSopenharmony_ci * @since 3 55b1b8bc3fSopenharmony_ci */ 56b1b8bc3fSopenharmony_ci fail?: (data: any, code: number) => void; 57b1b8bc3fSopenharmony_ci 58b1b8bc3fSopenharmony_ci /** 59b1b8bc3fSopenharmony_ci * Called when the execution is completed. 60b1b8bc3fSopenharmony_ci * @since 3 61b1b8bc3fSopenharmony_ci */ 62b1b8bc3fSopenharmony_ci complete?: () => void; 63b1b8bc3fSopenharmony_ci }): void; 64b1b8bc3fSopenharmony_ci 65b1b8bc3fSopenharmony_ci /** 66b1b8bc3fSopenharmony_ci * Listens to the network connection state. If this method is called multiple times, the last call takes effect. 67b1b8bc3fSopenharmony_ci * @param options 68b1b8bc3fSopenharmony_ci */ 69b1b8bc3fSopenharmony_ci static subscribe(options?: { 70b1b8bc3fSopenharmony_ci /** 71b1b8bc3fSopenharmony_ci * Called when the network connection state changes. 72b1b8bc3fSopenharmony_ci * @since 3 73b1b8bc3fSopenharmony_ci */ 74b1b8bc3fSopenharmony_ci success?: (data: NetworkResponse) => void; 75b1b8bc3fSopenharmony_ci 76b1b8bc3fSopenharmony_ci /** 77b1b8bc3fSopenharmony_ci * Called when the listening fails. 78b1b8bc3fSopenharmony_ci * @since 3 79b1b8bc3fSopenharmony_ci */ 80b1b8bc3fSopenharmony_ci fail?: (data: any, code: number) => void; 81b1b8bc3fSopenharmony_ci }): void; 82b1b8bc3fSopenharmony_ci 83b1b8bc3fSopenharmony_ci /** 84b1b8bc3fSopenharmony_ci * Cancels listening to the network connection state. 85b1b8bc3fSopenharmony_ci * @param options 86b1b8bc3fSopenharmony_ci */ 87b1b8bc3fSopenharmony_ci static unsubscribe(): void; 88b1b8bc3fSopenharmony_ci } 89