mirror of
https://gitee.com/openharmony/base_location
synced 2024-11-27 00:51:30 +00:00
wifimac
Signed-off-by: 李文龙 <liwenlong22@huawei.com>
This commit is contained in:
parent
5c1c2767a8
commit
1188496d54
@ -59,6 +59,7 @@ napi_value GetGeofenceSupportedCoordTypes(napi_env env, napi_callback_info info)
|
||||
void AddCallbackToGnssGeofenceCallbackHostMap(int fenceId, sptr<LocationGnssGeofenceCallbackNapi> callbackHost);
|
||||
void RemoveCallbackToGnssGeofenceCallbackHostMap(int fenceId);
|
||||
sptr<LocationGnssGeofenceCallbackNapi> FindCallbackInGnssGeofenceCallbackHostMap(int fenceId);
|
||||
napi_value GetCurrentWifiBssidForLocating(napi_env env, napi_callback_info info);
|
||||
#endif
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
@ -129,6 +129,27 @@ napi_value IsLocationEnabled(napi_env env, napi_callback_info info)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_NAPI_MANAGER
|
||||
napi_value GetCurrentWifiBssidForLocating(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAXIMUM_JS_PARAMS;
|
||||
napi_value argv[MAXIMUM_JS_PARAMS];
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, g_locatorClient != nullptr, "get locator SA failed");
|
||||
napi_value res;
|
||||
std::string bssid;
|
||||
LocationErrCode errorCode = g_locatorClient->GetCurrentWifiBssidForLocating(bssid);
|
||||
if (errorCode != ERRCODE_SUCCESS) {
|
||||
HandleSyncErrCode(env, errorCode);
|
||||
return UndefinedNapiValue(env);
|
||||
}
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, bssid.c_str(), NAPI_AUTO_LENGTH, &res));
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
napi_value EnableLocation(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LBSLOGI(LOCATOR_STANDARD, "%{public}s called.", __func__);
|
||||
|
@ -1300,6 +1300,21 @@ LocationErrCode LocatorImpl::UnSubscribeLocationError(sptr<ILocatorCallback>& ca
|
||||
return errCode;
|
||||
}
|
||||
|
||||
LocationErrCode LocatorImpl::GetCurrentWifiBssidForLocating(std::string& bssid)
|
||||
{
|
||||
if (!SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID)) {
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
LBSLOGD(LOCATOR_STANDARD, "LocatorImpl::GetCurrentWifiBssidForLocating()");
|
||||
sptr<LocatorProxy> proxy = GetProxy();
|
||||
if (proxy == nullptr) {
|
||||
LBSLOGE(LOCATOR_STANDARD, "%{public}s get proxy failed.", __func__);
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
LocationErrCode errCode = proxy->GetCurrentWifiBssidForLocating(bssid);
|
||||
return errCode;
|
||||
}
|
||||
|
||||
void LocatorImpl::ResetLocatorProxy(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
if (remote == nullptr) {
|
||||
|
@ -979,5 +979,17 @@ LocationErrCode LocatorProxy::UnSubscribeLocationError(sptr<ILocatorCallback>& c
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::StopLocatingV9 Transact ErrCodes = %{public}d", errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
LocationErrCode LocatorProxy::GetCurrentWifiBssidForLocating(std::string& bssid)
|
||||
{
|
||||
MessageParcel reply;
|
||||
LocationErrCode errorCode =
|
||||
SendMsgWithReplyV9(static_cast<int>(LocatorInterfaceCode::GET_CURRENT_WIFI_BSSID_FOR_LOCATING), reply);
|
||||
if (errorCode == ERRCODE_SUCCESS) {
|
||||
bssid = Str16ToStr8(reply.ReadString16());
|
||||
}
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::GetCurrentWifiBssidForLocating Transact ErrCodes = %{public}d", errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
@ -70,7 +70,8 @@ enum class LocatorInterfaceCode {
|
||||
REG_LOCATION_ERROR = 48,
|
||||
UNREG_LOCATION_ERROR = 49,
|
||||
REPORT_LOCATION_ERROR = 50,
|
||||
ENABLE_ABILITY_BY_USERID = 51
|
||||
ENABLE_ABILITY_BY_USERID = 51,
|
||||
GET_CURRENT_WIFI_BSSID_FOR_LOCATING = 52
|
||||
};
|
||||
|
||||
enum class GeoConvertInterfaceCode {
|
||||
|
@ -613,6 +613,15 @@ public:
|
||||
* @return Returns ERRCODE_SUCCESS if Unsubscribe error changed succeed.
|
||||
*/
|
||||
LocationErrCode UnSubscribeLocationError(sptr<ILocatorCallback>& callback);
|
||||
|
||||
/**
|
||||
* @brief Obtain last known location.
|
||||
*
|
||||
* @param loc Indicates the last known location information.
|
||||
* @return Returns ERRCODE_SUCCESS if obtain last known location succeed.
|
||||
*/
|
||||
LocationErrCode GetCurrentWifiBssidForLocating(std::string& bssid);
|
||||
|
||||
void ResetLocatorProxy(const wptr<IRemoteObject> &remote);
|
||||
sptr<LocatorProxy> GetProxy();
|
||||
bool IsLocationCallbackRegistered(const sptr<ILocatorCallback>& callback);
|
||||
|
@ -123,6 +123,7 @@ public:
|
||||
LocationErrCode UnRegisterLocatingRequiredDataCallback(sptr<ILocatingRequiredDataCallback>& callback);
|
||||
LocationErrCode SubscribeLocationError(sptr<ILocatorCallback>& callback);
|
||||
LocationErrCode UnSubscribeLocationError(sptr<ILocatorCallback>& callback);
|
||||
LocationErrCode GetCurrentWifiBssidForLocating(std::string& bssid);
|
||||
private:
|
||||
|
||||
static inline BrokerDelegator<LocatorProxy> delegator_;
|
||||
|
@ -207,6 +207,7 @@ public:
|
||||
int64_t GetWifiScanCompleteTimestamp();
|
||||
int64_t GetlastStillTime();
|
||||
bool IsStill();
|
||||
LocationErrCode GetCurrentWifiBssidForLocating(std::string& bssid);
|
||||
|
||||
private:
|
||||
int timeInterval_ = 0;
|
||||
|
@ -101,6 +101,7 @@ private:
|
||||
int PreRegisterLocationError(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
|
||||
int PreUnregisterLocationError(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
|
||||
int PreReportLocationError(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
|
||||
int PreGetCurrentWifiBssidForLocating(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
|
||||
|
||||
private:
|
||||
LocatorMsgHandleMap locatorHandleMap_;
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "location_log.h"
|
||||
#ifdef WIFI_ENABLE
|
||||
#include "wifi_errcode.h"
|
||||
#include "wifi_device.h"
|
||||
#endif
|
||||
#include "iservice_registry.h"
|
||||
#include "common_utils.h"
|
||||
@ -360,6 +361,28 @@ bool LocatorRequiredDataManager::IsConnecting()
|
||||
return false;
|
||||
}
|
||||
|
||||
LocationErrCode LocatorRequiredDataManager::GetCurrentWifiBssidForLocating(std::string& bssid)
|
||||
{
|
||||
#ifdef WIFI_ENABLE
|
||||
auto wifiDeviceSharedPtr = Wifi::WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
|
||||
Wifi::WifiDevice* wifiDevicePtr = wifiDeviceSharedPtr.get();
|
||||
if (wifiDevicePtr == nullptr) {
|
||||
LBSLOGE(LOCATOR, "Enter WifiEnhanceNewUtils:: wifiDevicePtr is null");
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
OHOS::Wifi::WifiLinkedInfo linkedInfo;
|
||||
ErrCode ret = wifiDevicePtr->GetLinkedInfo(linkedInfo);
|
||||
if (ret != Wifi::WIFI_OPT_SUCCESS) {
|
||||
LBSLOGE(LOCATOR, "Enter WifiEnhanceNewUtils::GetLinkedInfo fail: %{public}d", ret);
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
bssid = linkedInfo.bssid;
|
||||
return ERRCODE_SUCCESS;
|
||||
#else
|
||||
return ERRCODE_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
ScanHandler::ScanHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner) : EventHandler(runner) {}
|
||||
|
||||
ScanHandler::~ScanHandler() {}
|
||||
|
@ -1172,6 +1172,20 @@ int LocatorAbilityStub::PreReportLocationError(MessageParcel &data, MessageParce
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
int LocatorAbilityStub::PreGetCurrentWifiBssidForLocating(
|
||||
MessageParcel &data, MessageParcel &reply, AppIdentity &identity)
|
||||
{
|
||||
if (!CheckLocationPermission(reply, identity)) {
|
||||
return ERRCODE_PERMISSION_DENIED;
|
||||
}
|
||||
auto locatorDataManager = LocatorRequiredDataManager::GetInstance();
|
||||
std::string bssid;
|
||||
LocationErrCode errorCode = locatorDataManager->GetCurrentWifiBssidForLocating(bssid);
|
||||
reply.WriteInt32(errorCode);
|
||||
reply.WriteString16(Str8ToStr16(bssid));
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool LocatorAbilityStub::IsStopAction(uint32_t code)
|
||||
{
|
||||
if (code == static_cast<uint32_t>(LocatorInterfaceCode::UNREG_SWITCH_CALLBACK) ||
|
||||
|
@ -690,5 +690,20 @@ HWTEST_F(LocatorImplTest, locatorImplEnableAbilityForUser, TestSize.Level1)
|
||||
EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->EnableAbilityForUser(true, DEFAULT_USER));
|
||||
LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplEnableAbilityForUser end");
|
||||
}
|
||||
|
||||
HWTEST_F(LocatorImplTest, GetCurrentWifiBssidForLocating, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO)
|
||||
<< "LocatorImplTest, GetCurrentWifiBssidForLocating, TestSize.Level1";
|
||||
LBSLOGI(LOCATOR, "[LocatorImplTest] GetCurrentWifiBssidForLocating begin");
|
||||
std::string bssid;
|
||||
auto errCode = locatorImpl_->GetCurrentWifiBssidForLocating(bssid);
|
||||
if (errCode == ERRCODE_SUCCESS) {
|
||||
EXPECT_NE(0, bssid.size());
|
||||
} else {
|
||||
EXPECT_EQ(0, bssid.size());
|
||||
}
|
||||
LBSLOGI(LOCATOR, "[LocatorImplTest] GetCurrentWifiBssidForLocating end");
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user