Files
base_location/frameworks/native/source/location_data_rdb_observer.cpp
T
z30025928 92e1cd34de 检视意见修改
Signed-off-by: z30025928 <734222381@qq.com>
2023-05-05 19:53:25 +08:00

52 lines
1.7 KiB
C++

/*
* Copyright (c) 2023 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_data_rdb_observer.h"
#include "common_utils.h"
#include "location_data_rdb_helper.h"
#include "location_log.h"
namespace OHOS {
namespace Location {
using namespace AppExecFwk;
const uint32_t SWITCH_STATE_CHANGED = 1;
LocationDataRdbObserver::LocationDataRdbObserver()
{
locationDataHandler_ =
std::make_shared<LocationDataHandler>(AppExecFwk::EventRunner::Create(true));
}
LocationDataRdbObserver::~LocationDataRdbObserver() = default;
void LocationDataRdbObserver::OnChange()
{
LBSLOGI(LOCATOR, "LocationDataRdbObserver::%{public}s enter", __func__);
if (locationDataHandler_ == nullptr) {
LBSLOGI(LOCATOR, "LocationDataRdbObserver::%{public}s handler is nullptr", __func__);
return;
}
int32_t state = DISABLED;
Uri locationDataEnableUri(LOCATION_DATA_URI);
LocationErrCode errCode = DelayedSingleton<LocationDataRdbHelper>::GetInstance()->
GetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, state);
if (errCode != ERRCODE_SUCCESS) {
return;
}
locationDataHandler_->SendEvent(SWITCH_STATE_CHANGED, state, 0);
}
} // namespace Location
} // namespace OHOS