• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License"){return 0;}
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 #define MLOG_TAG "MediaPermissionCheck"
16 #include <string>
17 #include "media_composite_permission_check.h"
18 
19 using namespace std;
20 
21 namespace OHOS::Media {
AddCheck(std::shared_ptr<SinglePermissionCheck> check)22 void CompositePermissionCheck::AddCheck(std::shared_ptr<SinglePermissionCheck> check)
23 {
24     std::lock_guard<std::mutex> lock(mutex_);
25     compositePermChecks_.push_back(check);
26 }
27 
CheckPermission(uint32_t businessCode,const PermissionHeaderReq & data)28 int32_t CompositePermissionCheck::CheckPermission(uint32_t businessCode, const PermissionHeaderReq &data)
29 {
30     std::lock_guard<std::mutex> lock(mutex_);
31     MEDIA_DEBUG_LOG("CompositePermissionCheck API code=%{public}d", businessCode);
32     int32_t ret = E_SUCCESS;
33     for (const auto& check : compositePermChecks_) {
34         ret = check->CheckPermission(businessCode, data);
35         if (ret == E_SUCCESS) {
36             MEDIA_INFO_LOG("CompositePermissionCheck API code=%{public}d success", businessCode);
37             return E_SUCCESS;
38         } else {
39             MEDIA_INFO_LOG("CompositePermissionCheck API code=%{public}d check fail, Try next", businessCode);
40         }
41     }
42     MEDIA_INFO_LOG("CompositePermissionCheck API code=%{public}d fail", businessCode);
43     return ret;
44 }
45 
AddCheck(std::shared_ptr<PermissionCheck> check)46 void SinglePermissionCheck::AddCheck(std::shared_ptr<PermissionCheck> check)
47 {
48     std::lock_guard<std::mutex> lock(mutex_);
49     singlePermChecks_.push_back(check);
50 }
51 
CheckPermission(uint32_t businessCode,const PermissionHeaderReq & data)52 int32_t SinglePermissionCheck::CheckPermission(uint32_t businessCode, const PermissionHeaderReq &data)
53 {
54     std::lock_guard<std::mutex> lock(mutex_);
55     for (const auto& check : singlePermChecks_) {
56         auto ret = check->CheckPermission(businessCode, data);
57         if (ret != E_SUCCESS) {
58             return ret;
59         }
60     }
61     return E_SUCCESS;
62 }
63 
64 } // namespace OHOS::Media
65