1 /*
2 * Copyright (c) 2023 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 #include "nweb_export.h"
17 #include "nweb_log.h"
18
19 #include "locator.h"
20
21 using namespace OHOS;
22 using namespace OHOS::Location;
23 namespace OHOS::NWeb {
24 auto g_locatorProxy = Locator::GetInstance();
25 }
26
IsLocationEnable(bool & isEnabled)27 extern "C" OHOS_NWEB_EXPORT bool IsLocationEnable(bool& isEnabled)
28 {
29 if (!NWeb::g_locatorProxy) {
30 WVLOG_E("g_locatorProxy is nullptr");
31 return false;
32 }
33 LocationErrCode ret = NWeb::g_locatorProxy->IsLocationEnabledV9(isEnabled);
34 if (ret != LocationErrCode::ERRCODE_SUCCESS) {
35 WVLOG_E("StartLocating failed, errcode:%{public}d", ret);
36 return false;
37 }
38 return true;
39 }
40
StartLocating(std::unique_ptr<RequestConfig> & requestConfig,OHOS::sptr<ILocatorCallback> & callback)41 extern "C" OHOS_NWEB_EXPORT bool StartLocating(
42 std::unique_ptr<RequestConfig>& requestConfig,
43 OHOS::sptr<ILocatorCallback>& callback)
44 {
45 if (!NWeb::g_locatorProxy || !requestConfig || !callback) {
46 WVLOG_E("g_locatorProxy is nullptr");
47 return false;
48 }
49 LocationErrCode ret = NWeb::g_locatorProxy->StartLocatingV9(
50 requestConfig, callback);
51 if (ret != LocationErrCode::ERRCODE_SUCCESS) {
52 WVLOG_E("StartLocating failed, errcode:%{public}d", ret);
53 return false;
54 }
55 return true;
56 }
57
StopLocating(OHOS::sptr<ILocatorCallback> & callback)58 extern "C" OHOS_NWEB_EXPORT bool StopLocating(OHOS::sptr<ILocatorCallback>& callback)
59 {
60 if (!NWeb::g_locatorProxy || !callback) {
61 WVLOG_E("g_locatorProxy is nullptr");
62 return false;
63 }
64 LocationErrCode ret = NWeb::g_locatorProxy->StopLocatingV9(callback);
65 if (ret != LocationErrCode::ERRCODE_SUCCESS) {
66 WVLOG_E("StopLocating failed, errcode:%{public}d", ret);
67 return false;
68 }
69 return true;
70 }
71
EnableAbility(bool enable)72 extern "C" OHOS_NWEB_EXPORT bool EnableAbility(bool enable)
73 {
74 if (!NWeb::g_locatorProxy) {
75 WVLOG_E("g_locatorProxy is nullptr");
76 return false;
77 }
78 LocationErrCode ret = NWeb::g_locatorProxy->EnableAbilityV9(enable);
79 if (ret != LocationErrCode::ERRCODE_SUCCESS) {
80 WVLOG_E("StopLocating failed, errcode:%{public}d", ret);
81 return false;
82 }
83 return true;
84 }