From 1d2cbd107eec89b51775cc9fef2590f65c4202ea Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Fri, 10 Jun 2022 14:21:26 +0800 Subject: [PATCH 1/7] add low power Signed-off-by: liujiandong --- BUILD.gn | 3 + bundle.json | 2 + hisysevent.yaml | 26 +++ .../innerkits/include/i_tel_ril_manager.h | 5 + interfaces/innerkits/include/radio_event.h | 2 + .../include/device_state_handler.h | 63 +++++++ .../include/device_state_observer.h | 79 ++++++++ .../include/network_search_handler.h | 4 + .../include/network_search_manager.h | 11 ++ .../src/device_state_handler.cpp | 177 ++++++++++++++++++ .../src/device_state_observer.cpp | 130 +++++++++++++ .../network_search/src/network_register.cpp | 5 + .../src/network_search_handler.cpp | 18 +- .../src/network_search_manager.cpp | 23 +++ services/network_search/src/signal_info.cpp | 2 + services/sim/include/sim_account_manager.h | 1 + services/sim/include/sim_rdb_helper.h | 28 +-- services/sim/src/multi_sim_controller.cpp | 54 +----- services/sim/src/sim_account_manager.cpp | 20 +- services/sim/src/sim_rdb_helper.cpp | 105 ++--------- services/tel_ril/include/tel_ril_manager.h | 19 ++ services/tel_ril/include/tel_ril_network.h | 5 + services/tel_ril/src/tel_ril_manager.cpp | 13 ++ services/tel_ril/src/tel_ril_network.cpp | 117 ++++++++++++ services/tel_ril/test/tel_ril_test.cpp | 41 ++++ test/unittest/tel_ril_gtest/tel_ril_test.cpp | 65 +++++++ test/unittest/tel_ril_gtest/tel_ril_test.h | 4 + utils/BUILD.gn | 4 + utils/common/include/telephony_hisysevent.h | 28 +++ utils/common/src/telephony_hisysevent.cpp | 48 +++++ 30 files changed, 950 insertions(+), 152 deletions(-) create mode 100644 hisysevent.yaml create mode 100644 services/network_search/include/device_state_handler.h create mode 100644 services/network_search/include/device_state_observer.h create mode 100644 services/network_search/src/device_state_handler.cpp create mode 100644 services/network_search/src/device_state_observer.cpp create mode 100644 utils/common/include/telephony_hisysevent.h create mode 100644 utils/common/src/telephony_hisysevent.cpp diff --git a/BUILD.gn b/BUILD.gn index 1ab49ea8e..f522014c1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -35,6 +35,8 @@ ohos_shared_library("tel_core_service") { "$TELEPHONY_IMS_CORE_SERVICE_SRC_PATH/ims_core_service_death_recipient.cpp", "$TELEPHONY_IMS_CORE_SERVICE_SRC_PATH/ims_core_service_proxy.cpp", "$TELEPHONY_NETWORK_SEARCH_ROOT/src/cell_info.cpp", + "$TELEPHONY_NETWORK_SEARCH_ROOT/src/device_state_handler.cpp", + "$TELEPHONY_NETWORK_SEARCH_ROOT/src/device_state_observer.cpp", "$TELEPHONY_NETWORK_SEARCH_ROOT/src/ims_sms_callback_proxy.cpp", "$TELEPHONY_NETWORK_SEARCH_ROOT/src/ims_ut_callback_proxy.cpp", "$TELEPHONY_NETWORK_SEARCH_ROOT/src/ims_video_callback_proxy.cpp", @@ -152,6 +154,7 @@ ohos_shared_library("tel_core_service") { "eventhandler:libeventhandler", "i18n:zone_util", "ipc:ipc_core", + "netmanager_base:net_conn_manager_if", "power_manager_native:powermgr_client", "relational_store:native_rdb", "resource_management:global_resmgr", diff --git a/bundle.json b/bundle.json index 87f613749..a7435775d 100755 --- a/bundle.json +++ b/bundle.json @@ -40,6 +40,7 @@ "ipc", "dataability", "relational_store", + "netmanager_base", "power_manager_native", "resource_management", "ril_adapter", @@ -94,6 +95,7 @@ "header": { "header_base" : "//base/telephony/core_service/utils", "header_files": [ + "common/include/telephony_hisysevent.h", "common/include/str_convert.h", "common/include/telephony_permission.h", "log/include/telephony_log_c.h", diff --git a/hisysevent.yaml b/hisysevent.yaml new file mode 100644 index 000000000..3a92e4413 --- /dev/null +++ b/hisysevent.yaml @@ -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: CORE_SERVICE + +SIGNAL_LEVEL: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: signal level} + SLOT_ID: {type: INT32, desc: slot id} + LEVEL: {type: INT32, desc: signal strength level} + +NETWORK_REGISTER: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: network register} + SLOT_ID: {type: INT32, desc: slot id} + REGISTRATION_DOMAIN: {type: INT32, desc: network domain type} + RADIO_TECH: {type: INT32, desc: radio technology} + REGISTRATION_STATE: {type: INT32, desc: network registration state} diff --git a/interfaces/innerkits/include/i_tel_ril_manager.h b/interfaces/innerkits/include/i_tel_ril_manager.h index d2c2dafbb..d3c3936a4 100755 --- a/interfaces/innerkits/include/i_tel_ril_manager.h +++ b/interfaces/innerkits/include/i_tel_ril_manager.h @@ -285,6 +285,11 @@ public: int32_t slotId, ApduSimIORequestInfo reqInfo, const AppExecFwk::InnerEvent::Pointer &response) = 0; virtual int32_t SimAuthentication( int32_t slotId, SimAuthenticationRequestInfo reqInfo, const AppExecFwk::InnerEvent::Pointer &response) = 0; + + virtual int32_t SetNotificationFilter( + int32_t slotId, int32_t newFilter, const AppExecFwk::InnerEvent::Pointer &response) = 0; + virtual int32_t SetDeviceState(int32_t slotId, int32_t deviceStateType, bool deviceStateOn, + const AppExecFwk::InnerEvent::Pointer &response) = 0; }; } // namespace Telephony } // namespace OHOS diff --git a/interfaces/innerkits/include/radio_event.h b/interfaces/innerkits/include/radio_event.h index aa169b372..64ce5dfa4 100755 --- a/interfaces/innerkits/include/radio_event.h +++ b/interfaces/innerkits/include/radio_event.h @@ -131,6 +131,8 @@ enum RadioEvent { RADIO_SET_LOCATION_UPDATE, RADIO_CURRENT_CELL_UPDATE, RADIO_SET_DATA_CONNECT_ACTIVE, + RADIO_SET_DEVICE_STATE, + RADIO_SET_NOTIFICATION_FILTER, // module internal events RADIO_PS_CONNECTION_ATTACHED = 401, diff --git a/services/network_search/include/device_state_handler.h b/services/network_search/include/device_state_handler.h new file mode 100644 index 000000000..4578d754b --- /dev/null +++ b/services/network_search/include/device_state_handler.h @@ -0,0 +1,63 @@ +/* + * 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 NETWORK_SEARCH_INCLUDE_DEVICE_STATE_HANDLER_H +#define NETWORK_SEARCH_INCLUDE_DEVICE_STATE_HANDLER_H + +#include + +#include "i_tel_ril_manager.h" + +namespace OHOS { +namespace Telephony { +class NetworkSearchManager; +class DeviceStateHandler { +public: + DeviceStateHandler(const std::weak_ptr &networkSearchManager, + const std::weak_ptr &telRilManager, int32_t slotId); + virtual ~DeviceStateHandler() = default; + void ProcessWifiState(bool isWifiConnected); + void ProcessScreenDisplay(bool isScreenOn); + void ProcessPowerSaveMode(bool isPowerSaveModeOn); + void ProcessChargingState(bool isCharging); + void ProcessNetSharingState(bool isNetSharingOn); + void ProcessRadioState(); + +private: + uint32_t GetCellRequestMinInterval() const; + bool IsHighPowerConsumption() const; + bool IsSignalStrengthNotificationExpected() const; + void SetCellRequestMinInterval(uint32_t minInterval) const; + void ProcessDeviceState(); + void SetNotificationFilter(int32_t newFilter, bool force); + void SetDeviceState(int32_t deviceStateType, bool deviceStateOn); + void SyncSettings(); + +private: + std::weak_ptr networkSearchManager_; + std::weak_ptr telRilManager_; + int32_t slotId_ = 0; + int32_t notificationFilter_ = 0; + uint32_t cellRequestMinInterval_ = 2; + bool isWifiConnected_ = false; + bool isLowData_ = false; + bool isPowerSaveModeOn_ = false; + bool isCharging_ = false; + bool isScreenOn_ = false; + bool isNetSharingOn_ = false; +}; +} // namespace Telephony +} // namespace OHOS +#endif // NETWORK_SEARCH_INCLUDE_DEVICE_STATE_HANDLER_H diff --git a/services/network_search/include/device_state_observer.h b/services/network_search/include/device_state_observer.h new file mode 100644 index 000000000..429068abe --- /dev/null +++ b/services/network_search/include/device_state_observer.h @@ -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 NETWORK_SEARCH_DEVICE_STATE_OBSERVER_H +#define NETWORK_SEARCH_DEVICE_STATE_OBSERVER_H + +#include "common_event_subscriber.h" +#include "common_event_support.h" +#include "common_event_manager.h" +#include "device_state_handler.h" +#include "net_all_capabilities.h" +#include "net_supplier_info.h" + +namespace OHOS { +namespace Telephony { +using CommonEventData = OHOS::EventFwk::CommonEventData; +using CommonEventManager = OHOS::EventFwk::CommonEventManager; +using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; +using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; +using CommonEventSupport = OHOS::EventFwk::CommonEventSupport; +using MatchingSkills = OHOS::EventFwk::MatchingSkills; +using NetBearType = OHOS::NetManagerStandard::NetBearType; +using NetConnState = OHOS::NetManagerStandard::NetConnState; + +enum DeviceStateEventIntValue { + COMMON_EVENT_CONNECTIVITY_CHANGE, + COMMON_EVENT_SCREEN_ON, + COMMON_EVENT_SCREEN_OFF, + COMMON_EVENT_POWER_SAVE_MODE_CHANGED, + COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED, + COMMON_EVENT_CHARGING, + COMMON_EVENT_DISCHARGING, + COMMON_EVENT_WIFI_HOTSPOT_STATE, + COMMON_EVENT_WIFI_AP_STA_JOIN, + COMMON_EVENT_WIFI_AP_STA_LEAVE, + COMMON_EVENT_UNKNOWN, +}; + +class DeviceStateEventSubscriber : public CommonEventSubscriber { +public: + explicit DeviceStateEventSubscriber(const CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) {} + ~DeviceStateEventSubscriber() = default; + void OnReceiveEvent(const CommonEventData &data) override; + void SetEventHandler(const std::shared_ptr &deviceStateHandler); + void InitEventMap(); + +private: + DeviceStateEventIntValue GetDeviceStateEventIntValue(std::string &event) const; + +private: + std::shared_ptr deviceStateHandler_; + std::map deviceStateEventMapIntValues_; +}; + +class DeviceStateObserver { +public: + DeviceStateObserver() = default; + ~DeviceStateObserver() = default; + void StartEventSubscriber(const std::shared_ptr &deviceStateHandler); + void StopEventSubscriber(); + +private: + std::shared_ptr subscriber_; +}; +} // namespace Telephony +} // namespace OHOS +#endif // NETWORK_SEARCH_DEVICE_STATE_OBSERVER_H \ No newline at end of file diff --git a/services/network_search/include/network_search_handler.h b/services/network_search/include/network_search_handler.h index 334633b20..61fa1df17 100644 --- a/services/network_search/include/network_search_handler.h +++ b/services/network_search/include/network_search_handler.h @@ -87,6 +87,7 @@ public: void UpdateCellLocation(int32_t techType, int32_t cellId, int32_t lac); sptr GetCellLocation(); void TimezoneRefresh(); + void SetCellRequestMinInterval(uint32_t minInterval); private: void RadioOnState(); @@ -123,6 +124,7 @@ private: void AutoTimeChange(const AppExecFwk::InnerEvent::Pointer &); void AutoTimeZoneChange(const AppExecFwk::InnerEvent::Pointer &); void AirplaneModeChange(const AppExecFwk::InnerEvent::Pointer &); + private: std::weak_ptr networkSearchManager_; std::unique_ptr networkRegister_ = nullptr; @@ -142,6 +144,8 @@ private: int64_t lastTimeCsRegistrationReq_ = 0; bool firstInit_ = true; int32_t slotId_ = 0; + uint32_t cellRequestMinInterval_ = 2; // This is the minimum interval in seconds for cell requests + uint32_t lastCellRequestTime_ = 0; }; } // namespace Telephony } // namespace OHOS diff --git a/services/network_search/include/network_search_manager.h b/services/network_search/include/network_search_manager.h index 22067b46d..48b062d2b 100644 --- a/services/network_search/include/network_search_manager.h +++ b/services/network_search/include/network_search_manager.h @@ -37,6 +37,8 @@ #include "radio_event.h" #include "setting_utils.h" #include "iremote_stub.h" +#include "device_state_handler.h" +#include "device_state_observer.h" namespace OHOS { namespace Telephony { @@ -53,6 +55,8 @@ struct NetworkSearchManagerInner { std::shared_ptr networkSearchHandler_ = nullptr; std::shared_ptr eventLoop_ = nullptr; std::unique_ptr observerHandler_ = nullptr; + std::shared_ptr deviceStateHandler_ = nullptr; + std::shared_ptr deviceStateObserver_ = nullptr; sptr settingAutoTimeObserver_; sptr settingAutoTimezoneObserver_; sptr airplaneModeObserver_; @@ -70,6 +74,8 @@ struct NetworkSearchManagerInner { bool RegisterSetting(); bool UnRegisterSetting(); + bool RegisterDeviceStateObserver(); + bool UnRegisterDeviceStateObserver(); bool Init() { radioCapability_.ratFamily = DEFAULT_RAF; @@ -86,6 +92,11 @@ struct NetworkSearchManagerInner { return false; } } + if (deviceStateHandler_ != nullptr) { + if (!RegisterDeviceStateObserver()) { + return false; + } + } if (eventLoop_ != nullptr) { eventLoop_->Run(); } diff --git a/services/network_search/src/device_state_handler.cpp b/services/network_search/src/device_state_handler.cpp new file mode 100644 index 000000000..09cd5c4fd --- /dev/null +++ b/services/network_search/src/device_state_handler.cpp @@ -0,0 +1,177 @@ +/* + * 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 "device_state_handler.h" + +#include "network_search_manager.h" +#include "telephony_log_wrapper.h" + +namespace OHOS { +namespace Telephony { +const uint32_t CELL_REQUEST_SHORT_INTERVAL = 2; // This is the minimum interval in seconds for cell requests +const uint32_t CELL_REQUEST_LONG_INTERVAL = 10; // This is the maximum interval in seconds for cell requests + +DeviceStateHandler::DeviceStateHandler( + const std::weak_ptr &networkSearchManager, + const std::weak_ptr &telRilManager, int32_t slotId) + : networkSearchManager_(networkSearchManager), telRilManager_(telRilManager), slotId_(slotId) +{} + +void DeviceStateHandler::ProcessWifiState(bool isWifiConnected) +{ + isWifiConnected_ = isWifiConnected; + ProcessDeviceState(); +} + +void DeviceStateHandler::ProcessScreenDisplay(bool isScreenOn) +{ + isScreenOn_ = isScreenOn; + ProcessDeviceState(); +} + +void DeviceStateHandler::ProcessPowerSaveMode(bool isPowerSaveModeOn) +{ + isPowerSaveModeOn_ = isPowerSaveModeOn; + SetDeviceState(POWER_SAVE_MODE, isPowerSaveModeOn_); + ProcessDeviceState(); +} + +void DeviceStateHandler::ProcessChargingState(bool isCharging) +{ + isCharging_ = isCharging; + SetDeviceState(CHARGING_STATE, isCharging_); + ProcessDeviceState(); +} + +void DeviceStateHandler::ProcessNetSharingState(bool isNetSharingOn) +{ + isNetSharingOn_ = isNetSharingOn; + ProcessDeviceState(); +} + +void DeviceStateHandler::ProcessRadioState() +{ + SyncSettings(); +} + +void DeviceStateHandler::ProcessDeviceState() +{ + uint32_t newCellRequestMinInterval = GetCellRequestMinInterval(); + if (cellRequestMinInterval_ != newCellRequestMinInterval) { + cellRequestMinInterval_ = newCellRequestMinInterval; + SetCellRequestMinInterval(cellRequestMinInterval_); + } + + if (isLowData_ != !IsHighPowerConsumption()) { + isLowData_ = !isLowData_; + SetDeviceState(LOW_DATA_STATE, isLowData_); + } + + int32_t newFilter = NONE; + if (IsSignalStrengthNotificationExpected()) { + newFilter |= SIGNAL_STRENGTH; + } + + if (IsHighPowerConsumption()) { + newFilter |= NETWORK_STATE; + newFilter |= DATA_CALL; + newFilter |= PHYSICAL_CHANNEL_CONFIG; + } + + SetNotificationFilter(newFilter, false); +} + +bool DeviceStateHandler::IsSignalStrengthNotificationExpected() const +{ + return isCharging_ || isScreenOn_; +} + +bool DeviceStateHandler::IsHighPowerConsumption() const +{ + return isCharging_ || isScreenOn_ || isNetSharingOn_; +} + +uint32_t DeviceStateHandler::GetCellRequestMinInterval() const +{ + if (isScreenOn_ && (!isWifiConnected_ || isCharging_)) { + return CELL_REQUEST_SHORT_INTERVAL; + } else { + return CELL_REQUEST_LONG_INTERVAL; + } +} + +void DeviceStateHandler::SetCellRequestMinInterval(uint32_t minInterval) const +{ + std::shared_ptr nsm = networkSearchManager_.lock(); + if (nsm == nullptr) { + return; + } + auto inner = nsm->FindManagerInner(slotId_); + if (inner == nullptr) { + return; + } + if (inner->networkSearchHandler_ != nullptr) { + TELEPHONY_LOGI("DeviceStateHandler::SetCellRequestMinInterval %{public}d", minInterval); + inner->networkSearchHandler_->SetCellRequestMinInterval(minInterval); + } +} + +void DeviceStateHandler::SetNotificationFilter(int32_t newFilter, bool force) +{ + if (!force && newFilter == notificationFilter_) { + TELEPHONY_LOGE("DeviceStateHandler::SetNotificationFilter is not necessary"); + return; + } + auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SET_NOTIFICATION_FILTER); + if (event == nullptr) { + TELEPHONY_LOGE("DeviceStateHandler::SetNotificationFilter event is null"); + return; + } + std::shared_ptr telRilManager = telRilManager_.lock(); + if (telRilManager != nullptr) { + TELEPHONY_LOGI("DeviceStateHandler::SetNotificationFilter old filter:%{public}d, new filter:%{public}d", + notificationFilter_, newFilter); + telRilManager->SetNotificationFilter(slotId_, newFilter, event); + notificationFilter_ = newFilter; + } +} + +void DeviceStateHandler::SetDeviceState(int32_t deviceStateType, bool deviceStateOn) +{ + auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SET_DEVICE_STATE); + if (event == nullptr) { + TELEPHONY_LOGE("DeviceStateHandler::SetDeviceState event is null"); + return; + } + std::shared_ptr telRilManager = telRilManager_.lock(); + if (telRilManager != nullptr) { + TELEPHONY_LOGI("DeviceStateHandler::SetDeviceState type:%{public}d state:%{public}d", + deviceStateType, deviceStateOn); + telRilManager->SetDeviceState(slotId_, deviceStateType, deviceStateOn, event); + } +} + +void DeviceStateHandler::SyncSettings() +{ + TELEPHONY_LOGI("DeviceStateHandler::SyncSettings isCharging_=%{public}d, isLowData_=%{public}d," + " isPowerSaveModeOn_=%{public}d, notificationFilter_=%{public}d", + isCharging_, isLowData_, isPowerSaveModeOn_, notificationFilter_); + SetDeviceState(CHARGING_STATE, isCharging_); + SetDeviceState(LOW_DATA_STATE, isLowData_); + SetDeviceState(POWER_SAVE_MODE, isPowerSaveModeOn_); + SetNotificationFilter(notificationFilter_, true); +} +} // namespace Telephony +} // namespace OHOS diff --git a/services/network_search/src/device_state_observer.cpp b/services/network_search/src/device_state_observer.cpp new file mode 100644 index 000000000..01398b951 --- /dev/null +++ b/services/network_search/src/device_state_observer.cpp @@ -0,0 +1,130 @@ +/* + * 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 "device_state_observer.h" + +#include "telephony_log_wrapper.h" + +namespace OHOS { +namespace Telephony { +const std::string NET_TYPE = "NetType"; + +void DeviceStateObserver::StartEventSubscriber(const std::shared_ptr &deviceStateHandler) +{ + MatchingSkills matchingSkills; + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_ON); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_OFF); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CHARGING); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_DISCHARGING); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_HOTSPOT_STATE); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_AP_STA_JOIN); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_AP_STA_LEAVE); + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + subscriber_ = std::make_shared(subscriberInfo); + subscriber_->SetEventHandler(deviceStateHandler); + subscriber_->InitEventMap(); + bool subscribeResult = CommonEventManager::SubscribeCommonEvent(subscriber_); + TELEPHONY_LOGI("DeviceStateObserver::StartEventSubscriber subscribeResult = %{public}d", subscribeResult); +} + +void DeviceStateObserver::StopEventSubscriber() +{ + if (subscriber_ == nullptr) { + TELEPHONY_LOGE("DeviceStateObserver::StopEventSubscriber subscriber_ is nullptr"); + return; + } + bool subscribeResult = CommonEventManager::UnSubscribeCommonEvent(subscriber_); + subscriber_ = nullptr; + TELEPHONY_LOGI("DeviceStateObserver::StopEventSubscriber subscribeResult = %{public}d", subscribeResult); +} + +void DeviceStateEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + if (deviceStateHandler_ == nullptr) { + TELEPHONY_LOGE("DeviceStateEventSubscriber::OnReceiveEvent: networkSearchHandler_ is nullptr"); + return; + } + std::string action = data.GetWant().GetAction(); + TELEPHONY_LOGI("DeviceStateEventSubscriber::OnReceiveEvent: action = %{public}s", action.c_str()); + switch (GetDeviceStateEventIntValue(action)) { + case COMMON_EVENT_CONNECTIVITY_CHANGE: + if (data.GetWant().GetIntParam(NET_TYPE, NetBearType::BEARER_DEFAULT) == NetBearType::BEARER_WIFI) { + bool isWifiConnected = data.GetCode() == NetConnState::NET_CONN_STATE_CONNECTED; + deviceStateHandler_->ProcessWifiState(isWifiConnected); + TELEPHONY_LOGI("DeviceStateEventSubscriber:: wifi %{public}s", + isWifiConnected ? "connected" : "no connected"); + } + break; + case COMMON_EVENT_SCREEN_ON: + deviceStateHandler_->ProcessScreenDisplay(true); + break; + case COMMON_EVENT_SCREEN_OFF: + deviceStateHandler_->ProcessScreenDisplay(false); + break; + case COMMON_EVENT_POWER_SAVE_MODE_CHANGED: + deviceStateHandler_->ProcessPowerSaveMode(true); + break; + case COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED: + deviceStateHandler_->ProcessPowerSaveMode(false); + break; + case COMMON_EVENT_CHARGING: + deviceStateHandler_->ProcessChargingState(true); + break; + case COMMON_EVENT_DISCHARGING: + deviceStateHandler_->ProcessChargingState(false); + break; + case COMMON_EVENT_WIFI_HOTSPOT_STATE: + case COMMON_EVENT_WIFI_AP_STA_JOIN: + case COMMON_EVENT_WIFI_AP_STA_LEAVE: + break; + default: + break; + } +} + +void DeviceStateEventSubscriber::SetEventHandler(const std::shared_ptr &deviceStateHandler) +{ + deviceStateHandler_ = deviceStateHandler; +} + +DeviceStateEventIntValue DeviceStateEventSubscriber::GetDeviceStateEventIntValue(std::string &event) const +{ + auto iter = deviceStateEventMapIntValues_.find(event); + if (iter == deviceStateEventMapIntValues_.end()) { + return COMMON_EVENT_UNKNOWN; + } + return iter->second; +} + +void DeviceStateEventSubscriber::InitEventMap() +{ + deviceStateEventMapIntValues_ = { + {CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE, COMMON_EVENT_CONNECTIVITY_CHANGE}, + {CommonEventSupport::COMMON_EVENT_SCREEN_ON, COMMON_EVENT_SCREEN_ON}, + {CommonEventSupport::COMMON_EVENT_SCREEN_OFF, COMMON_EVENT_SCREEN_OFF}, + {CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED, COMMON_EVENT_POWER_SAVE_MODE_CHANGED}, + {CommonEventSupport::COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED, COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED}, + {CommonEventSupport::COMMON_EVENT_CHARGING, COMMON_EVENT_CHARGING}, + {CommonEventSupport::COMMON_EVENT_DISCHARGING, COMMON_EVENT_DISCHARGING}, + {CommonEventSupport::COMMON_EVENT_WIFI_HOTSPOT_STATE, COMMON_EVENT_WIFI_HOTSPOT_STATE}, + {CommonEventSupport::COMMON_EVENT_WIFI_AP_STA_JOIN, COMMON_EVENT_WIFI_AP_STA_JOIN}, + {CommonEventSupport::COMMON_EVENT_WIFI_AP_STA_LEAVE, COMMON_EVENT_WIFI_AP_STA_LEAVE}, + }; +} +} // namespace Telephony +} // namespace OHOS \ No newline at end of file diff --git a/services/network_search/src/network_register.cpp b/services/network_search/src/network_register.cpp index 1c634d348..57fa0d81f 100755 --- a/services/network_search/src/network_register.cpp +++ b/services/network_search/src/network_register.cpp @@ -24,6 +24,7 @@ #include "telephony_log_wrapper.h" #include "i_network_search_callback.h" #include "resource_utils.h" +#include "telephony_hisysevent.h" namespace OHOS { namespace Telephony { @@ -127,6 +128,8 @@ void NetworkRegister::ProcessCsRegister(const AppExecFwk::InnerEvent::Pointer &e if (networkSearchManager->CheckIsNeedNotify(slotId_) || networkSearchState_->IsEmergency()) { networkSearchState_->NotifyStateChange(); } + WriteNetworkStateHiSysEvent(slotId_, static_cast(DomainType::DOMAIN_TYPE_CS), + static_cast(tech), static_cast(regStatus)); } void NetworkRegister::ProcessPsRegister(const AppExecFwk::InnerEvent::Pointer &event) @@ -177,6 +180,8 @@ void NetworkRegister::ProcessPsRegister(const AppExecFwk::InnerEvent::Pointer &e if (networkSearchManager->CheckIsNeedNotify(slotId_) || networkSearchState_->IsEmergency()) { networkSearchState_->NotifyStateChange(); } + WriteNetworkStateHiSysEvent(slotId_, static_cast(DomainType::DOMAIN_TYPE_PS), + static_cast(tech), static_cast(regStatus)); } void NetworkRegister::ProcessChannelConfigInfo(const AppExecFwk::InnerEvent::Pointer &event) diff --git a/services/network_search/src/network_search_handler.cpp b/services/network_search/src/network_search_handler.cpp index b3793b489..5f34c5d0b 100644 --- a/services/network_search/src/network_search_handler.cpp +++ b/services/network_search/src/network_search_handler.cpp @@ -15,10 +15,11 @@ #include "network_search_handler.h" +#include + #include "ims_core_service_client.h" #include "network_search_manager.h" #include "telephony_log_wrapper.h" - namespace OHOS { namespace Telephony { const int64_t IMS_STATE_REGISTED = 1; @@ -274,6 +275,10 @@ void NetworkSearchHandler::RadioStateChange(const AppExecFwk::InnerEvent::Pointe } if (radioState == CORE_SERVICE_POWER_ON || radioState == CORE_SERVICE_POWER_OFF) { networkSearchManager->SetRadioStateValue(slotId_, (ModemPowerState)radioState); + auto inner = networkSearchManager->FindManagerInner(slotId_); + if (inner != nullptr && inner->deviceStateHandler_ != nullptr) { + inner->deviceStateHandler_->ProcessRadioState(); + } } else { networkSearchManager->SetRadioStateValue(slotId_, CORE_SERVICE_POWER_NOT_AVAILABLE); } @@ -690,10 +695,16 @@ void NetworkSearchHandler::TimezoneRefresh() void NetworkSearchHandler::SendUpdateCellLocationRequest() { + uint32_t curTime = (uint32_t)time(0); + if ((curTime - lastCellRequestTime_) < cellRequestMinInterval_) { + TELEPHONY_LOGE("NetworkSearchHandler::SendUpdateCellLocationRequest interval is too short"); + return; + } TELEPHONY_LOGI("NetworkSearchHandler::SendUpdateCellLocationRequest slotId:%{public}d", slotId_); std::shared_ptr telRilManager = telRilManager_.lock(); auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CURRENT_CELL_INFO); if (event != nullptr && telRilManager != nullptr) { + lastCellRequestTime_ = curTime; event->SetOwner(shared_from_this()); telRilManager->GetCurrentCellInfo(slotId_, event); } @@ -811,5 +822,10 @@ void NetworkSearchHandler::AirplaneModeChange(const AppExecFwk::InnerEvent::Poin radioInfo_->AirplaneModeChange(); } } + +void NetworkSearchHandler::SetCellRequestMinInterval(uint32_t minInterval) +{ + cellRequestMinInterval_ = minInterval; +} } // namespace Telephony } // namespace OHOS diff --git a/services/network_search/src/network_search_manager.cpp b/services/network_search/src/network_search_manager.cpp index aed3376d6..d7b468fab 100644 --- a/services/network_search/src/network_search_manager.cpp +++ b/services/network_search/src/network_search_manager.cpp @@ -40,6 +40,7 @@ NetworkSearchManager::~NetworkSearchManager() std::shared_ptr inner = FindManagerInner(slotId); if (inner != nullptr) { inner->UnRegisterSetting(); + inner->UnRegisterDeviceStateObserver(); } } } @@ -78,6 +79,11 @@ bool NetworkSearchManager::InitPointer(std::shared_ptrdeviceStateHandler_ = std::make_shared(shared_from_this(), telRilManager_, slotId); + if (inner->deviceStateHandler_ == nullptr) { + TELEPHONY_LOGE("failed to create new DeviceStateHandler slotId:%{public}d", slotId); + return false; + } return true; } @@ -120,6 +126,23 @@ bool NetworkSearchManagerInner::UnRegisterSetting() return true; } +bool NetworkSearchManagerInner::RegisterDeviceStateObserver() +{ + deviceStateObserver_ = std::make_shared(); + deviceStateObserver_->StartEventSubscriber(deviceStateHandler_); + return true; +} + +bool NetworkSearchManagerInner::UnRegisterDeviceStateObserver() +{ + if (deviceStateObserver_ == nullptr) { + TELEPHONY_LOGE("NetworkSearchManager::UnRegisterDeviceStateObserver deviceStateObserver_ is null."); + return false; + } + deviceStateObserver_->StopEventSubscriber(); + return true; +} + bool NetworkSearchManager::OnInit() { TELEPHONY_LOGI("NetworkSearchManager::Init"); diff --git a/services/network_search/src/signal_info.cpp b/services/network_search/src/signal_info.cpp index df57ad541..06bd4e00e 100755 --- a/services/network_search/src/signal_info.cpp +++ b/services/network_search/src/signal_info.cpp @@ -17,6 +17,7 @@ #include "network_search_notify.h" #include "telephony_log_wrapper.h" +#include "telephony_hisysevent.h" namespace OHOS { namespace Telephony { @@ -138,6 +139,7 @@ void SignalInfo::ProcessSignalIntensity(int32_t slotId, const AppExecFwk::InnerE std::vector> signals; GetSignalInfoList(signals); DelayedSingleton::GetInstance()->NotifySignalInfoUpdated(slotId, signals); + WriteSignalLevelHiSysEvent(slotId, signals[0]->GetSignalLevel()); } PrintfLog(*signalIntensity); } diff --git a/services/sim/include/sim_account_manager.h b/services/sim/include/sim_account_manager.h index 29fdb993c..239d4bc42 100755 --- a/services/sim/include/sim_account_manager.h +++ b/services/sim/include/sim_account_manager.h @@ -56,6 +56,7 @@ public: private: bool IsValidSlotId(int32_t); + bool IsValidSlotIdForDefault(int32_t); std::shared_ptr telRilManager_ = nullptr; std::shared_ptr simStateManager_ = nullptr; std::shared_ptr simFileManager_ = nullptr; diff --git a/services/sim/include/sim_rdb_helper.h b/services/sim/include/sim_rdb_helper.h index fd4ad18f9..dbc751712 100755 --- a/services/sim/include/sim_rdb_helper.h +++ b/services/sim/include/sim_rdb_helper.h @@ -18,18 +18,18 @@ #include -#include "iservice_registry.h" -#include "system_ability_definition.h" +#include "abs_shared_result_set.h" #include "data_ability_helper.h" #include "data_ability_predicates.h" -#include "abs_shared_result_set.h" -#include "values_bucket.h" +#include "iservice_registry.h" #include "result_set.h" -#include "uri.h" -#include "sim_utils.h" #include "sim_constant.h" #include "sim_rdb_info.h" +#include "sim_utils.h" +#include "system_ability_definition.h" #include "telephony_log_wrapper.h" +#include "uri.h" +#include "values_bucket.h" namespace OHOS { namespace Telephony { @@ -44,9 +44,6 @@ public: int32_t SetDefaultVoiceCard(int32_t slotId); int32_t SetDefaultMessageCard(int32_t slotId); int32_t SetDefaultCellularData(int32_t slotId); - bool RemoveDefaultVoiceCard(); - bool RemoveDefaultMessageCard(); - bool RemoveDefaultCellularCard(); int32_t InsertData(int64_t &id, const NativeRdb::ValuesBucket &values); int32_t QueryDataBySlotId(int32_t slotId, SimRdbInfo &simBean); @@ -61,8 +58,8 @@ public: private: std::shared_ptr CreateDataAHelper(); int Insert(const NativeRdb::ValuesBucket &values); - std::shared_ptr Query(std::vector &columns, - const NativeRdb::DataAbilityPredicates &predicates); + std::shared_ptr Query( + std::vector &columns, const NativeRdb::DataAbilityPredicates &predicates); int Update(const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates); int Delete(const NativeRdb::DataAbilityPredicates &predicates); void SaveDataToBean(std::shared_ptr result, SimRdbInfo &simBean); @@ -71,6 +68,13 @@ private: const static int32_t SUCCESS = 1; std::shared_ptr helper_ = nullptr; }; + +enum class DefaultCardType { + MAIN, + VOICE, + SMS, + DATA, +}; } // namespace Telephony } // namespace OHOS -#endif // TELEPHONY_SIM_RDB_HELPER_H \ No newline at end of file +#endif // TELEPHONY_SIM_RDB_HELPER_H diff --git a/services/sim/src/multi_sim_controller.cpp b/services/sim/src/multi_sim_controller.cpp index b01d606df..222692399 100644 --- a/services/sim/src/multi_sim_controller.cpp +++ b/services/sim/src/multi_sim_controller.cpp @@ -14,6 +14,7 @@ */ #include "multi_sim_controller.h" + #include "string_ex.h" namespace OHOS { @@ -121,9 +122,9 @@ bool MultiSimController::InitActive(int slotId) if (IsSimActive(slotId) && !simStateManager_->HasSimCard()) { if (result && SetActiveSim(slotId, DEACTIVE, true)) { result = true; - } else { + } else { result = false; - } // force set to database DEACTIVE and avoid duplicate + } // force set to database DEACTIVE and avoid duplicate } return result; } @@ -251,8 +252,8 @@ void MultiSimController::SortCache() sortCache.emplace_back(emptyUnit); } for (size_t j = 0; j < count; j++) { - TELEPHONY_LOGI("MultiSimController::index = %{public}d j = %{public}lu", - localCacheInfo_[j].slotIndex, (unsigned long)j); + TELEPHONY_LOGI( + "MultiSimController::index = %{public}d j = %{public}lu", localCacheInfo_[j].slotIndex, (unsigned long)j); sortCache[localCacheInfo_[j].slotIndex] = localCacheInfo_[j]; } localCacheInfo_ = sortCache; @@ -436,19 +437,7 @@ bool MultiSimController::SetDefaultVoiceSlotId(int32_t slotId) TELEPHONY_LOGE("MultiSimController::SetDefaultVoiceSlotId failed by nullptr"); return false; } - if (slotId == DEFAULT_SIM_SLOT_ID_REMOVE) { - int32_t result = simDbHelper_->RemoveDefaultVoiceCard(); - if (result == INVALID_VALUE) { - TELEPHONY_LOGE("MultiSimController::SetDefaultVoiceSlotId get Data Base failed"); - return false; - } - int32_t i = DEFAULT_SIM_SLOT_ID; - for (; i < maxCount_; i++) { - localCacheInfo_[i].isVoiceCard = NOT_MAIN; - } - return AnnounceDefaultVoiceSlotIdChanged(slotId); - } - if ((uint32_t)slotId >= localCacheInfo_.size() || (int32_t)slotId < DEFAULT_SIM_SLOT_ID_REMOVE) { + if (slotId >= (int32_t)localCacheInfo_.size() || slotId < DEFAULT_SIM_SLOT_ID_REMOVE) { TELEPHONY_LOGE("MultiSimController::SetDefaultVoiceSlotId failed by out of range"); return false; } @@ -501,19 +490,7 @@ bool MultiSimController::SetDefaultSmsSlotId(int32_t slotId) TELEPHONY_LOGE("MultiSimController::SetDefaultSmsSlotId failed by nullptr"); return false; } - if (slotId == DEFAULT_SIM_SLOT_ID_REMOVE) { - int32_t result = simDbHelper_->RemoveDefaultMessageCard(); - if (result == INVALID_VALUE) { - TELEPHONY_LOGE("MultiSimController::SetDefaultSmsSlotId get Data Base failed"); - return false; - } - int32_t i = DEFAULT_SIM_SLOT_ID; - for (; i < maxCount_; i++) { - localCacheInfo_[i].isMessageCard = NOT_MAIN; - } - return AnnounceDefaultSmsSlotIdChanged(slotId); - } - if ((uint32_t)slotId >= localCacheInfo_.size() || (int32_t)slotId < DEFAULT_SIM_SLOT_ID_REMOVE) { + if (slotId >= (int32_t)localCacheInfo_.size() || slotId < DEFAULT_SIM_SLOT_ID_REMOVE) { TELEPHONY_LOGE("MultiSimController::SetDefaultSmsSlotId failed by out of range"); return false; } @@ -553,19 +530,7 @@ bool MultiSimController::SetDefaultCellularDataSlotId(int32_t slotId) TELEPHONY_LOGE("MultiSimController::SetDefaultCellularDataSlotId failed by nullptr"); return false; } - if (slotId == DEFAULT_SIM_SLOT_ID_REMOVE) { - int32_t result = simDbHelper_->RemoveDefaultCellularCard(); - if (result == INVALID_VALUE) { - TELEPHONY_LOGE("MultiSimController::SetDefaultCellularDataSlotId get Data Base failed"); - return false; - } - int32_t i = DEFAULT_SIM_SLOT_ID; - for (; i < maxCount_; i++) { - localCacheInfo_[i].isCellularDataCard = NOT_MAIN; - } - return AnnounceDefaultCellularDataSlotIdChanged(slotId); - } - if ((uint32_t)slotId >= localCacheInfo_.size() || (int32_t)slotId < DEFAULT_SIM_SLOT_ID_REMOVE) { + if (slotId >= (int32_t)localCacheInfo_.size() || slotId < DEFAULT_SIM_SLOT_ID_REMOVE) { TELEPHONY_LOGE("MultiSimController::SetDefaultCellularDataSlotId failed by out of range"); return false; } @@ -793,8 +758,7 @@ bool MultiSimController::SetIccId(int32_t slotId, std::u16string iccId) bool MultiSimController::SetRadioProtocol(int32_t slotId, int32_t protocol) { - TELEPHONY_LOGI( - "MultiSimController::SetRadioProtocol slotId = %{public}d protocol = %{public}d", slotId, protocol); + TELEPHONY_LOGI("MultiSimController::SetRadioProtocol slotId = %{public}d protocol = %{public}d", slotId, protocol); if (radioCapController_ == nullptr) { TELEPHONY_LOGE("MultiSimController::SetRadioProtocol failed by nullptr"); return false; diff --git a/services/sim/src/sim_account_manager.cpp b/services/sim/src/sim_account_manager.cpp index 706a808a8..2deb626bd 100755 --- a/services/sim/src/sim_account_manager.cpp +++ b/services/sim/src/sim_account_manager.cpp @@ -136,6 +136,10 @@ bool SimAccountManager::SetDefaultVoiceSlotId(int32_t slotId) TELEPHONY_LOGE("SimAccountManager::SetDefaultVoiceSlotId failed by nullptr"); return false; } + if (!IsValidSlotIdForDefault(slotId)) { + TELEPHONY_LOGE("SimAccountManager::SetDefaultVoiceSlotId invalid slotId = %{public}d", slotId); + return false; + } return multiSimController_->SetDefaultVoiceSlotId(slotId); } @@ -145,7 +149,7 @@ bool SimAccountManager::SetDefaultSmsSlotId(int32_t slotId) TELEPHONY_LOGE("SimAccountManager::SetDefaultSmsSlotId failed by nullptr"); return false; } - if (!IsValidSlotId(slotId)) { + if (!IsValidSlotIdForDefault(slotId)) { TELEPHONY_LOGE("SimAccountManager::SetDefaultSmsSlotId invalid slotId = %{public}d", slotId); return false; } @@ -177,7 +181,7 @@ bool SimAccountManager::SetDefaultCellularDataSlotId(int32_t slotId) TELEPHONY_LOGE("SimAccountManager::SetDefaultCellularDataSlotId failed by nullptr"); return false; } - if (!IsValidSlotId(slotId)) { + if (!IsValidSlotIdForDefault(slotId)) { TELEPHONY_LOGE("SimAccountManager::SetDefaultCellularDataSlotId invalid slotId = %{public}d", slotId); return false; } @@ -306,6 +310,16 @@ bool SimAccountManager::IsValidSlotId(int32_t slotId) } } +bool SimAccountManager::IsValidSlotIdForDefault(int32_t slotId) +{ + int32_t count = SIM_SLOT_COUNT; + if ((slotId >= DEFAULT_SIM_SLOT_ID_REMOVE) && (slotId < count)) { + return true; + } else { + return false; + } +} + bool SimAccountManager::HasOperatorPrivileges(const int32_t slotId) { TELEPHONY_LOGI("SimAccountManager::HasOperatorPrivileges begin"); @@ -331,4 +345,4 @@ bool SimAccountManager::HasOperatorPrivileges(const int32_t slotId) return controller->HasOperatorPrivileges(); } } // namespace Telephony -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/sim/src/sim_rdb_helper.cpp b/services/sim/src/sim_rdb_helper.cpp index b62e86e05..a34af7908 100755 --- a/services/sim/src/sim_rdb_helper.cpp +++ b/services/sim/src/sim_rdb_helper.cpp @@ -14,6 +14,7 @@ */ #include "sim_rdb_helper.h" + #include "telephony_types.h" namespace OHOS { @@ -52,8 +53,8 @@ int SimRdbHelper::Insert(const NativeRdb::ValuesBucket &values) return helper_->Insert(simUri, values); } -std::shared_ptr SimRdbHelper::Query(std::vector &columns, - const NativeRdb::DataAbilityPredicates &predicates) +std::shared_ptr SimRdbHelper::Query( + std::vector &columns, const NativeRdb::DataAbilityPredicates &predicates) { if (helper_ == nullptr) { TELEPHONY_LOGE("SimRdbHelper::Query failed by nullptr"); @@ -152,20 +153,13 @@ int32_t SimRdbHelper::SetDefaultMainCard(int32_t slotId) TELEPHONY_LOGI("SimRdbHelper::SetDefaultMainCard = %{public}d", slotId); NativeRdb::DataAbilityPredicates predicates; NativeRdb::ValuesBucket value; + value.PutInt(SimRdbInfo::SLOT_INDEX, slotId); + value.PutInt(SimRdbInfo::CARD_TYPE, static_cast(DefaultCardType::MAIN)); if (helper_ == nullptr) { TELEPHONY_LOGE("SimRdbHelper::SetDefaultMainCard failed by nullptr"); return INVALID_VALUE; } - std::string slot = std::to_string(slotId); - value.PutInt(SimRdbInfo::IS_MAIN_CARD, static_cast(CardSeclectedStatus::OFF)); - - predicates.NotEqualTo(SimRdbInfo::SLOT_INDEX, slot); Uri defaultUri(SimRdbInfo::SIM_RDB_DEFAULT_SET_URI); - helper_->Update(defaultUri, value, predicates); - value.Clear(); - - value.PutInt(SimRdbInfo::IS_MAIN_CARD, static_cast(CardSeclectedStatus::ON)); - predicates.EqualTo(SimRdbInfo::SLOT_INDEX, slot); return helper_->Update(defaultUri, value, predicates); } @@ -174,35 +168,12 @@ int32_t SimRdbHelper::SetDefaultVoiceCard(int32_t slotId) TELEPHONY_LOGI("SimRdbHelper::SetDefaultVoiceCard = %{public}d", slotId); NativeRdb::DataAbilityPredicates predicates; NativeRdb::ValuesBucket value; + value.PutInt(SimRdbInfo::SLOT_INDEX, slotId); + value.PutInt(SimRdbInfo::CARD_TYPE, static_cast(DefaultCardType::VOICE)); if (helper_ == nullptr) { TELEPHONY_LOGE("SimRdbHelper::SetDefaultVoiceCard failed by nullptr"); return INVALID_VALUE; } - std::string slot = std::to_string(slotId); - value.PutInt(SimRdbInfo::IS_VOICE_CARD, static_cast(CardSeclectedStatus::OFF)); - - predicates.NotEqualTo(SimRdbInfo::SLOT_INDEX, slot); - Uri defaultUri(SimRdbInfo::SIM_RDB_DEFAULT_SET_URI); - helper_->Update(defaultUri, value, predicates); - value.Clear(); - - value.PutInt(SimRdbInfo::IS_VOICE_CARD, static_cast(CardSeclectedStatus::ON)); - predicates.EqualTo(SimRdbInfo::SLOT_INDEX, slot); - return helper_->Update(defaultUri, value, predicates); -} - -bool SimRdbHelper::RemoveDefaultVoiceCard() -{ - TELEPHONY_LOGI("SimRdbHelper::RemoveDefaultVoiceCard"); - NativeRdb::DataAbilityPredicates predicates; - NativeRdb::ValuesBucket value; - if (helper_ == nullptr) { - TELEPHONY_LOGE("SimRdbHelper::RemoveDefaultVoiceCard failed by nullptr"); - return false; - } - std::string slot = std::to_string(DEFAULT_SIM_SLOT_ID_REMOVE); - value.PutInt(SimRdbInfo::IS_VOICE_CARD, static_cast(CardSeclectedStatus::OFF)); - predicates.NotEqualTo(SimRdbInfo::SLOT_INDEX, slot); Uri defaultUri(SimRdbInfo::SIM_RDB_DEFAULT_SET_URI); return helper_->Update(defaultUri, value, predicates); } @@ -212,78 +183,31 @@ int32_t SimRdbHelper::SetDefaultMessageCard(int32_t slotId) TELEPHONY_LOGI("SimRdbHelper::SetDefaultMessageCard = %{public}d", slotId); NativeRdb::DataAbilityPredicates predicates; NativeRdb::ValuesBucket value; + value.PutInt(SimRdbInfo::SLOT_INDEX, slotId); + value.PutInt(SimRdbInfo::CARD_TYPE, static_cast(DefaultCardType::SMS)); if (helper_ == nullptr) { TELEPHONY_LOGE("SimRdbHelper::SetDefaultMessageCard failed by nullptr"); return INVALID_VALUE; } - std::string slot = std::to_string(slotId); - value.PutInt(SimRdbInfo::IS_MESSAGE_CARD, static_cast(CardSeclectedStatus::OFF)); - - predicates.NotEqualTo(SimRdbInfo::SLOT_INDEX, slot); - Uri defaultUri(SimRdbInfo::SIM_RDB_DEFAULT_SET_URI); - helper_->Update(defaultUri, value, predicates); - value.Clear(); - - value.PutInt(SimRdbInfo::IS_MESSAGE_CARD, static_cast(CardSeclectedStatus::ON)); - predicates.EqualTo(SimRdbInfo::SLOT_INDEX, slot); - return helper_->Update(defaultUri, value, predicates); -} - -bool SimRdbHelper::RemoveDefaultMessageCard() -{ - TELEPHONY_LOGI("SimRdbHelper::RemoveDefaultVoiceCard"); - NativeRdb::DataAbilityPredicates predicates; - NativeRdb::ValuesBucket value; - if (helper_ == nullptr) { - TELEPHONY_LOGE("SimRdbHelper::RemoveDefaultVoiceCard failed by nullptr"); - return false; - } - std::string slot = std::to_string(DEFAULT_SIM_SLOT_ID_REMOVE); - value.PutInt(SimRdbInfo::IS_MESSAGE_CARD, static_cast(CardSeclectedStatus::OFF)); - - predicates.NotEqualTo(SimRdbInfo::SLOT_INDEX, slot); Uri defaultUri(SimRdbInfo::SIM_RDB_DEFAULT_SET_URI); return helper_->Update(defaultUri, value, predicates); } int32_t SimRdbHelper::SetDefaultCellularData(int32_t slotId) { - TELEPHONY_LOGI("SimRdbHelper::SetDefaultMessageCard = %{public}d", slotId); + TELEPHONY_LOGI("SimRdbHelper::SetDefaultCellularData = %{public}d", slotId); NativeRdb::DataAbilityPredicates predicates; NativeRdb::ValuesBucket value; + value.PutInt(SimRdbInfo::SLOT_INDEX, slotId); + value.PutInt(SimRdbInfo::CARD_TYPE, static_cast(DefaultCardType::DATA)); if (helper_ == nullptr) { - TELEPHONY_LOGE("SimRdbHelper::SetDefaultMessageCard failed by nullptr"); + TELEPHONY_LOGE("SimRdbHelper::SetDefaultCellularData failed by nullptr"); return INVALID_VALUE; } - std::string slot = std::to_string(slotId); - value.PutInt(SimRdbInfo::IS_CELLULAR_DATA_CARD, static_cast(CardSeclectedStatus::OFF)); - - predicates.NotEqualTo(SimRdbInfo::SLOT_INDEX, slot); - Uri defaultUri(SimRdbInfo::SIM_RDB_DEFAULT_SET_URI); - helper_->Update(defaultUri, value, predicates); - value.Clear(); - - value.PutInt(SimRdbInfo::IS_CELLULAR_DATA_CARD, static_cast(CardSeclectedStatus::ON)); - predicates.EqualTo(SimRdbInfo::SLOT_INDEX, slot); - return helper_->Update(defaultUri, value, predicates); -} - -bool SimRdbHelper::RemoveDefaultCellularCard() -{ - TELEPHONY_LOGI("SimRdbHelper::RemoveDefaultVoiceCard"); - NativeRdb::DataAbilityPredicates predicates; - NativeRdb::ValuesBucket value; - if (helper_ == nullptr) { - TELEPHONY_LOGE("SimRdbHelper::RemoveDefaultVoiceCard failed by nullptr"); - return false; - } - std::string slot = std::to_string(DEFAULT_SIM_SLOT_ID_REMOVE); - value.PutInt(SimRdbInfo::IS_CELLULAR_DATA_CARD, static_cast(CardSeclectedStatus::OFF)); - - predicates.NotEqualTo(SimRdbInfo::SLOT_INDEX, slot); Uri defaultUri(SimRdbInfo::SIM_RDB_DEFAULT_SET_URI); return helper_->Update(defaultUri, value, predicates); } + int32_t SimRdbHelper::InsertData(int64_t &id, const NativeRdb::ValuesBucket &values) { TELEPHONY_LOGI("SimRdbHelper::InsertData"); @@ -446,4 +370,3 @@ int32_t SimRdbHelper::ClearData() } } // namespace Telephony } // namespace OHOS - diff --git a/services/tel_ril/include/tel_ril_manager.h b/services/tel_ril/include/tel_ril_manager.h index 9ef0545e7..b0c649af8 100644 --- a/services/tel_ril/include/tel_ril_manager.h +++ b/services/tel_ril/include/tel_ril_manager.h @@ -163,6 +163,25 @@ public: int32_t SetLocateUpdates( int32_t slotId, HRilRegNotifyMode mode, const AppExecFwk::InnerEvent::Pointer &response) override; + /** + * @param slotId is the card slot index number + * @param newFilter is the notification filter with bits in HRilNotificationFilter + * @param response is the feedback info after setting notification filter + * @return int32_t Indicates if notification filter is set successfully + */ + int32_t SetNotificationFilter( + int32_t slotId, int32_t newFilter, const AppExecFwk::InnerEvent::Pointer &response) override; + + /** + * @param slotId is the card slot index number + * @param deviceStateType is the device state type in HRilDeviceStateType + * @param deviceStateOn Indicates the specific device state is on + * @param response is the feedback info after setting device state + * @return int32_t Indicates if device state is set successfully + */ + int32_t SetDeviceState(int32_t slotId, int32_t deviceStateType, bool deviceStateOn, + const AppExecFwk::InnerEvent::Pointer &response) override; + int32_t GetBasebandVersion(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override; /** diff --git a/services/tel_ril/include/tel_ril_network.h b/services/tel_ril/include/tel_ril_network.h index acd45afa6..3de808412 100644 --- a/services/tel_ril/include/tel_ril_network.h +++ b/services/tel_ril/include/tel_ril_network.h @@ -44,6 +44,9 @@ public: int32_t GetCurrentCellInfo(const AppExecFwk::InnerEvent::Pointer &response); int32_t GetPhysicalChannelConfig(const AppExecFwk::InnerEvent::Pointer &response); int32_t SetLocateUpdates(HRilRegNotifyMode mode, const AppExecFwk::InnerEvent::Pointer &response); + int32_t SetNotificationFilter(int32_t newFilter, const AppExecFwk::InnerEvent::Pointer &response); + int32_t SetDeviceState( + int32_t deviceStateType, bool deviceStateOn, const AppExecFwk::InnerEvent::Pointer &response); // ril unsol int32_t SignalStrengthUpdated(MessageParcel &data); @@ -81,6 +84,8 @@ public: int32_t GetPreferredNetworkResponse(MessageParcel &data); int32_t GetPhysicalChannelConfigResponse(MessageParcel &data); int32_t SetLocateUpdatesResponse(MessageParcel &data); + int32_t SetNotificationFilterResponse(MessageParcel &data); + int32_t SetDeviceStateResponse(MessageParcel &data); /** * @brief Current operator ons or eons response diff --git a/services/tel_ril/src/tel_ril_manager.cpp b/services/tel_ril/src/tel_ril_manager.cpp index 1e5fad6b8..d8506066c 100644 --- a/services/tel_ril/src/tel_ril_manager.cpp +++ b/services/tel_ril/src/tel_ril_manager.cpp @@ -692,6 +692,19 @@ int32_t TelRilManager::SetLocateUpdates( return TaskSchedule(response, "TelRilNetwork", GetTelRilNetwork(slotId), &TelRilNetwork::SetLocateUpdates, mode); } +int32_t TelRilManager::SetNotificationFilter( + int32_t slotId, int32_t newFilter, const AppExecFwk::InnerEvent::Pointer &response) +{ + return TaskSchedule( + response, "TelRilNetwork", GetTelRilNetwork(slotId), &TelRilNetwork::SetNotificationFilter, newFilter); +} + +int32_t TelRilManager::SetDeviceState( + int32_t slotId, int32_t deviceStateType, bool deviceStateOn, const AppExecFwk::InnerEvent::Pointer &response) +{ + return TaskSchedule(response, "TelRilNetwork", GetTelRilNetwork(slotId), &TelRilNetwork::SetDeviceState, + deviceStateType, deviceStateOn); +} /*********************** TelRilNetwork end ****************************/ /*********************** TelRilSms start ******************************/ int32_t TelRilManager::SendGsmSms( diff --git a/services/tel_ril/src/tel_ril_network.cpp b/services/tel_ril/src/tel_ril_network.cpp index 9a53c3d6b..203dfe0b7 100644 --- a/services/tel_ril/src/tel_ril_network.cpp +++ b/services/tel_ril/src/tel_ril_network.cpp @@ -54,6 +54,8 @@ void TelRilNetwork::AddHandlerToMap() memberFuncMap_[HREQ_NETWORK_GET_RADIO_CAPABILITY] = &TelRilNetwork::GetRadioCapabilityResponse; memberFuncMap_[HREQ_NETWORK_GET_PHYSICAL_CHANNEL_CONFIG] = &TelRilNetwork::GetPhysicalChannelConfigResponse; memberFuncMap_[HREQ_NETWORK_SET_LOCATE_UPDATES] = &TelRilNetwork::SetLocateUpdatesResponse; + memberFuncMap_[HREQ_NETWORK_SET_NOTIFICATION_FILTER] = &TelRilNetwork::SetNotificationFilterResponse; + memberFuncMap_[HREQ_NETWORK_SET_DEVICE_STATE] = &TelRilNetwork::SetDeviceStateResponse; } TelRilNetwork::TelRilNetwork(int32_t slotId, sptr cellularRadio, @@ -657,6 +659,55 @@ int32_t TelRilNetwork::SetLocateUpdates(HRilRegNotifyMode mode, const AppExecFwk } } +int32_t TelRilNetwork::SetNotificationFilter(int32_t newFilter, const AppExecFwk::InnerEvent::Pointer &response) +{ + std::shared_ptr telRilRequest = CreateTelRilRequest(HREQ_NETWORK_SET_NOTIFICATION_FILTER, response); + if (telRilRequest == nullptr) { + TELEPHONY_LOGE("TelRilNetwork SetNotificationFilter::telRilRequest is nullptr"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + if (cellularRadio_ != nullptr) { + MessageParcel data; + MessageParcel reply; + data.WriteInt32(slotId_); + data.WriteInt32(telRilRequest->serialId_); + data.WriteInt32(static_cast(newFilter)); + OHOS::MessageOption option = {OHOS::MessageOption::TF_ASYNC}; + cellularRadio_->SendRequest(HREQ_NETWORK_SET_NOTIFICATION_FILTER, data, reply, option); + TELEPHONY_LOGI("TelRilNetwork::SetNotificationFilter: %{public}d", newFilter); + return TELEPHONY_ERR_SUCCESS; + } else { + TELEPHONY_LOGE("%{public}s cellularRadio_ == nullptr", __func__); + return ErrorResponse(telRilRequest->serialId_, HRilErrType::HRIL_ERR_INVALID_RESPONSE); + } +} + +int32_t TelRilNetwork::SetDeviceState( + int32_t deviceStateType, bool deviceStateOn, const AppExecFwk::InnerEvent::Pointer &response) +{ + std::shared_ptr telRilRequest = CreateTelRilRequest(HREQ_NETWORK_SET_DEVICE_STATE, response); + if (telRilRequest == nullptr) { + TELEPHONY_LOGE("TelRilNetwork SetDeviceState::telRilRequest is nullptr"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + if (cellularRadio_ != nullptr) { + MessageParcel data; + MessageParcel reply; + data.WriteInt32(slotId_); + data.WriteInt32(telRilRequest->serialId_); + data.WriteInt32(static_cast(deviceStateType)); + data.WriteInt32(static_cast(deviceStateOn)); + OHOS::MessageOption option = {OHOS::MessageOption::TF_ASYNC}; + cellularRadio_->SendRequest(HREQ_NETWORK_SET_DEVICE_STATE, data, reply, option); + TELEPHONY_LOGI("TelRilNetwork::SetDeviceState deviceStateType:%{public}d, deviceState:%{public}d", + deviceStateType, deviceStateOn); + return TELEPHONY_ERR_SUCCESS; + } else { + TELEPHONY_LOGE("%{public}s cellularRadio_ == nullptr", __func__); + return ErrorResponse(telRilRequest->serialId_, HRilErrType::HRIL_ERR_INVALID_RESPONSE); + } +} + int32_t TelRilNetwork::GetSignalStrengthResponse(MessageParcel &data) { const size_t readSpSize = sizeof(struct HRilRadioResponseInfo); @@ -1142,5 +1193,71 @@ int32_t TelRilNetwork::SetLocateUpdatesResponse(MessageParcel &data) return TELEPHONY_ERR_LOCAL_PTR_NULL; } } + +int32_t TelRilNetwork::SetNotificationFilterResponse(MessageParcel &data) +{ + const size_t readSpSize = sizeof(struct HRilRadioResponseInfo); + const uint8_t *spBuffer = data.ReadUnpadBuffer(readSpSize); + if (spBuffer == nullptr) { + TELEPHONY_LOGE("TelRilNetwork::SetNotificationFilterResponse read spBuffer failed"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + const struct HRilRadioResponseInfo *radioResponseInfo = + reinterpret_cast(spBuffer); + if (radioResponseInfo == nullptr) { + TELEPHONY_LOGE("ERROR : SetNotificationFilterResponse --> radioResponseInfo == nullptr !!!"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + std::shared_ptr telRilRequest = FindTelRilRequest(*radioResponseInfo); + if (telRilRequest != nullptr && telRilRequest->pointer_ != nullptr) { + if (radioResponseInfo->error == HRilErrType::NONE) { + const std::shared_ptr &handler = telRilRequest->pointer_->GetOwner(); + if (handler == nullptr) { + TELEPHONY_LOGE("SetNotificationFilterResponse handler is nullptr: this is the expected result"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + handler->SendEvent(telRilRequest->pointer_); + return TELEPHONY_ERR_SUCCESS; + } else { + return ErrorResponse(telRilRequest, *radioResponseInfo); + } + } else { + TELEPHONY_LOGE("telRilRequest or pointer_ == nullptr !"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } +} + +int32_t TelRilNetwork::SetDeviceStateResponse(MessageParcel &data) +{ + const size_t readSpSize = sizeof(struct HRilRadioResponseInfo); + const uint8_t *spBuffer = data.ReadUnpadBuffer(readSpSize); + if (spBuffer == nullptr) { + TELEPHONY_LOGE("TelRilNetwork::SetDeviceStateResponse read spBuffer failed"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + const struct HRilRadioResponseInfo *radioResponseInfo = + reinterpret_cast(spBuffer); + if (radioResponseInfo == nullptr) { + TELEPHONY_LOGE("ERROR : SetDeviceStateResponse --> radioResponseInfo == nullptr !!!"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + std::shared_ptr telRilRequest = FindTelRilRequest(*radioResponseInfo); + if (telRilRequest != nullptr && telRilRequest->pointer_ != nullptr) { + if (radioResponseInfo->error == HRilErrType::NONE) { + const std::shared_ptr &handler = telRilRequest->pointer_->GetOwner(); + if (handler == nullptr) { + TELEPHONY_LOGE("SetDeviceStateResponse handler is nullptr: this is the expected result"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + handler->SendEvent(telRilRequest->pointer_); + return TELEPHONY_ERR_SUCCESS; + } else { + return ErrorResponse(telRilRequest, *radioResponseInfo); + } + } else { + TELEPHONY_LOGE("telRilRequest or pointer_ == nullptr !"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } +} } // namespace Telephony } // namespace OHOS diff --git a/services/tel_ril/test/tel_ril_test.cpp b/services/tel_ril/test/tel_ril_test.cpp index 710b3952a..853c29032 100755 --- a/services/tel_ril/test/tel_ril_test.cpp +++ b/services/tel_ril/test/tel_ril_test.cpp @@ -114,6 +114,8 @@ enum class DiffInterfaceId { TEST_GET_VOICE_RADIO_INFO, TEST_GET_PHYSICAL_CHANNEL_CONFIG, TEST_SET_LOCATE_UPDATES, + TEST_SET_NOTIFICATION_FILTER, + TEST_SET_DEVICE_STATE, TEST_SET_USSD, TEST_GET_USSD, TEST_SET_MUTE, @@ -315,6 +317,8 @@ public: void OnRequestGetVoiceRadioTechnology(int32_t slotId, const std::shared_ptr &handler); void OnRequestGetPhysicalChannelConfig(int32_t slotId, const std::shared_ptr &handler); void OnRequestSetLocateUpdatesTest(int32_t slotId, const std::shared_ptr &handler); + void OnRequestSetNotificationFilterTest(int32_t slotId, const std::shared_ptr &handler); + void OnRequestSetDeviceStateTest(int32_t slotId, const std::shared_ptr &handler); void OnRequestGetImsCallListTest(int32_t slotId, const std::shared_ptr &handler); void OnRequestSetCallPreferenceModeTest(int32_t slotId, const std::shared_ptr &handler); @@ -507,6 +511,8 @@ void TelRilTest::OnInitNetwork() memberFuncMap_[DiffInterfaceId::TEST_GET_VOICE_RADIO_INFO] = &TelRilTest::OnRequestGetVoiceRadioTechnology; memberFuncMap_[DiffInterfaceId::TEST_GET_PHYSICAL_CHANNEL_CONFIG] = &TelRilTest::OnRequestGetPhysicalChannelConfig; memberFuncMap_[DiffInterfaceId::TEST_SET_LOCATE_UPDATES] = &TelRilTest::OnRequestSetLocateUpdatesTest; + memberFuncMap_[DiffInterfaceId::TEST_SET_NOTIFICATION_FILTER] = &TelRilTest::OnRequestSetNotificationFilterTest; + memberFuncMap_[DiffInterfaceId::TEST_SET_DEVICE_STATE] = &TelRilTest::OnRequestSetDeviceStateTest; } void TelRilTest::OnInitForRegister(int32_t slotId, const std::shared_ptr &handler) @@ -1696,6 +1702,39 @@ void TelRilTest::OnRequestSetLocateUpdatesTest( } } +void TelRilTest::OnRequestSetNotificationFilterTest( + int32_t slotId, const std::shared_ptr &handler) +{ + auto event = AppExecFwk::InnerEvent::Get(TYPESBITMAP); + if (event != nullptr && telRilManager_ != nullptr) { + event->SetOwner(handler); + int32_t filter = 0; + std::cout << "Please input filter: " << endl; + std::cin >> filter; + TELEPHONY_LOGI("TelRilTest::OnRequestSetNotificationFilterTest -->"); + telRilManager_->SetNotificationFilter(slotId, filter, event); + TELEPHONY_LOGI("TelRilTest::OnRequestSetNotificationFilterTest --> finished"); + } +} + +void TelRilTest::OnRequestSetDeviceStateTest( + int32_t slotId, const std::shared_ptr &handler) +{ + auto event = AppExecFwk::InnerEvent::Get(TYPESBITMAP); + if (event != nullptr && telRilManager_ != nullptr) { + event->SetOwner(handler); + int32_t deviceStateType = 0; + std::cout << "Please input deviceStateType: " << endl; + std::cin >> deviceStateType; + bool deviceStateOn = true; + std::cout << "Please input deviceStateOn: " << endl; + std::cin >> deviceStateOn; + TELEPHONY_LOGI("TelRilTest::OnRequestSetDeviceStateTest -->"); + telRilManager_->SetDeviceState(slotId, deviceStateType, deviceStateOn, event); + TELEPHONY_LOGI("TelRilTest::OnRequestSetDeviceStateTest --> finished"); + } +} + void TelRilTest::OnRequestCallJoinTest(int32_t slotId, const std::shared_ptr &handler) { int32_t callType = 0; /* call type @@ -2374,6 +2413,8 @@ void NetworkTest() cout << (int32_t)DiffInterfaceId::TEST_GET_PHYSICAL_CHANNEL_CONFIG << "--> OnRequestGetPhysicalChannelConfig" << endl; cout << (int32_t)DiffInterfaceId::TEST_SET_LOCATE_UPDATES << "--> OnRequestSetLocateUpdatesTest" << endl; + cout << (int32_t)DiffInterfaceId::TEST_SET_NOTIFICATION_FILTER << "--> OnRequestSetNotificationFilterTest" << endl; + cout << (int32_t)DiffInterfaceId::TEST_SET_DEVICE_STATE << "--> OnRequestSetDeviceStateTest" << endl; } } // namespace } // namespace Telephony diff --git a/test/unittest/tel_ril_gtest/tel_ril_test.cpp b/test/unittest/tel_ril_gtest/tel_ril_test.cpp index 19a485bca..3e666d8c5 100755 --- a/test/unittest/tel_ril_gtest/tel_ril_test.cpp +++ b/test/unittest/tel_ril_gtest/tel_ril_test.cpp @@ -201,6 +201,8 @@ void TelRilTest::InitNetwork() memberFuncMap_[DiffInterfaceId::TEST_GET_VOICE_RADIO_INFO] = &TelRilTest::GetVoiceRadioTechnologyTest; memberFuncMap_[DiffInterfaceId::TEST_GET_PHYSICAL_CHANNEL_CONFIG] = &TelRilTest::GetPhysicalChannelConfigTest; memberFuncMap_[DiffInterfaceId::TEST_SET_LOCATE_UPDATES] = &TelRilTest::SetLocateUpdatesTest; + memberFuncMap_[DiffInterfaceId::TEST_SET_NOTIFICATION_FILTER] = &TelRilTest::SetNotificationFilterTest; + memberFuncMap_[DiffInterfaceId::TEST_SET_DEVICE_STATE] = &TelRilTest::SetDeviceStateTest; } void TelRilTest::InitModem() @@ -1547,6 +1549,47 @@ void TelRilTest::SetLocateUpdatesTest(const std::shared_ptr &handler) +{ + int32_t eventId = static_cast(DiffInterfaceId::TEST_SET_NOTIFICATION_FILTER); + auto event = AppExecFwk::InnerEvent::Get(eventId); + if (event != nullptr && telRilManager_ != nullptr) { + event->SetOwner(handler); + int32_t filter = 1; + TELEPHONY_LOGI("TelRilTest::SetNotificationFilterTest -->"); + telRilManager_->SetNotificationFilter(slotId_, filter, event); + TELEPHONY_LOGI("TelRilTest::SetNotificationFilterTest --> finished"); + bool syncResult = WaitGetResult(eventId, handler, WAIT_TIME_SECOND); + ASSERT_TRUE(syncResult); + } +} + +/** + * @brief Set device state + * + * @param handler + */ +void TelRilTest::SetDeviceStateTest(const std::shared_ptr &handler) +{ + int32_t eventId = static_cast(DiffInterfaceId::TEST_SET_DEVICE_STATE); + auto event = AppExecFwk::InnerEvent::Get(eventId); + if (event != nullptr && telRilManager_ != nullptr) { + event->SetOwner(handler); + int32_t deviceStateType = 0; + bool deviceStateOn = true; + TELEPHONY_LOGI("TelRilTest::SetDeviceStateTest -->"); + telRilManager_->SetDeviceState(slotId_, deviceStateType, deviceStateOn, event); + TELEPHONY_LOGI("TelRilTest::SetDeviceStateTest --> finished"); + bool syncResult = WaitGetResult(eventId, handler, WAIT_TIME_SECOND); + ASSERT_TRUE(syncResult); + } +} + /** * @brief Call merge * @@ -2984,6 +3027,28 @@ HWTEST_F(TelRilTest, Telephony_TelRil_SetLocateUpdatesTest_0101, Function | Medi return; } +/** + * @tc.number Telephony_TelRil_SetNotificationFilterTest_0101 to do ... + * @tc.name Set notification filter + * @tc.desc Function test + */ +HWTEST_F(TelRilTest, Telephony_TelRil_SetNotificationFilterTest_0101, Function | MediumTest | Level3) +{ + ProcessTest(static_cast(DiffInterfaceId::TEST_SET_NOTIFICATION_FILTER), GetHandler()); + return; +} + +/** + * @tc.number Telephony_TelRil_SetDeviceStateTest_0101 to do ... + * @tc.name Set device state + * @tc.desc Function test + */ +HWTEST_F(TelRilTest, Telephony_TelRil_SetDeviceStateTest_0101, Function | MediumTest | Level3) +{ + ProcessTest(static_cast(DiffInterfaceId::TEST_SET_DEVICE_STATE), GetHandler()); + return; +} + /** * @tc.number Telephony_TelRil_SetUssdTest_0101 to do ... * @tc.name Set USSD information diff --git a/test/unittest/tel_ril_gtest/tel_ril_test.h b/test/unittest/tel_ril_gtest/tel_ril_test.h index bb9e33562..9028203cb 100755 --- a/test/unittest/tel_ril_gtest/tel_ril_test.h +++ b/test/unittest/tel_ril_gtest/tel_ril_test.h @@ -112,6 +112,8 @@ enum class DiffInterfaceId { TEST_GET_VOICE_RADIO_INFO, TEST_GET_PHYSICAL_CHANNEL_CONFIG, TEST_SET_LOCATE_UPDATES, + TEST_SET_NOTIFICATION_FILTER, + TEST_SET_DEVICE_STATE, TEST_SET_USSD, TEST_GET_USSD, TEST_SET_CMUT, @@ -246,6 +248,8 @@ private: void GetVoiceRadioTechnologyTest(const std::shared_ptr &handler); void GetPhysicalChannelConfigTest(const std::shared_ptr &handler); void SetLocateUpdatesTest(const std::shared_ptr &handler); + void SetNotificationFilterTest(const std::shared_ptr &handler); + void SetDeviceStateTest(const std::shared_ptr &handler); void SetUssdTest(const std::shared_ptr &handler); void GetUssdTest(const std::shared_ptr &handler); void SetMuteTest(const std::shared_ptr &handler); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 973763f71..d97faac40 100755 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -30,8 +30,11 @@ config("tel_utils_config") { } ohos_shared_library("libtel_common") { + include_dirs = [ "//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include" ] + sources = [ "common/src/str_convert.cpp", + "common/src/telephony_hisysevent.cpp", "common/src/telephony_permission.cpp", "preferences/src/tel_profile_util.cpp", ] @@ -69,6 +72,7 @@ ohos_shared_library("libtel_common") { "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + "hisysevent_native:libhisysevent", "ipc:ipc_single", "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", diff --git a/utils/common/include/telephony_hisysevent.h b/utils/common/include/telephony_hisysevent.h new file mode 100644 index 000000000..a1d3e4568 --- /dev/null +++ b/utils/common/include/telephony_hisysevent.h @@ -0,0 +1,28 @@ +/* + * 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 TELEPHONY_HISYSEVENT_H +#define TELEPHONY_HISYSEVENT_H + +#include + +namespace OHOS { +namespace Telephony { +// CoreService HiSysEvent +void WriteSignalLevelHiSysEvent(const int32_t slotId, const int32_t level); +void WriteNetworkStateHiSysEvent(const int32_t slotId, const int32_t domain, const int32_t tech, const int32_t state); +} // namespace Telephony +} // namespace OHOS +#endif // TELEPHONY_HISYSEVENT_H \ No newline at end of file diff --git a/utils/common/src/telephony_hisysevent.cpp b/utils/common/src/telephony_hisysevent.cpp new file mode 100644 index 000000000..52b968cb2 --- /dev/null +++ b/utils/common/src/telephony_hisysevent.cpp @@ -0,0 +1,48 @@ +/* + * 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 "telephony_hisysevent.h" +#include "hisysevent.h" + +namespace OHOS { +namespace Telephony { +// CoreService HiSysEvent +const std::string CORE_SERVICE_DOMAIN = "CORE_SERVICE"; +const std::string SLOT_ID = "SLOT_ID"; +const std::string SIGNAL_STRENGTH_EVENT = "SIGNAL_LEVEL"; +const std::string SIGANL_LEVEL = "LEVEL"; +const std::string NETWORK_REGISTER_EVENT = "NETWORK_REGISTER"; +const std::string NETWORK_DOMAIN = "REGISTRATION_DOMAIN"; +const std::string NETWORK_TECH = "RADIO_TECH"; +const std::string NETWORK_STATE = "REGISTRATION_STATE"; + +template +static void WriteStatisticEvent(const std::string &domain, const std::string &eventType, Types... args) +{ + HiviewDFX::HiSysEvent::Write(domain, eventType, HiviewDFX::HiSysEvent::EventType::STATISTIC, args...); +} + +void WriteSignalLevelHiSysEvent(const int32_t slotId, const int32_t level) +{ + WriteStatisticEvent(CORE_SERVICE_DOMAIN, SIGNAL_STRENGTH_EVENT, SLOT_ID, slotId, SIGANL_LEVEL, level); +} + +void WriteNetworkStateHiSysEvent(const int32_t slotId, const int32_t domain, const int32_t tech, const int32_t state) +{ + WriteStatisticEvent(CORE_SERVICE_DOMAIN, NETWORK_REGISTER_EVENT, + SLOT_ID, slotId, NETWORK_DOMAIN, domain, NETWORK_TECH, tech, NETWORK_STATE, state); +} +} // namespace Telephony +} // namespace OHOS \ No newline at end of file From eb8e9b5b9604e8a243fa8a5f7300bac933b3876d Mon Sep 17 00:00:00 2001 From: handyohos Date: Fri, 10 Jun 2022 17:48:23 +0800 Subject: [PATCH 2/7] feat: change ril_adapter:hril_innerkits to ril_device_driver_interface:hril_innerkits change ril_adapter:hril_innerkits to ril_device_driver_interface:hril_innerkits for system component. Signed-off-by: handyohos Change-Id: Idba3bb79993df42b5625134e90758599f3b011c3 #I5BLKK --- BUILD.gn | 2 +- frameworks/js/network_search/BUILD.gn | 2 +- frameworks/js/sim/BUILD.gn | 2 +- interfaces/innerkits/BUILD.gn | 2 +- services/network_search/test/BUILD.gn | 2 +- services/sim/test/BUILD.gn | 2 +- services/tel_ril/test/BUILD.gn | 2 +- test/unittest/core_service_gtest/BUILD.gn | 2 +- test/unittest/tel_ril_gtest/BUILD.gn | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 1ab49ea8e..4b676dfdd 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -155,7 +155,7 @@ ohos_shared_library("tel_core_service") { "power_manager_native:powermgr_client", "relational_store:native_rdb", "resource_management:global_resmgr", - "ril_adapter:hril_innerkits", + "ril_device_driver_interface:hril_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "startup_l2:syspara", diff --git a/frameworks/js/network_search/BUILD.gn b/frameworks/js/network_search/BUILD.gn index 8c3268668..da503004f 100755 --- a/frameworks/js/network_search/BUILD.gn +++ b/frameworks/js/network_search/BUILD.gn @@ -59,7 +59,7 @@ ohos_shared_library("radio") { "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "ril_adapter:hril_innerkits", + "ril_device_driver_interface:hril_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "startup_l2:syspara", diff --git a/frameworks/js/sim/BUILD.gn b/frameworks/js/sim/BUILD.gn index 8c8fd28c3..68172a92e 100755 --- a/frameworks/js/sim/BUILD.gn +++ b/frameworks/js/sim/BUILD.gn @@ -42,7 +42,7 @@ ohos_shared_library("sim") { "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "ril_adapter:hril_innerkits", + "ril_device_driver_interface:hril_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 707cd3e25..4f39f6456 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -77,7 +77,7 @@ ohos_shared_library("tel_core_service_api") { external_deps = [ "eventhandler:libeventhandler", "ipc:ipc_core", - "ril_adapter:hril_innerkits", + "ril_device_driver_interface:hril_innerkits", "samgr_standard:samgr_proxy", "startup_l2:syspara", "utils_base:utils", diff --git a/services/network_search/test/BUILD.gn b/services/network_search/test/BUILD.gn index b051fb5c6..c20409b81 100644 --- a/services/network_search/test/BUILD.gn +++ b/services/network_search/test/BUILD.gn @@ -44,7 +44,7 @@ ohos_executable("tel_network_search_test") { "core_service:tel_core_service_api", "eventhandler:libeventhandler", "ipc:ipc_core", - "ril_adapter:hril_innerkits", + "ril_device_driver_interface:hril_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/services/sim/test/BUILD.gn b/services/sim/test/BUILD.gn index 1d73eb8d4..05f036410 100755 --- a/services/sim/test/BUILD.gn +++ b/services/sim/test/BUILD.gn @@ -72,7 +72,7 @@ ohos_executable("tel_sim_test") { "eventhandler:libeventhandler", "ipc:ipc_core", "relational_store:native_rdb", - "ril_adapter:hril_innerkits", + "ril_device_driver_interface:hril_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "startup_l2:syspara", diff --git a/services/tel_ril/test/BUILD.gn b/services/tel_ril/test/BUILD.gn index 3193100de..78045a520 100644 --- a/services/tel_ril/test/BUILD.gn +++ b/services/tel_ril/test/BUILD.gn @@ -48,7 +48,7 @@ ohos_executable("tel_ril_test") { "eventhandler:libeventhandler", "ipc:ipc_core", "power_manager_native:powermgr_client", - "ril_adapter:hril_innerkits", + "ril_device_driver_interface:hril_innerkits", "samgr_standard:samgr_proxy", "startup_l2:syspara", ] diff --git a/test/unittest/core_service_gtest/BUILD.gn b/test/unittest/core_service_gtest/BUILD.gn index 843bc8541..80276e5bc 100755 --- a/test/unittest/core_service_gtest/BUILD.gn +++ b/test/unittest/core_service_gtest/BUILD.gn @@ -49,7 +49,7 @@ ohos_unittest("tel_core_service_gtest") { "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", "ipc:ipc_core", - "ril_adapter:hril_innerkits", + "ril_device_driver_interface:hril_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/test/unittest/tel_ril_gtest/BUILD.gn b/test/unittest/tel_ril_gtest/BUILD.gn index 329bd0144..544e41cd6 100644 --- a/test/unittest/tel_ril_gtest/BUILD.gn +++ b/test/unittest/tel_ril_gtest/BUILD.gn @@ -51,7 +51,7 @@ ohos_unittest("tel_ril_gtest") { "eventhandler:libeventhandler", "ipc:ipc_core", "power_manager_native:powermgr_client", - "ril_adapter:hril_innerkits", + "ril_device_driver_interface:hril_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "startup_l2:syspara", From 26ee5615541330b046d79925eba8ffcba353fee4 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Sat, 11 Jun 2022 09:39:39 +0800 Subject: [PATCH 3/7] fix filter enum name Signed-off-by: liujiandong --- services/network_search/src/device_state_handler.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/network_search/src/device_state_handler.cpp b/services/network_search/src/device_state_handler.cpp index 09cd5c4fd..54c793e5b 100644 --- a/services/network_search/src/device_state_handler.cpp +++ b/services/network_search/src/device_state_handler.cpp @@ -79,15 +79,15 @@ void DeviceStateHandler::ProcessDeviceState() SetDeviceState(LOW_DATA_STATE, isLowData_); } - int32_t newFilter = NONE; + int32_t newFilter = NOTIFICATION_FILTER_NONE; if (IsSignalStrengthNotificationExpected()) { - newFilter |= SIGNAL_STRENGTH; + newFilter |= NOTIFICATION_FILTER_SIGNAL_STRENGTH; } if (IsHighPowerConsumption()) { - newFilter |= NETWORK_STATE; - newFilter |= DATA_CALL; - newFilter |= PHYSICAL_CHANNEL_CONFIG; + newFilter |= NOTIFICATION_FILTER_NETWORK_STATE; + newFilter |= NOTIFICATION_FILTER_DATA_CALL; + newFilter |= NOTIFICATION_FILTER_PHYSICAL_CHANNEL_CONFIG; } SetNotificationFilter(newFilter, false); From ece999619b1ef43894be4cc98caa65ec31e106bb Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Tue, 14 Jun 2022 15:00:05 +0800 Subject: [PATCH 4/7] fix crash Signed-off-by: liujiandong --- services/network_search/src/signal_info.cpp | 6 +++++- services/tel_ril/src/tel_ril_sim.cpp | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/services/network_search/src/signal_info.cpp b/services/network_search/src/signal_info.cpp index 06bd4e00e..57e14cffe 100755 --- a/services/network_search/src/signal_info.cpp +++ b/services/network_search/src/signal_info.cpp @@ -139,7 +139,11 @@ void SignalInfo::ProcessSignalIntensity(int32_t slotId, const AppExecFwk::InnerE std::vector> signals; GetSignalInfoList(signals); DelayedSingleton::GetInstance()->NotifySignalInfoUpdated(slotId, signals); - WriteSignalLevelHiSysEvent(slotId, signals[0]->GetSignalLevel()); + int level = 0; + if (signals.size() != 0) { + level = signals[0]->GetSignalLevel(); + } + WriteSignalLevelHiSysEvent(slotId, level); } PrintfLog(*signalIntensity); } diff --git a/services/tel_ril/src/tel_ril_sim.cpp b/services/tel_ril/src/tel_ril_sim.cpp index 04d0e678b..7b551d3a9 100644 --- a/services/tel_ril/src/tel_ril_sim.cpp +++ b/services/tel_ril/src/tel_ril_sim.cpp @@ -957,6 +957,7 @@ int32_t TelRilSim::GetSimLockStatus(std::string fac, const AppExecFwk::InnerEven simLockInfo.serial = telRilRequest->serialId_; simLockInfo.fac = fac; simLockInfo.mode = MODE; + simLockInfo.classx = 0; simLockInfo.Marshalling(data); MessageParcel reply; OHOS::MessageOption option = {OHOS::MessageOption::TF_ASYNC}; @@ -981,6 +982,7 @@ int32_t TelRilSim::SetSimLock( simLockInfo.fac = fac; simLockInfo.mode = mode; simLockInfo.passwd = passwd; + simLockInfo.classx = 0; simLockInfo.Marshalling(data); MessageParcel reply; OHOS::MessageOption option = {OHOS::MessageOption::TF_ASYNC}; From d6d5d2d63d93586e58af445a42f6160212f38d2b Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Tue, 14 Jun 2022 21:04:22 +0800 Subject: [PATCH 5/7] fix open logical channel Signed-off-by: liujiandong --- .../src/icc_operator_privilege_controller.cpp | 12 +++++-- services/tel_ril/src/tel_ril_sim.cpp | 34 +++++++++++-------- services/tel_ril/test/tel_ril_test.cpp | 11 +++--- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/services/sim/src/icc_operator_privilege_controller.cpp b/services/sim/src/icc_operator_privilege_controller.cpp index a44db5139..6ef13ef51 100644 --- a/services/sim/src/icc_operator_privilege_controller.cpp +++ b/services/sim/src/icc_operator_privilege_controller.cpp @@ -37,7 +37,6 @@ constexpr int32_t P3 = 0x00; constexpr int32_t INT32_INTVALUE = 0; constexpr int32_t INT32_ZERO = 0; constexpr int32_t INT32_FST_NEGATIVE = -1; -constexpr int32_t INT32_FST_POSITIVE = 1; constexpr size_t FST_POS = 0; static std::string_view Strip(const std::string_view &src) @@ -318,7 +317,16 @@ void IccOperatorPrivilegeController::ProcessOpenLogicalChannelDone(const AppExec return; } TELEPHONY_LOGI("Will to SimTransmitApduLogicalChannel"); - state_->currentChannelId = INT32_FST_POSITIVE; + auto resultPtr = event->GetUniqueObject(); + if (resultPtr == nullptr) { + TELEPHONY_LOGE("the data of result is nullptr! then will Close Logical Channel"); + return; + } + state_->currentChannelId = resultPtr->channelId; + if (state_->currentChannelId <= INT32_ZERO) { + TELEPHONY_LOGE("the logical channel transmit Unexpected shutdown"); + return; + } auto transmitEvent = GenCallBackEvent(shared_from_this(), MSG_TRANSMIT_LOGICAL_CHANNEL_DONE); ApduSimIORequestInfo reqInfo; reqInfo.channelId = state_->currentChannelId; diff --git a/services/tel_ril/src/tel_ril_sim.cpp b/services/tel_ril/src/tel_ril_sim.cpp index 04d0e678b..152477265 100644 --- a/services/tel_ril/src/tel_ril_sim.cpp +++ b/services/tel_ril/src/tel_ril_sim.cpp @@ -686,27 +686,31 @@ int32_t TelRilSim::SimOpenLogicalChannelResponse(MessageParcel &data) TELEPHONY_LOGE("spBuffer == nullptr"); return TELEPHONY_ERR_LOCAL_PTR_NULL; } + std::unique_ptr openLogicalChannelResult = + std::make_unique(); + openLogicalChannelResult->ReadFromParcel(data); + const struct HRilRadioResponseInfo *radioResponseInfo = reinterpret_cast(spBuffer); if (radioResponseInfo == nullptr) { - TELEPHONY_LOGE("ERROR :radioResponseInfo == nullptr"); + TELEPHONY_LOGE("ERROR :radioResponseInfo == nullptr !!!"); return TELEPHONY_ERR_LOCAL_PTR_NULL; } std::shared_ptr telRilRequest = FindTelRilRequest(*radioResponseInfo); - if (telRilRequest != nullptr && telRilRequest->pointer_ != nullptr) { - if (radioResponseInfo->error == HRilErrType::NONE) { - const std::shared_ptr &handler = telRilRequest->pointer_->GetOwner(); - if (handler == nullptr) { - TELEPHONY_LOGE("ERROR :handler == nullptr"); - return TELEPHONY_ERR_LOCAL_PTR_NULL; - } - uint32_t eventId = telRilRequest->pointer_->GetInnerEventId(); - std::shared_ptr errorCode = std::make_shared(); - *errorCode = radioResponseInfo->error; - handler->SendEvent(eventId, errorCode); - } else { - return ErrorResponse(telRilRequest, *radioResponseInfo); - } + if (telRilRequest == nullptr || telRilRequest->pointer_ == nullptr) { + TELEPHONY_LOGE("ERROR :telRilRequest == nullptr || radioResponseInfo error"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + const std::shared_ptr &handler = telRilRequest->pointer_->GetOwner(); + if (handler == nullptr) { + TELEPHONY_LOGE("ERROR :handler == nullptr"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + if (radioResponseInfo->error == HRilErrType::NONE) { + uint32_t eventId = telRilRequest->pointer_->GetInnerEventId(); + handler->SendEvent(eventId, openLogicalChannelResult); + } else { + return ErrorResponse(telRilRequest, *radioResponseInfo); } return TELEPHONY_ERR_SUCCESS; } diff --git a/services/tel_ril/test/tel_ril_test.cpp b/services/tel_ril/test/tel_ril_test.cpp index 853c29032..fdd80c40e 100755 --- a/services/tel_ril/test/tel_ril_test.cpp +++ b/services/tel_ril/test/tel_ril_test.cpp @@ -2035,18 +2035,15 @@ void TelRilTest::DemoHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer "TelRilTest::DemoHandler::ProcessEvent --> eventId:%{public}d, slotId:%{public}d", eventId, this->slotId_); switch (eventId) { case uint32_t(CustomMessageID::MSG_OPEN_LOGICAL_CHANNEL_DONE): { - TELEPHONY_LOGI("open logical channel done"); - break; - } - case uint32_t(CustomMessageID::MSG_TRANSMIT_LOGICAL_CHANNEL_DONE): { - auto result = event->GetUniqueObject(); + auto result = event->GetUniqueObject(); if (result == nullptr) { - TELEPHONY_LOGE("TransmitSimIO response nullptr"); + TELEPHONY_LOGE("Open logical response nullptr"); break; } - TELEPHONY_LOGI("TransmitSimIO response:'%{public}s'", result->response.c_str()); + TELEPHONY_LOGI("Open logical response channel:'%{public}d'", result->channelId); break; } + case uint32_t(CustomMessageID::MSG_TRANSMIT_LOGICAL_CHANNEL_DONE): case uint32_t(CustomMessageID::MSG_TRANSMIT_BASIC_CHANNEL_DONE): { auto result = event->GetUniqueObject(); if (result == nullptr) { From b22a692114becce6796f80937d125d7b475db587 Mon Sep 17 00:00:00 2001 From: qian-nan-xu Date: Wed, 15 Jun 2022 10:06:21 +0800 Subject: [PATCH 6/7] ims issue fix Signed-off-by: qian-nan-xu --- .../include/napi_ims_callback_manager.h | 11 ++- .../include/napi_ims_sms_callback.h | 2 +- .../include/napi_ims_ut_callback.h | 8 +- .../include/napi_ims_video_callback.h | 2 +- .../include/napi_ims_voice_callback.h | 8 +- .../js/network_search/include/napi_radio.h | 37 +++------- .../src/napi_ims_callback_manager.cpp | 74 +++++++++---------- .../src/napi_ims_sms_callback.cpp | 3 +- .../src/napi_ims_ut_callback.cpp | 3 +- .../src/napi_ims_video_callback.cpp | 3 +- .../src/napi_ims_voice_callback.cpp | 5 +- .../js/network_search/src/napi_radio.cpp | 67 +++++++++++------ frameworks/native/src/core_service_proxy.cpp | 33 ++++++--- interfaces/innerkits/include/ims_reg_types.h | 2 +- .../innerkits/include/ims_sms_callback.h | 1 - .../innerkits/include/ims_sms_callback_stub.h | 2 +- .../innerkits/include/ims_ut_callback.h | 1 - .../innerkits/include/ims_ut_callback_stub.h | 2 +- .../innerkits/include/ims_video_callback.h | 1 - .../include/ims_video_callback_stub.h | 2 +- .../innerkits/include/ims_voice_callback.h | 1 - .../include/ims_voice_callback_stub.h | 2 +- services/core/src/core_service.cpp | 6 +- .../src/ims_core_service_callback_proxy.cpp | 12 ++- .../src/ims_core_service_callback_stub.cpp | 4 +- .../src/network_search_handler.cpp | 11 ++- services/network_search/test/test.cpp | 4 +- 27 files changed, 166 insertions(+), 141 deletions(-) diff --git a/frameworks/js/network_search/include/napi_ims_callback_manager.h b/frameworks/js/network_search/include/napi_ims_callback_manager.h index 6813fc48d..b3f89dbac 100644 --- a/frameworks/js/network_search/include/napi_ims_callback_manager.h +++ b/frameworks/js/network_search/include/napi_ims_callback_manager.h @@ -18,7 +18,6 @@ #include #include -#include #include "singleton.h" #include "napi_util.h" @@ -29,15 +28,15 @@ namespace OHOS { namespace Telephony { class NapiImsCallbackManager { public: - void RegImsStateCallback(ImsStateCallback stateCallback); + void RegImsStateCallback(const ImsStateCallback &stateCallback); void UnRegImsStateCallback(napi_env env, int32_t slotId, ImsServiceType imsSrvType); - void UnRegAllImsStateCallbackOfType(napi_env env, int32_t slotId, ImsServiceType imsSrvType); + void UnRegAllImsStateCallbackOfType(int32_t slotId, ImsServiceType imsSrvType); int32_t UpdateImsState(ImsServiceType imsSrvType, const ImsRegInfo &info); private: - void UnRegCallback(ImsServiceType imsSrvType, int32_t slotId, std::list::iterator iter); - int32_t UpdateImsStateInfo(ImsStateCallback stateCallback, const ImsRegInfo &info); + void UnRegCallback(ImsServiceType imsSrvType, int32_t slotId, ImsStateCallback stateCallback); + int32_t UpdateImsStateInfo(const ImsStateCallback &stateCallback, const ImsRegInfo &info); static void ReportImsStateWork(uv_work_t *work, int32_t status); - static int32_t ReportImsState(ImsRegInfo &info, ImsStateCallback stateCallback); + static int32_t ReportImsState(const ImsRegInfo &info, const ImsStateCallback &stateCallback); ImsStateCallback stateCallback_; std::list listStateCallback_; }; diff --git a/frameworks/js/network_search/include/napi_ims_sms_callback.h b/frameworks/js/network_search/include/napi_ims_sms_callback.h index 591d96bb8..a6fbaebd9 100644 --- a/frameworks/js/network_search/include/napi_ims_sms_callback.h +++ b/frameworks/js/network_search/include/napi_ims_sms_callback.h @@ -22,7 +22,7 @@ namespace OHOS { namespace Telephony { class NapiImsSmsCallback : public ImsSmsCallbackStub { public: - explicit NapiImsSmsCallback(ImsRegInfo info); + explicit NapiImsSmsCallback(const ImsRegInfo &info); void OnImsSmsStateChange(const ImsRegInfo &info) override; private: ImsRegInfo info_; diff --git a/frameworks/js/network_search/include/napi_ims_ut_callback.h b/frameworks/js/network_search/include/napi_ims_ut_callback.h index 6beca42b5..566f096b1 100644 --- a/frameworks/js/network_search/include/napi_ims_ut_callback.h +++ b/frameworks/js/network_search/include/napi_ims_ut_callback.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef NAPI_IMS_UT_CALL_BACK_H -#define NAPI_IMS_UT_CALL_BACK_H +#ifndef NAPI_IMS_UT_CALLBACK_H +#define NAPI_IMS_UT_CALLBACK_H #include "ims_ut_callback_stub.h" @@ -22,11 +22,11 @@ namespace OHOS { namespace Telephony { class NapiImsUtCallback : public ImsUtCallbackStub { public: - explicit NapiImsUtCallback(ImsRegInfo info); + explicit NapiImsUtCallback(const ImsRegInfo &info); void OnImsUtStateChange(const ImsRegInfo &info) override; private: ImsRegInfo info_; }; } // namespace Telephony } // namespace OHOS -#endif // NAPI_IMS_UT_CALL_BACK_H \ No newline at end of file +#endif // NAPI_IMS_UT_CALLBACK_H \ No newline at end of file diff --git a/frameworks/js/network_search/include/napi_ims_video_callback.h b/frameworks/js/network_search/include/napi_ims_video_callback.h index facc2f7f4..1e9ac45bd 100644 --- a/frameworks/js/network_search/include/napi_ims_video_callback.h +++ b/frameworks/js/network_search/include/napi_ims_video_callback.h @@ -22,7 +22,7 @@ namespace OHOS { namespace Telephony { class NapiImsVideoCallback : public ImsVideoCallbackStub { public: - explicit NapiImsVideoCallback(ImsRegInfo info); + explicit NapiImsVideoCallback(const ImsRegInfo &info); void OnImsVideoStateChange(const ImsRegInfo &info) override; private: ImsRegInfo info_; diff --git a/frameworks/js/network_search/include/napi_ims_voice_callback.h b/frameworks/js/network_search/include/napi_ims_voice_callback.h index 11862bb5d..5152ee6f4 100644 --- a/frameworks/js/network_search/include/napi_ims_voice_callback.h +++ b/frameworks/js/network_search/include/napi_ims_voice_callback.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef NAPI_IMS_UT_CALLBACK_H -#define NAPI_IMS_UT_CALLBACK_H +#ifndef NAPI_IMS_VOICE_CALLBACK_H +#define NAPI_IMS_VOICE_CALLBACK_H #include "ims_voice_callback_stub.h" @@ -22,11 +22,11 @@ namespace OHOS { namespace Telephony { class NapiImsVoiceCallback : public ImsVoiceCallbackStub { public: - explicit NapiImsVoiceCallback(ImsRegInfo info); + explicit NapiImsVoiceCallback(const ImsRegInfo &info); void OnImsVoiceStateChange(const ImsRegInfo &info) override; private: ImsRegInfo info_; }; } // namespace Telephony } // namespace OHOS -#endif // NAPI_IMS_UT_CALLBACK_H \ No newline at end of file +#endif // NAPI_IMS_VOICE_CALLBACK_H \ No newline at end of file diff --git a/frameworks/js/network_search/include/napi_radio.h b/frameworks/js/network_search/include/napi_radio.h index f3514a439..4004f9220 100755 --- a/frameworks/js/network_search/include/napi_radio.h +++ b/frameworks/js/network_search/include/napi_radio.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -281,30 +281,17 @@ struct ImsRegInfoContext : BaseContext { }; struct ImsStateCallback { - ImsStateCallback() - :env(nullptr), - thisVar(nullptr), - callbackRef(nullptr), - deferred(nullptr), - callbackBeginTime_(0), - slotId(0), - imsSrvType(TYPE_VOICE), - voiceCallback(nullptr), - videoCallback(nullptr), - utCallback(nullptr), - smsCallback(nullptr) - {} - napi_env env; - napi_value thisVar; - napi_ref callbackRef; - napi_deferred deferred; - time_t callbackBeginTime_; - int32_t slotId; - ImsServiceType imsSrvType; - sptr voiceCallback; - sptr videoCallback; - sptr utCallback; - sptr smsCallback; + napi_env env = nullptr; + napi_value thisVar = nullptr; + napi_ref callbackRef = nullptr; + napi_deferred deferred = nullptr; + time_t callbackBeginTime_ = 0; + int32_t slotId = DEFAULT_SIM_SLOT_ID; + ImsServiceType imsSrvType = TYPE_VOICE; + sptr voiceCallback = nullptr; + sptr videoCallback = nullptr; + sptr utCallback = nullptr; + sptr smsCallback = nullptr; }; struct ImsStateWorker { diff --git a/frameworks/js/network_search/src/napi_ims_callback_manager.cpp b/frameworks/js/network_search/src/napi_ims_callback_manager.cpp index 1ac4b6e8e..32587a118 100644 --- a/frameworks/js/network_search/src/napi_ims_callback_manager.cpp +++ b/frameworks/js/network_search/src/napi_ims_callback_manager.cpp @@ -17,7 +17,7 @@ namespace OHOS { namespace Telephony { -void NapiImsCallbackManager::RegImsStateCallback(ImsStateCallback stateCallback) +void NapiImsCallbackManager::RegImsStateCallback(const ImsStateCallback &stateCallback) { if (stateCallback.voiceCallback != nullptr || stateCallback.videoCallback != nullptr @@ -28,28 +28,32 @@ void NapiImsCallbackManager::RegImsStateCallback(ImsStateCallback stateCallback) } void NapiImsCallbackManager::UnRegCallback( - ImsServiceType imsSrvType, int32_t slotId, std::list::iterator iter) + ImsServiceType imsSrvType, int32_t slotId, ImsStateCallback stateCallback) { switch (imsSrvType) { case ImsServiceType::TYPE_VOICE: DelayedRefSingleton::GetInstance() - .UnRegImsVoiceCallback(slotId, iter->voiceCallback); - (void)memset_s(&iter->voiceCallback, sizeof(ImsStateCallback), 0, sizeof(ImsStateCallback)); + .UnRegImsVoiceCallback(slotId, stateCallback.voiceCallback); + delete stateCallback.voiceCallback; + stateCallback.voiceCallback = nullptr; break; case ImsServiceType::TYPE_VIDEO: DelayedRefSingleton::GetInstance() - .UnRegImsVideoCallback(slotId, iter->videoCallback); - (void)memset_s(&iter->videoCallback, sizeof(ImsStateCallback), 0, sizeof(ImsStateCallback)); + .UnRegImsVideoCallback(slotId, stateCallback.videoCallback); + delete stateCallback.videoCallback; + stateCallback.videoCallback = nullptr; break; case ImsServiceType::TYPE_UT: DelayedRefSingleton::GetInstance() - .UnRegImsUtCallback(slotId, iter->utCallback); - (void)memset_s(&iter->utCallback, sizeof(ImsStateCallback), 0, sizeof(ImsStateCallback)); + .UnRegImsUtCallback(slotId, stateCallback.utCallback); + delete stateCallback.utCallback; + stateCallback.utCallback = nullptr; break; case ImsServiceType::TYPE_SMS: DelayedRefSingleton::GetInstance() - .UnRegImsSmsCallback(slotId, iter->smsCallback); - (void)memset_s(&iter->smsCallback, sizeof(ImsStateCallback), 0, sizeof(ImsStateCallback)); + .UnRegImsSmsCallback(slotId, stateCallback.smsCallback); + delete stateCallback.smsCallback; + stateCallback.smsCallback = nullptr; break; default: TELEPHONY_LOGE("%{public}d type is error!", imsSrvType); @@ -65,21 +69,21 @@ void NapiImsCallbackManager::UnRegImsStateCallback(napi_env env, int32_t slotId, && (iter->slotId == slotId) && (iter->imsSrvType == imsSrvType) && (iter->callbackRef)) { - UnRegCallback(imsSrvType, slotId, iter); + UnRegCallback(imsSrvType, slotId, *iter); listStateCallback_.erase(iter); } } } void NapiImsCallbackManager::UnRegAllImsStateCallbackOfType( - napi_env env, int32_t slotId, ImsServiceType imsSrvType) + int32_t slotId, ImsServiceType imsSrvType) { auto iter = listStateCallback_.begin(); for (; iter != listStateCallback_.end(); ++iter) { if ((iter->slotId == slotId) && (iter->imsSrvType == imsSrvType) && (iter->callbackRef)) { - UnRegCallback(imsSrvType, slotId, iter); + UnRegCallback(imsSrvType, slotId, *iter); listStateCallback_.erase(iter); } } @@ -87,21 +91,20 @@ void NapiImsCallbackManager::UnRegAllImsStateCallbackOfType( int32_t NapiImsCallbackManager::UpdateImsState(ImsServiceType imsSrvType, const ImsRegInfo &info) { - int32_t ret; - auto iter = listStateCallback_.begin(); - for (; iter != listStateCallback_.end(); ++iter) { - if (iter->imsSrvType == imsSrvType) { - UpdateImsStateInfo(*iter, info); + int32_t ret = ERROR; + for (auto iter : listStateCallback_) { + if (iter.imsSrvType == imsSrvType) { + UpdateImsStateInfo(iter, info); ret = SUCCESS; - } else { - TELEPHONY_LOGE("%{public}d type is null!", imsSrvType); - ret = ERROR; } } + if (ret == ERROR) { + TELEPHONY_LOGE("%{public}d type is null!", imsSrvType); + } return ret; } -int32_t NapiImsCallbackManager::UpdateImsStateInfo(ImsStateCallback stateCallback, const ImsRegInfo &info) +int32_t NapiImsCallbackManager::UpdateImsStateInfo(const ImsStateCallback &stateCallback, const ImsRegInfo &info) { if (stateCallback.thisVar == nullptr) { TELEPHONY_LOGE("stateCallback is null!"); @@ -111,21 +114,13 @@ int32_t NapiImsCallbackManager::UpdateImsStateInfo(ImsStateCallback stateCallbac #if NAPI_VERSION >= 2 napi_get_uv_event_loop(stateCallback.env, &loop); #endif - ImsStateWorker *dataWorker = std::make_unique().release(); - if (dataWorker == nullptr) { - TELEPHONY_LOGE("dataWorker is nullptr!"); - return ERROR; - } - dataWorker->info = info; - dataWorker->callback = stateCallback; - uv_work_t *work = std::make_unique().release(); - if (work == nullptr) { - TELEPHONY_LOGE("work is nullptr!"); - return ERROR; - } - work->data = (void *)dataWorker; + ImsStateWorker dataWorker; + dataWorker.info = info; + dataWorker.callback = stateCallback; + uv_work_t work; + work.data = (void*)(&dataWorker); uv_queue_work( - loop, work, [](uv_work_t *work) {}, ReportImsStateWork); + loop, &work, [](uv_work_t *work) {}, ReportImsStateWork); return SUCCESS; } @@ -134,6 +129,8 @@ void NapiImsCallbackManager::ReportImsStateWork(uv_work_t *work, int32_t status) ImsStateWorker *dataWorkerData = (ImsStateWorker *)work->data; if (dataWorkerData == nullptr) { TELEPHONY_LOGE("dataWorkerData is nullptr!"); + delete work; + work = nullptr; return; } int32_t ret = ReportImsState(dataWorkerData->info, dataWorkerData->callback); @@ -143,7 +140,8 @@ void NapiImsCallbackManager::ReportImsStateWork(uv_work_t *work, int32_t status) delete work; work = nullptr; } -int32_t NapiImsCallbackManager::ReportImsState(ImsRegInfo &info, ImsStateCallback stateCallback) + +int32_t NapiImsCallbackManager::ReportImsState(const ImsRegInfo &info, const ImsStateCallback &stateCallback) { napi_value callbackFunc = nullptr; napi_env env = stateCallback.env; @@ -154,11 +152,11 @@ int32_t NapiImsCallbackManager::ReportImsState(ImsRegInfo &info, ImsStateCallbac NapiUtil::SetPropertyInt32( env, callbackValues[0], "imsRegTech", static_cast(info.imsRegTech)); napi_get_reference_value(env, stateCallback.callbackRef, &callbackFunc); - napi_value callbackResult = nullptr; if (callbackFunc == nullptr) { TELEPHONY_LOGE("callbackFunc is null!"); return ERROR; } + napi_value callbackResult = nullptr; napi_call_function(env, stateCallback.thisVar, callbackFunc, 1, callbackValues, &callbackResult); return SUCCESS; } diff --git a/frameworks/js/network_search/src/napi_ims_sms_callback.cpp b/frameworks/js/network_search/src/napi_ims_sms_callback.cpp index 0fa5c03e1..cdbf33907 100644 --- a/frameworks/js/network_search/src/napi_ims_sms_callback.cpp +++ b/frameworks/js/network_search/src/napi_ims_sms_callback.cpp @@ -18,8 +18,9 @@ namespace OHOS { namespace Telephony { -NapiImsSmsCallback::NapiImsSmsCallback(ImsRegInfo info) : info_(info) +NapiImsSmsCallback::NapiImsSmsCallback(const ImsRegInfo &info) : info_(info) {} + void NapiImsSmsCallback::OnImsSmsStateChange(const ImsRegInfo &info) { info_ = info; diff --git a/frameworks/js/network_search/src/napi_ims_ut_callback.cpp b/frameworks/js/network_search/src/napi_ims_ut_callback.cpp index c84edf74b..b12a23f28 100644 --- a/frameworks/js/network_search/src/napi_ims_ut_callback.cpp +++ b/frameworks/js/network_search/src/napi_ims_ut_callback.cpp @@ -18,8 +18,9 @@ namespace OHOS { namespace Telephony { -NapiImsUtCallback::NapiImsUtCallback(ImsRegInfo info) : info_(info) +NapiImsUtCallback::NapiImsUtCallback(const ImsRegInfo &info) : info_(info) {} + void NapiImsUtCallback::OnImsUtStateChange(const ImsRegInfo &info) { info_ = info; diff --git a/frameworks/js/network_search/src/napi_ims_video_callback.cpp b/frameworks/js/network_search/src/napi_ims_video_callback.cpp index 15f553f4c..4c602ea93 100644 --- a/frameworks/js/network_search/src/napi_ims_video_callback.cpp +++ b/frameworks/js/network_search/src/napi_ims_video_callback.cpp @@ -18,8 +18,9 @@ namespace OHOS { namespace Telephony { -NapiImsVideoCallback::NapiImsVideoCallback(ImsRegInfo info) : info_(info) +NapiImsVideoCallback::NapiImsVideoCallback(const ImsRegInfo &info) : info_(info) {} + void NapiImsVideoCallback::OnImsVideoStateChange(const ImsRegInfo &info) { info_ = info; diff --git a/frameworks/js/network_search/src/napi_ims_voice_callback.cpp b/frameworks/js/network_search/src/napi_ims_voice_callback.cpp index ede070b57..d9bf18c3b 100644 --- a/frameworks/js/network_search/src/napi_ims_voice_callback.cpp +++ b/frameworks/js/network_search/src/napi_ims_voice_callback.cpp @@ -18,11 +18,12 @@ namespace OHOS { namespace Telephony { -NapiImsVoiceCallback::NapiImsVoiceCallback(ImsRegInfo info) : info_(info) +NapiImsVoiceCallback::NapiImsVoiceCallback(const ImsRegInfo &info) : info_(info) {} + void NapiImsVoiceCallback::OnImsVoiceStateChange(const ImsRegInfo &info) { - TELEPHONY_LOGE("NapiImsVoiceCallback Enter!"); + TELEPHONY_LOGI("NapiImsVoiceCallback Enter!"); info_ = info; int32_t ret = DelayedSingleton::GetInstance()-> UpdateImsState(ImsServiceType::TYPE_VOICE, info); diff --git a/frameworks/js/network_search/src/napi_radio.cpp b/frameworks/js/network_search/src/napi_radio.cpp index 4513f3dc2..33853d74d 100644 --- a/frameworks/js/network_search/src/napi_radio.cpp +++ b/frameworks/js/network_search/src/napi_radio.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -1947,37 +1947,36 @@ static napi_value GetImsRegInfo(napi_env env, napi_callback_info info) env, asyncContext.release(), "GetImsRegInfo", NativeGetImsRegInfo, GetImsRegInfoCallback); } -void RegImsCallback(napi_env env, napi_value thisVar, int32_t slotId, int32_t imsSrvType, napi_value argv[]) +static void RegImsCallback(napi_env env, napi_value thisVar, int32_t slotId, int32_t imsSrvType, napi_value argv[]) { int32_t ret = ERROR; ImsStateCallback imsStateCallback; ImsRegInfo imsRegInfo = ERROR_IMS_REG_INFO; - (void)memset_s(&imsStateCallback, sizeof(ImsStateCallback), 0, sizeof(ImsStateCallback)); imsStateCallback.env = env; imsStateCallback.thisVar = thisVar; imsStateCallback.slotId = slotId; imsStateCallback.imsSrvType = static_cast(imsSrvType); switch (static_cast(imsSrvType)) { case ImsServiceType::TYPE_VOICE: - imsStateCallback.voiceCallback = std::make_unique(imsRegInfo).release(); + imsStateCallback.voiceCallback = new NapiImsVoiceCallback(imsRegInfo); ret = DelayedRefSingleton::GetInstance() .RegImsVoiceCallback(slotId, imsStateCallback.voiceCallback); break; case ImsServiceType::TYPE_VIDEO: - imsStateCallback.videoCallback = std::make_unique(imsRegInfo).release(); + imsStateCallback.videoCallback = new NapiImsVideoCallback(imsRegInfo); ret = DelayedRefSingleton::GetInstance() .RegImsVideoCallback(slotId, imsStateCallback.videoCallback); break; case ImsServiceType::TYPE_UT: - imsStateCallback.utCallback = std::make_unique(imsRegInfo).release(); + imsStateCallback.utCallback = new NapiImsUtCallback(imsRegInfo); ret = DelayedRefSingleton::GetInstance() .RegImsUtCallback(slotId, imsStateCallback.utCallback); break; case ImsServiceType::TYPE_SMS: - imsStateCallback.smsCallback = std::make_unique(imsRegInfo).release(); + imsStateCallback.smsCallback = new NapiImsSmsCallback(imsRegInfo); ret = DelayedRefSingleton::GetInstance() .RegImsSmsCallback(slotId, imsStateCallback.smsCallback); - break; + break; default: ret = ERROR; TELEPHONY_LOGE("ImsServiceType Error!"); @@ -1992,18 +1991,32 @@ void RegImsCallback(napi_env env, napi_value thisVar, int32_t slotId, int32_t im } } -napi_value ObserverOn(napi_env env, napi_callback_info info) +static napi_value ObserverOn(napi_env env, napi_callback_info info) { size_t argc = 4; + napi_value result = nullptr; napi_value argv[4]; napi_value thisVar; char callbackType[INFO_MAXIMUM_LIMIT + 1]; int32_t slotId; int32_t imsSrvType; - napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL); - napi_get_value_string_utf8(env, argv[ARRAY_INDEX_FIRST], callbackType, INFO_MAXIMUM_LIMIT, NULL); - napi_get_value_int32(env, argv[ARRAY_INDEX_SECOND], &slotId); - napi_get_value_int32(env, argv[ARRAY_INDEX_THIRD], &imsSrvType); + if (napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL) != napi_ok) { + TELEPHONY_LOGE("ObserverOn Can not get thisVar value"); + return result; + } + if (napi_get_value_string_utf8(env, argv[ARRAY_INDEX_FIRST], + callbackType, INFO_MAXIMUM_LIMIT, NULL) != napi_ok) { + TELEPHONY_LOGE("ObserverOn Can not get callbackType value"); + return result; + } + if (napi_get_value_int32(env, argv[ARRAY_INDEX_SECOND], &slotId) != napi_ok) { + TELEPHONY_LOGE("ObserverOn Can not get slotId value"); + return result; + } + if (napi_get_value_int32(env, argv[ARRAY_INDEX_THIRD], &imsSrvType) != napi_ok) { + TELEPHONY_LOGE("ObserverOn Can not get imsSrvType value"); + return result; + } bool matchFlag = NapiUtil::MatchValueType(env, argv[ARRAY_INDEX_FIRST], napi_string); NAPI_ASSERT(env, matchFlag, "Type error, should be string type"); std::string tmpStr = callbackType; @@ -2011,22 +2024,35 @@ napi_value ObserverOn(napi_env env, napi_callback_info info) if (tmpStr.compare("imsRegStateChange") == 0) { RegImsCallback(env, thisVar, slotId, imsSrvType, argv); } - napi_value result = nullptr; return result; } -napi_value ObserverOff(napi_env env, napi_callback_info info) +static napi_value ObserverOff(napi_env env, napi_callback_info info) { size_t argc = 4; + napi_value result = nullptr; napi_value argv[4]; napi_value thisVar; char callbackType[INFO_MAXIMUM_LIMIT + 1]; int32_t slotId; int32_t imsSrvType; - napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL); - napi_get_value_string_utf8(env, argv[ARRAY_INDEX_FIRST], callbackType, INFO_MAXIMUM_LIMIT, NULL); - napi_get_value_int32(env, argv[ARRAY_INDEX_SECOND], &slotId); - napi_get_value_int32(env, argv[ARRAY_INDEX_THIRD], &imsSrvType); + if (napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL) != napi_ok) { + TELEPHONY_LOGE("ObserverOn Can not get thisVar value"); + return result; + } + if (napi_get_value_string_utf8(env, argv[ARRAY_INDEX_FIRST], + callbackType, INFO_MAXIMUM_LIMIT, NULL) != napi_ok) { + TELEPHONY_LOGE("ObserverOn Can not get callbackType value"); + return result; + } + if (napi_get_value_int32(env, argv[ARRAY_INDEX_SECOND], &slotId) != napi_ok) { + TELEPHONY_LOGE("ObserverOn Can not get slotId value"); + return result; + } + if (napi_get_value_int32(env, argv[ARRAY_INDEX_THIRD], &imsSrvType) != napi_ok) { + TELEPHONY_LOGE("ObserverOn Can not get imsSrvType value"); + return result; + } std::string tmpStr = callbackType; bool matchFlag = NapiUtil::MatchValueType(env, argv[ARRAY_INDEX_FIRST], napi_string); NAPI_ASSERT(env, matchFlag, "Type error, should be string type"); @@ -2037,10 +2063,9 @@ napi_value ObserverOff(napi_env env, napi_callback_info info) UnRegImsStateCallback(env, slotId, static_cast(imsSrvType)); } else if (argc == THREE_PARAMETERS) { DelayedSingleton::GetInstance()-> - UnRegAllImsStateCallbackOfType(env, slotId, static_cast(imsSrvType)); + UnRegAllImsStateCallbackOfType(slotId, static_cast(imsSrvType)); } } - napi_value result = nullptr; return result; } diff --git a/frameworks/native/src/core_service_proxy.cpp b/frameworks/native/src/core_service_proxy.cpp index f4395cb9d..ba0dd7a51 100755 --- a/frameworks/native/src/core_service_proxy.cpp +++ b/frameworks/native/src/core_service_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -1929,11 +1929,12 @@ ImsRegInfo CoreServiceProxy::GetImsRegStatus(int32_t slotId, ImsServiceType imsS TELEPHONY_LOGE("GetImsRegStatus WriteInt32 imsSrvType is false"); return ERROR_IMS_REG_INFO; } - if (Remote() == nullptr) { + sptr remote = Remote(); + if (remote == nullptr) { TELEPHONY_LOGE("GetImsRegStatus Remote is null"); return ERROR_IMS_REG_INFO; } - int32_t st = Remote()->SendRequest(uint32_t(InterfaceID::GET_IMS_REG_STATUS), data, reply, option); + int32_t st = remote->SendRequest(uint32_t(InterfaceID::GET_IMS_REG_STATUS), data, reply, option); if (st != ERR_NONE) { TELEPHONY_LOGE("GetImsRegStatus failed, error code is %{public}d \n", st); return ERROR_IMS_REG_INFO; @@ -2108,14 +2109,14 @@ int32_t CoreServiceProxy::RegImsCallback(MessageParcel &idata) int32_t slotId = idata.ReadInt32(); sptr callback = idata.ReadRemoteObject(); TELEPHONY_LOGI("imsSrvType is %{public}d, slotId is %{public}d", imsSrvType, slotId); - if (!WriteInterfaceToken(data)) { - TELEPHONY_LOGE("RegisterCallBack WriteInterfaceToken is false"); - return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL; - } if (callback == nullptr) { TELEPHONY_LOGE("CoreServiceProxy::RegImsCallback is nullptr"); return ERROR; } + if (!WriteInterfaceToken(data)) { + TELEPHONY_LOGE("RegisterCallBack WriteInterfaceToken is false"); + return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL; + } if (!data.WriteInt32(imsSrvType)) { TELEPHONY_LOGE("WriteInt32 ERROR"); return ERROR; @@ -2128,7 +2129,11 @@ int32_t CoreServiceProxy::RegImsCallback(MessageParcel &idata) TELEPHONY_LOGE("WriteRemoteObject ERROR"); return ERROR; } - int32_t error = Remote()->SendRequest(static_cast(InterfaceID::REG_IMS_CALLBACK), data, reply, option); + sptr remote = Remote(); + if (remote == nullptr) { + return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; + } + int32_t error = remote->SendRequest(static_cast(InterfaceID::REG_IMS_CALLBACK), data, reply, option); if (error != TELEPHONY_SUCCESS) { TELEPHONY_LOGE("Function RegisterCallBack! errCode:%{public}d", error); return error; @@ -2144,17 +2149,21 @@ int32_t CoreServiceProxy::UnRegImsCallback(MessageParcel &idata) int32_t imsSrvType = idata.ReadInt32(); int32_t slotId = idata.ReadInt32(); sptr callback = idata.ReadRemoteObject(); + if (callback == nullptr) { + TELEPHONY_LOGE("CoreServiceProxy::RegImsCallback is nullptr"); + } if (!WriteInterfaceToken(data)) { TELEPHONY_LOGE("RegisterCallBack WriteInterfaceToken is false"); return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL; } - if (callback == nullptr) { - TELEPHONY_LOGE("CoreServiceProxy::RegImsCallback is nullptr"); - } data.WriteInt32(imsSrvType); data.WriteInt32(slotId); data.WriteRemoteObject(callback); - int32_t error = Remote()->SendRequest(static_cast(InterfaceID::UN_REG_IMS_CALLBACK), data, reply, option); + sptr remote = Remote(); + if (remote == nullptr) { + return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; + } + int32_t error = remote->SendRequest(static_cast(InterfaceID::UN_REG_IMS_CALLBACK), data, reply, option); if (error != TELEPHONY_SUCCESS) { TELEPHONY_LOGE("Function UnRegImsCallback! errCode:%{public}d", error); return error; diff --git a/interfaces/innerkits/include/ims_reg_types.h b/interfaces/innerkits/include/ims_reg_types.h index d1b3561c3..9aa0e1009 100644 --- a/interfaces/innerkits/include/ims_reg_types.h +++ b/interfaces/innerkits/include/ims_reg_types.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 diff --git a/interfaces/innerkits/include/ims_sms_callback.h b/interfaces/innerkits/include/ims_sms_callback.h index 522a9f7da..9ca00cc15 100644 --- a/interfaces/innerkits/include/ims_sms_callback.h +++ b/interfaces/innerkits/include/ims_sms_callback.h @@ -22,7 +22,6 @@ namespace OHOS { namespace Telephony { class ImsSmsCallback : public ImsManagerCallback { public: - ~ImsSmsCallback() = default; virtual int32_t OnImsStateCallback(const ImsRegInfo &info) = 0; }; } // namespace Telephony diff --git a/interfaces/innerkits/include/ims_sms_callback_stub.h b/interfaces/innerkits/include/ims_sms_callback_stub.h index 03ac8b8ed..52d1b17be 100644 --- a/interfaces/innerkits/include/ims_sms_callback_stub.h +++ b/interfaces/innerkits/include/ims_sms_callback_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 diff --git a/interfaces/innerkits/include/ims_ut_callback.h b/interfaces/innerkits/include/ims_ut_callback.h index 4ee5dbbd3..576927365 100644 --- a/interfaces/innerkits/include/ims_ut_callback.h +++ b/interfaces/innerkits/include/ims_ut_callback.h @@ -22,7 +22,6 @@ namespace OHOS { namespace Telephony { class ImsUtCallback : public ImsManagerCallback { public: - ~ImsUtCallback() = default; virtual int32_t OnImsStateCallback(const ImsRegInfo &info) = 0; }; } // namespace Telephony diff --git a/interfaces/innerkits/include/ims_ut_callback_stub.h b/interfaces/innerkits/include/ims_ut_callback_stub.h index 857507669..1bd98f648 100644 --- a/interfaces/innerkits/include/ims_ut_callback_stub.h +++ b/interfaces/innerkits/include/ims_ut_callback_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 diff --git a/interfaces/innerkits/include/ims_video_callback.h b/interfaces/innerkits/include/ims_video_callback.h index e287a8879..86a24408b 100644 --- a/interfaces/innerkits/include/ims_video_callback.h +++ b/interfaces/innerkits/include/ims_video_callback.h @@ -22,7 +22,6 @@ namespace OHOS { namespace Telephony { class ImsVideoCallback : public ImsManagerCallback { public: - ~ImsVideoCallback() = default; virtual int32_t OnImsStateCallback(const ImsRegInfo &info) = 0; }; } // namespace Telephony diff --git a/interfaces/innerkits/include/ims_video_callback_stub.h b/interfaces/innerkits/include/ims_video_callback_stub.h index 231e9c095..4c1c7d7d4 100644 --- a/interfaces/innerkits/include/ims_video_callback_stub.h +++ b/interfaces/innerkits/include/ims_video_callback_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 diff --git a/interfaces/innerkits/include/ims_voice_callback.h b/interfaces/innerkits/include/ims_voice_callback.h index 9b2583777..a43264b91 100644 --- a/interfaces/innerkits/include/ims_voice_callback.h +++ b/interfaces/innerkits/include/ims_voice_callback.h @@ -22,7 +22,6 @@ namespace OHOS { namespace Telephony { class ImsVoiceCallback : public ImsManagerCallback { public: - ~ImsVoiceCallback() = default; virtual int32_t OnImsStateCallback(const ImsRegInfo &info) = 0; }; } // namespace Telephony diff --git a/interfaces/innerkits/include/ims_voice_callback_stub.h b/interfaces/innerkits/include/ims_voice_callback_stub.h index d3675f515..e3f935f28 100644 --- a/interfaces/innerkits/include/ims_voice_callback_stub.h +++ b/interfaces/innerkits/include/ims_voice_callback_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 diff --git a/services/core/src/core_service.cpp b/services/core/src/core_service.cpp index 6124d33f8..92f7bb9e2 100644 --- a/services/core/src/core_service.cpp +++ b/services/core/src/core_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -861,7 +861,7 @@ bool CoreService::HasOperatorPrivileges(const int32_t slotId) int32_t CoreService::RegImsCallback(MessageParcel &data) { if (networkSearchManager_ == nullptr) { - return false; + return ERROR; } return networkSearchManager_->RegImsCallback(data); } @@ -869,7 +869,7 @@ int32_t CoreService::RegImsCallback(MessageParcel &data) int32_t CoreService::UnRegImsCallback(MessageParcel &data) { if (networkSearchManager_ == nullptr) { - return false; + return ERROR; } return networkSearchManager_->UnRegImsCallback(data); } diff --git a/services/ims_service_interaction/src/ims_core_service_callback_proxy.cpp b/services/ims_service_interaction/src/ims_core_service_callback_proxy.cpp index b1e933730..0f56363f7 100644 --- a/services/ims_service_interaction/src/ims_core_service_callback_proxy.cpp +++ b/services/ims_service_interaction/src/ims_core_service_callback_proxy.cpp @@ -41,7 +41,11 @@ int32_t ImsCoreServiceCallbackProxy::UpdateImsServiceStatusChanged( TELEPHONY_LOGE("write imsServiceStatus fail!"); return TELEPHONY_ERR_WRITE_DATA_FAIL; } - int32_t error = Remote()->SendRequest(IMS_SERVICE_STATUS_REPORT, in, out, option); + sptr remote = Remote(); + if (remote== nullptr) { + return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; + } + int32_t error = remote->SendRequest(IMS_SERVICE_STATUS_REPORT, in, out, option); if (error == ERR_NONE) { TELEPHONY_LOGE("send imsServiceStatus fail!"); return out.ReadInt32(); @@ -67,7 +71,11 @@ int32_t ImsCoreServiceCallbackProxy::GetImsRegistrationStatusResponse( TELEPHONY_LOGE("write imsRegStatus fail!"); return TELEPHONY_ERR_WRITE_DATA_FAIL; } - int32_t error = Remote()->SendRequest(IMS_GET_REGISTRATION_STATUS, in, out, option); + sptr remote = Remote(); + if (remote== nullptr) { + return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; + } + int32_t error = remote->SendRequest(IMS_GET_REGISTRATION_STATUS, in, out, option); if (error == ERR_NONE) { return out.ReadInt32(); } diff --git a/services/ims_service_interaction/src/ims_core_service_callback_stub.cpp b/services/ims_service_interaction/src/ims_core_service_callback_stub.cpp index 4e733c262..12bdf5d28 100644 --- a/services/ims_service_interaction/src/ims_core_service_callback_stub.cpp +++ b/services/ims_service_interaction/src/ims_core_service_callback_stub.cpp @@ -76,6 +76,7 @@ int32_t ImsCoreServiceCallbackStub::OnImsServiceStatusReportInner(MessageParcel int32_t ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged( int32_t slotId, const ImsServiceStatus &imsServiceStatus) { + TELEPHONY_LOGI("ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged entry"); std::shared_ptr imsCoreServiceClient = DelayedSingleton::GetInstance(); std::unique_ptr info = std::make_unique(); if (info.get() == nullptr) { @@ -86,7 +87,6 @@ int32_t ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged( *info = imsServiceStatus; imsCoreServiceClient->GetHandler(slotId)->SendEvent( ImsCoreServiceInterface::IMS_SERVICE_STATUS_UPDATE, std::move(info)); - TELEPHONY_LOGI("ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged entry"); return TELEPHONY_SUCCESS; } @@ -106,11 +106,11 @@ int32_t ImsCoreServiceCallbackStub::OnGetImsRegistrationStatusResponseInner(Mess int32_t ImsCoreServiceCallbackStub::GetImsRegistrationStatusResponse( int32_t slotId, const ImsRegistrationStatus &imsRegStatus) { + TELEPHONY_LOGI("ImsCoreServiceCallbackStub::GetImsRegistrationStatusResponse entry"); std::shared_ptr imsCoreServiceClient = DelayedSingleton::GetInstance(); int32_t isRegisterd = imsRegStatus.isRegisterd ? 1 : 0; imsCoreServiceClient->GetHandler(slotId)->SendEvent( ImsCoreServiceInterface::IMS_REGISTER_STATE_UPDATE, isRegisterd); - TELEPHONY_LOGI("ImsCoreServiceCallbackStub::GetImsRegistrationStatusResponse entry"); return TELEPHONY_SUCCESS; } } // namespace Telephony diff --git a/services/network_search/src/network_search_handler.cpp b/services/network_search/src/network_search_handler.cpp index 5f34c5d0b..75a226132 100644 --- a/services/network_search/src/network_search_handler.cpp +++ b/services/network_search/src/network_search_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -15,11 +15,10 @@ #include "network_search_handler.h" -#include - #include "ims_core_service_client.h" #include "network_search_manager.h" #include "telephony_log_wrapper.h" + namespace OHOS { namespace Telephony { const int64_t IMS_STATE_REGISTED = 1; @@ -162,7 +161,7 @@ void NetworkSearchHandler::RegisterEvents() } // Register IMS { - std::shared_ptr< ImsCoreServiceClient> imsCoreServiceClient = + std::shared_ptr imsCoreServiceClient = DelayedSingleton::GetInstance(); if (imsCoreServiceClient != nullptr) { imsCoreServiceClient->RegisterImsCoreServiceCallbackHandler(slotId_, shared_from_this()); @@ -749,7 +748,7 @@ void NetworkSearchHandler::DcPhysicalLinkActiveUpdate(const AppExecFwk::InnerEve if (event == nullptr) { return; } - bool isActive = (event->GetParam() == 1) ? true : false; + bool isActive = (event->GetParam() == 1); if (networkRegister_ != nullptr) { networkRegister_->DcPhysicalLinkActiveUpdate(isActive); } @@ -780,7 +779,7 @@ void NetworkSearchHandler::UpdateImsRegisterState(const AppExecFwk::InnerEvent:: TELEPHONY_LOGE("UpdateImsRegisterState event is null slotId:%{public}d", slotId_); return; } - bool isRegister = (event->GetParam() == 1) ? true : false; + bool isRegister = (event->GetParam() == 1); std::shared_ptr imsServiceStatus = event->GetSharedObject(); std::shared_ptr networkSearchState = networkSearchManager->GetNetworkSearchState(slotId_); diff --git a/services/network_search/test/test.cpp b/services/network_search/test/test.cpp index 20cc24e19..bd66746d2 100755 --- a/services/network_search/test/test.cpp +++ b/services/network_search/test/test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -377,7 +377,7 @@ void TestRegisterImsStateCallback() "TYPE_UT = 2,TYPE_SMS = 3):" << std::endl; std::cin >> imsSrvType; ImsRegInfo imsRegInfo = ERROR_IMS_REG_INFO; - sptr voiceCallback = std::make_unique(imsRegInfo).release(); + sptr voiceCallback = new ImsVoiceCallbackTestStub(imsRegInfo); sptr videoCallback(new ImsVideoCallbackStub()); sptr utCallback(new ImsUtCallbackStub()); sptr smsCallback(new ImsSmsCallbackStub()); From 4af5661a7ead730bf9bd8764cc092bd0221be9ac Mon Sep 17 00:00:00 2001 From: yuanbo Date: Wed, 15 Jun 2022 17:53:55 +0800 Subject: [PATCH 7/7] feat: normalize drivers framework component and repos Signed-off-by: yuanbo --- BUILD.gn | 6 +++--- bundle.json | 2 +- services/network_search/test/BUILD.gn | 2 +- services/sim/test/BUILD.gn | 2 +- services/tel_ril/include/tel_ril_common.h | 7 ------- services/tel_ril/src/tel_ril_data.cpp | 10 +++++----- services/tel_ril/test/BUILD.gn | 2 +- test/unittest/tel_ril_gtest/BUILD.gn | 2 +- 8 files changed, 13 insertions(+), 20 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 26c94b198..956087a5c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -14,7 +14,7 @@ import("//base/telephony/core_service/core_service_aafwk.gni") import("//base/telephony/core_service/telephony.gni") import("//build/ohos.gni") -import("//drivers/adapter/uhdf2/uhdf.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") TELEPHONY_CORE_SERVICE_ROOT = "//base/telephony/core_service" TELEPHONY_NETWORK_SEARCH_ROOT = @@ -149,9 +149,9 @@ ohos_shared_library("tel_core_service") { "common_event_service:cesfwk_innerkits", "common_event_service:cesfwk_services", "dataability:native_dataability", - "device_driver_framework:libhdf_utils", - "device_driver_framework:libhdi", "eventhandler:libeventhandler", + "hdf_core:libhdf_utils", + "hdf_core:libhdi", "i18n:zone_util", "ipc:ipc_core", "netmanager_base:net_conn_manager_if", diff --git a/bundle.json b/bundle.json index a7435775d..03e8f5d69 100755 --- a/bundle.json +++ b/bundle.json @@ -34,7 +34,7 @@ "ability_runtime", "appexecfwk_standard", "common_event_service", - "device_driver_framework", + "hdf_core", "dmsfwk_standard", "i18n", "ipc", diff --git a/services/network_search/test/BUILD.gn b/services/network_search/test/BUILD.gn index c20409b81..58cd1c20c 100644 --- a/services/network_search/test/BUILD.gn +++ b/services/network_search/test/BUILD.gn @@ -13,7 +13,7 @@ import("//base/telephony/core_service/core_service_aafwk.gni") import("//build/ohos.gni") -import("//drivers/adapter/uhdf2/uhdf.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") ohos_executable("tel_network_search_test") { install_enable = true diff --git a/services/sim/test/BUILD.gn b/services/sim/test/BUILD.gn index 05f036410..bac01c9d4 100755 --- a/services/sim/test/BUILD.gn +++ b/services/sim/test/BUILD.gn @@ -13,7 +13,7 @@ import("//base/telephony/core_service/core_service_aafwk.gni") import("//base/telephony/core_service/telephony.gni") import("//build/ohos.gni") -import("//drivers/adapter/uhdf2/uhdf.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") TELEPHONY_CORE_SERVICE_ROOT = "//base/telephony/core_service" TELEPHONY_SIM_ROOT = "//base/telephony/core_service/services/sim" diff --git a/services/tel_ril/include/tel_ril_common.h b/services/tel_ril/include/tel_ril_common.h index ad2def8fd..e8a200998 100755 --- a/services/tel_ril/include/tel_ril_common.h +++ b/services/tel_ril/include/tel_ril_common.h @@ -23,12 +23,5 @@ typedef enum { CORE_SERVICE_CDMA_LTE_PHONE = 3 } CoreServiceTelephonyType; -typedef enum { - HDF_SUCCESS = 0, /* The operation is successful. */ - HDF_FAILURE = -1, /* Failed to invoke the OS underlying function. */ - HDF_ERR_NOT_SUPPORT = -2, /* Not supported. */ - HDF_ERR_INVALID_PARAM = -3 /* Invalid parameter. */ -} HDF_STATUS; - typedef enum { CORE_SERVICE_SUCCESS = 0, CORE_SERVICE_ERROR = 1 } CoreServiceLteOptStatus; #endif \ No newline at end of file diff --git a/services/tel_ril/src/tel_ril_data.cpp b/services/tel_ril/src/tel_ril_data.cpp index 26b31b8d1..548c1777c 100644 --- a/services/tel_ril/src/tel_ril_data.cpp +++ b/services/tel_ril/src/tel_ril_data.cpp @@ -100,7 +100,7 @@ int32_t TelRilData::DeactivatePdpContext(int32_t cid, int32_t reason, const AppE uniInfo.gsmIndex = cid; uniInfo.arg1 = reason; int32_t ret = SendBufferEvent(HREQ_DATA_DEACTIVATE_PDP_CONTEXT, uniInfo); - if (ret != HDF_SUCCESS) { + if (ret != 0) { TELEPHONY_LOGE("Send HREQ_DATA_DEACTIVATE_PDP_CONTEXT return: %{public}d", ret); return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; } @@ -131,7 +131,7 @@ int32_t TelRilData::ActivatePdpContext(int32_t radioTechnology, DataProfile data dataCallInfo.roamingAllowed = allowRoaming; dataCallInfo.isRoaming = isRoaming; int32_t ret = SendBufferEvent(HREQ_DATA_ACTIVATE_PDP_CONTEXT, dataCallInfo); - if (ret != HDF_SUCCESS) { + if (ret != 0) { TELEPHONY_LOGE("Send HREQ_DATA_ACTIVATE_PDP_CONTEXT return: %{public}d", ret); return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; } @@ -188,7 +188,7 @@ int32_t TelRilData::GetPdpContextList(const AppExecFwk::InnerEvent::Pointer &res UniInfo uniInfo; uniInfo.serial = telRilRequest->serialId_; int32_t ret = SendBufferEvent(HREQ_DATA_GET_PDP_CONTEXT_LIST, uniInfo); - if (ret != HDF_SUCCESS) { + if (ret != 0) { TELEPHONY_LOGE("HREQ_DATA_GET_PDP_CONTEXT_LIST return: %{public}d", ret); return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; } @@ -262,7 +262,7 @@ int32_t TelRilData::SetInitApnInfo(const DataProfile &dataProfile, const AppExec dataProfileInfo.serial = telRilRequest->serialId_; int32_t ret = SendBufferEvent(HREQ_DATA_SET_INIT_APN_INFO, dataProfileInfo); - if (ret != HDF_SUCCESS) { + if (ret != 0) { TELEPHONY_LOGE("Send HREQ_DATA_ACTIVATE_PDP_CONTEXT return: %{public}d", ret); return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; } @@ -372,7 +372,7 @@ int32_t TelRilData::SetLinkBandwidthReportingRule( TELEPHONY_LOGI("maximumUplinkKbpsSize:%{public}d, maximumDownlinkKbpsSize:%{public}d", dLinkBandwidth.maximumUplinkKbpsSize, dLinkBandwidth.maximumDownlinkKbpsSize); int32_t ret = SendBufferEvent(HREQ_DATA_SET_LINK_BANDWIDTH_REPORTING_RULE, dLinkBandwidth); - if (ret != HDF_SUCCESS) { + if (ret != 0) { TELEPHONY_LOGE("HREQ_DATA_SET_LINK_BANDWIDTH_REPORTING_RULE return: %{public}d", ret); return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; } diff --git a/services/tel_ril/test/BUILD.gn b/services/tel_ril/test/BUILD.gn index 78045a520..c1d2c0ba8 100644 --- a/services/tel_ril/test/BUILD.gn +++ b/services/tel_ril/test/BUILD.gn @@ -13,7 +13,7 @@ import("//base/telephony/core_service/telephony.gni") import("//build/ohos.gni") -import("//drivers/adapter/uhdf2/uhdf.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") TELEPHONY_CORE_SERVICE_ROOT = "//base/telephony/core_service" TELEPHONY_SIM_ROOT = "//base/telephony/core_service/services/sim" diff --git a/test/unittest/tel_ril_gtest/BUILD.gn b/test/unittest/tel_ril_gtest/BUILD.gn index 544e41cd6..66a5135d7 100644 --- a/test/unittest/tel_ril_gtest/BUILD.gn +++ b/test/unittest/tel_ril_gtest/BUILD.gn @@ -34,7 +34,7 @@ ohos_unittest("tel_ril_gtest") { "//base/telephony/core_service/services/tel_ril/include", "//base/telephony/core_service/services/sim/include", "//utils/native/base/include", - "//drivers/adapter/uhdf2/include/hdi", + "//drivers/hdf_core/adapter/uhdf2/include/hdi", ] deps = [