1bae4d13cSopenharmony_ci/* 2bae4d13cSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3bae4d13cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bae4d13cSopenharmony_ci * you may not use this file except in compliance with the License. 5bae4d13cSopenharmony_ci * You may obtain a copy of the License at 6bae4d13cSopenharmony_ci * 7bae4d13cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bae4d13cSopenharmony_ci * 9bae4d13cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bae4d13cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bae4d13cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bae4d13cSopenharmony_ci * See the License for the specific language governing permissions and 13bae4d13cSopenharmony_ci * limitations under the License. 14bae4d13cSopenharmony_ci */ 15bae4d13cSopenharmony_ci 16bae4d13cSopenharmony_ci#include "sensor_service.h" 17bae4d13cSopenharmony_ci 18bae4d13cSopenharmony_ci#include <cinttypes> 19bae4d13cSopenharmony_ci#include <string_ex.h> 20bae4d13cSopenharmony_ci#include <sys/socket.h> 21bae4d13cSopenharmony_ci#include <unistd.h> 22bae4d13cSopenharmony_ci 23bae4d13cSopenharmony_ci#ifdef HIVIEWDFX_HISYSEVENT_ENABLE 24bae4d13cSopenharmony_ci#include "hisysevent.h" 25bae4d13cSopenharmony_ci#endif // HIVIEWDFX_HISYSEVENT_ENABLE 26bae4d13cSopenharmony_ci#include "iservice_registry.h" 27bae4d13cSopenharmony_ci#ifdef MEMMGR_ENABLE 28bae4d13cSopenharmony_ci#include "mem_mgr_client.h" 29bae4d13cSopenharmony_ci#endif // MEMMGR_ENABLE 30bae4d13cSopenharmony_ci#include "permission_util.h" 31bae4d13cSopenharmony_ci 32bae4d13cSopenharmony_ci#include "print_sensor_data.h" 33bae4d13cSopenharmony_ci#include "securec.h" 34bae4d13cSopenharmony_ci#include "sensor.h" 35bae4d13cSopenharmony_ci#include "sensor_dump.h" 36bae4d13cSopenharmony_ci#include "sensor_errors.h" 37bae4d13cSopenharmony_ci#include "system_ability_definition.h" 38bae4d13cSopenharmony_ci 39bae4d13cSopenharmony_ci#undef LOG_TAG 40bae4d13cSopenharmony_ci#define LOG_TAG "SensorService" 41bae4d13cSopenharmony_ci 42bae4d13cSopenharmony_cinamespace OHOS { 43bae4d13cSopenharmony_cinamespace Sensors { 44bae4d13cSopenharmony_ciusing namespace OHOS::HiviewDFX; 45bae4d13cSopenharmony_cinamespace { 46bae4d13cSopenharmony_ciauto g_sensorService = SensorDelayedSpSingleton<SensorService>::GetInstance(); 47bae4d13cSopenharmony_ciconst bool G_REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(g_sensorService.GetRefPtr()); 48bae4d13cSopenharmony_ciconstexpr int32_t INVALID_PID = -1; 49bae4d13cSopenharmony_ciconstexpr int64_t MAX_EVENT_COUNT = 1000; 50bae4d13cSopenharmony_cistd::atomic_bool g_isRegister = false; 51bae4d13cSopenharmony_ci} // namespace 52bae4d13cSopenharmony_ci 53bae4d13cSopenharmony_ciSensorService::SensorService() 54bae4d13cSopenharmony_ci : SystemAbility(SENSOR_SERVICE_ABILITY_ID, true), state_(SensorServiceState::STATE_STOPPED) 55bae4d13cSopenharmony_ci{ 56bae4d13cSopenharmony_ci SEN_HILOGD("Add SystemAbility"); 57bae4d13cSopenharmony_ci} 58bae4d13cSopenharmony_ci 59bae4d13cSopenharmony_ciSensorService::~SensorService() {} 60bae4d13cSopenharmony_ci 61bae4d13cSopenharmony_civoid SensorService::OnDump() 62bae4d13cSopenharmony_ci{ 63bae4d13cSopenharmony_ci SEN_HILOGI("OnDump"); 64bae4d13cSopenharmony_ci} 65bae4d13cSopenharmony_ci 66bae4d13cSopenharmony_civoid SensorService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) 67bae4d13cSopenharmony_ci{ 68bae4d13cSopenharmony_ci SEN_HILOGI("OnAddSystemAbility systemAbilityId:%{public}d", systemAbilityId); 69bae4d13cSopenharmony_ci#ifdef MEMMGR_ENABLE 70bae4d13cSopenharmony_ci if (systemAbilityId == MEMORY_MANAGER_SA_ID) { 71bae4d13cSopenharmony_ci Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), 72bae4d13cSopenharmony_ci PROCESS_TYPE_SA, PROCESS_STATUS_STARTED, SENSOR_SERVICE_ABILITY_ID); 73bae4d13cSopenharmony_ci } 74bae4d13cSopenharmony_ci#endif // MEMMGR_ENABLE 75bae4d13cSopenharmony_ci} 76bae4d13cSopenharmony_ci 77bae4d13cSopenharmony_civoid SensorService::OnStart() 78bae4d13cSopenharmony_ci{ 79bae4d13cSopenharmony_ci CALL_LOG_ENTER; 80bae4d13cSopenharmony_ci if (state_ == SensorServiceState::STATE_RUNNING) { 81bae4d13cSopenharmony_ci SEN_HILOGW("SensorService has already started"); 82bae4d13cSopenharmony_ci return; 83bae4d13cSopenharmony_ci } 84bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 85bae4d13cSopenharmony_ci if (!InitInterface()) { 86bae4d13cSopenharmony_ci SEN_HILOGE("Init interface error"); 87bae4d13cSopenharmony_ci } 88bae4d13cSopenharmony_ci if (!InitDataCallback()) { 89bae4d13cSopenharmony_ci SEN_HILOGE("Init data callback error"); 90bae4d13cSopenharmony_ci } 91bae4d13cSopenharmony_ci if (!InitSensorList()) { 92bae4d13cSopenharmony_ci SEN_HILOGE("Init sensor list error"); 93bae4d13cSopenharmony_ci } 94bae4d13cSopenharmony_ci sensorDataProcesser_ = new (std::nothrow) SensorDataProcesser(sensorMap_); 95bae4d13cSopenharmony_ci CHKPV(sensorDataProcesser_); 96bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 97bae4d13cSopenharmony_ci if (!InitSensorPolicy()) { 98bae4d13cSopenharmony_ci SEN_HILOGE("Init sensor policy error"); 99bae4d13cSopenharmony_ci } 100bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 101bae4d13cSopenharmony_ci sensorManager_.InitSensorMap(sensorMap_, sensorDataProcesser_, reportDataCallback_); 102bae4d13cSopenharmony_ci#else 103bae4d13cSopenharmony_ci sensorManager_.InitSensorMap(sensorMap_); 104bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 105bae4d13cSopenharmony_ci if (!SystemAbility::Publish(SensorDelayedSpSingleton<SensorService>::GetInstance())) { 106bae4d13cSopenharmony_ci SEN_HILOGE("Publish SensorService error"); 107bae4d13cSopenharmony_ci return; 108bae4d13cSopenharmony_ci } 109bae4d13cSopenharmony_ci state_ = SensorServiceState::STATE_RUNNING; 110bae4d13cSopenharmony_ci#ifdef MEMMGR_ENABLE 111bae4d13cSopenharmony_ci AddSystemAbilityListener(MEMORY_MANAGER_SA_ID); 112bae4d13cSopenharmony_ci#endif // MEMMGR_ENABLE 113bae4d13cSopenharmony_ci} 114bae4d13cSopenharmony_ci 115bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 116bae4d13cSopenharmony_cibool SensorService::InitInterface() 117bae4d13cSopenharmony_ci{ 118bae4d13cSopenharmony_ci auto ret = sensorHdiConnection_.ConnectHdi(); 119bae4d13cSopenharmony_ci if (ret != ERR_OK) { 120bae4d13cSopenharmony_ci SEN_HILOGE("Connect hdi failed"); 121bae4d13cSopenharmony_ci return false; 122bae4d13cSopenharmony_ci } 123bae4d13cSopenharmony_ci return true; 124bae4d13cSopenharmony_ci} 125bae4d13cSopenharmony_ci 126bae4d13cSopenharmony_cibool SensorService::InitDataCallback() 127bae4d13cSopenharmony_ci{ 128bae4d13cSopenharmony_ci reportDataCallback_ = new (std::nothrow) ReportDataCallback(); 129bae4d13cSopenharmony_ci CHKPF(reportDataCallback_); 130bae4d13cSopenharmony_ci ReportDataCb cb = &ReportDataCallback::ReportEventCallback; 131bae4d13cSopenharmony_ci auto ret = sensorHdiConnection_.RegisterDataReport(cb, reportDataCallback_); 132bae4d13cSopenharmony_ci if (ret != ERR_OK) { 133bae4d13cSopenharmony_ci SEN_HILOGE("RegisterDataReport failed"); 134bae4d13cSopenharmony_ci return false; 135bae4d13cSopenharmony_ci } 136bae4d13cSopenharmony_ci return true; 137bae4d13cSopenharmony_ci} 138bae4d13cSopenharmony_ci 139bae4d13cSopenharmony_cibool SensorService::InitSensorList() 140bae4d13cSopenharmony_ci{ 141bae4d13cSopenharmony_ci std::lock_guard<std::mutex> sensorLock(sensorsMutex_); 142bae4d13cSopenharmony_ci int32_t ret = sensorHdiConnection_.GetSensorList(sensors_); 143bae4d13cSopenharmony_ci if (ret != 0) { 144bae4d13cSopenharmony_ci SEN_HILOGE("GetSensorList is failed"); 145bae4d13cSopenharmony_ci return false; 146bae4d13cSopenharmony_ci } 147bae4d13cSopenharmony_ci { 148bae4d13cSopenharmony_ci std::lock_guard<std::mutex> sensorMapLock(sensorMapMutex_); 149bae4d13cSopenharmony_ci for (const auto &it : sensors_) { 150bae4d13cSopenharmony_ci if (!(sensorMap_.insert(std::make_pair(it.GetSensorId(), it)).second)) { 151bae4d13cSopenharmony_ci SEN_HILOGW("sensorMap_ insert failed"); 152bae4d13cSopenharmony_ci } 153bae4d13cSopenharmony_ci } 154bae4d13cSopenharmony_ci } 155bae4d13cSopenharmony_ci return true; 156bae4d13cSopenharmony_ci} 157bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 158bae4d13cSopenharmony_ci 159bae4d13cSopenharmony_cibool SensorService::InitSensorPolicy() 160bae4d13cSopenharmony_ci{ 161bae4d13cSopenharmony_ci return true; 162bae4d13cSopenharmony_ci} 163bae4d13cSopenharmony_ci 164bae4d13cSopenharmony_civoid SensorService::OnStop() 165bae4d13cSopenharmony_ci{ 166bae4d13cSopenharmony_ci CALL_LOG_ENTER; 167bae4d13cSopenharmony_ci if (state_ == SensorServiceState::STATE_STOPPED) { 168bae4d13cSopenharmony_ci SEN_HILOGW("Already stopped"); 169bae4d13cSopenharmony_ci return; 170bae4d13cSopenharmony_ci } 171bae4d13cSopenharmony_ci state_ = SensorServiceState::STATE_STOPPED; 172bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 173bae4d13cSopenharmony_ci int32_t ret = sensorHdiConnection_.DestroyHdiConnection(); 174bae4d13cSopenharmony_ci if (ret != ERR_OK) { 175bae4d13cSopenharmony_ci SEN_HILOGE("Destroy hdi connect fail"); 176bae4d13cSopenharmony_ci } 177bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 178bae4d13cSopenharmony_ci UnregisterPermCallback(); 179bae4d13cSopenharmony_ci#ifdef MEMMGR_ENABLE 180bae4d13cSopenharmony_ci Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), PROCESS_TYPE_SA, PROCESS_STATUS_DIED, 181bae4d13cSopenharmony_ci SENSOR_SERVICE_ABILITY_ID); 182bae4d13cSopenharmony_ci#endif // MEMMGR_ENABLE 183bae4d13cSopenharmony_ci} 184bae4d13cSopenharmony_ci 185bae4d13cSopenharmony_civoid SensorService::ReportSensorSysEvent(int32_t sensorId, bool enable, int32_t pid) 186bae4d13cSopenharmony_ci{ 187bae4d13cSopenharmony_ci std::string packageName(""); 188bae4d13cSopenharmony_ci AccessTokenID tokenId = clientInfo_.GetTokenIdByPid(pid); 189bae4d13cSopenharmony_ci sensorManager_.GetPackageName(tokenId, packageName); 190bae4d13cSopenharmony_ci#ifdef HIVIEWDFX_HISYSEVENT_ENABLE 191bae4d13cSopenharmony_ci const int logLevel = 4; 192bae4d13cSopenharmony_ci int32_t uid = clientInfo_.GetUidByPid(pid); 193bae4d13cSopenharmony_ci#endif // HIVIEWDFX_HISYSEVENT_ENABLE 194bae4d13cSopenharmony_ci if (enable) { 195bae4d13cSopenharmony_ci#ifdef HIVIEWDFX_HISYSEVENT_ENABLE 196bae4d13cSopenharmony_ci HiSysEventWrite(HiSysEvent::Domain::SENSOR, "ENABLE_SENSOR", HiSysEvent::EventType::STATISTIC, 197bae4d13cSopenharmony_ci "LEVEL", logLevel, "UID", uid, "PKG_NAME", packageName, "TYPE", sensorId); 198bae4d13cSopenharmony_ci#endif // HIVIEWDFX_HISYSEVENT_ENABLE 199bae4d13cSopenharmony_ci SEN_HILOGI("PackageName:%{public}s open the sensor, sensorId:%{public}d", packageName.c_str(), sensorId); 200bae4d13cSopenharmony_ci } else { 201bae4d13cSopenharmony_ci#ifdef HIVIEWDFX_HISYSEVENT_ENABLE 202bae4d13cSopenharmony_ci HiSysEventWrite(HiSysEvent::Domain::SENSOR, "DISABLE_SENSOR", HiSysEvent::EventType::STATISTIC, 203bae4d13cSopenharmony_ci "LEVEL", logLevel, "UID", uid, "PKG_NAME", packageName, "TYPE", sensorId); 204bae4d13cSopenharmony_ci#endif // HIVIEWDFX_HISYSEVENT_ENABLE 205bae4d13cSopenharmony_ci SEN_HILOGI("PackageName:%{public}s close the sensor, sensorId:%{public}d", packageName.c_str(), sensorId); 206bae4d13cSopenharmony_ci } 207bae4d13cSopenharmony_ci} 208bae4d13cSopenharmony_ci 209bae4d13cSopenharmony_civoid SensorService::ReportOnChangeData(int32_t sensorId) 210bae4d13cSopenharmony_ci{ 211bae4d13cSopenharmony_ci std::lock_guard<std::mutex> sensorMapLock(sensorMapMutex_); 212bae4d13cSopenharmony_ci auto it = sensorMap_.find(sensorId); 213bae4d13cSopenharmony_ci if (it == sensorMap_.end()) { 214bae4d13cSopenharmony_ci SEN_HILOGE("sensorId is invalid"); 215bae4d13cSopenharmony_ci return; 216bae4d13cSopenharmony_ci } 217bae4d13cSopenharmony_ci if ((SENSOR_ON_CHANGE & it->second.GetFlags()) != SENSOR_ON_CHANGE) { 218bae4d13cSopenharmony_ci SEN_HILOGW("The data has not changed , no need to report"); 219bae4d13cSopenharmony_ci return; 220bae4d13cSopenharmony_ci } 221bae4d13cSopenharmony_ci SensorData sensorData; 222bae4d13cSopenharmony_ci auto ret = clientInfo_.GetStoreEvent(sensorId, sensorData); 223bae4d13cSopenharmony_ci if (ret != ERR_OK) { 224bae4d13cSopenharmony_ci SEN_HILOGE("There is no data to be reported"); 225bae4d13cSopenharmony_ci return; 226bae4d13cSopenharmony_ci } 227bae4d13cSopenharmony_ci sptr<SensorBasicDataChannel> channel = clientInfo_.GetSensorChannelByPid(GetCallingPid()); 228bae4d13cSopenharmony_ci CHKPV(channel); 229bae4d13cSopenharmony_ci auto sendRet = channel->SendData(&sensorData, sizeof(sensorData)); 230bae4d13cSopenharmony_ci if (sendRet != ERR_OK) { 231bae4d13cSopenharmony_ci SEN_HILOGE("Send data failed"); 232bae4d13cSopenharmony_ci return; 233bae4d13cSopenharmony_ci } 234bae4d13cSopenharmony_ci} 235bae4d13cSopenharmony_ci 236bae4d13cSopenharmony_ciErrCode SensorService::SaveSubscriber(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) 237bae4d13cSopenharmony_ci{ 238bae4d13cSopenharmony_ci if (!sensorManager_.SaveSubscriber(sensorId, GetCallingPid(), samplingPeriodNs, maxReportDelayNs)) { 239bae4d13cSopenharmony_ci SEN_HILOGE("SaveSubscriber failed"); 240bae4d13cSopenharmony_ci return UPDATE_SENSOR_INFO_ERR; 241bae4d13cSopenharmony_ci } 242bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 243bae4d13cSopenharmony_ci sensorManager_.StartDataReportThread(); 244bae4d13cSopenharmony_ci SensorBasicInfo sensorInfo = clientInfo_.GetCurPidSensorInfo(sensorId, GetCallingPid()); 245bae4d13cSopenharmony_ci if (!sensorManager_.SetBestSensorParams(sensorId, 246bae4d13cSopenharmony_ci sensorInfo.GetSamplingPeriodNs(), sensorInfo.GetMaxReportDelayNs())) { 247bae4d13cSopenharmony_ci SEN_HILOGE("SetBestSensorParams failed"); 248bae4d13cSopenharmony_ci clientInfo_.RemoveSubscriber(sensorId, GetCallingPid()); 249bae4d13cSopenharmony_ci return SET_SENSOR_CONFIG_ERR; 250bae4d13cSopenharmony_ci } 251bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 252bae4d13cSopenharmony_ci return ERR_OK; 253bae4d13cSopenharmony_ci} 254bae4d13cSopenharmony_ci 255bae4d13cSopenharmony_cibool SensorService::CheckSensorId(int32_t sensorId) 256bae4d13cSopenharmony_ci{ 257bae4d13cSopenharmony_ci std::lock_guard<std::mutex> sensorMapLock(sensorMapMutex_); 258bae4d13cSopenharmony_ci auto it = sensorMap_.find(sensorId); 259bae4d13cSopenharmony_ci if (it == sensorMap_.end()) { 260bae4d13cSopenharmony_ci SEN_HILOGE("Invalid sensorId, sensorId:%{public}d", sensorId); 261bae4d13cSopenharmony_ci return false; 262bae4d13cSopenharmony_ci } 263bae4d13cSopenharmony_ci return true; 264bae4d13cSopenharmony_ci} 265bae4d13cSopenharmony_ci 266bae4d13cSopenharmony_cibool SensorService::CheckParameter(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) 267bae4d13cSopenharmony_ci{ 268bae4d13cSopenharmony_ci if ((!CheckSensorId(sensorId)) || 269bae4d13cSopenharmony_ci ((samplingPeriodNs != 0L) && ((maxReportDelayNs / samplingPeriodNs) > MAX_EVENT_COUNT))) { 270bae4d13cSopenharmony_ci SEN_HILOGE("sensorId is invalid or maxReportDelayNs exceeded the maximum value"); 271bae4d13cSopenharmony_ci return false; 272bae4d13cSopenharmony_ci } 273bae4d13cSopenharmony_ci return true; 274bae4d13cSopenharmony_ci} 275bae4d13cSopenharmony_ci 276bae4d13cSopenharmony_ciErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) 277bae4d13cSopenharmony_ci{ 278bae4d13cSopenharmony_ci CALL_LOG_ENTER; 279bae4d13cSopenharmony_ci if (!CheckParameter(sensorId, samplingPeriodNs, maxReportDelayNs)) { 280bae4d13cSopenharmony_ci SEN_HILOGE("sensorId, samplingPeriodNs or maxReportDelayNs is invalid"); 281bae4d13cSopenharmony_ci return ERR_NO_INIT; 282bae4d13cSopenharmony_ci } 283bae4d13cSopenharmony_ci int32_t pid = GetCallingPid(); 284bae4d13cSopenharmony_ci std::lock_guard<std::mutex> serviceLock(serviceLock_); 285bae4d13cSopenharmony_ci if (clientInfo_.GetSensorState(sensorId)) { 286bae4d13cSopenharmony_ci SEN_HILOGW("Sensor has been enabled already"); 287bae4d13cSopenharmony_ci auto ret = SaveSubscriber(sensorId, samplingPeriodNs, maxReportDelayNs); 288bae4d13cSopenharmony_ci if (ret != ERR_OK) { 289bae4d13cSopenharmony_ci SEN_HILOGE("SaveSubscriber failed"); 290bae4d13cSopenharmony_ci return ret; 291bae4d13cSopenharmony_ci } 292bae4d13cSopenharmony_ci ReportSensorSysEvent(sensorId, true, pid); 293bae4d13cSopenharmony_ci if (ret != ERR_OK) { 294bae4d13cSopenharmony_ci SEN_HILOGE("ret:%{public}d", ret); 295bae4d13cSopenharmony_ci } 296bae4d13cSopenharmony_ci ReportOnChangeData(sensorId); 297bae4d13cSopenharmony_ci if (isReportActiveInfo_) { 298bae4d13cSopenharmony_ci ReportActiveInfo(sensorId, pid); 299bae4d13cSopenharmony_ci } 300bae4d13cSopenharmony_ci PrintSensorData::GetInstance().ResetHdiCounter(sensorId); 301bae4d13cSopenharmony_ci return ERR_OK; 302bae4d13cSopenharmony_ci } 303bae4d13cSopenharmony_ci auto ret = SaveSubscriber(sensorId, samplingPeriodNs, maxReportDelayNs); 304bae4d13cSopenharmony_ci if (ret != ERR_OK) { 305bae4d13cSopenharmony_ci SEN_HILOGE("SaveSubscriber failed"); 306bae4d13cSopenharmony_ci clientInfo_.RemoveSubscriber(sensorId, GetCallingPid()); 307bae4d13cSopenharmony_ci return ret; 308bae4d13cSopenharmony_ci } 309bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 310bae4d13cSopenharmony_ci ret = sensorHdiConnection_.EnableSensor(sensorId); 311bae4d13cSopenharmony_ci if (ret != ERR_OK) { 312bae4d13cSopenharmony_ci SEN_HILOGE("EnableSensor failed"); 313bae4d13cSopenharmony_ci clientInfo_.RemoveSubscriber(sensorId, GetCallingPid()); 314bae4d13cSopenharmony_ci return ENABLE_SENSOR_ERR; 315bae4d13cSopenharmony_ci } 316bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 317bae4d13cSopenharmony_ci if ((!g_isRegister) && (RegisterPermCallback(sensorId))) { 318bae4d13cSopenharmony_ci g_isRegister = true; 319bae4d13cSopenharmony_ci } 320bae4d13cSopenharmony_ci ReportSensorSysEvent(sensorId, true, pid); 321bae4d13cSopenharmony_ci if (isReportActiveInfo_) { 322bae4d13cSopenharmony_ci ReportActiveInfo(sensorId, pid); 323bae4d13cSopenharmony_ci } 324bae4d13cSopenharmony_ci PrintSensorData::GetInstance().ResetHdiCounter(sensorId); 325bae4d13cSopenharmony_ci return ret; 326bae4d13cSopenharmony_ci} 327bae4d13cSopenharmony_ci 328bae4d13cSopenharmony_ciErrCode SensorService::DisableSensor(int32_t sensorId, int32_t pid) 329bae4d13cSopenharmony_ci{ 330bae4d13cSopenharmony_ci CALL_LOG_ENTER; 331bae4d13cSopenharmony_ci if (!CheckSensorId(sensorId)) { 332bae4d13cSopenharmony_ci SEN_HILOGE("sensorId is invalid"); 333bae4d13cSopenharmony_ci return ERR_NO_INIT; 334bae4d13cSopenharmony_ci } 335bae4d13cSopenharmony_ci if (pid < 0) { 336bae4d13cSopenharmony_ci SEN_HILOGE("pid is invalid, pid:%{public}d", pid); 337bae4d13cSopenharmony_ci return CLIENT_PID_INVALID_ERR; 338bae4d13cSopenharmony_ci } 339bae4d13cSopenharmony_ci ReportSensorSysEvent(sensorId, false, pid); 340bae4d13cSopenharmony_ci std::lock_guard<std::mutex> serviceLock(serviceLock_); 341bae4d13cSopenharmony_ci if (sensorManager_.IsOtherClientUsingSensor(sensorId, pid)) { 342bae4d13cSopenharmony_ci SEN_HILOGW("Other client is using this sensor now, can't disable"); 343bae4d13cSopenharmony_ci return ERR_OK; 344bae4d13cSopenharmony_ci } 345bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 346bae4d13cSopenharmony_ci if (sensorHdiConnection_.DisableSensor(sensorId) != ERR_OK) { 347bae4d13cSopenharmony_ci SEN_HILOGE("DisableSensor is failed"); 348bae4d13cSopenharmony_ci return DISABLE_SENSOR_ERR; 349bae4d13cSopenharmony_ci } 350bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 351bae4d13cSopenharmony_ci int32_t uid = clientInfo_.GetUidByPid(pid); 352bae4d13cSopenharmony_ci clientInfo_.DestroyCmd(uid); 353bae4d13cSopenharmony_ci clientInfo_.ClearDataQueue(sensorId); 354bae4d13cSopenharmony_ci return sensorManager_.AfterDisableSensor(sensorId); 355bae4d13cSopenharmony_ci} 356bae4d13cSopenharmony_ci 357bae4d13cSopenharmony_ciErrCode SensorService::DisableSensor(int32_t sensorId) 358bae4d13cSopenharmony_ci{ 359bae4d13cSopenharmony_ci CALL_LOG_ENTER; 360bae4d13cSopenharmony_ci return DisableSensor(sensorId, GetCallingPid()); 361bae4d13cSopenharmony_ci} 362bae4d13cSopenharmony_ci 363bae4d13cSopenharmony_cistd::vector<Sensor> SensorService::GetSensorList() 364bae4d13cSopenharmony_ci{ 365bae4d13cSopenharmony_ci std::lock_guard<std::mutex> sensorLock(sensorsMutex_); 366bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 367bae4d13cSopenharmony_ci int32_t ret = sensorHdiConnection_.GetSensorList(sensors_); 368bae4d13cSopenharmony_ci if (ret != 0) { 369bae4d13cSopenharmony_ci SEN_HILOGE("GetSensorList is failed"); 370bae4d13cSopenharmony_ci return sensors_; 371bae4d13cSopenharmony_ci } 372bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 373bae4d13cSopenharmony_ci for (const auto &it : sensors_) { 374bae4d13cSopenharmony_ci std::lock_guard<std::mutex> sensorMapLock(sensorMapMutex_); 375bae4d13cSopenharmony_ci sensorMap_.insert(std::make_pair(it.GetSensorId(), it)); 376bae4d13cSopenharmony_ci } 377bae4d13cSopenharmony_ci return sensors_; 378bae4d13cSopenharmony_ci} 379bae4d13cSopenharmony_ci 380bae4d13cSopenharmony_ciErrCode SensorService::TransferDataChannel(const sptr<SensorBasicDataChannel> &sensorBasicDataChannel, 381bae4d13cSopenharmony_ci const sptr<IRemoteObject> &sensorClient) 382bae4d13cSopenharmony_ci{ 383bae4d13cSopenharmony_ci CHKPR(sensorBasicDataChannel, ERR_NO_INIT); 384bae4d13cSopenharmony_ci auto pid = GetCallingPid(); 385bae4d13cSopenharmony_ci auto uid = GetCallingUid(); 386bae4d13cSopenharmony_ci auto callerToken = GetCallingTokenID(); 387bae4d13cSopenharmony_ci if (!clientInfo_.UpdateAppThreadInfo(pid, uid, callerToken)) { 388bae4d13cSopenharmony_ci SEN_HILOGE("UpdateUid is failed"); 389bae4d13cSopenharmony_ci return UPDATE_UID_ERR; 390bae4d13cSopenharmony_ci } 391bae4d13cSopenharmony_ci if (!clientInfo_.UpdateSensorChannel(pid, sensorBasicDataChannel)) { 392bae4d13cSopenharmony_ci SEN_HILOGE("UpdateSensorChannel is failed"); 393bae4d13cSopenharmony_ci return UPDATE_SENSOR_CHANNEL_ERR; 394bae4d13cSopenharmony_ci } 395bae4d13cSopenharmony_ci sensorBasicDataChannel->SetSensorStatus(true); 396bae4d13cSopenharmony_ci RegisterClientDeathRecipient(sensorClient, pid); 397bae4d13cSopenharmony_ci return ERR_OK; 398bae4d13cSopenharmony_ci} 399bae4d13cSopenharmony_ci 400bae4d13cSopenharmony_ciErrCode SensorService::DestroySensorChannel(sptr<IRemoteObject> sensorClient) 401bae4d13cSopenharmony_ci{ 402bae4d13cSopenharmony_ci CALL_LOG_ENTER; 403bae4d13cSopenharmony_ci const int32_t clientPid = GetCallingPid(); 404bae4d13cSopenharmony_ci if (clientPid < 0) { 405bae4d13cSopenharmony_ci SEN_HILOGE("clientPid is invalid, clientPid:%{public}d", clientPid); 406bae4d13cSopenharmony_ci return CLIENT_PID_INVALID_ERR; 407bae4d13cSopenharmony_ci } 408bae4d13cSopenharmony_ci std::lock_guard<std::mutex> serviceLock(serviceLock_); 409bae4d13cSopenharmony_ci bool destroyRet = clientInfo_.DestroySensorChannel(clientPid); 410bae4d13cSopenharmony_ci if (!destroyRet) { 411bae4d13cSopenharmony_ci SEN_HILOGE("DestroySensorChannel is failed"); 412bae4d13cSopenharmony_ci return DESTROY_SENSOR_CHANNEL_ERR; 413bae4d13cSopenharmony_ci } 414bae4d13cSopenharmony_ci clientInfo_.DestroyCmd(GetCallingUid()); 415bae4d13cSopenharmony_ci UnregisterClientDeathRecipient(sensorClient); 416bae4d13cSopenharmony_ci return ERR_OK; 417bae4d13cSopenharmony_ci} 418bae4d13cSopenharmony_ci 419bae4d13cSopenharmony_civoid SensorService::ProcessDeathObserver(const wptr<IRemoteObject> &object) 420bae4d13cSopenharmony_ci{ 421bae4d13cSopenharmony_ci CALL_LOG_ENTER; 422bae4d13cSopenharmony_ci sptr<IRemoteObject> client = object.promote(); 423bae4d13cSopenharmony_ci CHKPV(client); 424bae4d13cSopenharmony_ci int32_t pid = clientInfo_.FindClientPid(client); 425bae4d13cSopenharmony_ci if (pid == INVALID_PID) { 426bae4d13cSopenharmony_ci SEN_HILOGE("pid is invalid"); 427bae4d13cSopenharmony_ci return; 428bae4d13cSopenharmony_ci } 429bae4d13cSopenharmony_ci SEN_HILOGI("pid is %{public}d", pid); 430bae4d13cSopenharmony_ci std::vector<int32_t> activeSensors = clientInfo_.GetSensorIdByPid(pid); 431bae4d13cSopenharmony_ci for (size_t i = 0; i < activeSensors.size(); ++i) { 432bae4d13cSopenharmony_ci int32_t ret = DisableSensor(activeSensors[i], pid); 433bae4d13cSopenharmony_ci if (ret != ERR_OK) { 434bae4d13cSopenharmony_ci SEN_HILOGE("DisableSensor failed, ret:%{public}d", ret); 435bae4d13cSopenharmony_ci } 436bae4d13cSopenharmony_ci } 437bae4d13cSopenharmony_ci DelSession(pid); 438bae4d13cSopenharmony_ci clientInfo_.DelActiveInfoCBPid(pid); 439bae4d13cSopenharmony_ci clientInfo_.DestroySensorChannel(pid); 440bae4d13cSopenharmony_ci clientInfo_.DestroyClientPid(client); 441bae4d13cSopenharmony_ci clientInfo_.DestroyCmd(clientInfo_.GetUidByPid(pid)); 442bae4d13cSopenharmony_ci} 443bae4d13cSopenharmony_ci 444bae4d13cSopenharmony_civoid SensorService::RegisterClientDeathRecipient(sptr<IRemoteObject> sensorClient, int32_t pid) 445bae4d13cSopenharmony_ci{ 446bae4d13cSopenharmony_ci CALL_LOG_ENTER; 447bae4d13cSopenharmony_ci CHKPV(sensorClient); 448bae4d13cSopenharmony_ci std::lock_guard<std::mutex> clientDeathObserverLock(clientDeathObserverMutex_); 449bae4d13cSopenharmony_ci if (clientDeathObserver_ == nullptr) { 450bae4d13cSopenharmony_ci clientDeathObserver_ = new (std::nothrow) DeathRecipientTemplate(*const_cast<SensorService *>(this)); 451bae4d13cSopenharmony_ci CHKPV(clientDeathObserver_); 452bae4d13cSopenharmony_ci } 453bae4d13cSopenharmony_ci sensorClient->AddDeathRecipient(clientDeathObserver_); 454bae4d13cSopenharmony_ci clientInfo_.SaveClientPid(sensorClient, pid); 455bae4d13cSopenharmony_ci} 456bae4d13cSopenharmony_ci 457bae4d13cSopenharmony_civoid SensorService::UnregisterClientDeathRecipient(sptr<IRemoteObject> sensorClient) 458bae4d13cSopenharmony_ci{ 459bae4d13cSopenharmony_ci CALL_LOG_ENTER; 460bae4d13cSopenharmony_ci CHKPV(sensorClient); 461bae4d13cSopenharmony_ci int32_t pid = clientInfo_.FindClientPid(sensorClient); 462bae4d13cSopenharmony_ci if (pid == INVALID_PID) { 463bae4d13cSopenharmony_ci SEN_HILOGE("Pid is invalid"); 464bae4d13cSopenharmony_ci return; 465bae4d13cSopenharmony_ci } 466bae4d13cSopenharmony_ci if (!clientInfo_.CallingService(pid)) { 467bae4d13cSopenharmony_ci SEN_HILOGD("Can't unregister client death recipient"); 468bae4d13cSopenharmony_ci return; 469bae4d13cSopenharmony_ci } 470bae4d13cSopenharmony_ci std::lock_guard<std::mutex> clientDeathObserverLock(clientDeathObserverMutex_); 471bae4d13cSopenharmony_ci sensorClient->RemoveDeathRecipient(clientDeathObserver_); 472bae4d13cSopenharmony_ci clientInfo_.DestroyClientPid(sensorClient); 473bae4d13cSopenharmony_ci} 474bae4d13cSopenharmony_ci 475bae4d13cSopenharmony_ciint32_t SensorService::Dump(int32_t fd, const std::vector<std::u16string> &args) 476bae4d13cSopenharmony_ci{ 477bae4d13cSopenharmony_ci CALL_LOG_ENTER; 478bae4d13cSopenharmony_ci if (fd < 0) { 479bae4d13cSopenharmony_ci SEN_HILOGE("Invalid fd"); 480bae4d13cSopenharmony_ci return DUMP_PARAM_ERR; 481bae4d13cSopenharmony_ci } 482bae4d13cSopenharmony_ci SensorDump &sensorDump = SensorDump::GetInstance(); 483bae4d13cSopenharmony_ci if (args.empty()) { 484bae4d13cSopenharmony_ci SEN_HILOGE("Param cannot be empty"); 485bae4d13cSopenharmony_ci dprintf(fd, "param cannot be empty\n"); 486bae4d13cSopenharmony_ci sensorDump.DumpHelp(fd); 487bae4d13cSopenharmony_ci return DUMP_PARAM_ERR; 488bae4d13cSopenharmony_ci } 489bae4d13cSopenharmony_ci std::vector<std::string> argList = { "" }; 490bae4d13cSopenharmony_ci std::transform(args.begin(), args.end(), std::back_inserter(argList), 491bae4d13cSopenharmony_ci [](const std::u16string &arg) { 492bae4d13cSopenharmony_ci return Str16ToStr8(arg); 493bae4d13cSopenharmony_ci }); 494bae4d13cSopenharmony_ci sensorDump.ParseCommand(fd, argList, sensors_, clientInfo_); 495bae4d13cSopenharmony_ci return ERR_OK; 496bae4d13cSopenharmony_ci} 497bae4d13cSopenharmony_ci 498bae4d13cSopenharmony_ciErrCode SensorService::SuspendSensors(int32_t pid) 499bae4d13cSopenharmony_ci{ 500bae4d13cSopenharmony_ci CALL_LOG_ENTER; 501bae4d13cSopenharmony_ci if (pid < 0) { 502bae4d13cSopenharmony_ci SEN_HILOGE("Pid is invalid"); 503bae4d13cSopenharmony_ci return CLIENT_PID_INVALID_ERR; 504bae4d13cSopenharmony_ci } 505bae4d13cSopenharmony_ci return POWER_POLICY.SuspendSensors(pid); 506bae4d13cSopenharmony_ci} 507bae4d13cSopenharmony_ci 508bae4d13cSopenharmony_ciErrCode SensorService::ResumeSensors(int32_t pid) 509bae4d13cSopenharmony_ci{ 510bae4d13cSopenharmony_ci CALL_LOG_ENTER; 511bae4d13cSopenharmony_ci if (pid < 0) { 512bae4d13cSopenharmony_ci SEN_HILOGE("Pid is invalid"); 513bae4d13cSopenharmony_ci return CLIENT_PID_INVALID_ERR; 514bae4d13cSopenharmony_ci } 515bae4d13cSopenharmony_ci return POWER_POLICY.ResumeSensors(pid); 516bae4d13cSopenharmony_ci} 517bae4d13cSopenharmony_ci 518bae4d13cSopenharmony_ciErrCode SensorService::GetActiveInfoList(int32_t pid, std::vector<ActiveInfo> &activeInfoList) 519bae4d13cSopenharmony_ci{ 520bae4d13cSopenharmony_ci CALL_LOG_ENTER; 521bae4d13cSopenharmony_ci if (pid < 0) { 522bae4d13cSopenharmony_ci SEN_HILOGE("Pid is invalid"); 523bae4d13cSopenharmony_ci return CLIENT_PID_INVALID_ERR; 524bae4d13cSopenharmony_ci } 525bae4d13cSopenharmony_ci activeInfoList = POWER_POLICY.GetActiveInfoList(pid); 526bae4d13cSopenharmony_ci return ERR_OK; 527bae4d13cSopenharmony_ci} 528bae4d13cSopenharmony_ci 529bae4d13cSopenharmony_ciErrCode SensorService::CreateSocketChannel(sptr<IRemoteObject> sensorClient, int32_t &clientFd) 530bae4d13cSopenharmony_ci{ 531bae4d13cSopenharmony_ci CALL_LOG_ENTER; 532bae4d13cSopenharmony_ci CHKPR(sensorClient, INVALID_POINTER); 533bae4d13cSopenharmony_ci int32_t serverFd = -1; 534bae4d13cSopenharmony_ci int32_t ret = AddSocketPairInfo(GetCallingUid(), GetCallingPid(), 535bae4d13cSopenharmony_ci AccessTokenKit::GetTokenTypeFlag(GetCallingTokenID()), 536bae4d13cSopenharmony_ci serverFd, std::ref(clientFd)); 537bae4d13cSopenharmony_ci if (ret != ERR_OK) { 538bae4d13cSopenharmony_ci SEN_HILOGE("Add socket pair info failed, ret:%{public}d", ret); 539bae4d13cSopenharmony_ci return ret; 540bae4d13cSopenharmony_ci } 541bae4d13cSopenharmony_ci RegisterClientDeathRecipient(sensorClient, GetCallingPid()); 542bae4d13cSopenharmony_ci return ERR_OK; 543bae4d13cSopenharmony_ci} 544bae4d13cSopenharmony_ci 545bae4d13cSopenharmony_ciErrCode SensorService::DestroySocketChannel(sptr<IRemoteObject> sensorClient) 546bae4d13cSopenharmony_ci{ 547bae4d13cSopenharmony_ci CALL_LOG_ENTER; 548bae4d13cSopenharmony_ci CHKPR(sensorClient, INVALID_POINTER); 549bae4d13cSopenharmony_ci DelSession(GetCallingPid()); 550bae4d13cSopenharmony_ci UnregisterClientDeathRecipient(sensorClient); 551bae4d13cSopenharmony_ci return ERR_OK; 552bae4d13cSopenharmony_ci} 553bae4d13cSopenharmony_ci 554bae4d13cSopenharmony_ciErrCode SensorService::EnableActiveInfoCB() 555bae4d13cSopenharmony_ci{ 556bae4d13cSopenharmony_ci CALL_LOG_ENTER; 557bae4d13cSopenharmony_ci isReportActiveInfo_ = true; 558bae4d13cSopenharmony_ci return clientInfo_.AddActiveInfoCBPid(GetCallingPid()); 559bae4d13cSopenharmony_ci} 560bae4d13cSopenharmony_ci 561bae4d13cSopenharmony_ciErrCode SensorService::DisableActiveInfoCB() 562bae4d13cSopenharmony_ci{ 563bae4d13cSopenharmony_ci CALL_LOG_ENTER; 564bae4d13cSopenharmony_ci isReportActiveInfo_ = false; 565bae4d13cSopenharmony_ci return clientInfo_.DelActiveInfoCBPid(GetCallingPid()); 566bae4d13cSopenharmony_ci} 567bae4d13cSopenharmony_ci 568bae4d13cSopenharmony_ciErrCode SensorService::ResetSensors() 569bae4d13cSopenharmony_ci{ 570bae4d13cSopenharmony_ci CALL_LOG_ENTER; 571bae4d13cSopenharmony_ci return POWER_POLICY.ResetSensors(); 572bae4d13cSopenharmony_ci} 573bae4d13cSopenharmony_ci 574bae4d13cSopenharmony_civoid SensorService::ReportActiveInfo(int32_t sensorId, int32_t pid) 575bae4d13cSopenharmony_ci{ 576bae4d13cSopenharmony_ci CALL_LOG_ENTER; 577bae4d13cSopenharmony_ci std::vector<SessionPtr> sessionList; 578bae4d13cSopenharmony_ci auto pidList = clientInfo_.GetActiveInfoCBPid(); 579bae4d13cSopenharmony_ci for (const auto &pid : pidList) { 580bae4d13cSopenharmony_ci auto sess = GetSessionByPid(pid); 581bae4d13cSopenharmony_ci if (sess != nullptr) { 582bae4d13cSopenharmony_ci sessionList.push_back(sess); 583bae4d13cSopenharmony_ci } 584bae4d13cSopenharmony_ci } 585bae4d13cSopenharmony_ci SensorBasicInfo sensorInfo = clientInfo_.GetCurPidSensorInfo(sensorId, pid); 586bae4d13cSopenharmony_ci ActiveInfo activeInfo(pid, sensorId, sensorInfo.GetSamplingPeriodNs(), 587bae4d13cSopenharmony_ci sensorInfo.GetMaxReportDelayNs()); 588bae4d13cSopenharmony_ci POWER_POLICY.ReportActiveInfo(activeInfo, sessionList); 589bae4d13cSopenharmony_ci} 590bae4d13cSopenharmony_ci 591bae4d13cSopenharmony_cibool SensorService::RegisterPermCallback(int32_t sensorId) 592bae4d13cSopenharmony_ci{ 593bae4d13cSopenharmony_ci CALL_LOG_ENTER; 594bae4d13cSopenharmony_ci if ((sensorId != SENSOR_TYPE_ID_PEDOMETER) && (sensorId != SENSOR_TYPE_ID_PEDOMETER_DETECTION) && 595bae4d13cSopenharmony_ci (sensorId != SENSOR_TYPE_ID_HEART_RATE)) { 596bae4d13cSopenharmony_ci SEN_HILOGD("No need listen for the sensor permission changes"); 597bae4d13cSopenharmony_ci return false; 598bae4d13cSopenharmony_ci } 599bae4d13cSopenharmony_ci Security::AccessToken::PermStateChangeScope scope = { 600bae4d13cSopenharmony_ci .permList = { ACTIVITY_MOTION_PERMISSION, READ_HEALTH_DATA_PERMISSION } 601bae4d13cSopenharmony_ci }; 602bae4d13cSopenharmony_ci permStateChangeCb_ = std::make_shared<PermStateChangeCb>(scope, this); 603bae4d13cSopenharmony_ci int32_t ret = Security::AccessToken::AccessTokenKit::RegisterPermStateChangeCallback(permStateChangeCb_); 604bae4d13cSopenharmony_ci if (ret != ERR_OK) { 605bae4d13cSopenharmony_ci SEN_HILOGE("RegisterPermStateChangeCallback fail"); 606bae4d13cSopenharmony_ci return false; 607bae4d13cSopenharmony_ci } 608bae4d13cSopenharmony_ci return true; 609bae4d13cSopenharmony_ci} 610bae4d13cSopenharmony_ci 611bae4d13cSopenharmony_civoid SensorService::UnregisterPermCallback() 612bae4d13cSopenharmony_ci{ 613bae4d13cSopenharmony_ci CALL_LOG_ENTER; 614bae4d13cSopenharmony_ci CHKPV(permStateChangeCb_); 615bae4d13cSopenharmony_ci int32_t ret = Security::AccessToken::AccessTokenKit::UnRegisterPermStateChangeCallback(permStateChangeCb_); 616bae4d13cSopenharmony_ci if (ret != ERR_OK) { 617bae4d13cSopenharmony_ci SEN_HILOGE("UnregisterPermStateChangeCallback fail"); 618bae4d13cSopenharmony_ci return; 619bae4d13cSopenharmony_ci } 620bae4d13cSopenharmony_ci g_isRegister = false; 621bae4d13cSopenharmony_ci} 622bae4d13cSopenharmony_ci 623bae4d13cSopenharmony_civoid SensorService::PermStateChangeCb::PermStateChangeCallback(Security::AccessToken::PermStateChangeInfo &result) 624bae4d13cSopenharmony_ci{ 625bae4d13cSopenharmony_ci CALL_LOG_ENTER; 626bae4d13cSopenharmony_ci CHKPV(server_); 627bae4d13cSopenharmony_ci server_->clientInfo_.ChangeSensorPerm(result.tokenID, result.permissionName, 628bae4d13cSopenharmony_ci (result.permStateChangeType != 0)); 629bae4d13cSopenharmony_ci} 630bae4d13cSopenharmony_ci} // namespace Sensors 631bae4d13cSopenharmony_ci} // namespace OHOS 632