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 OHOS_ABILITY_RUNTIME_URI_UTILS_H 17 #define OHOS_ABILITY_RUNTIME_URI_UTILS_H 18 19 #include <string> 20 #include <vector> 21 22 #include "ability_record.h" 23 #include "nocopyable.h" 24 #include "uri.h" 25 #include "want.h" 26 27 namespace OHOS { 28 namespace AAFwk { 29 class UriUtils { 30 public: 31 static UriUtils &GetInstance(); 32 33 int32_t CheckNonImplicitShareFileUri(const Want &want, int32_t userId, uint32_t specifyTokenId); 34 35 std::vector<Uri> GetPermissionedUriList(const std::vector<std::string> &uriVec, 36 const std::vector<bool> &checkResults, Want &want); 37 38 bool GetUriListFromWant(Want &want, std::vector<std::string> &uriVec); 39 40 #ifdef SUPPORT_UPMS 41 bool IsGrantUriPermissionFlag(const Want &want); 42 #endif // SUPPORT_UPMS 43 44 bool IsServiceExtensionType(AppExecFwk::ExtensionAbilityType extensionAbilityType); 45 46 #ifdef SUPPORT_UPMS 47 void GrantDmsUriPermission(Want &want, uint32_t callerTokenId, std::string targetBundleName, int32_t appIndex); 48 49 void GrantUriPermissionForServiceExtension(const AbilityRequest &abilityRequest); 50 51 void GrantUriPermissionForUIOrServiceExtension(const AbilityRequest &abilityRequest); 52 53 void GrantUriPermission(Want &want, std::string targetBundleName, int32_t appIndex, 54 bool isSandboxApp, uint32_t callerTokenId, int32_t collaboratorType); 55 56 void CheckUriPermission(uint32_t callerTokenId, Want &want); 57 58 void GrantUriPermission(const std::vector<std::string> &uriVec, int32_t flag, 59 const std::string &targetBundleName, int32_t appIndex, uint32_t initiatorTokenId); 60 #endif // SUPPORT_UPMS 61 private: 62 UriUtils(); 63 ~UriUtils(); 64 65 #ifdef SUPPORT_UPMS 66 bool GrantShellUriPermission(const std::vector<std::string> &strUriVec, uint32_t flag, 67 const std::string &targetPkg, int32_t appIndex); 68 69 bool GrantUriPermissionInner(std::vector<std::string> uriVec, uint32_t callerTokenId, 70 const std::string &targetBundleName, int32_t appIndex, Want &want); 71 #endif // SUPPORT_UPMS 72 73 bool IsDmsCall(uint32_t fromTokenId); 74 75 bool IsSandboxApp(uint32_t tokenId); 76 77 std::vector<Uri> GetUriListFromWantDms(Want &want); 78 79 int32_t CheckNonImplicitShareFileUriInner(uint32_t callerTokenId, const std::string &targetBundleName, 80 int32_t userId); 81 82 bool IsSystemApplication(const std::string &bundleName, int32_t userId); 83 84 void PublishFileOpenEvent(const Want &want); 85 86 DISALLOW_COPY_AND_MOVE(UriUtils); 87 }; 88 } // namespace AAFwk 89 } // namespace OHOS 90 #endif // OHOS_ABILITY_RUNTIME_URI_UTILS_H