1 /* 2 * Copyright (c) 2024 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 #ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_SKILL_H 17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_SKILL_H 18 19 #include <string> 20 21 #include "parcel.h" 22 #include "application_info.h" 23 #include "nlohmann/json.hpp" 24 #include "want.h" 25 26 namespace OHOS { 27 namespace AppExecFwk { 28 29 struct SkillUri { 30 int32_t maxFileSupported = 0; 31 std::string scheme; 32 std::string host; 33 std::string port; 34 std::string path; 35 std::string pathStartWith; 36 std::string pathRegex; 37 std::string type; 38 std::string utd; 39 std::string linkFeature; 40 }; 41 42 struct Skill : public Parcelable { 43 public: 44 bool domainVerify = false; 45 std::vector<std::string> actions; 46 std::vector<std::string> entities; 47 std::vector<SkillUri> uris; 48 std::vector<std::string> permissions; 49 static std::string GetOptParamUri(const std::string &uriString); 50 bool Match(const OHOS::AAFwk::Want &want) const; 51 bool Match(const OHOS::AAFwk::Want &want, size_t &matchUriIndex) const; 52 bool MatchLauncher(const OHOS::AAFwk::Want &want) const; 53 bool MatchType(const std::string &type, const std::string &skillUriType) const; 54 bool ReadFromParcel(Parcel &parcel); 55 virtual bool Marshalling(Parcel &parcel) const override; 56 static Skill *Unmarshalling(Parcel &parcel); 57 void Dump(std::string prefix, int fd); 58 void from_json(const nlohmann::json &jsonObject, SkillUri &uri); 59 void from_json(const nlohmann::json &jsonObject, Skill &skill); 60 void to_json(nlohmann::json &jsonObject, const SkillUri &uri); 61 void to_json(nlohmann::json &jsonObject, const Skill &skill); 62 std::string ConvertToLower(const std::string &str) const; 63 std::string ConvertUriToLower(const std::string& uri) const; 64 private: 65 bool MatchAction(const std::string &action) const; 66 bool MatchEntities(const std::vector<std::string> ¶mEntities) const; 67 bool MatchUriAndType(const std::string &rawUriString, const std::string &type) const; 68 bool MatchUriAndType(const std::string &rawUriString, const std::string &type, size_t &matchUriIndex) const; 69 bool MatchUri(const std::string &uriString, const SkillUri &skillUri) const; 70 bool StartsWith(const std::string &sourceString, const std::string &targetPrefix) const; 71 bool MatchMimeType(const std::string &uriString) const; 72 bool MatchMimeType(const std::string &uriString, size_t &matchUriIndex) const; 73 bool MatchLinkFeature(const std::string &linkFeature, const OHOS::AAFwk::Want &want, size_t &matchUriIndex) const; 74 bool MatchUtd(const std::string ¶mType, const std::string &skillUriType, bool &containsUtd) const; 75 bool IsUtdMatch(const std::string ¶mUtd, const std::string &skillUtd) const; 76 bool IsUtd(const std::string ¶m) const; 77 }; 78 } // namespace AppExecFwk 79 } // namespace OHOS 80 #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_ABILITY_INFO_H 81