10826e83eSopenharmony_ci/* 20826e83eSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 30826e83eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 40826e83eSopenharmony_ci * you may not use this file except in compliance with the License. 50826e83eSopenharmony_ci * You may obtain a copy of the License at 60826e83eSopenharmony_ci * 70826e83eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 80826e83eSopenharmony_ci * 90826e83eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 100826e83eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 110826e83eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120826e83eSopenharmony_ci * See the License for the specific language governing permissions and 130826e83eSopenharmony_ci * limitations under the License. 140826e83eSopenharmony_ci */ 150826e83eSopenharmony_ci 160826e83eSopenharmony_ci#include "nweb_export.h" 170826e83eSopenharmony_ci#include "nweb_log.h" 180826e83eSopenharmony_ci 190826e83eSopenharmony_ci#include "locator.h" 200826e83eSopenharmony_ci 210826e83eSopenharmony_ciusing namespace OHOS; 220826e83eSopenharmony_ciusing namespace OHOS::Location; 230826e83eSopenharmony_cinamespace OHOS::NWeb { 240826e83eSopenharmony_ciauto g_locatorProxy = Locator::GetInstance(); 250826e83eSopenharmony_ci} 260826e83eSopenharmony_ci 270826e83eSopenharmony_ciextern "C" OHOS_NWEB_EXPORT bool IsLocationEnable(bool& isEnabled) 280826e83eSopenharmony_ci{ 290826e83eSopenharmony_ci if (!NWeb::g_locatorProxy) { 300826e83eSopenharmony_ci WVLOG_E("g_locatorProxy is nullptr"); 310826e83eSopenharmony_ci return false; 320826e83eSopenharmony_ci } 330826e83eSopenharmony_ci LocationErrCode ret = NWeb::g_locatorProxy->IsLocationEnabledV9(isEnabled); 340826e83eSopenharmony_ci if (ret != LocationErrCode::ERRCODE_SUCCESS) { 350826e83eSopenharmony_ci WVLOG_E("StartLocating failed, errcode:%{public}d", ret); 360826e83eSopenharmony_ci return false; 370826e83eSopenharmony_ci } 380826e83eSopenharmony_ci return true; 390826e83eSopenharmony_ci} 400826e83eSopenharmony_ci 410826e83eSopenharmony_ciextern "C" OHOS_NWEB_EXPORT bool StartLocating( 420826e83eSopenharmony_ci std::unique_ptr<RequestConfig>& requestConfig, 430826e83eSopenharmony_ci OHOS::sptr<ILocatorCallback>& callback) 440826e83eSopenharmony_ci{ 450826e83eSopenharmony_ci if (!NWeb::g_locatorProxy || !requestConfig || !callback) { 460826e83eSopenharmony_ci WVLOG_E("g_locatorProxy is nullptr"); 470826e83eSopenharmony_ci return false; 480826e83eSopenharmony_ci } 490826e83eSopenharmony_ci LocationErrCode ret = NWeb::g_locatorProxy->StartLocatingV9( 500826e83eSopenharmony_ci requestConfig, callback); 510826e83eSopenharmony_ci if (ret != LocationErrCode::ERRCODE_SUCCESS) { 520826e83eSopenharmony_ci WVLOG_E("StartLocating failed, errcode:%{public}d", ret); 530826e83eSopenharmony_ci return false; 540826e83eSopenharmony_ci } 550826e83eSopenharmony_ci return true; 560826e83eSopenharmony_ci} 570826e83eSopenharmony_ci 580826e83eSopenharmony_ciextern "C" OHOS_NWEB_EXPORT bool StopLocating(OHOS::sptr<ILocatorCallback>& callback) 590826e83eSopenharmony_ci{ 600826e83eSopenharmony_ci if (!NWeb::g_locatorProxy || !callback) { 610826e83eSopenharmony_ci WVLOG_E("g_locatorProxy is nullptr"); 620826e83eSopenharmony_ci return false; 630826e83eSopenharmony_ci } 640826e83eSopenharmony_ci LocationErrCode ret = NWeb::g_locatorProxy->StopLocatingV9(callback); 650826e83eSopenharmony_ci if (ret != LocationErrCode::ERRCODE_SUCCESS) { 660826e83eSopenharmony_ci WVLOG_E("StopLocating failed, errcode:%{public}d", ret); 670826e83eSopenharmony_ci return false; 680826e83eSopenharmony_ci } 690826e83eSopenharmony_ci return true; 700826e83eSopenharmony_ci} 710826e83eSopenharmony_ci 720826e83eSopenharmony_ciextern "C" OHOS_NWEB_EXPORT bool EnableAbility(bool enable) 730826e83eSopenharmony_ci{ 740826e83eSopenharmony_ci if (!NWeb::g_locatorProxy) { 750826e83eSopenharmony_ci WVLOG_E("g_locatorProxy is nullptr"); 760826e83eSopenharmony_ci return false; 770826e83eSopenharmony_ci } 780826e83eSopenharmony_ci LocationErrCode ret = NWeb::g_locatorProxy->EnableAbilityV9(enable); 790826e83eSopenharmony_ci if (ret != LocationErrCode::ERRCODE_SUCCESS) { 800826e83eSopenharmony_ci WVLOG_E("StopLocating failed, errcode:%{public}d", ret); 810826e83eSopenharmony_ci return false; 820826e83eSopenharmony_ci } 830826e83eSopenharmony_ci return true; 840826e83eSopenharmony_ci}