161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * This module provides the Network Response. 1861847f8eSopenharmony_ci * @interface NetworkResponse 1961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 2061847f8eSopenharmony_ci * @since 3 2161847f8eSopenharmony_ci */ 2261847f8eSopenharmony_ciexport interface NetworkResponse { 2361847f8eSopenharmony_ci /** 2461847f8eSopenharmony_ci * Network type. The values can be 2G, 3G, 4G, WiFi, or none. 2561847f8eSopenharmony_ci * @type {string} 2661847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 2761847f8eSopenharmony_ci * @since 3 2861847f8eSopenharmony_ci */ 2961847f8eSopenharmony_ci type: string; 3061847f8eSopenharmony_ci /** 3161847f8eSopenharmony_ci * Whether the billing is based on the data volume. 3261847f8eSopenharmony_ci * @type {boolean} 3361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 3461847f8eSopenharmony_ci * @since 3 3561847f8eSopenharmony_ci */ 3661847f8eSopenharmony_ci metered: boolean; 3761847f8eSopenharmony_ci} 3861847f8eSopenharmony_ci 3961847f8eSopenharmony_ci/** 4061847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 4161847f8eSopenharmony_ci * @since 3 4261847f8eSopenharmony_ci */ 4361847f8eSopenharmony_ciexport default class Network { 4461847f8eSopenharmony_ci /** 4561847f8eSopenharmony_ci * Obtains the network type. 4661847f8eSopenharmony_ci * @param { object } options - Options. 4761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 4861847f8eSopenharmony_ci * @since 3 4961847f8eSopenharmony_ci */ 5061847f8eSopenharmony_ci static getType(options?: { 5161847f8eSopenharmony_ci /** 5261847f8eSopenharmony_ci * Called when the network type is obtained. 5361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 5461847f8eSopenharmony_ci * @since 3 5561847f8eSopenharmony_ci */ 5661847f8eSopenharmony_ci success?: (data: NetworkResponse) => void; 5761847f8eSopenharmony_ci /** 5861847f8eSopenharmony_ci * Called when the network type fails to be obtained. 5961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 6061847f8eSopenharmony_ci * @since 3 6161847f8eSopenharmony_ci */ 6261847f8eSopenharmony_ci fail?: (data: any, code: number) => void; 6361847f8eSopenharmony_ci /** 6461847f8eSopenharmony_ci * Called when the execution is completed. 6561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 6661847f8eSopenharmony_ci * @since 3 6761847f8eSopenharmony_ci */ 6861847f8eSopenharmony_ci complete?: () => void; 6961847f8eSopenharmony_ci }): void; 7061847f8eSopenharmony_ci 7161847f8eSopenharmony_ci /** 7261847f8eSopenharmony_ci * Listens to the network connection state. If this method is called multiple times, the last call takes effect. 7361847f8eSopenharmony_ci * @param { object } options - Options. 7461847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 7561847f8eSopenharmony_ci * @since 3 7661847f8eSopenharmony_ci */ 7761847f8eSopenharmony_ci static subscribe(options?: { 7861847f8eSopenharmony_ci /** 7961847f8eSopenharmony_ci * Called when the network connection state changes. 8061847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 8161847f8eSopenharmony_ci * @since 3 8261847f8eSopenharmony_ci */ 8361847f8eSopenharmony_ci success?: (data: NetworkResponse) => void; 8461847f8eSopenharmony_ci /** 8561847f8eSopenharmony_ci * Called when the listening fails. 8661847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 8761847f8eSopenharmony_ci * @since 3 8861847f8eSopenharmony_ci */ 8961847f8eSopenharmony_ci fail?: (data: any, code: number) => void; 9061847f8eSopenharmony_ci }): void; 9161847f8eSopenharmony_ci 9261847f8eSopenharmony_ci /** 9361847f8eSopenharmony_ci * Cancels listening to the network connection state. 9461847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 9561847f8eSopenharmony_ci * @since 3 9661847f8eSopenharmony_ci */ 9761847f8eSopenharmony_ci static unsubscribe(): void; 9861847f8eSopenharmony_ci} 99