add telephony ext service.

Signed-off-by: clevercong <lichunlin2@huawei.com>
This commit is contained in:
clevercong 2023-10-26 21:44:57 +08:00
parent 21fe898d81
commit bccdd91ef3
7 changed files with 163 additions and 0 deletions

View File

@ -12,16 +12,19 @@
# limitations under the License.
import("//build/ohos.gni")
import("telephony_core_service.gni")
TELEPHONY_NETWORK_SEARCH_ROOT = "services/network_search"
TELEPHONY_SIM_ROOT = "services/sim"
TELEPHONY_TEL_RIL_ROOT = "services/tel_ril"
TELEPHONY_IMS_CORE_SERVICE_SRC_PATH = "services/ims_service_interaction/src"
TELEPHONY_EXT_WRAPPER_ROOT = "services/telephony_ext_wrapper"
ohos_shared_library("tel_core_service") {
install_enable = true
sources = [
"$TELEPHONY_EXT_WRAPPER_ROOT/src/telephony_ext_wrapper.cpp",
"$TELEPHONY_IMS_CORE_SERVICE_SRC_PATH/ims_core_service_callback_stub.cpp",
"$TELEPHONY_IMS_CORE_SERVICE_SRC_PATH/ims_core_service_client.cpp",
"$TELEPHONY_IMS_CORE_SERVICE_SRC_PATH/ims_core_service_proxy.cpp",
@ -110,6 +113,7 @@ ohos_shared_library("tel_core_service") {
"$TELEPHONY_SIM_ROOT/include",
"$TELEPHONY_TEL_RIL_ROOT/include",
"$TELEPHONY_NETWORK_SEARCH_ROOT/include",
"$TELEPHONY_EXT_WRAPPER_ROOT/include",
"services/core/include",
"utils/log/include",
]
@ -122,6 +126,8 @@ ohos_shared_library("tel_core_service") {
"OPENSSL_SUPPRESS_DEPRECATED",
]
defines += telephony_extra_defines
deps = [
"interfaces/innerkits:tel_core_service_api",
"utils:libtel_common",

View File

@ -30,6 +30,7 @@
#include "telephony_errors.h"
#include "telephony_log_wrapper.h"
#include "telephony_permission.h"
#include "telephony_ext_wrapper.h"
namespace OHOS {
namespace Telephony {
@ -104,6 +105,13 @@ bool CoreService::Init()
}
simManager_->SetNetworkSearchManager(networkSearchManager_);
CoreManagerInner::GetInstance().OnInit(networkSearchManager_, simManager_, telRilManager_);
#ifdef OHOS_BUILD_ENABLE_TELEPHONY_EXT
TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
if (TELEPHONY_EXT_WRAPPER.function_example_) {
// only example, when other functions are added, please delete it.
TELEPHONY_LOGD("CoreService::Init is not empty.");
}
#endif
TELEPHONY_LOGI("CoreService::Init success");
return true;
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TELEPHONY_EXT_WRAPPER_H
#define TELEPHONY_EXT_WRAPPER_H
#include "nocopyable.h"
#include "singleton.h"
namespace OHOS {
namespace Telephony {
class TelephonyExtWrapper final {
DECLARE_DELAYED_REF_SINGLETON(TelephonyExtWrapper);
public:
DISALLOW_COPY_AND_MOVE(TelephonyExtWrapper);
void InitTelephonyExtWrapper();
// only example, when other functions are added, please delete it.
typedef void (*FUNCTION_EXAMPLE)(int32_t&);
// only example, when other functions are added, please delete it.
FUNCTION_EXAMPLE function_example_ = nullptr;
private:
void* telephonyExtWrapperHandle_ = nullptr;
};
#define TELEPHONY_EXT_WRAPPER ::OHOS::DelayedRefSingleton<TelephonyExtWrapper>::GetInstance()
} // namespace Telephony
} // namespace OHOS
#endif // TELEPHONY_EXT_WRAPPER_H

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <dlfcn.h>
#include "telephony_ext_wrapper.h"
#include "telephony_log_wrapper.h"
namespace OHOS {
namespace Telephony {
namespace {
const std::string TELEPHONY_EXT_WRAPPER_PATH = "libtelephony_ext_service.z.so";
} // namespace
TelephonyExtWrapper::TelephonyExtWrapper() {}
TelephonyExtWrapper::~TelephonyExtWrapper()
{
TELEPHONY_LOGD("TelephonyExtWrapper::~TelephonyExtWrapper() start");
dlclose(telephonyExtWrapperHandle_);
telephonyExtWrapperHandle_ = nullptr;
}
void TelephonyExtWrapper::InitTelephonyExtWrapper()
{
TELEPHONY_LOGD("TelephonyExtWrapper::InitTelephonyExtWrapper() start");
telephonyExtWrapperHandle_ = dlopen(TELEPHONY_EXT_WRAPPER_PATH.c_str(), RTLD_NOW);
if (telephonyExtWrapperHandle_ == nullptr) {
TELEPHONY_LOGE("libtelephony_ext_service.z.so was not loaded, error: %{public}s", dlerror());
return;
}
// only example, when other functions are added, please delete it.
function_example_ = (FUNCTION_EXAMPLE)dlsym(telephonyExtWrapperHandle_, "FunctionExample");
// Check whether all function pointers are empty.
if (function_example_ == nullptr) {
TELEPHONY_LOGE("telephony ext wrapper symbol failed, error: %{public}s", dlerror());
return;
}
TELEPHONY_LOGI("telephony ext wrapper init success");
}
} // namespace Telephony
} // namespace OHOS

View File

@ -0,0 +1,33 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
declare_args() {
telephony_ext_feature = false
telephony_vsim_feature = false
telephony_fullnetwork_feature = false
}
print("telephony_ext_feature = ${telephony_ext_feature}")
telephony_extra_defines = []
if (telephony_ext_feature) {
telephony_extra_defines += [ "OHOS_BUILD_ENABLE_TELEPHONY_EXT" ]
}
if (telephony_vsim_feature) {
telephony_extra_defines += [ "OHOS_BUILD_ENABLE_TELEPHONY_VSIM" ]
}
if (telephony_fullnetwork_feature) {
telephony_extra_defines += [ "OHOS_BUILD_ENABLE_TELEPHONY_FULLNETWORK" ]
}

View File

@ -48,6 +48,7 @@ ohos_unittest("tel_core_service_gtest") {
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]

View File

@ -29,6 +29,7 @@
#include "str_convert.h"
#include "string_ex.h"
#include "tel_profile_util.h"
#include "telephony_ext_wrapper.h"
namespace OHOS {
namespace Telephony {
@ -349,6 +350,23 @@ HWTEST_F(SimTest, Telephony_Sim_GetDefaultVoiceSimId_0100, Function | MediumTest
TELEPHONY_LOGI("TelephonyTestService has no sim card");
}
}
/**
* @tc.number Telephony_Sim_InitTelephonyExtService_0100
* @tc.name Init Telephony Ext Service.
* @tc.desc Function test
*/
HWTEST_F(SimTest, Telephony_Sim_InitTelephonyExtService_0100, Function | MediumTest | Level1)
{
AccessToken token;
TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
if (TELEPHONY_EXT_WRAPPER.telephonyExtWrapperHandle_ == nullptr) {
TELEPHONY_LOGI("telephonyExtWrapperHandle_ null");
} else {
TELEPHONY_LOGI("telephonyExtWrapperHandle_ not null");
EXPECT_EQ(TELEPHONY_EXT_WRAPPER.function_example_ != nullptr, true);
}
}
#endif // TEL_TEST_UNSUPPORT
} // namespace Telephony
} // namespace OHOS