diff --git a/frameworks/native/source/system_ability_manager_proxy.cpp b/frameworks/native/source/system_ability_manager_proxy.cpp index a18dd8d56d0f547a46aa6589044a037513957a30..8e4b0578b008ef06311cd732f19e4f4862ed5368 100755 --- a/frameworks/native/source/system_ability_manager_proxy.cpp +++ b/frameworks/native/source/system_ability_manager_proxy.cpp @@ -25,7 +25,6 @@ #include "string_ex.h" #include "sam_log.h" -#include "system_ability_info.h" using namespace std; namespace OHOS { @@ -33,71 +32,12 @@ namespace { const int32_t RETRY_TIME_OUT_NUMBER = 10; const int32_t SLEEP_INTERVAL_TIME = 100; const int32_t SLEEP_ONE_MILLI_SECOND_TIME = 1000; -const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken"; -constexpr int32_t MAX_SYSCAP_NAME_LEN = 64; } sptr SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId) { return GetSystemAbilityWrapper(systemAbilityId); } -bool SystemAbilityManagerProxy::GetSystemAbilityInfoList(int32_t systemAbilityId, - const std::u16string& capability, std::list>& saInfoList) -{ - HILOGD("GetSystemAbilityInfoList called, systemAbilityId is %{public}d", systemAbilityId); - if (!CheckInputSysAbilityId(systemAbilityId)) { - HILOGE("GetSystemAbilityInfoList systemAbilityId is invalid"); - return false; - } - - auto remote = Remote(); - if (remote == nullptr) { - HILOGI("remote is nullptr!"); - return false; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - HILOGW("GetSystemAbilityInfoList write InterfaceToken failed!"); - return false; - } - bool ret = data.WriteInt32(systemAbilityId); - if (!ret) { - HILOGW("GetSystemAbilityInfoList write systemAbilityId failed!"); - return false; - } - ret = data.WriteString16(capability); - if (!ret) { - HILOGW("GetSystemAbilityInfoList write capability failed!"); - return false; - } - - MessageParcel reply; - MessageOption option; - int32_t err = remote->SendRequest(GET_SYSTEM_ABILITYINFOLIST_TRANSACTION, data, reply, option); - if (err != ERR_NONE) { - return false; - } - ret = reply.ReadBool(); - if (!ret) { - HILOGW("GetSystemAbilityInfoList read vector failed!"); - return false; - } - int32_t replySize = 0; - ret = reply.ReadInt32(replySize); - if (!ret) { - HILOGW("GetSystemAbilityInfoList read replySize failed!"); - return false; - } - for (int32_t i = 0; i < replySize; i++) { - std::shared_ptr spSAInfo(reply.ReadParcelable()); - if (spSAInfo != nullptr) { - saInfoList.emplace_back(spSAInfo); - } - } - return true; -} - sptr SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { @@ -120,7 +60,8 @@ sptr SystemAbilityManagerProxy::GetSystemAbilityWrapper(int32_t s svc = CheckSystemAbility(systemAbilityId, isExist); if (!isExist) { HILOGE("%{public}s:sa %{public}d is not exist", __func__, systemAbilityId); - return nullptr; + usleep(SLEEP_ONE_MILLI_SECOND_TIME * SLEEP_INTERVAL_TIME); + continue; } } else { svc = CheckSystemAbility(systemAbilityId, deviceId); @@ -169,25 +110,6 @@ sptr SystemAbilityManagerProxy::CheckSystemAbility(int32_t system return CheckSystemAbilityWrapper(CHECK_SYSTEM_ABILITY_TRANSACTION, data); } -sptr SystemAbilityManagerProxy::CheckLocalAbilityManager(const u16string& name) -{ - HILOGI("%{public}s called", __func__); - if (name.empty()) { - HILOGI("name is nullptr."); - return nullptr; - } - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return nullptr; - } - bool ret = data.WriteString16(name); - if (!ret) { - HILOGW("CheckLocalAbilityManager Write name failed!"); - return nullptr; - } - return CheckSystemAbilityWrapper(CHECK_LOCAL_ABILITY_TRANSACTION, data); -} - sptr SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { if (!CheckInputSysAbilityId(systemAbilityId) || deviceId.empty()) { @@ -321,157 +243,6 @@ int32_t SystemAbilityManagerProxy::AddOnDemandSystemAbilityInfo(int32_t systemAb return result; } -int32_t SystemAbilityManagerProxy::RecycleOnDemandSystemAbility() -{ - HILOGI("%{public}s called", __func__); - - auto remote = Remote(); - if (remote == nullptr) { - HILOGE("RecycleOnDemandSystemAbility remote is nullptr !"); - return ERR_INVALID_OPERATION; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return ERR_FLATTEN_OBJECT; - } - int32_t err = remote->SendRequest(RECYCLE_ONDEMAND_SYSTEM_ABILITY_TRANSACTION, data, reply, option); - - HILOGI("%{public}s:recycle ondemand system ability %{public}s, return %{public}d", - __func__, err ? "fail" : "succ", err); - if (err != ERR_NONE) { - HILOGE("RecycleOnDemandSystemAbility SendRequest error:%{public}d!", err); - return err; - } - - int32_t result = 0; - if (!reply.ReadInt32(result)) { - HILOGW("RecycleOnDemandSystemAbility Read result failed!"); - return ERR_FLATTEN_OBJECT; - } - - return result; -} - -int32_t SystemAbilityManagerProxy::ConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) -{ - HILOGI("%{public}s called", __func__); - if (!CheckInputSysAbilityId(systemAbilityId)) { - HILOGE("ConnectSystemAbility systemAbilityId invalid."); - return ERR_INVALID_VALUE; - } - - if (connectionCallback == nullptr) { - HILOGE("ConnectSystemAbility connectionCallback nullptr."); - return ERR_INVALID_VALUE; - } - HILOGI("connection ondemand system ability name is : %{public}d ", systemAbilityId); - - auto remote = Remote(); - if (remote == nullptr) { - HILOGE("ConnectSystemAbility remote is nullptr !"); - return ERR_INVALID_OPERATION; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return ERR_FLATTEN_OBJECT; - } - bool ret = data.WriteInt32(systemAbilityId); - if (!ret) { - HILOGW("ConnectSystemAbility Write name failed!"); - return ERR_FLATTEN_OBJECT; - } - ret = data.WriteRemoteObject(connectionCallback->AsObject()); - if (!ret) { - HILOGW("ConnectSystemAbility Write connectionCallback failed!"); - return ERR_FLATTEN_OBJECT; - } - - MessageParcel reply; - MessageOption option { MessageOption::TF_ASYNC }; - int32_t err = remote->SendRequest(CONNECTION_SYSTEM_ABILITY_TRANSACTION, data, reply, option); - - HILOGI("%{public}s:connect ondemand system ability %{public}d %{public}s, err: %{public}d", - __func__, systemAbilityId, err ? "fail" : "succ", err); - - return err; -} - -int32_t SystemAbilityManagerProxy::DisConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) -{ - HILOGI("%{public}s called", __func__); - if (!CheckInputSysAbilityId(systemAbilityId)) { - HILOGE("DisConnectSystemAbility systemAbilityId is invalid."); - return ERR_INVALID_VALUE; - } - if (connectionCallback == nullptr) { - HILOGE("DisConnectSystemAbility connectionCallback nullptr."); - return ERR_INVALID_VALUE; - } - HILOGI("disconnect ondemand system ability name is : %{public}d ", systemAbilityId); - - auto remote = Remote(); - if (remote == nullptr) { - HILOGE("DisConnectSystemAbility remote is nullptr !"); - return ERR_INVALID_OPERATION; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return ERR_FLATTEN_OBJECT; - } - bool ret = data.WriteInt32(systemAbilityId); - if (!ret) { - HILOGW("DisConnectSystemAbility Write systemAbilityId failed!"); - return ERR_FLATTEN_OBJECT; - } - - ret = data.WriteRemoteObject(connectionCallback->AsObject()); - if (!ret) { - HILOGW("DisConnectSystemAbility Write connectionCallback failed!"); - return ERR_FLATTEN_OBJECT; - } - - MessageParcel reply; - MessageOption option { MessageOption::TF_ASYNC }; - int32_t err = remote->SendRequest(DISCONNECTION_SYSTEM_ABILITY_TRANSACTION, data, reply, - option); - - HILOGI("%{public}s:disconnect ondemand system ability %{public}d %{public}s, err: %{public}d", - __func__, systemAbilityId, err ? "fail" : "succ", err); - - return err; -} - -int32_t SystemAbilityManagerProxy::AddLocalAbilityManager(const u16string& name, const sptr& ability) -{ - HILOGI("%{public}s called, local ability name is %{public}s", __func__, Str16ToStr8(name).c_str()); - if (name.empty()) { - HILOGI("name is invalid."); - return ERR_INVALID_VALUE; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteString16(name)) { - HILOGW("AddLocalAbilityManager Write name failed!"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteRemoteObject(ability)) { - HILOGW("AddLocalAbilityManager Write ability failed!"); - return ERR_FLATTEN_OBJECT; - } - return AddSystemAbilityWrapper(ADD_LOCAL_ABILITY_TRANSACTION, data); -} - int32_t SystemAbilityManagerProxy::RemoveSystemAbilityWrapper(int32_t code, MessageParcel& data) { sptr remote = Remote(); @@ -518,28 +289,6 @@ int32_t SystemAbilityManagerProxy::RemoveSystemAbility(int32_t systemAbilityId) return RemoveSystemAbilityWrapper(REMOVE_SYSTEM_ABILITY_TRANSACTION, data); } -int32_t SystemAbilityManagerProxy::RemoveLocalAbilityManager(const u16string& name) -{ - HILOGI("%{public}s called", __func__); - if (name.empty()) { - HILOGI("name is null."); - return ERR_INVALID_VALUE; - } - - HILOGI("RemoveLocalAbilityManager name is : %{public}s \n", Str16ToStr8(name).c_str()); - - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return ERR_FLATTEN_OBJECT; - } - bool ret = data.WriteString16(name); - if (!ret) { - HILOGW("RemoveLocalAbilityManager Write name failed!"); - return ERR_FLATTEN_OBJECT; - } - return RemoveSystemAbilityWrapper(REMOVE_LOCAL_ABILITY_TRANSACTION, data); -} - std::vector SystemAbilityManagerProxy::ListSystemAbilities(unsigned int dumpFlags) { HILOGI("%{public}s called", __func__); @@ -579,17 +328,16 @@ std::vector SystemAbilityManagerProxy::ListSystemAbilities(unsigned i return saNames; } -int32_t SystemAbilityManagerProxy::SubscribeSystemAbility(int32_t systemAbilityId, const std::u16string& listenerName) +int32_t SystemAbilityManagerProxy::SubscribeSystemAbility(int32_t systemAbilityId, + const sptr& listener) { HILOGI("%{public}s called", __func__); - if (!CheckInputSysAbilityId(systemAbilityId) || listenerName.empty()) { - HILOGE("SubscribeSystemAbility systemAbilityId:%{public}d or listenerName:%{public}s invalid!", - systemAbilityId, Str16ToStr8(listenerName).c_str()); + if (!CheckInputSysAbilityId(systemAbilityId) || listener == nullptr) { + HILOGE("SubscribeSystemAbility systemAbilityId:%{public}d or listener invalid!", systemAbilityId); return ERR_INVALID_VALUE; } - HILOGD("SubscribeSystemAbility systemAbilityId:%{public}d: listenerName:%{public}s", - systemAbilityId, Str16ToStr8(listenerName).c_str()); + HILOGI("SubscribeSystemAbility systemAbilityId:%{public}d", systemAbilityId); sptr remote = Remote(); if (remote == nullptr) { @@ -607,7 +355,7 @@ int32_t SystemAbilityManagerProxy::SubscribeSystemAbility(int32_t systemAbilityI return ERR_FLATTEN_OBJECT; } - ret = data.WriteString16(listenerName); + ret = data.WriteRemoteObject(listener->AsObject()); if (!ret) { HILOGW("SubscribeSystemAbility Write listenerName failed!"); return ERR_FLATTEN_OBJECT; @@ -616,14 +364,11 @@ int32_t SystemAbilityManagerProxy::SubscribeSystemAbility(int32_t systemAbilityI MessageParcel reply; MessageOption option; int32_t err = remote->SendRequest(SUBSCRIBE_SYSTEM_ABILITY_TRANSACTION, data, reply, option); - - HILOGI("%{public}s : systemAbilityId:%{public}d: listenerName:%{public}s : %{public}s return %{public}d", - __func__, systemAbilityId, Str16ToStr8(listenerName).c_str(), err ? "fail" : "succ", err); if (err != ERR_NONE) { HILOGE("SubscribeSystemAbility SendRequest error:%{public}d!", err); return err; } - + HILOGI("SubscribeSystemAbility SendRequest succeed!"); int32_t result = 0; ret = reply.ReadInt32(result); if (!ret) { @@ -634,17 +379,16 @@ int32_t SystemAbilityManagerProxy::SubscribeSystemAbility(int32_t systemAbilityI return result; } -int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilityId, const std::u16string& listenerName) +int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilityId, + const sptr& listener) { HILOGI("%{public}s called", __func__); - if (!CheckInputSysAbilityId(systemAbilityId) || listenerName.empty()) { - HILOGE("UnSubscribeSystemAbility systemAbilityId:%{public}d or listenerName:%{public}s invalid!", - systemAbilityId, Str16ToStr8(listenerName).c_str()); + if (!CheckInputSysAbilityId(systemAbilityId) || listener == nullptr) { + HILOGE("UnSubscribeSystemAbility systemAbilityId:%{public}d or listener invalid!", systemAbilityId); return ERR_INVALID_VALUE; } - HILOGD("UnSubscribeSystemAbility systemAbilityId:%{public}d: listenerName:%{public}s", - systemAbilityId, Str16ToStr8(listenerName).c_str()); + HILOGI("UnSubscribeSystemAbility systemAbilityId:%{public}d", systemAbilityId); sptr remote = Remote(); if (remote == nullptr) { @@ -662,7 +406,7 @@ int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilit return ERR_FLATTEN_OBJECT; } - ret = data.WriteString16(listenerName); + ret = data.WriteRemoteObject(listener->AsObject()); if (!ret) { HILOGW("UnSubscribeSystemAbility Write listenerSaId failed!"); return ERR_FLATTEN_OBJECT; @@ -671,14 +415,11 @@ int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilit MessageParcel reply; MessageOption option; int32_t err = remote->SendRequest(UNSUBSCRIBE_SYSTEM_ABILITY_TRANSACTION, data, reply, option); - - HILOGI("%{public}s : systemAbilityId:%{public}d: listenerName:%{public}s : %{public}s return %{public}d", - __func__, systemAbilityId, Str16ToStr8(listenerName).c_str(), err ? "fail" : "succ", err); if (err != ERR_NONE) { HILOGE("UnSubscribeSystemAbility SendRequest error:%{public}d!", err); return err; } - + HILOGI("UnSubscribeSystemAbility SendRequest succeed!"); int32_t result = 0; ret = reply.ReadInt32(result); if (!ret) { @@ -689,75 +430,6 @@ int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilit return result; } -const std::u16string SystemAbilityManagerProxy::CheckOnDemandSystemAbility(int32_t systemAbilityId) -{ - HILOGI("%{public}s called", __func__); - std::u16string localManagerName; - auto remote = Remote(); - if (remote == nullptr) { - HILOGE("CheckOnDemandSystemAbility remote is nullptr !"); - return localManagerName; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return localManagerName; - } - bool ret = data.WriteInt32(systemAbilityId); - if (!ret) { - HILOGW("CheckOnDemandSystemAbility Write name failed!"); - return localManagerName; - } - - MessageParcel reply; - MessageOption option; - int32_t err = remote->SendRequest(CHECK_ONDEMAND_SYSTEM_ABILITY_TRANSACTION, data, reply, option); - if (err != ERR_NONE) { - HILOGE("CheckOnDemandSystemAbility SendRequest error:%{public}d!", err); - return localManagerName; - } - - localManagerName = reply.ReadString16(); - if (localManagerName.empty()) { - HILOGW("CheckOnDemandSystemAbility localManagerName is empty!"); - } - return localManagerName; -} - -bool SystemAbilityManagerProxy::GetDeviceId(string& deviceId) -{ - HILOGI("%{public}s called", __func__); - sptr remote = Remote(); - if (remote == nullptr) { - HILOGI("remote is nullptr !"); - return false; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return false; - } - int32_t err = remote->SendRequest(GET_LOCAL_DEVICE_ID_TRANSACTION, data, reply, option); - if (err != ERR_NONE) { - HILOGE("GetDeviceId SendRequest error:%{public}d!", err); - return false; - } - bool ret = reply.ReadString(deviceId); - if (!ret) { - HILOGW("GetDeviceId Read deviceId failed!"); - return false; - } - bool result = false; - ret = reply.ReadBool(result); - if (!ret) { - HILOGW("GetDeviceId Read result failed!"); - return false; - } - return result; -} - int32_t SystemAbilityManagerProxy::MarshalSAExtraProp(const SAExtraProp& extraProp, MessageParcel& data) const { if (!data.WriteBool(extraProp.isDistributed)) { @@ -833,178 +505,27 @@ int32_t SystemAbilityManagerProxy::AddSystemAbilityWrapper(int32_t code, Message return result; } -int32_t SystemAbilityManagerProxy::RegisterSystemReadyCallback(const sptr& systemReadyCallback) +int32_t SystemAbilityManagerProxy::AddSystemProcess(const u16string& procName, const sptr& procObject) { - if (systemReadyCallback == nullptr) { + HILOGI("%{public}s called, process name is %{public}s", __func__, Str16ToStr8(procName).c_str()); + if (procName.empty()) { + HILOGI("process name is invalid!"); return ERR_INVALID_VALUE; } - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteRemoteObject(systemReadyCallback)) { - HILOGW("RegisterSystemReadyCallback Write systemReadyCallback failed!"); - return ERR_FLATTEN_OBJECT; - } - sptr remote = Remote(); - if (remote == nullptr) { - HILOGI("remote is nullptr !"); - return ERR_INVALID_OPERATION; - } - - MessageParcel reply; - MessageOption option; - int32_t err = remote->SendRequest(REGISTER_SYSTEM_READY_CALLBACK, data, reply, option); - if (err != ERR_NONE) { - HILOGE("RegisterSystemReadyCallback SendRequest error:%{public}d!", err); - return err; - } - int32_t result = 0; - bool ret = reply.ReadInt32(result); - if (!ret) { - HILOGE("RegisterSystemReadyCallback read result error!"); - return ERR_FLATTEN_OBJECT; - } - return result; -} - -int32_t SystemAbilityManagerProxy::GetCoreSystemAbilityList(std::vector& coreSaList, int dumpMode) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteInt32(dumpMode)) { - return ERR_FLATTEN_OBJECT; - } - sptr remote = Remote(); - if (remote == nullptr) { - HILOGI("remote is nullptr !"); - return ERR_INVALID_OPERATION; - } - - MessageParcel reply; - MessageOption option; - int32_t err = remote->SendRequest(GET_CORE_SYSTEM_ABILITY_LIST, data, reply, option); - if (err != ERR_NONE) { - HILOGE("GetCoreSaList SendRequest error:%{public}d!", err); - return err; - } - int32_t result = 0; - bool ret = reply.ReadInt32(result); - if (!ret) { - HILOGE("GetCoreSaList read result error!"); - return ERR_FLATTEN_OBJECT; - } - if (result == ERR_NONE && (!reply.ReadInt32Vector(&coreSaList))) { - HILOGE("GetCoreSaList ReadInt32Vector error!"); - return ERR_FLATTEN_OBJECT; - } - return result; -} -int32_t SystemAbilityManagerProxy::AddSystemCapability(const std::string& sysCap) -{ - if (sysCap.empty() || sysCap.length() > MAX_SYSCAP_NAME_LEN) { - return ERR_INVALID_VALUE; - } MessageParcel data; if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteString16(Str8ToStr16(sysCap))) { - HILOGW("%{public}s Write sysCap failed!", __func__); + if (!data.WriteString16(procName)) { + HILOGW("AddSystemProcess Write name failed!"); return ERR_FLATTEN_OBJECT; } - sptr remote = Remote(); - if (remote == nullptr) { - HILOGI("AddSystemCapability remote is nullptr !"); - return ERR_INVALID_OPERATION; - } - - MessageParcel reply; - MessageOption option; - int32_t err = remote->SendRequest(ADD_SYSTEM_CAPABILITY, data, reply, option); - if (err != ERR_NONE) { - HILOGE("%{public}s SendRequest error:%{public}d!", __func__, err); - return err; - } - int32_t result = 0; - bool ret = reply.ReadInt32(result); - if (!ret) { - HILOGE("%{public}s read result error!", __func__); + if (!data.WriteRemoteObject(procObject)) { + HILOGW("AddSystemProcess Write ability failed!"); return ERR_FLATTEN_OBJECT; } - return result; -} - -bool SystemAbilityManagerProxy::HasSystemCapability(const std::string& sysCap) -{ - if (sysCap.empty() || sysCap.length() > MAX_SYSCAP_NAME_LEN) { - return false; - } - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return false; - } - if (!data.WriteString16(Str8ToStr16(sysCap))) { - HILOGW("%{public}s Write sysCap failed!", __func__); - return false; - } - - sptr remote = Remote(); - if (remote == nullptr) { - HILOGI("HasSystemCapability remote is nullptr !"); - return false; - } - - MessageParcel reply; - MessageOption option; - int32_t err = remote->SendRequest(HAS_SYSTEM_CAPABILITY, data, reply, option); - if (err != ERR_NONE) { - HILOGE("%{public}s SendRequest error:%{public}d!", __func__, err); - return false; - } - bool result = false; - bool ret = reply.ReadBool(result); - if (!ret) { - HILOGE("%{public}s read result error!", __func__); - return false; - } - return result; -} - -vector SystemAbilityManagerProxy::GetSystemAvailableCapabilities() -{ - vector sysCaps; - MessageParcel data; - if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) { - return sysCaps; - } - - sptr remote = Remote(); - if (remote == nullptr) { - HILOGI("GetSystemAvailableCapabilities remote is nullptr !"); - return sysCaps; - } - - MessageParcel reply; - MessageOption option; - int32_t err = remote->SendRequest(GET_AVAILABLE_SYSTEM_CAPABILITY, data, reply, option); - if (err != ERR_NONE) { - HILOGE("%{public}s SendRequest error:%{public}d!", __func__, err); - return sysCaps; - } - vector result; - bool ret = reply.ReadString16Vector(&result); - if (!ret) { - HILOGE("%{public}s read result error!", __func__); - return sysCaps; - } - for (const u16string& sysCap : result) { - sysCaps.emplace_back(Str16ToStr8(sysCap)); - } - return sysCaps; + return AddSystemAbilityWrapper(ADD_SYSTEM_PROCESS_TRANSACTION, data); } } // namespace OHOS diff --git a/frameworks/native/source/system_ability_status_change_stub.cpp b/frameworks/native/source/system_ability_status_change_stub.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a8c6ffd0f51e0d16cb73b90153b32ae09b386e00 --- /dev/null +++ b/frameworks/native/source/system_ability_status_change_stub.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2021 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 "system_ability_status_change_stub.h" + +#include "ipc_skeleton.h" +#include "sam_log.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace { +constexpr int32_t UID_ROOT = 0; +constexpr int32_t UID_SYSTEM = 1000; +} +SystemAbilityStatusChangeStub::SystemAbilityStatusChangeStub() +{ + memberFuncMap_[ON_ADD_SYSTEM_ABILITY] = + &SystemAbilityStatusChangeStub::OnAddSystemAbilityInner; + memberFuncMap_[ON_REMOVE_SYSTEM_ABILITY] = + &SystemAbilityStatusChangeStub::OnRemoveSystemAbilityInner; +} + +int32_t SystemAbilityStatusChangeStub::OnRemoteRequest(uint32_t code, + MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + HILOGI("code:%{public}d, flags:%{public}d", code, option.GetFlags()); + if (!CanRequest()) { + HILOGW("permission denied!"); + return ERR_PERMISSION_DENIED; + } + if (!EnforceInterceToken(data)) { + HILOGW("check interface token failed!"); + return ERR_PERMISSION_DENIED; + } + auto iter = memberFuncMap_.find(code); + if (iter != memberFuncMap_.end()) { + auto memberFunc = iter->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data, reply); + } + } + HILOGW("unknown request code!"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int32_t SystemAbilityStatusChangeStub::OnAddSystemAbilityInner(MessageParcel& data, MessageParcel& reply) +{ + int32_t systemAbilityId = data.ReadInt32(); + if (!CheckInputSysAbilityId(systemAbilityId)) { + HILOGW("read systemAbilityId failed!"); + return ERR_NULL_OBJECT; + } + std::string deviceId = data.ReadString(); + OnAddSystemAbility(systemAbilityId, deviceId); + return ERR_NONE; +} + +int32_t SystemAbilityStatusChangeStub::OnRemoveSystemAbilityInner(MessageParcel& data, MessageParcel& reply) +{ + int32_t systemAbilityId = data.ReadInt32(); + if (!CheckInputSysAbilityId(systemAbilityId)) { + HILOGW("read systemAbilityId failed!"); + return ERR_NULL_OBJECT; + } + std::string deviceId = data.ReadString(); + OnRemoveSystemAbility(systemAbilityId, deviceId); + return ERR_NONE; +} + +bool SystemAbilityStatusChangeStub::CheckInputSysAbilityId(int32_t systemAbilityId) +{ + return (systemAbilityId >= FIRST_SYS_ABILITY_ID) && (systemAbilityId <= LAST_SYS_ABILITY_ID); +} + +bool SystemAbilityStatusChangeStub::CanRequest() +{ + auto callingUid = IPCSkeleton::GetCallingUid(); + return (callingUid == UID_ROOT) || (callingUid == UID_SYSTEM); +} + +bool SystemAbilityStatusChangeStub::EnforceInterceToken(MessageParcel& data) +{ + std::u16string interfaceToken = data.ReadInterfaceToken(); + return interfaceToken == GetDescriptor(); +} +} diff --git a/interfaces/innerkits/samgr_proxy/BUILD.gn b/interfaces/innerkits/samgr_proxy/BUILD.gn index 2c92a7ecfe3deea1d1090fd8295550ff3487eed8..47f0b41b9256b0b50c71196fb41464a6f1e3b1a6 100755 --- a/interfaces/innerkits/samgr_proxy/BUILD.gn +++ b/interfaces/innerkits/samgr_proxy/BUILD.gn @@ -38,9 +38,8 @@ config("samgr_proxy_private_config") { ohos_shared_library("samgr_proxy") { sources = [ - "//foundation/distributedschedule/samgr/frameworks/native/source/if_system_ability_manager.cpp", - "//foundation/distributedschedule/samgr/frameworks/native/source/system_ability_info.cpp", "//foundation/distributedschedule/samgr/frameworks/native/source/system_ability_manager_proxy.cpp", + "//foundation/distributedschedule/samgr/frameworks/native/source/system_ability_status_change_stub.cpp", "//foundation/distributedschedule/samgr/services/lsamgr/src/local_ability_manager_proxy.cpp", "//foundation/distributedschedule/samgr/services/samgr/native/source/service_registry.cpp", ] diff --git a/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h b/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h old mode 100644 new mode 100755 index 99449b93973f94c1da23fed16434a772f09aa311..6c12b2efb6cb968250e388fda9d742f90ead2dac --- a/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h +++ b/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h @@ -22,27 +22,13 @@ #include "iremote_broker.h" #include "iremote_object.h" #include "iremote_proxy.h" -#include "system_ability_info.h" -#include "if_system_ability_connection_callback.h" +#include "isystem_ability_status_change.h" namespace OHOS { class ISystemAbilityManager : public IRemoteBroker { public: - // Retrieve an existing localAbilityManager - virtual sptr CheckLocalAbilityManager(const std::u16string& name) = 0; - // Register an localAbilityManager just for sa_main - virtual int32_t AddLocalAbilityManager(const std::u16string& name, const sptr& ability) = 0; - // Remove an localAbilityManager just for sa_main - virtual int32_t RemoveLocalAbilityManager(const std::u16string& name) = 0; - // Return list of all existing abilities. virtual std::vector ListSystemAbilities(unsigned int dumpFlags = DUMP_FLAG_PRIORITY_ALL) = 0; - // Recycle ondemand ability. - virtual int32_t RecycleOnDemandSystemAbility() = 0; - // Register system ready callback. - virtual int32_t RegisterSystemReadyCallback(const sptr& systemReadyCallback) = 0; - // Get core system ability list. - virtual int32_t GetCoreSystemAbilityList(std::vector& coreSaList, int dumpMode) = 0; enum { SHEEFT_CRITICAL = 0, @@ -70,23 +56,12 @@ public: SUBSCRIBE_SYSTEM_ABILITY_TRANSACTION = 6, CHECK_REMOTE_SYSTEM_ABILITY_TRANSACTION = 9, ADD_ONDEMAND_SYSTEM_ABILITY_TRANSACTION = 10, - RECYCLE_ONDEMAND_SYSTEM_ABILITY_TRANSACTION = 11, CHECK_SYSTEM_ABILITY_IMMEDIATELY_TRANSACTION = 12, - CONNECTION_SYSTEM_ABILITY_TRANSACTION = 13, - DISCONNECTION_SYSTEM_ABILITY_TRANSACTION = 14, CHECK_ONDEMAND_SYSTEM_ABILITY_TRANSACTION = 15, CHECK_REMOTE_SYSTEM_ABILITY_FOR_JAVA_TRANSACTION = 16, GET_SYSTEM_ABILITYINFOLIST_TRANSACTION = 17, UNSUBSCRIBE_SYSTEM_ABILITY_TRANSACTION = 18, - GET_LOCAL_DEVICE_ID_TRANSACTION = 19, - ADD_LOCAL_ABILITY_TRANSACTION = 20, - CHECK_LOCAL_ABILITY_TRANSACTION = 22, - REMOVE_LOCAL_ABILITY_TRANSACTION = 23, - REGISTER_SYSTEM_READY_CALLBACK = 24, - GET_CORE_SYSTEM_ABILITY_LIST = 25, - ADD_SYSTEM_CAPABILITY = 26, - HAS_SYSTEM_CAPABILITY = 27, - GET_AVAILABLE_SYSTEM_CAPABILITY = 28 + ADD_SYSTEM_PROCESS_TRANSACTION = 20 }; // Retrieve an existing ability, blocking for a few seconds if it doesn't ye exist. @@ -98,12 +73,10 @@ public: // Remove an ability. virtual int32_t RemoveSystemAbility(int32_t systemAbilityId) = 0; - // Subscribe an ability's status by listener name, - // so the listener need to inherit from SystemAbilityListener class and implement the notify interfaces. - virtual int32_t SubscribeSystemAbility(int32_t systemAbilityId, const std::u16string& listenerName) = 0; - - // UnSubscribe an ability's status by listener name, - virtual int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, const std::u16string& listenerName) = 0; + virtual int32_t SubscribeSystemAbility(int32_t systemAbilityId, + const sptr& listener) = 0; + virtual int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, + const sptr& listener) = 0; // Retrieve an existing ability, blocking for a few seconds if it doesn't ye exist. virtual sptr GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; @@ -118,24 +91,6 @@ public: // Retrieve an ability, no-blocking. virtual sptr CheckSystemAbility(int32_t systemAbilityId, bool& isExist) = 0; - // connect system ability - virtual int32_t ConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) = 0; - - // disconnect system ability - virtual int32_t DisConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) = 0; - - // check ondemand system ability - virtual const std::u16string CheckOnDemandSystemAbility(int32_t systemAbilityId) = 0; - - // Retrieve an ability info list that satisfies capability - virtual bool GetSystemAbilityInfoList(int32_t systemAbilityId, - const std::u16string& capability, std::list>& saInfoList) = 0; - - // get local device id - virtual bool GetDeviceId(std::string& deviceId) = 0; - struct SAExtraProp { SAExtraProp() = default; SAExtraProp(bool isDistributed, unsigned int dumpFlags, const std::u16string& capability, @@ -154,9 +109,8 @@ public: }; virtual int32_t AddSystemAbility(int32_t systemAbilityId, const sptr& ability, const SAExtraProp& extraProp = SAExtraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u"")) = 0; - virtual int32_t AddSystemCapability(const std::string& sysCap) = 0; - virtual bool HasSystemCapability(const std::string& sysCap) = 0; - virtual std::vector GetSystemAvailableCapabilities() = 0; + + virtual int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) = 0; public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityManager"); protected: @@ -169,6 +123,7 @@ protected: } return false; } + static inline const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken"; }; } // namespace OHOS diff --git a/interfaces/innerkits/samgr_proxy/include/if_system_ability_connection_callback.h b/interfaces/innerkits/samgr_proxy/include/isystem_ability_status_change.h old mode 100644 new mode 100755 similarity index 48% rename from interfaces/innerkits/samgr_proxy/include/if_system_ability_connection_callback.h rename to interfaces/innerkits/samgr_proxy/include/isystem_ability_status_change.h index 7840ad84fa1aaddc9bb8519629a8c611082c6688..ace87cb10cd83c9982616239797056fa8616e658 --- a/interfaces/innerkits/samgr_proxy/include/if_system_ability_connection_callback.h +++ b/interfaces/innerkits/samgr_proxy/include/isystem_ability_status_change.h @@ -13,26 +13,24 @@ * limitations under the License. */ -#ifndef INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_CONNECTION_CALLBACK_H -#define INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_CONNECTION_CALLBACK_H +#ifndef SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_IF_SYSTEM_ABILITY_STATUS_CHANGE_H +#define SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_IF_SYSTEM_ABILITY_STATUS_CHANGE_H #include "iremote_broker.h" #include "iremote_object.h" +#include "iremote_proxy.h" namespace OHOS { -class ISystemAbilityConnectionCallback : public IRemoteBroker { -public: - virtual void OnConnectedSystemAbility(const sptr& connectionCallback) = 0; - virtual void OnDisConnectedSystemAbility(int32_t systemAbilityId) = 0; - +class ISystemAbilityStatusChange : public IRemoteBroker { public: + virtual ~ISystemAbilityStatusChange() = default; + virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; + virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityStatusChange"); enum { - ON_CONNECTED_SYSTEM_ABILITY = 1, - ON_DISCONNECTED_SYSTEM_ABILITY, + ON_ADD_SYSTEM_ABILITY = 1, + ON_REMOVE_SYSTEM_ABILITY = 2, }; -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityConnectionCallback"); }; -} // namespace OHOS - -#endif // !defined(INTERFACES_INNERKITS_SAFWK_INCLUDE_IF_SYSTEM_ABILITY_CONNECTION_CALLBACK_H ) +} +#endif /* SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_IF_SYSTEM_ABILITY_STATUS_CHANGE_H */ diff --git a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h old mode 100644 new mode 100755 index f28408a98c436576305db03de6a0a818088b9f70..adfa7cb889a5ba8d2df4faf74010ea44efa0230a --- a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h +++ b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h @@ -26,40 +26,24 @@ public: explicit SystemAbilityManagerProxy(const sptr& impl) : IRemoteProxy(impl) {} ~SystemAbilityManagerProxy() = default; - - sptr CheckLocalAbilityManager(const std::u16string& name) override; - int32_t AddLocalAbilityManager(const std::u16string& name, const sptr& ability) override; - int32_t RemoveLocalAbilityManager(const std::u16string& name) override; std::vector ListSystemAbilities(unsigned int dumpFlags) override; - int32_t RecycleOnDemandSystemAbility() override; // IntToString adapter interface sptr GetSystemAbility(int32_t systemAbilityId) override; sptr CheckSystemAbility(int32_t systemAbilityId) override; int32_t RemoveSystemAbility(int32_t systemAbilityId) override; - int32_t SubscribeSystemAbility(int32_t systemAbilityId, const std::u16string& listenerName) override; - int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, const std::u16string& listenerName) override; + int32_t SubscribeSystemAbility(int32_t systemAbilityId, const sptr& listener) override; + int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, + const sptr &listener) override; sptr GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; sptr CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId, const std::u16string& localAbilityManagerName) override; sptr CheckSystemAbility(int32_t systemAbilityId, bool& isExist) override; - int32_t ConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) override; - int32_t DisConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) override; - const std::u16string CheckOnDemandSystemAbility(int32_t systemAbilityId) override; - bool GetSystemAbilityInfoList(int32_t systemAbilityId, - const std::u16string& capability, std::list>& saInfoList) override; - bool GetDeviceId(std::string& deviceId) override; - int32_t AddSystemAbility(int32_t systemAbilityId, const sptr& ability, const SAExtraProp& extraProp) override; - int32_t RegisterSystemReadyCallback(const sptr& systemReadyCallback) override; - int32_t GetCoreSystemAbilityList(std::vector& coreSaList, int dumpMode) override; - int32_t AddSystemCapability(const std::string& sysCap) override; - bool HasSystemCapability(const std::string& sysCap) override; - std::vector GetSystemAvailableCapabilities() override; + + int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) override; private: sptr GetSystemAbilityWrapper(int32_t systemAbilityId, const std::string& deviceId = ""); sptr CheckSystemAbilityWrapper(int32_t code, MessageParcel& data); diff --git a/frameworks/native/source/system_ability_info.cpp b/interfaces/innerkits/samgr_proxy/include/system_ability_status_change_stub.h similarity index 34% rename from frameworks/native/source/system_ability_info.cpp rename to interfaces/innerkits/samgr_proxy/include/system_ability_status_change_stub.h index 05a420e5fdfaa3dbef2a3af520226721660fd324..e2205eef959cea1f9764fba27e8cd04ec7c9e6e3 100755 --- a/frameworks/native/source/system_ability_info.cpp +++ b/interfaces/innerkits/samgr_proxy/include/system_ability_status_change_stub.h @@ -1,57 +1,44 @@ -/* - * Copyright (c) 2021 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 "system_ability_info.h" - -#include "sam_log.h" - -namespace OHOS { -bool SystemAbilityInfo::ReadFromParcel(Parcel& parcel) -{ - if (!parcel.ReadInt32(systemAbilityId)) { - HILOGW("read systemAbilityId from parcel failed"); - return false; - } - if (!parcel.ReadString(deviceId)) { - HILOGW("read deviceId from parcel failed"); - return false; - } - return true; -} - -SystemAbilityInfo* SystemAbilityInfo::Unmarshalling(Parcel& parcel) -{ - SystemAbilityInfo* info = new SystemAbilityInfo(); - if (info != nullptr && !info->ReadFromParcel(parcel)) { - HILOGW("read from parcel failed"); - delete info; - info = nullptr; - } - return info; -} - -bool SystemAbilityInfo::Marshalling(Parcel& parcel) const -{ - if (!parcel.WriteInt32(systemAbilityId)) { - HILOGW("write systemAbilityId failed"); - return false; - } - if (!parcel.WriteString(deviceId)) { - HILOGW("write deviceId failed"); - return false; - } - return true; -} -} // namespace OHOS \ No newline at end of file +/* + * Copyright (c) 2021 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 SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_STATUS_CHANGE_STUB_H_ +#define SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_STATUS_CHANGE_STUB_H_ + +#include +#include "iremote_stub.h" +#include "isystem_ability_status_change.h" + +namespace OHOS { +class SystemAbilityStatusChangeStub : public IRemoteStub { +public: + SystemAbilityStatusChangeStub(); + ~SystemAbilityStatusChangeStub() = default; + int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; + +protected: + static bool CheckInputSysAbilityId(int32_t systemAbilityId); + +private: + int32_t OnAddSystemAbilityInner(MessageParcel& data, MessageParcel& reply); + int32_t OnRemoveSystemAbilityInner(MessageParcel& data, MessageParcel& reply); + static bool CanRequest(); + static bool EnforceInterceToken(MessageParcel& data); + + using SystemAbilityStatusChangeStubFunc = + int32_t (SystemAbilityStatusChangeStub::*)(MessageParcel& data, MessageParcel& reply); + std::map memberFuncMap_; +}; +} +#endif /* SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_STATUS_CHANGE_STUB_H_ */ diff --git a/ohos.build b/ohos.build index c5227b736840e95ccf4fd0c2fb36875227c00c7c..d24de4ff7b3253df798dd7f64a46551c2b0a9271 100755 --- a/ohos.build +++ b/ohos.build @@ -7,12 +7,12 @@ "header": { "header_base": "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include/", "header_files": [ - "iservice_registry.h", "if_system_ability_manager.h", + "iservice_registry.h", + "isystem_ability_status_change.h", "system_ability_manager_proxy.h", - "sam_log.h", - "system_ability_info.h", - "if_system_ability_connection_callback.h" + "system_ability_status_change_stub.h", + "sam_log.h" ] }, "name": "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy" diff --git a/services/lsamgr/include/if_local_ability_manager.h b/services/lsamgr/include/if_local_ability_manager.h index a18fe6cd91e4b9c87a8d15aeb3f219e9b153e4ec..110b7be746a9f8bdf2c2fcedb60634087fefb653 100755 --- a/services/lsamgr/include/if_local_ability_manager.h +++ b/services/lsamgr/include/if_local_ability_manager.h @@ -25,34 +25,14 @@ namespace OHOS { class ILocalAbilityManager : public IRemoteBroker { public: - virtual bool Debug(int32_t saId) = 0; - virtual bool Test(int32_t saId) = 0; - virtual bool SADump(int32_t saId) = 0; - virtual bool HandoffAbilityAfter(const std::u16string& begin, const std::u16string& after) = 0; - virtual bool HandoffAbilityBegin(int32_t saId) = 0; virtual bool StartAbility(int32_t saId) = 0; - virtual bool StopAbility(int32_t saId) = 0; - virtual bool OnAddSystemAbility(int32_t saId, const std::string& deviceId = "") = 0; - virtual bool OnRemoveSystemAbility(int32_t saId, const std::string& deviceId = "") = 0; - virtual void StartAbilityAsyn(int32_t saId) = 0; - virtual bool RecycleOndemandSystemAbility(int32_t saId) = 0; -public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ILocalAbilityManager"); +protected: enum { - DEBUG_TRANSACTION = 1, - TEST_TRANSACTION = 2, - DUMP_TRANSACTION = 3, - HAND_OFF_ABILITY_AFTER_TRANSACTION = 4, - HAND_OFF_ABILITY_BEGIN_TRANSACTION = 5, - START_ABILITY_TRANSACTION = 6, - STOP_ABILITY_TRANSACTION = 7, - ON_ADD_SYSTEM_ABILITY_TRANSACTION = 8, - ON_REMOVE_SYSTEM_ABILITY_TRANSACTION = 9, - START_ABILITY_ASYN_TRANSACTION = 10, - RECYCLE_SYSTEM_ABILITY_TRANSACTION = 11, + START_ABILITY_TRANSACTION = 1, }; -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ILocalAbilityManager"); + static inline const std::u16string LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN = u"ohos.localabilitymanager.accessToken"; }; } #endif // !defined(IF_LOCAL_ABILITY_MANAGER_H_) diff --git a/services/lsamgr/include/local_ability_manager_proxy.h b/services/lsamgr/include/local_ability_manager_proxy.h index 473afc7b3ebc9bf757c2fb6dcd7438b3c427ef6b..647b7f106317986b7fec73ce0b45a7efbf12baa8 100755 --- a/services/lsamgr/include/local_ability_manager_proxy.h +++ b/services/lsamgr/include/local_ability_manager_proxy.h @@ -27,21 +27,7 @@ public: : IRemoteProxy(impl) {} ~LocalAbilityManagerProxy() = default; - bool Debug(int32_t saId); - bool Test(int32_t saId); - bool SADump(int32_t saId); - bool HandoffAbilityAfter(const std::u16string& begin, const std::u16string& after); - bool HandoffAbilityBegin(int32_t saId); bool StartAbility(int32_t saId); - bool StopAbility(int32_t saId); - bool OnAddSystemAbility(int32_t saId, const std::string& deviceId = ""); - bool OnRemoveSystemAbility(int32_t saId, const std::string& deviceId = ""); - void StartAbilityAsyn(int32_t saId); - bool RecycleOndemandSystemAbility(int32_t saId); -private: - bool TransactInner(uint32_t code, uint32_t flags, int32_t saId); - bool TransactInner(uint32_t code, int32_t saId, const std::string& deviceId); - private: static inline BrokerDelegator delegator_; OHOS::HiviewDFX::HiLogLabel label_ = { LOG_CORE, 0xD001800, "SA" }; diff --git a/services/lsamgr/src/local_ability_manager_proxy.cpp b/services/lsamgr/src/local_ability_manager_proxy.cpp old mode 100644 new mode 100755 index a2b1639286c8f4394c438743a85b0cbc9ee182c9..e5be03b7c5c8f7807ea722a924047f2077efb469 --- a/services/lsamgr/src/local_ability_manager_proxy.cpp +++ b/services/lsamgr/src/local_ability_manager_proxy.cpp @@ -14,7 +14,6 @@ */ #include "local_ability_manager_proxy.h" -#include #include "ipc_types.h" #include "parcel.h" @@ -22,223 +21,37 @@ using namespace std; using namespace OHOS::HiviewDFX; namespace OHOS { -namespace { -const std::u16string LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN = u"ohos.localabilitymanager.accessToken"; -} -bool LocalAbilityManagerProxy::SADump(int32_t systemAbilityId) -{ - bool ret = TransactInner(DUMP_TRANSACTION, 0, systemAbilityId); - if (!ret) { - HiLog::Error(label_, "SADump transact failed!"); - } - return ret; -} - -bool LocalAbilityManagerProxy::Debug(int32_t systemAbilityId) -{ - bool ret = TransactInner(DEBUG_TRANSACTION, 0, systemAbilityId); - if (!ret) { - HiLog::Error(label_, "Debug transact failed!"); - } - return ret; -} - -bool LocalAbilityManagerProxy::Test(int32_t systemAbilityId) -{ - bool ret = TransactInner(TEST_TRANSACTION, 0, systemAbilityId); - if (!ret) { - HiLog::Error(label_, "Test transact failed!"); - } - return ret; -} - -bool LocalAbilityManagerProxy::HandoffAbilityAfter(const std::u16string& begin, const std::u16string& after) -{ - sptr iro = Remote(); - if (iro == nullptr) { - HiLog::Error(label_, "HandoffAbilityAfter Remote return null"); - return false; - } - MessageParcel data; - if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) { - HiLog::Warn(label_, "HandoffAbilityAfter interface token check failed"); - return false; - } - bool ret = data.WriteString16(begin); - if (!ret) { - HiLog::Warn(label_, "HandoffAbilityAfter write begin failed!"); - return false; - } - ret = data.WriteString16(after); - if (!ret) { - HiLog::Warn(label_, "HandoffAbilityAfter write after failed!"); - return false; - } - - MessageParcel reply; - MessageOption option; - int32_t status = iro->SendRequest(HAND_OFF_ABILITY_AFTER_TRANSACTION, data, reply, option); - if (status != NO_ERROR) { - HiLog::Error(label_, "HandoffAbilityAfter Transact failed, return value : %{public}d", status); - return false; - } - bool result = true; - ret = reply.ReadBool(result); - if (!ret) { - HiLog::Warn(label_, "read reply failed!"); - return false; - } - return result; -} - -bool LocalAbilityManagerProxy::HandoffAbilityBegin(int32_t systemAbilityId) -{ - bool ret = TransactInner(HAND_OFF_ABILITY_BEGIN_TRANSACTION, 0, systemAbilityId); - if (!ret) { - HiLog::Error(label_, "HandoffAbilityBegin transact failed!"); - } - return ret; -} - bool LocalAbilityManagerProxy::StartAbility(int32_t systemAbilityId) -{ - bool ret = TransactInner(START_ABILITY_TRANSACTION, 0, systemAbilityId); - if (!ret) { - HiLog::Error(label_, "StartAbility transact failed!"); - } - return ret; -} - -bool LocalAbilityManagerProxy::StopAbility(int32_t systemAbilityId) -{ - bool ret = TransactInner(STOP_ABILITY_TRANSACTION, 0, systemAbilityId); - if (!ret) { - HiLog::Error(label_, "StopAbility transact failed!"); - } - return ret; -} - -bool LocalAbilityManagerProxy::OnAddSystemAbility(int32_t saId, const std::string& deviceId) -{ - bool ret = TransactInner(ON_ADD_SYSTEM_ABILITY_TRANSACTION, saId, deviceId); - if (!ret) { - HiLog::Error(label_, "OnAddSystemAbility transact failed!"); - } - return ret; -} - -bool LocalAbilityManagerProxy::OnRemoveSystemAbility(int32_t saId, const std::string& deviceId) -{ - bool ret = TransactInner(ON_REMOVE_SYSTEM_ABILITY_TRANSACTION, saId, deviceId); - if (!ret) { - HiLog::Error(label_, "OnRemoveSystemAbility transact failed!"); - } - return ret; -} - -void LocalAbilityManagerProxy::StartAbilityAsyn(int32_t systemAbilityId) -{ - bool ret = TransactInner(START_ABILITY_ASYN_TRANSACTION, TRANS_ASYNC, systemAbilityId); - if (!ret) { - HiLog::Error(label_, "StartAbilityAsyn transact failed!"); - } - return; -} - -bool LocalAbilityManagerProxy::RecycleOndemandSystemAbility(int32_t systemAbilityId) -{ - bool ret = TransactInner(RECYCLE_SYSTEM_ABILITY_TRANSACTION, 0, systemAbilityId); - if (!ret) { - HiLog::Error(label_, "RecycleOndemandSystemAbility transact failed!"); - } - return ret; -} - -bool LocalAbilityManagerProxy::TransactInner(uint32_t code, uint32_t flags, int32_t systemAbilityId) { if (systemAbilityId <= 0) { - HiLog::Warn(label_, "TransactInner systemAbilityId invalid."); + HiLog::Warn(label_, "StartAbility systemAbilityId invalid."); return false; } sptr iro = Remote(); if (iro == nullptr) { - HiLog::Error(label_, "TransactInner Remote return null"); + HiLog::Error(label_, "StartAbility Remote return null"); return false; } MessageParcel data; if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) { - HiLog::Warn(label_, "TransactInner interface token check failed"); + HiLog::Warn(label_, "StartAbility interface token check failed"); return false; } bool ret = data.WriteInt32(systemAbilityId); if (!ret) { - HiLog::Warn(label_, "TransactInner write systemAbilityId failed!"); - return false; - } - - MessageParcel reply; - MessageOption option; - if (flags == TRANS_ASYNC) { - option.SetFlags(MessageOption::TF_ASYNC); - } - int32_t status = iro->SendRequest(code, data, reply, option); - if (status != NO_ERROR) { - HiLog::Error(label_, "TransactInner Transact failed, return value : %{public}d", status); - return false; - } - bool result = true; - ret = reply.ReadBool(result); - if (!ret) { - HiLog::Warn(label_, "read reply failed!"); - return false; - } - return (flags == TRANS_ASYNC) ? true : result; -} - -bool LocalAbilityManagerProxy::TransactInner(uint32_t code, int32_t saId, const std::string& deviceId) -{ - if (saId <= 0) { - HiLog::Info(label_, "TransactInner saId:%{public}d is invalid!", saId); - return false; - } - - sptr iro = Remote(); - if (iro == nullptr) { - HiLog::Error(label_, "TransactInner Remote return null"); - return false; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) { - HiLog::Warn(label_, "TransactInner interface token check failed"); - return false; - } - bool ret = data.WriteInt32(saId); - if (!ret) { - HiLog::Warn(label_, "TransactInner write saId failed!"); - return false; - } - ret = data.WriteString(deviceId); - if (!ret) { - HiLog::Warn(label_, "TransactInner write deviceId failed!"); + HiLog::Warn(label_, "StartAbility write systemAbilityId failed!"); return false; } MessageParcel reply; - MessageOption option; - int32_t status = iro->SendRequest(code, data, reply, option); + MessageOption option(MessageOption::TF_ASYNC); + int32_t status = iro->SendRequest(START_ABILITY_TRANSACTION, data, reply, option); if (status != NO_ERROR) { - HiLog::Error(label_, "TransactInner Transact failed, return value : %{public}d", status); - return false; - } - bool result = true; - ret = reply.ReadBool(result); - if (!ret) { - HiLog::Warn(label_, "read reply failed!"); + HiLog::Error(label_, "StartAbility SendRequest failed, return value : %{public}d", status); return false; } - return result; + return true; } } diff --git a/services/samgr/native/BUILD.gn b/services/samgr/native/BUILD.gn index e3c8d1bb4e24db203601dd93e0096488d0d25064..cbd33c0d3b541f4ef07375b8d051a2d9523d0862 100755 --- a/services/samgr/native/BUILD.gn +++ b/services/samgr/native/BUILD.gn @@ -55,14 +55,15 @@ ohos_executable("samgr") { install_enable = true sources = [ "//foundation/distributedschedule/samgr/services/samgr/native/source/ability_death_recipient.cpp", - "//foundation/distributedschedule/samgr/services/samgr/native/source/sa_main.cpp", + "//foundation/distributedschedule/samgr/services/samgr/native/source/main.cpp", "//foundation/distributedschedule/samgr/services/samgr/native/source/system_ability_manager.cpp", "//foundation/distributedschedule/samgr/services/samgr/native/source/system_ability_manager_stub.cpp", - "//foundation/distributedschedule/samgr/services/samgr/native/source/utils.cpp", + "//foundation/distributedschedule/samgr/services/samgr/native/source/system_ability_status_change_proxy.cpp", "//foundation/distributedschedule/samgr/utils/native/source/tools.cpp", ] deps = [ + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/lsamgr:lsamgr", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//utils/native/base:utils", @@ -76,6 +77,7 @@ ohos_executable("samgr") { if (is_standard_system) { external_deps = [ + "appexecfwk_standard:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "ipc:libdbinder", diff --git a/services/samgr/native/include/ability_death_recipient.h b/services/samgr/native/include/ability_death_recipient.h old mode 100644 new mode 100755 index fbd99a9ff0f43176ebdc335d9d58c081116aa252..f11ea992fd5c75793b6a77ea8cdb8a8fb39551eb --- a/services/samgr/native/include/ability_death_recipient.h +++ b/services/samgr/native/include/ability_death_recipient.h @@ -26,18 +26,18 @@ public: ~AbilityDeathRecipient() override = default; }; -class LocalAbilityManagerDeathRecipient : public IRemoteObject::DeathRecipient { +class SystemProcessDeathRecipient : public IRemoteObject::DeathRecipient { public: void OnRemoteDied(const wptr& remote) override; - LocalAbilityManagerDeathRecipient() = default; - ~LocalAbilityManagerDeathRecipient() override = default; + SystemProcessDeathRecipient() = default; + ~SystemProcessDeathRecipient() override = default; }; -class SystemReadyCallbackDeathRecipient : public IRemoteObject::DeathRecipient { +class AbilityStatusDeathRecipient : public IRemoteObject::DeathRecipient { public: void OnRemoteDied(const wptr& remote) override; - SystemReadyCallbackDeathRecipient() = default; - ~SystemReadyCallbackDeathRecipient() override = default; + AbilityStatusDeathRecipient() = default; + ~AbilityStatusDeathRecipient() override = default; }; } // namespace OHOS diff --git a/services/samgr/native/include/system_ability_data_info.h b/services/samgr/native/include/system_ability_data_info.h deleted file mode 100644 index e922fb6b95ecf3ddbf0eaa38958de4d192920cfe..0000000000000000000000000000000000000000 --- a/services/samgr/native/include/system_ability_data_info.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2021 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 -#include "app_types.h" -#include "utils.h" -#include "string_ex.h" - -#ifndef OHOS_SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_DATA_INFO_H_ -#define OHOS_SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_DATA_INFO_H_ - -namespace OHOS { -namespace { -const std::string SEPARATOR = "_"; -const std::string EMPTY_STRING = "nullstr"; - -constexpr size_t REMOTE_OBJ_INDEX = 0; -constexpr size_t CAPABILITY_INDEX = 1; -constexpr size_t DEF_PERM_INDEX = 2; -constexpr size_t SPLIT_LENGTH = 3; -} -struct SADataValue { - SADataValue() = default; - void ConvertToValue(AppDistributedKv::Value& value) - { - value = std::to_string(iRemoteObjAddr) - .append(SEPARATOR).append(capability.empty() ? EMPTY_STRING : capability) - .append(SEPARATOR).append(permission.empty() ? EMPTY_STRING : permission); - } - - bool UnConvert(const AppDistributedKv::Value& value) - { - if (value.Empty()) { - return false; - } - std::string addValue = value.ToString(); - if (addValue.empty()) { - return false; - } - std::vector strVector; - SplitStr(addValue, SEPARATOR, strVector); - if (strVector.size() < SPLIT_LENGTH) { - return false; - } - iRemoteObjAddr = Utils::StrToUint64(strVector[REMOTE_OBJ_INDEX]); - if (iRemoteObjAddr == Utils::MAX_U64_VAL) { - return false; - } - if (strVector[CAPABILITY_INDEX] != EMPTY_STRING) { - capability = strVector[CAPABILITY_INDEX]; - } - if (strVector[DEF_PERM_INDEX] != EMPTY_STRING) { - permission = strVector[DEF_PERM_INDEX]; - } - return true; - } - - SADataValue(uint64_t remoteObjAddr, const std::string& capability, const std::string& permission) - { - iRemoteObjAddr = remoteObjAddr; - this->capability = capability; - this->permission = permission; - } - - uint64_t iRemoteObjAddr = Utils::MAX_U64_VAL; - std::string capability; - std::string permission; -}; -} // namespace OHOS - -#endif // OHOS_SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_DATA_INFO_H_ diff --git a/services/samgr/native/include/system_ability_manager.h b/services/samgr/native/include/system_ability_manager.h index 5558354314d3bd6e6ca66f515c44b54341c42193..203a0c7c528d4d932b5f123bb1ab9c9315223f56 100755 --- a/services/samgr/native/include/system_ability_manager.h +++ b/services/samgr/native/include/system_ability_manager.h @@ -13,7 +13,6 @@ * limitations under the License. */ - #ifndef SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_H_ #define SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_H_ @@ -25,10 +24,11 @@ #include #include -#include "system_ability_definition.h" +#include "event_handler.h" #include "dbinder_service.h" #include "dbinder_service_stub.h" -#include "system_ability_info.h" +#include "sa_profiles.h" +#include "system_ability_definition.h" namespace OHOS { struct SAInfo { @@ -49,42 +49,25 @@ public: virtual ~SystemAbilityManager(); static sptr GetInstance(); - sptr CheckLocalAbilityManager(const std::u16string& localAbilityManagerName) override; - int32_t AddLocalAbilityManager(const std::u16string& localAbilityManagerName, - const sptr& localAbilityManager) override; - int32_t RemoveLocalAbilityManager(const std::u16string& localAbilityManagerName) override; - int32_t RemoveSystemAbility(const sptr& ability); - int32_t RemoveLocalAbilityManager(const sptr& localAbilityManager); - std::vector ListSystemAbilities(uint32_t dumpFlags) override; - int32_t RecycleOnDemandSystemAbility() override; - - int32_t RegisterSystemReadyCallback(const sptr& systemReadyCallback) override; - - int32_t GetCoreSystemAbilityList(std::vector& coreSaList, int dumpMode) override; - - int32_t RemoveSystemReadyCallback(const sptr& callback); - void SetDeviceName(const std::u16string &name); const std::u16string& GetDeviceName() const; - bool GetDeviceId(std::string& deviceId) override; - const sptr GetDBinder() const; - void DoSADataStorageInit(); - sptr GetSystemAbility(int32_t systemAbilityId) override; sptr CheckSystemAbility(int32_t systemAbilityId) override; int32_t RemoveSystemAbility(int32_t systemAbilityId) override; - int32_t SubscribeSystemAbility(int32_t systemAbilityId, const std::u16string& listenerName) override; - int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, const std::u16string& listenerName) override; + int32_t SubscribeSystemAbility(int32_t systemAbilityId, const sptr& listener) override; + int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, + const sptr& listener) override; + void UnSubscribeSystemAbility(const sptr& remoteObject); sptr GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; @@ -95,27 +78,16 @@ public: sptr CheckSystemAbility(int32_t systemAbilityId, bool& isExist) override; - int32_t ConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) override; - - int32_t DisConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) override; - - const std::u16string CheckOnDemandSystemAbility(int32_t systemAbilityId) override; - - bool GetSystemAbilityInfoList(int32_t systemAbilityId, - const std::u16string& capability, std::list>& saInfoList) override; void NotifyRemoteSaDied(const std::u16string& name); void NotifyRemoteDeviceOffline(const std::string& deviceId); int32_t AddSystemAbility(int32_t systemAbilityId, const sptr& ability, const SAExtraProp& extraProp) override; std::string TransformDeviceId(const std::string& deviceId, int32_t type, bool isPrivate); std::string GetLocalNodeId(); - int32_t AddSystemCapability(const std::string& sysCap) override; - bool HasSystemCapability(const std::string& sysCap) override; - std::vector GetSystemAvailableCapabilities() override; - void Init(); + + int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) override; + int32_t RemoveSystemProcess(const sptr& procObject); private: SystemAbilityManager(); std::u16string GetSystemAbilityName(int32_t index) override; @@ -123,32 +95,29 @@ private: bool IsNameInValid(const std::u16string& name); int32_t StartOnDemandAbility(int32_t systemAbilityId); void DeleteStartingAbilityMember(int32_t systemAbilityId); - bool CheckCapability(const std::u16string& capability); void ParseRemoteSaName(const std::u16string& name, std::string& deviceId, std::u16string& saName); - void OnDemandConnected(int32_t systemAbilityId, const sptr& ability); bool IsLocalDeviceId(const std::string& deviceId); - bool CheckRemoteSa(const std::string& saName, std::string& selectedDeviceId); bool CheckDistributedPermission(); int32_t AddSystemAbility(const std::u16string& name, const sptr& ability, const SAExtraProp& extraProp); - int32_t FindSystemAbilityManagerNotify(int32_t systemAbilityId, int32_t code); - int32_t FindSystemAbilityManagerNotify(int32_t systemAbilityId, const std::string& deviceId, int32_t code); - bool CheckPermission(const std::string& permission); - - void InitCoreSaList(); - void RestoreCoreSaId(int32_t saId); - void RemoveCompletedCoreSaId(int32_t saId); - void SendSystemReadyMessage(); - void SendSingleSystemReadyMessage(const sptr& systemReadyCallback); - void InitSysCapMap(); - void AddDefaultCoreSa(std::set& coreSaIdSet) const; + int32_t FindSystemAbilityNotify(int32_t systemAbilityId, int32_t code); + int32_t FindSystemAbilityNotify(int32_t systemAbilityId, const std::string& deviceId, int32_t code); + + sptr GetSystemProcess(const std::u16string& procName); + sptr CheckLocalAbilityManager(const std::u16string& name); + void InitSaProfile(); + bool GetSaProfile(int32_t saId, SaProfile& saProfile); + void NotifySystemAbilityChanged(int32_t systemAbilityId, const std::string& deviceId, int32_t code, + const sptr& listener); + void UnSubscribeSystemAbilityLocked(std::list, int32_t>>& listenerList, + const sptr& listener); std::u16string deviceName_; static sptr instance; static std::mutex instanceLock; sptr abilityDeath_; - sptr localAbilityManagerDeath_; - sptr systemReadyCallbackDeath_; + sptr systemProcessDeath_; + sptr abilityStatusDeath_; sptr dBinderService_; bool isDbinderStart_ = false; @@ -156,29 +125,24 @@ private: std::shared_mutex abilityMapLock_; std::map abilityMap_; - // must hold localAbilityManagerMapLock_ never access other locks - std::recursive_mutex localAbilityManagerMapLock_; - std::map> localAbilityManagerMap_; + // must hold systemProcessMapLock_ never access other locks + std::recursive_mutex systemProcessMapLock_; + std::map> systemProcessMap_; - // maybe hold listenerMapLock_ and then access localAbilityMapLock_ + // maybe hold listenerMapLock_ and then access systemProcessMapLock_ std::recursive_mutex listenerMapLock_; - std::map> listenerMap_; + std::map, int32_t>>> listenerMap_; + std::map subscribeCountMap_; - // maybe hold onDemandAbilityMapLock_ and then access localAbilityMapLock_ + // maybe hold onDemandAbilityMapLock_ and then access systemProcessMapLock_ std::recursive_mutex onDemandAbilityMapLock_; std::map onDemandAbilityMap_; std::list startingAbilityList_; - std::map> connectionCallbackMap_; - std::set coreSaIdSet_; - std::set coreSaIdSetBackup_; - std::map, int32_t> systemCallbackMap_; - std::map callingPidCountMap_; // key:callintPid value:callingCount - std::condition_variable parseCoreSaCV_; - std::mutex parseCoreSaMtx_; - bool parseCoreSaReady_ = false; - bool isCoreSaInitReady_ = false; - std::mutex sysCapMapLock_; - std::map sysCapMap_; + + std::shared_ptr parseHandler_; + + std::map saProfileMap_; + std::mutex saProfileMapLock_; }; } // namespace OHOS diff --git a/services/samgr/native/include/system_ability_manager_stub.h b/services/samgr/native/include/system_ability_manager_stub.h old mode 100644 new mode 100755 index 67a14d6e848cebc5230b9a2fec46e021b94c5de1..079bd27ec73e2696d14bfa76e1fa60ab18d10c11 --- a/services/samgr/native/include/system_ability_manager_stub.h +++ b/services/samgr/native/include/system_ability_manager_stub.h @@ -35,33 +35,18 @@ protected: static bool IsSystemApp(int32_t callingUid); private: - int32_t GetLocalAbilityInner(MessageParcel& data, MessageParcel& reply); - int32_t CheckLocalAbilityInner(MessageParcel& data, MessageParcel& reply); - int32_t AddLocalAbilityInner(MessageParcel& data, MessageParcel& reply); - int32_t RemoveLocalAbilityInner(MessageParcel& data, MessageParcel& reply); int32_t ListSystemAbilityInner(MessageParcel& data, MessageParcel& reply); int32_t SubsSystemAbilityInner(MessageParcel& data, MessageParcel& reply); int32_t UnSubsSystemAbilityInner(MessageParcel& data, MessageParcel& reply); - int32_t GetLocalManagerInner(MessageParcel& data, MessageParcel& reply); int32_t CheckRemtSystemAbilityInner(MessageParcel& data, MessageParcel& reply); int32_t AddOndemandSystemAbilityInner(MessageParcel& data, MessageParcel& reply); - int32_t RecycleOndemandSystemAbilityInner(MessageParcel& data, MessageParcel& reply); int32_t CheckSystemAbilityImmeInner(MessageParcel& data, MessageParcel& reply); - int32_t ConnOndemandSystemAbilityInner(MessageParcel& data, MessageParcel& reply); - int32_t DisConnOndemandSystemAbilityInner(MessageParcel& data, MessageParcel& reply); - int32_t CheckOndemandSystemAbilityInner(MessageParcel& data, MessageParcel& reply); int32_t CheckRemtSystemAbilityForJavaInner(MessageParcel& data, MessageParcel& reply); - int32_t GetSystemAbilityInfoListInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceIdInner(MessageParcel& data, MessageParcel& reply); int32_t AddSystemAbilityInner(MessageParcel& data, MessageParcel& reply); int32_t GetSystemAbilityInner(MessageParcel& data, MessageParcel& reply); int32_t CheckSystemAbilityInner(MessageParcel& data, MessageParcel& reply); + int32_t AddSystemProcessInner(MessageParcel& data, MessageParcel& reply); int32_t RemoveSystemAbilityInner(MessageParcel& data, MessageParcel& reply); - int32_t RegisterSystemReadyCallbackInner(MessageParcel& data, MessageParcel& reply); - int32_t GetCoreSystemAbilityListInner(MessageParcel& data, MessageParcel& reply); - int32_t AddSystemCapabilityInner(MessageParcel& data, MessageParcel& reply); - int32_t HasSystemCapabilityInner(MessageParcel& data, MessageParcel& reply); - int32_t GetSystemAvailableCapabilitiesInner(MessageParcel& data, MessageParcel& reply); int32_t UnmarshalingSaExtraProp(MessageParcel& data, SAExtraProp& extraProp); static int32_t GetHapIdMultiuser(int32_t uid); diff --git a/services/samgr/native/include/utils.h b/services/samgr/native/include/system_ability_status_change_proxy.h old mode 100644 new mode 100755 similarity index 41% rename from services/samgr/native/include/utils.h rename to services/samgr/native/include/system_ability_status_change_proxy.h index 7788557b043fbc7bae487cc783c775b9e7efd57e..c81d4323233a60459a30a06564c834a82030eafe --- a/services/samgr/native/include/utils.h +++ b/services/samgr/native/include/system_ability_status_change_proxy.h @@ -13,30 +13,24 @@ * limitations under the License. */ -#ifndef SERVICES_SAMGR_NATIVE_INCLUDE_UTILS_H_ -#define SERVICES_SAMGR_NATIVE_INCLUDE_UTILS_H_ +#ifndef SAMGR_SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_STATUS_CHANGE_PROXY_H_ +#define SAMGR_SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_STATUS_CHANGE_PROXY_H_ -#include -#include -#include #include -#include "nocopyable.h" - -#include "libxml/xpath.h" +#include "isystem_ability_status_change.h" namespace OHOS { -class Utils { +class SystemAbilityStatusChangeProxy : public IRemoteProxy { public: - static const uint64_t MAX_U64_VAL = (std::numeric_limits::max)(); - static uint64_t StrToUint64(const std::string& param); - static bool ParseCoreSaList(const std::string& saPath, std::set& saList); - static bool ParseSysCapMap(const std::string& sysCapPath, std::map& sysCapMap); + explicit SystemAbilityStatusChangeProxy(const sptr& impl) + : IRemoteProxy(impl) {} + ~SystemAbilityStatusChangeProxy() = default; + + void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId = "") override; + void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId = "") override; private: - Utils() = delete; - ~Utils() = delete; - DISALLOW_COPY_AND_MOVE(Utils); - static bool ParseSystemAbility(const xmlNode& rootNode, std::set& saList); + bool SendRequestInner(uint32_t code, int32_t systemAbilityId, const std::string& deviceId); + static inline BrokerDelegator delegator_; }; -} // namespace OHOS - -#endif // SERVICES_SAMGR_NATIVE_INCLUDE_UTILS_H_ +} +#endif /* SAMGR_SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_STATUS_CHANGE_PROXY_H_ */ diff --git a/services/samgr/native/source/ability_death_recipient.cpp b/services/samgr/native/source/ability_death_recipient.cpp old mode 100644 new mode 100755 index 63ba6e76e7d2827017d8a816dd2910d8c44b8a72..a355b803b544f5c76d9f2676e0735ee47bbe0d6a --- a/services/samgr/native/source/ability_death_recipient.cpp +++ b/services/samgr/native/source/ability_death_recipient.cpp @@ -22,21 +22,22 @@ namespace OHOS { void AbilityDeathRecipient::OnRemoteDied(const wptr& remote) { - HILOGI("%s called", __func__); + HILOGI("%{public}s called", __func__); SystemAbilityManager::GetInstance()->RemoveSystemAbility(remote.promote()); - HILOGI("recv death notice success"); + HILOGI("%{public}s death notice success", __func__); } -void LocalAbilityManagerDeathRecipient::OnRemoteDied(const wptr& remote) +void SystemProcessDeathRecipient::OnRemoteDied(const wptr& remote) { - HILOGI("LocalAbilityManagerDeathRecipient::OnRemoteDied called!"); - SystemAbilityManager::GetInstance()->RemoveLocalAbilityManager(remote.promote()); - HILOGI("LocalAbilityManagerDeathRecipient::OnRemoteDied death notice success"); + HILOGI("%{public}s called!", __func__); + SystemAbilityManager::GetInstance()->RemoveSystemProcess(remote.promote()); + HILOGI("%{public}s death notice success", __func__); } -void SystemReadyCallbackDeathRecipient::OnRemoteDied(const wptr& remote) + +void AbilityStatusDeathRecipient::OnRemoteDied(const wptr& remote) { - HILOGI("SystemReadyCallbackDeathRecipient::coreSa::OnRemoteDied called!"); - SystemAbilityManager::GetInstance()->RemoveSystemReadyCallback(remote.promote()); - HILOGI("SystemReadyCallbackDeathRecipient::coreSa::OnRemoteDied death notice success"); + HILOGI("%{public}s called!", __func__); + SystemAbilityManager::GetInstance()->UnSubscribeSystemAbility(remote.promote()); + HILOGI("%{public}s death notice success", __func__); } } // namespace OHOS diff --git a/services/samgr/native/source/sa_main.cpp b/services/samgr/native/source/main.cpp similarity index 100% rename from services/samgr/native/source/sa_main.cpp rename to services/samgr/native/source/main.cpp diff --git a/services/samgr/native/source/system_ability_manager.cpp b/services/samgr/native/source/system_ability_manager.cpp index 82b08fa6f8152c0c906f158e7fa413718e9a9305..e4e7beeb8aed4b3e32df66ae59a1934b470cbc38 100755 --- a/services/samgr/native/source/system_ability_manager.cpp +++ b/services/samgr/native/source/system_ability_manager.cpp @@ -20,10 +20,11 @@ #include "ability_death_recipient.h" #include "datetime_ex.h" +#include "directory_ex.h" #include "errors.h" #include "if_local_ability_manager.h" #include "local_ability_manager_proxy.h" -#include "nlohmann/json.hpp" +#include "parse_util.h" #include "sam_log.h" #include "string_ex.h" @@ -31,28 +32,18 @@ #include "system_ability_definition.h" #include "tools.h" -#include "utils.h" using namespace std; namespace OHOS { namespace { -const string STR_LOCAL_ABILITY_MGR = "localabilitymanager"; -const string CORE_SYSTEM_ABILITY_PATH = "/system/profile/core_system_ability.xml"; -const string SYSTEM_CAPABILITY_PATH = "/system/profile/system_capability.json"; -const string SYSTEM_PARAM_SAMGR_CORESA_INITREADY = "sys.samgr.coresa.initready"; -const std::u16string SYSTEM_READY_CALLBACK_INTERFACE_TOKEN = u"ohos.systemReadyCallback.accessToken"; +const string PREFIX = "/system/profile/"; constexpr int32_t MAX_NAME_SIZE = 200; constexpr int32_t SPLIT_NAME_VECTOR_SIZE = 2; -constexpr int32_t MAX_CAPABILITY_SIZE = 8192; constexpr int32_t UID_ROOT = 0; constexpr int32_t UID_SYSTEM = 1000; - -constexpr int32_t DUMP_ALL_CORE_SYSTEM_ABILITY = 0; -constexpr int32_t DUMP_REGISTERED_CORE_SYSTEM_ABILITY = 1; -constexpr int32_t DUMP_UNREGISTERED_CORE_SYSTEM_ABILITY = 2; -constexpr int32_t MAX_SYSCAP_NAME_LEN = 64; +constexpr int32_t MAX_SUBSCRIBE_COUNT = 256; } std::mutex SystemAbilityManager::instanceLock; @@ -70,10 +61,13 @@ SystemAbilityManager::~SystemAbilityManager() void SystemAbilityManager::Init() { abilityDeath_ = sptr(new AbilityDeathRecipient()); - localAbilityManagerDeath_ = sptr(new LocalAbilityManagerDeathRecipient()); - systemReadyCallbackDeath_ = sptr(new SystemReadyCallbackDeathRecipient()); - InitCoreSaList(); - InitSysCapMap(); + systemProcessDeath_ = sptr(new SystemProcessDeathRecipient()); + abilityStatusDeath_ = sptr(new AbilityStatusDeathRecipient()); + if (parseHandler_ == nullptr) { + auto parseRunner = AppExecFwk::EventRunner::Create("ParseHandler"); + parseHandler_ = make_shared(parseRunner); + } + InitSaProfile(); } const sptr SystemAbilityManager::GetDBinder() const @@ -90,28 +84,48 @@ sptr SystemAbilityManager::GetInstance() return instance; } -void SystemAbilityManager::DoSADataStorageInit() -{ -} - -void SystemAbilityManager::InitCoreSaList() -{ -} - -void SystemAbilityManager::RestoreCoreSaId(int32_t saId) +void SystemAbilityManager::InitSaProfile() { -} - -void SystemAbilityManager::RemoveCompletedCoreSaId(int32_t saId) -{ -} + if (parseHandler_ == nullptr) { + HILOGE("InitSaProfile parseHandler_ not init!"); + return; + } -void SystemAbilityManager::SendSystemReadyMessage() -{ + auto callback = [this] () { + int64_t begin = GetTickCount(); + std::vector fileNames; + GetDirFiles(PREFIX, fileNames); + auto parser = std::make_shared(); + for (const auto& file : fileNames) { + if (file.empty() || file.find(".xml") == std::string::npos + || file.find("_trust.xml") != std::string::npos) { + continue; + } + parser->ParseSaProfiles(file); + } + auto saInfos = parser->GetAllSaProfiles(); + lock_guard autoLock(saProfileMapLock_); + for (const auto& saInfo : saInfos) { + saProfileMap_[saInfo.saId] = saInfo; + } + HILOGI("[PerformanceTest] InitSaProfile spend %{public}" PRId64 " ms", GetTickCount() - begin); + }; + bool ret = parseHandler_->PostTask(callback); + if (!ret) { + HILOGW("SystemAbilityManager::InitSaProfile PostTask fail"); + } } -void SystemAbilityManager::SendSingleSystemReadyMessage(const sptr& systemReadyCallback) +bool SystemAbilityManager::GetSaProfile(int32_t saId, SaProfile& saProfile) { + lock_guard autoLock(saProfileMapLock_); + auto iter = saProfileMap_.find(saId); + if (iter == saProfileMap_.end()) { + return false; + } else { + saProfile = iter->second; + } + return true; } sptr SystemAbilityManager::GetSystemAbility(int32_t systemAbilityId) @@ -119,30 +133,6 @@ sptr SystemAbilityManager::GetSystemAbility(int32_t systemAbility return CheckSystemAbility(systemAbilityId); } -bool SystemAbilityManager::GetSystemAbilityInfoList(int32_t systemAbilityId, - const std::u16string& capability, std::list>& saInfoList) -{ - return false; -} - -sptr SystemAbilityManager::CheckLocalAbilityManager(const u16string& localAbilityManagerName) -{ - if (localAbilityManagerName.empty()) { - HILOGW("CheckLocalAbilityManager empty name!"); - return nullptr; - } - - lock_guard autoLock(localAbilityManagerMapLock_); - auto iter = localAbilityManagerMap_.find(localAbilityManagerName); - if (iter != localAbilityManagerMap_.end()) { - HILOGI("localAbilityMgr %{public}s found", Str16ToStr8(localAbilityManagerName).c_str()); - return iter->second; - } - HILOGE("localAbilityMgr %{public}s not exist", Str16ToStr8(localAbilityManagerName).c_str()); - - return nullptr; -} - sptr SystemAbilityManager::GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { return CheckSystemAbility(systemAbilityId, deviceId); @@ -156,25 +146,13 @@ sptr SystemAbilityManager::CheckSystemAbility(int32_t systemAbili return nullptr; } - // find the suited sa - std::string selectedDeviceId; - if (CheckRemoteSa(to_string(systemAbilityId), selectedDeviceId)) { - // already find the remote deviceId's sa is suited - return CheckSystemAbility(systemAbilityId, selectedDeviceId); - } - shared_lock readLock(abilityMapLock_); auto iter = abilityMap_.find(systemAbilityId); if (iter != abilityMap_.end()) { - auto callingUid = IPCSkeleton::GetCallingUid(); - if (IsSystemApp(callingUid) || CheckPermission(iter->second.permission)) { - HILOGI("finded service : %{public}d.", systemAbilityId); - return iter->second.remoteObj; - } - HILOGE("CheckSystemAbility systemAbilityId: %{public}d PERMISSION DENIED", systemAbilityId); - return nullptr; + HILOGI("found service : %{public}d.", systemAbilityId); + return iter->second.remoteObj; } - HILOGI("NOT finded service : %{public}d", systemAbilityId); + HILOGI("NOT found service : %{public}d", systemAbilityId); return nullptr; } @@ -203,40 +181,43 @@ sptr SystemAbilityManager::CheckSystemAbility(int32_t systemAbili return remoteBinder; } -int32_t SystemAbilityManager::FindSystemAbilityManagerNotify(int32_t systemAbilityId, int32_t code) +int32_t SystemAbilityManager::FindSystemAbilityNotify(int32_t systemAbilityId, int32_t code) { - return ERR_NO_INIT; + return FindSystemAbilityNotify(systemAbilityId, "", code); } -int32_t SystemAbilityManager::FindSystemAbilityManagerNotify(int32_t systemAbilityId, const std::string& deviceId, +void SystemAbilityManager::NotifySystemAbilityChanged(int32_t systemAbilityId, const std::string& deviceId, + int32_t code, const sptr& listener) +{ + if (listener == nullptr) { + HILOGE("%s listener null pointer!", __func__); + return; + } + + switch (code) { + case ADD_SYSTEM_ABILITY_TRANSACTION: { + listener->OnAddSystemAbility(systemAbilityId, deviceId); + break; + } + case REMOVE_SYSTEM_ABILITY_TRANSACTION: { + listener->OnRemoveSystemAbility(systemAbilityId, deviceId); + break; + } + default: + break; + } +} + +int32_t SystemAbilityManager::FindSystemAbilityNotify(int32_t systemAbilityId, const std::string& deviceId, int32_t code) { HILOGI("%s called:systemAbilityId = %{public}d, code = %{public}d", __func__, systemAbilityId, code); lock_guard autoLock(listenerMapLock_); auto iter = listenerMap_.find(systemAbilityId); if (iter != listenerMap_.end()) { - auto& listenerNames = iter->second; - for (const auto& listenerName : listenerNames) { - HILOGI("%s called:listenerName = %{public}s", __func__, Str16ToStr8(listenerName).c_str()); - sptr object = CheckLocalAbilityManager(listenerName); - sptr localAbilityManagerService = iface_cast(object); - if (localAbilityManagerService == nullptr) { - HILOGE(" %s get service fail", __func__); - continue; - } - - switch (code) { - case ADD_SYSTEM_ABILITY_TRANSACTION: { - localAbilityManagerService->OnAddSystemAbility(systemAbilityId, deviceId); - break; - } - case REMOVE_SYSTEM_ABILITY_TRANSACTION: { - localAbilityManagerService->OnRemoveSystemAbility(systemAbilityId, deviceId); - break; - } - default: - break; - } + auto& listeners = iter->second; + for (const auto& item : listeners) { + NotifySystemAbilityChanged(systemAbilityId, deviceId, code, item.first); } } @@ -276,56 +257,20 @@ int32_t SystemAbilityManager::AddOnDemandSystemAbilityInfo(int32_t systemAbility return ERR_OK; } -int32_t SystemAbilityManager::RecycleOnDemandSystemAbility() -{ - HILOGI("%{public}s called", __func__); - bool ret = false; - int32_t refCount = 0; - - lock_guard autoLock(onDemandAbilityMapLock_); - for (const auto& [systemAbilityId, localName] : onDemandAbilityMap_) { - sptr abilityProxy = CheckSystemAbility(systemAbilityId); - if (abilityProxy == nullptr) { - continue; - } - refCount = abilityProxy->GetSptrRefCount(); - if (refCount == 1) { - sptr localAbilityManagerService = - iface_cast(CheckLocalAbilityManager(localName)); - if (localAbilityManagerService == nullptr) { - HILOGI("get local ability %{public}s fail", Str16ToStr8(localName).c_str()); - continue; - } - ret = localAbilityManagerService->StopAbility(systemAbilityId); - if (!ret) { - HILOGI("stop ability %{public}d fail.", systemAbilityId); - continue; - } - ret = localAbilityManagerService->RecycleOndemandSystemAbility(systemAbilityId); - if (!ret) { - HILOGI("RecycleOndemandSystemAbility ability %{public}d fail.", systemAbilityId); - continue; - } - } - } - - return ERR_OK; -} - int32_t SystemAbilityManager::StartOnDemandAbility(int32_t systemAbilityId) { HILOGI("%{public}s called, systemAbilityId is %{public}d", __func__, systemAbilityId); lock_guard onDemandAbilityLock(onDemandAbilityMapLock_); auto iter = onDemandAbilityMap_.find(systemAbilityId); if (iter != onDemandAbilityMap_.end()) { - HILOGI("finded onDemandAbility: %{public}d.", systemAbilityId); - sptr localAbilityManagerService = - iface_cast(CheckLocalAbilityManager(iter->second)); - if (localAbilityManagerService == nullptr) { - HILOGI("get local ability %{public}s fail", Str16ToStr8(iter->second).c_str()); + HILOGI("found onDemandAbility: %{public}d.", systemAbilityId); + sptr procObject = + iface_cast(GetSystemProcess(iter->second)); + if (procObject == nullptr) { + HILOGI("get process:%{public}s fail", Str16ToStr8(iter->second).c_str()); return ERR_OK; } - localAbilityManagerService->StartAbilityAsyn(systemAbilityId); + procObject->StartAbility(systemAbilityId); startingAbilityList_.emplace_back(systemAbilityId); return ERR_OK; } @@ -365,102 +310,6 @@ sptr SystemAbilityManager::CheckSystemAbility(int32_t systemAbili return abilityProxy; } -int32_t SystemAbilityManager::ConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) -{ - HILOGI("%{public}s called, systemAbilityId is %{public}d", __func__, systemAbilityId); - if (connectionCallback == nullptr) { - HILOGI("connectionAbility is null."); - return ERR_INVALID_VALUE; - } - - lock_guard autoLock(onDemandAbilityMapLock_); - auto iter = onDemandAbilityMap_.find(systemAbilityId); - if (iter != onDemandAbilityMap_.end()) { - HILOGI("finded onDemandAbility: %{public}d.", systemAbilityId); - sptr localAbilityManagerService = - iface_cast(CheckLocalAbilityManager(iter->second)); - if (localAbilityManagerService == nullptr) { - HILOGI("%{public}s:get local service fail!", __func__); - connectionCallback->OnConnectedSystemAbility(nullptr); - return ERR_INVALID_VALUE; - } - localAbilityManagerService->StartAbilityAsyn(systemAbilityId); - } - connectionCallbackMap_[systemAbilityId] = connectionCallback; - HILOGI("insert %{public}d. size : %{public}zu", systemAbilityId, connectionCallbackMap_.size()); - - return ERR_OK; -} - -int32_t SystemAbilityManager::DisConnectSystemAbility(int32_t systemAbilityId, - const sptr& connectionCallback) -{ - HILOGI("%{public}s called, systemAbilityId is %{public}d", __func__, systemAbilityId); - if (connectionCallback == nullptr) { - HILOGI("connectionCallback is null."); - return ERR_INVALID_VALUE; - } - - { - lock_guard autoLock(onDemandAbilityMapLock_); - (void)connectionCallbackMap_.erase(systemAbilityId); - } - - connectionCallback->OnDisConnectedSystemAbility(systemAbilityId); - return ERR_OK; -} - -bool SystemAbilityManager::CheckCapability(const std::u16string& capability) -{ - if (capability.empty()) { - return true; - } - if (capability.size() > MAX_CAPABILITY_SIZE) { - return false; - } - - auto json = nlohmann::json::parse(Str16ToStr8(capability), nullptr, false); - if (json.is_discarded()) { - HILOGW("SystemAbilityManager::CheckCapability exception"); - return false; - } - return true; -} - -int32_t SystemAbilityManager::AddLocalAbilityManager(const u16string& localAbilityManagerName, - const sptr& localAbilityManager) -{ - if (localAbilityManagerName.empty() || localAbilityManager == nullptr) { - HILOGE("SystemAbilityManager::AddLocalAbilityManager empty name or null manager object!"); - return ERR_INVALID_VALUE; - } - if (Str16ToStr8(localAbilityManagerName) != (STR_LOCAL_ABILITY_MGR + to_string(IPCSkeleton::GetCallingPid()))) { - HILOGE("SystemAbilityManager::AddLocalAbilityManager please call AddSystemAbility function!"); - return ERR_INVALID_VALUE; - } - - lock_guard autoLock(localAbilityManagerMapLock_); - size_t managerNum = localAbilityManagerMap_.size(); - if (managerNum >= MAX_SERVICES) { - HILOGE("SystemAbilityManager::AddLocalAbilityManager map size reach MAX_SERVICES already"); - return ERR_INVALID_VALUE; - } - localAbilityManagerMap_[localAbilityManagerName] = localAbilityManager; - - if (localAbilityManagerDeath_ != nullptr) { - localAbilityManager->AddDeathRecipient(localAbilityManagerDeath_); - } - - return ERR_OK; -} - -void SystemAbilityManager::DoInsertSaData(const u16string& strName, - const sptr& ability, const SAExtraProp& extraProp) -{ - HILOGW("AddSystemAbility samgrHandler_ Insert fail"); -} - void SystemAbilityManager::DeleteStartingAbilityMember(int32_t systemAbilityId) { if (!CheckInputSysAbilityId(systemAbilityId)) { @@ -495,60 +344,15 @@ int32_t SystemAbilityManager::RemoveSystemAbility(int32_t systemAbilityId) ability->RemoveDeathRecipient(abilityDeath_); } (void)abilityMap_.erase(itSystemAbility); - RestoreCoreSaId(systemAbilityId); HILOGI("%s called, systemAbilityId : %{public}d, size : %{public}zu", __func__, systemAbilityId, abilityMap_.size()); } - FindSystemAbilityManagerNotify(systemAbilityId, REMOVE_SYSTEM_ABILITY_TRANSACTION); + FindSystemAbilityNotify(systemAbilityId, REMOVE_SYSTEM_ABILITY_TRANSACTION); DeleteStartingAbilityMember(systemAbilityId); return ERR_OK; } -int32_t SystemAbilityManager::RemoveLocalAbilityManager(const u16string& localAbilityManagerName) -{ - if (localAbilityManagerName.empty()) { - HILOGE("SystemAbilityManager::RemoveLocalAbilityManager empty name!"); - return ERR_INVALID_VALUE; - } - - lock_guard autoLock(localAbilityManagerMapLock_); - auto iter = localAbilityManagerMap_.find(localAbilityManagerName); - if (iter == localAbilityManagerMap_.end()) { - HILOGE("SystemAbilityManager::RemoveLocalAbilityManager name not exist!"); - return ERR_INVALID_VALUE; - } - sptr localAbilityManager = iter->second; - if (localAbilityManager != nullptr && localAbilityManagerDeath_ != nullptr) { - localAbilityManager->RemoveDeathRecipient(localAbilityManagerDeath_); - } - localAbilityManagerMap_.erase(iter); - - return ERR_OK; -} - -int32_t SystemAbilityManager::RemoveLocalAbilityManager(const sptr& localAbilityManager) -{ - HILOGI("SystemAbilityManager::RemoveLocalAbilityManager called"); - if (localAbilityManager == nullptr) { - HILOGW("SystemAbilityManager::RemoveLocalAbilityManager null manager object!"); - return ERR_INVALID_VALUE; - } - - lock_guard autoLock(localAbilityManagerMapLock_); - for (const auto& [managerName, manager] : localAbilityManagerMap_) { - if (manager == localAbilityManager) { - (void)localAbilityManagerMap_.erase(managerName); - if (localAbilityManagerDeath_ != nullptr) { - localAbilityManager->RemoveDeathRecipient(localAbilityManagerDeath_); - } - break; - } - } - - return ERR_OK; -} - int32_t SystemAbilityManager::RemoveSystemAbility(const sptr& ability) { HILOGI("%s called, (ability)", __func__); @@ -564,11 +368,10 @@ int32_t SystemAbilityManager::RemoveSystemAbility(const sptr& abi if (iter->second.remoteObj == ability) { saId = iter->first; (void)abilityMap_.erase(iter); - RestoreCoreSaId(saId); if (abilityDeath_ != nullptr) { ability->RemoveDeathRecipient(abilityDeath_); } - HILOGI("%s called, systemAbilityId:%{public}d removed, size : %zu", __func__, saId, + HILOGI("%s called, systemAbilityId:%{public}d removed, size : %{public}zu", __func__, saId, abilityMap_.size()); break; } @@ -576,17 +379,12 @@ int32_t SystemAbilityManager::RemoveSystemAbility(const sptr& abi } if (saId != 0) { - FindSystemAbilityManagerNotify(saId, REMOVE_SYSTEM_ABILITY_TRANSACTION); + FindSystemAbilityNotify(saId, REMOVE_SYSTEM_ABILITY_TRANSACTION); DeleteStartingAbilityMember(saId); } return ERR_OK; } -int32_t SystemAbilityManager::RemoveSystemReadyCallback(const sptr& callback) -{ - return ERR_INVALID_VALUE; -} - vector SystemAbilityManager::ListSystemAbilities(uint32_t dumpFlags) { vector list; @@ -612,67 +410,99 @@ u16string SystemAbilityManager::GetSystemAbilityName(int32_t index) return u16string(); } -int32_t SystemAbilityManager::SubscribeSystemAbility(int32_t systemAbilityId, const u16string& listenerName) +int32_t SystemAbilityManager::SubscribeSystemAbility(int32_t systemAbilityId, + const sptr& listener) { HILOGI("%s called", __func__); - if (!CheckInputSysAbilityId(systemAbilityId) || listenerName.empty()) { - HILOGW("SubscribeSystemAbility systemAbilityId or listenerName invalid!"); + if (!CheckInputSysAbilityId(systemAbilityId) || listener == nullptr) { + HILOGW("SubscribeSystemAbility systemAbilityId or listener invalid!"); return ERR_INVALID_VALUE; } - lock_guard autoLock(listenerMapLock_); - HILOGD("systemAbilityId = %{public}d, listenerName = %{public}s, size = %{public}zu", - systemAbilityId, Str16ToStr8(listenerName).c_str(), listenerMap_.size()); - auto& listenerNames = listenerMap_[systemAbilityId]; - bool found = false; - for (const auto& itemName : listenerNames) { - if (itemName == listenerName) { - found = true; - HILOGI("already exist systemAbilityId = %{public}d, listenerName = %{public}s", - systemAbilityId, Str16ToStr8(listenerName).c_str()); - break; + auto callingPid = IPCSkeleton::GetCallingPid(); + { + lock_guard autoLock(listenerMapLock_); + auto& listeners = listenerMap_[systemAbilityId]; + for (const auto& itemListener : listeners) { + if (listener->AsObject() == itemListener.first->AsObject()) { + HILOGI("already exist listener object systemAbilityId = %{public}d", systemAbilityId); + return ERR_OK; + } + } + auto& count = subscribeCountMap_[callingPid]; + if (count >= MAX_SUBSCRIBE_COUNT) { + HILOGE("SubscribeSystemAbility pid:%{public}d overflow max subscribe count!", callingPid); + return ERR_PERMISSION_DENIED; + } + ++count; + if (abilityStatusDeath_ != nullptr) { + bool ret = listener->AsObject()->AddDeathRecipient(abilityStatusDeath_); + listeners.emplace_back(listener, callingPid); + HILOGI("SubscribeSystemAbility systemAbilityId = %{public}d AddDeathRecipient %{public}s", + systemAbilityId, ret ? "succeed" : "failed"); } + HILOGI("SubscribeSystemAbility systemAbilityId = %{public}d, size = %{public}zu", systemAbilityId, + listeners.size()); } - if (!found) { - listenerNames.emplace_back(listenerName); + sptr targetObject = CheckSystemAbility(systemAbilityId); + if (targetObject != nullptr) { + NotifySystemAbilityChanged(systemAbilityId, "", ADD_SYSTEM_ABILITY_TRANSACTION, listener); } return ERR_OK; } -int32_t SystemAbilityManager::UnSubscribeSystemAbility(int32_t systemAbilityId, const u16string& listenerName) +void SystemAbilityManager::UnSubscribeSystemAbilityLocked( + std::list, int32_t>>& listenerList, + const sptr& listener) +{ + auto iter = listenerList.begin(); + while (iter != listenerList.end()) { + auto& item = *iter; + if (item.first->AsObject() != listener) { + ++iter; + continue; + } + + if (abilityStatusDeath_ != nullptr) { + listener->RemoveDeathRecipient(abilityStatusDeath_); + } + auto iterPair = subscribeCountMap_.find(item.second); + if (iterPair != subscribeCountMap_.end()) { + --iterPair->second; + if (iterPair->second == 0) { + subscribeCountMap_.erase(iterPair); + } + } + iter = listenerList.erase(iter); + break; + } +} + +int32_t SystemAbilityManager::UnSubscribeSystemAbility(int32_t systemAbilityId, + const sptr& listener) { HILOGI("%s called", __func__); - if (!CheckInputSysAbilityId(systemAbilityId) || listenerName.empty()) { - HILOGW("UnSubscribeSystemAbility systemAbilityId or listenerSaId invalid!"); + if (!CheckInputSysAbilityId(systemAbilityId) || listener == nullptr) { + HILOGW("UnSubscribeSystemAbility systemAbilityId or listener invalid!"); return ERR_INVALID_VALUE; } lock_guard autoLock(listenerMapLock_); - HILOGD("systemAbilityId = %{public}d, listenerName = %{public}s, size = %{public}zu", - systemAbilityId, Str16ToStr8(listenerName).c_str(), listenerMap_.size()); - auto& listenerNames = listenerMap_[systemAbilityId]; - for (auto iter = listenerNames.begin(); iter != listenerNames.end();) { - if (*iter == listenerName) { - iter = listenerNames.erase(iter); - break; - } else { - ++iter; - } - } + auto& listeners = listenerMap_[systemAbilityId]; + UnSubscribeSystemAbilityLocked(listeners, listener->AsObject()); + HILOGI("UnSubscribeSystemAbility systemAbilityId = %{public}d, size = %{public}zu", systemAbilityId, + listeners.size()); return ERR_OK; } -const std::u16string SystemAbilityManager::CheckOnDemandSystemAbility(int32_t systemAbilityId) +void SystemAbilityManager::UnSubscribeSystemAbility(const sptr& remoteObject) { - HILOGI("%{public}s called, systemAbilityId is %{public}d", __func__, systemAbilityId); - lock_guard autoLock(onDemandAbilityMapLock_); - auto iter = onDemandAbilityMap_.find(systemAbilityId); - if (iter != onDemandAbilityMap_.end()) { - HILOGI("finded onDemandAbility: %{public}d.", systemAbilityId); - return iter->second; + lock_guard autoLock(listenerMapLock_); + for (auto& item : listenerMap_) { + auto& listeners = item.second; + UnSubscribeSystemAbilityLocked(listeners, remoteObject); } - - return u16string(); + HILOGI("UnSubscribeSystemAbility remote object dead!"); } void SystemAbilityManager::SetDeviceName(const u16string &name) @@ -685,11 +515,6 @@ const u16string& SystemAbilityManager::GetDeviceName() const return deviceName_; } -bool SystemAbilityManager::GetDeviceId(string& deviceId) -{ - return false; -} - void SystemAbilityManager::NotifyRemoteSaDied(const std::u16string& name) { std::u16string saName; @@ -721,29 +546,11 @@ void SystemAbilityManager::ParseRemoteSaName(const std::u16string& name, std::st } } -void SystemAbilityManager::OnDemandConnected(int32_t systemAbilityId, const sptr& ability) -{ - if (!CheckInputSysAbilityId(systemAbilityId)) { - return; - } - sptr connectionAbility; - { - lock_guard autoLock(onDemandAbilityMapLock_); - auto iter = connectionCallbackMap_.find(systemAbilityId); - if (iter != connectionCallbackMap_.end()) { - connectionAbility = iter->second; - } - } - if (connectionAbility != nullptr) { - connectionAbility->OnConnectedSystemAbility(ability); - } -} - int32_t SystemAbilityManager::AddSystemAbility(int32_t systemAbilityId, const sptr& ability, const SAExtraProp& extraProp) { HILOGI("%s called", __func__); - if (!CheckInputSysAbilityId(systemAbilityId) || ability == nullptr || (!CheckCapability(extraProp.capability))) { + if (!CheckInputSysAbilityId(systemAbilityId) || ability == nullptr) { HILOGE("AddSystemAbilityExtra input params is invalid."); return ERR_INVALID_VALUE; } @@ -760,13 +567,12 @@ int32_t SystemAbilityManager::AddSystemAbility(int32_t systemAbilityId, const sp saInfo.capability = extraProp.capability; saInfo.permission = Str16ToStr8(extraProp.permission); abilityMap_[systemAbilityId] = std::move(saInfo); - RemoveCompletedCoreSaId(systemAbilityId); - HILOGI("insert %{public}d. size : %zu,", systemAbilityId, abilityMap_.size()); + HILOGI("insert %{public}d. size : %{public}zu", systemAbilityId, abilityMap_.size()); } if (abilityDeath_ != nullptr) { ability->AddDeathRecipient(abilityDeath_); } - FindSystemAbilityManagerNotify(systemAbilityId, ADD_SYSTEM_ABILITY_TRANSACTION); + FindSystemAbilityNotify(systemAbilityId, ADD_SYSTEM_ABILITY_TRANSACTION); u16string strName = Str8ToStr16(to_string(systemAbilityId)); if (extraProp.isDistributed && dBinderService_ != nullptr) { dBinderService_->RegisterRemoteProxy(strName, systemAbilityId); @@ -775,58 +581,76 @@ int32_t SystemAbilityManager::AddSystemAbility(int32_t systemAbilityId, const sp 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"); + HILOGI("start result is %{public}s", ret ? "succeed" : "fail"); isDbinderStart_ = true; } } return ERR_OK; } -int32_t SystemAbilityManager::RegisterSystemReadyCallback(const sptr& systemReadyCallback) +int32_t SystemAbilityManager::AddSystemProcess(const u16string& procName, + const sptr& procObject) { + if (procName.empty() || procObject == nullptr) { + HILOGE("AddSystemProcess empty name or null object!"); + return ERR_INVALID_VALUE; + } + + lock_guard autoLock(systemProcessMapLock_); + size_t procNum = systemProcessMap_.size(); + if (procNum >= MAX_SERVICES) { + HILOGE("AddSystemProcess map size reach MAX_SERVICES already"); + return ERR_INVALID_VALUE; + } + systemProcessMap_[procName] = procObject; + if (systemProcessDeath_ != nullptr) { + bool ret = procObject->AddDeathRecipient(systemProcessDeath_); + HILOGW("AddSystemProcess AddDeathRecipient %{public}s!", ret ? "succeed" : "failed"); + } + HILOGI("AddSystemProcess insert %{public}s. size : %{public}zu", Str16ToStr8(procName).c_str(), + systemProcessMap_.size()); return ERR_OK; } -int32_t SystemAbilityManager::GetCoreSystemAbilityList(vector& coreSaList, int dumpMode) +int32_t SystemAbilityManager::RemoveSystemProcess(const sptr& procObject) { - if (dumpMode > DUMP_UNREGISTERED_CORE_SYSTEM_ABILITY || dumpMode < DUMP_ALL_CORE_SYSTEM_ABILITY) { + HILOGI("RemoveSystemProcess called"); + if (procObject == nullptr) { + HILOGW("RemoveSystemProcess null object!"); return ERR_INVALID_VALUE; } - set coreSaIdSet; - bool result = Utils::ParseCoreSaList(CORE_SYSTEM_ABILITY_PATH, coreSaIdSet); - HILOGD("coreSa::GetCoreSystemAbilityList coreSaIdSet: %{public}zu result:%d", coreSaIdSet.size(), result); - if (coreSaIdSet.empty()) { - HILOGE("coreSa::GetCoreSystemAbilityList parse core salist error, add the default core sa!!"); - AddDefaultCoreSa(coreSaIdSet); - } - for (int32_t saId : coreSaIdSet) { - if (dumpMode == DUMP_REGISTERED_CORE_SYSTEM_ABILITY) { - if (GetSystemAbility(saId) == nullptr) { - continue; - } - } else if (dumpMode == DUMP_UNREGISTERED_CORE_SYSTEM_ABILITY) { - if (GetSystemAbility(saId) != nullptr) { - continue; + + lock_guard autoLock(systemProcessMapLock_); + for (const auto& [procName, object] : systemProcessMap_) { + if (object == procObject) { + if (systemProcessDeath_ != nullptr) { + procObject->RemoveDeathRecipient(systemProcessDeath_); } + std::string name = Str16ToStr8(procName); + (void)systemProcessMap_.erase(procName); + HILOGI("RemoveSystemProcess process:%{public}s dead, size : %{public}zu", name.c_str(), + systemProcessMap_.size()); + break; } - coreSaList.push_back(saId); } return ERR_OK; } -bool SystemAbilityManager::IsLocalDeviceId(const std::string& deviceId) +sptr SystemAbilityManager::GetSystemProcess(const u16string& procName) { - return false; -} - -bool SystemAbilityManager::CheckRemoteSa(const std::string& saName, std::string& selectedDeviceId) -{ - return false; -} + if (procName.empty()) { + HILOGE("GetSystemProcess empty name!"); + return nullptr; + } -bool SystemAbilityManager::CheckPermission(const std::string& permission) -{ - return true; + lock_guard autoLock(systemProcessMapLock_); + auto iter = systemProcessMap_.find(procName); + if (iter != systemProcessMap_.end()) { + HILOGI("process:%{public}s found", Str16ToStr8(procName).c_str()); + return iter->second; + } + HILOGE("process:%{public}s not exist", Str16ToStr8(procName).c_str()); + return nullptr; } std::string SystemAbilityManager::TransformDeviceId(const std::string& deviceId, int32_t type, bool isPrivate) @@ -838,62 +662,4 @@ std::string SystemAbilityManager::GetLocalNodeId() { return std::string(); } - -int32_t SystemAbilityManager::AddSystemCapability(const string& sysCap) -{ - int32_t ret = ERR_INVALID_VALUE; - if (sysCap.empty() || sysCap.length() > MAX_SYSCAP_NAME_LEN) { - HILOGE("SystemAbilityManager::AddSystemCapability syscap error!"); - return ret; - } - lock_guard autoLock(sysCapMapLock_); - auto iter = sysCapMap_.find(sysCap); - if (iter != sysCapMap_.end()) { - HILOGD("SystemAbilityManager::AddSystemCapability In %s!", sysCap.c_str()); - iter->second = true; - ret = ERR_OK; - } - return ret; -} - -bool SystemAbilityManager::HasSystemCapability(const string& sysCap) -{ - if (sysCap.empty() || sysCap.length() > MAX_SYSCAP_NAME_LEN) { - HILOGE("SystemAbilityManager::HasSystemCapability syscap error!"); - return false; - } - lock_guard autoLock(sysCapMapLock_); - const auto iter = sysCapMap_.find(sysCap); - if (iter != sysCapMap_.end()) { - return iter->second; - } - return false; -} - -vector SystemAbilityManager::GetSystemAvailableCapabilities() -{ - vector sysCaps; - lock_guard autoLock(sysCapMapLock_); - for (const auto& [sysCap, isReg] : sysCapMap_) { - if (!isReg) { - continue; - } - sysCaps.emplace_back(sysCap); - } - return sysCaps; -} - -void SystemAbilityManager::InitSysCapMap() -{ -} - -void SystemAbilityManager::AddDefaultCoreSa(set& coreSaIdSet) const -{ - coreSaIdSet.emplace(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN); - coreSaIdSet.emplace(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - coreSaIdSet.emplace(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); - coreSaIdSet.emplace(WORK_SCHEDULE_SERVICE_ID); - coreSaIdSet.emplace(DISTRIBUTED_SCHED_SA_ID); - coreSaIdSet.emplace(COMMON_EVENT_SERVICE_ABILITY_ID); -} } // namespace OHOS diff --git a/services/samgr/native/source/system_ability_manager_stub.cpp b/services/samgr/native/source/system_ability_manager_stub.cpp old mode 100644 new mode 100755 index bff10a7d73b26220cdd1d0065f04b29f4bd091e7..6a16adab59bb81e019041ec2bbeb964fc05645fc --- a/services/samgr/native/source/system_ability_manager_stub.cpp +++ b/services/samgr/native/source/system_ability_manager_stub.cpp @@ -20,7 +20,6 @@ #include "ipc_types.h" #include "sam_log.h" #include "string_ex.h" -#include "system_ability_info.h" #include "system_ability_manager.h" #include "tools.h" @@ -29,7 +28,6 @@ namespace { constexpr int32_t MULTIUSER_HAP_PER_USER_RANGE = 100000; constexpr int32_t HID_HAP = 10000; /* first hap user */ constexpr int32_t UID_SHELL = 2000; -const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken"; } SystemAbilityManagerStub::SystemAbilityManagerStub() { @@ -49,40 +47,14 @@ SystemAbilityManagerStub::SystemAbilityManagerStub() &SystemAbilityManagerStub::CheckRemtSystemAbilityInner; memberFuncMap_[ADD_ONDEMAND_SYSTEM_ABILITY_TRANSACTION] = &SystemAbilityManagerStub::AddOndemandSystemAbilityInner; - memberFuncMap_[RECYCLE_ONDEMAND_SYSTEM_ABILITY_TRANSACTION] = - &SystemAbilityManagerStub::RecycleOndemandSystemAbilityInner; memberFuncMap_[CHECK_SYSTEM_ABILITY_IMMEDIATELY_TRANSACTION] = &SystemAbilityManagerStub::CheckSystemAbilityImmeInner; - memberFuncMap_[CONNECTION_SYSTEM_ABILITY_TRANSACTION] = - &SystemAbilityManagerStub::ConnOndemandSystemAbilityInner; - memberFuncMap_[DISCONNECTION_SYSTEM_ABILITY_TRANSACTION] = - &SystemAbilityManagerStub::DisConnOndemandSystemAbilityInner; - memberFuncMap_[CHECK_ONDEMAND_SYSTEM_ABILITY_TRANSACTION] = - &SystemAbilityManagerStub::CheckOndemandSystemAbilityInner; memberFuncMap_[CHECK_REMOTE_SYSTEM_ABILITY_FOR_JAVA_TRANSACTION] = &SystemAbilityManagerStub::CheckRemtSystemAbilityForJavaInner; - memberFuncMap_[GET_SYSTEM_ABILITYINFOLIST_TRANSACTION] = - &SystemAbilityManagerStub::GetSystemAbilityInfoListInner; memberFuncMap_[UNSUBSCRIBE_SYSTEM_ABILITY_TRANSACTION] = &SystemAbilityManagerStub::UnSubsSystemAbilityInner; - memberFuncMap_[GET_LOCAL_DEVICE_ID_TRANSACTION] = - &SystemAbilityManagerStub::GetDeviceIdInner; - memberFuncMap_[ADD_LOCAL_ABILITY_TRANSACTION] = - &SystemAbilityManagerStub::AddLocalAbilityInner; - memberFuncMap_[CHECK_LOCAL_ABILITY_TRANSACTION] = - &SystemAbilityManagerStub::CheckLocalAbilityInner; - memberFuncMap_[REMOVE_LOCAL_ABILITY_TRANSACTION] = - &SystemAbilityManagerStub::RemoveLocalAbilityInner; - memberFuncMap_[REGISTER_SYSTEM_READY_CALLBACK] = - &SystemAbilityManagerStub::RegisterSystemReadyCallbackInner; - memberFuncMap_[GET_CORE_SYSTEM_ABILITY_LIST] = - &SystemAbilityManagerStub::GetCoreSystemAbilityListInner; - memberFuncMap_[ADD_SYSTEM_CAPABILITY] = - &SystemAbilityManagerStub::AddSystemCapabilityInner; - memberFuncMap_[HAS_SYSTEM_CAPABILITY] = - &SystemAbilityManagerStub::HasSystemCapabilityInner; - memberFuncMap_[GET_AVAILABLE_SYSTEM_CAPABILITY] = - &SystemAbilityManagerStub::GetSystemAvailableCapabilitiesInner; + memberFuncMap_[ADD_SYSTEM_PROCESS_TRANSACTION] = + &SystemAbilityManagerStub::AddSystemProcessInner; } int32_t SystemAbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption &option) @@ -112,110 +84,6 @@ bool SystemAbilityManagerStub::EnforceInterceToken(MessageParcel& data) return interfaceToken == SAMANAGER_INTERFACE_TOKEN; } -int32_t SystemAbilityManagerStub::GetSystemAbilityInfoListInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("GetSystemAbilityInfoListInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - int32_t systemAbilityId = 0; - bool ret = data.ReadInt32(systemAbilityId); - if (!ret) { - HILOGW("SystemAbilityManagerStub::GetSystemAbilityInfoListInner read systemAbilityId failed!"); - return ERR_NULL_OBJECT; - } - std::u16string capability = data.ReadString16(); - std::list> saInfoList; - bool saRet = GetSystemAbilityInfoList(systemAbilityId, capability, saInfoList); - if (!reply.WriteBool(saRet)) { - HILOGW("SystemAbilityManagerStub::GetSystemAbilityListInner write reply size failed!"); - return ERR_FLATTEN_OBJECT; - } - if (!reply.WriteInt32(static_cast(saInfoList.size()))) { - HILOGW("SystemAbilityManagerStub::GetSystemAbilityListInner write reply size failed!"); - return ERR_FLATTEN_OBJECT; - } - for (const auto& sa : saInfoList) { - if (!reply.WriteParcelable(sa.get())) { - HILOGW("SystemAbilityManagerStub::GetSystemAbilityListInner write vector failed!"); - return ERR_FLATTEN_OBJECT; - } - } - return ERR_NONE; -} - -int32_t SystemAbilityManagerStub::CheckLocalAbilityInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("CheckLocalAbilityInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - std::u16string name = data.ReadString16(); - if (name.empty()) { - HILOGW("SystemAbilityManagerStub::CheckLocalAbilityInner read name failed!"); - return ERR_NULL_OBJECT; - } - bool ret = reply.WriteRemoteObject(CheckLocalAbilityManager(name)); - if (!ret) { - HILOGW("SystemAbilityManagerStub::CheckLocalAbilityInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - - return ERR_NONE; -} - -int32_t SystemAbilityManagerStub::AddLocalAbilityInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("AddLocalAbilityInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - std::u16string name = data.ReadString16(); - if (name.empty()) { - HILOGW("SystemAbilityManagerStub::AddLocalAbilityInner read name failed!"); - return ERR_NULL_OBJECT; - } - - auto object = data.ReadRemoteObject(); - if (object == nullptr) { - HILOGW("SystemAbilityManagerStub::AddLocalAbilityInner readParcelable failed!"); - return ERR_NULL_OBJECT; - } - - int32_t result = AddLocalAbilityManager(name, object); - HILOGI("SystemAbilityManagerStub::AddLocalAbilityInner result is %d", result); - bool ret = reply.WriteInt32(result); - if (!ret) { - HILOGW("SystemAbilityManagerStub::AddLocalAbilityInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - - return result; -} - -int32_t SystemAbilityManagerStub::RemoveLocalAbilityInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("RemoveLocalAbilityInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - std::u16string name = data.ReadString16(); - if (name.empty()) { - HILOGW("SystemAbilityManagerStub::RemoveLocalAbilityInner read name failed!"); - return ERR_NULL_OBJECT; - } - - int32_t result = RemoveLocalAbilityManager(name); - HILOGI("SystemAbilityManagerStub::RemoveLocalAbilityInner result is %{public}d", result); - bool ret = reply.WriteInt32(result); - if (!ret) { - HILOGW("SystemAbilityManagerStub::RemoveLocalAbilityInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - - return result; -} - int32_t SystemAbilityManagerStub::ListSystemAbilityInner(MessageParcel& data, MessageParcel& reply) { if (!CanRequest()) { @@ -260,13 +128,17 @@ int32_t SystemAbilityManagerStub::SubsSystemAbilityInner(MessageParcel& data, Me HILOGW("SystemAbilityManagerStub::SubsSystemAbilityInner read systemAbilityId failed!"); return ERR_NULL_OBJECT; } - std::u16string listenerName = data.ReadString16(); - if (listenerName.empty()) { - HILOGW("SystemAbilityManagerStub::SubsSystemAbilityInner read listenerName failed!"); + sptr remoteObject = data.ReadRemoteObject(); + if (remoteObject == nullptr) { + HILOGW("SystemAbilityManagerStub::SubsSystemAbilityInner read listener failed!"); return ERR_NULL_OBJECT; } - - int32_t result = SubscribeSystemAbility(systemAbilityId, listenerName); + sptr listener = iface_cast(remoteObject); + if (listener == nullptr) { + HILOGW("SystemAbilityManagerStub::SubsSystemAbilityInner iface_cast failed!"); + return ERR_NULL_OBJECT; + } + int32_t result = SubscribeSystemAbility(systemAbilityId, listener); HILOGI("SystemAbilityManagerStub::SubsSystemAbilityInner result is %d", result); bool ret = reply.WriteInt32(result); if (!ret) { @@ -288,13 +160,17 @@ int32_t SystemAbilityManagerStub::UnSubsSystemAbilityInner(MessageParcel& data, HILOGW("SystemAbilityManagerStub::UnSubsSystemAbilityInner read systemAbilityId failed!"); return ERR_NULL_OBJECT; } - std::u16string listenerName = data.ReadString16(); - if (listenerName.empty()) { - HILOGW("SystemAbilityManagerStub::SubsSystemAbilityInner read listenerName failed!"); + sptr remoteObject = data.ReadRemoteObject(); + if (remoteObject == nullptr) { + HILOGW("SystemAbilityManagerStub::UnSubscribeSystemAbility read listener failed!"); return ERR_NULL_OBJECT; } - - int32_t result = UnSubscribeSystemAbility(systemAbilityId, listenerName); + sptr listener = iface_cast(remoteObject); + if (listener == nullptr) { + HILOGW("SystemAbilityManagerStub::UnSubscribeSystemAbility iface_cast failed!"); + return ERR_NULL_OBJECT; + } + int32_t result = UnSubscribeSystemAbility(systemAbilityId, listener); HILOGI("SystemAbilityManagerStub::UnSubscribeSystemAbility result is %d", result); bool ret = reply.WriteInt32(result); if (!ret) { @@ -382,23 +258,6 @@ int32_t SystemAbilityManagerStub::AddOndemandSystemAbilityInner(MessageParcel& d return result; } -int32_t SystemAbilityManagerStub::RecycleOndemandSystemAbilityInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("RecycleOndemandSystemAbilityInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - int32_t result = RecycleOnDemandSystemAbility(); - HILOGI("SystemAbilityManagerStub::RecycleOndemandSystemAbilityInner result is %d", result); - bool ret = reply.WriteInt32(result); - if (!ret) { - HILOGW("SystemAbilityManagerStub::RecycleOndemandSystemAbilityInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - - return result; -} - int32_t SystemAbilityManagerStub::CheckSystemAbilityImmeInner(MessageParcel& data, MessageParcel& reply) { int32_t systemAbilityId = data.ReadInt32(); @@ -427,112 +286,6 @@ int32_t SystemAbilityManagerStub::CheckSystemAbilityImmeInner(MessageParcel& dat return ERR_NONE; } -int32_t SystemAbilityManagerStub::ConnOndemandSystemAbilityInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("ConnOndemandSystemAbilityInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - int32_t systemAbilityId = data.ReadInt32(); - if (!CheckInputSysAbilityId(systemAbilityId)) { - HILOGW("SystemAbilityManagerStub::ConnOndemandSystemAbilityInner read systemAbilityId failed!"); - return ERR_NULL_OBJECT; - } - auto object = data.ReadRemoteObject(); - if (object == nullptr) { - HILOGW("SystemAbilityManagerStub::ConnOndemandSystemAbilityInner readParcelable failed!"); - return ERR_NULL_OBJECT; - } - - sptr connectionAbility = - iface_cast(object); - int32_t result = ConnectSystemAbility(systemAbilityId, connectionAbility); - HILOGI("SystemAbilityManagerStub::ConnOndemandSystemAbilityInner result is %d", result); - bool ret = reply.WriteInt32(result); - if (!ret) { - HILOGW("SystemAbilityManagerStub::ConnOndemandSystemAbilityInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - - return result; -} - -int32_t SystemAbilityManagerStub::DisConnOndemandSystemAbilityInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("DisConnOndemandSystemAbilityInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - int32_t systemAbilityId = data.ReadInt32(); - if (!CheckInputSysAbilityId(systemAbilityId)) { - HILOGW("SystemAbilityManagerStub::DisConnOndemandSystemAbilityInner read systemAbilityId failed!"); - return ERR_NULL_OBJECT; - } - auto object = data.ReadRemoteObject(); - if (object == nullptr) { - HILOGW("SystemAbilityManagerStub::DisConnOndemandSystemAbilityInner readParcel failed!"); - return ERR_NULL_OBJECT; - } - - sptr connectionAbility = - iface_cast(object); - int32_t result = DisConnectSystemAbility(systemAbilityId, connectionAbility); - HILOGI("SystemAbilityManagerStub::DisConnOndemandSystemAbilityInner result is %d", result); - bool ret = reply.WriteInt32(result); - if (!ret) { - HILOGW("SystemAbilityManagerStub::DisConnOndemandSystemAbilityInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - - return result; -} - -int32_t SystemAbilityManagerStub::CheckOndemandSystemAbilityInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("CheckOndemandSystemAbilityInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - int32_t systemAbilityId = data.ReadInt32(); - if (!CheckInputSysAbilityId(systemAbilityId)) { - HILOGW("SystemAbilityManagerStub::CheckOndemandSystemAbilityInner read systemAbilityId failed!"); - return ERR_NULL_OBJECT; - } - bool ret = reply.WriteString16((CheckOnDemandSystemAbility(systemAbilityId)).c_str()); - if (!ret) { - HILOGW("SystemAbilityManagerStub::ConnOndemandSystemAbilityInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - - return ERR_NONE; -} - -int32_t SystemAbilityManagerStub::GetDeviceIdInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("GetDeviceIdInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - std::string deviceId = SystemAbilityManager::GetInstance()->GetLocalNodeId(); - if (deviceId.empty()) { - HILOGW("SystemAbilityManagerStub::GetLocalDeviceIdInner get deviceId failed!"); - return ERR_FLATTEN_OBJECT; - } - - bool result = reply.WriteString(deviceId); - if (!result) { - HILOGW("SystemAbilityManagerStub::GetDeviceIdInner write deviceId failed."); - return ERR_FLATTEN_OBJECT; - } - - bool ret = reply.WriteBool(result); - if (!ret) { - HILOGW("SystemAbilityManagerStub::GetDeviceIdInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - return ERR_NONE; -} - int32_t SystemAbilityManagerStub::UnmarshalingSaExtraProp(MessageParcel& data, SAExtraProp& extraProp) { bool isDistributed = false; @@ -640,94 +393,33 @@ int32_t SystemAbilityManagerStub::RemoveSystemAbilityInner(MessageParcel& data, return result; } -int32_t SystemAbilityManagerStub::RegisterSystemReadyCallbackInner(MessageParcel& data, MessageParcel& reply) -{ - auto object = data.ReadRemoteObject(); - if (object == nullptr) { - HILOGW("SystemAbilityManagerStub::RegisterSystemReadyCallback readParcelable failed!"); - return ERR_NULL_OBJECT; - } - int32_t result = RegisterSystemReadyCallback(object); - HILOGI("SystemAbilityManagerStub::RegisterSystemReadyCallbackInner result is %{public}d", result); - bool ret = reply.WriteInt32(result); - if (!ret) { - HILOGW("SystemAbilityManagerStub::RegisterSystemReadyCallbackInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - return result; -} - -int32_t SystemAbilityManagerStub::GetCoreSystemAbilityListInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("SystemAbilityManagerStub::GetCoreSystemAbilityListInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - int32_t dumpMode = data.ReadInt32(); - std::vector coreSaList; - int32_t result = GetCoreSystemAbilityList(coreSaList, dumpMode); - HILOGI("SystemAbilityManagerStub::GetCoreSystemAbilityListInner result is %{public}d", result); - bool ret = reply.WriteInt32(result); - if (!ret) { - HILOGW("SystemAbilityManagerStub::GetCoreSystemAbilityListInner write reply failed."); - return ERR_FLATTEN_OBJECT; - } - if (result == ERR_NONE && (!reply.WriteInt32Vector(coreSaList))) { - return ERR_FLATTEN_OBJECT; - } - return result; -} -int32_t SystemAbilityManagerStub::AddSystemCapabilityInner(MessageParcel& data, MessageParcel& reply) +int32_t SystemAbilityManagerStub::AddSystemProcessInner(MessageParcel& data, MessageParcel& reply) { if (!CanRequest()) { - HILOGE("SystemAbilityManagerStub::AddSystemCapabilityInner PERMISSION DENIED!"); + HILOGE("AddSystemProcessInner PERMISSION DENIED!"); return ERR_PERMISSION_DENIED; } - - std::u16string sysCap = data.ReadString16(); - bool ret = AddSystemCapability(Str16ToStr8(sysCap)); - if (!reply.WriteInt32(ret)) { - HILOGW("SystemAbilityManagerStub::AddSystemCapabilityInner write reply failed!"); - return ERR_FLATTEN_OBJECT; - } - - return ERR_NONE; -} - -int32_t SystemAbilityManagerStub::HasSystemCapabilityInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("SystemAbilityManagerStub::HasSystemCapabilityInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; + std::u16string procName = data.ReadString16(); + if (procName.empty()) { + HILOGW("SystemAbilityManagerStub::AddSystemProcessInner read process name failed!"); + return ERR_NULL_OBJECT; } - std::u16string sysCap = data.ReadString16(); - if (!reply.WriteBool(HasSystemCapability(Str16ToStr8(sysCap)))) { - HILOGW("SystemAbilityManagerStub::HasSystemCapabilityInner write reply failed!"); - return ERR_FLATTEN_OBJECT; + sptr procObject = data.ReadRemoteObject(); + if (procObject == nullptr) { + HILOGW("SystemAbilityManagerStub::AddSystemProcessInner readParcelable failed!"); + return ERR_NULL_OBJECT; } - return ERR_NONE; -} - -int32_t SystemAbilityManagerStub::GetSystemAvailableCapabilitiesInner(MessageParcel& data, MessageParcel& reply) -{ - if (!CanRequest()) { - HILOGE("SystemAbilityManagerStub::GetSystemAvailableCapabilitiesInner PERMISSION DENIED!"); - return ERR_PERMISSION_DENIED; - } - std::vector sysCaps = GetSystemAvailableCapabilities(); - std::vector u16SysCaps; - for (const std::string& sysCap : sysCaps) { - u16SysCaps.emplace_back(Str8ToStr16(sysCap)); - } - if (!reply.WriteString16Vector(u16SysCaps)) { - HILOGW("SystemAbilityManagerStub::GetSystemAvailableCapabilitiesInner write reply failed!"); + int32_t result = AddSystemProcess(procName, procObject); + HILOGI("SystemAbilityManagerStub::AddSystemProcessInner result is %{public}d", result); + bool ret = reply.WriteInt32(result); + if (!ret) { + HILOGW("SystemAbilityManagerStub::AddSystemProcessInner write reply failed."); return ERR_FLATTEN_OBJECT; } - - return ERR_NONE; + return result; } int32_t SystemAbilityManagerStub::GetHapIdMultiuser(int32_t uid) diff --git a/services/samgr/native/source/system_ability_status_change_proxy.cpp b/services/samgr/native/source/system_ability_status_change_proxy.cpp new file mode 100755 index 0000000000000000000000000000000000000000..2816a8390dcd7f0d008ae70507cc892e3b3beba5 --- /dev/null +++ b/services/samgr/native/source/system_ability_status_change_proxy.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021 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 "system_ability_status_change_proxy.h" + +#include "ipc_types.h" +#include "parcel.h" +#include "sam_log.h" + +namespace OHOS { +void SystemAbilityStatusChangeProxy::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +{ + bool ret = SendRequestInner(ON_ADD_SYSTEM_ABILITY, systemAbilityId, deviceId); + if (!ret) { + HILOGE("OnAddSystemAbility SendRequest failed!"); + } +} + +void SystemAbilityStatusChangeProxy::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +{ + bool ret = SendRequestInner(ON_REMOVE_SYSTEM_ABILITY, systemAbilityId, deviceId); + if (!ret) { + HILOGE("OnRemoveSystemAbility SendRequest failed!"); + } +} + +bool SystemAbilityStatusChangeProxy::SendRequestInner(uint32_t code, int32_t systemAbilityId, + const std::string& deviceId) +{ + if (systemAbilityId <= 0) { + HILOGE("SendRequestInner saId:%{public}d is invalid!", systemAbilityId); + return false; + } + + sptr iro = Remote(); + if (iro == nullptr) { + HILOGE("SendRequestInner Remote return null"); + return false; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + HILOGE("SendRequestInner interface token check failed"); + return false; + } + bool ret = data.WriteInt32(systemAbilityId); + if (!ret) { + HILOGE("SendRequestInner write saId failed!"); + return false; + } + ret = data.WriteString(deviceId); + if (!ret) { + HILOGE("SendRequestInner write deviceId failed!"); + return false; + } + + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + int32_t status = iro->SendRequest(code, data, reply, option); + if (status != NO_ERROR) { + HILOGE("SendRequestInner SendRequest failed, return value : %{public}d", status); + return false; + } + return true; +} +} diff --git a/services/samgr/native/source/utils.cpp b/services/samgr/native/source/utils.cpp deleted file mode 100644 index cae9273a12f17acdd2ec2db8e8c6ca0ef0049345..0000000000000000000000000000000000000000 --- a/services/samgr/native/source/utils.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2021 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 "utils.h" -#include -#include -#include "libxml/parser.h" -#include "nlohmann/json.hpp" -#include "sam_log.h" - -using namespace std; -namespace OHOS { -namespace { - const string XML_TAG_ROOT = "systemAbility"; - const string XML_TAG_NAME = "name"; - const string SYSTEM_CAP_KEY = "systemCapability"; - const string SYS_CAP_NAME = "name"; - const string REGISTER_ON_STARTUP = "register-on-startup"; - constexpr int32_t MAX_SYSCAP_SIZE = 512; - constexpr int32_t MAX_SYSCAP_NAME_LEN = 64; - template - inline bool CheckTagName(const T curNodePtr, const string& tagName) - { - if (curNodePtr == nullptr || curNodePtr->name == nullptr) { - return false; - } - return xmlStrcmp(curNodePtr->name, reinterpret_cast(tagName.c_str())) == 0; - } -} - -uint64_t Utils::StrToUint64(const string& str) -{ - istringstream buf(str); - uint64_t num = MAX_U64_VAL; - if ((buf >> num) && (buf.eof())) { - return num; - } - return MAX_U64_VAL; -} - -bool Utils::ParseCoreSaList(const string& saPath, set& saList) -{ - std::unique_ptr docPtr( - xmlReadFile(saPath.c_str(), nullptr, XML_PARSE_NOBLANKS), xmlFreeDoc); - if (docPtr == nullptr) { - HILOGE("Utils::coreSa::ParseCoreSaList xmlReadFile error!"); - return false; - } - xmlNodePtr rootNodePtr = xmlDocGetRootElement(docPtr.get()); - if ((rootNodePtr == nullptr) || (!CheckTagName(rootNodePtr, XML_TAG_ROOT))) { - HILOGW("Utils::coreSa::ParseCoreSaList root element tag wrong!"); - return false; - } - return ParseSystemAbility(*rootNodePtr, saList); -} - -bool Utils::ParseSystemAbility(const xmlNode& rootNode, set& saList) -{ - auto currNodePtr = rootNode.xmlChildrenNode; - if (currNodePtr == nullptr) { - return false; - } - for (; currNodePtr != nullptr; currNodePtr = currNodePtr->next) { - if (currNodePtr->name == nullptr || currNodePtr->type == XML_COMMENT_NODE) { - continue; - } - auto contentPtr = xmlNodeGetContent(currNodePtr); - if (contentPtr == nullptr) { - continue; - } - std::string nodeName(reinterpret_cast(currNodePtr->name)); - std::string nodeContent(reinterpret_cast(contentPtr)); - HILOGI("Utils::coreSa::ParseSystemAbility nodeName:%{public}s nodeContent:%{public}s", - nodeName.c_str(), nodeContent.c_str()); - if (nodeName == XML_TAG_NAME) { - int32_t systemAbilityId = atoi(nodeContent.c_str()); - saList.emplace(systemAbilityId); - } - xmlFree(contentPtr); - } - return true; -} - -bool Utils::ParseSysCapMap(const string& sysCapPath, map& sysCapMap) -{ - ifstream sysCapStream(sysCapPath.c_str()); - if (!sysCapStream.good()) { - HILOGI("ParseSysCapMap ifstream bad!"); - return false; - } - auto json = nlohmann::json::parse(sysCapStream, nullptr, false); - if (json.is_discarded()) { - HILOGW("Utils::ParseSysCapMap sysCapStream exception"); - return false; - } - if (json.find(SYSTEM_CAP_KEY) == json.end()) { - return false; - } - auto sysCap = json.at(SYSTEM_CAP_KEY); - if (!sysCap.is_array()) { - return false; - } - size_t sysCapSize = sysCap.size(); - int sysCapNum = 0; - for (size_t i = 0; i < sysCapSize; i++) { - if (sysCapNum >= MAX_SYSCAP_SIZE) { - HILOGE("ParseSysCapMap system capability exceed!"); - break; - } - if (!sysCap[i].is_object()) { - continue; - } - auto item = sysCap[i]; - if (item.find(SYS_CAP_NAME) == item.end() || item.find(REGISTER_ON_STARTUP) == item.end()) { - continue; - } - auto nameJson = item.at(SYS_CAP_NAME); - auto isRegJson = item.at(REGISTER_ON_STARTUP); - if (!nameJson.is_string() || !isRegJson.is_boolean()) { - continue; - } - auto name = nameJson.get(); - if (name.empty() || name.length() > MAX_SYSCAP_NAME_LEN) { - HILOGW("ParseSysCapMap system capability invalid"); - continue; - } - auto isRegister = isRegJson.get(); - if (sysCapMap.count(name) != 0) { - HILOGW("ParseSysCapMap duplicate system capability %s", name.c_str()); - continue; - } - sysCapMap[name] = isRegister; - sysCapNum++; - } - return true; -} -} // namespace OHOS \ No newline at end of file diff --git a/services/samgr/native/test/unittest/BUILD.gn b/services/samgr/native/test/unittest/BUILD.gn old mode 100644 new mode 100755 index a22d9098b5449cd031a0b3173a17ae20d6d27eee..359ab6dc0d08afec1d84b0d22bbb97ce2add7482 --- a/services/samgr/native/test/unittest/BUILD.gn +++ b/services/samgr/native/test/unittest/BUILD.gn @@ -26,7 +26,13 @@ ohos_unittest("SystemAbilityMgrTest") { module_out_path = module_output_path sources = [ + "${samgr_dir}/utils/native/source/tools.cpp", + "${samgr_services_dir}/source/ability_death_recipient.cpp", + "${samgr_services_dir}/source/system_ability_manager.cpp", + "${samgr_services_dir}/source/system_ability_manager_stub.cpp", + "${samgr_services_dir}/source/system_ability_status_change_proxy.cpp", "${samgr_services_dir}/test/unittest/src/itest_transaction_service.cpp", + "${samgr_services_dir}/test/unittest/src/sa_status_change_mock.cpp", "${samgr_services_dir}/test/unittest/src/system_ability_mgr_test.cpp", ] @@ -44,13 +50,16 @@ ohos_unittest("SystemAbilityMgrTest") { deps = [ "${samgr_dir}/interfaces/innerkits/lsamgr:lsamgr", "${samgr_dir}/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] external_deps = [ + "appexecfwk_standard:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "ipc:libdbinder", ] } diff --git a/services/samgr/native/test/unittest/include/itest_transaction_service.h b/services/samgr/native/test/unittest/include/itest_transaction_service.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/samgr_proxy/include/system_ability_info.h b/services/samgr/native/test/unittest/include/sa_status_change_mock.h old mode 100644 new mode 100755 similarity index 50% rename from interfaces/innerkits/samgr_proxy/include/system_ability_info.h rename to services/samgr/native/test/unittest/include/sa_status_change_mock.h index 8d77862a4bd5c5c4f15891b6fd0647426024c2f8..9383a7b4c9711546be974bdff433b80ca112d8f5 --- a/interfaces/innerkits/samgr_proxy/include/system_ability_info.h +++ b/services/samgr/native/test/unittest/include/sa_status_change_mock.h @@ -11,23 +11,17 @@ * 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 INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_INFO_H_ -#define INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_INFO_H_ - -#include - -#include "parcel.h" - -namespace OHOS { -struct SystemAbilityInfo : public Parcelable { - int32_t systemAbilityId = 0; // id of this system ability - std::string deviceId; // deviceId of this system ability - - bool ReadFromParcel(Parcel& parcel); - virtual bool Marshalling(Parcel& parcel) const override; - static SystemAbilityInfo* Unmarshalling(Parcel& parcel); -}; -} // namespace OHOS -#endif // INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_INFO_H_ + */ + +#ifndef SAMGR_SERVICES_SAMGR_NATIVE_TEST_UNITTEST_INCLUDE_SA_STATUS_CHANGE_MOCK_H +#define SAMGR_SERVICES_SAMGR_NATIVE_TEST_UNITTEST_INCLUDE_SA_STATUS_CHANGE_MOCK_H + +#include "system_ability_status_change_stub.h" +namespace OHOS { +class SaStatusChangeMock : public SystemAbilityStatusChangeStub { +public: + void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; + void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; +}; +} +#endif /* SAMGR_SERVICES_SAMGR_NATIVE_TEST_UNITTEST_INCLUDE_SA_STATUS_CHANGE_MOCK_H */ diff --git a/services/samgr/native/test/unittest/include/system_ability_mgr_test.h b/services/samgr/native/test/unittest/include/system_ability_mgr_test.h old mode 100644 new mode 100755 diff --git a/services/samgr/native/test/unittest/include/test_log.h b/services/samgr/native/test/unittest/include/test_log.h old mode 100644 new mode 100755 diff --git a/services/samgr/native/test/unittest/src/itest_transaction_service.cpp b/services/samgr/native/test/unittest/src/itest_transaction_service.cpp old mode 100644 new mode 100755 diff --git a/frameworks/native/source/if_system_ability_manager.cpp b/services/samgr/native/test/unittest/src/sa_status_change_mock.cpp similarity index 58% rename from frameworks/native/source/if_system_ability_manager.cpp rename to services/samgr/native/test/unittest/src/sa_status_change_mock.cpp index 17b0464f70df4335f403bf2cfd36ec9a04564b17..bd2b678b2ffcc0c5c5c69fe8e763246d5d7c117c 100755 --- a/frameworks/native/source/if_system_ability_manager.cpp +++ b/services/samgr/native/test/unittest/src/sa_status_change_mock.cpp @@ -13,5 +13,18 @@ * limitations under the License. */ +#include "sa_status_change_mock.h" + +#include "sam_log.h" + namespace OHOS { -} // namespace OHOS +void SaStatusChangeMock::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +{ + HILOGI("OnAddSystemAbility systemAbilityId:%{public}d added!", systemAbilityId); +} + +void SaStatusChangeMock::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +{ + HILOGI("OnRemoveSystemAbility systemAbilityId:%{public}d removed!", systemAbilityId); +} +} diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp old mode 100644 new mode 100755 index 7b2b92f50ff506e0c791093bfb826e53e24a7d81..ea5b88a7070798f5b1dc8b223054c8a88fee3954 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp @@ -16,14 +16,19 @@ #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "itest_transaction_service.h" +#include "sa_status_change_mock.h" #include "string_ex.h" #include "system_ability_definition.h" #include "system_ability_mgr_test.h" #include "test_log.h" +#define private public +#include "system_ability_manager.h" + using namespace std; using namespace testing; using namespace testing::ext; +using namespace OHOS; namespace OHOS { namespace { @@ -32,6 +37,7 @@ constexpr int32_t TEST_REVERSE_VALUE = 1202; constexpr int32_t REPEAT = 10; constexpr int32_t TEST_EXCEPTION_HIGH_SA_ID = LAST_SYS_ABILITY_ID + 1; constexpr int32_t TEST_EXCEPTION_LOW_SA_ID = FIRST_SYS_ABILITY_ID - 1; +const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken"; } void SystemAbilityMgrTest::SetUpTestCase() { @@ -53,12 +59,11 @@ void SystemAbilityMgrTest::TearDown() DTEST_LOG << "TearDown" << std::endl; } -/* - * Feature: SAMGR - * Function: AddSystemAbility - * SubFunction: AddSystemAbility - * FunctionPoints: add system ability, input invalid parameter - * CaseDescription: test AddSystemAbility interface +/** + * @tc.name: AddSystemAbility001 + * @tc.desc: add system ability, input invalid parameter + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility001, TestSize.Level1) { @@ -69,12 +74,11 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility001, TestSize.Level1) EXPECT_TRUE(result != ERR_OK); } -/* - * Feature: SAMGR - * Function: AddSystemAbility - * SubFunction: AddSystemAbility - * FunctionPoints: add system ability - * CaseDescription: test AddSystemAbility interface +/** + * @tc.name: AddSystemAbility002 + * @tc.desc: add system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility002, TestSize.Level1) { @@ -87,12 +91,11 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility002, TestSize.Level1) sm->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); } -/* - * Feature: SAMGR - * Function: AddSystemAbility - * SubFunction: AddSystemAbility - * FunctionPoints: add system ability saId exception - * CaseDescription: test AddSystemAbility interface +/** + * @tc.name: AddSystemAbility003 + * @tc.desc: add system ability saId exception. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility003, TestSize.Level1) { @@ -107,32 +110,29 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility003, TestSize.Level1) sm->RemoveSystemAbility(TEST_EXCEPTION_LOW_SA_ID); } -/* - * Feature: SAMGR - * Function: AddSystemAbility - * SubFunction: AddSystemAbility - * FunctionPoints: add system ability with illegal capability - * CaseDescription: test AddSystemAbility interface +/** + * @tc.name: AddSystemAbility004 + * @tc.desc: add system ability with empty capability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility004, TestSize.Level1) { int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); EXPECT_TRUE(sm != nullptr); - std::u16string capability = u"illegal capability"; ISystemAbilityManager::SAExtraProp saExtraProp(false, ISystemAbilityManager::DUMP_FLAG_PRIORITY_DEFAULT, - capability, u""); + u"", u""); int32_t ret = sm->AddSystemAbility(systemAbilityId, new TestTransactionService(), saExtraProp); - EXPECT_TRUE(ret != ERR_OK); + EXPECT_EQ(ret, ERR_OK); sm->RemoveSystemAbility(systemAbilityId); } -/* - * Feature: SAMGR - * Function: AddSystemAbility - * SubFunction: AddSystemAbility - * FunctionPoints: add system ability with validated capability - * CaseDescription: test AddSystemAbility interface +/** + * @tc.name: AddSystemAbility005 + * @tc.desc: add system ability with validated capability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility005, TestSize.Level1) { @@ -148,12 +148,11 @@ HWTEST_F(SystemAbilityMgrTest, AddSystemAbility005, TestSize.Level1) sm->RemoveSystemAbility(systemAbilityId); } -/* - * Feature: SAMGR - * Function: RemoveSystemAbility - * SubFunction: RemoveSystemAbility - * FunctionPoints: remove not exist system ability - * CaseDescription: test RemoveSystemAbility interface +/** + * @tc.name: RemoveSystemAbility001 + * @tc.desc: remove not exist system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility001, TestSize.Level1) { @@ -163,12 +162,11 @@ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility001, TestSize.Level1) EXPECT_TRUE(result != ERR_OK); } -/* - * Feature: SAMGR - * Function: RemoveSystemAbility - * SubFunction: RemoveSystemAbility - * FunctionPoints: remove system ability - * CaseDescription: test RemoveSystemAbility interface +/** + * @tc.name: RemoveSystemAbility002 + * @tc.desc: remove system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility002, TestSize.Level1) { @@ -180,12 +178,11 @@ HWTEST_F(SystemAbilityMgrTest, RemoveSystemAbility002, TestSize.Level1) EXPECT_EQ(result, ERR_OK); } -/* - * Feature: SAMGR - * Function: GetSystemAbility - * SubFunction: GetSystemAbility - * FunctionPoints: get not exist system ability - * CaseDescription: test GetSystemAbility interface +/** + * @tc.name: GetSystemAbility001 + * @tc.desc: get not exist system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility001, TestSize.Level1) { @@ -195,12 +192,11 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility001, TestSize.Level1) EXPECT_EQ(ability, nullptr); } -/* - * Feature: SAMGR - * Function: GetSystemAbility - * SubFunction: GetSystemAbility - * FunctionPoints: get system ability - * CaseDescription: test GetSystemAbility interface +/** + * @tc.name: GetSystemAbility002 + * @tc.desc: get system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility002, TestSize.Level1) { @@ -213,12 +209,11 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility002, TestSize.Level1) sm->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); } -/* - * Feature: SAMGR - * Function: GetSystemAbility - * SubFunction: GetSystemAbility - * FunctionPoints: get system ability and then transaction - * CaseDescription: test GetSystemAbility interface +/** + * @tc.name: GetSystemAbility003 + * @tc.desc: get system ability and then transaction. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility003, TestSize.Level1) { @@ -237,12 +232,11 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility003, TestSize.Level1) sm->RemoveSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID); } -/* - * Feature: SAMGR - * Function: GetSystemAbility - * SubFunction: GetSystemAbility - * FunctionPoints: get system ability - * CaseDescription: test GetSystemAbility interface +/** + * @tc.name: GetSystemAbility004 + * @tc.desc: get system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility004, TestSize.Level2) { @@ -260,12 +254,11 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility004, TestSize.Level2) } } -/* - * Feature: SAMGR - * Function: GetSystemAbility - * SubFunction: GetSystemAbility - * FunctionPoints: get remote device system ability - * CaseDescription: test GetSystemAbility interface +/** + * @tc.name: GetSystemAbility005 + * @tc.desc: get remote device system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility005, TestSize.Level2) { @@ -274,61 +267,13 @@ HWTEST_F(SystemAbilityMgrTest, GetSystemAbility005, TestSize.Level2) string fakeDeviceId = "fake_dev"; auto abilityObj = sm->GetSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, fakeDeviceId); EXPECT_EQ(abilityObj, nullptr); - sm->SubscribeSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, u"test.listener.service"); - sm->UnSubscribeSystemAbility(DISTRIBUTED_SCHED_TEST_TT_ID, u"test.listener.service"); - sm->CheckLocalAbilityManager(u"test2.service"); -} - -/* - * Feature: SAMGR - * Function: GetSystemAbilityInfoList - * SubFunction: GetSystemAbilityInfoList - * FunctionPoints: get system ability info list - * CaseDescription: test GetSystemAbilityInfoList interface with invalid capability - */ -HWTEST_F(SystemAbilityMgrTest, GetSystemAbilityInfoList001, TestSize.Level1) -{ - int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; - sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - EXPECT_TRUE(sm != nullptr); - std::u16string capability = u" "; - std::list> saInfoList; - bool ret = sm->GetSystemAbilityInfoList(systemAbilityId, capability, saInfoList); - EXPECT_FALSE(ret); - capability = u"illegal capability"; - ret = sm->GetSystemAbilityInfoList(systemAbilityId, capability, saInfoList); - EXPECT_FALSE(ret); -} - -/* - * Feature: SAMGR - * Function: SystemAbilityInfo - * SubFunction: SystemAbilityInfo - * FunctionPoints: SystemAbilityInfo parcel read and write - * CaseDescription: test SystemAbilityInfo parcel read and write - */ -HWTEST_F(SystemAbilityMgrTest, SystemAbilityInfo001, TestSize.Level1) -{ - unique_ptr saInfoIn = make_unique(); - saInfoIn->systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; - saInfoIn->deviceId = "deviceId"; - MessageParcel in; - bool ret = saInfoIn->Marshalling(in); - EXPECT_TRUE(ret); - unique_ptr spSaInfoOut(SystemAbilityInfo::Unmarshalling(in)); - if (spSaInfoOut == nullptr) { - return; - } - EXPECT_EQ(spSaInfoOut->systemAbilityId, DISTRIBUTED_SCHED_TEST_TT_ID); - EXPECT_EQ(spSaInfoOut->deviceId, "deviceId"); } -/* - * Feature: SAMGR - * Function: CheckSystemAbility - * SubFunction: CheckSystemAbility - * FunctionPoints: check system ability - * CaseDescription: test CheckSystemAbility interface +/** + * @tc.name: CheckSystemAbility001 + * @tc.desc: check system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility001, TestSize.Level1) { @@ -342,12 +287,11 @@ HWTEST_F(SystemAbilityMgrTest, CheckSystemAbility001, TestSize.Level1) sm->RemoveSystemAbility(systemAbilityId); } -/* - * Feature: SAMGR - * Function: CheckOnDemandSystemAbility - * SubFunction: CheckOnDemandSystemAbility - * FunctionPoints: check on demand system ability - * CaseDescription: test AddOnDemandSystemAbilityInfo and CheckOnDemandSystemAbility interface +/** + * @tc.name: CheckOnDemandSystemAbility001 + * @tc.desc: check on demand system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, CheckOnDemandSystemAbility001, TestSize.Level1) { @@ -357,17 +301,14 @@ HWTEST_F(SystemAbilityMgrTest, CheckOnDemandSystemAbility001, TestSize.Level1) sm->AddSystemAbility(systemAbilityId, new TestTransactionService()); int32_t ret = sm->AddOnDemandSystemAbilityInfo(systemAbilityId, u"test_localmanagername"); EXPECT_EQ(ret, ERR_OK); - std::u16string localAbilityName = sm->CheckOnDemandSystemAbility(systemAbilityId); - EXPECT_TRUE(!localAbilityName.empty()); sm->RemoveSystemAbility(systemAbilityId); } -/* - * Feature: SAMGR - * Function: CheckOnDemandSystemAbility - * SubFunction: CheckOnDemandSystemAbility - * FunctionPoints: check on demand system ability - * CaseDescription: test AddOnDemandSystemAbilityInfo and CheckOnDemandSystemAbility interface +/** + * @tc.name: CheckOnDemandSystemAbility002 + * @tc.desc: check on demand system ability. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, CheckOnDemandSystemAbility002, TestSize.Level1) { @@ -380,17 +321,14 @@ HWTEST_F(SystemAbilityMgrTest, CheckOnDemandSystemAbility002, TestSize.Level1) sptr saObject = sm->CheckSystemAbility(systemAbilityId); result = sm->AddOnDemandSystemAbilityInfo(systemAbilityId, u"just_test"); EXPECT_EQ(result, ERR_OK); - auto localAbilityManager = sm->CheckOnDemandSystemAbility(systemAbilityId); - EXPECT_TRUE(!localAbilityManager.empty()); sm->RemoveSystemAbility(systemAbilityId); } -/* - * Feature: SAMGR - * Function: ListSystemAbility - * SubFunction: ListSystemAbility - * FunctionPoints: list all system abilities - * CaseDescription: test ListSystemAbility interface +/** + * @tc.name: ListSystemAbility001 + * @tc.desc: list all system abilities. + * @tc.type: FUNC + * @tc.require: AR000GGVR6 */ HWTEST_F(SystemAbilityMgrTest, ListSystemAbility001, TestSize.Level1) { @@ -404,39 +342,4 @@ HWTEST_F(SystemAbilityMgrTest, ListSystemAbility001, TestSize.Level1) EXPECT_TRUE(iter != saList.end()); sm->RemoveSystemAbility(systemAbilityId); } - -/* - * Feature: SAMGR - * Function: GetLocalAbilityManager - * SubFunction: GetLocalAbilityManager - * FunctionPoints: get local ability manager - * CaseDescription: test GetLocalAbilityManager interface - */ -HWTEST_F(SystemAbilityMgrTest, GetLocalAbilityManager001, TestSize.Level1) -{ - sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - EXPECT_TRUE(sm != nullptr); - u16string locAblilityName(u"123"); - sptr localAbilityMgr = sm->CheckLocalAbilityManager(locAblilityName); - EXPECT_TRUE(localAbilityMgr == nullptr); - sm->RemoveLocalAbilityManager(locAblilityName); -} - -/* - * Feature: SAMGR - * Function: ConnectSystemAbility - * SubFunction: ConnectSystemAbility - * FunctionPoints: connect system ability - * CaseDescription: test ConnectSystemAbility interface - */ -HWTEST_F(SystemAbilityMgrTest, ConnectSystemAbility001, TestSize.Level1) -{ - int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; - sptr sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - EXPECT_TRUE(sm != nullptr); - auto result = sm->ConnectSystemAbility(systemAbilityId, nullptr); - EXPECT_TRUE(result != ERR_OK); - result = sm->DisConnectSystemAbility(systemAbilityId, nullptr); - EXPECT_TRUE(result != ERR_OK); -} } // namespace OHOS