1a69a01cdSopenharmony_ci/*
2a69a01cdSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3a69a01cdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a69a01cdSopenharmony_ci * you may not use this file except in compliance with the License.
5a69a01cdSopenharmony_ci * You may obtain a copy of the License at
6a69a01cdSopenharmony_ci *
7a69a01cdSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a69a01cdSopenharmony_ci *
9a69a01cdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a69a01cdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a69a01cdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a69a01cdSopenharmony_ci * See the License for the specific language governing permissions and
13a69a01cdSopenharmony_ci * limitations under the License.
14a69a01cdSopenharmony_ci */
15a69a01cdSopenharmony_ci
16a69a01cdSopenharmony_ci#include "ability_tree.h"
17a69a01cdSopenharmony_ci
18a69a01cdSopenharmony_ci#include "ability_manager_client.h"
19a69a01cdSopenharmony_ci#include "wukong_define.h"
20a69a01cdSopenharmony_ci
21a69a01cdSopenharmony_cinamespace OHOS {
22a69a01cdSopenharmony_cinamespace WuKong {
23a69a01cdSopenharmony_cinamespace {
24a69a01cdSopenharmony_ciconst uint8_t ABILITY_BUNDLE_NAME_SIZE_POSION = 56;
25a69a01cdSopenharmony_ciconst uint8_t ABILITY_BUNDLE_NAME_POSION = 32;
26a69a01cdSopenharmony_ciconst uint8_t ABILITY_ABILITY_NAME_SIZE_POSION = 24;
27a69a01cdSopenharmony_ciconst uint8_t ABILITY_ABILITY_NAME_POSION = 0;
28a69a01cdSopenharmony_ci}  // namespace
29a69a01cdSopenharmony_ci
30a69a01cdSopenharmony_ci/**
31a69a01cdSopenharmony_ci * @brief Ability Node Id specification format
32a69a01cdSopenharmony_ci * @details
33a69a01cdSopenharmony_ci * |----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
34a69a01cdSopenharmony_ci * |BUN SIZ  |BUN STR                      |ABI SIZ  |ABI STR                      |
35a69a01cdSopenharmony_ci */
36a69a01cdSopenharmony_cibool AbilityTree::SetNodeId()
37a69a01cdSopenharmony_ci{
38a69a01cdSopenharmony_ci    auto amcPtr = AAFwk::AbilityManagerClient::GetInstance();
39a69a01cdSopenharmony_ci    if (amcPtr == nullptr) {
40a69a01cdSopenharmony_ci        ERROR_LOG("AbilityManagerClient is nullptr");
41a69a01cdSopenharmony_ci        return false;
42a69a01cdSopenharmony_ci    }
43a69a01cdSopenharmony_ci    auto elementName = amcPtr->GetTopAbility();
44a69a01cdSopenharmony_ci    if (elementName.GetBundleName().empty()) {
45a69a01cdSopenharmony_ci        ERROR_LOG("GetTopAbility GetBundleName is nullptr");
46a69a01cdSopenharmony_ci        return false;
47a69a01cdSopenharmony_ci    }
48a69a01cdSopenharmony_ci    const uint8_t nameCount = 3;
49a69a01cdSopenharmony_ci    // make bundle name value
50a69a01cdSopenharmony_ci    bundleName_ = elementName.GetBundleName();
51a69a01cdSopenharmony_ci    uint64_t nameSize = bundleName_.size();
52a69a01cdSopenharmony_ci    nodeId_ |= nameSize << ABILITY_BUNDLE_NAME_SIZE_POSION;
53a69a01cdSopenharmony_ci    nodeId_ |= GetSubName(bundleName_, nameCount) << ABILITY_BUNDLE_NAME_POSION;
54a69a01cdSopenharmony_ci
55a69a01cdSopenharmony_ci    // make ability name value
56a69a01cdSopenharmony_ci    abilityName_ = elementName.GetAbilityName();
57a69a01cdSopenharmony_ci    nameSize = abilityName_.size();
58a69a01cdSopenharmony_ci    nodeId_ |= nameSize << ABILITY_ABILITY_NAME_SIZE_POSION;
59a69a01cdSopenharmony_ci    nodeId_ |= GetSubName(abilityName_, nameCount) << ABILITY_ABILITY_NAME_POSION;
60a69a01cdSopenharmony_ci
61a69a01cdSopenharmony_ci    TRACK_LOG_STR("Ability Node ID: (0x%016llX)", nodeId_);
62a69a01cdSopenharmony_ci    return true;
63a69a01cdSopenharmony_ci}
64a69a01cdSopenharmony_ci}  // namespace WuKong
65a69a01cdSopenharmony_ci}  // namespace OHOS
66