diff --git a/services/samgr/native/include/system_ability_manager.h b/services/samgr/native/include/system_ability_manager.h index 883e0b814074fb3d4c6c88bae6725c93727d3800..5558354314d3bd6e6ca66f515c44b54341c42193 100755 --- a/services/samgr/native/include/system_ability_manager.h +++ b/services/samgr/native/include/system_ability_manager.h @@ -150,6 +150,7 @@ private: sptr localAbilityManagerDeath_; sptr systemReadyCallbackDeath_; sptr dBinderService_; + bool isDbinderStart_ = false; // must hold abilityMapLock_ never access other locks std::shared_mutex abilityMapLock_; diff --git a/services/samgr/native/source/sa_main.cpp b/services/samgr/native/source/sa_main.cpp index 030f394fe303dab0f8a30a7718ffdd9575ba9be5..d5550c990e12e4a9feb3592d250e6ff06e4e7dbb 100755 --- a/services/samgr/native/source/sa_main.cpp +++ b/services/samgr/native/source/sa_main.cpp @@ -13,9 +13,6 @@ * limitations under the License. */ -#include -#include - #include "errors.h" #include "ipc_skeleton.h" #include "ipc_types.h" @@ -25,18 +22,6 @@ using namespace OHOS; -void startDBinderService(OHOS::sptr manager) { - int time = 15; - while (time-- > 0) { - sleep(1); - } - auto dBinder = manager->GetDBinder(); - if (dBinder != nullptr) { - bool ret = dBinder->StartDBinderService(); - HILOGI("started dbinder service result is %{public}s", ret ? "ok" : "fail"); - } -} - int main(int argc, char *argv[]) { HILOGI("%{public}s called, enter System Ability Manager ", __func__); @@ -46,8 +31,6 @@ int main(int argc, char *argv[]) // Tell IPCThreadState we're the service manager OHOS::sptr serv = manager->AsObject(); IPCSkeleton::SetContextObject(serv); - std::thread th(startDBinderService, manager); - th.detach(); // Create IPCThreadPool and join in. HILOGI("start System Ability Manager Loop"); diff --git a/services/samgr/native/source/system_ability_manager.cpp b/services/samgr/native/source/system_ability_manager.cpp index a02647f3a1b2c0d6478e1f6fb40348538cf8c966..82b08fa6f8152c0c906f158e7fa413718e9a9305 100755 --- a/services/samgr/native/source/system_ability_manager.cpp +++ b/services/samgr/native/source/system_ability_manager.cpp @@ -772,6 +772,13 @@ int32_t SystemAbilityManager::AddSystemAbility(int32_t systemAbilityId, const sp dBinderService_->RegisterRemoteProxy(strName, systemAbilityId); HILOGD("AddSystemAbility RegisterRemoteProxy, serviceId is %{public}d", systemAbilityId); } + if (systemAbilityId == SOFTBUS_SERVER_SA_ID && !isDbinderStart_) { + if (dBinderService_ != nullptr) { + bool ret = dBinderService_->StartDBinderService(); + HILOGI("startd dbinder service result is %{public}s", ret ? "ok" : "fail"); + isDbinderStart_ = true; + } + } return ERR_OK; }