mirror of
https://gitee.com/openharmony/base_location
synced 2024-11-27 00:51:30 +00:00
Submit location subsystem code
Signed-off-by: liu-binjun <liubinjun@huawei.com>
This commit is contained in:
parent
2d945e680a
commit
22aba156f4
177
LICENSE
Normal file
177
LICENSE
Normal file
@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
46
bundle.json
Normal file
46
bundle.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "@ohos/location",
|
||||
"version": "3.1.0",
|
||||
"description": "Location service, providing location and geocoding capabilities.",
|
||||
"homePage": "https://gitee.com/openharmony",
|
||||
"license": "Apache License 2.0",
|
||||
"repository": "",
|
||||
"domain": "os",
|
||||
"language": "",
|
||||
"publishAs": "code-segment",
|
||||
"private": false,
|
||||
"segment": {
|
||||
"destPath": "base/location/location"
|
||||
},
|
||||
"component": {
|
||||
"name": "location",
|
||||
"subsystem": "location",
|
||||
"syscap": [
|
||||
"SystemCapability.Location.Location"
|
||||
],
|
||||
"features": [],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"deps": {
|
||||
"components": [
|
||||
"ipc",
|
||||
"ces_standard",
|
||||
"hiviewdfx_hilog_native",
|
||||
"access_token"
|
||||
],
|
||||
"third_party": []
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//base/location/interfaces/innerkits/locator_standard:locator_sdk",
|
||||
"//base/location/interfaces/innerkits/napi:geolocation",
|
||||
"//base/location/etc:etc",
|
||||
"//base/location/profile:location_sa_profile"
|
||||
],
|
||||
"test": []
|
||||
}
|
||||
}
|
||||
}
|
83
interfaces/innerkits/locator_standard/BUILD.gn
Normal file
83
interfaces/innerkits/locator_standard/BUILD.gn
Normal file
@ -0,0 +1,83 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
################################################################################
|
||||
|
||||
SUBSYSTEM_DIR = "//base/location"
|
||||
|
||||
ohos_shared_library("locator_sdk") {
|
||||
install_enable = true
|
||||
|
||||
include_dirs = [
|
||||
"//distributedschedule/safwk/include",
|
||||
"//native_engine",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
"//base/notification/ces_standard/frameworks/core/include",
|
||||
"//base/location/interfaces/innerkits/napi",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/include",
|
||||
"$SUBSYSTEM_DIR/location_geocode/geocode/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/include",
|
||||
"$SUBSYSTEM_DIR/location_common/common/include",
|
||||
"$SUBSYSTEM_DIR/utils/include",
|
||||
"//base/security/access_token/interfaces/innerkits/accesstoken/include"
|
||||
]
|
||||
|
||||
sources = [
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/src/locator.cpp",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/src/locator_proxy.cpp",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/src/locator_callback_host.cpp",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/src/location_switch_callback_host.cpp",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/src/locator_impl.cpp",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/src/location_util.cpp",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/src/gnss_status_callback_host.cpp",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/src/nmea_message_callback_host.cpp",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/src/cached_locations_callback_host.cpp",
|
||||
"$SUBSYSTEM_DIR/utils/source/common_utils.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$SUBSYSTEM_DIR/location_common/common:lbsservice_common",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//utils/native/base:utils",
|
||||
"//third_party/libuv:uv_static",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ipc:ipc_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
]
|
||||
|
||||
cflags_cc = [
|
||||
"-std=c++17",
|
||||
"-fno-rtti",
|
||||
]
|
||||
|
||||
ldflags = [
|
||||
"-fPIC",
|
||||
"-Wl,-E",
|
||||
]
|
||||
|
||||
part_name = "location"
|
||||
subsystem_name = "location"
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_CACHED_LOCATIONS_CALLBACK_HOST_H
|
||||
#define OHOS_CACHED_LOCATIONS_CALLBACK_HOST_H
|
||||
|
||||
#include <shared_mutex>
|
||||
#include "i_cached_locations_callback.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "location_util.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class CachedLocationsCallbackHost : public IRemoteStub<ICachedLocationsCallback> {
|
||||
public:
|
||||
CachedLocationsCallbackHost();
|
||||
virtual ~CachedLocationsCallbackHost();
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
bool IsRemoteDied();
|
||||
bool Send(const std::vector<std::unique_ptr<Location>>& locations);
|
||||
void OnCacheLocationsReport(const std::vector<std::unique_ptr<Location>>& locations) override;
|
||||
void DeleteHandler();
|
||||
|
||||
napi_env m_env;
|
||||
napi_ref m_thisVarRef;
|
||||
napi_ref m_handlerCb;
|
||||
bool m_remoteDied;
|
||||
std::shared_mutex m_mutex;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_CACHED_LOCATIONS_CALLBACK_HOST_H
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_GNSS_STATUS_CALLBACK_HOST_H
|
||||
#define OHOS_GNSS_STATUS_CALLBACK_HOST_H
|
||||
|
||||
#include <shared_mutex>
|
||||
#include "i_gnss_status_callback.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "location_util.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "satellite_status.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class GnssStatusCallbackHost : public IRemoteStub<IGnssStatusCallback> {
|
||||
public:
|
||||
GnssStatusCallbackHost();
|
||||
virtual ~GnssStatusCallbackHost();
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
bool IsRemoteDied();
|
||||
bool Send(const std::unique_ptr<SatelliteStatus>& statusInfo);
|
||||
void OnStatusChange(const std::unique_ptr<SatelliteStatus>& statusInfo) override;
|
||||
void DeleteHandler();
|
||||
|
||||
pid_t m_lastCallingPid;
|
||||
pid_t m_lastCallingUid;
|
||||
napi_env m_env;
|
||||
napi_ref m_thisVarRef;
|
||||
napi_ref m_handlerCb;
|
||||
bool m_remoteDied;
|
||||
std::shared_mutex m_mutex;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_GNSS_STATUS_CALLBACK_HOST_H
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_SWITCH_CALLBACK_HOST_H
|
||||
#define OHOS_LOCATION_SWITCH_CALLBACK_HOST_H
|
||||
|
||||
#include <shared_mutex>
|
||||
#include "i_switch_callback.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "location_util.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class LocationSwitchCallbackHost : public IRemoteStub<ISwitchCallback> {
|
||||
public:
|
||||
LocationSwitchCallbackHost();
|
||||
virtual ~LocationSwitchCallbackHost();
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
bool IsRemoteDied();
|
||||
napi_value PackResult(int switchState);
|
||||
bool Send(int switchState);
|
||||
void OnSwitchChange(int switchState) override;
|
||||
void DeleteHandler();
|
||||
|
||||
pid_t m_lastCallingPid;
|
||||
pid_t m_lastCallingUid;
|
||||
napi_env m_env;
|
||||
napi_ref m_thisVarRef;
|
||||
napi_ref m_handlerCb;
|
||||
int m_fixNumber;
|
||||
bool m_remoteDied;
|
||||
std::shared_mutex m_mutex;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_SWITCH_CALLBACK_HOST_H
|
144
interfaces/innerkits/locator_standard/include/location_util.h
Normal file
144
interfaces/innerkits/locator_standard/include/location_util.h
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_UTIL_H_
|
||||
#define LOCATION_UTIL_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <ctime>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "constant_definition.h"
|
||||
#include "geo_address.h"
|
||||
#include "location.h"
|
||||
#include "message_parcel.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "request_config.h"
|
||||
#include "satellite_status.h"
|
||||
#include "uv.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
constexpr int32_t PARAM0 = 0;
|
||||
constexpr int32_t PARAM1 = 1;
|
||||
constexpr size_t RESULT_SIZE = 2;
|
||||
class TraceFuncCall final {
|
||||
public:
|
||||
TraceFuncCall(std::string funcName);
|
||||
|
||||
TraceFuncCall() = delete;
|
||||
|
||||
~TraceFuncCall();
|
||||
|
||||
private:
|
||||
std::string m_funcName;
|
||||
std::chrono::steady_clock::time_point m_startTime;
|
||||
bool m_isTrace = true;
|
||||
};
|
||||
|
||||
#define TRACE_FUNC_CALL TraceFuncCall func(__func__)
|
||||
#define TRACE_FUNC_CALL_NAME(name) TraceFuncCall func(name)
|
||||
|
||||
class AsyncContext {
|
||||
public:
|
||||
napi_env env;
|
||||
napi_async_work work;
|
||||
napi_deferred deferred;
|
||||
napi_ref callback[2] = { 0 };
|
||||
std::function<void(void*)> executeFunc;
|
||||
std::function<void(void*)> completeFunc;
|
||||
napi_value resourceName;
|
||||
napi_value result[RESULT_SIZE];
|
||||
int errCode;
|
||||
|
||||
AsyncContext(napi_env e, napi_async_work w = nullptr, napi_deferred d = nullptr)
|
||||
{
|
||||
env = e;
|
||||
work = w;
|
||||
deferred = d;
|
||||
executeFunc = nullptr;
|
||||
completeFunc = nullptr;
|
||||
resourceName = nullptr;
|
||||
result[PARAM0] = 0;
|
||||
result[PARAM1] = 0;
|
||||
errCode = 0;
|
||||
}
|
||||
|
||||
AsyncContext() = delete;
|
||||
|
||||
virtual ~AsyncContext()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class JsContext : public AsyncContext {
|
||||
public:
|
||||
napi_env m_env;
|
||||
napi_deferred m_deferred;
|
||||
napi_ref m_thisVarRef;
|
||||
napi_ref m_handlerCb;
|
||||
napi_value m_jsEvent;
|
||||
napi_value resourceName;
|
||||
JsContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) :
|
||||
AsyncContext(env, work, deferred)
|
||||
{
|
||||
m_env = nullptr;
|
||||
m_deferred = nullptr;
|
||||
m_thisVarRef = nullptr;
|
||||
m_handlerCb = nullptr;
|
||||
m_jsEvent = nullptr;
|
||||
resourceName = nullptr;
|
||||
}
|
||||
|
||||
virtual ~JsContext(){}
|
||||
};
|
||||
|
||||
napi_value UndefinedNapiValue(const napi_env& env);
|
||||
void LocationToJs(const napi_env& env, const std::unique_ptr<Location>& locationInfo, napi_value& result);
|
||||
void LocationsToJs(const napi_env& env, const std::vector<std::unique_ptr<Location>>& locations, napi_value& result);
|
||||
void SatelliteStatusToJs(const napi_env& env, const std::unique_ptr<SatelliteStatus>& statusInfo, napi_value& result);
|
||||
bool GeoAddressesToJsObj(const napi_env& env,
|
||||
std::list<std::shared_ptr<GeoAddress>>& replyList, napi_value& arrayResult);
|
||||
void JsObjToLocationRequest(const napi_env& env, const napi_value& object,
|
||||
std::unique_ptr<RequestConfig>& requestConfig);
|
||||
void JsObjToCachedLocationRequest(const napi_env& env, const napi_value& object,
|
||||
std::unique_ptr<CachedGnssLoactionsRequest>& request);
|
||||
void JsObjToCommand(const napi_env& env, const napi_value& object,
|
||||
std::unique_ptr<LocationCommand>& commandConfig);
|
||||
void JsObjToGeoFenceRequest(const napi_env& env, const napi_value& object,
|
||||
std::unique_ptr<GeofenceRequest>& request);
|
||||
bool JsObjToGeoCodeRequest(const napi_env& env, const napi_value& object, MessageParcel& dataParcel);
|
||||
bool JsObjToReverseGeoCodeRequest(const napi_env& env, const napi_value& object, MessageParcel& dataParcel);
|
||||
napi_value JsObjectToString(const napi_env& env, const napi_value& object,
|
||||
const char* fieldStr, const int bufLen, std::string& fieldRef);
|
||||
napi_value JsObjectToDouble(const napi_env& env, const napi_value& object, const char* fieldStr, double& fieldRef);
|
||||
napi_value JsObjectToInt(const napi_env& env, const napi_value& object, const char* fieldStr, int& fieldRef);
|
||||
napi_value JsObjectToBool(const napi_env& env, const napi_value& object, const char* fieldStr, bool& fieldRef);
|
||||
napi_status SetValueUtf8String(const napi_env& env, const char* fieldStr, const char* str, napi_value& result);
|
||||
napi_status SetValueStringArray(const napi_env& env, const char* fieldStr, napi_value& value, napi_value& result);
|
||||
napi_status SetValueInt32(const napi_env& env, const char* fieldStr, const int intValue, napi_value& result);
|
||||
napi_status SetValueInt64(const napi_env& env, const char* fieldStr, const int64_t intValue, napi_value& result);
|
||||
napi_status SetValueDouble(const napi_env& env, const char* fieldStr, const double doubleValue, napi_value& result);
|
||||
napi_status SetValueBool(const napi_env& env, const char* fieldStr, const bool boolvalue, napi_value& result);
|
||||
napi_value DoAsyncWork(const napi_env& env, AsyncContext* asyncContext,
|
||||
const size_t argc, const napi_value* argv, const size_t nonCallbackArgNum);
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
89
interfaces/innerkits/locator_standard/include/locator.h
Normal file
89
interfaces/innerkits/locator_standard/include/locator.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef OHOS_LOCATOR_H
|
||||
#define OHOS_LOCATOR_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "iremote_object.h"
|
||||
|
||||
#include "constant_definition.h"
|
||||
#include "geo_address.h"
|
||||
#include "i_cached_locations_callback.h"
|
||||
#include "i_locator_callback.h"
|
||||
#include "location.h"
|
||||
#include "request_config.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class Locator {
|
||||
public:
|
||||
static std::unique_ptr<Locator> GetInstance(int systemAbilityId);
|
||||
|
||||
virtual ~Locator();
|
||||
|
||||
virtual bool IsLocationEnabled() = 0;
|
||||
|
||||
virtual void RequestEnableLocation() = 0;
|
||||
|
||||
virtual void EnableAbility(bool enable) = 0;
|
||||
|
||||
virtual void StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
|
||||
sptr<ILocatorCallback>& callback) = 0;
|
||||
|
||||
virtual void StopLocating(sptr<ILocatorCallback>& callback) = 0;
|
||||
|
||||
virtual std::unique_ptr<Location> GetCachedLocation() = 0;
|
||||
|
||||
virtual bool RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid) = 0;
|
||||
|
||||
virtual bool UnregisterSwitchCallback(const sptr<IRemoteObject>& callback) = 0;
|
||||
|
||||
virtual void ShowNotification() = 0;
|
||||
|
||||
virtual void RequestPermission(napi_env env) = 0;
|
||||
|
||||
virtual bool IsGeoServiceAvailable() = 0;
|
||||
|
||||
virtual void GetAddressByCoordinate(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList) = 0;
|
||||
|
||||
virtual void GetAddressByLocationName(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList) = 0;
|
||||
|
||||
virtual bool IsLocationPrivacyConfirmed(const LocationPrivacyType type) = 0;
|
||||
|
||||
virtual void SetLocationPrivacyConfirmStatus(const LocationPrivacyType type, bool isConfirmed) = 0;
|
||||
|
||||
virtual bool RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) = 0;
|
||||
virtual bool UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) = 0;
|
||||
virtual bool RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) = 0;
|
||||
virtual bool UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) = 0;
|
||||
|
||||
virtual void RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
sptr<ICachedLocationsCallback>& callback) = 0;
|
||||
|
||||
virtual void UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback) = 0;
|
||||
|
||||
virtual int GetCachedGnssLocationsSize() = 0;
|
||||
virtual bool FlushCachedGnssLocations() = 0;
|
||||
virtual bool SendCommand(std::unique_ptr<LocationCommand>& commands) = 0;
|
||||
|
||||
virtual bool AddFence(std::unique_ptr<GeofenceRequest>& request) = 0;
|
||||
virtual bool RemoveFence(std::unique_ptr<GeofenceRequest>& request) = 0;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // LOCATOR_H
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATOR_CALLBACK_HOST_H
|
||||
#define OHOS_LOCATOR_CALLBACK_HOST_H
|
||||
#include <shared_mutex>
|
||||
#include "i_locator_callback.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "location_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class LocatorCallbackHost : public IRemoteStub<ILocatorCallback> {
|
||||
public:
|
||||
LocatorCallbackHost();
|
||||
virtual ~LocatorCallbackHost();
|
||||
virtual int OnRemoteRequest(uint32_t code,
|
||||
MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
bool Send(const std::unique_ptr<Location>& location);
|
||||
void OnLocationReport(const std::unique_ptr<Location>& location) override;
|
||||
void OnLocatingStatusChange(const int status) override;
|
||||
void OnErrorReport(const int errorCode) override;
|
||||
void DeleteHandler();
|
||||
|
||||
pid_t m_lastCallingPid;
|
||||
pid_t m_lastCallingUid;
|
||||
napi_env m_env;
|
||||
napi_ref m_thisVarRef;
|
||||
napi_ref m_handlerCb;
|
||||
int m_fixNumber;
|
||||
napi_deferred m_deferred;
|
||||
std::shared_mutex m_mutex;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATOR_CALLBACK_HOST_H
|
65
interfaces/innerkits/locator_standard/include/locator_impl.h
Normal file
65
interfaces/innerkits/locator_standard/include/locator_impl.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef OHOS_LOCATOR_IMPL_H
|
||||
#define OHOS_LOCATOR_IMPL_H
|
||||
|
||||
#include "constant_definition.h"
|
||||
#include "i_cached_locations_callback.h"
|
||||
#include "locator.h"
|
||||
#include "locator_proxy.h"
|
||||
#include "geo_address.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class LocatorImpl : public Locator {
|
||||
public:
|
||||
explicit LocatorImpl(int systemAbilityId);
|
||||
~LocatorImpl();
|
||||
bool Init();
|
||||
bool IsLocationEnabled() override;
|
||||
void ShowNotification() override;
|
||||
void RequestPermission(napi_env env) override;
|
||||
void RequestEnableLocation() override;
|
||||
void EnableAbility(bool enable) override;
|
||||
void StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
|
||||
sptr<ILocatorCallback>& callback) override;
|
||||
void StopLocating(sptr<ILocatorCallback>& callback) override;
|
||||
std::unique_ptr<Location> GetCachedLocation() override;
|
||||
bool RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
bool UnregisterSwitchCallback(const sptr<IRemoteObject>& callback) override;
|
||||
bool RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
bool UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) override;
|
||||
bool RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
bool UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) override;
|
||||
void RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
sptr<ICachedLocationsCallback>& callback) override;
|
||||
void UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback) override;
|
||||
bool IsGeoServiceAvailable() override;
|
||||
void GetAddressByCoordinate(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList) override;
|
||||
void GetAddressByLocationName(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList) override;
|
||||
bool IsLocationPrivacyConfirmed(const LocationPrivacyType type) override;
|
||||
void SetLocationPrivacyConfirmStatus(const LocationPrivacyType type, bool isConfirmed) override;
|
||||
int GetCachedGnssLocationsSize() override;
|
||||
bool FlushCachedGnssLocations() override;
|
||||
bool SendCommand(std::unique_ptr<LocationCommand>& commands) override;
|
||||
bool AddFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
bool RemoveFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
private:
|
||||
int systemAbilityId_;
|
||||
std::unique_ptr<LocatorProxy> client_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif
|
138
interfaces/innerkits/locator_standard/include/locator_proxy.h
Normal file
138
interfaces/innerkits/locator_standard/include/locator_proxy.h
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATOR_PROXY_H
|
||||
#define OHOS_LOCATOR_PROXY_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
#include "constant_definition.h"
|
||||
#include "i_cached_locations_callback.h"
|
||||
#include "i_locator_callback.h"
|
||||
#include "location.h"
|
||||
#include "request_config.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class ILocator : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
GET_SWITCH_STATE = 1,
|
||||
REG_SWITCH_CALLBACK = 2,
|
||||
START_LOCATING = 3,
|
||||
STOP_LOCATING = 4,
|
||||
GET_CACHE_LOCATION = 5,
|
||||
REPORT_LOCATION = 6,
|
||||
REPORT_LOCATION_STATUS = 7,
|
||||
REPORT_ERROR_STATUS = 8,
|
||||
ENABLE_ABILITY = 9,
|
||||
UPDATE_SA_ABILITY = 10,
|
||||
GEO_IS_AVAILABLE = 11,
|
||||
GET_FROM_COORDINATE = 12,
|
||||
GET_FROM_LOCATION_NAME = 13,
|
||||
UNREG_SWITCH_CALLBACK = 15,
|
||||
REG_GNSS_STATUS_CALLBACK = 16,
|
||||
UNREG_GNSS_STATUS_CALLBACK = 17,
|
||||
REG_NMEA_CALLBACK = 18,
|
||||
UNREG_NMEA_CALLBACK = 19,
|
||||
IS_PRIVACY_COMFIRMED = 20,
|
||||
SET_PRIVACY_COMFIRM_STATUS = 21,
|
||||
REG_CACHED_CALLBACK = 22,
|
||||
UNREG_CACHED_CALLBACK = 23,
|
||||
GET_CACHED_LOCATION_SIZE = 24,
|
||||
FLUSH_CACHED_LOCATIONS = 25,
|
||||
SEND_COMMAND = 26,
|
||||
ADD_FENCE = 27,
|
||||
REMOVE_FENCE = 28
|
||||
};
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"location.ILocator");
|
||||
virtual void UpdateSaAbility() = 0;
|
||||
virtual int GetSwitchState() = 0;
|
||||
virtual void EnableAbility(bool isEnabled) = 0;
|
||||
virtual void RegisterSwitchCallback(const sptr<IRemoteObject> &callback, pid_t uid) = 0;
|
||||
virtual void UnregisterSwitchCallback(const sptr<IRemoteObject> &callback) = 0;
|
||||
virtual void RegisterGnssStatusCallback(const sptr<IRemoteObject> &callback, pid_t uid) = 0;
|
||||
virtual void UnregisterGnssStatusCallback(const sptr<IRemoteObject> &callback) = 0;
|
||||
virtual void RegisterNmeaMessageCallback(const sptr<IRemoteObject> &callback, pid_t uid) = 0;
|
||||
virtual void UnregisterNmeaMessageCallback(const sptr<IRemoteObject> &callback) = 0;
|
||||
virtual int StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
|
||||
sptr<ILocatorCallback>& callback, std::string bundleName, pid_t pid, pid_t uid) = 0;
|
||||
virtual int StopLocating(sptr<ILocatorCallback>& callback) = 0;
|
||||
virtual int ReportLocation(const std::unique_ptr<Location>& location, std::string abilityName) = 0;
|
||||
virtual int ReportLocationStatus(sptr<ILocatorCallback>& callback, int result) = 0;
|
||||
virtual int ReportErrorStatus(sptr<ILocatorCallback>& callback, int result) = 0;
|
||||
virtual int GetCacheLocation(MessageParcel &data, MessageParcel &replay) = 0;
|
||||
virtual int IsGeoConvertAvailable(MessageParcel &data, MessageParcel &replay) = 0;
|
||||
virtual int GetAddressByCoordinate(MessageParcel &data, MessageParcel &replay) = 0;
|
||||
virtual int GetAddressByLocationName(MessageParcel &data, MessageParcel &replay) = 0;
|
||||
virtual bool IsLocationPrivacyConfirmed(const LocationPrivacyType type) = 0;
|
||||
virtual void SetLocationPrivacyConfirmStatus(const LocationPrivacyType type, bool isConfirmed) = 0;
|
||||
|
||||
virtual int RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
sptr<ICachedLocationsCallback>& callback, std::string bundleName) = 0;
|
||||
virtual int UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback) = 0;
|
||||
|
||||
virtual int GetCachedGnssLocationsSize() = 0;
|
||||
virtual void FlushCachedGnssLocations() = 0;
|
||||
virtual void SendCommand(std::unique_ptr<LocationCommand>& commands) = 0;
|
||||
virtual void AddFence(std::unique_ptr<GeofenceRequest>& request) = 0;
|
||||
virtual void RemoveFence(std::unique_ptr<GeofenceRequest>& request) = 0;
|
||||
};
|
||||
|
||||
class LocatorProxy : public IRemoteProxy<ILocator> {
|
||||
public:
|
||||
explicit LocatorProxy(const sptr<IRemoteObject> &impl);
|
||||
~LocatorProxy() = default;
|
||||
void UpdateSaAbility() override;
|
||||
int GetSwitchState() override;
|
||||
void EnableAbility(bool isEnabled) override;
|
||||
void RegisterSwitchCallback(const sptr<IRemoteObject> &callback, pid_t uid) override;
|
||||
void UnregisterSwitchCallback(const sptr<IRemoteObject> &callback) override;
|
||||
void RegisterGnssStatusCallback(const sptr<IRemoteObject> &callback, pid_t uid) override;
|
||||
void UnregisterGnssStatusCallback(const sptr<IRemoteObject> &callback) override;
|
||||
void RegisterNmeaMessageCallback(const sptr<IRemoteObject> &callback, pid_t uid) override;
|
||||
void UnregisterNmeaMessageCallback(const sptr<IRemoteObject> &callback) override;
|
||||
int StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
|
||||
sptr<ILocatorCallback>& callback, std::string bundleName, pid_t pid, pid_t uid) override;
|
||||
int StopLocating(sptr<ILocatorCallback>& callback) override;
|
||||
int ReportLocation(const std::unique_ptr<Location>& location, std::string abilityName) override;
|
||||
int ReportLocationStatus(sptr<ILocatorCallback>& callback, int result) override;
|
||||
int ReportErrorStatus(sptr<ILocatorCallback>& callback, int result) override;
|
||||
int GetCacheLocation(MessageParcel &data, MessageParcel &replay) override;
|
||||
int IsGeoConvertAvailable(MessageParcel &data, MessageParcel &replay) override;
|
||||
int GetAddressByCoordinate(MessageParcel &data, MessageParcel &replay) override;
|
||||
int GetAddressByLocationName(MessageParcel &data, MessageParcel &replay) override;
|
||||
bool IsLocationPrivacyConfirmed(const LocationPrivacyType type) override;
|
||||
void SetLocationPrivacyConfirmStatus(const LocationPrivacyType type, bool isConfirmed) override;
|
||||
|
||||
int RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
sptr<ICachedLocationsCallback>& callback, std::string bundleName) override;
|
||||
int UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback) override;
|
||||
|
||||
int GetCachedGnssLocationsSize() override;
|
||||
void FlushCachedGnssLocations() override;
|
||||
void SendCommand(std::unique_ptr<LocationCommand>& commands) override;
|
||||
|
||||
void AddFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
void RemoveFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
private:
|
||||
static inline BrokerDelegator<LocatorProxy> delegator_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATOR_PROXY_H
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_NMEA_MESSAGE_CALLBACK_HOST_H
|
||||
#define OHOS_NMEA_MESSAGE_CALLBACK_HOST_H
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
#include "i_nmea_message_callback.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "location_util.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class NmeaMessageCallbackHost : public IRemoteStub<INmeaMessageCallback> {
|
||||
public:
|
||||
NmeaMessageCallbackHost();
|
||||
virtual ~NmeaMessageCallbackHost();
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
bool IsRemoteDied();
|
||||
bool Send(const std::string msg);
|
||||
napi_value PackResult(const std::string msg);
|
||||
void OnMessageChange(const std::string msg) override;
|
||||
void DeleteHandler();
|
||||
|
||||
pid_t m_lastCallingPid;
|
||||
pid_t m_lastCallingUid;
|
||||
napi_env m_env;
|
||||
napi_ref m_thisVarRef;
|
||||
napi_ref m_handlerCb;
|
||||
bool m_remoteDied;
|
||||
std::shared_mutex m_mutex;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_NMEA_MESSAGE_CALLBACK_HOST_H
|
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "cached_locations_callback_host.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
#include "location_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
CachedLocationsCallbackHost::CachedLocationsCallbackHost()
|
||||
{
|
||||
m_env = nullptr;
|
||||
m_handlerCb = nullptr;
|
||||
m_thisVarRef = nullptr;
|
||||
m_remoteDied = false;
|
||||
}
|
||||
|
||||
CachedLocationsCallbackHost::~CachedLocationsCallbackHost()
|
||||
{
|
||||
}
|
||||
|
||||
int CachedLocationsCallbackHost::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
LBSLOGD(CACHED_LOCATIONS_CALLBACK, "CachedLocationsCallbackHost::OnRemoteRequest!");
|
||||
if (m_remoteDied) {
|
||||
LBSLOGD(CACHED_LOCATIONS_CALLBACK, "Failed to `%{public}s`,Remote service is died!", __func__);
|
||||
return -1;
|
||||
}
|
||||
int uid = IPCSkeleton::GetCallingUid();
|
||||
if (uid > SYSTEM_UID) {
|
||||
LBSLOGE(CACHED_LOCATIONS_CALLBACK, "invalid uid!");
|
||||
return false;
|
||||
}
|
||||
switch (code) {
|
||||
case RECEIVE_CACHED_LOCATIONS_EVENT: {
|
||||
int size = data.ReadInt32();
|
||||
std::vector<std::unique_ptr<Location>> locations(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
locations.push_back(Location::Unmarshalling(data));
|
||||
}
|
||||
OnCacheLocationsReport(locations);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CachedLocationsCallbackHost::IsRemoteDied()
|
||||
{
|
||||
return m_remoteDied;
|
||||
}
|
||||
|
||||
bool CachedLocationsCallbackHost::Send(const std::vector<std::unique_ptr<Location>>& locations)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(m_env, &scope);
|
||||
napi_value jsEvent = nullptr;
|
||||
napi_create_object(m_env, &jsEvent);
|
||||
LocationsToJs(m_env, locations, jsEvent);
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(m_env, &loop);
|
||||
if (loop == nullptr) {
|
||||
LBSLOGE(CACHED_LOCATIONS_CALLBACK, "loop == nullptr.");
|
||||
return false;
|
||||
}
|
||||
uv_work_t *work = new uv_work_t;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(CACHED_LOCATIONS_CALLBACK, "work == nullptr.");
|
||||
return false;
|
||||
}
|
||||
JsContext *context = new (std::nothrow) JsContext(m_env);
|
||||
context->m_env = m_env;
|
||||
context->m_thisVarRef = m_thisVarRef;
|
||||
context->m_handlerCb = m_handlerCb;
|
||||
context->m_jsEvent = jsEvent;
|
||||
work->data = context;
|
||||
uv_queue_work(
|
||||
loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
JsContext *context = nullptr;
|
||||
napi_handle_scope scope = nullptr;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(CACHED_LOCATIONS_CALLBACK, "work is nullptr");
|
||||
return;
|
||||
}
|
||||
context = static_cast<JsContext *>(work->data);
|
||||
if (context == nullptr) {
|
||||
LBSLOGE(CACHED_LOCATIONS_CALLBACK, "context is nullptr");
|
||||
return;
|
||||
}
|
||||
napi_open_handle_scope(context->m_env, &scope);
|
||||
if (scope == nullptr) {
|
||||
LBSLOGE(CACHED_LOCATIONS_CALLBACK, "scope is nullptr");
|
||||
// close handle scope, release napi_value
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
return;
|
||||
}
|
||||
if (context->m_handlerCb != nullptr) {
|
||||
napi_value thisVar = nullptr;
|
||||
napi_get_reference_value(context->m_env, context->m_thisVarRef, &thisVar);
|
||||
napi_value undefine;
|
||||
napi_value handler = nullptr;
|
||||
napi_get_undefined(context->m_env, &undefine);
|
||||
napi_get_reference_value(context->m_env, context->m_handlerCb, &handler);
|
||||
if (napi_call_function(context->m_env, thisVar, handler, 1,
|
||||
&context->m_jsEvent, &undefine) != napi_ok) {
|
||||
LBSLOGE(CACHED_LOCATIONS_CALLBACK, "Report event failed");
|
||||
}
|
||||
}
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
delete context;
|
||||
context = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void CachedLocationsCallbackHost::OnCacheLocationsReport(const std::vector<std::unique_ptr<Location>>& locations)
|
||||
{
|
||||
LBSLOGD(CACHED_LOCATIONS_CALLBACK, "CachedLocationsCallbackHost::OnCacheLocationsReport");
|
||||
Send(locations);
|
||||
}
|
||||
|
||||
void CachedLocationsCallbackHost::DeleteHandler()
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
napi_delete_reference(m_env, m_handlerCb);
|
||||
m_handlerCb = nullptr;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "gnss_status_callback_host.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
#include "location_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
GnssStatusCallbackHost::GnssStatusCallbackHost()
|
||||
{
|
||||
m_env = nullptr;
|
||||
m_handlerCb = nullptr;
|
||||
m_thisVarRef = nullptr;
|
||||
m_remoteDied = false;
|
||||
m_lastCallingPid = 0;
|
||||
m_lastCallingUid = 0;
|
||||
}
|
||||
|
||||
GnssStatusCallbackHost::~GnssStatusCallbackHost()
|
||||
{
|
||||
}
|
||||
|
||||
int GnssStatusCallbackHost::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
LBSLOGD(GNSS_STATUS_CALLBACK, "GnssStatusCallbackHost::OnRemoteRequest!");
|
||||
if (m_remoteDied) {
|
||||
LBSLOGD(GNSS_STATUS_CALLBACK, "Failed to `%{public}s`,Remote service is died!", __func__);
|
||||
return -1;
|
||||
}
|
||||
int uid = IPCSkeleton::GetCallingUid();
|
||||
if (uid > SYSTEM_UID) {
|
||||
LBSLOGE(GNSS_STATUS_CALLBACK, "invalid uid!");
|
||||
return false;
|
||||
}
|
||||
switch (code) {
|
||||
case RECEIVE_STATUS_INFO_EVENT: {
|
||||
std::unique_ptr<SatelliteStatus> statusInfo = SatelliteStatus::Unmarshalling(data);
|
||||
OnStatusChange(statusInfo);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GnssStatusCallbackHost::IsRemoteDied()
|
||||
{
|
||||
return m_remoteDied;
|
||||
}
|
||||
|
||||
bool GnssStatusCallbackHost::Send(const std::unique_ptr<SatelliteStatus>& statusInfo)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(m_env, &scope);
|
||||
|
||||
napi_value jsEvent = nullptr;
|
||||
if (statusInfo != nullptr) {
|
||||
napi_create_object(m_env, &jsEvent);
|
||||
SatelliteStatusToJs(m_env, statusInfo, jsEvent);
|
||||
}
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(m_env, &loop);
|
||||
if (loop == nullptr) {
|
||||
LBSLOGE(GNSS_STATUS_CALLBACK, "loop == nullptr.");
|
||||
return false;
|
||||
}
|
||||
uv_work_t *work = new uv_work_t;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(GNSS_STATUS_CALLBACK, "work == nullptr.");
|
||||
return false;
|
||||
}
|
||||
JsContext *context = new (std::nothrow) JsContext(m_env);
|
||||
context->m_env = m_env;
|
||||
context->m_thisVarRef = m_thisVarRef;
|
||||
context->m_handlerCb = m_handlerCb;
|
||||
context->m_jsEvent = jsEvent;
|
||||
work->data = context;
|
||||
|
||||
uv_queue_work(
|
||||
loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
JsContext *context = nullptr;
|
||||
napi_handle_scope scope = nullptr;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "work is nullptr!");
|
||||
return;
|
||||
}
|
||||
context = static_cast<JsContext *>(work->data);
|
||||
if (context == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!");
|
||||
return;
|
||||
}
|
||||
napi_open_handle_scope(context->m_env, &scope);
|
||||
if (scope == nullptr) {
|
||||
LBSLOGE(GNSS_STATUS_CALLBACK, "scope is nullptr");
|
||||
// close handle scope, release napi_value
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
return;
|
||||
}
|
||||
if (context->m_handlerCb != nullptr) {
|
||||
napi_value thisVar = nullptr;
|
||||
napi_get_reference_value(context->m_env, context->m_thisVarRef, &thisVar);
|
||||
napi_value undefine;
|
||||
napi_value handler = nullptr;
|
||||
napi_get_undefined(context->m_env, &undefine);
|
||||
napi_get_reference_value(context->m_env, context->m_handlerCb, &handler);
|
||||
if (napi_call_function(context->m_env, thisVar, handler, 1,
|
||||
&context->m_jsEvent, &undefine) != napi_ok) {
|
||||
LBSLOGE(GNSS_STATUS_CALLBACK, "Report event failed");
|
||||
}
|
||||
}
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
delete context;
|
||||
context = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void GnssStatusCallbackHost::OnStatusChange(const std::unique_ptr<SatelliteStatus>& statusInfo)
|
||||
{
|
||||
LBSLOGD(GNSS_STATUS_CALLBACK, "GnssStatusCallbackHost::OnStatusChange");
|
||||
Send(statusInfo);
|
||||
}
|
||||
|
||||
void GnssStatusCallbackHost::DeleteHandler()
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
napi_delete_reference(m_env, m_handlerCb);
|
||||
m_handlerCb = nullptr;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "location_switch_callback_host.h"
|
||||
#include "common_utils.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "i_switch_callback.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
LocationSwitchCallbackHost::LocationSwitchCallbackHost()
|
||||
{
|
||||
m_env = nullptr;
|
||||
m_handlerCb = nullptr;
|
||||
m_thisVarRef = nullptr;
|
||||
m_remoteDied = false;
|
||||
m_fixNumber = 0;
|
||||
m_lastCallingPid = 0;
|
||||
m_lastCallingUid = 0;
|
||||
}
|
||||
|
||||
LocationSwitchCallbackHost::~LocationSwitchCallbackHost()
|
||||
{
|
||||
}
|
||||
|
||||
int LocationSwitchCallbackHost::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
LBSLOGD(SWITCH_CALLBACK, "LocatorCallbackHost::OnRemoteRequest!");
|
||||
if (m_remoteDied) {
|
||||
LBSLOGD(SWITCH_CALLBACK, "Failed to `%{public}s`,Remote service is died!", __func__);
|
||||
return -1;
|
||||
}
|
||||
int uid = IPCSkeleton::GetCallingUid();
|
||||
if (uid > SYSTEM_UID) {
|
||||
LBSLOGE(SWITCH_CALLBACK, "invalid uid!");
|
||||
return false;
|
||||
}
|
||||
switch (code) {
|
||||
case RECEIVE_SWITCH_STATE_EVENT: {
|
||||
OnSwitchChange(data.ReadInt32());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool LocationSwitchCallbackHost::IsRemoteDied()
|
||||
{
|
||||
return m_remoteDied;
|
||||
}
|
||||
|
||||
napi_value LocationSwitchCallbackHost::PackResult(int switchState)
|
||||
{
|
||||
napi_value result;
|
||||
napi_get_boolean(m_env, (switchState == 1), &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LocationSwitchCallbackHost::Send(int switchState)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
|
||||
napi_value jsEvent = PackResult(switchState);
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(m_env, &loop);
|
||||
if (loop == nullptr) {
|
||||
LBSLOGE(SWITCH_CALLBACK, "loop == nullptr.");
|
||||
return false;
|
||||
}
|
||||
uv_work_t *work = new uv_work_t;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(SWITCH_CALLBACK, "work == nullptr.");
|
||||
return false;
|
||||
}
|
||||
|
||||
JsContext *context = new (std::nothrow) JsContext(m_env);
|
||||
context->m_env = m_env;
|
||||
context->m_thisVarRef = m_thisVarRef;
|
||||
context->m_handlerCb = m_handlerCb;
|
||||
context->m_jsEvent = jsEvent;
|
||||
work->data = context;
|
||||
|
||||
uv_queue_work(
|
||||
loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
JsContext *context = nullptr;
|
||||
napi_handle_scope scope = nullptr;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "work is nullptr!");
|
||||
return;
|
||||
}
|
||||
context = static_cast<JsContext *>(work->data);
|
||||
if (context == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!");
|
||||
return;
|
||||
}
|
||||
napi_open_handle_scope(context->m_env, &scope);
|
||||
if (scope == nullptr) {
|
||||
LBSLOGE(SWITCH_CALLBACK, "scope is nullptr");
|
||||
// close handle scope, release napi_value
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
return;
|
||||
}
|
||||
if (context->m_handlerCb != nullptr) {
|
||||
napi_value thisVar = nullptr;
|
||||
napi_get_reference_value(context->m_env, context->m_thisVarRef, &thisVar);
|
||||
napi_value undefine;
|
||||
napi_value handler = nullptr;
|
||||
napi_get_undefined(context->m_env, &undefine);
|
||||
napi_get_reference_value(context->m_env, context->m_handlerCb, &handler);
|
||||
if (napi_call_function(context->m_env, thisVar, handler, 1,
|
||||
&context->m_jsEvent, &undefine) != napi_ok) {
|
||||
LBSLOGE(SWITCH_CALLBACK, "Report event failed");
|
||||
}
|
||||
}
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
delete context;
|
||||
context = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LocationSwitchCallbackHost::OnSwitchChange(int switchState)
|
||||
{
|
||||
LBSLOGD(SWITCH_CALLBACK, "LocatorCallbackHost::OnSwitchChange");
|
||||
Send(switchState);
|
||||
}
|
||||
|
||||
void LocationSwitchCallbackHost::DeleteHandler()
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
napi_delete_reference(m_env, m_handlerCb);
|
||||
m_handlerCb = nullptr;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
602
interfaces/innerkits/locator_standard/src/location_util.cpp
Normal file
602
interfaces/innerkits/locator_standard/src/location_util.cpp
Normal file
@ -0,0 +1,602 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "location_util.h"
|
||||
#include <string>
|
||||
#include "common_utils.h"
|
||||
#include "geo_address.h"
|
||||
#include "lbs_log.h"
|
||||
#include "request_config.h"
|
||||
#include "securec.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
TraceFuncCall::TraceFuncCall(std::string funcName): m_funcName(funcName)
|
||||
{
|
||||
if (m_isTrace) {
|
||||
m_startTime = std::chrono::steady_clock::now();
|
||||
LBSLOGD(LOCATOR_STANDARD, "Call func: %{public}s (start)", m_funcName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
TraceFuncCall::~TraceFuncCall()
|
||||
{
|
||||
if (m_isTrace) {
|
||||
auto us = std::chrono::duration_cast<std::chrono::microseconds>
|
||||
(std::chrono::steady_clock::now() - m_startTime).count();
|
||||
constexpr int usForPerMs = 1000;
|
||||
LBSLOGD(LOCATOR_STANDARD, "Call func: %{public}s (end), time cost:%{public}lldus, %{public}lldms",
|
||||
m_funcName.c_str(), us, us / usForPerMs);
|
||||
}
|
||||
}
|
||||
|
||||
napi_value UndefinedNapiValue(const napi_env& env)
|
||||
{
|
||||
napi_value result;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void SatelliteStatusToJs(const napi_env& env, const std::unique_ptr<SatelliteStatus>& statusInfo, napi_value& result)
|
||||
{
|
||||
napi_value satelliteIdsArray;
|
||||
napi_value cn0Array;
|
||||
napi_value altitudesArray;
|
||||
napi_value azimuthsArray;
|
||||
napi_value carrierFrequenciesArray;
|
||||
uint32_t idx1 = 0;
|
||||
SetValueDouble(env, "satellitesNumber", statusInfo->GetSatellitesNumber(), result);
|
||||
if (statusInfo->GetSatellitesNumber() > 0) {
|
||||
napi_create_array_with_length(env, statusInfo->GetSatellitesNumber(), &satelliteIdsArray);
|
||||
napi_create_array_with_length(env, statusInfo->GetSatellitesNumber(), &cn0Array);
|
||||
napi_create_array_with_length(env, statusInfo->GetSatellitesNumber(), &altitudesArray);
|
||||
napi_create_array_with_length(env, statusInfo->GetSatellitesNumber(), &azimuthsArray);
|
||||
napi_create_array_with_length(env, statusInfo->GetSatellitesNumber(), &carrierFrequenciesArray);
|
||||
for (int index = 0; index < statusInfo->GetSatellitesNumber(); index++) {
|
||||
napi_value value = nullptr;
|
||||
napi_status status = napi_ok;
|
||||
status = napi_create_double(env, statusInfo->GetSatelliteIds()[index], &value);
|
||||
status = napi_set_element(env, satelliteIdsArray, idx1, value);
|
||||
status = napi_create_double(env, statusInfo->GetCarrierToNoiseDensitys()[index], &value);
|
||||
status = napi_set_element(env, cn0Array, idx1, value);
|
||||
status = napi_create_double(env, statusInfo->GetAltitudes()[index], &value);
|
||||
status = napi_set_element(env, altitudesArray, idx1, value);
|
||||
status = napi_create_double(env, statusInfo->GetAzimuths()[index], &value);
|
||||
status = napi_set_element(env, azimuthsArray, idx1, value);
|
||||
status = napi_create_double(env, statusInfo->GetCarrierFrequencies()[index], &value);
|
||||
status = napi_set_element(env, carrierFrequenciesArray, idx1, value);
|
||||
if (status != napi_ok) {
|
||||
return;
|
||||
}
|
||||
idx1++;
|
||||
}
|
||||
SetValueStringArray(env, "satelliteIds", satelliteIdsArray, result);
|
||||
SetValueStringArray(env, "carrierToNoiseDensitys", satelliteIdsArray, result);
|
||||
SetValueStringArray(env, "altitudes", satelliteIdsArray, result);
|
||||
SetValueStringArray(env, "azimuths", satelliteIdsArray, result);
|
||||
SetValueStringArray(env, "carrierFrequencies", satelliteIdsArray, result);
|
||||
}
|
||||
}
|
||||
|
||||
void LocationsToJs(const napi_env& env, const std::vector<std::unique_ptr<Location>>& locations, napi_value& result)
|
||||
{
|
||||
if (locations.size() > 0) {
|
||||
for (int index = 0; index < locations.size(); index++) {
|
||||
napi_value value;
|
||||
napi_status status;
|
||||
LocationToJs(env, locations[index], value);
|
||||
status = napi_set_element(env, result, index, value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "napi set element error: %{public}d, idx: %{public}d", status, index - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocationToJs(const napi_env& env, const std::unique_ptr<Location>& locationInfo, napi_value& result)
|
||||
{
|
||||
SetValueDouble(env, "latitude", locationInfo->GetLatitude(), result);
|
||||
SetValueDouble(env, "longitude", locationInfo->GetLongitude(), result);
|
||||
SetValueDouble(env, "altitude", locationInfo->GetAltitude(), result);
|
||||
SetValueDouble(env, "accuracy", locationInfo->GetAccuracy(), result);
|
||||
SetValueDouble(env, "speed", locationInfo->GetSpeed(), result);
|
||||
SetValueInt64(env, "timeStamp", locationInfo->GetTimeStamp(), result);
|
||||
SetValueDouble(env, "direction", locationInfo->GetDirection(), result);
|
||||
SetValueInt64(env, "timeSinceBoot", locationInfo->GetTimeSinceBoot(), result);
|
||||
}
|
||||
|
||||
bool GeoAddressesToJsObj(const napi_env& env,
|
||||
std::list<std::shared_ptr<GeoAddress>>& replyList, napi_value& arrayResult)
|
||||
{
|
||||
uint32_t idx = 0;
|
||||
napi_status status;
|
||||
for (auto iter = replyList.begin(); iter != replyList.end(); ++iter) {
|
||||
auto geoAddress = *iter;
|
||||
napi_value eachObj;
|
||||
napi_create_object(env, &eachObj);
|
||||
SetValueDouble(env, "latitude", geoAddress->GetLatitude(), eachObj);
|
||||
SetValueDouble(env, "longitude", geoAddress->GetLongitude(), eachObj);
|
||||
SetValueUtf8String(env, "locale", geoAddress->m_localeLanguage.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "placeName", geoAddress->m_placeName.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "countryCode", geoAddress->m_countryCode.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "countryName", geoAddress->m_countryName.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "administrativeArea", geoAddress->m_administrativeArea.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "subAdministrativeArea", geoAddress->m_subAdministrativeArea.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "locality", geoAddress->m_locality.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "subLocality", geoAddress->m_subLocality.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "roadName", geoAddress->m_roadName.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "subRoadName", geoAddress->m_subRoadName.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "premises", geoAddress->m_premises.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "postalCode", geoAddress->m_postalCode.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "phoneNumber", geoAddress->m_phoneNumber.c_str(), eachObj);
|
||||
SetValueUtf8String(env, "addressUrl", geoAddress->m_addressUrl.c_str(), eachObj);
|
||||
napi_value descriptionArray;
|
||||
uint32_t idx1 = 0;
|
||||
if (geoAddress->m_descriptionsSize > 0) {
|
||||
napi_create_array_with_length(env, geoAddress->m_descriptionsSize, &descriptionArray);
|
||||
for (int index = 0; index < geoAddress->m_descriptionsSize; index++) {
|
||||
napi_value value;
|
||||
status = napi_create_string_utf8(env, geoAddress->GetDescriptions(index).c_str(),
|
||||
NAPI_AUTO_LENGTH, &value);
|
||||
status = napi_set_element(env, descriptionArray, idx1++, value);
|
||||
if (status != napi_ok) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
SetValueStringArray(env, "descriptions", descriptionArray, eachObj);
|
||||
}
|
||||
SetValueInt32(env, "descriptionsSize", geoAddress->m_descriptionsSize, eachObj);
|
||||
status = napi_set_element(env, arrayResult, idx++, eachObj);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "napi set element error: %{public}d, idx: %{public}d", status, idx - 1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void JsObjToCachedLocationRequest(const napi_env& env, const napi_value& object,
|
||||
std::unique_ptr<CachedGnssLoactionsRequest>& request)
|
||||
{
|
||||
int value = 0;
|
||||
bool valueBool;
|
||||
JsObjectToInt(env, object, "reportingPeriodSec", value);
|
||||
request->reportingPeriodSec = value;
|
||||
JsObjectToBool(env, object, "wakeUpCacheQueueFull", valueBool);
|
||||
request->wakeUpCacheQueueFull = valueBool;
|
||||
}
|
||||
|
||||
void JsObjToGeoFenceRequest(const napi_env& env, const napi_value& object,
|
||||
std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
int value = 0;
|
||||
double doubleValue = 0.0;
|
||||
JsObjectToInt(env, object, "priority", value);
|
||||
request->priority = value;
|
||||
JsObjectToInt(env, object, "scenario", value);
|
||||
request->scenario = value;
|
||||
JsObjectToDouble(env, object, "latitude", doubleValue);
|
||||
request->geofence.latitude = doubleValue;
|
||||
JsObjectToDouble(env, object, "longitude", doubleValue);
|
||||
request->geofence.longitude = doubleValue;
|
||||
JsObjectToDouble(env, object, "radius", doubleValue);
|
||||
request->geofence.radius = doubleValue;
|
||||
JsObjectToDouble(env, object, "expiration", doubleValue);
|
||||
request->geofence.expiration = doubleValue;
|
||||
}
|
||||
|
||||
void JsObjToLocationRequest(const napi_env& env, const napi_value& object,
|
||||
std::unique_ptr<RequestConfig>& requestConfig)
|
||||
{
|
||||
int value = 0;
|
||||
double valueDouble = 0.0;
|
||||
JsObjectToInt(env, object, "priority", value);
|
||||
requestConfig->SetPriority(value);
|
||||
JsObjectToInt(env, object, "scenario", value);
|
||||
requestConfig->SetScenario(value);
|
||||
JsObjectToInt(env, object, "timeInterval", value);
|
||||
requestConfig->SetTimeInterval(value);
|
||||
JsObjectToDouble(env, object, "maxAccuracy", valueDouble);
|
||||
requestConfig->SetMaxAccuracy(valueDouble);
|
||||
JsObjectToInt(env, object, "distanceInterval", value);
|
||||
requestConfig->SetDistanceInterval(value);
|
||||
}
|
||||
|
||||
void JsObjToCommand(const napi_env& env, const napi_value& object,
|
||||
std::unique_ptr<LocationCommand>& commandConfig)
|
||||
{
|
||||
int value = 0;
|
||||
std::string command = "";
|
||||
JsObjectToInt(env, object, "scenario", value);
|
||||
commandConfig->scenario = value;
|
||||
JsObjectToString(env, object, "command", 100, command);
|
||||
commandConfig->command = command;
|
||||
}
|
||||
|
||||
bool JsObjToGeoCodeRequest(const napi_env& env, const napi_value& object, MessageParcel& dataParcel)
|
||||
{
|
||||
std::string description = "";
|
||||
int maxItems = 0;
|
||||
double minLatitude = 0.0;
|
||||
double minLongitude = 0.0;
|
||||
double maxLatitude = 0.0;
|
||||
double maxLongitude = 0.0;
|
||||
std::string locale = "";
|
||||
|
||||
JsObjectToString(env, object, "locale", 100, locale);
|
||||
JsObjectToString(env, object, "description", 100, description);
|
||||
JsObjectToInt(env, object, "maxItems", maxItems);
|
||||
JsObjectToDouble(env, object, "minLatitude", minLatitude);
|
||||
JsObjectToDouble(env, object, "minLongitude", minLongitude);
|
||||
JsObjectToDouble(env, object, "maxLatitude", maxLatitude);
|
||||
JsObjectToDouble(env, object, "maxLongitude", maxLongitude);
|
||||
|
||||
if (minLatitude < -90.0 || minLatitude > 90.0) {
|
||||
return false;
|
||||
}
|
||||
if (minLongitude < -180.0 || minLongitude > 180.0) {
|
||||
return false;
|
||||
}
|
||||
if (maxLatitude < -90.0 || maxLatitude > 90.0) {
|
||||
return false;
|
||||
}
|
||||
if (maxLongitude < -180.0 || maxLongitude > 180.0) {
|
||||
return false;
|
||||
}
|
||||
std::string str = "";
|
||||
dataParcel.WriteString(description);
|
||||
dataParcel.WriteDouble(minLatitude); // latitude
|
||||
dataParcel.WriteDouble(minLongitude); // longitude
|
||||
dataParcel.WriteDouble(maxLatitude); // latitude
|
||||
dataParcel.WriteDouble(maxLongitude); // longitude
|
||||
dataParcel.WriteInt32(maxItems); // maxItems
|
||||
dataParcel.WriteInt32(1); // locale object size = 1
|
||||
dataParcel.WriteString16(Str8ToStr16(locale)); // locale.getLanguage()
|
||||
dataParcel.WriteString16(Str8ToStr16(str)); // locale.getCountry()
|
||||
dataParcel.WriteString16(Str8ToStr16(str)); // locale.getVariant()
|
||||
dataParcel.WriteString16(Str8ToStr16(str)); // ""
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsObjToReverseGeoCodeRequest(const napi_env& env, const napi_value& object, MessageParcel& dataParcel)
|
||||
{
|
||||
double latitude;
|
||||
double longitude;
|
||||
int maxItems;
|
||||
std::string locale = "";
|
||||
|
||||
JsObjectToDouble(env, object, "latitude", latitude);
|
||||
JsObjectToDouble(env, object, "longitude", longitude);
|
||||
JsObjectToInt(env, object, "maxItems", maxItems);
|
||||
JsObjectToString(env, object, "locale", 100, locale);
|
||||
|
||||
if (latitude < -90.0 || latitude > 90.0) {
|
||||
return false;
|
||||
}
|
||||
if (longitude < -180.0 || longitude > 180.0) {
|
||||
return false;
|
||||
}
|
||||
std::string str = "";
|
||||
dataParcel.WriteDouble(latitude); // latitude
|
||||
dataParcel.WriteDouble(longitude); // longitude
|
||||
dataParcel.WriteInt32(maxItems); // maxItems
|
||||
dataParcel.WriteInt32(1); // locale object size = 1
|
||||
dataParcel.WriteString16(Str8ToStr16(locale)); // locale.getLanguage()
|
||||
dataParcel.WriteString16(Str8ToStr16(str)); // locale.getCountry()
|
||||
dataParcel.WriteString16(Str8ToStr16(str)); // locale.getVariant()
|
||||
dataParcel.WriteString16(Str8ToStr16(str)); // ""
|
||||
return true;
|
||||
}
|
||||
|
||||
napi_value JsObjectToString(const napi_env& env, const napi_value& object,
|
||||
const char* fieldStr, const int bufLen, std::string& fieldRef)
|
||||
{
|
||||
bool hasProperty = false;
|
||||
NAPI_CALL(env, napi_has_named_property(env, object, fieldStr, &hasProperty));
|
||||
if (hasProperty) {
|
||||
napi_value field;
|
||||
napi_valuetype valueType;
|
||||
|
||||
napi_get_named_property(env, object, fieldStr, &field);
|
||||
NAPI_CALL(env, napi_typeof(env, field, &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_string, "Wrong argument type. String expected.");
|
||||
if (bufLen <= 0) {
|
||||
goto error;
|
||||
}
|
||||
char *buf = (char *)malloc(bufLen);
|
||||
if (buf == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Js object to str malloc failed!");
|
||||
goto error;
|
||||
}
|
||||
(void)memset_s(buf, bufLen, 0, bufLen);
|
||||
size_t result = 0;
|
||||
NAPI_CALL(env, napi_get_value_string_utf8(env, field, buf, bufLen, &result));
|
||||
fieldRef = buf;
|
||||
free(buf);
|
||||
buf = nullptr;
|
||||
} else {
|
||||
LBSLOGD(LOCATOR_STANDARD, "Js obj to str no property: %{public}s", fieldStr);
|
||||
}
|
||||
|
||||
error:
|
||||
return UndefinedNapiValue(env);
|
||||
}
|
||||
|
||||
napi_value JsObjectToDouble(const napi_env& env, const napi_value& object, const char* fieldStr, double& fieldRef)
|
||||
{
|
||||
bool hasProperty = false;
|
||||
NAPI_CALL(env, napi_has_named_property(env, object, fieldStr, &hasProperty));
|
||||
if (hasProperty) {
|
||||
napi_value field;
|
||||
napi_valuetype valueType;
|
||||
|
||||
napi_get_named_property(env, object, fieldStr, &field);
|
||||
NAPI_CALL(env, napi_typeof(env, field, &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_number, "Wrong argument type. Number expected.");
|
||||
napi_get_value_double(env, field, &fieldRef);
|
||||
} else {
|
||||
LBSLOGD(LOCATOR_STANDARD, "Js to int no property: %{public}s", fieldStr);
|
||||
}
|
||||
return UndefinedNapiValue(env);
|
||||
}
|
||||
|
||||
napi_value JsObjectToInt(const napi_env& env, const napi_value& object, const char* fieldStr, int& fieldRef)
|
||||
{
|
||||
bool hasProperty = false;
|
||||
NAPI_CALL(env, napi_has_named_property(env, object, fieldStr, &hasProperty));
|
||||
if (hasProperty) {
|
||||
napi_value field;
|
||||
napi_valuetype valueType;
|
||||
|
||||
napi_get_named_property(env, object, fieldStr, &field);
|
||||
NAPI_CALL(env, napi_typeof(env, field, &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_number, "Wrong argument type. Number expected.");
|
||||
napi_get_value_int32(env, field, &fieldRef);
|
||||
} else {
|
||||
LBSLOGD(LOCATOR_STANDARD, "Js to int no property: %{public}s", fieldStr);
|
||||
}
|
||||
return UndefinedNapiValue(env);
|
||||
}
|
||||
|
||||
napi_value JsObjectToBool(const napi_env& env, const napi_value& object, const char* fieldStr, bool& fieldRef)
|
||||
{
|
||||
bool hasProperty = false;
|
||||
NAPI_CALL(env, napi_has_named_property(env, object, fieldStr, &hasProperty));
|
||||
if (hasProperty) {
|
||||
napi_value field;
|
||||
napi_valuetype valueType;
|
||||
|
||||
napi_get_named_property(env, object, fieldStr, &field);
|
||||
NAPI_CALL(env, napi_typeof(env, field, &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_boolean, "Wrong argument type. Bool expected.");
|
||||
napi_get_value_bool(env, field, &fieldRef);
|
||||
} else {
|
||||
LBSLOGD(LOCATOR_STANDARD, "Js to bool no property: %{public}s", fieldStr);
|
||||
}
|
||||
return UndefinedNapiValue(env);
|
||||
}
|
||||
|
||||
napi_status SetValueUtf8String(const napi_env& env, const char* fieldStr, const char* str, napi_value& result)
|
||||
{
|
||||
napi_value value;
|
||||
napi_status status = napi_create_string_utf8(env, str, NAPI_AUTO_LENGTH, &value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set value create utf8 string error! field:%{public}s", fieldStr);
|
||||
return status;
|
||||
}
|
||||
status = napi_set_named_property(env, result, fieldStr, value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set utf8 string named property error!, field:%{public}s", fieldStr);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
napi_status SetValueStringArray(const napi_env& env, const char* fieldStr, napi_value& value, napi_value& result)
|
||||
{
|
||||
napi_status status = napi_set_named_property(env, result, fieldStr, value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set int32 named property error! field:%{public}s", fieldStr);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
napi_status SetValueInt32(const napi_env& env, const char* fieldStr, const int intValue, napi_value& result)
|
||||
{
|
||||
napi_value value;
|
||||
napi_status status = napi_create_int32(env, intValue, &value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set value create int32 error! field:%{public}s", fieldStr);
|
||||
return status;
|
||||
}
|
||||
status = napi_set_named_property(env, result, fieldStr, value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set int32 named property error! field:%{public}s", fieldStr);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
napi_status SetValueInt64(const napi_env& env, const char* fieldStr, const int64_t intValue, napi_value& result)
|
||||
{
|
||||
napi_value value;
|
||||
napi_status status = napi_create_int64(env, intValue, &value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set value create int64 error! field:%{public}s", fieldStr);
|
||||
return status;
|
||||
}
|
||||
status = napi_set_named_property(env, result, fieldStr, value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set int64 named property error! field:%{public}s", fieldStr);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
napi_status SetValueDouble(const napi_env& env, const char* fieldStr, const double doubleValue, napi_value& result)
|
||||
{
|
||||
napi_value value;
|
||||
napi_status status = napi_create_double(env, doubleValue, &value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set value create double error! field:%{public}s", fieldStr);
|
||||
return status;
|
||||
}
|
||||
status = napi_set_named_property(env, result, fieldStr, value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set double named property error! field:%{public}s", fieldStr);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
napi_status SetValueBool(const napi_env& env, const char* fieldStr, const bool boolvalue, napi_value& result)
|
||||
{
|
||||
napi_value value;
|
||||
napi_status status = napi_get_boolean(env, boolvalue, &value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set value create boolean error! field:%{public}s", fieldStr);
|
||||
return status;
|
||||
}
|
||||
status = napi_set_named_property(env, result, fieldStr, value);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Set boolean named property error! field:%{public}s", fieldStr);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static napi_value InitAsyncCallBackEnv(const napi_env& env, AsyncContext* asyncContext,
|
||||
const size_t argc, const napi_value* argv, const size_t nonCallbackArgNum)
|
||||
{
|
||||
for (size_t i = nonCallbackArgNum; i != argc; ++i) {
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[i], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[i], 1, &asyncContext->callback[i - nonCallbackArgNum]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value InitAsyncPromiseEnv(const napi_env& env, AsyncContext *asyncContext, napi_value& promise)
|
||||
{
|
||||
napi_deferred deferred;
|
||||
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
|
||||
asyncContext->deferred = deferred;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value DoCallBackAsyncWork(const napi_env& env, AsyncContext* asyncContext)
|
||||
{
|
||||
napi_create_async_work(
|
||||
env,
|
||||
nullptr,
|
||||
asyncContext->resourceName,
|
||||
[](napi_env env, void* data) {
|
||||
if (data == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Async data parameter is null");
|
||||
return;
|
||||
}
|
||||
AsyncContext* context = (AsyncContext *)data;
|
||||
context->executeFunc(context);
|
||||
},
|
||||
[](napi_env env, napi_status status, void* data) {
|
||||
if (data == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Async data parameter is null");
|
||||
return;
|
||||
}
|
||||
AsyncContext* context = (AsyncContext *)data;
|
||||
napi_value undefine;
|
||||
napi_get_undefined(env, &undefine);
|
||||
napi_value callback;
|
||||
context->completeFunc(data);
|
||||
|
||||
if (context->errCode != SUCCESS) {
|
||||
napi_value message = nullptr;
|
||||
std::string msg = "errCode is " + std::to_string(context->errCode);
|
||||
napi_create_string_utf8(env, msg.c_str(), NAPI_AUTO_LENGTH, &message);
|
||||
napi_create_error(env, nullptr, message, &context->result[PARAM0]);
|
||||
napi_get_undefined(env, &context->result[PARAM1]);
|
||||
} else {
|
||||
napi_get_undefined(env, &context->result[PARAM0]);
|
||||
}
|
||||
napi_get_reference_value(env, context->callback[0], &callback);
|
||||
napi_call_function(env, nullptr, callback, RESULT_SIZE, context->result, &undefine);
|
||||
if (context->callback[0] != nullptr) {
|
||||
napi_delete_reference(env, context->callback[0]);
|
||||
}
|
||||
if (context->callback[1] != nullptr) {
|
||||
napi_delete_reference(env, context->callback[1]);
|
||||
}
|
||||
napi_delete_async_work(env, context->work);
|
||||
delete context;
|
||||
},
|
||||
(void*)asyncContext,
|
||||
&asyncContext->work);
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asyncContext->work));
|
||||
return UndefinedNapiValue(env);
|
||||
}
|
||||
|
||||
static napi_value DoPromiseAsyncWork(const napi_env& env, AsyncContext* asyncContext)
|
||||
{
|
||||
napi_create_async_work(
|
||||
env,
|
||||
nullptr,
|
||||
asyncContext->resourceName,
|
||||
[](napi_env env, void* data) {
|
||||
if (data == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Async data parameter is null");
|
||||
return;
|
||||
}
|
||||
AsyncContext* context = (AsyncContext*)data;
|
||||
context->executeFunc(context);
|
||||
},
|
||||
[](napi_env env, napi_status status, void* data) {
|
||||
if (data == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Async data parameter is null");
|
||||
return;
|
||||
}
|
||||
AsyncContext* context = (AsyncContext*)data;
|
||||
context->completeFunc(data);
|
||||
|
||||
if (!context->errCode) {
|
||||
napi_resolve_deferred(context->env, context->deferred, context->result[PARAM1]);
|
||||
} else {
|
||||
napi_value message = nullptr;
|
||||
std::string msg = "errCode is " + std::to_string(context->errCode);
|
||||
napi_create_string_utf8(env, msg.c_str(), NAPI_AUTO_LENGTH, &message);
|
||||
napi_create_error(env, nullptr, message, &context->result[PARAM0]);
|
||||
napi_get_undefined(env, &context->result[PARAM1]);
|
||||
napi_reject_deferred(context->env, context->deferred, context->result[PARAM0]);
|
||||
}
|
||||
napi_delete_async_work(env, context->work);
|
||||
delete context;
|
||||
},
|
||||
(void*)asyncContext,
|
||||
&asyncContext->work);
|
||||
napi_queue_async_work(env, asyncContext->work);
|
||||
return UndefinedNapiValue(env);
|
||||
}
|
||||
|
||||
napi_value DoAsyncWork(const napi_env& env, AsyncContext* asyncContext,
|
||||
const size_t argc, const napi_value* argv, const size_t nonCallbackArgNum)
|
||||
{
|
||||
if (argc > nonCallbackArgNum) {
|
||||
InitAsyncCallBackEnv(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
return DoCallBackAsyncWork(env, asyncContext);
|
||||
} else {
|
||||
napi_value promise;
|
||||
InitAsyncPromiseEnv(env, asyncContext, promise);
|
||||
DoPromiseAsyncWork(env, asyncContext);
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
37
interfaces/innerkits/locator_standard/src/locator.cpp
Normal file
37
interfaces/innerkits/locator_standard/src/locator.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "locator.h"
|
||||
#include "lbs_log.h"
|
||||
#include "locator_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
Locator::~Locator()
|
||||
{}
|
||||
|
||||
std::unique_ptr<Locator> Locator::GetInstance(int systemAbilityId)
|
||||
{
|
||||
std::unique_ptr<LocatorImpl> locator = std::make_unique<LocatorImpl>(systemAbilityId);
|
||||
if (locator != nullptr) {
|
||||
if (locator->Init()) {
|
||||
LBSLOGI(LOCATOR_STANDARD, "init successfully!");
|
||||
return locator;
|
||||
}
|
||||
}
|
||||
LBSLOGE(LOCATOR_STANDARD, "new locator_standard failed!");
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "locator_callback_host.h"
|
||||
#include "common_utils.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "i_locator_callback.h"
|
||||
#include "lbs_log.h"
|
||||
#include "location_util.h"
|
||||
#include "locator.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
LocatorCallbackHost::LocatorCallbackHost()
|
||||
{
|
||||
m_env = nullptr;
|
||||
m_handlerCb = nullptr;
|
||||
m_thisVarRef = nullptr;
|
||||
m_deferred = nullptr;
|
||||
m_lastCallingUid = 0;
|
||||
m_lastCallingPid = 0;
|
||||
m_fixNumber = 0;
|
||||
}
|
||||
|
||||
LocatorCallbackHost::~LocatorCallbackHost()
|
||||
{
|
||||
}
|
||||
|
||||
int LocatorCallbackHost::OnRemoteRequest(uint32_t code,
|
||||
MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
int uid = IPCSkeleton::GetCallingUid();
|
||||
if (uid > SYSTEM_UID) {
|
||||
LBSLOGE(SWITCH_CALLBACK, "invalid uid!");
|
||||
return false;
|
||||
}
|
||||
switch (code) {
|
||||
case RECEIVE_LOCATION_INFO_EVENT: {
|
||||
std::unique_ptr<Location> location = Location::Unmarshalling(data);
|
||||
OnLocationReport(location);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool LocatorCallbackHost::Send(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
|
||||
napi_value jsEvent = nullptr;
|
||||
if (location != nullptr) {
|
||||
napi_create_object(m_env, &jsEvent);
|
||||
LocationToJs(m_env, location, jsEvent);
|
||||
}
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(m_env, &loop);
|
||||
if (loop == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "loop == nullptr.");
|
||||
return false;
|
||||
}
|
||||
uv_work_t *work = new uv_work_t;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "work == nullptr.");
|
||||
return false;
|
||||
}
|
||||
JsContext *context = new (std::nothrow) JsContext(m_env);
|
||||
context->m_env = m_env;
|
||||
context->m_thisVarRef = m_thisVarRef;
|
||||
context->m_handlerCb = m_handlerCb;
|
||||
context->m_deferred = m_deferred;
|
||||
context->m_jsEvent = jsEvent;
|
||||
work->data = context;
|
||||
|
||||
uv_queue_work(
|
||||
loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
JsContext *context = nullptr;
|
||||
napi_handle_scope scope = nullptr;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "work is nullptr!");
|
||||
return;
|
||||
}
|
||||
context = static_cast<JsContext *>(work->data);
|
||||
if (context == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!");
|
||||
return;
|
||||
}
|
||||
napi_open_handle_scope(context->m_env, &scope);
|
||||
if (scope == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "scope is nullptr");
|
||||
// close handle scope, release napi_value
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
return;
|
||||
}
|
||||
if (context->m_handlerCb != nullptr) {
|
||||
napi_value thisVar = nullptr;
|
||||
napi_get_reference_value(context->m_env, context->m_thisVarRef, &thisVar);
|
||||
napi_value undefine;
|
||||
napi_value handler = nullptr;
|
||||
napi_get_undefined(context->m_env, &undefine);
|
||||
napi_get_reference_value(context->m_env, context->m_handlerCb, &handler);
|
||||
if (napi_call_function(context->m_env, thisVar, handler, 1,
|
||||
&context->m_jsEvent, &undefine) != napi_ok) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "Report event failed");
|
||||
}
|
||||
} else if (context->m_deferred != nullptr) {
|
||||
if (context->m_jsEvent != nullptr) {
|
||||
napi_resolve_deferred(context->m_env, context->m_deferred, context->m_jsEvent);
|
||||
} else {
|
||||
napi_reject_deferred(context->m_env, context->m_deferred, context->m_jsEvent);
|
||||
}
|
||||
}
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
delete context;
|
||||
context = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LocatorCallbackHost::OnLocationReport(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
Send(location);
|
||||
}
|
||||
|
||||
void LocatorCallbackHost::OnLocatingStatusChange(const int status)
|
||||
{
|
||||
}
|
||||
|
||||
void LocatorCallbackHost::OnErrorReport(const int errorCode)
|
||||
{
|
||||
Send(nullptr);
|
||||
}
|
||||
|
||||
void LocatorCallbackHost::DeleteHandler()
|
||||
{
|
||||
LBSLOGD(LOCATOR_CALLBACK, "before DeleteHandler");
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
napi_delete_reference(m_env, m_handlerCb);
|
||||
m_handlerCb = nullptr;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
245
interfaces/innerkits/locator_standard/src/locator_impl.cpp
Normal file
245
interfaces/innerkits/locator_standard/src/locator_impl.cpp
Normal file
@ -0,0 +1,245 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "locator_impl.h"
|
||||
#include "common_utils.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "lbs_log.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
LocatorImpl::LocatorImpl(int systemAbilityId) : systemAbilityId_(systemAbilityId)
|
||||
{}
|
||||
|
||||
LocatorImpl::~LocatorImpl()
|
||||
{}
|
||||
|
||||
bool LocatorImpl::Init()
|
||||
{
|
||||
client_ = std::make_unique<LocatorProxy>(CommonUtils::GetRemoteObject(LOCATION_LOCATOR_SA_ID,
|
||||
CommonUtils::InitDeviceId()));
|
||||
if (client_ == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "locator init failed. %{public}d", systemAbilityId_);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocatorImpl::IsLocationEnabled()
|
||||
{
|
||||
return client_->GetSwitchState() == 1;
|
||||
}
|
||||
|
||||
void LocatorImpl::ShowNotification()
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "ShowNotification");
|
||||
}
|
||||
|
||||
void LocatorImpl::RequestPermission(napi_env env)
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "permission need to be granted");
|
||||
}
|
||||
|
||||
void LocatorImpl::RequestEnableLocation()
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "RequestEnableLocation");
|
||||
}
|
||||
|
||||
void LocatorImpl::EnableAbility(bool enable)
|
||||
{
|
||||
client_->EnableAbility(enable);
|
||||
}
|
||||
|
||||
void LocatorImpl::StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
|
||||
sptr<ILocatorCallback>& callback)
|
||||
{
|
||||
client_->StartLocating(requestConfig, callback, "location.ILocator", 0, 0);
|
||||
}
|
||||
|
||||
void LocatorImpl::StopLocating(sptr<ILocatorCallback>& callback)
|
||||
{
|
||||
client_->StopLocating(callback);
|
||||
}
|
||||
|
||||
std::unique_ptr<Location> LocatorImpl::GetCachedLocation()
|
||||
{
|
||||
std::unique_ptr<Location> location = nullptr;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
client_->GetCacheLocation(data, reply);
|
||||
int exception = reply.ReadInt32();
|
||||
if (exception == SECURITY_EXCEPTION) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "can not get cached location without location permission.");
|
||||
} else if (exception != REPLY_NO_EXCEPTION) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "cause some exception happened in lower service.");
|
||||
} else {
|
||||
location = Location::Unmarshalling(reply);
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
bool LocatorImpl::RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
client_->RegisterSwitchCallback(callback, 10001);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocatorImpl::UnregisterSwitchCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
client_->UnregisterSwitchCallback(callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocatorImpl::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
client_->RegisterGnssStatusCallback(callback, 10001);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocatorImpl::UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
client_->UnregisterGnssStatusCallback(callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocatorImpl::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
client_->RegisterNmeaMessageCallback(callback, 10001);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocatorImpl::UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
client_->UnregisterNmeaMessageCallback(callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
void LocatorImpl::RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
sptr<ICachedLocationsCallback>& callback)
|
||||
{
|
||||
client_->RegisterCachedLocationCallback(request, callback, "location.ILocator");
|
||||
}
|
||||
|
||||
void LocatorImpl::UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback)
|
||||
{
|
||||
client_->UnregisterCachedLocationCallback(callback);
|
||||
}
|
||||
|
||||
bool LocatorImpl::IsGeoServiceAvailable()
|
||||
{
|
||||
bool result = false;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
client_->IsGeoConvertAvailable(data, reply);
|
||||
int exception = reply.ReadInt32();
|
||||
if (exception == SECURITY_EXCEPTION) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "can not get cached location without location permission.");
|
||||
} else if (exception != REPLY_NO_EXCEPTION) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "cause some exception happened in lower service.");
|
||||
} else {
|
||||
result = reply.ReadInt32() == 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void LocatorImpl::GetAddressByCoordinate(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList)
|
||||
{
|
||||
MessageParcel reply;
|
||||
client_->GetAddressByCoordinate(data, reply);
|
||||
int exception = reply.ReadInt32();
|
||||
if (exception == SECURITY_EXCEPTION) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "can not get cached location without location permission.");
|
||||
} else if (exception != REPLY_NO_EXCEPTION) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "cause some exception happened in lower service.");
|
||||
} else {
|
||||
int resultSize = reply.ReadInt32();
|
||||
if (resultSize > GeoAddress::MAX_RESULT) {
|
||||
resultSize = GeoAddress::MAX_RESULT;
|
||||
}
|
||||
for (int i = 0; i < resultSize; i++) {
|
||||
replyList.push_back(GeoAddress::Unmarshalling(reply));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorImpl::GetAddressByLocationName(MessageParcel &data, std::list<std::shared_ptr<GeoAddress>>& replyList)
|
||||
{
|
||||
MessageParcel reply;
|
||||
client_->GetAddressByLocationName(data, reply);
|
||||
int exception = reply.ReadInt32();
|
||||
if (exception == SECURITY_EXCEPTION) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "can not get cached location without location permission.");
|
||||
} else if (exception != REPLY_NO_EXCEPTION) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "cause some exception happened in lower service.");
|
||||
} else {
|
||||
int resultSize = reply.ReadInt32();
|
||||
if (resultSize > GeoAddress::MAX_RESULT) {
|
||||
resultSize = GeoAddress::MAX_RESULT;
|
||||
}
|
||||
for (int i = 0; i < resultSize; i++) {
|
||||
replyList.push_back(GeoAddress::Unmarshalling(reply));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LocatorImpl::IsLocationPrivacyConfirmed(const LocationPrivacyType type)
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::IsLocationPrivacyConfirmed()");
|
||||
return client_->IsLocationPrivacyConfirmed(type);
|
||||
}
|
||||
|
||||
void LocatorImpl::SetLocationPrivacyConfirmStatus(const LocationPrivacyType type, bool isConfirmed)
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SetLocationPrivacyConfirmStatus()");
|
||||
client_->SetLocationPrivacyConfirmStatus(type, isConfirmed);
|
||||
}
|
||||
|
||||
int LocatorImpl::GetCachedGnssLocationsSize()
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::GetCachedGnssLocationsSize()");
|
||||
return client_->GetCachedGnssLocationsSize();
|
||||
}
|
||||
|
||||
bool LocatorImpl::FlushCachedGnssLocations()
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::FlushCachedGnssLocations()");
|
||||
client_->FlushCachedGnssLocations();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocatorImpl::SendCommand(std::unique_ptr<LocationCommand>& commands)
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::SendCommand()");
|
||||
client_->SendCommand(commands);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocatorImpl::AddFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::AddFence()");
|
||||
client_->AddFence(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocatorImpl::RemoveFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::RemoveFence()");
|
||||
client_->RemoveFence(request);
|
||||
return true;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
507
interfaces/innerkits/locator_standard/src/locator_proxy.cpp
Normal file
507
interfaces/innerkits/locator_standard/src/locator_proxy.cpp
Normal file
@ -0,0 +1,507 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "locator_proxy.h"
|
||||
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_types.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
LocatorProxy::LocatorProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<ILocator>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int LocatorProxy::GetSwitchState()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "GetSwitchState remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = remote->SendRequest(GET_SWITCH_STATE, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetSwitchState Transact ErrCode = %{public}d", error);
|
||||
int state = 0;
|
||||
if (error == NO_ERROR) {
|
||||
state = reply.ReadInt32();
|
||||
}
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetSwitchState return %{public}d", state);
|
||||
return state;
|
||||
}
|
||||
|
||||
void LocatorProxy::EnableAbility(bool isEnabled)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteBool(isEnabled);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "EnableAbility remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(ENABLE_ABILITY, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::EnableAbility Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorProxy::UpdateSaAbility()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "UpdateSaAbility remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(UPDATE_SA_ABILITY, data, reply, option);
|
||||
if (error != NO_ERROR) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "Proxy::UpdateSaAbility update sa fail, ErrCodes=%{public}d", error);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorProxy::RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "uid is: %{public}d", uid);
|
||||
MessageParcel data;
|
||||
data.WriteObject<IRemoteObject>(callback);
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "RegisterSwitchCallback remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(REG_SWITCH_CALLBACK, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterSwitchCallback Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorProxy::UnregisterSwitchCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
data.WriteObject<IRemoteObject>(callback);
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "UnregisterSwitchCallback remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(UNREG_SWITCH_CALLBACK, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterSwitchCallback Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorProxy::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "uid is: %{public}d", uid);
|
||||
MessageParcel data;
|
||||
data.WriteObject<IRemoteObject>(callback);
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "RegisterGnssStatusCallback remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(REG_GNSS_STATUS_CALLBACK, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterGnssStatusCallback Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorProxy::UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
data.WriteObject<IRemoteObject>(callback);
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "UnregisterGnssStatusCallback remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(UNREG_GNSS_STATUS_CALLBACK, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterGnssStatusCallback Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorProxy::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "uid is: %{public}d", uid);
|
||||
MessageParcel data;
|
||||
data.WriteObject<IRemoteObject>(callback);
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "RegisterNmeaMessageCallback remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(REG_NMEA_CALLBACK, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterNmeaMessageCallback Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorProxy::UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
data.WriteObject<IRemoteObject>(callback);
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "UnregisterNmeaMessageCallback remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(UNREG_NMEA_CALLBACK, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterNmeaMessageCallback Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
int LocatorProxy::StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
|
||||
sptr<ILocatorCallback>& callback, std::string bundleName, pid_t pid, pid_t uid)
|
||||
{
|
||||
LBSLOGD(LOCATOR_STANDARD, "uid is: %{public}d, pid is: %{public}d", uid, pid);
|
||||
MessageParcel data;
|
||||
if (requestConfig != nullptr) {
|
||||
requestConfig->Marshalling(data);
|
||||
}
|
||||
if (callback != nullptr) {
|
||||
data.WriteObject<IRemoteObject>(callback->AsObject());
|
||||
}
|
||||
data.WriteString16(Str8ToStr16(bundleName));
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "StartLocating remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = remote->SendRequest(START_LOCATING, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::StartLocating Transact ErrCodes = %{public}d", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::StopLocating(sptr<ILocatorCallback>& callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (callback != nullptr) {
|
||||
data.WriteObject<IRemoteObject>(callback->AsObject());
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "StopLocating remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = remote->SendRequest(STOP_LOCATING, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::StopLocating Transact ErrCodes = %{public}d", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::ReportLocation(const std::unique_ptr<Location>& location, std::string abilityName)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteString(abilityName);
|
||||
if (location != nullptr) {
|
||||
location->Marshalling(data);
|
||||
}
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "ReportLocation remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = remote->SendRequest(REPORT_LOCATION, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::ReportLocation Transact ErrCodes = %{public}d", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::ReportLocationStatus(sptr<ILocatorCallback>& callback, int result)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteObject<IRemoteObject>(callback->AsObject());
|
||||
data.WriteInt32(result);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "ReportLocationStatus remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = remote->SendRequest(REPORT_LOCATION_STATUS, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::ReportLocationStatus Transact ErrCodes = %{public}d", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::ReportErrorStatus(sptr<ILocatorCallback>& callback, int result)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteObject<IRemoteObject>(callback->AsObject());
|
||||
data.WriteInt32(result);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "ReportErrorStatus remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = remote->SendRequest(REPORT_ERROR_STATUS, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::ReportErrorStatus Transact ErrCodes = %{public}d", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::GetCacheLocation(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "GetCacheLocation remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = remote->SendRequest(GET_CACHE_LOCATION, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCacheLocation Transact ErrCodes = %{public}d", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::IsGeoConvertAvailable(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int error;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "IsGeoConvertAvailable remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
error = remote->SendRequest(GEO_IS_AVAILABLE, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::IsGeoConvertAvailable result from server");
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::GetAddressByCoordinate(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int error;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "GetAddressByCoordinate remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
error = remote->SendRequest(GET_FROM_COORDINATE, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetAddressByCoordinate result from server.");
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::GetAddressByLocationName(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int error;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "GetAddressByLocationName remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
error = remote->SendRequest(GET_FROM_LOCATION_NAME, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetAddressByLocationName result from server.");
|
||||
return error;
|
||||
}
|
||||
|
||||
bool LocatorProxy::IsLocationPrivacyConfirmed(const LocationPrivacyType type)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "IsLocationPrivacyConfirmed remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
data.WriteInt32(CommonUtils::GetPrivacyType(type));
|
||||
int error = remote->SendRequest(IS_PRIVACY_COMFIRMED, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::IsLocationPrivacyConfirmed Transact ErrCode = %{public}d", error);
|
||||
bool state = false;
|
||||
if (error == NO_ERROR) {
|
||||
state = reply.ReadBool();
|
||||
}
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::IsLocationPrivacyConfirmed return %{public}d", state ? 1 : 0);
|
||||
return state;
|
||||
}
|
||||
|
||||
void LocatorProxy::SetLocationPrivacyConfirmStatus(const LocationPrivacyType type, bool isConfirmed)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInt32(CommonUtils::GetPrivacyType(type));
|
||||
data.WriteBool(isConfirmed);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "SetLocationPrivacyConfirmStatus remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(SET_PRIVACY_COMFIRM_STATUS, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::SetLocationPrivacyConfirmStatus Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
int LocatorProxy::RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
sptr<ICachedLocationsCallback>& callback, std::string bundleName)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (request != nullptr) {
|
||||
data.WriteInt32(request->reportingPeriodSec);
|
||||
data.WriteBool(request->wakeUpCacheQueueFull);
|
||||
}
|
||||
if (callback != nullptr) {
|
||||
data.WriteRemoteObject(callback->AsObject());
|
||||
}
|
||||
data.WriteString16(Str8ToStr16(bundleName));
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "RegisterCachedLocationCallback remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = remote->SendRequest(REG_CACHED_CALLBACK, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterCachedLocationCallback Transact ErrCodes = %{public}d", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (callback != nullptr) {
|
||||
data.WriteRemoteObject(callback->AsObject());
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "UnregisterCachedLocationCallback remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = remote->SendRequest(UNREG_CACHED_CALLBACK, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::UnregisterCachedLocationCallback Transact ErrCodes = %{public}d", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
int LocatorProxy::GetCachedGnssLocationsSize()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "GetCachedGnssLocationsSize remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
int error = remote->SendRequest(GET_CACHED_LOCATION_SIZE, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize Transact ErrCode = %{public}d", error);
|
||||
int size = 0;
|
||||
if (error == NO_ERROR) {
|
||||
size = reply.ReadInt32();
|
||||
}
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize return %{public}d", size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void LocatorProxy::FlushCachedGnssLocations()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "FlushCachedGnssLocations remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(FLUSH_CACHED_LOCATIONS, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::FlushCachedGnssLocations Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorProxy::SendCommand(std::unique_ptr<LocationCommand>& commands)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInt32(commands->scenario);
|
||||
data.WriteString16(Str8ToStr16(commands->command));
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "SendCommand remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(SEND_COMMAND, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::SendCommand Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorProxy::AddFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInt32(request->priority);
|
||||
data.WriteInt32(request->scenario);
|
||||
data.WriteDouble(request->geofence.latitude);
|
||||
data.WriteDouble(request->geofence.longitude);
|
||||
data.WriteDouble(request->geofence.radius);
|
||||
data.WriteDouble(request->geofence.expiration);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "AddFence remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(ADD_FENCE, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::AddFence Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorProxy::RemoveFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInt32(request->priority);
|
||||
data.WriteInt32(request->scenario);
|
||||
data.WriteDouble(request->geofence.latitude);
|
||||
data.WriteDouble(request->geofence.longitude);
|
||||
data.WriteDouble(request->geofence.radius);
|
||||
data.WriteDouble(request->geofence.expiration);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "RemoveFence remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(REMOVE_FENCE, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::RemoveFence Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "nmea_message_callback_host.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
NmeaMessageCallbackHost::NmeaMessageCallbackHost()
|
||||
{
|
||||
m_env = nullptr;
|
||||
m_handlerCb = nullptr;
|
||||
m_thisVarRef = nullptr;
|
||||
m_remoteDied = false;
|
||||
m_lastCallingPid = 0;
|
||||
m_lastCallingUid = 0;
|
||||
}
|
||||
|
||||
NmeaMessageCallbackHost::~NmeaMessageCallbackHost()
|
||||
{
|
||||
}
|
||||
|
||||
int NmeaMessageCallbackHost::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
LBSLOGD(NMEA_MESSAGE_CALLBACK, "NmeaMessageCallbackHost::OnRemoteRequest!");
|
||||
if (m_remoteDied) {
|
||||
LBSLOGD(NMEA_MESSAGE_CALLBACK, "Failed to `%{public}s`,Remote service is died!", __func__);
|
||||
return -1;
|
||||
}
|
||||
int uid = IPCSkeleton::GetCallingUid();
|
||||
if (uid > SYSTEM_UID) {
|
||||
LBSLOGE(NMEA_MESSAGE_CALLBACK, "invalid uid!");
|
||||
return false;
|
||||
}
|
||||
switch (code) {
|
||||
case RECEIVE_NMEA_MESSAGE_EVENT: {
|
||||
std::string msg = Str16ToStr8(data.ReadString16());
|
||||
OnMessageChange(msg);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool NmeaMessageCallbackHost::IsRemoteDied()
|
||||
{
|
||||
return m_remoteDied;
|
||||
}
|
||||
|
||||
napi_value NmeaMessageCallbackHost::PackResult(const std::string msg)
|
||||
{
|
||||
napi_value result;
|
||||
napi_create_string_utf8(m_env, msg.c_str(), NAPI_AUTO_LENGTH, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool NmeaMessageCallbackHost::Send(const std::string msg)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
|
||||
napi_value jsEvent = PackResult(msg);
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(m_env, &loop);
|
||||
if (loop == nullptr) {
|
||||
LBSLOGE(NMEA_MESSAGE_CALLBACK, "loop == nullptr.");
|
||||
return false;
|
||||
}
|
||||
uv_work_t *work = new uv_work_t;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(NMEA_MESSAGE_CALLBACK, "work == nullptr.");
|
||||
return false;
|
||||
}
|
||||
|
||||
JsContext *context = new (std::nothrow) JsContext(m_env);
|
||||
context->m_env = m_env;
|
||||
context->m_thisVarRef = m_thisVarRef;
|
||||
context->m_handlerCb = m_handlerCb;
|
||||
context->m_jsEvent = jsEvent;
|
||||
work->data = context;
|
||||
|
||||
uv_queue_work(
|
||||
loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
JsContext *context = nullptr;
|
||||
napi_handle_scope scope = nullptr;
|
||||
if (work == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "work is nullptr!");
|
||||
return;
|
||||
}
|
||||
context = static_cast<JsContext *>(work->data);
|
||||
if (context == nullptr) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "context is nullptr!");
|
||||
return;
|
||||
}
|
||||
napi_open_handle_scope(context->m_env, &scope);
|
||||
if (scope == nullptr) {
|
||||
LBSLOGE(NMEA_MESSAGE_CALLBACK, "scope is nullptr");
|
||||
// close handle scope, release napi_value
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
return;
|
||||
}
|
||||
if (context->m_handlerCb != nullptr) {
|
||||
napi_value thisVar = nullptr;
|
||||
napi_get_reference_value(context->m_env, context->m_thisVarRef, &thisVar);
|
||||
napi_value undefine;
|
||||
napi_value handler = nullptr;
|
||||
napi_get_undefined(context->m_env, &undefine);
|
||||
napi_get_reference_value(context->m_env, context->m_handlerCb, &handler);
|
||||
if (napi_call_function(context->m_env, thisVar, handler, 1,
|
||||
&context->m_jsEvent, &undefine) != napi_ok) {
|
||||
LBSLOGE(NMEA_MESSAGE_CALLBACK, "Report event failed");
|
||||
}
|
||||
}
|
||||
napi_close_handle_scope(context->m_env, scope);
|
||||
delete context;
|
||||
context = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void NmeaMessageCallbackHost::OnMessageChange(const std::string msg)
|
||||
{
|
||||
LBSLOGD(NMEA_MESSAGE_CALLBACK, "NmeaMessageCallbackHost::OnMessageChange");
|
||||
Send(msg);
|
||||
}
|
||||
|
||||
void NmeaMessageCallbackHost::DeleteHandler()
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(m_mutex);
|
||||
napi_delete_reference(m_env, m_handlerCb);
|
||||
m_handlerCb = nullptr;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
68
interfaces/innerkits/napi/BUILD.gn
Normal file
68
interfaces/innerkits/napi/BUILD.gn
Normal file
@ -0,0 +1,68 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
SUBSYSTEM_DIR = "//base/location"
|
||||
|
||||
ohos_shared_library("geolocation") {
|
||||
install_enable = true
|
||||
include_dirs = [
|
||||
"//third_party/node/src",
|
||||
"//native_engine",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
"//base/location/interfaces/innerkits/napi",
|
||||
"//base/location/interfaces/innerkits/locator_standard/include",
|
||||
"//base/location/location_common/common/include",
|
||||
"//base/location/location_locator/callback/include",
|
||||
"//base/location/utils/include",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
|
||||
"//base/security/access_token/interfaces/innerkits/accesstoken/include"
|
||||
]
|
||||
|
||||
sources = [
|
||||
"location_napi_adapter.cpp" ,
|
||||
"location_napi_entry.cpp" ,
|
||||
"location_napi_event.cpp" ,
|
||||
"$SUBSYSTEM_DIR/utils/source/common_utils.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//base/location/interfaces/innerkits/locator_standard:locator_sdk",
|
||||
"//base/location/location_common/common:lbsservice_common",
|
||||
"//utils/native/base:utils",
|
||||
"//third_party/libuv:uv_static",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ipc:ipc_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
"permission_standard:libpermissionsdk_standard",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"ability_base:want",
|
||||
"ability_runtime:wantagent_innerkits",
|
||||
]
|
||||
|
||||
relative_install_dir = "module"
|
||||
part_name = "location"
|
||||
subsystem_name = "location"
|
||||
}
|
483
interfaces/innerkits/napi/location_napi_adapter.cpp
Normal file
483
interfaces/innerkits/napi/location_napi_adapter.cpp
Normal file
@ -0,0 +1,483 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "location_napi_adapter.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::Location;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
std::unique_ptr<Locator> g_locatorPtr = Locator::GetInstance(LOCATION_LOCATOR_SA_ID);
|
||||
|
||||
napi_value GetLastLocation(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
pid_t callingPid = IPCSkeleton::GetCallingPid();
|
||||
pid_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
if (!CommonUtils::CheckLocationPermission(callingPid, callingUid)) {
|
||||
LBSLOGE(LOCATION_NAPI, "pid:%{public}d uid:%{public}d has no access permission to get cache location",
|
||||
callingPid, callingUid);
|
||||
g_locatorPtr->RequestPermission(env);
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
LocationAsyncContext* asyncContext = new LocationAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "getLastLocation", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
LocationAsyncContext* context = static_cast<LocationAsyncContext*>(data);
|
||||
TRACE_FUNC_CALL_NAME("g_locatorPtr->getCachedLocation");
|
||||
context->loc = g_locatorPtr->GetCachedLocation();
|
||||
if (context->loc != nullptr) {
|
||||
context->errCode = SUCCESS;
|
||||
} else {
|
||||
context->errCode = LAST_KNOWN_LOCATION_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
LocationAsyncContext* context = static_cast<LocationAsyncContext*>(data);
|
||||
napi_create_object(context->env, &context->result[PARAM1]);
|
||||
if (context->loc != nullptr) {
|
||||
LocationToJs(context->env, context->loc, context->result[PARAM1]);
|
||||
} else {
|
||||
LBSLOGE(LOCATOR_STANDARD, "loc is nullptr!");
|
||||
}
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push last location result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 0;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value IsLocationEnabled(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
|
||||
SwitchAsyncContext* asyncContext = new SwitchAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "isLocationEnabled", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
TRACE_FUNC_CALL_NAME("g_locatorPtr->IsLocationEnabled");
|
||||
context->enable = g_locatorPtr->IsLocationEnabled();
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
napi_get_boolean(context->env, context->enable, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push IsLocationEnabled result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 0;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value EnableLocation(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
if (!CommonUtils::CheckLocationPermission(IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid())) {
|
||||
LBSLOGE(LOCATION_NAPI, "pid:%{public}d uid:%{public}d has no access permission to EnableLocation",
|
||||
IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
SwitchAsyncContext* asyncContext = new SwitchAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "enableLocation", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
g_locatorPtr->EnableAbility(true);
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
napi_get_boolean(context->env, context->errCode == SUCCESS, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push IsLocationEnabled result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 0;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value DisableLocation(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
if (!CommonUtils::CheckLocationPermission(IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid())) {
|
||||
LBSLOGE(LOCATION_NAPI, "pid:%{public}d uid:%{public}d has no access permission to DisableLocation",
|
||||
IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
SwitchAsyncContext* asyncContext = new SwitchAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "disableLocation", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
g_locatorPtr->EnableAbility(false);
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
napi_get_boolean(context->env, context->errCode == SUCCESS, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push IsLocationEnabled result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 0;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value RequestEnableLocation(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
|
||||
SwitchAsyncContext* asyncContext = new SwitchAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "enableLocation", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
if (!g_locatorPtr->IsLocationEnabled()) {
|
||||
g_locatorPtr->ShowNotification();
|
||||
}
|
||||
g_locatorPtr->EnableAbility(true);
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
napi_get_boolean(context->env, context->errCode == SUCCESS, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push IsLocationEnabled result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 0;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value IsGeoServiceAvailable(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
|
||||
SwitchAsyncContext* asyncContext = new SwitchAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "isGeoServiceAvailable", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
TRACE_FUNC_CALL_NAME("g_locatorPtr->isGeoServiceAvailable");
|
||||
context->enable = g_locatorPtr->IsLocationEnabled() && g_locatorPtr->IsGeoServiceAvailable();
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
SwitchAsyncContext* context = static_cast<SwitchAsyncContext*>(data);
|
||||
napi_get_boolean(context->env, context->enable, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push isGeoServiceAvailable result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 0;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value GetAddressesFromLocation(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
napi_valuetype valueType;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type, object is expected for parameter 1.");
|
||||
|
||||
ReverseGeoCodeAsyncContext* asyncContext = new ReverseGeoCodeAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "getAddressesFromLocation", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
JsObjToReverseGeoCodeRequest(env, argv[0], asyncContext->reverseGeoCodeRequest);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
ReverseGeoCodeAsyncContext* context = static_cast<ReverseGeoCodeAsyncContext*>(data);
|
||||
if (g_locatorPtr->IsLocationEnabled()) {
|
||||
g_locatorPtr->GetAddressByCoordinate(context->reverseGeoCodeRequest, context->replyList);
|
||||
}
|
||||
if (context->replyList.size() <= 0) {
|
||||
context->errCode = REVERSE_GEOCODE_ERROR;
|
||||
} else {
|
||||
context->errCode = SUCCESS;
|
||||
}
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
ReverseGeoCodeAsyncContext* context = static_cast<ReverseGeoCodeAsyncContext*>(data);
|
||||
napi_create_array_with_length(context->env, context->replyList.size(), &context->result[PARAM1]);
|
||||
GeoAddressesToJsObj(context->env, context->replyList, context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push GetAddressesFromLocation result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 1;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value GetAddressesFromLocationName(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
napi_valuetype valueType;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type, object is expected for parameter 1.");
|
||||
|
||||
GeoCodeAsyncContext* asyncContext = new GeoCodeAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "GetAddressesFromLocationName", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
JsObjToGeoCodeRequest(env, argv[0], asyncContext->geoCodeRequest);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
GeoCodeAsyncContext* context = static_cast<GeoCodeAsyncContext*>(data);
|
||||
if (g_locatorPtr->IsLocationEnabled()) {
|
||||
g_locatorPtr->GetAddressByLocationName(context->geoCodeRequest,
|
||||
context->replyList);
|
||||
}
|
||||
if (context->replyList.size() <= 0) {
|
||||
context->errCode = REVERSE_GEOCODE_ERROR;
|
||||
} else {
|
||||
context->errCode = SUCCESS;
|
||||
}
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
GeoCodeAsyncContext* context = static_cast<GeoCodeAsyncContext*>(data);
|
||||
napi_create_array_with_length(context->env, context->replyList.size(), &context->result[PARAM1]);
|
||||
GeoAddressesToJsObj(context->env, context->replyList, context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push GetAddressesFromLocationName result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 1;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value IsLocationPrivacyConfirmed(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
|
||||
PrivacyAsyncContext* asyncContext = new PrivacyAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "isLocationPrivacyConfirmed", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
int type;
|
||||
napi_get_value_int32(env, argv[0], &type);
|
||||
asyncContext->type = CommonUtils::GetPrivacyTypeByInt(type);
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
PrivacyAsyncContext* context = static_cast<PrivacyAsyncContext*>(data);
|
||||
TRACE_FUNC_CALL_NAME("g_locatorPtr->IsLocationPrivacyConfirmed");
|
||||
context->isConfirmed = g_locatorPtr->IsLocationPrivacyConfirmed(context->type);
|
||||
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
PrivacyAsyncContext* context = static_cast<PrivacyAsyncContext*>(data);
|
||||
napi_get_boolean(context->env, context->isConfirmed, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push IsLocationPrivacyConfirmed result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 1;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value SetLocationPrivacyConfirmStatus(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 3;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
|
||||
PrivacyAsyncContext* asyncContext = new PrivacyAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "SetLocationPrivacyConfirmStatus", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
int type;
|
||||
napi_get_value_int32(env, argv[0], &type);
|
||||
asyncContext->type = CommonUtils::GetPrivacyTypeByInt(type);
|
||||
napi_get_value_bool(env, argv[1], &asyncContext->isConfirmed);
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
PrivacyAsyncContext* context = static_cast<PrivacyAsyncContext*>(data);
|
||||
TRACE_FUNC_CALL_NAME("g_locatorPtr->SetLocationPrivacyConfirmStatus");
|
||||
g_locatorPtr->SetLocationPrivacyConfirmStatus(context->type, context->isConfirmed);
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
PrivacyAsyncContext* context = static_cast<PrivacyAsyncContext*>(data);
|
||||
napi_get_boolean(context->env, context->errCode == SUCCESS, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push SetLocationPrivacyConfirmStatus result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 2;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value GetCachedGnssLocationsSize(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
|
||||
CachedAsyncContext* asyncContext = new CachedAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "GetCachedGnssLocationsSize", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
CachedAsyncContext* context = static_cast<CachedAsyncContext*>(data);
|
||||
TRACE_FUNC_CALL_NAME("g_locatorPtr->GetCachedGnssLocationsSize");
|
||||
context->locationSize = g_locatorPtr->GetCachedGnssLocationsSize();
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
CachedAsyncContext* context = static_cast<CachedAsyncContext*>(data);
|
||||
napi_create_int32(context->env, context->locationSize, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push GetCachedGnssLocationsSize result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 0;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value FlushCachedGnssLocations(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
|
||||
CachedAsyncContext* asyncContext = new CachedAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "FlushCachedGnssLocations", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
CachedAsyncContext* context = static_cast<CachedAsyncContext*>(data);
|
||||
TRACE_FUNC_CALL_NAME("g_locatorPtr->FlushCachedGnssLocations");
|
||||
g_locatorPtr->FlushCachedGnssLocations();
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
CachedAsyncContext* context = static_cast<CachedAsyncContext*>(data);
|
||||
napi_get_boolean(context->env, context->errCode == SUCCESS, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push FlushCachedGnssLocations result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 0;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
|
||||
napi_value SendCommand(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value argv[argc];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorPtr != nullptr, "locator instance is null.");
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
napi_valuetype valueType;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type, object is expected for parameter 1.");
|
||||
|
||||
CommandAsyncContext* asyncContext = new CommandAsyncContext(env);
|
||||
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
|
||||
napi_create_string_latin1(env, "SendCommand", NAPI_AUTO_LENGTH, &asyncContext->resourceName);
|
||||
|
||||
JsObjToCommand(env, argv[0], asyncContext->command);
|
||||
|
||||
asyncContext->executeFunc = [&](void* data) -> void {
|
||||
CommandAsyncContext* context = static_cast<CommandAsyncContext*>(data);
|
||||
context->enable = g_locatorPtr->SendCommand(context->command);
|
||||
context->errCode = SUCCESS;
|
||||
};
|
||||
|
||||
asyncContext->completeFunc = [&](void* data) -> void {
|
||||
CommandAsyncContext* context = static_cast<CommandAsyncContext*>(data);
|
||||
napi_get_boolean(context->env, context->enable, &context->result[PARAM1]);
|
||||
LBSLOGI(LOCATOR_STANDARD, "Push SendCommand result to client");
|
||||
};
|
||||
|
||||
size_t nonCallbackArgNum = 1;
|
||||
return DoAsyncWork(env, asyncContext, argc, argv, nonCallbackArgNum);
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
176
interfaces/innerkits/napi/location_napi_adapter.h
Normal file
176
interfaces/innerkits/napi/location_napi_adapter.h
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_NAPI_ADAPTER_H
|
||||
#define LOCATION_NAPI_ADAPTER_H
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include "constant_definition.h"
|
||||
#include "location.h"
|
||||
#include "location_util.h"
|
||||
#include "message_parcel.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "request_config.h"
|
||||
#include "common_utils.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
#include "locator.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
napi_value GetLastLocation(napi_env env, napi_callback_info info);
|
||||
napi_value IsLocationEnabled(napi_env env, napi_callback_info info);
|
||||
napi_value EnableLocation(napi_env env, napi_callback_info info);
|
||||
napi_value DisableLocation(napi_env env, napi_callback_info info);
|
||||
napi_value RequestEnableLocation(napi_env env, napi_callback_info info);
|
||||
napi_value IsGeoServiceAvailable(napi_env env, napi_callback_info info);
|
||||
napi_value GetAddressesFromLocation(napi_env env, napi_callback_info info);
|
||||
napi_value GetAddressesFromLocationName(napi_env env, napi_callback_info info);
|
||||
napi_value IsLocationPrivacyConfirmed(napi_env env, napi_callback_info info);
|
||||
napi_value SetLocationPrivacyConfirmStatus(napi_env env, napi_callback_info info);
|
||||
napi_value GetCachedGnssLocationsSize(napi_env env, napi_callback_info info);
|
||||
napi_value FlushCachedGnssLocations(napi_env env, napi_callback_info info);
|
||||
napi_value SendCommand(napi_env env, napi_callback_info info);
|
||||
|
||||
class LocationRequestAsyncContext : public AsyncContext {
|
||||
public:
|
||||
std::unique_ptr<Location> loc;
|
||||
std::unique_ptr<RequestConfig> request;
|
||||
|
||||
LocationRequestAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) :
|
||||
AsyncContext(env, work, deferred)
|
||||
{
|
||||
loc = nullptr;
|
||||
request = nullptr;
|
||||
}
|
||||
|
||||
LocationRequestAsyncContext() = delete;
|
||||
|
||||
virtual ~LocationRequestAsyncContext(){}
|
||||
};
|
||||
|
||||
class LocationAsyncContext : public AsyncContext {
|
||||
public:
|
||||
std::unique_ptr<Location> loc;
|
||||
|
||||
LocationAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) :
|
||||
AsyncContext(env, work, deferred)
|
||||
{
|
||||
loc = nullptr;
|
||||
}
|
||||
|
||||
LocationAsyncContext() = delete;
|
||||
|
||||
virtual ~LocationAsyncContext(){}
|
||||
};
|
||||
|
||||
class SwitchAsyncContext : public AsyncContext {
|
||||
public:
|
||||
bool enable;
|
||||
|
||||
SwitchAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) :
|
||||
AsyncContext(env, work, deferred)
|
||||
{
|
||||
enable = false;
|
||||
}
|
||||
|
||||
SwitchAsyncContext() = delete;
|
||||
|
||||
virtual ~SwitchAsyncContext(){}
|
||||
};
|
||||
|
||||
class PrivacyAsyncContext : public AsyncContext {
|
||||
public:
|
||||
LocationPrivacyType type;
|
||||
bool isConfirmed;
|
||||
|
||||
PrivacyAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) :
|
||||
AsyncContext(env, work, deferred)
|
||||
{
|
||||
type = LocationPrivacyType::OTHERS;
|
||||
isConfirmed = false;
|
||||
}
|
||||
|
||||
PrivacyAsyncContext() = delete;
|
||||
|
||||
virtual ~PrivacyAsyncContext(){}
|
||||
};
|
||||
|
||||
class CachedAsyncContext : public AsyncContext {
|
||||
public:
|
||||
bool enable;
|
||||
int locationSize;
|
||||
|
||||
CachedAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) :
|
||||
AsyncContext(env, work, deferred)
|
||||
{
|
||||
locationSize = 0;
|
||||
enable = false;
|
||||
}
|
||||
|
||||
CachedAsyncContext() = delete;
|
||||
|
||||
virtual ~CachedAsyncContext(){}
|
||||
};
|
||||
|
||||
class CommandAsyncContext : public AsyncContext {
|
||||
public:
|
||||
bool enable;
|
||||
std::unique_ptr<LocationCommand> command;
|
||||
|
||||
CommandAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) :
|
||||
AsyncContext(env, work, deferred)
|
||||
{
|
||||
command = nullptr;
|
||||
enable = false;
|
||||
}
|
||||
|
||||
CommandAsyncContext() = delete;
|
||||
|
||||
virtual ~CommandAsyncContext(){}
|
||||
};
|
||||
|
||||
class ReverseGeoCodeAsyncContext : public AsyncContext {
|
||||
public:
|
||||
MessageParcel reverseGeoCodeRequest;
|
||||
std::list<std::shared_ptr<GeoAddress>> replyList;
|
||||
|
||||
ReverseGeoCodeAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) :
|
||||
AsyncContext(env, work, deferred) {}
|
||||
|
||||
ReverseGeoCodeAsyncContext() = delete;
|
||||
|
||||
virtual ~ReverseGeoCodeAsyncContext(){}
|
||||
};
|
||||
|
||||
class GeoCodeAsyncContext : public AsyncContext {
|
||||
public:
|
||||
MessageParcel geoCodeRequest;
|
||||
std::list<std::shared_ptr<GeoAddress>> replyList;
|
||||
|
||||
GeoCodeAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) :
|
||||
AsyncContext(env, work, deferred) {}
|
||||
|
||||
GeoCodeAsyncContext() = delete;
|
||||
|
||||
virtual ~GeoCodeAsyncContext(){}
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
87
interfaces/innerkits/napi/location_napi_entry.cpp
Normal file
87
interfaces/innerkits/napi/location_napi_entry.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "location_util.h"
|
||||
#include "lbs_log.h"
|
||||
#include "location_napi_adapter.h"
|
||||
#include "location_napi_event.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
/*
|
||||
* Event class initialization function
|
||||
*/
|
||||
static void InitEventClass(napi_env& env, napi_value& exports)
|
||||
{
|
||||
const char className[] = "LocationEventListener";
|
||||
napi_property_descriptor properties[] = {
|
||||
DECLARE_NAPI_FUNCTION("on", On),
|
||||
DECLARE_NAPI_FUNCTION("off", Off),
|
||||
DECLARE_NAPI_FUNCTION("getCurrentLocation", GetCurrentLocation),
|
||||
};
|
||||
|
||||
napi_value locationEventListenerClass = nullptr;
|
||||
napi_define_class(env, className, sizeof(className), LocationEventListenerConstructor, nullptr,
|
||||
sizeof(properties) / sizeof(napi_property_descriptor), properties, &locationEventListenerClass);
|
||||
napi_status status = napi_set_named_property(env, exports, "LocationEventListener", locationEventListenerClass);
|
||||
if (status != napi_ok) {
|
||||
LBSLOGE(LOCATION_NAPI, "Init event class set property error.");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Module initialization function
|
||||
*/
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "Init,location_napi_entry");
|
||||
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("getLastLocation", GetLastLocation),
|
||||
DECLARE_NAPI_FUNCTION("isLocationEnabled", IsLocationEnabled),
|
||||
DECLARE_NAPI_FUNCTION("requestEnableLocation", RequestEnableLocation),
|
||||
DECLARE_NAPI_FUNCTION("enableLocation", EnableLocation),
|
||||
DECLARE_NAPI_FUNCTION("disableLocation", DisableLocation),
|
||||
DECLARE_NAPI_FUNCTION("getAddressesFromLocation", GetAddressesFromLocation),
|
||||
DECLARE_NAPI_FUNCTION("getAddressesFromLocationName", GetAddressesFromLocationName),
|
||||
DECLARE_NAPI_FUNCTION("isGeoServiceAvailable", IsGeoServiceAvailable),
|
||||
DECLARE_NAPI_FUNCTION("isLocationPrivacyConfirmed", IsLocationPrivacyConfirmed),
|
||||
DECLARE_NAPI_FUNCTION("setLocationPrivacyConfirmStatus", SetLocationPrivacyConfirmStatus),
|
||||
DECLARE_NAPI_FUNCTION("getCachedGnssLocationsSize", GetCachedGnssLocationsSize),
|
||||
DECLARE_NAPI_FUNCTION("flushCachedGnssLocations", FlushCachedGnssLocations),
|
||||
DECLARE_NAPI_FUNCTION("sendCommand", SendCommand)
|
||||
};
|
||||
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc));
|
||||
InitEventClass(env, exports);
|
||||
return exports;
|
||||
}
|
||||
|
||||
static napi_module g_locationModule = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = NULL,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "geolocation",
|
||||
.nm_priv = ((void *)0),
|
||||
.reserved = { 0 }
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterModule(void)
|
||||
{
|
||||
napi_module_register(&g_locationModule);
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
547
interfaces/innerkits/napi/location_napi_event.cpp
Normal file
547
interfaces/innerkits/napi/location_napi_event.cpp
Normal file
@ -0,0 +1,547 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "location_napi_event.h"
|
||||
#include <unistd.h>
|
||||
#include "common_utils.h"
|
||||
#include "constant_definition.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_types.h"
|
||||
#include "lbs_log.h"
|
||||
#include "location_napi_adapter.h"
|
||||
#include "location_util.h"
|
||||
#include "locator.h"
|
||||
#include "request_config.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
std::unique_ptr<Locator> g_locatorNapiPtr = Locator::GetInstance(LOCATION_LOCATOR_SA_ID);
|
||||
|
||||
EventManager::EventManager(napi_env env, napi_value thisVar) : m_env(env)
|
||||
{
|
||||
m_thisVarRef = nullptr;
|
||||
napi_create_reference(env, thisVar, 1, &m_thisVarRef);
|
||||
m_locatorCallbackHost = sptr<LocatorCallbackHost>(new LocatorCallbackHost());
|
||||
m_locatorCallback = sptr<ILocatorCallback>(m_locatorCallbackHost);
|
||||
m_singleLocatorCallbackHost = sptr<LocatorCallbackHost>(new LocatorCallbackHost());
|
||||
m_singleLocatorCallback = sptr<ILocatorCallback>(m_singleLocatorCallbackHost);
|
||||
m_switchCallbackHost = sptr<LocationSwitchCallbackHost>(new LocationSwitchCallbackHost());
|
||||
m_switchCallback = sptr<ISwitchCallback>(m_switchCallbackHost);
|
||||
m_gnssStatusCallbackHost = sptr<GnssStatusCallbackHost>(new GnssStatusCallbackHost());
|
||||
m_nmeaMessageCallbackHost = sptr<NmeaMessageCallbackHost>(new NmeaMessageCallbackHost());
|
||||
m_cachedCallbackHost = sptr<CachedLocationsCallbackHost>(new CachedLocationsCallbackHost());
|
||||
m_cachedCallback = sptr<ICachedLocationsCallback>(m_cachedCallbackHost);
|
||||
}
|
||||
|
||||
EventManager::~EventManager()
|
||||
{
|
||||
if (m_locatorCallbackHost != nullptr) {
|
||||
delete m_locatorCallbackHost;
|
||||
}
|
||||
if (m_singleLocatorCallbackHost != nullptr) {
|
||||
delete m_singleLocatorCallbackHost;
|
||||
}
|
||||
if (m_switchCallbackHost != nullptr) {
|
||||
delete m_switchCallbackHost;
|
||||
}
|
||||
if (m_gnssStatusCallbackHost != nullptr) {
|
||||
delete m_gnssStatusCallbackHost;
|
||||
}
|
||||
if (m_nmeaMessageCallbackHost != nullptr) {
|
||||
delete m_nmeaMessageCallbackHost;
|
||||
}
|
||||
if (m_cachedCallbackHost != nullptr) {
|
||||
delete m_cachedCallbackHost;
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::SubscribeLocationServiceState(const std::string& name, napi_value& handler)
|
||||
{
|
||||
napi_ref handlerRef = nullptr;
|
||||
|
||||
if (m_switchCallbackHost->m_handlerCb != nullptr) {
|
||||
LBSLOGI(LOCATION_NAPI, "GetHandlerCb() != nullptr, UnSubscribeLocationServiceState");
|
||||
UnSubscribeLocationServiceState();
|
||||
m_switchCallbackHost->DeleteHandler();
|
||||
}
|
||||
|
||||
napi_create_reference(m_env, handler, 1, &handlerRef);
|
||||
LBSLOGI(LOCATION_NAPI, "Subscribe event: %{public}s", name.c_str());
|
||||
|
||||
m_switchCallbackHost->m_env = m_env;
|
||||
m_switchCallbackHost->m_handlerCb = handlerRef;
|
||||
m_switchCallbackHost->m_thisVarRef = m_thisVarRef;
|
||||
g_locatorNapiPtr->RegisterSwitchCallback(m_switchCallbackHost->AsObject(), 10001);
|
||||
}
|
||||
|
||||
void EventManager::SubscribeGnssStatus(const std::string& name, napi_value& handler)
|
||||
{
|
||||
napi_ref handlerRef = nullptr;
|
||||
|
||||
if (m_gnssStatusCallbackHost->m_handlerCb != nullptr) {
|
||||
LBSLOGI(LOCATION_NAPI, "GetHandlerCb() != nullptr, UnSubscribeGnssStatus");
|
||||
UnSubscribeGnssStatus();
|
||||
m_gnssStatusCallbackHost->DeleteHandler();
|
||||
}
|
||||
|
||||
napi_create_reference(m_env, handler, 1, &handlerRef);
|
||||
LBSLOGI(LOCATION_NAPI, "Subscribe event: %{public}s", name.c_str());
|
||||
|
||||
m_gnssStatusCallbackHost->m_env = m_env;
|
||||
m_gnssStatusCallbackHost->m_handlerCb = handlerRef;
|
||||
m_gnssStatusCallbackHost->m_thisVarRef = m_thisVarRef;
|
||||
g_locatorNapiPtr->RegisterGnssStatusCallback(m_gnssStatusCallbackHost->AsObject(), 10001);
|
||||
}
|
||||
|
||||
void EventManager::SubscribeNmeaMessage(const std::string& name, napi_value& handler)
|
||||
{
|
||||
napi_ref handlerRef = nullptr;
|
||||
|
||||
if (m_nmeaMessageCallbackHost->m_handlerCb != nullptr) {
|
||||
LBSLOGI(LOCATION_NAPI, "GetHandlerCb() != nullptr, UnSubscribeNmeaMessage");
|
||||
UnSubscribeNmeaMessage();
|
||||
m_nmeaMessageCallbackHost->DeleteHandler();
|
||||
}
|
||||
|
||||
napi_create_reference(m_env, handler, 1, &handlerRef);
|
||||
LBSLOGI(LOCATION_NAPI, "Subscribe event: %{public}s", name.c_str());
|
||||
|
||||
m_nmeaMessageCallbackHost->m_env = m_env;
|
||||
m_nmeaMessageCallbackHost->m_handlerCb = handlerRef;
|
||||
m_nmeaMessageCallbackHost->m_thisVarRef = m_thisVarRef;
|
||||
g_locatorNapiPtr->RegisterNmeaMessageCallback(m_nmeaMessageCallbackHost->AsObject(), 10001);
|
||||
}
|
||||
|
||||
bool EventManager::IsCallbackEquals(napi_value& handler, napi_ref& savedCallback)
|
||||
{
|
||||
napi_value handlerTemp = nullptr;
|
||||
if (savedCallback == nullptr || handler == nullptr) {
|
||||
return false;
|
||||
}
|
||||
napi_get_reference_value(m_env, savedCallback, &handlerTemp);
|
||||
bool isEqual = false;
|
||||
napi_strict_equals(m_env, handlerTemp, handler, &isEqual);
|
||||
return isEqual;
|
||||
}
|
||||
|
||||
void EventManager::UnSubscribeLocationServiceState()
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "UnSubscribeLocationServiceState");
|
||||
g_locatorNapiPtr->UnregisterSwitchCallback(m_switchCallbackHost->AsObject());
|
||||
}
|
||||
|
||||
void EventManager::UnSubscribeGnssStatus()
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "UnSubscribeGnssStatus");
|
||||
g_locatorNapiPtr->UnregisterGnssStatusCallback(m_gnssStatusCallbackHost->AsObject());
|
||||
}
|
||||
|
||||
void EventManager::UnSubscribeNmeaMessage()
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "UnSubscribeNmeaMessage");
|
||||
g_locatorNapiPtr->UnregisterNmeaMessageCallback(m_nmeaMessageCallbackHost->AsObject());
|
||||
}
|
||||
|
||||
void EventManager::SubscribeLocationChange(const std::string& name, const napi_value& object,
|
||||
napi_value& handler, int fixNumber)
|
||||
{
|
||||
napi_ref handlerRef = nullptr;
|
||||
if (m_locatorCallbackHost->m_handlerCb != nullptr) {
|
||||
LBSLOGI(LOCATION_NAPI, "GetHandlerCb() != nullptr, UnSubscribeLocationChange");
|
||||
UnSubscribeLocationChange(m_locatorCallback);
|
||||
m_locatorCallbackHost->DeleteHandler();
|
||||
}
|
||||
|
||||
napi_create_reference(m_env, handler, 1, &handlerRef);
|
||||
LBSLOGI(LOCATION_NAPI, "Subscribe event: %{public}s", name.c_str());
|
||||
|
||||
m_locatorCallbackHost->m_fixNumber = fixNumber;
|
||||
m_locatorCallbackHost->m_env = m_env;
|
||||
m_locatorCallbackHost->m_handlerCb = handlerRef;
|
||||
m_locatorCallbackHost->m_thisVarRef = m_thisVarRef;
|
||||
|
||||
std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
|
||||
JsObjToLocationRequest(m_env, object, requestConfig);
|
||||
g_locatorNapiPtr->StartLocating(requestConfig, m_locatorCallback);
|
||||
}
|
||||
|
||||
void EventManager::SubscribeCacheLocationChange(const std::string& name, const napi_value& object,
|
||||
napi_value& handler)
|
||||
{
|
||||
napi_ref handlerRef = nullptr;
|
||||
if (m_cachedCallbackHost->m_handlerCb != nullptr) {
|
||||
LBSLOGI(LOCATION_NAPI, "GetHandlerCb() != nullptr, UnSubscribeLocationChange");
|
||||
UnSubscribeCacheLocationChange(m_cachedCallback);
|
||||
m_cachedCallbackHost->DeleteHandler();
|
||||
}
|
||||
|
||||
napi_create_reference(m_env, handler, 1, &handlerRef);
|
||||
LBSLOGI(LOCATION_NAPI, "Subscribe event: %{public}s", name.c_str());
|
||||
|
||||
m_cachedCallbackHost->m_env = m_env;
|
||||
m_cachedCallbackHost->m_handlerCb = handlerRef;
|
||||
m_cachedCallbackHost->m_thisVarRef = m_thisVarRef;
|
||||
|
||||
std::unique_ptr<CachedGnssLoactionsRequest> request = std::make_unique<CachedGnssLoactionsRequest>();
|
||||
JsObjToCachedLocationRequest(m_env, object, request);
|
||||
g_locatorNapiPtr->RegisterCachedLocationCallback(request, m_cachedCallback);
|
||||
}
|
||||
|
||||
void EventManager::SubscribeFenceStatusChange(const std::string& name, const napi_value& object,
|
||||
napi_value& handler)
|
||||
{
|
||||
napi_ref handlerRef = nullptr;
|
||||
|
||||
napi_create_reference(m_env, handler, 1, &handlerRef);
|
||||
LBSLOGI(LOCATION_NAPI, "UnSubscribe event: %{public}s", name.c_str());
|
||||
|
||||
AbilityRuntime::WantAgent::WantAgent wantAgent = AbilityRuntime::WantAgent::WantAgent();
|
||||
napi_unwrap(m_env, handler, (void **)&wantAgent);
|
||||
std::unique_ptr<GeofenceRequest> request = std::make_unique<GeofenceRequest>();
|
||||
JsObjToGeoFenceRequest(m_env, object, request);
|
||||
GeoFenceState* state = new GeoFenceState(request->geofence, wantAgent);
|
||||
mFences.push_back(state);
|
||||
g_locatorNapiPtr->AddFence(request);
|
||||
}
|
||||
|
||||
void EventManager::UnSubscribeFenceStatusChange(const std::string& name, const napi_value& object,
|
||||
napi_value& handler)
|
||||
{
|
||||
napi_ref handlerRef = nullptr;
|
||||
|
||||
napi_create_reference(m_env, handler, 1, &handlerRef);
|
||||
LBSLOGI(LOCATION_NAPI, "UnSubscribe event: %{public}s", name.c_str());
|
||||
|
||||
AbilityRuntime::WantAgent::WantAgent wantAgent = AbilityRuntime::WantAgent::WantAgent();
|
||||
napi_unwrap(m_env, handler, (void **)&wantAgent);
|
||||
std::unique_ptr<GeofenceRequest> request = std::make_unique<GeofenceRequest>();
|
||||
JsObjToGeoFenceRequest(m_env, object, request);
|
||||
mFences.erase(mFences.begin());
|
||||
g_locatorNapiPtr->RemoveFence(request);
|
||||
}
|
||||
|
||||
void EventManager::GetCallbackType(napi_env env, const size_t argc, const napi_value* argv, bool& isCallbackType,
|
||||
size_t& nonCallbackArgNum)
|
||||
{
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
|
||||
if (argc == 0) {
|
||||
isCallbackType = false;
|
||||
} else if (argc == 1) {
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
if (valueType == napi_object) {
|
||||
isCallbackType = false;
|
||||
nonCallbackArgNum = 1;
|
||||
} else if (valueType == napi_function) {
|
||||
isCallbackType = true;
|
||||
nonCallbackArgNum = 0;
|
||||
}
|
||||
} else {
|
||||
isCallbackType = true;
|
||||
nonCallbackArgNum = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::GenRequestConfig(napi_env env, const napi_value* argv,
|
||||
size_t& nonCallbackArgNum, std::unique_ptr<RequestConfig>& requestConfig)
|
||||
{
|
||||
if (nonCallbackArgNum > 0) {
|
||||
JsObjToLocationRequest(env, argv[nonCallbackArgNum - 1], requestConfig);
|
||||
} else {
|
||||
requestConfig->SetPriority(PRIORITY_FAST_FIRST_FIX);
|
||||
requestConfig->SetScenario(SCENE_UNSET);
|
||||
requestConfig->SetTimeInterval(1);
|
||||
requestConfig->SetDistanceInterval(0);
|
||||
requestConfig->SetMaxAccuracy(0);
|
||||
}
|
||||
requestConfig->SetFixNumber(1);
|
||||
}
|
||||
|
||||
void EventManager::GetTimeoutParam(napi_env env, const napi_value* argv,
|
||||
size_t& nonCallbackArgNum, int& timeout)
|
||||
{
|
||||
if (nonCallbackArgNum > 0) {
|
||||
JsObjectToInt(env, argv[nonCallbackArgNum - 1], "timeoutMs", timeout);
|
||||
} else {
|
||||
timeout = 30000;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value EventManager::RequestLocationOnce(napi_env env, const size_t argc, const napi_value* argv)
|
||||
{
|
||||
napi_ref handlerRef = nullptr;
|
||||
napi_deferred deferred;
|
||||
napi_value promise;
|
||||
std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
|
||||
bool isCallbackType = false;
|
||||
size_t nonCallbackArgNum = 0;
|
||||
int timeout = 5000;
|
||||
LBSLOGI(LOCATION_NAPI, "RequestLocationOnce enter");
|
||||
|
||||
GetCallbackType(env, argc, argv, isCallbackType, nonCallbackArgNum);
|
||||
|
||||
GenRequestConfig(env, argv, nonCallbackArgNum, requestConfig);
|
||||
|
||||
GetTimeoutParam(env, argv, nonCallbackArgNum, timeout);
|
||||
|
||||
if (m_singleLocatorCallbackHost->m_handlerCb != nullptr || m_singleLocatorCallbackHost->m_deferred != nullptr) {
|
||||
LBSLOGI(LOCATION_NAPI, "GetHandlerCb() != nullptr, UnSubscribeLocationChange");
|
||||
UnSubscribeLocationChange(m_singleLocatorCallback);
|
||||
if (m_singleLocatorCallbackHost->m_handlerCb != nullptr) {
|
||||
m_singleLocatorCallbackHost->DeleteHandler();
|
||||
}
|
||||
}
|
||||
|
||||
m_singleLocatorCallbackHost->m_env = m_env;
|
||||
m_singleLocatorCallbackHost->m_thisVarRef = m_thisVarRef;
|
||||
m_singleLocatorCallbackHost->m_fixNumber = 1;
|
||||
if (isCallbackType) {
|
||||
napi_create_reference(env, argv[nonCallbackArgNum], 1, &handlerRef);
|
||||
m_singleLocatorCallbackHost->m_handlerCb = handlerRef;
|
||||
} else {
|
||||
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
|
||||
m_singleLocatorCallbackHost->m_deferred = deferred;
|
||||
}
|
||||
g_locatorNapiPtr->StartLocating(requestConfig, m_singleLocatorCallback);
|
||||
if (isCallbackType) {
|
||||
return UndefinedNapiValue(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::UnSubscribeLocationChange(sptr<ILocatorCallback>& callback)
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "UnSubscribeLocationChange");
|
||||
g_locatorNapiPtr->StopLocating(callback);
|
||||
}
|
||||
|
||||
void EventManager::UnSubscribeCacheLocationChange(sptr<ICachedLocationsCallback>& callback)
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "UnSubscribeCacheLocationChange");
|
||||
g_locatorNapiPtr->UnregisterCachedLocationCallback(callback);
|
||||
}
|
||||
|
||||
void EventManager::DeleteHanderRef(napi_value& handler)
|
||||
{
|
||||
if (IsCallbackEquals(handler, m_locatorCallbackHost->m_handlerCb)) {
|
||||
LBSLOGD(LOCATION_NAPI, "DeleteHanderRef locator");
|
||||
m_locatorCallbackHost->DeleteHandler();
|
||||
}
|
||||
if (IsCallbackEquals(handler, m_switchCallbackHost->m_handlerCb)) {
|
||||
LBSLOGD(LOCATION_NAPI, "DeleteHanderRef switch");
|
||||
m_switchCallbackHost->DeleteHandler();
|
||||
}
|
||||
if (IsCallbackEquals(handler, m_singleLocatorCallbackHost->m_handlerCb)) {
|
||||
LBSLOGD(LOCATION_NAPI, "DeleteHanderRef single locator callback");
|
||||
m_singleLocatorCallbackHost->DeleteHandler();
|
||||
}
|
||||
}
|
||||
|
||||
napi_value On(napi_env env, napi_callback_info cbinfo)
|
||||
{
|
||||
TRACE_FUNC_CALL;
|
||||
size_t argc = 3;
|
||||
napi_value argv[3] = {0};
|
||||
napi_value thisVar = 0;
|
||||
pid_t callingPid = IPCSkeleton::GetCallingPid();
|
||||
pid_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
napi_value result = nullptr;
|
||||
LBSLOGI(LOCATION_NAPI, "On function entry");
|
||||
napi_get_cb_info(env, cbinfo, &argc, argv, &thisVar, nullptr);
|
||||
napi_valuetype eventName = napi_undefined;
|
||||
napi_typeof(env, argv[0], &eventName);
|
||||
NAPI_ASSERT(env, eventName == napi_string, "type mismatch for parameter 1");
|
||||
NAPI_ASSERT(env, g_locatorNapiPtr != nullptr, "locator instance is null.");
|
||||
if (argc == 2 || argc == 3) {
|
||||
napi_valuetype handler = napi_undefined;
|
||||
napi_typeof(env, argv[argc - 1], &handler);
|
||||
NAPI_ASSERT(env, handler == napi_function, "type mismatch for parameter");
|
||||
}
|
||||
if (!CommonUtils::CheckLocationPermission(callingPid, callingUid)) {
|
||||
LBSLOGE(LOCATION_NAPI, "pid:%{public}d uid:%{public}d has no access permission to get cache location",
|
||||
callingPid, callingUid);
|
||||
g_locatorNapiPtr->RequestPermission(env);
|
||||
return result;
|
||||
}
|
||||
EventManager* manager = nullptr;
|
||||
napi_status status = napi_unwrap(env, thisVar, (void**)&manager);
|
||||
if (status == napi_ok && manager != nullptr) {
|
||||
char type[64] = {0};
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &typeLen);
|
||||
std::string event = type;
|
||||
LBSLOGI(LOCATION_NAPI, "Subscribe event: %{public}s", event.c_str());
|
||||
|
||||
if (event == "locationServiceState") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->SubscribeLocationServiceState(type, argv[1]);
|
||||
} else if (event == "locationChange") {
|
||||
NAPI_ASSERT(env, argc == 3, "number of parameters is wrong");
|
||||
manager->SubscribeLocationChange(type, argv[1], argv[2], 0);
|
||||
} else if (event == "gnssStatusChange") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->SubscribeGnssStatus(type, argv[1]);
|
||||
} else if (event == "nmeaMessageChange") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->SubscribeNmeaMessage(type, argv[1]);
|
||||
} else if (event == "cachedGnssLocationsReporting") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->SubscribeCacheLocationChange(type, argv[1], argv[2]);
|
||||
} else if (event == "fenceStatusChange") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->SubscribeFenceStatusChange(type, argv[1], argv[2]);
|
||||
}
|
||||
} else {
|
||||
LBSLOGE(LOCATION_NAPI, "On unwrap class failed");
|
||||
}
|
||||
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Off(napi_env env, napi_callback_info cbinfo)
|
||||
{
|
||||
TRACE_FUNC_CALL;
|
||||
size_t requireArgc = 2;
|
||||
size_t requireArgcWithCb = 2;
|
||||
size_t argc = 2;
|
||||
napi_value argv[3] = {0};
|
||||
napi_value thisVar = 0;
|
||||
napi_get_cb_info(env, cbinfo, &argc, argv, &thisVar, nullptr);
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "requires at least 1 parameter");
|
||||
NAPI_ASSERT(env, g_locatorNapiPtr != nullptr, "locator instance is null.");
|
||||
|
||||
napi_valuetype eventName = napi_undefined;
|
||||
napi_typeof(env, argv[0], &eventName);
|
||||
NAPI_ASSERT(env, eventName == napi_string, "type mismatch for parameter 1");
|
||||
LBSLOGI(LOCATION_NAPI, "Off function entry");
|
||||
|
||||
if (argc >= requireArgcWithCb) {
|
||||
napi_valuetype handler = napi_undefined;
|
||||
napi_typeof(env, argv[1], &handler);
|
||||
NAPI_ASSERT(env, handler == napi_function, "type mismatch for parameter 2");
|
||||
}
|
||||
|
||||
EventManager* manager = nullptr;
|
||||
napi_status status = napi_unwrap(env, thisVar, (void**)&manager);
|
||||
if (status == napi_ok && manager != nullptr) {
|
||||
char type[64] = {0};
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &typeLen);
|
||||
std::string event = type;
|
||||
LBSLOGI(LOCATION_NAPI, "Unsubscribe event: %{public}s", event.c_str());
|
||||
|
||||
if (event == "locationServiceState") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->UnSubscribeLocationServiceState();
|
||||
} else if (event == "locationChange") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->UnSubscribeLocationChange(manager->m_locatorCallback);
|
||||
} else if (event == "gnssStatusChange") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->UnSubscribeGnssStatus();
|
||||
} else if (event == "nmeaMessageChange") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->UnSubscribeNmeaMessage();
|
||||
} else if (event == "cachedGnssLocationsReporting") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->UnSubscribeCacheLocationChange(manager->m_cachedCallback);
|
||||
} else if (event == "fenceStatusChange") {
|
||||
NAPI_ASSERT(env, argc == 2, "number of parameters is wrong");
|
||||
manager->UnSubscribeFenceStatusChange(type, argv[1], argv[2]);
|
||||
}
|
||||
manager->DeleteHanderRef(argv[1]);
|
||||
} else {
|
||||
LBSLOGE(LOCATION_NAPI, "Off unwrap class failed");
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value GetCurrentLocation(napi_env env, napi_callback_info cbinfo)
|
||||
{
|
||||
TRACE_FUNC_CALL;
|
||||
size_t requireArgc = 0;
|
||||
size_t argc = 3;
|
||||
napi_value argv[3] = {0};
|
||||
napi_value thisVar = 0;
|
||||
pid_t callingPid = IPCSkeleton::GetCallingPid();
|
||||
pid_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
napi_value result = nullptr;
|
||||
|
||||
napi_get_cb_info(env, cbinfo, &argc, argv, &thisVar, nullptr);
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "number of parameters is error");
|
||||
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
NAPI_ASSERT(env, g_locatorNapiPtr != nullptr, "locator instance is null.");
|
||||
LBSLOGI(LOCATION_NAPI, "GetCurrentLocation enter");
|
||||
|
||||
if (argc == 1) {
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT(env, valueType == napi_function || valueType == napi_object, "type mismatch for parameter 2");
|
||||
}
|
||||
if (argc == 2) {
|
||||
napi_valuetype valueType1 = napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
napi_typeof(env, argv[1], &valueType1);
|
||||
NAPI_ASSERT(env, valueType == napi_object, "type mismatch for parameter 1");
|
||||
NAPI_ASSERT(env, valueType1 == napi_function, "type mismatch for parameter 2");
|
||||
}
|
||||
if (!CommonUtils::CheckLocationPermission(callingPid, callingUid)) {
|
||||
LBSLOGE(LOCATION_NAPI, "pid:%{public}d uid:%{public}d has no access permission to get cache location",
|
||||
callingPid, callingUid);
|
||||
g_locatorNapiPtr->RequestPermission(env);
|
||||
return result;
|
||||
}
|
||||
|
||||
EventManager* manager = nullptr;
|
||||
napi_status status = napi_unwrap(env, thisVar, (void**)&manager);
|
||||
if (status == napi_ok && manager != nullptr) {
|
||||
return manager->RequestLocationOnce(env, argc, argv);
|
||||
} else {
|
||||
LBSLOGE(LOCATION_NAPI, "On unwrap class failed");
|
||||
}
|
||||
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value LocationEventListenerConstructor(napi_env env, napi_callback_info cbinfo)
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "Event listener constructor");
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
napi_get_cb_info(env, cbinfo, nullptr, nullptr, &thisVar, &data);
|
||||
|
||||
EventManager* eventManager = new EventManager(env, thisVar);
|
||||
if (eventManager == nullptr) {
|
||||
LBSLOGE(LOCATION_NAPI, "Init listener constructor failed");
|
||||
return nullptr;
|
||||
}
|
||||
napi_wrap(
|
||||
env, thisVar, eventManager,
|
||||
[](napi_env env, void* data, void* hint) {
|
||||
LBSLOGI(LOCATION_NAPI, "Event listener destructor");
|
||||
EventManager *eventManager = (EventManager *)data;
|
||||
delete eventManager;
|
||||
eventManager = nullptr;
|
||||
},
|
||||
nullptr, nullptr);
|
||||
return thisVar;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
84
interfaces/innerkits/napi/location_napi_event.h
Normal file
84
interfaces/innerkits/napi/location_napi_event.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_NAPI_EVENT_H
|
||||
#define LOCATION_NAPI_EVENT_H
|
||||
|
||||
#include <string>
|
||||
#include "cached_locations_callback_host.h"
|
||||
#include "geofence_state.h"
|
||||
#include "gnss_status_callback_host.h"
|
||||
#include "location_switch_callback_host.h"
|
||||
#include "locator_callback_host.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "nmea_message_callback_host.h"
|
||||
#include "request_config.h"
|
||||
#include "want_agent_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class EventManager {
|
||||
public:
|
||||
EventManager(napi_env env, napi_value thisVar);
|
||||
virtual ~EventManager();
|
||||
void SubscribeLocationServiceState(const std::string& name, napi_value& handler);
|
||||
bool IsCallbackEquals(napi_value& handler, napi_ref& savedCallback);
|
||||
void UnSubscribeLocationServiceState();
|
||||
void SubscribeLocationChange(const std::string& name, const napi_value& object, napi_value& handler, int fixNumber);
|
||||
void GetCallbackType(napi_env env, const size_t argc, const napi_value* argv, bool& isCallbackType,
|
||||
size_t& nonCallbackArgNum);
|
||||
void GenRequestConfig(napi_env env, const napi_value* argv,
|
||||
size_t& nonCallbackArgNum, std::unique_ptr<RequestConfig>& requestConfig);
|
||||
void GetTimeoutParam(napi_env env, const napi_value* argv,
|
||||
size_t& nonCallbackArgNum, int& timeout);
|
||||
napi_value RequestLocationOnce(napi_env env, const size_t argc, const napi_value* argv);
|
||||
void UnSubscribeLocationChange(sptr<ILocatorCallback>& callback);
|
||||
void DeleteHanderRef(napi_value& handler);
|
||||
|
||||
void SubscribeGnssStatus(const std::string& name, napi_value& handler);
|
||||
void SubscribeNmeaMessage(const std::string& name, napi_value& handler);
|
||||
void UnSubscribeGnssStatus();
|
||||
void UnSubscribeNmeaMessage();
|
||||
|
||||
void SubscribeCacheLocationChange(const std::string& name, const napi_value& object, napi_value& handler);
|
||||
void UnSubscribeCacheLocationChange(sptr<ICachedLocationsCallback>& callback);
|
||||
|
||||
void SubscribeFenceStatusChange(const std::string& name, const napi_value& object, napi_value& handler);
|
||||
void UnSubscribeFenceStatusChange(const std::string& name, const napi_value& object, napi_value& handler);
|
||||
|
||||
napi_env m_env;
|
||||
napi_ref m_thisVarRef;
|
||||
sptr<LocatorCallbackHost> m_locatorCallbackHost;
|
||||
sptr<LocatorCallbackHost> m_singleLocatorCallbackHost;
|
||||
sptr<LocationSwitchCallbackHost> m_switchCallbackHost;
|
||||
sptr<ILocatorCallback> m_locatorCallback;
|
||||
sptr<ILocatorCallback> m_singleLocatorCallback;
|
||||
sptr<ISwitchCallback> m_switchCallback;
|
||||
sptr<GnssStatusCallbackHost> m_gnssStatusCallbackHost;
|
||||
sptr<NmeaMessageCallbackHost> m_nmeaMessageCallbackHost;
|
||||
sptr<CachedLocationsCallbackHost> m_cachedCallbackHost;
|
||||
sptr<ICachedLocationsCallback> m_cachedCallback;
|
||||
|
||||
std::vector<GeoFenceState*> mFences;
|
||||
};
|
||||
|
||||
napi_value On(napi_env env, napi_callback_info cbinfo);
|
||||
napi_value Off(napi_env env, napi_callback_info cbinfo);
|
||||
napi_value GetCurrentLocation(napi_env env, napi_callback_info cbinfo);
|
||||
napi_value LocationEventListenerConstructor(napi_env env, napi_callback_info cbinfo);
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
20
location_common/BUILD.gn
Normal file
20
location_common/BUILD.gn
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/config/ohos/rules.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos_var.gni")
|
||||
|
||||
ohos_subsystem("location") {
|
||||
subsystem_packages = [ "location_common:lbsservice_common" ]
|
||||
}
|
46
location_common/bundle.json
Normal file
46
location_common/bundle.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "@ohos/location_common",
|
||||
"version": "3.1.0",
|
||||
"description": "Common Module Capabilities in Location Services.",
|
||||
"homePage": "https://gitee.com/openharmony",
|
||||
"license": "Apache License 2.0",
|
||||
"repository": "",
|
||||
"domain": "os",
|
||||
"language": "",
|
||||
"publishAs": "code-segment",
|
||||
"private": false,
|
||||
"segment": {
|
||||
"destPath": "base/location/location_common"
|
||||
},
|
||||
"component": {
|
||||
"name": "location_common",
|
||||
"subsystem": "location",
|
||||
"syscap": [
|
||||
"SystemCapability.Location.Location"
|
||||
],
|
||||
"features": [],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"deps": {
|
||||
"components": [
|
||||
"ipc",
|
||||
"ces_standard",
|
||||
"hiviewdfx_hilog_native",
|
||||
"access_token",
|
||||
"startup_l2:syspara"
|
||||
],
|
||||
"third_party": []
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//base/location/location_common/common:lbsservice_common",
|
||||
"//base/location/etc:etc",
|
||||
"//base/location/profile:location_sa_profile"
|
||||
],
|
||||
"test": []
|
||||
}
|
||||
}
|
||||
}
|
67
location_common/common/BUILD.gn
Normal file
67
location_common/common/BUILD.gn
Normal file
@ -0,0 +1,67 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
SUBSYSTEM_DIR = "//base/location"
|
||||
LOCATION_COMMON_ROOT = "$SUBSYSTEM_DIR/location_common/common"
|
||||
LOCATION_SERVICE_ROOT = "$SUBSYSTEM_DIR/services"
|
||||
|
||||
ohos_shared_library("lbsservice_common") {
|
||||
sources = [
|
||||
"$LOCATION_COMMON_ROOT/source/location.cpp",
|
||||
"$LOCATION_COMMON_ROOT/source/request_config.cpp",
|
||||
"$LOCATION_COMMON_ROOT/source/geo_address.cpp",
|
||||
"$LOCATION_COMMON_ROOT/source/location_config_manager.cpp",
|
||||
"$LOCATION_COMMON_ROOT/source/satellite_status.cpp",
|
||||
"$LOCATION_COMMON_ROOT/source/geofence_state.cpp",
|
||||
"$LOCATION_COMMON_ROOT/source/location_dumper.cpp",
|
||||
"$SUBSYSTEM_DIR/utils/source/common_utils.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/include",
|
||||
"$SUBSYSTEM_DIR/location_common/common/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/distribute/include",
|
||||
"$SUBSYSTEM_DIR/location_geocode/geocode/include",
|
||||
"$SUBSYSTEM_DIR/location_gnss/gnss/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/include",
|
||||
"$SUBSYSTEM_DIR/location_network/network/include",
|
||||
"$SUBSYSTEM_DIR/location_passive/passive/include",
|
||||
"$LOCATION_SERVICE_ROOT/visibility/include",
|
||||
"$SUBSYSTEM_DIR/utils/include",
|
||||
"$SUBSYSTEM_DIR/adapter/services/include",
|
||||
"//base/security/access_token/interfaces/innerkits/accesstoken/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"startup_l2:syspara",
|
||||
"ability_base:want",
|
||||
"ability_runtime:wantagent_innerkits",
|
||||
]
|
||||
|
||||
part_name = "location_common"
|
||||
subsystem_name = "location"
|
||||
}
|
75
location_common/common/include/constant_definition.h
Normal file
75
location_common/common/include/constant_definition.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_CONSTANT_DEFINITION_H
|
||||
#define OHOS_LOCATION_CONSTANT_DEFINITION_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
// error type
|
||||
const int ERROR_PERMISSION_NOT_GRANTED = 0x0100;
|
||||
const int ERROR_SWITCH_UNOPEN = 0x0101;
|
||||
const int SESSION_START = 0x0002;
|
||||
const int SESSION_STOP = 0x0003;
|
||||
|
||||
enum {
|
||||
SCENE_UNSET = 0x0300,
|
||||
SCENE_NAVIGATION = 0x0301,
|
||||
SCENE_TRAJECTORY_TRACKING = 0x0302,
|
||||
SCENE_CAR_HAILING = 0x0303,
|
||||
SCENE_DAILY_LIFE_SERVICE = 0x0304,
|
||||
SCENE_NO_POWER = 0x0305
|
||||
};
|
||||
|
||||
enum {
|
||||
PRIORITY_UNSET = 0x0200,
|
||||
PRIORITY_ACCURACY = 0x0201,
|
||||
PRIORITY_LOW_POWER = 0x0202,
|
||||
PRIORITY_FAST_FIRST_FIX = 0x0203
|
||||
};
|
||||
|
||||
enum class LocationPrivacyType {
|
||||
OTHERS = 0,
|
||||
STARTUP,
|
||||
CORE_LOCATION
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int reportingPeriodSec;
|
||||
bool wakeUpCacheQueueFull;
|
||||
} CachedGnssLoactionsRequest;
|
||||
|
||||
typedef struct {
|
||||
int scenario;
|
||||
std::string command;
|
||||
} LocationCommand;
|
||||
|
||||
typedef struct {
|
||||
double latitude;
|
||||
double longitude;
|
||||
double radius;
|
||||
double expiration;
|
||||
} GeoFence;
|
||||
|
||||
typedef struct {
|
||||
int priority;
|
||||
int scenario;
|
||||
GeoFence geofence;
|
||||
} GeofenceRequest;
|
||||
} // Location
|
||||
} // OHOS
|
||||
#endif // OHOS_LOCATION_CONSTANT_DEFINITION_H
|
64
location_common/common/include/geo_address.h
Normal file
64
location_common/common/include/geo_address.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_GEO_ADDRESS_H
|
||||
#define OHOS_LOCATION_GEO_ADDRESS_H
|
||||
|
||||
#include <parcel.h>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class GeoAddress : public Parcelable {
|
||||
public:
|
||||
GeoAddress();
|
||||
virtual ~GeoAddress() = default;
|
||||
bool Marshalling(Parcel& parcel) const override;
|
||||
static std::unique_ptr<GeoAddress> Unmarshalling(Parcel& parcel);
|
||||
std::string GetDescriptions(int index);
|
||||
double GetLatitude();
|
||||
double GetLongitude();
|
||||
void ReadFromParcel(Parcel& in);
|
||||
|
||||
double m_latitude;
|
||||
double m_longitude;
|
||||
std::string m_localeLanguage;
|
||||
std::string m_localeCountry;
|
||||
std::string m_placeName;
|
||||
std::string m_countryCode;
|
||||
std::string m_countryName;
|
||||
std::string m_administrativeArea;
|
||||
std::string m_subAdministrativeArea;
|
||||
std::string m_locality;
|
||||
std::string m_subLocality;
|
||||
std::string m_roadName;
|
||||
std::string m_subRoadName;
|
||||
std::string m_premises;
|
||||
std::string m_postalCode;
|
||||
std::string m_phoneNumber;
|
||||
std::string m_addressUrl;
|
||||
std::map<int, std::string> m_descriptions;
|
||||
int m_descriptionsSize = 0;
|
||||
bool m_hasLatitude = false;
|
||||
bool m_hasLongitude = false;
|
||||
static constexpr double PARCEL_INT_SIZE = 64.0;
|
||||
static constexpr int MAX_PARCEL_SIZE = 100;
|
||||
static constexpr int MAX_RESULT = 10;
|
||||
};
|
||||
} // Location
|
||||
} // OHOS
|
||||
#endif // OHOS_LOCATION_GEO_ADDRESS_H
|
36
location_common/common/include/geofence_state.h
Normal file
36
location_common/common/include/geofence_state.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_GEOFENCE_STATE_H
|
||||
#define OHOS_GEOFENCE_STATE_H
|
||||
|
||||
#include "constant_definition.h"
|
||||
#include "want_agent_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class GeoFenceState {
|
||||
public:
|
||||
GeoFenceState();
|
||||
explicit GeoFenceState(const GeoFence fence, const AbilityRuntime::WantAgent::WantAgent wantAgent);
|
||||
virtual ~GeoFenceState() = default;
|
||||
private:
|
||||
int mState;
|
||||
GeoFence mFence;
|
||||
AbilityRuntime::WantAgent::WantAgent mWantAgent;
|
||||
};
|
||||
} // Location
|
||||
} // OHOS
|
||||
#endif // OHOS_GEOFENCE_STATE_H
|
128
location_common/common/include/location.h
Normal file
128
location_common/common/include/location.h
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_OBJECT_H
|
||||
#define OHOS_LOCATION_OBJECT_H
|
||||
|
||||
#include <parcel.h>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class Location : public Parcelable {
|
||||
public:
|
||||
Location();
|
||||
explicit Location(Location &location);
|
||||
virtual ~Location() = default;
|
||||
|
||||
inline double GetLatitude() const
|
||||
{
|
||||
return latitude_;
|
||||
}
|
||||
|
||||
inline void SetLatitude(double latitude)
|
||||
{
|
||||
latitude_ = latitude;
|
||||
}
|
||||
|
||||
inline double GetLongitude() const
|
||||
{
|
||||
return longitude_;
|
||||
}
|
||||
|
||||
inline void SetLongitude(double longitude)
|
||||
{
|
||||
longitude_ = longitude;
|
||||
}
|
||||
|
||||
inline double GetAltitude() const
|
||||
{
|
||||
return altitude_;
|
||||
}
|
||||
|
||||
inline void SetAltitude(double altitude)
|
||||
{
|
||||
altitude_ = altitude;
|
||||
}
|
||||
|
||||
inline float GetAccuracy() const
|
||||
{
|
||||
return accuracy_;
|
||||
}
|
||||
|
||||
inline void SetAccuracy(float accuracy)
|
||||
{
|
||||
accuracy_ = accuracy;
|
||||
}
|
||||
|
||||
inline float GetSpeed() const
|
||||
{
|
||||
return speed_;
|
||||
}
|
||||
|
||||
inline void SetSpeed(float speed)
|
||||
{
|
||||
speed_ = speed;
|
||||
}
|
||||
|
||||
inline double GetDirection() const
|
||||
{
|
||||
return direction_;
|
||||
}
|
||||
|
||||
inline void SetDirection(double direction)
|
||||
{
|
||||
direction_ = direction;
|
||||
}
|
||||
|
||||
inline int64_t GetTimeStamp() const
|
||||
{
|
||||
return timeStamp_;
|
||||
}
|
||||
|
||||
inline void SetTimeStamp(int64_t timeStamp)
|
||||
{
|
||||
timeStamp_ = timeStamp;
|
||||
}
|
||||
|
||||
inline int64_t GetTimeSinceBoot() const
|
||||
{
|
||||
return timeSinceBoot_;
|
||||
}
|
||||
|
||||
inline void SetTimeSinceBoot(int64_t timeStamp)
|
||||
{
|
||||
timeSinceBoot_ = timeStamp;
|
||||
}
|
||||
|
||||
void ReadFromParcel(Parcel& parcel);
|
||||
void ReadFromParcelLocation(Parcel& parcel);
|
||||
bool Marshalling(Parcel& parcel) const override;
|
||||
std::string ToString() const;
|
||||
static std::unique_ptr<Location> Unmarshalling(Parcel& parcel);
|
||||
static std::unique_ptr<Location> UnmarshallingLocation(Parcel& parcel);
|
||||
private:
|
||||
double latitude_;
|
||||
double longitude_;
|
||||
double altitude_;
|
||||
float accuracy_;
|
||||
float speed_;
|
||||
double direction_;
|
||||
int64_t timeStamp_;
|
||||
int64_t timeSinceBoot_;
|
||||
};
|
||||
} // Location
|
||||
} // OHOS
|
||||
#endif // OHOS_LOCATION_OBJECT_H
|
79
location_common/common/include/location_config_manager.h
Normal file
79
location_common/common/include/location_config_manager.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_CONFIG_MANAGER_H
|
||||
#define OHOS_LOCATION_CONFIG_MANAGER_H
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <constant_definition.h>
|
||||
|
||||
constexpr int STATE_OPEN = 1;
|
||||
constexpr int STATE_CLOSE = 0;
|
||||
constexpr int32_t PER_USER_RANGE = 100000;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class LocationConfigManager {
|
||||
public:
|
||||
~LocationConfigManager();
|
||||
static LocationConfigManager &GetInstance();
|
||||
|
||||
/**
|
||||
* @Description Init the LocationConfigManager object
|
||||
*
|
||||
* @return int - init result, when 0 means success, other means some fails happened
|
||||
*/
|
||||
int Init();
|
||||
|
||||
/**
|
||||
* @Description Get current location switch state
|
||||
*
|
||||
* @return int - the location switch state, open/close
|
||||
*/
|
||||
int GetLocationSwitchState();
|
||||
|
||||
/**
|
||||
* @Description set location switch state
|
||||
*
|
||||
* @param state - the location switch state
|
||||
* @return int - 0 success
|
||||
*/
|
||||
int SetLocationSwitchState(int state);
|
||||
|
||||
bool IsExistFile(const std::string& filename);
|
||||
bool CreateFile(const std::string& filename, const std::string& filedata);
|
||||
|
||||
std::string GetPrivacyTypeConfigPath(const LocationPrivacyType type);
|
||||
bool GetPrivacyTypeState(const LocationPrivacyType type);
|
||||
void SetPrivacyTypeState(const LocationPrivacyType type, bool isConfirmed);
|
||||
|
||||
private:
|
||||
LocationConfigManager();
|
||||
std::string GetLocationSwitchConfigPath();
|
||||
|
||||
private:
|
||||
std::atomic<int> mPrivacyTypeState[3];
|
||||
std::atomic<int> mLocationSwitchState; /* location switch state */
|
||||
std::mutex mMutex;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif
|
45
location_common/common/include/location_dumper.h
Normal file
45
location_common/common/include/location_dumper.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_DUMPER_H
|
||||
#define OHOS_LOCATION_DUMPER_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class LocationDumper {
|
||||
public:
|
||||
bool GeocodeDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string> &vecArgs, std::string &result);
|
||||
|
||||
bool GnssDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string> &vecArgs, std::string &result);
|
||||
|
||||
bool LocatorDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string> &vecArgs, std::string &result);
|
||||
|
||||
bool NetWorkDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string> &vecArgs, std::string &result);
|
||||
|
||||
bool PassiveDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string> &vecArgs, std::string &result);
|
||||
private:
|
||||
void PrintArgs(const std::vector<std::string>& vecArgs);
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif
|
106
location_common/common/include/request_config.h
Normal file
106
location_common/common/include/request_config.h
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_REQUEST_CONFIGRATION_H
|
||||
#define OHOS_LOCATION_REQUEST_CONFIGRATION_H
|
||||
|
||||
#include <parcel.h>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class RequestConfig : public Parcelable {
|
||||
public:
|
||||
RequestConfig();
|
||||
explicit RequestConfig(const int scenario);
|
||||
virtual ~RequestConfig() = default;
|
||||
|
||||
inline int GetScenario() const
|
||||
{
|
||||
return scenario_;
|
||||
}
|
||||
|
||||
inline void SetScenario(int scenario)
|
||||
{
|
||||
scenario_ = scenario;
|
||||
}
|
||||
|
||||
inline void SetPriority(int priority)
|
||||
{
|
||||
priority_ = priority;
|
||||
}
|
||||
|
||||
inline int GetPriority()
|
||||
{
|
||||
return priority_;
|
||||
}
|
||||
|
||||
inline int GetTimeInterval() const
|
||||
{
|
||||
return timeInterval_;
|
||||
}
|
||||
|
||||
inline void SetTimeInterval(int timeInterval)
|
||||
{
|
||||
timeInterval_ = timeInterval;
|
||||
}
|
||||
|
||||
inline int GetDistanceInterval() const
|
||||
{
|
||||
return distanceInterval_;
|
||||
}
|
||||
|
||||
inline void SetDistanceInterval(int distanceInterval)
|
||||
{
|
||||
distanceInterval_ = distanceInterval;
|
||||
}
|
||||
|
||||
inline float GetMaxAccuracy() const
|
||||
{
|
||||
return maxAccuracy_;
|
||||
}
|
||||
|
||||
inline void SetMaxAccuracy(float maxAccuracy)
|
||||
{
|
||||
maxAccuracy_ = maxAccuracy;
|
||||
}
|
||||
|
||||
inline void SetFixNumber(int fixNumber)
|
||||
{
|
||||
fixNumber_ = fixNumber;
|
||||
}
|
||||
|
||||
inline int GetFixNumber()
|
||||
{
|
||||
return fixNumber_;
|
||||
}
|
||||
|
||||
void ReadFromParcel(Parcel& parcel);
|
||||
bool Marshalling(Parcel& parcel) const override;
|
||||
std::string ToString() const;
|
||||
static std::unique_ptr<RequestConfig> Unmarshalling(Parcel& parcel);
|
||||
void Set(RequestConfig& requestConfig);
|
||||
bool IsSame(RequestConfig& requestConfig);
|
||||
private:
|
||||
int scenario_;
|
||||
int timeInterval_;
|
||||
int distanceInterval_;
|
||||
float maxAccuracy_;
|
||||
int fixNumber_;
|
||||
int priority_;
|
||||
};
|
||||
} // Location
|
||||
} // OHOS
|
||||
#endif // OHOS_LOCATION_REQUEST_CONFIGRATION_H
|
112
location_common/common/include/satellite_status.h
Normal file
112
location_common/common/include/satellite_status.h
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SATELLITE_STATUS_H
|
||||
#define OHOS_SATELLITE_STATUS_H
|
||||
|
||||
#include <parcel.h>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class SatelliteStatus : public Parcelable {
|
||||
public:
|
||||
SatelliteStatus();
|
||||
explicit SatelliteStatus(SatelliteStatus &satelliteStatus);
|
||||
virtual ~SatelliteStatus() = default;
|
||||
|
||||
inline int GetSatellitesNumber() const
|
||||
{
|
||||
return satellitesNumber_;
|
||||
}
|
||||
|
||||
inline void SetSatellitesNumber(int num)
|
||||
{
|
||||
satellitesNumber_ = num;
|
||||
}
|
||||
|
||||
inline std::vector<int> GetSatelliteIds() const
|
||||
{
|
||||
return satelliteIds_;
|
||||
}
|
||||
|
||||
inline void SetSatelliteIds(std::vector<int> ids)
|
||||
{
|
||||
for (std::vector<int>::iterator it = ids.begin(); it != ids.end(); ++it) {
|
||||
satelliteIds_.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::vector<double> GetCarrierToNoiseDensitys() const
|
||||
{
|
||||
return carrierToNoiseDensitys_;
|
||||
}
|
||||
|
||||
inline void SetCarrierToNoiseDensitys(std::vector<double> ids)
|
||||
{
|
||||
for (std::vector<double>::iterator it = ids.begin(); it != ids.end(); ++it) {
|
||||
carrierToNoiseDensitys_.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::vector<double> GetAltitudes() const
|
||||
{
|
||||
return altitudes_;
|
||||
}
|
||||
|
||||
inline void SetAltitudes(std::vector<double> altitudes)
|
||||
{
|
||||
for (std::vector<double>::iterator it = altitudes.begin(); it != altitudes.end(); ++it) {
|
||||
altitudes_.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::vector<double> GetAzimuths() const
|
||||
{
|
||||
return azimuths_;
|
||||
}
|
||||
|
||||
inline void SetAzimuths(std::vector<double> azimuths)
|
||||
{
|
||||
for (std::vector<double>::iterator it = azimuths.begin(); it != azimuths.end(); ++it) {
|
||||
azimuths_.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::vector<double> GetCarrierFrequencies() const
|
||||
{
|
||||
return carrierFrequencies_;
|
||||
}
|
||||
|
||||
inline void SetCarrierFrequencies(std::vector<double> ids)
|
||||
{
|
||||
for (std::vector<double>::iterator it = ids.begin(); it != ids.end(); ++it) {
|
||||
carrierFrequencies_.push_back(*it);
|
||||
}
|
||||
}
|
||||
void ReadFromParcel(Parcel& parcel);
|
||||
bool Marshalling(Parcel& parcel) const override;
|
||||
static std::unique_ptr<SatelliteStatus> Unmarshalling(Parcel& parcel);
|
||||
private:
|
||||
int satellitesNumber_;
|
||||
std::vector<int> satelliteIds_;
|
||||
std::vector<double> carrierToNoiseDensitys_;
|
||||
std::vector<double> altitudes_;
|
||||
std::vector<double> azimuths_;
|
||||
std::vector<double> carrierFrequencies_;
|
||||
};
|
||||
} // Location
|
||||
} // OHOS
|
||||
#endif // OHOS_SATELLITE_STATUS_H
|
144
location_common/common/source/geo_address.cpp
Normal file
144
location_common/common/source/geo_address.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "geo_address.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
GeoAddress::GeoAddress()
|
||||
{
|
||||
m_latitude = 0.0;
|
||||
m_longitude = 0.0;
|
||||
}
|
||||
|
||||
std::string GeoAddress::GetDescriptions(int index)
|
||||
{
|
||||
if (index < 0) {
|
||||
return "";
|
||||
}
|
||||
if (m_descriptionsSize <= 0) {
|
||||
return "";
|
||||
}
|
||||
std::map<int, std::string>::iterator it = m_descriptions.find(index);
|
||||
if (it == m_descriptions.end()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
double GeoAddress::GetLatitude()
|
||||
{
|
||||
if (m_hasLatitude) {
|
||||
return m_latitude;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double GeoAddress::GetLongitude()
|
||||
{
|
||||
if (m_hasLongitude) {
|
||||
return m_longitude;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
std::unique_ptr<GeoAddress> GeoAddress::Unmarshalling(Parcel& parcel)
|
||||
{
|
||||
std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
|
||||
geoAddress->ReadFromParcel(parcel);
|
||||
return geoAddress;
|
||||
}
|
||||
|
||||
void GeoAddress::ReadFromParcel(Parcel& in)
|
||||
{
|
||||
m_localeLanguage = in.ReadString();
|
||||
m_localeCountry = in.ReadString();
|
||||
int size = in.ReadInt32();
|
||||
if (size > 0 && size < MAX_PARCEL_SIZE) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (in.GetWritableBytes() < PARCEL_INT_SIZE) {
|
||||
break;
|
||||
}
|
||||
int index = in.ReadInt32();
|
||||
std::string line = in.ReadString();
|
||||
m_descriptions.insert(std::pair<int, std::string>(index, line));
|
||||
m_descriptionsSize = std::max(m_descriptionsSize, index + 1);
|
||||
}
|
||||
} else {
|
||||
m_descriptionsSize = 0;
|
||||
}
|
||||
m_placeName = in.ReadString();
|
||||
m_administrativeArea = in.ReadString();
|
||||
m_subAdministrativeArea = in.ReadString();
|
||||
m_locality = in.ReadString();
|
||||
m_subLocality = in.ReadString();
|
||||
m_roadName = in.ReadString();
|
||||
m_subRoadName = in.ReadString();
|
||||
m_premises = in.ReadString();
|
||||
m_postalCode = in.ReadString();
|
||||
m_countryCode = in.ReadString();
|
||||
m_countryName = in.ReadString();
|
||||
m_hasLatitude = (in.ReadInt32() != 0);
|
||||
if (m_hasLatitude) {
|
||||
m_latitude = in.ReadDouble();
|
||||
}
|
||||
m_hasLongitude = (in.ReadInt32() != 0);
|
||||
if (m_hasLongitude) {
|
||||
m_longitude = in.ReadDouble();
|
||||
}
|
||||
m_phoneNumber = in.ReadString();
|
||||
m_addressUrl = in.ReadString();
|
||||
}
|
||||
|
||||
bool GeoAddress::Marshalling(Parcel& parcel) const
|
||||
{
|
||||
parcel.WriteString(m_localeLanguage);
|
||||
parcel.WriteString(m_localeCountry);
|
||||
if (m_descriptions.size() == 0) {
|
||||
parcel.WriteInt32(0);
|
||||
} else {
|
||||
parcel.WriteInt32(m_descriptions.size());
|
||||
for (auto iter = m_descriptions.begin(); iter != m_descriptions.end(); iter++) {
|
||||
parcel.WriteInt32(iter->first);
|
||||
parcel.WriteString(iter->second);
|
||||
}
|
||||
}
|
||||
parcel.WriteString(m_placeName);
|
||||
parcel.WriteString(m_administrativeArea);
|
||||
parcel.WriteString(m_subAdministrativeArea);
|
||||
parcel.WriteString(m_locality);
|
||||
parcel.WriteString(m_subLocality);
|
||||
parcel.WriteString(m_roadName);
|
||||
parcel.WriteString(m_subRoadName);
|
||||
parcel.WriteString(m_premises);
|
||||
parcel.WriteString(m_postalCode);
|
||||
parcel.WriteString(m_countryCode);
|
||||
parcel.WriteString(m_countryName);
|
||||
parcel.WriteInt32(m_hasLatitude ? 1 : 0);
|
||||
if (m_hasLatitude) {
|
||||
parcel.WriteDouble(m_latitude);
|
||||
}
|
||||
parcel.WriteInt32(m_hasLongitude ? 1 : 0);
|
||||
if (m_hasLongitude) {
|
||||
parcel.WriteDouble(m_longitude);
|
||||
}
|
||||
parcel.WriteString(m_phoneNumber);
|
||||
parcel.WriteString(m_addressUrl);
|
||||
return true;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
26
location_common/common/source/geofence_state.cpp
Normal file
26
location_common/common/source/geofence_state.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "geofence_state.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
GeoFenceState::GeoFenceState(const GeoFence fence, const AbilityRuntime::WantAgent::WantAgent wantAgent)
|
||||
{
|
||||
mFence = fence;
|
||||
mWantAgent = wantAgent;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
127
location_common/common/source/location.cpp
Normal file
127
location_common/common/source/location.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "location.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
Location::Location()
|
||||
{
|
||||
latitude_ = 0.0;
|
||||
longitude_ = 0.0;
|
||||
altitude_ = 0.0;
|
||||
accuracy_ = 0.0;
|
||||
speed_ = 0.0;
|
||||
direction_ = 0.0;
|
||||
timeStamp_ = 0;
|
||||
timeSinceBoot_ = 0;
|
||||
}
|
||||
|
||||
Location::Location(Location& location)
|
||||
{
|
||||
latitude_ = location.GetLatitude();
|
||||
longitude_ = location.GetLongitude();
|
||||
altitude_ = location.GetAltitude();
|
||||
accuracy_ = location.GetAccuracy();
|
||||
speed_ = location.GetSpeed();
|
||||
direction_ = location.GetDirection();
|
||||
timeStamp_ = location.GetTimeStamp();
|
||||
timeSinceBoot_ = location.GetTimeSinceBoot();
|
||||
}
|
||||
|
||||
void Location::ReadFromParcel(Parcel& parcel)
|
||||
{
|
||||
latitude_ = parcel.ReadDouble();
|
||||
longitude_ = parcel.ReadDouble();
|
||||
altitude_ = parcel.ReadDouble();
|
||||
accuracy_ = parcel.ReadFloat();
|
||||
speed_ = parcel.ReadFloat();
|
||||
direction_ = parcel.ReadDouble();
|
||||
timeStamp_ = parcel.ReadInt64();
|
||||
timeSinceBoot_ = parcel.ReadInt64();
|
||||
}
|
||||
|
||||
void Location::ReadFromParcelLocation(Parcel& parcel)
|
||||
{
|
||||
if (parcel.ReadInt32() == 0) {
|
||||
return;
|
||||
}
|
||||
parcel.ReadString16(); // read provider
|
||||
timeStamp_ = parcel.ReadInt64(); // read time
|
||||
timeSinceBoot_ = parcel.ReadInt64(); // read mElapsedRealtimeNanos
|
||||
parcel.ReadDouble(); // read mElapsedRealtimeUncertaintyNanos
|
||||
parcel.ReadInt32(); // read mFieldsMask
|
||||
latitude_ = parcel.ReadDouble(); // read mLatitude
|
||||
longitude_ = parcel.ReadDouble(); // read mLongitude
|
||||
altitude_ = parcel.ReadDouble(); // read mAltitude
|
||||
speed_ = parcel.ReadFloat(); // read mSpeed
|
||||
direction_ = parcel.ReadFloat(); // read mBearing
|
||||
accuracy_ = parcel.ReadFloat(); // read mHorizontalAccuracyMeters
|
||||
parcel.ReadFloat(); // read mVerticalAccuracyMeters
|
||||
parcel.ReadFloat(); // read mSpeedAccuracyMetersPerSecond
|
||||
parcel.ReadFloat(); // read mBearingAccuracyDegrees
|
||||
}
|
||||
|
||||
std::unique_ptr<Location> Location::UnmarshallingLocation(Parcel& parcel)
|
||||
{
|
||||
std::unique_ptr<Location> location = std::make_unique<Location>();
|
||||
location->ReadFromParcelLocation(parcel);
|
||||
return location;
|
||||
}
|
||||
|
||||
std::unique_ptr<Location> Location::Unmarshalling(Parcel& parcel)
|
||||
{
|
||||
std::unique_ptr<Location> location = std::make_unique<Location>();
|
||||
location->ReadFromParcel(parcel);
|
||||
return location;
|
||||
}
|
||||
|
||||
bool Location::Marshalling(Parcel& parcel) const
|
||||
{
|
||||
return parcel.WriteDouble(latitude_) &&
|
||||
parcel.WriteDouble(longitude_) &&
|
||||
parcel.WriteDouble(altitude_) &&
|
||||
parcel.WriteFloat(accuracy_) &&
|
||||
parcel.WriteFloat(speed_) &&
|
||||
parcel.WriteDouble(direction_) &&
|
||||
parcel.WriteInt64(timeStamp_) &&
|
||||
parcel.WriteInt64(timeSinceBoot_);
|
||||
}
|
||||
|
||||
std::string Location::ToString() const
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "latitude : ";
|
||||
str << latitude_;
|
||||
str << ", longitude : ";
|
||||
str << longitude_;
|
||||
str << ", altitude : ";
|
||||
str << altitude_;
|
||||
str << ", accuracy : ";
|
||||
str << accuracy_;
|
||||
str << ", speed : ";
|
||||
str << speed_;
|
||||
str << ", direction : ";
|
||||
str << direction_;
|
||||
str << ", timeStamp : ";
|
||||
str << timeStamp_;
|
||||
str << ", timeSinceBoot : ";
|
||||
str << timeSinceBoot_;
|
||||
return str.str();
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
230
location_common/common/source/location_config_manager.cpp
Normal file
230
location_common/common/source/location_config_manager.cpp
Normal file
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "location_config_manager.h"
|
||||
#include "common_utils.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
LocationConfigManager &LocationConfigManager::GetInstance()
|
||||
{
|
||||
static LocationConfigManager gLocationConfigManager;
|
||||
return gLocationConfigManager;
|
||||
}
|
||||
|
||||
LocationConfigManager::LocationConfigManager()
|
||||
{
|
||||
mLocationSwitchState = STATE_CLOSE;
|
||||
mPrivacyTypeState[0] = STATE_CLOSE;
|
||||
mPrivacyTypeState[1] = STATE_CLOSE;
|
||||
mPrivacyTypeState[2] = STATE_CLOSE;
|
||||
}
|
||||
|
||||
LocationConfigManager::~LocationConfigManager()
|
||||
{
|
||||
}
|
||||
|
||||
int LocationConfigManager::Init()
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "LocationConfigManager::Init");
|
||||
if (!IsExistFile(GetLocationSwitchConfigPath())) {
|
||||
CreateFile(GetLocationSwitchConfigPath(), "0");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool LocationConfigManager::IsExistFile(const std::string& filename)
|
||||
{
|
||||
bool bExist = false;
|
||||
std::fstream ioFile;
|
||||
char path[PATH_MAX + 1] = {0x00};
|
||||
if (strlen(filename.c_str()) > PATH_MAX || realpath(filename.c_str(), path) == NULL) {
|
||||
return false;
|
||||
}
|
||||
ioFile.open(path, std::ios::in);
|
||||
if (ioFile) {
|
||||
bExist = true;
|
||||
}
|
||||
ioFile.clear();
|
||||
ioFile.close();
|
||||
LBSLOGD(LOCATION_NAPI, "IsExistFile = %{public}d", bExist ? 1 : 0);
|
||||
return bExist;
|
||||
}
|
||||
|
||||
bool LocationConfigManager::CreateFile(const std::string& filename, const std::string& filedata)
|
||||
{
|
||||
LBSLOGD(LOCATION_NAPI, "CreateFile");
|
||||
std::ofstream outFile;
|
||||
outFile.open(filename.c_str());
|
||||
if (!outFile) {
|
||||
LBSLOGE(LOCATION_NAPI, "file open failed, %{public}s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
outFile.flush();
|
||||
outFile << filedata << std::endl;
|
||||
outFile.clear();
|
||||
outFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string LocationConfigManager::GetLocationSwitchConfigPath()
|
||||
{
|
||||
pid_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
int32_t userId = callingUid / PER_USER_RANGE;
|
||||
|
||||
std::string filePath = "/data/vendor/gnss/location_switch_" + std::to_string(userId) + ".conf";
|
||||
return filePath;
|
||||
}
|
||||
|
||||
std::string LocationConfigManager::GetPrivacyTypeConfigPath(const LocationPrivacyType type)
|
||||
{
|
||||
pid_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
int32_t userId = callingUid / PER_USER_RANGE;
|
||||
std::string filePath;
|
||||
switch (type) {
|
||||
case LocationPrivacyType::OTHERS: {
|
||||
filePath = "others_";
|
||||
break;
|
||||
}
|
||||
case LocationPrivacyType::STARTUP: {
|
||||
filePath = "startup_";
|
||||
break;
|
||||
}
|
||||
case LocationPrivacyType::CORE_LOCATION: {
|
||||
filePath = "core_location_";
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
filePath = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "/data/vendor/gnss/location_pricacy_" + filePath + std::to_string(userId) + ".conf";
|
||||
}
|
||||
|
||||
int LocationConfigManager::GetLocationSwitchState()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
if (!IsExistFile(GetLocationSwitchConfigPath())) {
|
||||
CreateFile(GetLocationSwitchConfigPath(), "0");
|
||||
}
|
||||
std::ifstream fs(GetLocationSwitchConfigPath());
|
||||
if (!fs.is_open()) {
|
||||
LBSLOGE(LOCATION_NAPI, "LocationConfigManager: fs.is_open false, return");
|
||||
return -1;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(fs, line)) {
|
||||
if (line.empty()) {
|
||||
break;
|
||||
}
|
||||
if (line[0] == '0') {
|
||||
mLocationSwitchState = STATE_CLOSE;
|
||||
} else if (line[0] == '1') {
|
||||
mLocationSwitchState = STATE_OPEN;
|
||||
}
|
||||
break;
|
||||
}
|
||||
fs.clear();
|
||||
fs.close();
|
||||
return mLocationSwitchState;
|
||||
}
|
||||
|
||||
int LocationConfigManager::SetLocationSwitchState(int state)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
if (!IsExistFile(GetLocationSwitchConfigPath())) {
|
||||
CreateFile(GetLocationSwitchConfigPath(), "0");
|
||||
}
|
||||
std::fstream fs(GetLocationSwitchConfigPath());
|
||||
if (state != STATE_CLOSE && state != STATE_OPEN) {
|
||||
LBSLOGE(LOCATION_NAPI, "LocationConfigManager:SetLocationSwitchState state = %{public}d, return", state);
|
||||
return -1;
|
||||
}
|
||||
if (!fs.is_open()) {
|
||||
LBSLOGE(LOCATION_NAPI, "LocationConfigManager: fs.is_open false, return");
|
||||
return -1;
|
||||
}
|
||||
std::ostringstream ss;
|
||||
if (state == STATE_CLOSE) {
|
||||
ss << "0" << std::endl;
|
||||
} else {
|
||||
ss << "1" << std::endl;
|
||||
}
|
||||
std::string content = ss.str();
|
||||
fs.write(content.c_str(), content.length());
|
||||
fs.clear();
|
||||
fs.close();
|
||||
mLocationSwitchState = state;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool LocationConfigManager::GetPrivacyTypeState(const LocationPrivacyType type)
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "LocationConfigManager::GetPrivacyTypeState");
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
if (!IsExistFile(GetPrivacyTypeConfigPath(type))) {
|
||||
CreateFile(GetPrivacyTypeConfigPath(type), "0");
|
||||
}
|
||||
std::ifstream fs(GetPrivacyTypeConfigPath(type));
|
||||
if (!fs.is_open()) {
|
||||
LBSLOGE(LOCATION_NAPI, "LocationConfigManager: fs.is_open false, return");
|
||||
return -1;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(fs, line)) {
|
||||
if (line.empty()) {
|
||||
break;
|
||||
}
|
||||
if (line[0] == '0') {
|
||||
mPrivacyTypeState[CommonUtils::GetPrivacyType(type)] = STATE_CLOSE;
|
||||
} else if (line[0] == '1') {
|
||||
mPrivacyTypeState[CommonUtils::GetPrivacyType(type)] = STATE_OPEN;
|
||||
}
|
||||
break;
|
||||
}
|
||||
fs.clear();
|
||||
fs.close();
|
||||
return (mPrivacyTypeState[CommonUtils::GetPrivacyType(type)] == 1) ? true : false;
|
||||
}
|
||||
|
||||
void LocationConfigManager::SetPrivacyTypeState(const LocationPrivacyType type, bool isConfirmed)
|
||||
{
|
||||
LBSLOGI(LOCATION_NAPI, "LocationConfigManager::SetPrivacyTypeState");
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
if (!IsExistFile(GetPrivacyTypeConfigPath(type))) {
|
||||
CreateFile(GetPrivacyTypeConfigPath(type), "0");
|
||||
}
|
||||
std::fstream fs(GetPrivacyTypeConfigPath(type));
|
||||
if (!fs.is_open()) {
|
||||
LBSLOGE(LOCATION_NAPI, "LocationConfigManager: fs.is_open false, return");
|
||||
return;
|
||||
}
|
||||
std::ostringstream ss;
|
||||
if (isConfirmed) {
|
||||
ss << "1" << std::endl;
|
||||
} else {
|
||||
ss << "0" << std::endl;
|
||||
}
|
||||
std::string content = ss.str();
|
||||
fs.write(content.c_str(), content.length());
|
||||
fs.clear();
|
||||
fs.close();
|
||||
mPrivacyTypeState[CommonUtils::GetPrivacyType(type)] = isConfirmed ? 1 : 0;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
117
location_common/common/source/location_dumper.cpp
Normal file
117
location_common/common/source/location_dumper.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "location_dumper.h"
|
||||
#include <functional>
|
||||
#include "lbs_log.h"
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const std::string ARGS_HELP = "-h";
|
||||
|
||||
void LocationDumper::PrintArgs(const std::vector<std::string>& vecArgs)
|
||||
{
|
||||
std::string strArgs;
|
||||
for (auto& each: vecArgs) {
|
||||
strArgs += each + "|";
|
||||
}
|
||||
LBSLOGI(COMMON_UTILS, "Dumper[%{public}zu] args: %{public}s", vecArgs.size(), strArgs.c_str());
|
||||
}
|
||||
|
||||
bool LocationDumper::GeocodeDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string>& vecArgs, std::string& result)
|
||||
{
|
||||
PrintArgs(vecArgs);
|
||||
result.clear();
|
||||
if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
|
||||
result.append("Geocode dump options:\n")
|
||||
.append(" [-h]\n")
|
||||
.append(" description of the cmd option:\n")
|
||||
.append(" -h: show help.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
saBasicDumpFunc(result);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocationDumper::GnssDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string>& vecArgs, std::string& result)
|
||||
{
|
||||
PrintArgs(vecArgs);
|
||||
result.clear();
|
||||
if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
|
||||
result.append("Gnss dump options:\n")
|
||||
.append(" [-h]\n")
|
||||
.append(" description of the cmd option:\n")
|
||||
.append(" -h: show help.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
saBasicDumpFunc(result);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocationDumper::LocatorDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string>& vecArgs, std::string& result)
|
||||
{
|
||||
PrintArgs(vecArgs);
|
||||
result.clear();
|
||||
if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
|
||||
result.append("Locator dump options:\n")
|
||||
.append(" [-h]\n")
|
||||
.append(" description of the cmd option:\n")
|
||||
.append(" -h: show help.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
saBasicDumpFunc(result);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocationDumper::NetWorkDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string>& vecArgs, std::string& result)
|
||||
{
|
||||
PrintArgs(vecArgs);
|
||||
result.clear();
|
||||
if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
|
||||
result.append("Network dump options:\n")
|
||||
.append(" [-h]\n")
|
||||
.append(" description of the cmd option:\n")
|
||||
.append(" -h: show help.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
saBasicDumpFunc(result);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocationDumper::PassiveDump(std::function<void(std::string&)> saBasicDumpFunc,
|
||||
const std::vector<std::string>& vecArgs, std::string& result)
|
||||
{
|
||||
PrintArgs(vecArgs);
|
||||
result.clear();
|
||||
if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
|
||||
result.append("Passive dump options:\n")
|
||||
.append(" [-h]\n")
|
||||
.append(" description of the cmd option:\n")
|
||||
.append(" -h: show help.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
saBasicDumpFunc(result);
|
||||
return true;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
108
location_common/common/source/request_config.cpp
Normal file
108
location_common/common/source/request_config.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "request_config.h"
|
||||
|
||||
#include <sstream>
|
||||
#include "constant_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
RequestConfig::RequestConfig()
|
||||
{
|
||||
scenario_ = SCENE_UNSET;
|
||||
priority_ = PRIORITY_UNSET;
|
||||
timeInterval_ = 0; // no time interval limit for reporting location
|
||||
distanceInterval_ = 0; // no distance interval limit for reporting location
|
||||
maxAccuracy_ = 0.0; // no accuracy limit for reporting location
|
||||
fixNumber_ = 0; // no fix size limit for reporting location
|
||||
}
|
||||
|
||||
RequestConfig::RequestConfig(const int scenario) : scenario_(scenario)
|
||||
{
|
||||
priority_ = PRIORITY_UNSET;
|
||||
timeInterval_ = 0; // no time interval limit for reporting location
|
||||
distanceInterval_ = 0; // no distance interval limit for reporting location
|
||||
maxAccuracy_ = 0.0; // no accuracy limit for reporting location
|
||||
fixNumber_ = 0; // no fix size limit for reporting location
|
||||
}
|
||||
|
||||
void RequestConfig::Set(RequestConfig& requestConfig)
|
||||
{
|
||||
scenario_ = requestConfig.GetScenario();
|
||||
priority_ = requestConfig.GetPriority();
|
||||
timeInterval_ = requestConfig.GetTimeInterval();
|
||||
distanceInterval_ = requestConfig.GetDistanceInterval();
|
||||
maxAccuracy_ = requestConfig.GetMaxAccuracy();
|
||||
fixNumber_ = requestConfig.GetFixNumber();
|
||||
}
|
||||
|
||||
bool RequestConfig::IsSame(RequestConfig& requestConfig)
|
||||
{
|
||||
if (scenario_ != requestConfig.GetScenario()) {
|
||||
return false;
|
||||
}
|
||||
if (scenario_ != SCENE_UNSET) {
|
||||
return true;
|
||||
}
|
||||
return priority_ == requestConfig.GetPriority();
|
||||
}
|
||||
|
||||
void RequestConfig::ReadFromParcel(Parcel& parcel)
|
||||
{
|
||||
scenario_ = parcel.ReadInt32();
|
||||
priority_ = parcel.ReadInt32();
|
||||
timeInterval_ = parcel.ReadInt32();
|
||||
distanceInterval_ = parcel.ReadInt32();
|
||||
maxAccuracy_ = parcel.ReadFloat();
|
||||
fixNumber_ = parcel.ReadInt32();
|
||||
}
|
||||
|
||||
std::unique_ptr<RequestConfig> RequestConfig::Unmarshalling(Parcel& parcel)
|
||||
{
|
||||
std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
|
||||
requestConfig->ReadFromParcel(parcel);
|
||||
return requestConfig;
|
||||
}
|
||||
|
||||
bool RequestConfig::Marshalling(Parcel& parcel) const
|
||||
{
|
||||
return parcel.WriteInt32(scenario_) &&
|
||||
parcel.WriteInt32(priority_) &&
|
||||
parcel.WriteInt32(timeInterval_) &&
|
||||
parcel.WriteInt32(distanceInterval_) &&
|
||||
parcel.WriteFloat(maxAccuracy_) &&
|
||||
parcel.WriteInt32(fixNumber_);
|
||||
}
|
||||
|
||||
std::string RequestConfig::ToString() const
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "scenario : ";
|
||||
str << scenario_;
|
||||
str << ", location priority : ";
|
||||
str << priority_;
|
||||
str << ", timeInterval : ";
|
||||
str << timeInterval_;
|
||||
str << ", distanceInterval : ";
|
||||
str << distanceInterval_;
|
||||
str << ", maxAccuracy : ";
|
||||
str << maxAccuracy_;
|
||||
str << ", fixNumber : ";
|
||||
str << fixNumber_;
|
||||
return str.str();
|
||||
}
|
||||
} // Location
|
||||
} // OHOS
|
69
location_common/common/source/satellite_status.cpp
Normal file
69
location_common/common/source/satellite_status.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "satellite_status.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
SatelliteStatus::SatelliteStatus()
|
||||
{
|
||||
satellitesNumber_ = 0;
|
||||
}
|
||||
|
||||
SatelliteStatus::SatelliteStatus(SatelliteStatus& satelliteStatus)
|
||||
{
|
||||
satellitesNumber_ = satelliteStatus.GetSatellitesNumber();
|
||||
satelliteIds_ = satelliteStatus.GetSatelliteIds();
|
||||
carrierToNoiseDensitys_ = satelliteStatus.GetCarrierToNoiseDensitys();
|
||||
altitudes_ = satelliteStatus.GetAltitudes();
|
||||
azimuths_ = satelliteStatus.GetAzimuths();
|
||||
carrierFrequencies_ = satelliteStatus.GetCarrierFrequencies();
|
||||
}
|
||||
|
||||
void SatelliteStatus::ReadFromParcel(Parcel& parcel)
|
||||
{
|
||||
satellitesNumber_ = parcel.ReadInt64();
|
||||
for (int i = 0; i < satellitesNumber_; i++) {
|
||||
satelliteIds_[i] = parcel.ReadInt64();
|
||||
carrierToNoiseDensitys_[i] = parcel.ReadDouble();
|
||||
altitudes_[i] = parcel.ReadDouble();
|
||||
azimuths_[i] = parcel.ReadDouble();
|
||||
carrierFrequencies_[i] = parcel.ReadDouble();
|
||||
}
|
||||
}
|
||||
|
||||
bool SatelliteStatus::Marshalling(Parcel& parcel) const
|
||||
{
|
||||
bool ret = false;
|
||||
ret = parcel.WriteInt64(satellitesNumber_);
|
||||
for (int i = 0; i < satellitesNumber_; i++) {
|
||||
ret = parcel.WriteInt64(satelliteIds_[i]);
|
||||
ret = parcel.WriteInt64(satelliteIds_[i]);
|
||||
ret = parcel.WriteDouble(carrierToNoiseDensitys_[i]);
|
||||
ret = parcel.WriteDouble(altitudes_[i]);
|
||||
ret = parcel.WriteDouble(azimuths_[i]);
|
||||
ret = parcel.WriteDouble(carrierFrequencies_[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::unique_ptr<SatelliteStatus> SatelliteStatus::Unmarshalling(Parcel& parcel)
|
||||
{
|
||||
std::unique_ptr<SatelliteStatus> status = std::make_unique<SatelliteStatus>();
|
||||
status->ReadFromParcel(parcel);
|
||||
return status;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
25
location_geocode/BUILD.gn
Normal file
25
location_geocode/BUILD.gn
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/config/ohos/rules.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos_var.gni")
|
||||
|
||||
ohos_subsystem("location") {
|
||||
subsystem_packages = [ "location_geocode:lbsservice_geocode" ]
|
||||
}
|
||||
|
||||
ohos_subsystem_test("location_test") {
|
||||
testonly = true
|
||||
test_packages = [ "location_geocode/test/unittest:unittest" ]
|
||||
}
|
47
location_geocode/bundle.json
Normal file
47
location_geocode/bundle.json
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@ohos/location_geocode",
|
||||
"version": "3.1.0",
|
||||
"description": "Geocoding Capability in Location Services.",
|
||||
"homePage": "https://gitee.com/openharmony",
|
||||
"license": "Apache License 2.0",
|
||||
"repository": "",
|
||||
"domain": "os",
|
||||
"language": "",
|
||||
"publishAs": "code-segment",
|
||||
"private": false,
|
||||
"segment": {
|
||||
"destPath": "base/location/location_geocode"
|
||||
},
|
||||
"component": {
|
||||
"name": "location_geocode",
|
||||
"subsystem": "location",
|
||||
"syscap": [
|
||||
"SystemCapability.Location.Location"
|
||||
],
|
||||
"features": [],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"deps": {
|
||||
"components": [
|
||||
"ipc",
|
||||
"ces_standard",
|
||||
"hiviewdfx_hilog_native",
|
||||
"access_token"
|
||||
],
|
||||
"third_party": []
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//base/location/location_geocode/geocode:lbsservice_geocode",
|
||||
"//base/location/etc:etc",
|
||||
"//base/location/profile:location_sa_profile"
|
||||
],
|
||||
"test": [
|
||||
"//base/location/location_geocode/test/unittest:unittest"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
60
location_geocode/geocode/BUILD.gn
Normal file
60
location_geocode/geocode/BUILD.gn
Normal file
@ -0,0 +1,60 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
SUBSYSTEM_DIR = "//base/location"
|
||||
LOCATION_GEOCONVERT_ROOT = "$SUBSYSTEM_DIR/location_geocode/geocode"
|
||||
LOCATION_SERVICE_ROOT = "$SUBSYSTEM_DIR/services"
|
||||
|
||||
ohos_shared_library("lbsservice_geocode") {
|
||||
sources = [
|
||||
"$LOCATION_GEOCONVERT_ROOT/source/geo_convert_service.cpp",
|
||||
"$LOCATION_GEOCONVERT_ROOT/source/geo_convert_skeleton.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/include",
|
||||
"$SUBSYSTEM_DIR/location_common/common/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/distribute/include",
|
||||
"$SUBSYSTEM_DIR/location_geocode/geocode/include",
|
||||
"$SUBSYSTEM_DIR/location_gnss/gnss/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/include",
|
||||
"$SUBSYSTEM_DIR/location_network/network/include",
|
||||
"$SUBSYSTEM_DIR/location_passive/passive/include",
|
||||
"$LOCATION_SERVICE_ROOT/visibility/include",
|
||||
"$SUBSYSTEM_DIR/utils/include",
|
||||
"$SUBSYSTEM_DIR/adapter/services/include",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk/",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include"
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$SUBSYSTEM_DIR/location_common/common:lbsservice_common",
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
part_name = "location_geocode"
|
||||
subsystem_name = "location"
|
||||
}
|
59
location_geocode/geocode/include/geo_convert_service.h
Normal file
59
location_geocode/geocode/include/geo_convert_service.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_GEO_CONVERT_SERVICE_H
|
||||
#define OHOS_LOCATION_GEO_CONVERT_SERVICE_H
|
||||
|
||||
#include <mutex>
|
||||
#include <singleton.h>
|
||||
|
||||
#include "geo_convert_skeleton.h"
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class GeoConvertService : public SystemAbility, public GeoConvertServiceStub, DelayedSingleton<GeoConvertService> {
|
||||
DECLEAR_SYSTEM_ABILITY(GeoConvertService);
|
||||
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(GeoConvertService);
|
||||
GeoConvertService();
|
||||
~GeoConvertService();
|
||||
void OnStart() override;
|
||||
void OnStop() override;
|
||||
ServiceRunningState QueryServiceState() const
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
int IsGeoConvertAvailable(MessageParcel &data, MessageParcel &rep) override;
|
||||
int GetAddressByCoordinate(MessageParcel &data, MessageParcel &rep) override;
|
||||
int GetAddressByLocationName(MessageParcel &data, MessageParcel &rep) override;
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
private:
|
||||
static void SaDumpInfo(std::string& result);
|
||||
int RemoteToService(uint32_t code, MessageParcel &data, MessageParcel &rep);
|
||||
bool Init();
|
||||
|
||||
bool registerToService_ = false;
|
||||
ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
|
||||
sptr<IRemoteObject> locationService_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
} // namespace Location
|
||||
#endif // OHOS_LOCATION_GEO_CONVERT_SERVICE_H
|
61
location_geocode/geocode/include/geo_convert_skeleton.h
Normal file
61
location_geocode/geocode/include/geo_convert_skeleton.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_GEO_CONVERT_SKELETON_H
|
||||
#define OHOS_LOCATION_GEO_CONVERT_SKELETON_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class IGeoConvert : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
IS_AVAILABLE = 11,
|
||||
GET_FROM_COORDINATE = 12,
|
||||
GET_FROM_LOCATION_NAME_BY_BOUNDARY = 13,
|
||||
};
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"location.IGeoConvert");
|
||||
virtual int IsGeoConvertAvailable(MessageParcel &data, MessageParcel &rep) = 0;
|
||||
virtual int GetAddressByCoordinate(MessageParcel &data, MessageParcel &rep) = 0;
|
||||
virtual int GetAddressByLocationName(MessageParcel &data, MessageParcel &rep) = 0;
|
||||
};
|
||||
|
||||
class GeoConvertServiceStub : public IRemoteStub<IGeoConvert> {
|
||||
public:
|
||||
int32_t OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
private:
|
||||
static pid_t lastCallingPid;
|
||||
static pid_t lastCallinguid;
|
||||
};
|
||||
|
||||
class GeoConvertProxy : public IRemoteProxy<IGeoConvert> {
|
||||
public:
|
||||
explicit GeoConvertProxy(const sptr<IRemoteObject> &impl);
|
||||
~GeoConvertProxy() = default;
|
||||
int IsGeoConvertAvailable(MessageParcel &data, MessageParcel &rep) override;
|
||||
int GetAddressByCoordinate(MessageParcel &data, MessageParcel &rep) override;
|
||||
int GetAddressByLocationName(MessageParcel &data, MessageParcel &rep) override;
|
||||
private:
|
||||
static inline BrokerDelegator<GeoConvertProxy> delegator_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
} // namespace Location
|
||||
#endif // OHOS_LOCATION_GEO_CONVERT_SKELETON_H
|
116
location_geocode/geocode/source/geo_convert_service.cpp
Normal file
116
location_geocode/geocode/source/geo_convert_service.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "geo_convert_service.h"
|
||||
#include <file_ex.h>
|
||||
#include "geo_address.h"
|
||||
#include "location_dumper.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(
|
||||
DelayedSingleton<GeoConvertService>::GetInstance().get());
|
||||
|
||||
GeoConvertService::GeoConvertService() : SystemAbility(LOCATION_GEO_CONVERT_SA_ID, true)
|
||||
{
|
||||
LBSLOGI(GEO_CONVERT, "GeoConvertService constructed.");
|
||||
}
|
||||
|
||||
GeoConvertService::~GeoConvertService()
|
||||
{
|
||||
}
|
||||
|
||||
void GeoConvertService::OnStart()
|
||||
{
|
||||
if (state_ == ServiceRunningState::STATE_RUNNING) {
|
||||
LBSLOGI(GEO_CONVERT, "GeoConvertService has already started.");
|
||||
return;
|
||||
}
|
||||
if (!Init()) {
|
||||
LBSLOGE(GEO_CONVERT, "failed to init GeoConvertService");
|
||||
OnStop();
|
||||
return;
|
||||
}
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
LBSLOGI(GEO_CONVERT, "GeoConvertService::OnStart start service success.");
|
||||
}
|
||||
|
||||
void GeoConvertService::OnStop()
|
||||
{
|
||||
state_ = ServiceRunningState::STATE_NOT_START;
|
||||
registerToService_ = false;
|
||||
LBSLOGI(GEO_CONVERT, "GeoConvertService::OnStop service stopped.");
|
||||
}
|
||||
|
||||
bool GeoConvertService::Init()
|
||||
{
|
||||
if (!registerToService_) {
|
||||
bool ret = Publish(AsObject());
|
||||
if (!ret) {
|
||||
LBSLOGE(GEO_CONVERT, "GeoConvertService::Init Publish failed!");
|
||||
return false;
|
||||
}
|
||||
registerToService_ = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int GeoConvertService::IsGeoConvertAvailable(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
reply.WriteInt32(0);
|
||||
reply.WriteInt32(1);
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
int GeoConvertService::GetAddressByCoordinate(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
reply.WriteInt32(0);
|
||||
reply.WriteInt32(1);
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
int GeoConvertService::GetAddressByLocationName(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
LBSLOGD(GEO_CONVERT, "GetAddressByLocationName");
|
||||
reply.WriteInt32(0);
|
||||
reply.WriteInt32(1);
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
void GeoConvertService::SaDumpInfo(std::string& result)
|
||||
{
|
||||
result += "GeoConvert enable status: true";
|
||||
result += "\n";
|
||||
}
|
||||
|
||||
int32_t GeoConvertService::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
std::vector<std::string> vecArgs;
|
||||
std::transform(args.begin(), args.end(), std::back_inserter(vecArgs), [](const std::u16string &arg) {
|
||||
return Str16ToStr8(arg);
|
||||
});
|
||||
|
||||
LocationDumper dumper;
|
||||
std::string result;
|
||||
dumper.GeocodeDump(SaDumpInfo, vecArgs, result);
|
||||
if (!SaveStringToFd(fd, result)) {
|
||||
LBSLOGE(GEO_CONVERT, "Geocode save string to fd failed!");
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
87
location_geocode/geocode/source/geo_convert_skeleton.cpp
Normal file
87
location_geocode/geocode/source/geo_convert_skeleton.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "geo_convert_skeleton.h"
|
||||
#include "common_utils.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
GeoConvertProxy::GeoConvertProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<IGeoConvert>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int GeoConvertProxy::IsGeoConvertAvailable(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int error;
|
||||
MessageOption option;
|
||||
error = Remote()->SendRequest(IS_AVAILABLE, data, reply, option);
|
||||
LBSLOGI(GEO_CONVERT, "IsGeoConvertAvailable result from server");
|
||||
return error;
|
||||
}
|
||||
|
||||
int GeoConvertProxy::GetAddressByCoordinate(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int error;
|
||||
MessageOption option;
|
||||
error = Remote()->SendRequest(GET_FROM_COORDINATE, data, reply, option);
|
||||
LBSLOGI(GEO_CONVERT, "GetAddressByCoordinate result from server.");
|
||||
return error;
|
||||
}
|
||||
|
||||
int GeoConvertProxy::GetAddressByLocationName(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int error;
|
||||
MessageOption option;
|
||||
error = Remote()->SendRequest(GET_FROM_LOCATION_NAME_BY_BOUNDARY, data, reply, option);
|
||||
LBSLOGI(GEO_CONVERT, "GetAddressByLocationName result from server.");
|
||||
return error;
|
||||
}
|
||||
|
||||
int GeoConvertServiceStub::OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
pid_t callingPid = IPCSkeleton::GetCallingPid();
|
||||
pid_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
LBSLOGI(GEO_CONVERT, "OnRemoteRequest cmd = %{public}d, flags= %{public}d, pid= %{public}d, uid= %{public}d",
|
||||
code, option.GetFlags(), callingPid, callingUid);
|
||||
if (callingUid > SYSTEM_UID) {
|
||||
LBSLOGE(GEO_CONVERT, "this remote request is not allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret;
|
||||
switch (code) {
|
||||
case IS_AVAILABLE: {
|
||||
ret = IsGeoConvertAvailable(data, reply);
|
||||
break;
|
||||
}
|
||||
case GET_FROM_COORDINATE: {
|
||||
ret = GetAddressByCoordinate(data, reply);
|
||||
break;
|
||||
}
|
||||
case GET_FROM_LOCATION_NAME_BY_BOUNDARY: {
|
||||
ret = GetAddressByLocationName(data, reply);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
85
location_geocode/test/unittest/BUILD.gn
Normal file
85
location_geocode/test/unittest/BUILD.gn
Normal file
@ -0,0 +1,85 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/appexecfwk/standard/appexecfwk.gni")
|
||||
|
||||
SUBSYSTEM_DIR = "//base/location"
|
||||
module_output_path = "location/service"
|
||||
|
||||
ohos_unittest("GeocodeServiceAbilityTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "$SUBSYSTEM_DIR/location_geocode/test/unittest/source/geo_convert_service_test.cpp" ]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"$SUBSYSTEM_DIR/utils/include",
|
||||
"$SUBSYSTEM_DIR/location_geocode/geocode/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/include",
|
||||
"$SUBSYSTEM_DIR/location_common/common/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/include",
|
||||
"$SUBSYSTEM_DIR/location_gnss/gnss/include",
|
||||
"$SUBSYSTEM_DIR/location_network/network/include",
|
||||
"$SUBSYSTEM_DIR/location_passive/passive/include",
|
||||
"$SUBSYSTEM_DIR/visibility/include",
|
||||
"$SUBSYSTEM_DIR/location_geocode/test/unittest/include",
|
||||
"$SUBSYSTEM_DIR/adapter/services/include",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk/",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"//foundation/aafwk/intent/interfaces/innerkits/base/include",
|
||||
"//foundation/appexecfwk/adapter/interfaces/innerkits/appexecfwk_base/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include",
|
||||
"//base/notification/ces_standard/frameworks/core/include",
|
||||
"//base/notification/ces_standard/interfaces/innerkits/native/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include",
|
||||
"//foundation/resourceschedule/backgroundtaskmanager/interfaces/innerkits/native/include",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include"
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$SUBSYSTEM_DIR/location_common/common:lbsservice_common",
|
||||
"$SUBSYSTEM_DIR/location_geocode/geocode:lbsservice_geocode",
|
||||
"${aafwk_path}/interfaces/innerkits/base:base",
|
||||
"${aafwk_path}/interfaces/innerkits/want:want",
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//base/notification/ces_standard/frameworks/core:cesfwk_core",
|
||||
"//base/notification/ces_standard/frameworks/native:cesfwk_innerkits",
|
||||
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
]
|
||||
|
||||
module_out_path = module_output_path
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":GeocodeServiceAbilityTest" ]
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_GEOCONVERT_UNITTEST
|
||||
#define OHOS_LOCATION_GEOCONVERT_UNITTEST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "geo_convert_skeleton.h"
|
||||
|
||||
class GeoConvertServiceTest : public testing::Test {
|
||||
public:
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
bool IsDeviceSupport();
|
||||
bool Available();
|
||||
OHOS::sptr<OHOS::Location::GeoConvertProxy> proxy_;
|
||||
bool available_;
|
||||
};
|
||||
#endif
|
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "geo_convert_service_test.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "geo_convert_service.h"
|
||||
#include "geo_convert_skeleton.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "lbs_log.h"
|
||||
#include "parameters.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::Location;
|
||||
|
||||
void GeoConvertServiceTest::SetUp()
|
||||
{
|
||||
/**
|
||||
* @tc.setup: Get system ability's pointer and get sa proxy object.
|
||||
*/
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
EXPECT_NE(nullptr, systemAbilityManager);
|
||||
sptr<IRemoteObject> object = systemAbilityManager->GetSystemAbility(LOCATION_GEO_CONVERT_SA_ID);
|
||||
EXPECT_NE(nullptr, object);
|
||||
proxy_ = new (std::nothrow) GeoConvertProxy(object);
|
||||
EXPECT_NE(nullptr, proxy_);
|
||||
available_ = Available();
|
||||
}
|
||||
|
||||
void GeoConvertServiceTest::TearDown()
|
||||
{
|
||||
/**
|
||||
* @tc.teardown: release memory.
|
||||
*/
|
||||
proxy_ = nullptr;
|
||||
}
|
||||
|
||||
bool GeoConvertServiceTest::IsDeviceSupport()
|
||||
{
|
||||
std::string result = OHOS::system::GetParameter(BUILD_INFO, "unknown");
|
||||
if (DEVICE_PLATE.compare(result) == 0 || DEVICE_UNKOWN.compare(result) == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeoConvertServiceTest::Available()
|
||||
{
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel replyParcel;
|
||||
if (proxy_ != nullptr) {
|
||||
proxy_->IsGeoConvertAvailable(dataParcel, replyParcel);
|
||||
}
|
||||
replyParcel.ReadInt32();
|
||||
int temp = replyParcel.ReadInt32();
|
||||
bool result = (temp != 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GeoConvertAvailable001
|
||||
* @tc.desc: Check location system ability whether available.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(GeoConvertServiceTest, GeoConvertAvailable001, TestSize.Level1)
|
||||
{
|
||||
if (!IsDeviceSupport() || !available_) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. Call system ability and check whether available.
|
||||
* @tc.expected: step1. system ability is available.
|
||||
*/
|
||||
bool result = Available();
|
||||
EXPECT_EQ(true, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GeoAddressByCoordinate001
|
||||
* @tc.desc: Test get address from system ability by coordinate.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(GeoConvertServiceTest, GetAddressByCoordinate001, TestSize.Level1)
|
||||
{
|
||||
if (!IsDeviceSupport() || !available_) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.steps: step1.read test data.
|
||||
*/
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel replyParcel;
|
||||
dataParcel.WriteDouble(39.92879); // latitude
|
||||
dataParcel.WriteDouble(116.3709); // longitude
|
||||
dataParcel.WriteInt32(5); // maxItem
|
||||
dataParcel.WriteInt32(1); // geocoder param object tag
|
||||
dataParcel.WriteString16(Str8ToStr16("ZH")); // language
|
||||
dataParcel.WriteString16(Str8ToStr16("cn")); // country
|
||||
dataParcel.WriteString16(Str8ToStr16("")); // description
|
||||
dataParcel.WriteString16(Str8ToStr16("test")); // package name
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. test get address by coordinate.
|
||||
* @tc.expected: step2. no exception head info.
|
||||
*/
|
||||
proxy_->GetAddressByCoordinate(dataParcel, replyParcel);
|
||||
bool ret = false;
|
||||
int exceptionHeader = replyParcel.ReadInt32();
|
||||
if (exceptionHeader == REPLY_NO_EXCEPTION) {
|
||||
ret = true;
|
||||
}
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAddressByLocationName001
|
||||
* @tc.desc: Test get address from system ability by location name.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(GeoConvertServiceTest, GetAddressByLocationName001, TestSize.Level1)
|
||||
{
|
||||
if (!IsDeviceSupport() || !available_) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.steps: step1.read test data.
|
||||
*/
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel replyParcel;
|
||||
dataParcel.WriteString16(Str8ToStr16("北京")); // input description of a location
|
||||
dataParcel.WriteDouble(0.0); // minLatitude
|
||||
dataParcel.WriteDouble(0.0); // minLongitude
|
||||
dataParcel.WriteDouble(0.0); // maxLatitude
|
||||
dataParcel.WriteDouble(0.0); // maxLongitude
|
||||
dataParcel.WriteInt32(5); // maxItem
|
||||
dataParcel.WriteInt32(1); // description
|
||||
dataParcel.WriteString16(Str8ToStr16("ZH")); // language
|
||||
dataParcel.WriteString16(Str8ToStr16("cn")); // country
|
||||
dataParcel.WriteString16(Str8ToStr16("")); // description
|
||||
dataParcel.WriteString16(u"ohos"); // package name
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. test get address by location's name.
|
||||
* @tc.expected: step2. no exception head info.
|
||||
*/
|
||||
proxy_->GetAddressByLocationName(dataParcel, replyParcel);
|
||||
bool ret = false;
|
||||
int exceptionHeader = replyParcel.ReadInt32();
|
||||
if (exceptionHeader == REPLY_NO_EXCEPTION) {
|
||||
ret = true;
|
||||
}
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
20
location_gnss/BUILD.gn
Normal file
20
location_gnss/BUILD.gn
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/config/ohos/rules.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos_var.gni")
|
||||
|
||||
ohos_subsystem("location") {
|
||||
subsystem_packages = [ "location_gnss:lbsservice_gnss" ]
|
||||
}
|
46
location_gnss/bundle.json
Normal file
46
location_gnss/bundle.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "@ohos/location_gnss",
|
||||
"version": "3.1.0",
|
||||
"description": "Satellite Positioning Capability in Location Service.",
|
||||
"homePage": "https://gitee.com/openharmony",
|
||||
"license": "Apache License 2.0",
|
||||
"repository": "",
|
||||
"domain": "os",
|
||||
"language": "",
|
||||
"publishAs": "code-segment",
|
||||
"private": false,
|
||||
"segment": {
|
||||
"destPath": "base/location/location_gnss"
|
||||
},
|
||||
"component": {
|
||||
"name": "location_gnss",
|
||||
"subsystem": "location",
|
||||
"syscap": [
|
||||
"SystemCapability.Location.Location"
|
||||
],
|
||||
"features": [],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"deps": {
|
||||
"components": [
|
||||
"ipc",
|
||||
"ces_standard",
|
||||
"hiviewdfx_hilog_native",
|
||||
"appexecfwk_standard",
|
||||
"hisysevent_native"
|
||||
],
|
||||
"third_party": []
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//base/location/location_gnss/gnss:lbsservice_gnss",
|
||||
"//base/location/etc:etc",
|
||||
"//base/location/profile:location_sa_profile"
|
||||
],
|
||||
"test": []
|
||||
}
|
||||
}
|
||||
}
|
77
location_gnss/gnss/BUILD.gn
Normal file
77
location_gnss/gnss/BUILD.gn
Normal file
@ -0,0 +1,77 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/appexecfwk/standard/appexecfwk.gni")
|
||||
|
||||
SUBSYSTEM_DIR = "//base/location"
|
||||
LOCATION_GNSS_ROOT = "$SUBSYSTEM_DIR/location_gnss/gnss"
|
||||
LOCATION_SERVICE_ROOT = "$SUBSYSTEM_DIR/services"
|
||||
|
||||
ohos_shared_library("lbsservice_gnss") {
|
||||
sources = [
|
||||
"$LOCATION_GNSS_ROOT/source/gnss_ability.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/gnss_ability_skeleton.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/include",
|
||||
"$SUBSYSTEM_DIR/location_common/common/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/distribute/include",
|
||||
"$SUBSYSTEM_DIR/location_geocode/geocode/include",
|
||||
"$SUBSYSTEM_DIR/location_gnss/gnss/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/include",
|
||||
"$SUBSYSTEM_DIR/location_network/network/include",
|
||||
"$SUBSYSTEM_DIR/location_passive/passive/include",
|
||||
"$LOCATION_SERVICE_ROOT/visibility/include",
|
||||
"$SUBSYSTEM_DIR/utils/include",
|
||||
"$SUBSYSTEM_DIR/adapter/services/include",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk/",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"//foundation/aafwk/intent/interfaces/innerkits/base/include",
|
||||
"//foundation/appexecfwk/adapter/interfaces/innerkits/appexecfwk_base/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include",
|
||||
"//base/notification/ces_standard/frameworks/core/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$SUBSYSTEM_DIR/location_common/common:lbsservice_common",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator:lbsservice_locator",
|
||||
"//base/location/interfaces/innerkits/locator_standard:locator_sdk",
|
||||
"${aafwk_path}/interfaces/innerkits/base:base",
|
||||
"${aafwk_path}/interfaces/innerkits/want:want",
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//base/notification/ces_standard/frameworks/core:cesfwk_core",
|
||||
"//base/notification/ces_standard/frameworks/native:cesfwk_innerkits",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"hisysevent_native:libhisysevent",
|
||||
]
|
||||
|
||||
part_name = "location_gnss"
|
||||
subsystem_name = "location"
|
||||
}
|
74
location_gnss/gnss/include/gnss_ability.h
Normal file
74
location_gnss/gnss/include/gnss_ability.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_GNSS_ABILITY_H
|
||||
#define OHOS_LOCATION_GNSS_ABILITY_H
|
||||
|
||||
#include <mutex>
|
||||
#include <singleton.h>
|
||||
#include "i_gnss_status_callback.h"
|
||||
#include "i_nmea_message_callback.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "gnss_ability_skeleton.h"
|
||||
#include "subability_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class GnssAbility : public SystemAbility, public GnssAbilityStub, public SubAbility, DelayedSingleton<GnssAbility> {
|
||||
DECLEAR_SYSTEM_ABILITY(GnssAbility);
|
||||
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(GnssAbility);
|
||||
GnssAbility();
|
||||
~GnssAbility();
|
||||
void OnStart() override;
|
||||
void OnStop() override;
|
||||
ServiceRunningState QueryServiceState() const
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
void SendLocationRequest(uint64_t interval, WorkRecord &workrecord) override;
|
||||
std::unique_ptr<Location> GetCachedLocation() override;
|
||||
void SetEnable(bool state) override;
|
||||
void RemoteRequest(bool state) override;
|
||||
void RefrashRequirements() override;
|
||||
void RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
void UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) override;
|
||||
void RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
void UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) override;
|
||||
void RegisterCachedCallback(const std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
const sptr<IRemoteObject>& callback) override;
|
||||
void UnregisterCachedCallback(const sptr<IRemoteObject>& callback) override;
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
|
||||
int GetCachedGnssLocationsSize() override;
|
||||
void FlushCachedGnssLocations() override;
|
||||
void SendCommand(std::unique_ptr<LocationCommand>& commands) override;
|
||||
void AddFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
void RemoveFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
private:
|
||||
std::unique_ptr<std::map<pid_t, sptr<IGnssStatusCallback>>> gnssStatusCallback_;
|
||||
std::unique_ptr<std::map<pid_t, sptr<INmeaMessageCallback>>> nmeaCallback_;
|
||||
bool Init();
|
||||
static void SaDumpInfo(std::string& result);
|
||||
bool registerToAbility_ = false;
|
||||
ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_GNSS_ABILITY_H
|
80
location_gnss/gnss/include/gnss_ability_skeleton.h
Normal file
80
location_gnss/gnss/include/gnss_ability_skeleton.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_GNSS_ABILITY_SKELETON_H
|
||||
#define OHOS_LOCATION_GNSS_ABILITY_SKELETON_H
|
||||
|
||||
#include "constant_definition.h"
|
||||
#include "subability_common.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class IGnssAbility : public ISubAbility {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"location.IGnssAbility");
|
||||
virtual void RemoteRequest(bool state) = 0;
|
||||
virtual void RefrashRequirements() = 0;
|
||||
virtual void RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) = 0;
|
||||
virtual void UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) = 0;
|
||||
virtual void RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) = 0;
|
||||
virtual void UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) = 0;
|
||||
virtual void RegisterCachedCallback(const std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
const sptr<IRemoteObject>& callback) = 0;
|
||||
virtual void UnregisterCachedCallback(const sptr<IRemoteObject>& callback) = 0;
|
||||
|
||||
virtual int GetCachedGnssLocationsSize() = 0;
|
||||
virtual void FlushCachedGnssLocations() = 0;
|
||||
virtual void SendCommand(std::unique_ptr<LocationCommand>& commands) = 0;
|
||||
virtual void AddFence(std::unique_ptr<GeofenceRequest>& request) = 0;
|
||||
virtual void RemoveFence(std::unique_ptr<GeofenceRequest>& request) = 0;
|
||||
};
|
||||
|
||||
class GnssAbilityProxy : public IRemoteProxy<IGnssAbility>, public SubAbilityProxy {
|
||||
public:
|
||||
explicit GnssAbilityProxy(const sptr<IRemoteObject> &impl);
|
||||
~GnssAbilityProxy() = default;
|
||||
void SendLocationRequest(uint64_t interval, WorkRecord &workrecord) override;
|
||||
std::unique_ptr<Location> GetCachedLocation() override;
|
||||
void SetEnable(bool state) override;
|
||||
void RemoteRequest(bool state) override;
|
||||
void RefrashRequirements() override;
|
||||
void RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
void UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) override;
|
||||
void RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
void UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) override;
|
||||
void RegisterCachedCallback(const std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
const sptr<IRemoteObject>& callback) override;
|
||||
void UnregisterCachedCallback(const sptr<IRemoteObject>& callback) override;
|
||||
|
||||
int GetCachedGnssLocationsSize() override;
|
||||
void FlushCachedGnssLocations() override;
|
||||
void SendCommand(std::unique_ptr<LocationCommand>& commands) override;
|
||||
void AddFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
void RemoveFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
};
|
||||
|
||||
class GnssAbilityStub : public IRemoteStub<IGnssAbility> {
|
||||
public:
|
||||
int32_t OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
private:
|
||||
static inline BrokerDelegator<GnssAbilityProxy> delegator_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_GNSS_ABILITY_SKELETON_H
|
270
location_gnss/gnss/source/gnss_ability.cpp
Normal file
270
location_gnss/gnss/source/gnss_ability.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "gnss_ability.h"
|
||||
#include <file_ex.h>
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "lbs_log.h"
|
||||
#include "location_dumper.h"
|
||||
|
||||
#include "gnss_status_callback_proxy.h"
|
||||
#include "nmea_message_callback_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(
|
||||
DelayedSingleton<GnssAbility>::GetInstance().get());
|
||||
|
||||
GnssAbility::GnssAbility() : SystemAbility(LOCATION_GNSS_SA_ID, true)
|
||||
{
|
||||
gnssStatusCallback_ = std::unique_ptr<std::map<pid_t, sptr<IGnssStatusCallback>>>();
|
||||
nmeaCallback_ = std::unique_ptr<std::map<pid_t, sptr<INmeaMessageCallback>>>();
|
||||
SetAbility(GNSS_ABILITY);
|
||||
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgr != nullptr) {
|
||||
}
|
||||
LBSLOGI(GNSS, "ability constructed.");
|
||||
}
|
||||
|
||||
GnssAbility::~GnssAbility() {}
|
||||
|
||||
void GnssAbility::OnStart()
|
||||
{
|
||||
if (state_ == ServiceRunningState::STATE_RUNNING) {
|
||||
LBSLOGI(GNSS, "ability has already started.");
|
||||
return;
|
||||
}
|
||||
if (!Init()) {
|
||||
LBSLOGE(GNSS, "failed to init ability");
|
||||
OnStop();
|
||||
return;
|
||||
}
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
LBSLOGI(GNSS, "OnStart start ability success.");
|
||||
}
|
||||
|
||||
void GnssAbility::OnStop()
|
||||
{
|
||||
state_ = ServiceRunningState::STATE_NOT_START;
|
||||
registerToAbility_ = false;
|
||||
LBSLOGI(GNSS, "OnStop ability stopped.");
|
||||
}
|
||||
|
||||
bool GnssAbility::Init()
|
||||
{
|
||||
if (!registerToAbility_) {
|
||||
bool ret = Publish(AsObject());
|
||||
if (!ret) {
|
||||
LBSLOGE(GNSS, "Init Publish failed!");
|
||||
return false;
|
||||
}
|
||||
registerToAbility_ = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void GnssAbility::SendLocationRequest(uint64_t interval, WorkRecord &workrecord)
|
||||
{
|
||||
LocationRequest(interval, workrecord);
|
||||
}
|
||||
|
||||
std::unique_ptr<Location> GnssAbility::GetCachedLocation()
|
||||
{
|
||||
return GetCache();
|
||||
}
|
||||
|
||||
void GnssAbility::SetEnable(bool state)
|
||||
{
|
||||
Enable(state, AsObject());
|
||||
}
|
||||
|
||||
void GnssAbility::RemoteRequest(bool state)
|
||||
{
|
||||
std::string deviceId = IPCSkeleton::GetCallingDeviceID();
|
||||
HandleRemoteRequest(state, deviceId);
|
||||
}
|
||||
|
||||
void GnssAbility::RefrashRequirements()
|
||||
{
|
||||
HandleRefrashRequirements();
|
||||
}
|
||||
|
||||
void GnssAbility::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(GNSS, "register an invalid gnssStatus callback");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IGnssStatusCallback> gnssStatusCallback = iface_cast<IGnssStatusCallback>(callback);
|
||||
if (gnssStatusCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast switch callback fail!");
|
||||
return;
|
||||
}
|
||||
gnssStatusCallback_->erase(uid);
|
||||
gnssStatusCallback_->insert(std::make_pair(uid, gnssStatusCallback));
|
||||
LBSLOGD(GNSS, "after uid:%{public}d register, gnssStatusCallback size:%{public}s",
|
||||
uid, std::to_string(gnssStatusCallback_->size()).c_str());
|
||||
}
|
||||
|
||||
void GnssAbility::UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(GNSS, "unregister an invalid gnssStatus callback");
|
||||
return;
|
||||
}
|
||||
sptr<IGnssStatusCallback> gnssStatusCallback = iface_cast<IGnssStatusCallback>(callback);
|
||||
if (gnssStatusCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast gnssStatus callback fail!");
|
||||
return;
|
||||
}
|
||||
|
||||
pid_t uid = -1;
|
||||
for (auto iter = gnssStatusCallback_->begin(); iter != gnssStatusCallback_->end(); iter++) {
|
||||
sptr<IRemoteObject> remoteObject = (iter->second)->AsObject();
|
||||
if (remoteObject == callback) {
|
||||
uid = iter->first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
gnssStatusCallback_->erase(uid);
|
||||
LBSLOGD(GNSS, "after uid:%{public}d unregister, gnssStatus callback size:%{public}s",
|
||||
uid, std::to_string(gnssStatusCallback_->size()).c_str());
|
||||
}
|
||||
|
||||
void GnssAbility::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(GNSS, "register an invalid nmea callback");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<INmeaMessageCallback> nmeaCallback = iface_cast<INmeaMessageCallback>(callback);
|
||||
if (nmeaCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast nmea callback fail!");
|
||||
return;
|
||||
}
|
||||
nmeaCallback_->erase(uid);
|
||||
nmeaCallback_->insert(std::make_pair(uid, nmeaCallback));
|
||||
LBSLOGD(GNSS, "after uid:%{public}d register, nmeaCallback size:%{public}s",
|
||||
uid, std::to_string(nmeaCallback_->size()).c_str());
|
||||
}
|
||||
|
||||
void GnssAbility::UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(GNSS, "unregister an invalid nmea callback");
|
||||
return;
|
||||
}
|
||||
sptr<INmeaMessageCallback> nmeaCallback = iface_cast<INmeaMessageCallback>(callback);
|
||||
if (nmeaCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast nmea callback fail!");
|
||||
return;
|
||||
}
|
||||
|
||||
pid_t uid = -1;
|
||||
for (auto iter = nmeaCallback_->begin(); iter != nmeaCallback_->end(); iter++) {
|
||||
sptr<IRemoteObject> remoteObject = (iter->second)->AsObject();
|
||||
if (remoteObject == callback) {
|
||||
uid = iter->first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
nmeaCallback_->erase(uid);
|
||||
LBSLOGD(GNSS, "after uid:%{public}d unregister, nmea callback size:%{public}s",
|
||||
uid, std::to_string(nmeaCallback_->size()).c_str());
|
||||
}
|
||||
|
||||
void GnssAbility::RegisterCachedCallback(const std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(GNSS, "register an invalid cached location callback");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<ICachedLocationsCallback> cachedCallback = iface_cast<ICachedLocationsCallback>(callback);
|
||||
if (cachedCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast cached location callback fail!");
|
||||
return;
|
||||
}
|
||||
LBSLOGD(GNSS, "request:%{public}d %{public}d",
|
||||
request->reportingPeriodSec, request->wakeUpCacheQueueFull ? 1 : 0);
|
||||
}
|
||||
|
||||
void GnssAbility::UnregisterCachedCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(GNSS, "register an invalid cached location callback");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<ICachedLocationsCallback> cachedCallback = iface_cast<ICachedLocationsCallback>(callback);
|
||||
if (cachedCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast cached location callback fail!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int GnssAbility::GetCachedGnssLocationsSize()
|
||||
{
|
||||
int size = 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
void GnssAbility::FlushCachedGnssLocations()
|
||||
{
|
||||
}
|
||||
|
||||
void GnssAbility::SendCommand(std::unique_ptr<LocationCommand>& commands)
|
||||
{
|
||||
}
|
||||
|
||||
void GnssAbility::AddFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
}
|
||||
|
||||
void GnssAbility::RemoveFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
}
|
||||
|
||||
void GnssAbility::SaDumpInfo(std::string& result)
|
||||
{
|
||||
result += "Gnss Location enable status: true";
|
||||
result += "\n";
|
||||
}
|
||||
|
||||
int32_t GnssAbility::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
std::vector<std::string> vecArgs;
|
||||
std::transform(args.begin(), args.end(), std::back_inserter(vecArgs), [](const std::u16string &arg) {
|
||||
return Str16ToStr8(arg);
|
||||
});
|
||||
|
||||
LocationDumper dumper;
|
||||
std::string result;
|
||||
dumper.GnssDump(SaDumpInfo, vecArgs, result);
|
||||
if (!SaveStringToFd(fd, result)) {
|
||||
LBSLOGE(GEO_CONVERT, "Gnss save string to fd failed!");
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
314
location_gnss/gnss/source/gnss_ability_skeleton.cpp
Normal file
314
location_gnss/gnss/source/gnss_ability_skeleton.cpp
Normal file
@ -0,0 +1,314 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "gnss_ability_skeleton.h"
|
||||
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
GnssAbilityProxy::GnssAbilityProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<IGnssAbility>(impl)
|
||||
{
|
||||
SetProxy(GNSS_ABILITY, AsObject());
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::SendLocationRequest(uint64_t interval, WorkRecord &workrecord)
|
||||
{
|
||||
SendRequest(interval, workrecord);
|
||||
}
|
||||
|
||||
std::unique_ptr<Location> GnssAbilityProxy::GetCachedLocation()
|
||||
{
|
||||
return GetCache();
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::SetEnable(bool state)
|
||||
{
|
||||
Enable(state);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::RemoteRequest(bool state)
|
||||
{
|
||||
MessageParcel data;
|
||||
data.WriteBool(state);
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
int error = Remote()->SendRequest(ISubAbility::HANDLE_REMOTE_REQUEST, data, reply, option);
|
||||
LBSLOGD(GNSS, "RemoteRequest Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::RefrashRequirements()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
int error = Remote()->SendRequest(ISubAbility::REFRESH_REQUESTS, data, reply, option);
|
||||
LBSLOGD(GNSS, "RefrashRequirements Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
data.WriteRemoteObject(callback);
|
||||
int error = Remote()->SendRequest(ISubAbility::REG_GNSS_STATUS, data, reply, option);
|
||||
LBSLOGD(GNSS, "RegisterGnssStatusCallback Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
data.WriteRemoteObject(callback);
|
||||
int error = Remote()->SendRequest(ISubAbility::UNREG_GNSS_STATUS, data, reply, option);
|
||||
LBSLOGD(GNSS, "UnregisterGnssStatusCallback Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
data.WriteRemoteObject(callback);
|
||||
int error = Remote()->SendRequest(ISubAbility::REG_NMEA, data, reply, option);
|
||||
LBSLOGD(GNSS, "RegisterNmeaMessageCallback Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
data.WriteRemoteObject(callback);
|
||||
int error = Remote()->SendRequest(ISubAbility::UNREG_NMEA, data, reply, option);
|
||||
LBSLOGD(GNSS, "UnregisterNmeaMessageCallback Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::RegisterCachedCallback(const std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
data.WriteInt32(request->reportingPeriodSec);
|
||||
data.WriteBool(request->wakeUpCacheQueueFull);
|
||||
data.WriteRemoteObject(callback);
|
||||
int error = Remote()->SendRequest(ISubAbility::REG_CACHED, data, reply, option);
|
||||
LBSLOGD(GNSS, "RegisterCachedCallback Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::UnregisterCachedCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
data.WriteRemoteObject(callback);
|
||||
int error = Remote()->SendRequest(ISubAbility::UNREG_CACHED, data, reply, option);
|
||||
LBSLOGD(GNSS, "UnregisterCachedCallback Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
int GnssAbilityProxy::GetCachedGnssLocationsSize()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "GetCachedGnssLocationsSize remote is null");
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
int error = remote->SendRequest(ISubAbility::GET_CACHED_SIZE, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize Transact ErrCode = %{public}d", error);
|
||||
int size = 0;
|
||||
if (error == NO_ERROR) {
|
||||
size = reply.ReadInt32();
|
||||
}
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCachedGnssLocationsSize return %{public}d", size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::FlushCachedGnssLocations()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "FlushCachedGnssLocations remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(ISubAbility::FLUSH_CACHED, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::FlushCachedGnssLocations Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::SendCommand(std::unique_ptr<LocationCommand>& commands)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInt32(commands->scenario);
|
||||
data.WriteString16(Str8ToStr16(commands->command));
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "SendCommand remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(ISubAbility::SEND_COMMANDS, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::SendCommand Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::AddFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInt32(request->priority);
|
||||
data.WriteInt32(request->scenario);
|
||||
data.WriteDouble(request->geofence.latitude);
|
||||
data.WriteDouble(request->geofence.longitude);
|
||||
data.WriteDouble(request->geofence.radius);
|
||||
data.WriteDouble(request->geofence.expiration);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "AddFence remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(ISubAbility::ADD_FENCE_INFO, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::AddFence Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
void GnssAbilityProxy::RemoveFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInt32(request->priority);
|
||||
data.WriteInt32(request->scenario);
|
||||
data.WriteDouble(request->geofence.latitude);
|
||||
data.WriteDouble(request->geofence.longitude);
|
||||
data.WriteDouble(request->geofence.radius);
|
||||
data.WriteDouble(request->geofence.expiration);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "RemoveFence remote is null");
|
||||
return;
|
||||
}
|
||||
int error = remote->SendRequest(ISubAbility::REMOVE_FENCE_INFO, data, reply, option);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::RemoveFence Transact ErrCodes = %{public}d", error);
|
||||
}
|
||||
|
||||
int GnssAbilityStub::OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
pid_t lastCallingPid = IPCSkeleton::GetCallingPid();
|
||||
pid_t lastCallinguid = IPCSkeleton::GetCallingUid();
|
||||
LBSLOGI(GNSS, "OnRemoteRequest cmd = %{public}u, flags= %{public}d, pid= %{public}d, uid= %{public}d",
|
||||
code, option.GetFlags(), lastCallingPid, lastCallinguid);
|
||||
if (lastCallinguid > SYSTEM_UID) {
|
||||
LBSLOGE(GNSS, "this remote request is not allowed");
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
int ret = REPLY_NO_EXCEPTION;
|
||||
switch (code) {
|
||||
case SEND_LOCATION_REQUEST: {
|
||||
int64_t interval = data.ReadInt64();
|
||||
std::unique_ptr<WorkRecord> workrecord = WorkRecord::Unmarshalling(data);
|
||||
SendLocationRequest((uint64_t)interval, *workrecord);
|
||||
break;
|
||||
}
|
||||
case GET_CACHED_LOCATION: {
|
||||
std::unique_ptr<Location> location = GetCachedLocation();
|
||||
if (location != nullptr) {
|
||||
location->Marshalling(reply);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SET_ENABLE: {
|
||||
SetEnable(data.ReadBool());
|
||||
break;
|
||||
}
|
||||
case HANDLE_REMOTE_REQUEST: {
|
||||
bool state = data.ReadBool();
|
||||
RemoteRequest(state);
|
||||
break;
|
||||
}
|
||||
case REFRESH_REQUESTS: {
|
||||
RefrashRequirements();
|
||||
break;
|
||||
}
|
||||
case REG_GNSS_STATUS: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
RegisterGnssStatusCallback(client, lastCallinguid);
|
||||
break;
|
||||
}
|
||||
case UNREG_GNSS_STATUS: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
UnregisterGnssStatusCallback(client);
|
||||
break;
|
||||
}
|
||||
case REG_NMEA: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
RegisterNmeaMessageCallback(client, lastCallinguid);
|
||||
break;
|
||||
}
|
||||
case UNREG_NMEA: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
UnregisterNmeaMessageCallback(client);
|
||||
break;
|
||||
}
|
||||
case REG_CACHED: {
|
||||
std::unique_ptr<CachedGnssLoactionsRequest> requestConfig = std::make_unique<CachedGnssLoactionsRequest>();
|
||||
requestConfig->reportingPeriodSec = data.ReadInt32();
|
||||
requestConfig->wakeUpCacheQueueFull = data.ReadBool();
|
||||
sptr<IRemoteObject> callback = data.ReadObject<IRemoteObject>();
|
||||
RegisterCachedCallback(requestConfig, callback);
|
||||
break;
|
||||
}
|
||||
case UNREG_CACHED: {
|
||||
sptr<IRemoteObject> callback = data.ReadObject<IRemoteObject>();
|
||||
UnregisterCachedCallback(callback);
|
||||
break;
|
||||
}
|
||||
case GET_CACHED_SIZE: {
|
||||
reply.WriteInt32(GetCachedGnssLocationsSize());
|
||||
break;
|
||||
}
|
||||
case FLUSH_CACHED: {
|
||||
FlushCachedGnssLocations();
|
||||
break;
|
||||
}
|
||||
case SEND_COMMANDS: {
|
||||
std::unique_ptr<LocationCommand> locationCommand = std::make_unique<LocationCommand>();
|
||||
locationCommand->scenario = data.ReadInt32();
|
||||
locationCommand->command = data.ReadBool();
|
||||
SendCommand(locationCommand);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
25
location_locator/BUILD.gn
Normal file
25
location_locator/BUILD.gn
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/config/ohos/rules.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos_var.gni")
|
||||
|
||||
ohos_subsystem("location") {
|
||||
subsystem_packages = [ "location_locator:lbsservice_locator" ]
|
||||
}
|
||||
|
||||
ohos_subsystem_test("location_test") {
|
||||
testonly = true
|
||||
test_packages = [ "location_locator/test/unittest:unittest" ]
|
||||
}
|
54
location_locator/bundle.json
Normal file
54
location_locator/bundle.json
Normal file
@ -0,0 +1,54 @@
|
||||
{
|
||||
"name": "@ohos/location_locator",
|
||||
"version": "3.1.0",
|
||||
"description": "Location Management Capability in Location Services.",
|
||||
"homePage": "https://gitee.com/openharmony",
|
||||
"license": "Apache License 2.0",
|
||||
"repository": "",
|
||||
"domain": "os",
|
||||
"language": "",
|
||||
"publishAs": "code-segment",
|
||||
"private": false,
|
||||
"segment": {
|
||||
"destPath": "base/location/location_locator"
|
||||
},
|
||||
"component": {
|
||||
"name": "location_locator",
|
||||
"subsystem": "location",
|
||||
"syscap": [
|
||||
"SystemCapability.Location.Location"
|
||||
],
|
||||
"features": [],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"deps": {
|
||||
"components": [
|
||||
"ipc",
|
||||
"ces_standard",
|
||||
"hiviewdfx_hilog_native",
|
||||
"appexecfwk_standard",
|
||||
"hisysevent_native",
|
||||
"samgr_standard",
|
||||
"startup_l2",
|
||||
"access_token"
|
||||
],
|
||||
"third_party": []
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//base/location/location_locator/locator:lbsservice_locator",
|
||||
"//base/location/etc:etc",
|
||||
"//base/location/profile:location_sa_profile"
|
||||
],
|
||||
"test": [
|
||||
"//base/location/location_locator/test/unittest:unittest"
|
||||
]
|
||||
},
|
||||
"hisysevent_config": [
|
||||
"//base/location/location_locator/hisysevent.yaml"
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_CALLBACK_PROXY_H
|
||||
#define OHOS_LOCATION_CALLBACK_PROXY_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
#include "location.h"
|
||||
#include "locator_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class ILocationCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
RECEIVE_LOCATION_CHANGE_EVENT = 1,
|
||||
};
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.location.ILocationListener");
|
||||
virtual void OnLocationChange(const std::unique_ptr<Location>& location) = 0;
|
||||
};
|
||||
|
||||
class LocationCallbackStub : public IRemoteStub<ILocationCallback> {
|
||||
public:
|
||||
LocationCallbackStub(std::string abilityName);
|
||||
~LocationCallbackStub() = default;
|
||||
int32_t OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnLocationChange(const std::unique_ptr<Location>& location) override;
|
||||
std::string GetAbilityName();
|
||||
void GetRemoteLocatorProxy(std::string deviceId);
|
||||
private:
|
||||
OHOS::HiviewDFX::HiLogLabel label_;
|
||||
std::unique_ptr<LocatorProxy> proxyLocator_;
|
||||
bool isInitForProxy_;
|
||||
std::string abilityName_;
|
||||
std::string localDeviceId_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_CALLBACK_PROXY_H
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_CACHED_LOCATIONS_CALLBACK_PROXY_H
|
||||
#define OHOS_CACHED_LOCATIONS_CALLBACK_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "i_cached_locations_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class CachedLocationsCallbackProxy : public IRemoteProxy<ICachedLocationsCallback> {
|
||||
public:
|
||||
explicit CachedLocationsCallbackProxy(const sptr<IRemoteObject> &impl);
|
||||
~CachedLocationsCallbackProxy() = default;
|
||||
void OnCacheLocationsReport(const std::vector<std::unique_ptr<Location>>& locations) override;
|
||||
private:
|
||||
static inline BrokerDelegator<CachedLocationsCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_CACHED_LOCATIONS_CALLBACK_PROXY_H
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_GNSS_STATUS_CALLBACK_PROXY_H
|
||||
#define OHOS_GNSS_STATUS_CALLBACK_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "i_gnss_status_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class GnssStatusCallbackProxy : public IRemoteProxy<IGnssStatusCallback> {
|
||||
public:
|
||||
explicit GnssStatusCallbackProxy(const sptr<IRemoteObject> &impl);
|
||||
~GnssStatusCallbackProxy() = default;
|
||||
void OnStatusChange(const std::unique_ptr<SatelliteStatus>& statusInfo) override;
|
||||
private:
|
||||
static inline BrokerDelegator<GnssStatusCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_GNSS_STATUS_CALLBACK_PROXY_H
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_I_CACHED_LOCATIONS_CALLBACK_H
|
||||
#define LOCATION_I_CACHED_LOCATIONS_CALLBACK_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "ipc_types.h"
|
||||
#include "location.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class ICachedLocationsCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
RECEIVE_CACHED_LOCATIONS_EVENT = 1,
|
||||
};
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"location.ICachedLocationsCallback");
|
||||
virtual void OnCacheLocationsReport(const std::vector<std::unique_ptr<Location>>& locations) = 0;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // LOCATION_I_CACHED_LOCATIONS_CALLBACK_H
|
39
location_locator/callback/include/i_gnss_status_callback.h
Normal file
39
location_locator/callback/include/i_gnss_status_callback.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_GNSS_STATUS_CALLBACK_H
|
||||
#define OHOS_GNSS_STATUS_CALLBACK_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "ipc_types.h"
|
||||
#include "satellite_status.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class IGnssStatusCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
RECEIVE_STATUS_INFO_EVENT = 1,
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"location.IGnssStatusCallback");
|
||||
/*
|
||||
* status info report to kits
|
||||
*/
|
||||
virtual void OnStatusChange(const std::unique_ptr<SatelliteStatus>& statusInfo) = 0;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_GNSS_STATUS_CALLBACK_H
|
40
location_locator/callback/include/i_locator_callback.h
Normal file
40
location_locator/callback/include/i_locator_callback.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_I_LOCATOR_CALLBACK_H
|
||||
#define LOCATION_I_LOCATOR_CALLBACK_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "ipc_types.h"
|
||||
|
||||
#include "location.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class ILocatorCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
RECEIVE_LOCATION_INFO_EVENT = 1,
|
||||
RECEIVE_LOCATION_STATUS_EVENT = 2,
|
||||
RECEIVE_ERROR_INFO_EVENT = 3,
|
||||
};
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"location.ILocatorCallback");
|
||||
virtual void OnLocationReport(const std::unique_ptr<Location>& location) = 0;
|
||||
virtual void OnLocatingStatusChange(const int status) = 0;
|
||||
virtual void OnErrorReport(const int errorCode) = 0;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // LOCATION_I_LOCATOR_CALLBACK_H
|
38
location_locator/callback/include/i_nmea_message_callback.h
Normal file
38
location_locator/callback/include/i_nmea_message_callback.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_NMEA_MESSAGE_CALLBACK_H
|
||||
#define OHOS_NMEA_MESSAGE_CALLBACK_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "ipc_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class INmeaMessageCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
RECEIVE_NMEA_MESSAGE_EVENT = 1,
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"location.INmeaMessageCallback");
|
||||
/*
|
||||
* message changed report to kits
|
||||
*/
|
||||
virtual void OnMessageChange(const std::string msg) = 0;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_NMEA_MESSAGE_CALLBACK_H
|
38
location_locator/callback/include/i_switch_callback.h
Normal file
38
location_locator/callback/include/i_switch_callback.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_SWITCH_CALLBACK_H
|
||||
#define OHOS_LOCATION_SWITCH_CALLBACK_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "ipc_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class ISwitchCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
RECEIVE_SWITCH_STATE_EVENT = 1,
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"location.ISwitchCallback");
|
||||
/*
|
||||
* state changed report to kits
|
||||
*/
|
||||
virtual void OnSwitchChange(const int state) = 0;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_SWITCH_CALLBACK_H
|
50
location_locator/callback/include/locator_callback_proxy.h
Normal file
50
location_locator/callback/include/locator_callback_proxy.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_LOCATOR_CALLBACK_PROXY_H
|
||||
#define OHOS_LOCATION_LOCATOR_CALLBACK_PROXY_H
|
||||
|
||||
#include "i_locator_callback.h"
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class LocatorCallbackProxy : public IRemoteProxy<ILocatorCallback> {
|
||||
public:
|
||||
explicit LocatorCallbackProxy(const sptr<IRemoteObject> &impl);
|
||||
~LocatorCallbackProxy() = default;
|
||||
void OnLocationReport(const std::unique_ptr<Location>& location) override;
|
||||
void OnLocatingStatusChange(const int status) override;
|
||||
void OnErrorReport(const int errorCode) override;
|
||||
private:
|
||||
static inline BrokerDelegator<LocatorCallbackProxy> delegator_;
|
||||
};
|
||||
|
||||
class LocatorCallbackStub : public IRemoteStub<ILocatorCallback> {
|
||||
public:
|
||||
int32_t OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnLocationReport(const std::unique_ptr<Location>& location) override;
|
||||
void OnLocatingStatusChange(const int status) override;
|
||||
void OnErrorReport(const int errorCode) override;
|
||||
private:
|
||||
static pid_t lastCallingPid;
|
||||
static pid_t lastCallingUid;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_LOCATOR_CALLBACK_PROXY_H
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_NMEA_MESSAGE_CALLBACK_PROXY_H
|
||||
#define OHOS_NMEA_MESSAGE_CALLBACK_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "i_nmea_message_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class NmeaMessageCallbackProxy : public IRemoteProxy<INmeaMessageCallback> {
|
||||
public:
|
||||
explicit NmeaMessageCallbackProxy(const sptr<IRemoteObject> &impl);
|
||||
~NmeaMessageCallbackProxy() = default;
|
||||
void OnMessageChange(const std::string msg) override;
|
||||
private:
|
||||
static inline BrokerDelegator<NmeaMessageCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_NMEA_MESSAGE_CALLBACK_PROXY_H
|
34
location_locator/callback/include/switch_callback_proxy.h
Normal file
34
location_locator/callback/include/switch_callback_proxy.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_SWITCH_CALLBACK_PROXY_H
|
||||
#define OHOS_LOCATION_SWITCH_CALLBACK_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "i_switch_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class SwitchCallbackProxy : public IRemoteProxy<ISwitchCallback> {
|
||||
public:
|
||||
explicit SwitchCallbackProxy(const sptr<IRemoteObject> &impl);
|
||||
~SwitchCallbackProxy() = default;
|
||||
void OnSwitchChange(const int state) override;
|
||||
private:
|
||||
static inline BrokerDelegator<SwitchCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_SWITCH_CALLBACK_PROXY_H
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "adapter_callback_skeleton.h"
|
||||
|
||||
#include <string>
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_file_descriptor.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
LocationCallbackStub::LocationCallbackStub(std::string abilityName)
|
||||
{
|
||||
isInitForProxy_ = false;
|
||||
localDeviceId_ = CommonUtils::InitDeviceId();
|
||||
abilityName_ = abilityName;
|
||||
label_ = CommonUtils::GetLabel(abilityName);
|
||||
GetRemoteLocatorProxy(localDeviceId_);
|
||||
}
|
||||
|
||||
std::string LocationCallbackStub::GetAbilityName()
|
||||
{
|
||||
return abilityName_;
|
||||
}
|
||||
|
||||
int LocationCallbackStub::OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
int ret = EXCEPTION;
|
||||
pid_t lastCallingPid = IPCSkeleton::GetCallingPid();
|
||||
pid_t lastCallinguid = IPCSkeleton::GetCallingUid();
|
||||
LBSLOGI(label_, "OnReceived cmd = %{public}d, flags= %{public}d, pid= %{public}d, uid= %{public}d",
|
||||
code, option.GetFlags(), lastCallingPid, lastCallinguid);
|
||||
|
||||
switch (code) {
|
||||
case RECEIVE_LOCATION_CHANGE_EVENT: {
|
||||
std::unique_ptr<Location> location = Location::UnmarshallingLocation(data);
|
||||
OnLocationChange(location);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LocationCallbackStub::GetRemoteLocatorProxy(std::string deviceId)
|
||||
{
|
||||
if (!isInitForProxy_) {
|
||||
proxyLocator_ = std::make_unique<LocatorProxy>(
|
||||
CommonUtils::GetRemoteObject(LOCATION_LOCATOR_SA_ID, localDeviceId_));
|
||||
isInitForProxy_ = true;
|
||||
return;
|
||||
}
|
||||
if (deviceId.compare(localDeviceId_) == 0 && proxyLocator_ != nullptr) {
|
||||
return;
|
||||
}
|
||||
proxyLocator_ = std::make_unique<LocatorProxy>(CommonUtils::GetRemoteObject(LOCATION_LOCATOR_SA_ID, deviceId));
|
||||
}
|
||||
|
||||
void LocationCallbackStub::OnLocationChange(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
LBSLOGI(label_, "LocationCallbackStub::onLocationChange");
|
||||
if (proxyLocator_ != nullptr) {
|
||||
proxyLocator_->ReportLocation(location, abilityName_);
|
||||
}
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2022-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cached_locations_callback_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
CachedLocationsCallbackProxy::CachedLocationsCallbackProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<ICachedLocationsCallback>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
void CachedLocationsCallbackProxy::OnCacheLocationsReport(const std::vector<std::unique_ptr<Location>>& locations)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
for (int i = 0; i < locations.size(); i++) {
|
||||
locations[i]->Marshalling(data);
|
||||
}
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
int error = Remote()->SendRequest(RECEIVE_CACHED_LOCATIONS_EVENT, data, reply, option);
|
||||
LBSLOGI(CACHED_LOCATIONS_CALLBACK,
|
||||
"CachedLocationsCallbackProxy::OnCacheLocationsReport Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "gnss_status_callback_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
GnssStatusCallbackProxy::GnssStatusCallbackProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<IGnssStatusCallback>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
void GnssStatusCallbackProxy::OnStatusChange(const std::unique_ptr<SatelliteStatus>& statusInfo)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
if (statusInfo != nullptr) {
|
||||
statusInfo->Marshalling(data);
|
||||
}
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
int error = Remote()->SendRequest(RECEIVE_STATUS_INFO_EVENT, data, reply, option);
|
||||
LBSLOGI(SWITCH_CALLBACK, "GnssStatusCallbackProxy::OnStatusChange Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
94
location_locator/callback/source/locator_callback_proxy.cpp
Normal file
94
location_locator/callback/source/locator_callback_proxy.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "locator_callback_proxy.h"
|
||||
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
#include "lbs_log.h"
|
||||
#include "locator_background_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
LocatorCallbackProxy::LocatorCallbackProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<ILocatorCallback>(impl)
|
||||
{
|
||||
LBSLOGD(LOCATOR_CALLBACK, "construct");
|
||||
}
|
||||
|
||||
void LocatorCallbackProxy::OnLocationReport(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
if (location == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
location->Marshalling(data);
|
||||
MessageOption option;
|
||||
if (DelayedSingleton<LocatorBackgroundProxy>::GetInstance().get()->IsCallbackInProxy(this)) {
|
||||
// if callback is from locatorBackgroundProxy, should send sync message to wake up app
|
||||
option = { MessageOption::TF_SYNC };
|
||||
LBSLOGD(LOCATOR_CALLBACK, "OnLocationReport Transact TF_SYNC");
|
||||
} else {
|
||||
option = { MessageOption::TF_ASYNC };
|
||||
}
|
||||
int error = Remote()->SendRequest(ILocatorCallback::RECEIVE_LOCATION_INFO_EVENT, data, reply, option);
|
||||
LBSLOGD(LOCATOR_CALLBACK, "OnLocationReport Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorCallbackProxy::OnLocatingStatusChange(const int status)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
data.WriteInt32(status);
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
int error = Remote()->SendRequest(RECEIVE_LOCATION_STATUS_EVENT, data, reply, option);
|
||||
LBSLOGD(LOCATOR_CALLBACK, "OnLocatingStatusChange Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
|
||||
void LocatorCallbackProxy::OnErrorReport(const int errorCode)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
data.WriteInt32(errorCode);
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
int error = Remote()->SendRequest(RECEIVE_ERROR_INFO_EVENT, data, reply, option);
|
||||
LBSLOGD(LOCATOR_CALLBACK, "OnErrorReport:%{public}d, Transact ErrCode = %{public}d", errorCode, error);
|
||||
}
|
||||
|
||||
|
||||
int LocatorCallbackStub::OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
pid_t callingPid = IPCSkeleton::GetCallingPid();
|
||||
pid_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
LBSLOGI(LOCATOR_CALLBACK, "OnReceived cmd = %{public}u, flags= %{public}d, pid= %{public}d, uid= %{public}d",
|
||||
code, option.GetFlags(), callingPid, callingUid);
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
void LocatorCallbackStub::OnLocationReport(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
}
|
||||
|
||||
void LocatorCallbackStub::OnLocatingStatusChange(const int status)
|
||||
{
|
||||
}
|
||||
|
||||
void LocatorCallbackStub::OnErrorReport(const int errorCode)
|
||||
{
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nmea_message_callback_proxy.h"
|
||||
#include "common_utils.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
NmeaMessageCallbackProxy::NmeaMessageCallbackProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<INmeaMessageCallback>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
void NmeaMessageCallbackProxy::OnMessageChange(const std::string msg)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
data.WriteString16(Str8ToStr16(msg));
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
int error = Remote()->SendRequest(RECEIVE_NMEA_MESSAGE_EVENT, data, reply, option);
|
||||
LBSLOGI(SWITCH_CALLBACK, "NmeaMessageCallbackProxy::OnStatusChange Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
37
location_locator/callback/source/switch_callback_proxy.cpp
Normal file
37
location_locator/callback/source/switch_callback_proxy.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "switch_callback_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
SwitchCallbackProxy::SwitchCallbackProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<ISwitchCallback>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
void SwitchCallbackProxy::OnSwitchChange(const int state)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
data.WriteInt32(state);
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
int error = Remote()->SendRequest(RECEIVE_SWITCH_STATE_EVENT, data, reply, option);
|
||||
LBSLOGI(SWITCH_CALLBACK, "SwitchCallbackProxy::OnSwitchChange Transact ErrCode = %{public}d", error);
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
26
location_locator/hisysevent.yaml
Normal file
26
location_locator/hisysevent.yaml
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
domain: LOCATION
|
||||
|
||||
# Start or stop Location switch
|
||||
LOCATION_SWITCH_STATE:
|
||||
__BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: start or stop Location switch}
|
||||
STATE: {type: STRING, desc: enable or disable}
|
||||
|
||||
# GNSS location status
|
||||
GNSS_STATE:
|
||||
__BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: GNSS location status}
|
||||
STATE: {type: STRING, desc: start or stop}
|
||||
PID: {type: INT32, desc: PID value}
|
||||
UID: {type: INT32, desc: UID value}
|
103
location_locator/locator/BUILD.gn
Normal file
103
location_locator/locator/BUILD.gn
Normal file
@ -0,0 +1,103 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/appexecfwk/standard/appexecfwk.gni")
|
||||
|
||||
SUBSYSTEM_DIR = "//base/location"
|
||||
LOCATION_SERVICE_ROOT = "$SUBSYSTEM_DIR/services"
|
||||
|
||||
ohos_shared_library("lbsservice_locator") {
|
||||
sources = [
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/source/adapter_callback_skeleton.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/source/locator_callback_proxy.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/source/switch_callback_proxy.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/source/gnss_status_callback_proxy.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/source/nmea_message_callback_proxy.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/source/cached_locations_callback_proxy.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/fusion_controller.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/locator_ability.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/locator_background_proxy.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/locator_event_manager.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/locator_event_subscriber.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/locator_skeleton.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/report_manager.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/request.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/request_manager.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/subability_common.cpp",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/source/work_record.cpp",
|
||||
"$SUBSYSTEM_DIR/utils/source/common_utils.cpp",
|
||||
"$SUBSYSTEM_DIR/utils/source/common_hisysevent.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits/locator_standard/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/callback/include",
|
||||
"$SUBSYSTEM_DIR/location_common/common/include",
|
||||
"$SUBSYSTEM_DIR/location_geocode/geocode/include",
|
||||
"$SUBSYSTEM_DIR/location_gnss/gnss/include",
|
||||
"$SUBSYSTEM_DIR/location_locator/locator/include",
|
||||
"$SUBSYSTEM_DIR/location_network/network/include",
|
||||
"$SUBSYSTEM_DIR/location_passive/passive/include",
|
||||
"$LOCATION_SERVICE_ROOT/visibility/include",
|
||||
"$SUBSYSTEM_DIR/utils/include",
|
||||
"$SUBSYSTEM_DIR/adapter/services/include",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk/",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content",
|
||||
"//base/security/access_token/interfaces/innerkits/accesstoken/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"//foundation/aafwk/intent/interfaces/innerkits/base/include",
|
||||
"//foundation/appexecfwk/adapter/interfaces/innerkits/appexecfwk_base/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include",
|
||||
"//base/notification/ces_standard/frameworks/core/include",
|
||||
"//base/notification/ces_standard/interfaces/innerkits/native/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include",
|
||||
"//foundation/resourceschedule/backgroundtaskmanager/interfaces/innerkits/native/include",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include"
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$SUBSYSTEM_DIR/location_common/common:lbsservice_common",
|
||||
"//base/location/interfaces/innerkits/locator_standard:locator_sdk",
|
||||
"${aafwk_path}/interfaces/innerkits/base:base",
|
||||
"${aafwk_path}/interfaces/innerkits/want:want",
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//base/notification/ces_standard/frameworks/core:cesfwk_core",
|
||||
"//base/notification/ces_standard/frameworks/native:cesfwk_innerkits",
|
||||
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ipc:ipc_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
"permission_standard:libpermissionsdk_standard",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
]
|
||||
|
||||
part_name = "location_locator"
|
||||
subsystem_name = "location"
|
||||
}
|
39
location_locator/locator/include/fusion_controller.h
Normal file
39
location_locator/locator/include/fusion_controller.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_FUSION_CONTROLLER_H
|
||||
#define LOCATION_FUSION_CONTROLLER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <singleton.h>
|
||||
|
||||
#include "location.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class FusionController : public DelayedSingleton<FusionController> {
|
||||
public:
|
||||
void ActiveFusionStrategies(int type);
|
||||
void Process(std::string abilityName);
|
||||
void FuseResult(std::string abilityName, const std::unique_ptr<Location>& location);
|
||||
private:
|
||||
void RequestQuickFix(bool state);
|
||||
|
||||
uint32_t fusedFlag_ = 0;
|
||||
bool needReset_ = true;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // LOCATION_FUSION_CONTROLLER_H
|
128
location_locator/locator/include/locator_ability.h
Normal file
128
location_locator/locator/include/locator_ability.h
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_LOCATOR_ABILITY_H
|
||||
#define OHOS_LOCATION_LOCATOR_ABILITY_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <singleton.h>
|
||||
|
||||
#include "event_handler.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
#include "common_hisysevent.h"
|
||||
#include "common_utils.h"
|
||||
#include "locator_callback_proxy.h"
|
||||
#include "locator_event_subscriber.h"
|
||||
#include "locator_skeleton.h"
|
||||
#include "switch_callback_proxy.h"
|
||||
#include "request.h"
|
||||
#include "request_manager.h"
|
||||
#include "report_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class LocatorHandler : public AppExecFwk::EventHandler {
|
||||
public:
|
||||
explicit LocatorHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner);
|
||||
~LocatorHandler() override;
|
||||
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
|
||||
};
|
||||
|
||||
class LocatorAbility : public SystemAbility, public LocatorAbilityStub, DelayedSingleton<LocatorAbility> {
|
||||
DECLEAR_SYSTEM_ABILITY(LocatorAbility);
|
||||
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(LocatorAbility);
|
||||
LocatorAbility();
|
||||
~LocatorAbility();
|
||||
void OnStart() override;
|
||||
void OnStop() override;
|
||||
ServiceRunningState QueryServiceState() const
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
void InitSaAbility();
|
||||
void InitRequestManagerMap();
|
||||
|
||||
void UpdateSaAbility() override;
|
||||
int GetSwitchState() override;
|
||||
void EnableAbility(bool isEnabled) override;
|
||||
void RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
void UnregisterSwitchCallback(const sptr<IRemoteObject>& callback) override;
|
||||
void RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
void UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) override;
|
||||
void RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
void UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) override;
|
||||
int StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
|
||||
sptr<ILocatorCallback>& callback, std::string bundleName, pid_t pid, pid_t uid) override;
|
||||
int StopLocating(sptr<ILocatorCallback>& callback) override;
|
||||
int GetCacheLocation(MessageParcel& data, MessageParcel& replay) override;
|
||||
int IsGeoConvertAvailable(MessageParcel &data, MessageParcel &replay) override;
|
||||
int GetAddressByCoordinate(MessageParcel &data, MessageParcel &replay) override;
|
||||
int GetAddressByLocationName(MessageParcel &data, MessageParcel &replay) override;
|
||||
|
||||
bool IsLocationPrivacyConfirmed(const LocationPrivacyType type) override;
|
||||
void SetLocationPrivacyConfirmStatus(const LocationPrivacyType type, bool isConfirmed) override;
|
||||
|
||||
int RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
sptr<ICachedLocationsCallback>& callback, std::string bundleName) override;
|
||||
int UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback) override;
|
||||
|
||||
int GetCachedGnssLocationsSize() override;
|
||||
void FlushCachedGnssLocations() override;
|
||||
void SendCommand(std::unique_ptr<LocationCommand>& commands) override;
|
||||
void AddFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
void RemoveFence(std::unique_ptr<GeofenceRequest>& request) override;
|
||||
|
||||
int ReportLocation(const std::unique_ptr<Location>& location, std::string abilityName) override;
|
||||
int ReportLocationStatus(sptr<ILocatorCallback>& callback, int result) override;
|
||||
int ReportErrorStatus(sptr<ILocatorCallback>& callback, int result) override;
|
||||
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
|
||||
std::shared_ptr<std::map<std::string, std::list<std::shared_ptr<Request>>>> GetRequests();
|
||||
std::shared_ptr<std::map<sptr<IRemoteObject>, std::list<std::shared_ptr<Request>>>> GetReceivers();
|
||||
std::shared_ptr<std::map<std::string, sptr<IRemoteObject>>> GetProxyMap();
|
||||
void UpdateSaAbilityHandler();
|
||||
void ApplyRequests();
|
||||
void RegisterAction();
|
||||
private:
|
||||
bool Init();
|
||||
bool CheckSaValid();
|
||||
static int QuerySwitchState();
|
||||
int SendGeoRequest(int type, MessageParcel &data, MessageParcel &replay);
|
||||
|
||||
static void SaDumpInfo(std::string& result);
|
||||
|
||||
bool registerToAbility_ = false;
|
||||
bool isActionRegistered = false;
|
||||
bool isEnabled_ = false;
|
||||
std::string deviceId_;
|
||||
ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
|
||||
std::shared_ptr<LocatorEventSubscriber> locatorEventSubscriber_;
|
||||
std::unique_ptr<std::map<pid_t, sptr<ISwitchCallback>>> switchCallbacks_;
|
||||
std::shared_ptr<std::map<std::string, std::list<std::shared_ptr<Request>>>> requests_;
|
||||
std::shared_ptr<std::map<sptr<IRemoteObject>, std::list<std::shared_ptr<Request>>>> receivers_;
|
||||
std::shared_ptr<std::map<std::string, sptr<IRemoteObject>>> proxyMap_;
|
||||
std::shared_ptr<LocatorHandler> locatorHandler_;
|
||||
std::shared_ptr<RequestManager> requestManager_;
|
||||
std::unique_ptr<ReportManager> reportManager_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_LOCATOR_ABILITY_H
|
90
location_locator/locator/include/locator_background_proxy.h
Normal file
90
location_locator/locator/include/locator_background_proxy.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_BACKGROUND_PROXY_H
|
||||
#define LOCATION_BACKGROUND_PROXY_H
|
||||
|
||||
#include <map>
|
||||
#include <singleton.h>
|
||||
#include <string>
|
||||
#include "common_event_subscriber.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "i_locator_callback.h"
|
||||
#include "request.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class LocatorBackgroundProxy : DelayedSingleton<LocatorBackgroundProxy> {
|
||||
public:
|
||||
LocatorBackgroundProxy();
|
||||
~LocatorBackgroundProxy();
|
||||
void OnSuspend(const std::shared_ptr<Request>& request, bool active);
|
||||
void OnPermissionChanged(int32_t uid);
|
||||
void OnProviderSwitch(bool enable);
|
||||
void OnDeleteRequestRecord(const std::shared_ptr<Request>& request);
|
||||
bool IsCallbackInProxy(const sptr<ILocatorCallback>& callback) const;
|
||||
|
||||
private:
|
||||
void StartLocator();
|
||||
void StopLocator();
|
||||
void StartLocatorThread();
|
||||
void OnUserSwitch(int32_t userId);
|
||||
void OnUserRemove(int32_t userId);
|
||||
void UpdateListOnPermissionChanged(int32_t uid);
|
||||
void UpdateListOnSuspend(const std::shared_ptr<Request>& request, bool active);
|
||||
void UpdateListOnUserSwitch(int32_t userId);
|
||||
void SubscribeUserSwtich();
|
||||
void SubscribeUserSwtichThread();
|
||||
void InitArgsFromProp();
|
||||
|
||||
bool CheckPermission(const std::shared_ptr<Request>& request) const;
|
||||
bool CheckMaxRequestNum(int32_t uid, const std::string& packageName) const;
|
||||
int32_t GetUserId(int32_t uid) const;
|
||||
const std::list<std::shared_ptr<Request>>& GetRequestsInProxy() const;
|
||||
|
||||
bool isLocating_ = false;
|
||||
bool proxySwtich_ = false;
|
||||
bool featureSwitch_ = true;
|
||||
bool isWating_ = false;
|
||||
bool isSubscribed_ = false;
|
||||
int timeInterval_;
|
||||
int32_t curUserId_ = 0;
|
||||
|
||||
sptr<ILocatorCallback> callback_;
|
||||
std::shared_ptr<Request> request_;
|
||||
std::shared_ptr<std::map<int32_t, std::shared_ptr<std::list<std::shared_ptr<Request>>>>> requestsMap_;
|
||||
std::shared_ptr<std::list<std::shared_ptr<Request>>> requestsList_;
|
||||
static std::mutex requestListMutex_;
|
||||
static std::mutex locatorMutex_;
|
||||
|
||||
class mLocatorCallback : public IRemoteStub<ILocatorCallback> {
|
||||
public:
|
||||
void OnLocationReport(const std::unique_ptr<Location>& location);
|
||||
void OnLocatingStatusChange(const int status);
|
||||
void OnErrorReport(const int errorCode);
|
||||
};
|
||||
|
||||
class UserSwitchSubscriber : public OHOS::EventFwk::CommonEventSubscriber {
|
||||
public:
|
||||
explicit UserSwitchSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &info);
|
||||
virtual ~UserSwitchSubscriber() override = default;
|
||||
static bool Subscribe();
|
||||
private:
|
||||
virtual void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &event) override;
|
||||
};
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // LOCATION_BACKGROUND_PROXY_H
|
81
location_locator/locator/include/locator_event_manager.h
Normal file
81
location_locator/locator/include/locator_event_manager.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_LOCATOREVENTMANAGER_H
|
||||
#define LOCATION_LOCATOREVENTMANAGER_H
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <singleton.h>
|
||||
#include <string>
|
||||
|
||||
#include "event_handler.h"
|
||||
|
||||
#include "request.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
constexpr uint32_t EVENT_SEND_HIVIEW_MESSAGE = 0x0001;
|
||||
constexpr uint32_t EVENT_SEND_DAILY_REPORT = 0x0002;
|
||||
|
||||
constexpr uint32_t DAILY_INTERVAL = 24 * 60 * 60 * 1000;
|
||||
constexpr uint32_t COUNT_MAX = 500;
|
||||
constexpr uint32_t INVALID_VALUE = 0xFFFFFFFF;
|
||||
constexpr uint32_t DFT_APP_MAX_SIZE = 10;
|
||||
constexpr uint32_t DFT_TOP_REQUEST_UPLOAD_MAX_SIZE = 5;
|
||||
|
||||
struct AppRequestCount {
|
||||
std::string packageName;
|
||||
std::vector<int> requestType;
|
||||
std::vector<int> count;
|
||||
};
|
||||
|
||||
class DftEvent {
|
||||
public:
|
||||
void PutInt(const std::string& name, int value);
|
||||
int GetInt(const std::string& name);
|
||||
private:
|
||||
std::map<std::string, int> intValues_;
|
||||
};
|
||||
|
||||
class DftHandler : public AppExecFwk::EventHandler {
|
||||
public:
|
||||
explicit DftHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner);
|
||||
~DftHandler() override;
|
||||
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
|
||||
};
|
||||
|
||||
class LocatorDftManager : DelayedSingleton<LocatorDftManager> {
|
||||
public:
|
||||
LocatorDftManager();
|
||||
~LocatorDftManager();
|
||||
void Init();
|
||||
void IpcCallingErr(int error);
|
||||
void LocationSessionStart(std::shared_ptr<Request> request);
|
||||
void DistributionSessionStart();
|
||||
void DistributionDisconnect();
|
||||
void SendDistributionDailyCount();
|
||||
void SendRequestDailyCount();
|
||||
private:
|
||||
std::shared_ptr<AppRequestCount> GetTopRequest();
|
||||
|
||||
std::shared_ptr<DftHandler> handler_;
|
||||
std::list<std::shared_ptr<AppRequestCount>> appRequests_;
|
||||
uint32_t distributeSissionCnt_;
|
||||
uint32_t distributeDisconnectCnt_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // LOCATION_LOCATOREVENTMANAGER_H
|
39
location_locator/locator/include/locator_event_subscriber.h
Normal file
39
location_locator/locator/include/locator_event_subscriber.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_LOCATOR_EVENT_SUBSCRIBER_H
|
||||
#define LOCATION_LOCATOR_EVENT_SUBSCRIBER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "common_event_manager.h"
|
||||
|
||||
#include "locator_skeleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const std::string MODE_CHANGED_EVENT = "usual.event.location.MODE_STATE_CHANGED";
|
||||
|
||||
class LocatorEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber {
|
||||
public:
|
||||
LocatorEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &info);
|
||||
~LocatorEventSubscriber();
|
||||
virtual void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &event) override;
|
||||
private:
|
||||
std::unique_ptr<LocatorProxy> proxyLocator_;
|
||||
};
|
||||
} // Location
|
||||
} // OHOS
|
||||
#endif // LOCATION_LOCATOR_EVENT_SUBSCRIBER_H
|
59
location_locator/locator/include/locator_skeleton.h
Normal file
59
location_locator/locator/include/locator_skeleton.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_LOCATOR_SKELETON_H
|
||||
#define OHOS_LOCATION_LOCATOR_SKELETON_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "location.h"
|
||||
#include "locator_proxy.h"
|
||||
#include "request_config.h"
|
||||
#include "i_locator_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class LocatorAbilityStub : public IRemoteStub<ILocator> {
|
||||
public:
|
||||
int32_t OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void ParseDataAndStartLocating(MessageParcel& data, MessageParcel& reply, pid_t pid, pid_t uid);
|
||||
void ParseDataAndStopLocating(MessageParcel& data, MessageParcel& reply);
|
||||
int ReportStatus(MessageParcel& data, int type);
|
||||
void ParseDataAndStartCacheLocating(MessageParcel& data, MessageParcel& reply);
|
||||
void ParseDataAndStopCacheLocating(MessageParcel& data, MessageParcel& reply);
|
||||
private:
|
||||
static pid_t lastCallingPid;
|
||||
static pid_t lastCallingUid;
|
||||
};
|
||||
|
||||
class LocatorCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
virtual void OnRemoteDied(const wptr<IRemoteObject> &object);
|
||||
LocatorCallbackDeathRecipient();
|
||||
virtual ~LocatorCallbackDeathRecipient();
|
||||
};
|
||||
|
||||
class SwitchCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
virtual void OnRemoteDied(const wptr<IRemoteObject> &object);
|
||||
SwitchCallbackDeathRecipient();
|
||||
virtual ~SwitchCallbackDeathRecipient();
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_LOCATOR_SKELETON_H
|
39
location_locator/locator/include/report_manager.h
Normal file
39
location_locator/locator/include/report_manager.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_REPORT_MANAGER_H
|
||||
#define BASE_REPORT_MANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <list>
|
||||
|
||||
#include "iremote_broker.h"
|
||||
|
||||
#include "location.h"
|
||||
#include "request.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class ReportManager {
|
||||
public:
|
||||
bool ReportRemoteCallback(sptr<ILocatorCallback>& locatorCallback, int type, int result);
|
||||
bool OnReportLocation(const std::unique_ptr<Location>& location, std::string abilityName);
|
||||
bool ReportIntervalCheck(const std::unique_ptr<Location>& location, const std::shared_ptr<Request>& request);
|
||||
bool MaxAccuracyCheck(const std::unique_ptr<Location>& location, const std::shared_ptr<Request>& request);
|
||||
};
|
||||
} // namespace OHOS
|
||||
} // namespace Location
|
||||
#endif // BASE_REPORT_MANAGER_H
|
60
location_locator/locator/include/request.h
Normal file
60
location_locator/locator/include/request.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_REQUEST_H
|
||||
#define OHOS_LOCATION_REQUEST_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "i_locator_callback.h"
|
||||
#include "request_config.h"
|
||||
#include "work_record.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class Request {
|
||||
public:
|
||||
Request();
|
||||
~Request();
|
||||
pid_t GetUid();
|
||||
pid_t GetPid();
|
||||
std::string GetPackageName();
|
||||
sptr<RequestConfig> GetRequestConfig();
|
||||
sptr<ILocatorCallback> GetLocatorCallBack();
|
||||
void SetUid(pid_t uid);
|
||||
void SetPid(pid_t pid);
|
||||
void SetPackageName(std::string packageName);
|
||||
void SetRequestConfig(RequestConfig& requestConfig);
|
||||
void SetLocatorCallBack(const sptr<ILocatorCallback>& callback);
|
||||
std::string ToString() const;
|
||||
void GetProxyName(std::shared_ptr<std::list<std::string>> proxys);
|
||||
bool GetIsRequesting();
|
||||
void SetRequesting(bool state);
|
||||
sptr<Location> GetLastLocation();
|
||||
void SetLastLocation(const std::unique_ptr<Location>& location);
|
||||
private:
|
||||
void GetProxyNameByPriority(std::shared_ptr<std::list<std::string>> proxys);
|
||||
|
||||
pid_t uid_;
|
||||
pid_t pid_;
|
||||
sptr<Location> lastLocation_;
|
||||
std::string packageName_;
|
||||
sptr<RequestConfig> requestConfig_;
|
||||
sptr<ILocatorCallback> callBack_;
|
||||
bool isRequesting_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_REQUEST_H
|
60
location_locator/locator/include/request_manager.h
Normal file
60
location_locator/locator/include/request_manager.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <singleton.h>
|
||||
#include <string>
|
||||
|
||||
#include "iremote_stub.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "request.h"
|
||||
#include "work_record.h"
|
||||
|
||||
#ifndef BASE_REQUEST_MANAGER_H
|
||||
#define BASE_REQUEST_MANAGER_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class RequestManager : public DelayedSingleton<RequestManager> {
|
||||
public:
|
||||
RequestManager();
|
||||
~RequestManager();
|
||||
bool InitSystemListeners();
|
||||
void HandleStartLocating(std::shared_ptr<Request> request);
|
||||
void HandleStopLocating(sptr<ILocatorCallback> callback);
|
||||
void HandlePermissionChanged(int32_t uid);
|
||||
void HandlePowerSuspendChanged(int32_t pid, int32_t uid, int32_t flag);
|
||||
void UpdateRequestRecord(std::shared_ptr<Request> request, bool shouldInsert);
|
||||
void HandleRequest();
|
||||
private:
|
||||
bool RestorRequest(std::shared_ptr<Request> newRequest);
|
||||
void UpdateRequestRecord(std::shared_ptr<Request> request, std::string abilityName, bool shouldInsert);
|
||||
void DeleteRequestRecord(std::shared_ptr<std::list<std::shared_ptr<Request>>> requests);
|
||||
void HandleRequest(std::string abilityName);
|
||||
void ProxySendLocationRequest(std::string abilityName, WorkRecord& workRecord, int timeInterval);
|
||||
sptr<IRemoteObject> GetRemoteObject(std::string abilityName);
|
||||
bool IsUidInProcessing(int32_t uid);
|
||||
|
||||
bool isPermissionRegistered_ = false;
|
||||
bool isPowerRegistered_ = false;
|
||||
std::list<int32_t> runningUids_;
|
||||
static std::mutex requestMutex;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // BASE_REQUEST_MANAGER_H
|
103
location_locator/locator/include/subability_common.h
Normal file
103
location_locator/locator/include/subability_common.h
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LOCATION_SUBABILITY_COMMON_H
|
||||
#define OHOS_LOCATION_SUBABILITY_COMMON_H
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <map>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "adapter_callback_skeleton.h"
|
||||
#include "common_hisysevent.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "lbs_log.h"
|
||||
#include "work_record.h"
|
||||
|
||||
#define HIGNSS_ADAPTER_PATH "/system/lib/libgnss.default.so"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class ISubAbility : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
SEND_LOCATION_REQUEST = 1,
|
||||
GET_CACHED_LOCATION = 2,
|
||||
SET_ENABLE = 3,
|
||||
SELF_REQUEST = 4,
|
||||
HANDLE_REMOTE_REQUEST = 5,
|
||||
REFRESH_REQUESTS = 6,
|
||||
REG_GNSS_STATUS = 7,
|
||||
UNREG_GNSS_STATUS = 8,
|
||||
REG_NMEA = 9,
|
||||
UNREG_NMEA = 10,
|
||||
REG_CACHED = 11,
|
||||
UNREG_CACHED = 12,
|
||||
GET_CACHED_SIZE = 13,
|
||||
FLUSH_CACHED = 14,
|
||||
SEND_COMMANDS = 15,
|
||||
ADD_FENCE_INFO = 16,
|
||||
REMOVE_FENCE_INFO = 17,
|
||||
};
|
||||
virtual void SendLocationRequest(uint64_t interval, WorkRecord &workrecord) = 0;
|
||||
virtual std::unique_ptr<Location> GetCachedLocation() = 0;
|
||||
virtual void SetEnable(bool state) = 0;
|
||||
};
|
||||
|
||||
class SubAbilityProxy {
|
||||
public:
|
||||
void SetProxy(std::string name, sptr<IRemoteObject> proxy);
|
||||
void SendRequest(uint64_t interval, WorkRecord &workrecord);
|
||||
std::unique_ptr<Location> GetCache();
|
||||
void Enable(bool state);
|
||||
|
||||
private:
|
||||
OHOS::HiviewDFX::HiLogLabel label_;
|
||||
sptr<IRemoteObject> proxy_;
|
||||
};
|
||||
|
||||
class SubAbility {
|
||||
public:
|
||||
void SetAbility(std::string name);
|
||||
void LocationRequest(uint64_t interval, WorkRecord &workrecord);
|
||||
std::unique_ptr<Location> GetCache();
|
||||
void Enable(bool state, const sptr<IRemoteObject> ability);
|
||||
void HandleSelfRequest(pid_t pid, pid_t uid, bool state);
|
||||
void HandleRemoteRequest(bool state, std::string deviceId);
|
||||
void HandleRefrashRequirements();
|
||||
|
||||
private:
|
||||
void HandleLocalRequest(WorkRecord &record);
|
||||
void HandleRemoveRecord(WorkRecord &record);
|
||||
void HandleAddRecord(WorkRecord &record);
|
||||
void RequestRecord(sptr<LocationCallbackStub> addCallback, WorkRecord &workRecord, bool isAdded);
|
||||
sptr<LocationCallbackStub> GetCallback(int uid);
|
||||
void WriteCallbackToParcel(sptr<LocationCallbackStub> callback, MessageParcel &data);
|
||||
void WriteInfoToParcel(WorkRecord &workRecord, MessageParcel &data);
|
||||
bool ParseReplyInfo(MessageParcel &rep);
|
||||
|
||||
OHOS::HiviewDFX::HiLogLabel label_;
|
||||
sptr<IRemoteObject> ability_;
|
||||
sptr<LocationCallbackStub> callback_;
|
||||
uint64_t interval_ = 0;
|
||||
std::string name_;
|
||||
std::u16string capability_ = u"";
|
||||
std::unique_ptr<WorkRecord> lastRecord_;
|
||||
std::unique_ptr<WorkRecord> newRecord_;
|
||||
std::unique_ptr<std::map<int, sptr<LocationCallbackStub>>> requestMap_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOCATION_SUBABILITY_COMMON_H
|
58
location_locator/locator/include/work_record.h
Normal file
58
location_locator/locator/include/work_record.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOCATION_WORK_RECORD_H
|
||||
#define LOCATION_WORK_RECORD_H
|
||||
|
||||
#include <parcel.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class WorkRecord : public Parcelable {
|
||||
public:
|
||||
WorkRecord();
|
||||
virtual ~WorkRecord() = default;
|
||||
bool Add(int uid, int pid, std::string name);
|
||||
bool Remove(int uid, int pid, std::string name);
|
||||
bool Find(int uid, std::string name);
|
||||
void Clear();
|
||||
void Set(WorkRecord &workRecord);
|
||||
bool Add(int uid, std::string name);
|
||||
bool Remove(int uid, std::string name);
|
||||
bool Remove(std::string name);
|
||||
std::string GetDeviceId();
|
||||
void SetDeviceId(std::string deviceId);
|
||||
int Size();
|
||||
bool IsEmpty();
|
||||
std::string GetName(int index);
|
||||
int GetUid(int index);
|
||||
int GetPid(int index);
|
||||
void ReadFromParcel(Parcel& parcel);
|
||||
bool Marshalling(Parcel& parcel) const override;
|
||||
bool MarshallingWorkRecord(Parcel& parcel) const;
|
||||
static std::unique_ptr<WorkRecord> Unmarshalling(Parcel& parcel);
|
||||
std::string ToString();
|
||||
private:
|
||||
int num_;
|
||||
std::vector<int> uids_;
|
||||
std::vector<int> pids_;
|
||||
std::vector<std::string> names_;
|
||||
std::string deviceId_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // LOCATION_WORK_RECORD_H
|
84
location_locator/locator/source/fusion_controller.cpp
Normal file
84
location_locator/locator/source/fusion_controller.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "fusion_controller.h"
|
||||
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "constant_definition.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const uint32_t FUSION_DEFAULT_FLAG = 0;
|
||||
const uint32_t FUSION_BASE_FLAG = 1;
|
||||
const uint32_t REPORT_FUSED_LOCATION_FLAG = FUSION_BASE_FLAG;
|
||||
const uint32_t QUICK_FIX_FLAG = FUSION_BASE_FLAG << 1;
|
||||
const uint32_t NETWORK_SELF_REQUEST = 4;
|
||||
|
||||
void FusionController::ActiveFusionStrategies(int type)
|
||||
{
|
||||
if (needReset_) {
|
||||
fusedFlag_ = FUSION_DEFAULT_FLAG;
|
||||
needReset_ = false;
|
||||
}
|
||||
switch (type) {
|
||||
case SCENE_NAVIGATION:
|
||||
case SCENE_TRAJECTORY_TRACKING:
|
||||
fusedFlag_ = fusedFlag_ | QUICK_FIX_FLAG;
|
||||
LBSLOGI(FUSION_CONTROLLER, "enable quick first fix");
|
||||
break;
|
||||
case PRIORITY_FAST_FIRST_FIX:
|
||||
fusedFlag_ = fusedFlag_ | REPORT_FUSED_LOCATION_FLAG;
|
||||
LBSLOGI(FUSION_CONTROLLER, "enable basic fused report");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FusionController::Process(std::string abilityName)
|
||||
{
|
||||
needReset_ = true;
|
||||
if (GNSS_ABILITY.compare(abilityName) != 0) {
|
||||
return;
|
||||
}
|
||||
LBSLOGI(FUSION_CONTROLLER, "fused flag:%{public}d", fusedFlag_);
|
||||
RequestQuickFix(fusedFlag_ & QUICK_FIX_FLAG);
|
||||
}
|
||||
|
||||
void FusionController::FuseResult(std::string abilityName, const std::unique_ptr<Location>& location)
|
||||
{
|
||||
if (GNSS_ABILITY.compare(abilityName) == 0) {
|
||||
RequestQuickFix(false);
|
||||
}
|
||||
}
|
||||
|
||||
void FusionController::RequestQuickFix(bool state)
|
||||
{
|
||||
sptr<IRemoteObject> remoteObject = CommonUtils::GetRemoteObject(LOCATION_NETWORK_LOCATING_SA_ID);
|
||||
if (remoteObject == nullptr) {
|
||||
LBSLOGW(FUSION_CONTROLLER, "can not get network ability remote object");
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteBool(state);
|
||||
remoteObject->SendRequest(NETWORK_SELF_REQUEST, data, reply, option);
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
751
location_locator/locator/source/locator_ability.cpp
Normal file
751
location_locator/locator/source/locator_ability.cpp
Normal file
@ -0,0 +1,751 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "locator_ability.h"
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <file_ex.h>
|
||||
#include <thread>
|
||||
#include "constant_definition.h"
|
||||
#include "event_runner.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_types.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "lbs_log.h"
|
||||
#include "location_config_manager.h"
|
||||
#include "location_dumper.h"
|
||||
#include "locator_background_proxy.h"
|
||||
#include "locator_event_manager.h"
|
||||
#include "request_manager.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(
|
||||
DelayedSingleton<LocatorAbility>::GetInstance().get());
|
||||
|
||||
const uint32_t EVENT_UPDATE_SA = 0x0001;
|
||||
const uint32_t EVENT_INIT_REQUEST_MANAGER = 0x0002;
|
||||
const uint32_t EVENT_APPLY_REQUIREMENTS = 0x0003;
|
||||
const uint32_t EVENT_RETRY_REGISTER_ACTION = 0x0004;
|
||||
const uint32_t RETRY_INTERVAL_UNITE = 1000;
|
||||
const uint32_t RETRY_INTERVAL_2_SECONDS = 2 * RETRY_INTERVAL_UNITE;
|
||||
const uint32_t RETRY_INTERVAL_OF_INIT_REQUEST_MANAGER = 5 * RETRY_INTERVAL_UNITE;
|
||||
const uint32_t SET_ENABLE = 3;
|
||||
const uint32_t GET_CACHED_LOCATION = 2;
|
||||
const uint32_t REG_GNSS_STATUS = 7;
|
||||
const uint32_t UNREG_GNSS_STATUS = 8;
|
||||
const uint32_t REG_NMEA = 9;
|
||||
const uint32_t UNREG_NMEA = 10;
|
||||
const uint32_t REG_CACHED = 11;
|
||||
const uint32_t UNREG_CACHED = 12;
|
||||
const uint32_t GET_CACHED_SIZE = 13;
|
||||
const uint32_t FLUSH_CACHED = 14;
|
||||
const uint32_t SEND_COMMANDS = 15;
|
||||
const uint32_t ADD_FENCE_INFO = 16;
|
||||
const uint32_t REMOVE_FENCE_INFO = 17;
|
||||
const float_t PRECISION = 0.000001;
|
||||
|
||||
LocatorAbility::LocatorAbility() : SystemAbility(LOCATION_LOCATOR_SA_ID, true)
|
||||
{
|
||||
switchCallbacks_ = std::make_unique<std::map<pid_t, sptr<ISwitchCallback>>>();
|
||||
requests_ = std::make_shared<std::map<std::string, std::list<std::shared_ptr<Request>>>>();
|
||||
receivers_ = std::make_shared<std::map<sptr<IRemoteObject>, std::list<std::shared_ptr<Request>>>>();
|
||||
proxyMap_ = std::make_shared<std::map<std::string, sptr<IRemoteObject>>>();
|
||||
InitRequestManagerMap();
|
||||
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgr != nullptr) {
|
||||
}
|
||||
LBSLOGI(LOCATOR, "LocatorAbility constructed.");
|
||||
}
|
||||
|
||||
LocatorAbility::~LocatorAbility() {}
|
||||
|
||||
void LocatorAbility::OnStart()
|
||||
{
|
||||
if (state_ == ServiceRunningState::STATE_RUNNING) {
|
||||
LBSLOGI(LOCATOR, "LocatorAbility has already started.");
|
||||
return;
|
||||
}
|
||||
if (!Init()) {
|
||||
LBSLOGE(LOCATOR, "failed to init LocatorAbility");
|
||||
OnStop();
|
||||
return;
|
||||
}
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
LBSLOGI(LOCATOR, "LocatorAbility::OnStart start ability success.");
|
||||
}
|
||||
|
||||
void LocatorAbility::OnStop()
|
||||
{
|
||||
state_ = ServiceRunningState::STATE_NOT_START;
|
||||
registerToAbility_ = false;
|
||||
LBSLOGI(LOCATOR, "LocatorAbility::OnStop ability stopped.");
|
||||
}
|
||||
|
||||
bool LocatorAbility::Init()
|
||||
{
|
||||
if (registerToAbility_) {
|
||||
return true;
|
||||
}
|
||||
bool ret = Publish(AsObject());
|
||||
if (!ret) {
|
||||
LBSLOGE(LOCATOR, "Init add system ability failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
deviceId_ = CommonUtils::InitDeviceId();
|
||||
requestManager_ = DelayedSingleton<RequestManager>::GetInstance();
|
||||
reportManager_ = std::make_unique<ReportManager>();
|
||||
locatorHandler_ = std::make_shared<LocatorHandler>(AppExecFwk::EventRunner::Create(true));
|
||||
InitSaAbility();
|
||||
if (locatorHandler_ != nullptr) {
|
||||
locatorHandler_->SendHighPriorityEvent(EVENT_INIT_REQUEST_MANAGER, 0, RETRY_INTERVAL_OF_INIT_REQUEST_MANAGER);
|
||||
}
|
||||
RegisterAction();
|
||||
|
||||
registerToAbility_ = true;
|
||||
return registerToAbility_;
|
||||
}
|
||||
|
||||
void LocatorAbility::SaDumpInfo(std::string& result)
|
||||
{
|
||||
int state = QuerySwitchState();
|
||||
result += "Location switch state: ";
|
||||
std::string status = state ? "on" : "off";
|
||||
result += status + "\n";
|
||||
}
|
||||
|
||||
int32_t LocatorAbility::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
std::vector<std::string> vecArgs;
|
||||
std::transform(args.begin(), args.end(), std::back_inserter(vecArgs), [](const std::u16string &arg) {
|
||||
return Str16ToStr8(arg);
|
||||
});
|
||||
|
||||
LocationDumper dumper;
|
||||
std::string result;
|
||||
dumper.LocatorDump(SaDumpInfo, vecArgs, result);
|
||||
if (!SaveStringToFd(fd, result)) {
|
||||
LBSLOGE(GEO_CONVERT, "Gnss save string to fd failed!");
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
LocatorHandler::LocatorHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner) : EventHandler(runner) {}
|
||||
|
||||
LocatorHandler::~LocatorHandler() {}
|
||||
|
||||
void LocatorHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
|
||||
{
|
||||
uint32_t eventId = event->GetInnerEventId();
|
||||
LBSLOGI(LOCATOR, "ProcessEvent event:%{public}d", eventId);
|
||||
switch (eventId) {
|
||||
case EVENT_UPDATE_SA: {
|
||||
DelayedSingleton<LocatorAbility>::GetInstance()->UpdateSaAbilityHandler();
|
||||
break;
|
||||
}
|
||||
case EVENT_RETRY_REGISTER_ACTION: {
|
||||
DelayedSingleton<LocatorAbility>::GetInstance()->RegisterAction();
|
||||
break;
|
||||
}
|
||||
case EVENT_INIT_REQUEST_MANAGER: {
|
||||
if (!DelayedSingleton<RequestManager>::GetInstance()->InitSystemListeners()) {
|
||||
SendHighPriorityEvent(EVENT_INIT_REQUEST_MANAGER, 0, RETRY_INTERVAL_OF_INIT_REQUEST_MANAGER);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EVENT_APPLY_REQUIREMENTS: {
|
||||
DelayedSingleton<RequestManager>::GetInstance()->HandleRequest();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorAbility::InitRequestManagerMap()
|
||||
{
|
||||
if (requests_ != nullptr) {
|
||||
std::list<std::shared_ptr<Request>> gnssList;
|
||||
requests_->insert(make_pair(GNSS_ABILITY, gnssList));
|
||||
std::list<std::shared_ptr<Request>> networkList;
|
||||
requests_->insert(make_pair(NETWORK_ABILITY, networkList));
|
||||
std::list<std::shared_ptr<Request>> passiveList;
|
||||
requests_->insert(make_pair(PASSIVE_ABILITY, passiveList));
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<std::map<std::string, std::list<std::shared_ptr<Request>>>> LocatorAbility::GetRequests()
|
||||
{
|
||||
return requests_;
|
||||
}
|
||||
|
||||
std::shared_ptr<std::map<sptr<IRemoteObject>, std::list<std::shared_ptr<Request>>>> LocatorAbility::GetReceivers()
|
||||
{
|
||||
return receivers_;
|
||||
}
|
||||
|
||||
std::shared_ptr<std::map<std::string, sptr<IRemoteObject>>> LocatorAbility::GetProxyMap()
|
||||
{
|
||||
return proxyMap_;
|
||||
}
|
||||
|
||||
void LocatorAbility::ApplyRequests()
|
||||
{
|
||||
locatorHandler_->SendHighPriorityEvent(EVENT_APPLY_REQUIREMENTS, 0, RETRY_INTERVAL_UNITE);
|
||||
}
|
||||
|
||||
void LocatorAbility::InitSaAbility()
|
||||
{
|
||||
LBSLOGI(LOCATOR, "initSaAbility start");
|
||||
if (proxyMap_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
// init gnss ability sa
|
||||
sptr<IRemoteObject> objectGnss = CommonUtils::GetRemoteObject(LOCATION_GNSS_SA_ID, CommonUtils::InitDeviceId());
|
||||
if (objectGnss != nullptr) {
|
||||
proxyMap_->insert(make_pair(GNSS_ABILITY, objectGnss));
|
||||
} else {
|
||||
LBSLOGI(LOCATOR, "GetRemoteObject gnss sa is null");
|
||||
}
|
||||
|
||||
// init network ability sa
|
||||
sptr<IRemoteObject> objectNetwork = CommonUtils::GetRemoteObject(LOCATION_NETWORK_LOCATING_SA_ID,
|
||||
CommonUtils::InitDeviceId());
|
||||
if (objectNetwork != nullptr) {
|
||||
proxyMap_->insert(make_pair(NETWORK_ABILITY, objectNetwork));
|
||||
} else {
|
||||
LBSLOGI(LOCATOR, "GetRemoteObject network sa is null");
|
||||
}
|
||||
|
||||
// init passive ability sa
|
||||
sptr<IRemoteObject> objectPassive = CommonUtils::GetRemoteObject(LOCATION_NOPOWER_LOCATING_SA_ID,
|
||||
CommonUtils::InitDeviceId());
|
||||
if (objectPassive != nullptr) {
|
||||
proxyMap_->insert(make_pair(PASSIVE_ABILITY, objectPassive));
|
||||
} else {
|
||||
LBSLOGI(LOCATOR, "GetRemoteObject passive sa is null");
|
||||
}
|
||||
|
||||
UpdateSaAbilityHandler();
|
||||
}
|
||||
|
||||
bool LocatorAbility::CheckSaValid()
|
||||
{
|
||||
auto objectGnss = proxyMap_->find(GNSS_ABILITY);
|
||||
if (objectGnss == proxyMap_->end()) {
|
||||
LBSLOGI(LOCATOR, "gnss sa is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto objectNetwork = proxyMap_->find(NETWORK_ABILITY);
|
||||
if (objectNetwork == proxyMap_->end()) {
|
||||
LBSLOGI(LOCATOR, "network sa is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto objectPassive = proxyMap_->find(PASSIVE_ABILITY);
|
||||
if (objectPassive == proxyMap_->end()) {
|
||||
LBSLOGI(LOCATOR, "passive sa is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LocatorAbility::UpdateSaAbility()
|
||||
{
|
||||
auto event = AppExecFwk::InnerEvent::Get(EVENT_UPDATE_SA, 0);
|
||||
if (locatorHandler_ != nullptr) {
|
||||
locatorHandler_->SendHighPriorityEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorAbility::UpdateSaAbilityHandler()
|
||||
{
|
||||
int state = QuerySwitchState();
|
||||
LBSLOGI(LOCATOR, "update location subability enable state, switch state=%{public}d, action registered=%{public}d",
|
||||
state, isActionRegistered);
|
||||
if (state == EXCEPTION) {
|
||||
auto event = AppExecFwk::InnerEvent::Get(EVENT_UPDATE_SA, 0);
|
||||
locatorHandler_->SendHighPriorityEvent(event, RETRY_INTERVAL_2_SECONDS);
|
||||
return;
|
||||
}
|
||||
|
||||
bool currentEnable = isEnabled_;
|
||||
isEnabled_ = (state == ENABLED);
|
||||
if (isEnabled_ == currentEnable) {
|
||||
return;
|
||||
}
|
||||
if (proxyMap_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
DelayedSingleton<LocatorBackgroundProxy>::GetInstance().get()->OnProviderSwitch(isEnabled_);
|
||||
for (auto iter = proxyMap_->begin(); iter != proxyMap_->end(); iter++) {
|
||||
sptr<IRemoteObject> remoteObject = iter->second;
|
||||
MessageParcel data;
|
||||
data.WriteBool(isEnabled_);
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int error = remoteObject->SendRequest(SET_ENABLE, data, reply, option);
|
||||
LBSLOGD(LOCATOR, "enable %{public}s ability, remote result %{public}d", (iter->first).c_str(), error);
|
||||
}
|
||||
for (auto iter = switchCallbacks_->begin(); iter != switchCallbacks_->end(); iter++) {
|
||||
sptr<IRemoteObject> remoteObject = (iter->second)->AsObject();
|
||||
auto callback = std::make_unique<SwitchCallbackProxy>(remoteObject);
|
||||
if (callback != nullptr) {
|
||||
callback->OnSwitchChange(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorAbility::EnableAbility(bool isEnabled)
|
||||
{
|
||||
if (isEnabled_ == isEnabled) {
|
||||
LBSLOGD(LOCATOR, "no need to set location ability, enable:%{public}d", isEnabled_);
|
||||
return;
|
||||
}
|
||||
LBSLOGI(LOCATOR, "EnableAbility %{public}d", isEnabled);
|
||||
int modeValue = isEnabled ? 1 : 0;
|
||||
LocationConfigManager::GetInstance().SetLocationSwitchState(modeValue);
|
||||
UpdateSaAbility();
|
||||
std::string state = isEnabled ? "enable" : "disable";
|
||||
WriteLocationSwitchStateEvent(state);
|
||||
}
|
||||
|
||||
int LocatorAbility::GetSwitchState()
|
||||
{
|
||||
int state = QuerySwitchState();
|
||||
isEnabled_ = (state == ENABLED);
|
||||
return isEnabled_ ? ENABLED : DISABLED;
|
||||
}
|
||||
|
||||
int LocatorAbility::QuerySwitchState()
|
||||
{
|
||||
return LocationConfigManager::GetInstance().GetLocationSwitchState();
|
||||
}
|
||||
|
||||
bool LocatorAbility::IsLocationPrivacyConfirmed(const LocationPrivacyType type)
|
||||
{
|
||||
return LocationConfigManager::GetInstance().GetPrivacyTypeState(type);
|
||||
}
|
||||
|
||||
void LocatorAbility::SetLocationPrivacyConfirmStatus(const LocationPrivacyType type, bool isConfirmed)
|
||||
{
|
||||
LocationConfigManager::GetInstance().SetPrivacyTypeState(type, isConfirmed);
|
||||
}
|
||||
|
||||
void LocatorAbility::RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(LOCATOR, "register an invalid switch callback");
|
||||
return;
|
||||
}
|
||||
sptr<IRemoteObject::DeathRecipient> death(new SwitchCallbackDeathRecipient());
|
||||
callback->AddDeathRecipient(death.GetRefPtr());
|
||||
sptr<ISwitchCallback> switchCallback = iface_cast<ISwitchCallback>(callback);
|
||||
if (switchCallback == nullptr) {
|
||||
LBSLOGE(LOCATOR, "cast switch callback fail!");
|
||||
return;
|
||||
}
|
||||
switchCallbacks_->erase(uid);
|
||||
switchCallbacks_->insert(std::make_pair(uid, switchCallback));
|
||||
LBSLOGD(LOCATOR, "after uid:%{public}d register, switch callback size:%{public}s",
|
||||
uid, std::to_string(switchCallbacks_->size()).c_str());
|
||||
}
|
||||
|
||||
void LocatorAbility::UnregisterSwitchCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(LOCATOR, "unregister an invalid switch callback");
|
||||
return;
|
||||
}
|
||||
sptr<ISwitchCallback> switchCallback = iface_cast<ISwitchCallback>(callback);
|
||||
if (switchCallback == nullptr) {
|
||||
LBSLOGE(LOCATOR, "cast switch callback fail!");
|
||||
return;
|
||||
}
|
||||
|
||||
pid_t uid = -1;
|
||||
for (auto iter = switchCallbacks_->begin(); iter != switchCallbacks_->end(); iter++) {
|
||||
sptr<IRemoteObject> remoteObject = (iter->second)->AsObject();
|
||||
if (remoteObject == callback) {
|
||||
uid = iter->first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
switchCallbacks_->erase(uid);
|
||||
LBSLOGD(LOCATOR, "after uid:%{public}d unregister, switch callback size:%{public}s",
|
||||
uid, std::to_string(switchCallbacks_->size()).c_str());
|
||||
}
|
||||
|
||||
void LocatorAbility::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
LBSLOGD(LOCATOR, "uid is: %{public}d", uid);
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
dataToStub.WriteRemoteObject(callback);
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
obj->SendRequest(REG_GNSS_STATUS, dataToStub, replyToStub, option);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorAbility::UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
dataToStub.WriteRemoteObject(callback);
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
obj->SendRequest(UNREG_GNSS_STATUS, dataToStub, replyToStub, option);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorAbility::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
dataToStub.WriteRemoteObject(callback);
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
obj->SendRequest(REG_NMEA, dataToStub, replyToStub, option);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorAbility::UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
dataToStub.WriteRemoteObject(callback);
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
obj->SendRequest(UNREG_NMEA, dataToStub, replyToStub, option);
|
||||
}
|
||||
}
|
||||
|
||||
int LocatorAbility::RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLoactionsRequest>& request,
|
||||
sptr<ICachedLocationsCallback>& callback, std::string bundleName)
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
dataToStub.WriteInt32(request->reportingPeriodSec);
|
||||
dataToStub.WriteBool(request->wakeUpCacheQueueFull);
|
||||
dataToStub.WriteRemoteObject(callback->AsObject());
|
||||
dataToStub.WriteString16(Str8ToStr16(bundleName));
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return EXCEPTION;
|
||||
}
|
||||
obj->SendRequest(REG_CACHED, dataToStub, replyToStub, option);
|
||||
}
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
|
||||
int LocatorAbility::UnregisterCachedLocationCallback(sptr<ICachedLocationsCallback>& callback)
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
dataToStub.WriteRemoteObject(callback->AsObject());
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return EXCEPTION;
|
||||
}
|
||||
obj->SendRequest(UNREG_CACHED, dataToStub, replyToStub, option);
|
||||
}
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
|
||||
int LocatorAbility::GetCachedGnssLocationsSize()
|
||||
{
|
||||
int size = 0;
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return EXCEPTION;
|
||||
}
|
||||
int error = obj->SendRequest(GET_CACHED_SIZE, dataToStub, replyToStub, option);
|
||||
if (error == NO_ERROR) {
|
||||
size = replyToStub.ReadInt32();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void LocatorAbility::FlushCachedGnssLocations()
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
obj->SendRequest(FLUSH_CACHED, dataToStub, replyToStub, option);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorAbility::SendCommand(std::unique_ptr<LocationCommand>& commands)
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
dataToStub.WriteInt32(commands->scenario);
|
||||
dataToStub.WriteString16(Str8ToStr16(commands->command));
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
obj->SendRequest(SEND_COMMANDS, dataToStub, replyToStub, option);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorAbility::AddFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
dataToStub.WriteInt32(request->priority);
|
||||
dataToStub.WriteInt32(request->scenario);
|
||||
dataToStub.WriteDouble(request->geofence.latitude);
|
||||
dataToStub.WriteDouble(request->geofence.longitude);
|
||||
dataToStub.WriteDouble(request->geofence.radius);
|
||||
dataToStub.WriteDouble(request->geofence.expiration);
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
obj->SendRequest(ADD_FENCE_INFO, dataToStub, replyToStub, option);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorAbility::RemoveFence(std::unique_ptr<GeofenceRequest>& request)
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
dataToStub.WriteInt32(request->priority);
|
||||
dataToStub.WriteInt32(request->scenario);
|
||||
dataToStub.WriteDouble(request->geofence.latitude);
|
||||
dataToStub.WriteDouble(request->geofence.longitude);
|
||||
dataToStub.WriteDouble(request->geofence.radius);
|
||||
dataToStub.WriteDouble(request->geofence.expiration);
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
obj->SendRequest(REMOVE_FENCE_INFO, dataToStub, replyToStub, option);
|
||||
}
|
||||
}
|
||||
|
||||
int LocatorAbility::StartLocating(std::unique_ptr<RequestConfig>& requestConfig,
|
||||
sptr<ILocatorCallback>& callback, std::string bundleName, pid_t pid, pid_t uid)
|
||||
{
|
||||
if (isEnabled_ == DISABLED) {
|
||||
ReportErrorStatus(callback, ERROR_SWITCH_UNOPEN);
|
||||
}
|
||||
if (!CheckSaValid()) {
|
||||
InitSaAbility();
|
||||
}
|
||||
// generate request object according to input params
|
||||
std::shared_ptr<Request> request = std::make_shared<Request>();
|
||||
if (request != nullptr) {
|
||||
request->SetUid(uid);
|
||||
request->SetPid(pid);
|
||||
request->SetPackageName(bundleName);
|
||||
request->SetRequestConfig(*requestConfig);
|
||||
request->SetLocatorCallBack(callback);
|
||||
}
|
||||
LBSLOGI(LOCATOR, "start locating");
|
||||
requestManager_->HandleStartLocating(request);
|
||||
ReportLocationStatus(callback, SESSION_START);
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
|
||||
int LocatorAbility::StopLocating(sptr<ILocatorCallback>& callback)
|
||||
{
|
||||
LBSLOGI(LOCATOR, "stop locating");
|
||||
requestManager_->HandleStopLocating(callback);
|
||||
ReportLocationStatus(callback, SESSION_STOP);
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
|
||||
int LocatorAbility::GetCacheLocation(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
auto remoteObject = proxyMap_->find(GNSS_ABILITY);
|
||||
if (remoteObject != proxyMap_->end()) {
|
||||
auto obj = remoteObject->second;
|
||||
MessageParcel dataToStub;
|
||||
MessageParcel replyToStub;
|
||||
MessageOption option;
|
||||
if (obj == nullptr) {
|
||||
return EXCEPTION;
|
||||
}
|
||||
obj->SendRequest(GET_CACHED_LOCATION, dataToStub, replyToStub, option);
|
||||
std::unique_ptr<Location> location = Location::Unmarshalling(replyToStub);
|
||||
if (location != nullptr && fabs(location->GetLatitude() - 0.0) > PRECISION
|
||||
&& fabs(location->GetLongitude() - 0.0) > PRECISION) {
|
||||
reply.WriteInt32(REPLY_NO_EXCEPTION);
|
||||
location->Marshalling(reply);
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
}
|
||||
reply.WriteInt32(EXCEPTION);
|
||||
reply.WriteString("get no cached result");
|
||||
LBSLOGI(LOCATOR, "GetCacheLocation location is null");
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
|
||||
int LocatorAbility::ReportLocation(const std::unique_ptr<Location>& location, std::string abilityName)
|
||||
{
|
||||
if (requests_ == nullptr) {
|
||||
return EXCEPTION;
|
||||
}
|
||||
LBSLOGI(LOCATOR, "start report location");
|
||||
if (reportManager_->OnReportLocation(location, abilityName)) {
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
int LocatorAbility::ReportLocationStatus(sptr<ILocatorCallback>& callback, int result)
|
||||
{
|
||||
if (reportManager_->ReportRemoteCallback(callback, ILocatorCallback::RECEIVE_LOCATION_STATUS_EVENT, result)) {
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
int LocatorAbility::ReportErrorStatus(sptr<ILocatorCallback>& callback, int result)
|
||||
{
|
||||
if (reportManager_->ReportRemoteCallback(callback, ILocatorCallback::RECEIVE_ERROR_INFO_EVENT, result)) {
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
||||
void LocatorAbility::RegisterAction()
|
||||
{
|
||||
if (isActionRegistered) {
|
||||
LBSLOGI(LOCATOR, "action has already registered");
|
||||
return;
|
||||
}
|
||||
OHOS::EventFwk::MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(MODE_CHANGED_EVENT);
|
||||
OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
locatorEventSubscriber_ = std::make_shared<LocatorEventSubscriber>(subscriberInfo);
|
||||
|
||||
bool result = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(locatorEventSubscriber_);
|
||||
if (result != 0) {
|
||||
LBSLOGE(LOCATOR, "Failed to subscriber locator event, result = %{public}d", result);
|
||||
isActionRegistered = false;
|
||||
} else {
|
||||
LBSLOGI(LOCATOR, "success to subscriber locator event, result = %{public}d", result);
|
||||
isActionRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
int LocatorAbility::IsGeoConvertAvailable(MessageParcel &data, MessageParcel &replay)
|
||||
{
|
||||
MessageParcel dataParcel;
|
||||
return SendGeoRequest(GEO_IS_AVAILABLE, dataParcel, replay);
|
||||
}
|
||||
|
||||
int LocatorAbility::GetAddressByCoordinate(MessageParcel &data, MessageParcel &replay)
|
||||
{
|
||||
LBSLOGI(LOCATOR, "locator_ability GetAddressByCoordinate");
|
||||
MessageParcel dataParcel;
|
||||
dataParcel.WriteDouble(data.ReadDouble()); // latitude
|
||||
dataParcel.WriteDouble(data.ReadDouble()); // longitude
|
||||
dataParcel.WriteInt32(data.ReadInt32()); // maxItems
|
||||
dataParcel.WriteInt32(data.ReadInt32()); // locale object size = 1
|
||||
dataParcel.WriteString16(data.ReadString16()); // locale.getLanguage()
|
||||
dataParcel.WriteString16(data.ReadString16()); // locale.getCountry()
|
||||
dataParcel.WriteString16(data.ReadString16()); // locale.getVariant()
|
||||
dataParcel.WriteString16(data.ReadString16()); // ""
|
||||
return SendGeoRequest(GET_FROM_COORDINATE, dataParcel, replay);
|
||||
}
|
||||
|
||||
int LocatorAbility::GetAddressByLocationName(MessageParcel &data, MessageParcel &replay)
|
||||
{
|
||||
MessageParcel dataParcel;
|
||||
dataParcel.WriteString16(data.ReadString16()); // description
|
||||
dataParcel.WriteDouble(data.ReadDouble()); // minLatitude
|
||||
dataParcel.WriteDouble(data.ReadDouble()); // minLongitude
|
||||
dataParcel.WriteDouble(data.ReadDouble()); // maxLatitude
|
||||
dataParcel.WriteDouble(data.ReadDouble()); // maxLongitude
|
||||
dataParcel.WriteInt32(data.ReadInt32()); // maxItems
|
||||
dataParcel.WriteInt32(data.ReadInt32()); // locale object size = 1
|
||||
dataParcel.WriteString16(data.ReadString16()); // locale.getLanguage()
|
||||
dataParcel.WriteString16(data.ReadString16()); // locale.getCountry()
|
||||
dataParcel.WriteString16(data.ReadString16()); // locale.getVariant()
|
||||
dataParcel.WriteString16(data.ReadString16()); // ""
|
||||
return SendGeoRequest(GET_FROM_LOCATION_NAME, dataParcel, replay);
|
||||
}
|
||||
|
||||
int LocatorAbility::SendGeoRequest(int type, MessageParcel &data, MessageParcel &replay)
|
||||
{
|
||||
sptr<IRemoteObject> remoteObject = CommonUtils::GetRemoteObject(LOCATION_GEO_CONVERT_SA_ID,
|
||||
CommonUtils::InitDeviceId());
|
||||
if (remoteObject == nullptr) {
|
||||
return EXCEPTION;
|
||||
}
|
||||
MessageOption option;
|
||||
return remoteObject->SendRequest(type, data, replay, option);
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
403
location_locator/locator/source/locator_background_proxy.cpp
Normal file
403
location_locator/locator/source/locator_background_proxy.cpp
Normal file
@ -0,0 +1,403 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "locator_background_proxy.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include "common_event_manager.h"
|
||||
#include "common_event_support.h"
|
||||
#include "common_utils.h"
|
||||
#include "constant_definition.h"
|
||||
#include "lbs_log.h"
|
||||
#include "locator_ability.h"
|
||||
#include "request_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
namespace {
|
||||
const int32_t UNKNOW_USER_ID = -1;
|
||||
const int32_t PER_USER_RANGE = 100000;
|
||||
const int32_t SUBSCRIBE_TIME = 5;
|
||||
const int32_t DEFAULT_TIME_INTERVAL = 30 * 60; // app recive location every 30 minutes in frozen state
|
||||
const int32_t REQUESTS_NUM_MAX = 1;
|
||||
const int DEFAULT_WORK_TIME = 6;
|
||||
const std::string FEATURE_SWITCH_PROP = "ro.config.locator_background";
|
||||
const std::string TIME_INTERVAL_PROP = "ro.config.locator_background.timeInterval";
|
||||
const std::string PROC_NAME = "system";
|
||||
}
|
||||
|
||||
std::mutex LocatorBackgroundProxy::requestListMutex_;
|
||||
std::mutex LocatorBackgroundProxy::locatorMutex_;
|
||||
LocatorBackgroundProxy::LocatorBackgroundProxy()
|
||||
{
|
||||
InitArgsFromProp();
|
||||
if (!featureSwitch_) {
|
||||
return;
|
||||
}
|
||||
requestsMap_ = std::make_shared<std::map<int32_t, std::shared_ptr<std::list<std::shared_ptr<Request>>>>>();
|
||||
requestsList_ = std::make_shared<std::list<std::shared_ptr<Request>>>();
|
||||
requestsMap_->insert(make_pair(curUserId_, requestsList_));
|
||||
|
||||
auto requestConfig = std::make_unique<RequestConfig>();
|
||||
requestConfig->SetPriority(PRIORITY_LOW_POWER);
|
||||
requestConfig->SetTimeInterval(timeInterval_);
|
||||
|
||||
callback_ = sptr<mLocatorCallback>(new LocatorBackgroundProxy::mLocatorCallback());
|
||||
request_ = std::make_shared<Request>();
|
||||
request_->SetUid(SYSTEM_UID);
|
||||
request_->SetPid(getpid());
|
||||
request_->SetPackageName(PROC_NAME);
|
||||
request_->SetRequestConfig(*requestConfig);
|
||||
request_->SetLocatorCallBack(callback_);
|
||||
SubscribeUserSwtich();
|
||||
}
|
||||
|
||||
LocatorBackgroundProxy::~LocatorBackgroundProxy() {}
|
||||
|
||||
// modify the parameters, in order to make the test easier
|
||||
void LocatorBackgroundProxy::InitArgsFromProp()
|
||||
{
|
||||
featureSwitch_ = 1;
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "feature switch %{public}d", featureSwitch_);
|
||||
char timeData[92] = {'\0'};
|
||||
int len = 0;
|
||||
if (len <= 0) {
|
||||
timeInterval_ = DEFAULT_TIME_INTERVAL;
|
||||
} else {
|
||||
timeInterval_ = std::atoi(timeData); // std::stoi will throw exception.
|
||||
if (timeInterval_ <= DEFAULT_WORK_TIME) {
|
||||
// the time app stays awake is DEFAULT_WORK_TIME(6 seconds)
|
||||
// timeInerval should set greater than DEFAULT_WORK_TIME
|
||||
timeInterval_ = DEFAULT_TIME_INTERVAL;
|
||||
}
|
||||
}
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "set time interval %{public}d", timeInterval_);
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::SubscribeUserSwtich()
|
||||
{
|
||||
std::thread th(&LocatorBackgroundProxy::SubscribeUserSwtichThread, this);
|
||||
th.detach();
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::SubscribeUserSwtichThread()
|
||||
{
|
||||
// registering too early will cause failure(CommonEvent module has not been initialized)
|
||||
// so delay for 5 sceonds
|
||||
std::this_thread::sleep_for(std::chrono::seconds(SUBSCRIBE_TIME));
|
||||
isSubscribed_ = LocatorBackgroundProxy::UserSwitchSubscriber::Subscribe();
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::StartLocatorThread()
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::seconds(timeInterval_));
|
||||
std::lock_guard lock(locatorMutex_);
|
||||
isWating_ = false;
|
||||
if (isLocating_ || !proxySwtich_ || requestsList_->empty()) {
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "cancel locating");
|
||||
return;
|
||||
}
|
||||
isLocating_ = true;
|
||||
LBSLOGI(LOCATOR_BACKGROUND_PROXY, "real start locating");
|
||||
DelayedSingleton<RequestManager>::GetInstance().get()->HandleStartLocating(request_);
|
||||
DelayedSingleton<LocatorAbility>::GetInstance().get()->ReportLocationStatus(callback_, SESSION_START);
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::StopLocator()
|
||||
{
|
||||
std::lock_guard lock(locatorMutex_);
|
||||
if (!isLocating_) {
|
||||
return;
|
||||
}
|
||||
DelayedSingleton<LocatorAbility>::GetInstance().get()->StopLocating(callback_);
|
||||
isLocating_ = false;
|
||||
LBSLOGI(LOCATOR_BACKGROUND_PROXY, "end locating");
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::StartLocator()
|
||||
{
|
||||
std::lock_guard lock(locatorMutex_);
|
||||
if (isLocating_ || !proxySwtich_ || isWating_) {
|
||||
return;
|
||||
}
|
||||
isWating_ = true;
|
||||
LBSLOGI(LOCATOR_BACKGROUND_PROXY, "start locating");
|
||||
std::thread th(&LocatorBackgroundProxy::StartLocatorThread, this);
|
||||
th.detach();
|
||||
}
|
||||
|
||||
// called when the app freezes or wakes up
|
||||
// When the app enters frozen state, start proxy
|
||||
// when the app wakes up, stop proxy
|
||||
void LocatorBackgroundProxy::OnSuspend(const std::shared_ptr<Request>& request, bool active)
|
||||
{
|
||||
if (!featureSwitch_) {
|
||||
return;
|
||||
}
|
||||
if (!isSubscribed_) {
|
||||
isSubscribed_ = LocatorBackgroundProxy::UserSwitchSubscriber::Subscribe();
|
||||
}
|
||||
UpdateListOnSuspend(request, active);
|
||||
if (requestsList_->empty()) {
|
||||
StopLocator();
|
||||
} else {
|
||||
StartLocator();
|
||||
}
|
||||
}
|
||||
|
||||
// called when the app’s background location permission is cancelled, stop proxy
|
||||
void LocatorBackgroundProxy::OnPermissionChanged(int32_t uid)
|
||||
{
|
||||
if (!featureSwitch_) {
|
||||
return;
|
||||
}
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "OnPermissionChanged %{public}d", uid);
|
||||
UpdateListOnPermissionChanged(uid);
|
||||
if (requestsList_->empty()) {
|
||||
StopLocator();
|
||||
}
|
||||
}
|
||||
|
||||
// called when provider switch on or switch off
|
||||
// when switch on, start proxy
|
||||
// when switch off, stop proxy
|
||||
void LocatorBackgroundProxy::OnProviderSwitch(bool enable)
|
||||
{
|
||||
if (proxySwtich_ == enable || !featureSwitch_) {
|
||||
return;
|
||||
}
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "onProviderswitch %{public}d", enable);
|
||||
proxySwtich_ = enable;
|
||||
if (enable && !requestsList_->empty()) {
|
||||
StartLocator();
|
||||
} else {
|
||||
StopLocator();
|
||||
}
|
||||
}
|
||||
|
||||
// called when deleteRequest called from locator ability (e.g. app stop locating)
|
||||
void LocatorBackgroundProxy::OnDeleteRequestRecord(const std::shared_ptr<Request>& request)
|
||||
{
|
||||
if (!featureSwitch_) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard lock(requestListMutex_);
|
||||
auto it = find(requestsList_->begin(), requestsList_->end(), request);
|
||||
if (it != requestsList_->end()) {
|
||||
requestsList_->remove(request);
|
||||
if (requestsList_->empty()) {
|
||||
StopLocator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LocatorBackgroundProxy::CheckPermission(const std::shared_ptr<Request>& request) const
|
||||
{
|
||||
pid_t pid = request->GetPid();
|
||||
pid_t uid = request->GetUid();
|
||||
return (CommonUtils::CheckLocationPermission(pid, uid) && CommonUtils::CheckBackgroundPermission(pid, uid));
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::UpdateListOnPermissionChanged(int32_t uid)
|
||||
{
|
||||
std::lock_guard lock(requestListMutex_);
|
||||
pid_t uid1 = uid;
|
||||
auto userId = GetUserId(uid);
|
||||
auto iter = requestsMap_->find(userId);
|
||||
if (iter == requestsMap_->end()) {
|
||||
return;
|
||||
}
|
||||
auto requestsList = iter->second;
|
||||
for (auto request = requestsList->begin(); request != requestsList->end(); ) {
|
||||
if ((uid1 == (*request)->GetUid()) && !CheckPermission(*request)) {
|
||||
request = requestsList->erase(request);
|
||||
} else {
|
||||
request++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::UpdateListOnSuspend(const std::shared_ptr<Request>& request, bool active)
|
||||
{
|
||||
std::lock_guard lock(requestListMutex_);
|
||||
auto userId = GetUserId(request->GetUid());
|
||||
auto iter = requestsMap_->find(userId);
|
||||
if (iter == requestsMap_->end()) {
|
||||
return;
|
||||
}
|
||||
auto requestsList = iter->second;
|
||||
auto it = find(requestsList->begin(), requestsList->end(), request);
|
||||
if (it != requestsList->end()) {
|
||||
if (active || !CheckPermission(request)) {
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "remove request:%{public}s from User:%{public}d",
|
||||
request->ToString().c_str(), userId);
|
||||
requestsList->remove(request);
|
||||
}
|
||||
} else {
|
||||
if (!active && CheckPermission(request) && request->GetRequestConfig()->GetFixNumber() == 0
|
||||
&& CheckMaxRequestNum(request->GetUid(), request->GetPackageName())) {
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "add request:%{public}s from User:%{public}d",
|
||||
request->ToString().c_str(), userId);
|
||||
requestsList->push_back(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::UpdateListOnUserSwitch(int32_t userId)
|
||||
{
|
||||
std::lock_guard lock(requestListMutex_);
|
||||
auto iter = requestsMap_->find(userId);
|
||||
if (iter == requestsMap_->end()) {
|
||||
auto mRequestsList = std::make_shared<std::list<std::shared_ptr<Request>>>();
|
||||
requestsMap_->insert(make_pair(userId, mRequestsList));
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "add requsetlist on user:%{public}d", userId);
|
||||
}
|
||||
// if change to another user, proxy requestList should change
|
||||
requestsList_ = (*requestsMap_)[userId];
|
||||
curUserId_ = userId;
|
||||
}
|
||||
|
||||
|
||||
const std::list<std::shared_ptr<Request>>& LocatorBackgroundProxy::GetRequestsInProxy() const
|
||||
{
|
||||
return *requestsList_;
|
||||
}
|
||||
|
||||
// called in LocatorCallbackProxy::OnLocationReport
|
||||
// check if callback is from proxy
|
||||
bool LocatorBackgroundProxy::IsCallbackInProxy(const sptr<ILocatorCallback>& callback) const
|
||||
{
|
||||
if (!featureSwitch_) {
|
||||
return false;
|
||||
}
|
||||
for (auto request : *requestsList_) {
|
||||
if (request->GetLocatorCallBack() == callback) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t LocatorBackgroundProxy::GetUserId(int32_t uid) const
|
||||
{
|
||||
return uid / PER_USER_RANGE;
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::OnUserSwitch(int32_t userId)
|
||||
{
|
||||
UpdateListOnUserSwitch(userId);
|
||||
if (!requestsList_->empty()) {
|
||||
StartLocator();
|
||||
} else {
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "OnUserSwitch stoplocator");
|
||||
StopLocator();
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::OnUserRemove(int32_t userId)
|
||||
{
|
||||
// if user is removed, remove the requestList from the user in requestsMap
|
||||
std::lock_guard lock(requestListMutex_);
|
||||
auto iter = requestsMap_->find(userId);
|
||||
if (iter != requestsMap_->end()) {
|
||||
requestsMap_->erase(iter);
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "erase requsetlist on user:%{public}d", userId);
|
||||
}
|
||||
}
|
||||
|
||||
// limit the number of requests per app
|
||||
bool LocatorBackgroundProxy::CheckMaxRequestNum(pid_t uid, const std::string& packageName) const
|
||||
{
|
||||
int32_t num = 0;
|
||||
auto iter = requestsMap_->find(GetUserId(uid));
|
||||
if (iter == requestsMap_->end()) {
|
||||
return false;
|
||||
}
|
||||
for (auto request : *(iter->second)) {
|
||||
if (request->GetUid() == uid && packageName.compare(request->GetPackageName()) == 0) {
|
||||
if (++num >= REQUESTS_NUM_MAX) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::mLocatorCallback::OnLocationReport(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "locator background OnLocationReport");
|
||||
auto locatorProxy = DelayedSingleton<LocatorBackgroundProxy>::GetInstance().get();
|
||||
auto requestsList = locatorProxy->GetRequestsInProxy();
|
||||
if (requestsList.empty()) {
|
||||
locatorProxy->StopLocator();
|
||||
return;
|
||||
}
|
||||
// call the callback of each proxy app
|
||||
for (auto request : requestsList) {
|
||||
request->GetLocatorCallBack()->OnLocationReport(location);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::mLocatorCallback::OnLocatingStatusChange(const int status)
|
||||
{
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::mLocatorCallback::OnErrorReport(const int errorCode)
|
||||
{
|
||||
}
|
||||
|
||||
LocatorBackgroundProxy::UserSwitchSubscriber::UserSwitchSubscriber(
|
||||
const OHOS::EventFwk::CommonEventSubscribeInfo &info)
|
||||
: CommonEventSubscriber(info)
|
||||
{
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "create UserSwitchEventSubscriber");
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::UserSwitchSubscriber::OnReceiveEvent(const OHOS::EventFwk::CommonEventData& event)
|
||||
{
|
||||
int32_t userId = UNKNOW_USER_ID;
|
||||
const auto action = event.GetWant().GetAction();
|
||||
auto locatorProxy = DelayedSingleton<LocatorBackgroundProxy>::GetInstance().get();
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "action = %{public}s, userId = %{public}d", action.c_str(), userId);
|
||||
if (action == OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
|
||||
locatorProxy->OnUserSwitch(userId);
|
||||
} else if (action == OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) {
|
||||
locatorProxy->OnUserRemove(userId);
|
||||
}
|
||||
}
|
||||
|
||||
bool LocatorBackgroundProxy::UserSwitchSubscriber::Subscribe()
|
||||
{
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "subscribe common event");
|
||||
OHOS::EventFwk::MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
|
||||
OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
std::shared_ptr<UserSwitchSubscriber> subscriber = std::make_shared<UserSwitchSubscriber>(subscriberInfo);
|
||||
if (subscriber == nullptr) {
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "subscriber is null.");
|
||||
return false;
|
||||
}
|
||||
bool result = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
|
||||
if (result) {
|
||||
} else {
|
||||
LBSLOGE(LOCATOR_BACKGROUND_PROXY, "Subscribe service event error.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace OHOS
|
||||
} // namespace Location
|
||||
|
148
location_locator/locator/source/locator_event_manager.cpp
Normal file
148
location_locator/locator/source/locator_event_manager.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "locator_event_manager.h"
|
||||
|
||||
#include "hisysevent.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "constant_definition.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
void DftEvent::PutInt(const std::string& name, int value)
|
||||
{
|
||||
intValues_.emplace(name, value);
|
||||
}
|
||||
|
||||
int DftEvent::GetInt(const std::string& name)
|
||||
{
|
||||
auto it = intValues_.find(name);
|
||||
if (it == intValues_.end()) {
|
||||
return 0;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
DftHandler::DftHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner) : EventHandler(runner) {}
|
||||
|
||||
DftHandler::~DftHandler() {}
|
||||
|
||||
void DftHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
|
||||
{
|
||||
}
|
||||
|
||||
LocatorDftManager::LocatorDftManager()
|
||||
{
|
||||
distributeSissionCnt_ = 0;
|
||||
distributeDisconnectCnt_ = 0;
|
||||
|
||||
handler_ = std::make_shared<DftHandler>(AppExecFwk::EventRunner::Create(true));
|
||||
}
|
||||
|
||||
LocatorDftManager::~LocatorDftManager() {}
|
||||
|
||||
void LocatorDftManager::Init()
|
||||
{
|
||||
if (handler_ != nullptr) {
|
||||
handler_->SendHighPriorityEvent(EVENT_SEND_DAILY_REPORT, 0, DAILY_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorDftManager::IpcCallingErr(int error)
|
||||
{
|
||||
}
|
||||
|
||||
void LocatorDftManager::LocationSessionStart(std::shared_ptr<Request> request)
|
||||
{
|
||||
std::shared_ptr<AppRequestCount> requestCount = nullptr;
|
||||
for (auto appRequest : appRequests_) {
|
||||
if (appRequest->packageName.compare(request->GetPackageName()) == 0) {
|
||||
requestCount = appRequest;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (requestCount == nullptr) {
|
||||
requestCount = std::make_shared<AppRequestCount>();
|
||||
requestCount->packageName = request->GetPackageName();
|
||||
requestCount->requestType = std::vector<int>(DFT_APP_MAX_SIZE);
|
||||
requestCount->count = std::vector<int>(DFT_APP_MAX_SIZE);
|
||||
appRequests_.push_back(requestCount);
|
||||
}
|
||||
|
||||
unsigned index = INVALID_VALUE;
|
||||
int scenario = request->GetRequestConfig()->GetScenario();
|
||||
int priority = request->GetRequestConfig()->GetPriority();
|
||||
for (unsigned i = 0; i < requestCount->requestType.size(); i++) {
|
||||
if (requestCount->requestType.at(i) == scenario || requestCount->requestType.at(i) == priority) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index != INVALID_VALUE) {
|
||||
requestCount->count.at(index)++;
|
||||
} else {
|
||||
if (scenario != SCENE_UNSET) {
|
||||
requestCount->requestType.at(0) = scenario;
|
||||
} else if (priority != PRIORITY_UNSET) {
|
||||
requestCount->requestType.at(0) = priority;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
requestCount->count.at(0)++;
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorDftManager::DistributionDisconnect()
|
||||
{
|
||||
if (distributeDisconnectCnt_ < COUNT_MAX) {
|
||||
distributeDisconnectCnt_++;
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorDftManager::DistributionSessionStart()
|
||||
{
|
||||
if (distributeSissionCnt_ < COUNT_MAX) {
|
||||
distributeSissionCnt_++;
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorDftManager::SendDistributionDailyCount()
|
||||
{
|
||||
}
|
||||
|
||||
void LocatorDftManager::SendRequestDailyCount()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<AppRequestCount> LocatorDftManager::GetTopRequest()
|
||||
{
|
||||
std::shared_ptr<AppRequestCount> topRequest;
|
||||
int topSum = 0;
|
||||
for (auto appRequest : appRequests_) {
|
||||
int sum = 0;
|
||||
for (unsigned i = 0; i < appRequest->count.size(); i++) {
|
||||
sum = sum + appRequest->count.at(i);
|
||||
}
|
||||
if (sum > topSum) {
|
||||
topSum = sum;
|
||||
topRequest = appRequest;
|
||||
}
|
||||
}
|
||||
return topRequest;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
43
location_locator/locator/source/locator_event_subscriber.cpp
Normal file
43
location_locator/locator/source/locator_event_subscriber.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "locator_event_subscriber.h"
|
||||
|
||||
#include "ipc_skeleton.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "lbs_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
LocatorEventSubscriber::LocatorEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &info)
|
||||
: CommonEventSubscriber(info) {}
|
||||
|
||||
LocatorEventSubscriber::~LocatorEventSubscriber() {}
|
||||
|
||||
void LocatorEventSubscriber::OnReceiveEvent(const OHOS::EventFwk::CommonEventData& event)
|
||||
{
|
||||
proxyLocator_ = std::make_unique<LocatorProxy>(CommonUtils::GetRemoteObject(LOCATION_LOCATOR_SA_ID,
|
||||
CommonUtils::InitDeviceId()));
|
||||
|
||||
std::string action = event.GetWant().GetAction();
|
||||
LBSLOGI(LOCATOR_EVENT, "received action = %{public}s", action.c_str());
|
||||
if (MODE_CHANGED_EVENT.compare(action) == 0 && proxyLocator_ != nullptr) {
|
||||
proxyLocator_->UpdateSaAbility();
|
||||
}
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
328
location_locator/locator/source/locator_skeleton.cpp
Normal file
328
location_locator/locator/source/locator_skeleton.cpp
Normal file
@ -0,0 +1,328 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "locator_skeleton.h"
|
||||
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_types.h"
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "locator_ability.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
void LocatorAbilityStub::ParseDataAndStartLocating(MessageParcel& data, MessageParcel& reply, pid_t pid, pid_t uid)
|
||||
{
|
||||
std::unique_ptr<RequestConfig> requestConfig = RequestConfig::Unmarshalling(data);
|
||||
sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
|
||||
std::string bundleName = Str16ToStr8(data.ReadString16());
|
||||
if (remoteObject == nullptr) {
|
||||
LBSLOGE(LOCATOR, "StartLocating remote object nullptr");
|
||||
return;
|
||||
}
|
||||
if (bundleName.empty()) {
|
||||
LBSLOGE(LOCATOR, "StartLocating get empty bundle name");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject::DeathRecipient> death(new LocatorCallbackDeathRecipient());
|
||||
remoteObject->AddDeathRecipient(death.GetRefPtr());
|
||||
sptr<ILocatorCallback> callback = iface_cast<ILocatorCallback>(remoteObject);
|
||||
StartLocating(requestConfig, callback, bundleName, pid, uid);
|
||||
}
|
||||
|
||||
void LocatorAbilityStub::ParseDataAndStopLocating(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
|
||||
if (remoteObject == nullptr) {
|
||||
LBSLOGE(LOCATOR, "LocatorAbility::StartLocating remote object nullptr");
|
||||
return;
|
||||
}
|
||||
sptr<ILocatorCallback> callback = iface_cast<ILocatorCallback>(remoteObject);
|
||||
StopLocating(callback);
|
||||
}
|
||||
|
||||
int LocatorAbilityStub::ReportStatus(MessageParcel& data, int type)
|
||||
{
|
||||
sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
|
||||
if (remoteObject == nullptr) {
|
||||
LBSLOGE(LOCATOR, "LocatorAbility::StartLocating remote object nullptr");
|
||||
return EXCEPTION;
|
||||
}
|
||||
sptr<ILocatorCallback> callback = iface_cast<ILocatorCallback>(remoteObject);
|
||||
int result = data.ReadInt32();
|
||||
switch (type) {
|
||||
case REPORT_LOCATION_STATUS: {
|
||||
ReportLocationStatus(callback, result);
|
||||
break;
|
||||
}
|
||||
case REPORT_ERROR_STATUS: {
|
||||
ReportErrorStatus(callback, result);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return REPLY_NO_EXCEPTION;
|
||||
}
|
||||
|
||||
void LocatorAbilityStub::ParseDataAndStartCacheLocating(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
std::unique_ptr<CachedGnssLoactionsRequest> requestConfig = std::make_unique<CachedGnssLoactionsRequest>();
|
||||
requestConfig->reportingPeriodSec = data.ReadInt32();
|
||||
requestConfig->wakeUpCacheQueueFull = data.ReadBool();
|
||||
sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
|
||||
std::string bundleName = Str16ToStr8(data.ReadString16());
|
||||
if (remoteObject == nullptr) {
|
||||
LBSLOGE(LOCATOR, "ParseDataAndStartCacheLocating remote object nullptr");
|
||||
return;
|
||||
}
|
||||
if (bundleName.empty()) {
|
||||
LBSLOGE(LOCATOR, "ParseDataAndStartCacheLocating get empty bundle name");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<ICachedLocationsCallback> callback = iface_cast<ICachedLocationsCallback>(remoteObject);
|
||||
RegisterCachedLocationCallback(requestConfig, callback, bundleName);
|
||||
}
|
||||
|
||||
void LocatorAbilityStub::ParseDataAndStopCacheLocating(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
|
||||
if (remoteObject == nullptr) {
|
||||
LBSLOGE(LOCATOR, "LocatorAbility::ParseDataAndStopCacheLocating remote object nullptr");
|
||||
return;
|
||||
}
|
||||
sptr<ICachedLocationsCallback> callback = iface_cast<ICachedLocationsCallback>(remoteObject);
|
||||
UnregisterCachedLocationCallback(callback);
|
||||
}
|
||||
|
||||
int LocatorAbilityStub::OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
pid_t callingPid = IPCSkeleton::GetCallingPid();
|
||||
pid_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
IPCSkeleton::ResetCallingIdentity();
|
||||
LBSLOGI(LOCATOR, "OnReceived cmd = %{public}u, flags= %{public}d, pid= %{public}d, uid= %{public}d",
|
||||
code, option.GetFlags(), callingPid, callingUid);
|
||||
|
||||
int ret = REPLY_NO_EXCEPTION;
|
||||
|
||||
switch (code) {
|
||||
case GET_SWITCH_STATE: {
|
||||
reply.WriteInt32(GetSwitchState());
|
||||
break;
|
||||
}
|
||||
case REG_SWITCH_CALLBACK: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
RegisterSwitchCallback(client, callingUid);
|
||||
break;
|
||||
}
|
||||
case UNREG_SWITCH_CALLBACK: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
UnregisterSwitchCallback(client);
|
||||
break;
|
||||
}
|
||||
case REG_GNSS_STATUS_CALLBACK: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
RegisterGnssStatusCallback(client, callingUid);
|
||||
break;
|
||||
}
|
||||
case UNREG_GNSS_STATUS_CALLBACK: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
UnregisterGnssStatusCallback(client);
|
||||
break;
|
||||
}
|
||||
case REG_NMEA_CALLBACK: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
RegisterNmeaMessageCallback(client, callingUid);
|
||||
break;
|
||||
}
|
||||
case UNREG_NMEA_CALLBACK: {
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
UnregisterNmeaMessageCallback(client);
|
||||
break;
|
||||
}
|
||||
case START_LOCATING: {
|
||||
ParseDataAndStartLocating(data, reply, callingPid, callingUid);
|
||||
break;
|
||||
}
|
||||
case STOP_LOCATING: {
|
||||
ParseDataAndStopLocating(data, reply);
|
||||
break;
|
||||
}
|
||||
case REPORT_LOCATION: {
|
||||
if (!CommonUtils::CheckSystemCalling(callingUid)) {
|
||||
ret = SECURITY_EXCEPTION;
|
||||
break;
|
||||
}
|
||||
std::string abilityName = data.ReadString();
|
||||
std::unique_ptr<Location> location = Location::Unmarshalling(data);
|
||||
ReportLocation(location, abilityName);
|
||||
break;
|
||||
}
|
||||
case GET_CACHE_LOCATION: {
|
||||
if (!CommonUtils::CheckLocationPermission(callingPid, callingUid)) {
|
||||
LBSLOGI(LOCATOR, "pid:%{public}d uid:%{public}d has no access permission to get cache location",
|
||||
callingPid, callingUid);
|
||||
reply.WriteInt32(SECURITY_EXCEPTION);
|
||||
reply.WriteString("should grant location permission");
|
||||
ret = SECURITY_EXCEPTION;
|
||||
break;
|
||||
}
|
||||
ret = GetCacheLocation(data, reply);
|
||||
break;
|
||||
}
|
||||
case REPORT_LOCATION_STATUS: {
|
||||
if (!CommonUtils::CheckSystemCalling(callingUid)) {
|
||||
ret = SECURITY_EXCEPTION;
|
||||
break;
|
||||
}
|
||||
ReportStatus(data, REPORT_LOCATION_STATUS);
|
||||
break;
|
||||
}
|
||||
case REPORT_ERROR_STATUS: {
|
||||
if (!CommonUtils::CheckSystemCalling(callingUid)) {
|
||||
ret = SECURITY_EXCEPTION;
|
||||
break;
|
||||
}
|
||||
ReportStatus(data, REPORT_ERROR_STATUS);
|
||||
break;
|
||||
}
|
||||
case ENABLE_ABILITY: {
|
||||
if (!CommonUtils::CheckSystemCalling(callingUid) &&
|
||||
!CommonUtils::CheckSecureSettings(callingPid, callingUid)) {
|
||||
ret = SECURITY_EXCEPTION;
|
||||
break;
|
||||
}
|
||||
bool isEnabled = data.ReadBool();
|
||||
EnableAbility(isEnabled);
|
||||
break;
|
||||
}
|
||||
case UPDATE_SA_ABILITY: {
|
||||
if (!CommonUtils::CheckSystemCalling(callingUid)) {
|
||||
ret = SECURITY_EXCEPTION;
|
||||
break;
|
||||
}
|
||||
UpdateSaAbility();
|
||||
break;
|
||||
}
|
||||
case GEO_IS_AVAILABLE: {
|
||||
ret = IsGeoConvertAvailable(data, reply);
|
||||
break;
|
||||
}
|
||||
case GET_FROM_COORDINATE: {
|
||||
ret = GetAddressByCoordinate(data, reply);
|
||||
break;
|
||||
}
|
||||
case GET_FROM_LOCATION_NAME: {
|
||||
ret = GetAddressByLocationName(data, reply);
|
||||
break;
|
||||
}
|
||||
case IS_PRIVACY_COMFIRMED: {
|
||||
reply.WriteInt32(IsLocationPrivacyConfirmed(CommonUtils::GetPrivacyTypeByInt(data.ReadInt32())));
|
||||
break;
|
||||
}
|
||||
case SET_PRIVACY_COMFIRM_STATUS: {
|
||||
SetLocationPrivacyConfirmStatus(CommonUtils::GetPrivacyTypeByInt(data.ReadInt32()), data.ReadBool());
|
||||
break;
|
||||
}
|
||||
case REG_CACHED_CALLBACK: {
|
||||
ParseDataAndStartCacheLocating(data, reply);
|
||||
break;
|
||||
}
|
||||
case UNREG_CACHED_CALLBACK: {
|
||||
ParseDataAndStopCacheLocating(data, reply);
|
||||
break;
|
||||
}
|
||||
case GET_CACHED_LOCATION_SIZE: {
|
||||
reply.WriteInt32(GetCachedGnssLocationsSize());
|
||||
break;
|
||||
}
|
||||
case FLUSH_CACHED_LOCATIONS: {
|
||||
FlushCachedGnssLocations();
|
||||
break;
|
||||
}
|
||||
case SEND_COMMAND: {
|
||||
std::unique_ptr<LocationCommand> locationCommand = std::make_unique<LocationCommand>();
|
||||
locationCommand->scenario = data.ReadInt32();
|
||||
locationCommand->command = data.ReadBool();
|
||||
SendCommand(locationCommand);
|
||||
break;
|
||||
}
|
||||
case ADD_FENCE: {
|
||||
std::unique_ptr<GeofenceRequest> request = std::make_unique<GeofenceRequest>();
|
||||
request->priority = data.ReadInt32();
|
||||
request->scenario = data.ReadInt32();
|
||||
request->geofence.latitude = data.ReadDouble();
|
||||
request->geofence.longitude = data.ReadDouble();
|
||||
request->geofence.radius = data.ReadDouble();
|
||||
request->geofence.expiration = data.ReadDouble();
|
||||
AddFence(request);
|
||||
break;
|
||||
}
|
||||
case REMOVE_FENCE: {
|
||||
std::unique_ptr<GeofenceRequest> request = std::make_unique<GeofenceRequest>();
|
||||
request->priority = data.ReadInt32();
|
||||
request->scenario = data.ReadInt32();
|
||||
request->geofence.latitude = data.ReadDouble();
|
||||
request->geofence.longitude = data.ReadDouble();
|
||||
request->geofence.radius = data.ReadDouble();
|
||||
request->geofence.expiration = data.ReadDouble();
|
||||
RemoveFence(request);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LocatorCallbackDeathRecipient::LocatorCallbackDeathRecipient()
|
||||
{
|
||||
}
|
||||
|
||||
LocatorCallbackDeathRecipient::~LocatorCallbackDeathRecipient()
|
||||
{
|
||||
}
|
||||
|
||||
void LocatorCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
sptr<ILocatorCallback> callback = iface_cast<ILocatorCallback>(remote.promote());
|
||||
sptr<LocatorAbility> locatorAbility = DelayedSingleton<LocatorAbility>::GetInstance().get();
|
||||
if (locatorAbility != nullptr) {
|
||||
locatorAbility->StopLocating(callback);
|
||||
LBSLOGI(LOCATOR, "locator callback OnRemoteDied");
|
||||
}
|
||||
}
|
||||
|
||||
SwitchCallbackDeathRecipient::SwitchCallbackDeathRecipient()
|
||||
{
|
||||
}
|
||||
|
||||
SwitchCallbackDeathRecipient::~SwitchCallbackDeathRecipient()
|
||||
{
|
||||
}
|
||||
|
||||
void SwitchCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
sptr<LocatorAbility> locatorAbility = DelayedSingleton<LocatorAbility>::GetInstance().get();
|
||||
if (locatorAbility != nullptr) {
|
||||
locatorAbility->UnregisterSwitchCallback(remote.promote());
|
||||
LBSLOGI(LOCATOR, "switch callback OnRemoteDied");
|
||||
}
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user