• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "resource_info.h"
17 
18 #include "nlohmann/json.hpp"
19 #include "json_util.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 namespace {
24 const std::string SEPARATOR = "/";
25 }
26 
ResourceInfo()27 ResourceInfo::ResourceInfo()
28 {}
29 
~ResourceInfo()30 ResourceInfo::~ResourceInfo()
31 {}
32 
GetKey() const33 std::string ResourceInfo::GetKey() const
34 {
35     std::string key = bundleName_;
36     /**
37     * if moduleName and abilityName both empty, it represents bundle resource,
38     * otherwise it represents launcher ability resource.
39     */
40     key = moduleName_.empty() ? key : (key + SEPARATOR + moduleName_);
41     key = abilityName_.empty() ? key : (key + SEPARATOR + abilityName_);
42     return key;
43 }
44 
ParseKey(const std::string & key)45 void ResourceInfo::ParseKey(const std::string &key)
46 {
47     auto firstPos = key.find_first_of(SEPARATOR);
48     if (firstPos == std::string::npos) {
49         bundleName_ = key;
50         moduleName_ = std::string();
51         abilityName_ = std::string();
52         return;
53     }
54     bundleName_ = key.substr(0, firstPos);
55     auto lastPos = key.find_last_of(SEPARATOR);
56     abilityName_ = key.substr(lastPos + 1);
57     if (firstPos != lastPos) {
58         moduleName_ = key.substr(firstPos + 1, lastPos - firstPos - 1);
59         return;
60     }
61     moduleName_ = std::string();
62 }
63 } // AppExecFwk
64 } // OHOS
65