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 #ifndef RINGTONE_PERMISSION_UTILS_H 16 #define RINGTONE_PERMISSION_UTILS_H 17 18 #include "bundle_mgr_interface.h" 19 20 namespace OHOS { 21 namespace Media { 22 #define EXPORT __attribute__ ((visibility ("default"))) 23 const std::string PERM_WRITE_RINGTONE = "ohos.permission.WRITE_RINGTONE"; 24 25 class RingtonePermissionUtils { 26 public: 27 EXPORT static bool CheckCallerPermission(const std::string &permission); 28 EXPORT static bool CheckCallerPermission(const std::vector<std::string> &permsVec); 29 EXPORT static bool CheckHasPermission(const std::vector<std::string> &permsVec); 30 EXPORT static void GetClientBundle(const int uid, std::string &bundleName); 31 EXPORT static uint32_t GetTokenId(); 32 EXPORT static bool CheckIsSystemAppByUid(); 33 EXPORT static bool IsSystemApp(); 34 EXPORT static bool IsNativeSAApp(); 35 EXPORT static std::string GetPackageNameByBundleName(const std::string &bundleName); 36 37 private: 38 static sptr<AppExecFwk::IBundleMgr> GetSysBundleManager(); 39 __attribute__ ((visibility ("hidden"))) static sptr<AppExecFwk::IBundleMgr> bundleManager_; 40 __attribute__ ((visibility ("hidden"))) static std::mutex bundleManagerMutex_; 41 }; 42 } // namespace Media 43 } // namespace OHOS 44 #endif // RINGTONE_PERMISSION_UTILS_H 45