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