1 Star 0 Fork 283

XiYuhao / distributedschedule_samgr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 4.30 KB
一键复制 编辑 原始数据 按行查看 历史
majiajun 提交于 2021-10-24 23:13 . update samgr doc

samgr

Introduction

The samgr module is a core module of OpenHarmony. It provides functions related to system abilities (also called system services), including system ability (SA) startup, registration, and query.

Directory Structure

/foundation/distributedschedule/samgr/services/samgr/
├── native             
│   ├── BUILD.gn  # Compilation script
│   ├── include   # Header files
│   ├── samgr.rc  # RC file for starting samgr
│   ├── source    # Source code
│   ├── test      # Test code

Usage

  1. After receiving the registration message from the SA framework, the samgr service saves information about the particular SA in the local cache.

    int32_t SystemAbilityManager::AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability,
        const SAExtraProp& extraProp)
    {
        if (!CheckInputSysAbilityId(systemAbilityId) || ability == nullptr || (!CheckCapability(extraProp.capability))) {
            HILOGE("AddSystemAbilityExtra input params is invalid.");
            return ERR_INVALID_VALUE;
        }
        {
            unique_lock<shared_mutex> writeLock(abilityMapLock_);
            auto saSize = abilityMap_.size();
            if (saSize >= MAX_SERVICES) {
                HILOGE("map size error, (Has been greater than %zu)", saSize);
                return ERR_INVALID_VALUE;
            }
            SAInfo saInfo;
            saInfo.remoteObj = ability;
            saInfo.isDistributed = extraProp.isDistributed;
            saInfo.capability = extraProp.capability;
            saInfo.permission = Str16ToStr8(extraProp.permission);
            abilityMap_[systemAbilityId] = std::move(saInfo);
            HILOGI("insert %{public}d. size : %zu,", systemAbilityId, abilityMap_.size());
        }
        if (abilityDeath_ != nullptr) {
            ability->AddDeathRecipient(abilityDeath_);
        }
        FindSystemAbilityManagerNotify(systemAbilityId, ADD_SYSTEM_ABILITY_TRANSACTION);
        u16string strName = Str8ToStr16(to_string(systemAbilityId));
        if (extraProp.isDistributed && dBinderService_ != nullptr) {
            dBinderService_->RegisterRemoteProxy(strName, ability);
            HILOGD("AddSystemAbility RegisterRemoteProxy, serviceId is %{public}d", systemAbilityId);
        }
        if (systemAbilityDataStorage_ == nullptr) {
            HILOGE("AddSystemAbility systemAbilityDataStorage not init!");
            return ERR_NO_INIT;
        }
        if (extraProp.isDistributed) {
            systemAbilityDataStorage_->ClearSyncRecords();
            DoInsertSaData(strName, ability, extraProp);
        }
    }
  2. If the SA requested by the SA framework is a local SA, the samgr service searches for the proxy object of the SA based on the SA ID and then returns the proxy object to the SA framework.

    sptr<IRemoteObject> SystemAbilityManager::CheckSystemAbility(int32_t systemAbilityId)
    {
        if (!CheckInputSysAbilityId(systemAbilityId)) {
            return nullptr;
        }
    
        std::string selectedDeviceId;
        if (CheckRemoteSa(to_string(systemAbilityId), selectedDeviceId)) {
           return CheckSystemAbility(systemAbilityId, selectedDeviceId);
        }
    
        shared_lock<shared_mutex> readLock(abilityMapLock_);
        auto iter = abilityMap_.find(systemAbilityId);
        if (iter != abilityMap_.end()) {
            auto callingUid = IPCSkeleton::GetCallingUid();
            if (IsSystemApp(callingUid) || CheckPermission(iter->second.permission)) {
                 return iter->second.remoteObj;
            }
            return nullptr;
        }
        return nullptr;
    }

Repositories Involved

Distributed Scheduler subsystem

distributedschedule_dms_fwk

distributedschedule_safwk

distributedschedule_samgr

distributedschedule_safwk_lite

hdistributedschedule_samgr_lite

distributedschedule_dms_fwk_lite

1
https://gitee.com/Xi_Yuhao/distributedschedule_samgr.git
git@gitee.com:Xi_Yuhao/distributedschedule_samgr.git
Xi_Yuhao
distributedschedule_samgr
distributedschedule_samgr
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891