1 /*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 // #define LOG_NDEBUG 0
18 #define LOG_TAG "VirtualCameraPermissions"
19
20 #include "Permissions.h"
21
22 #include "binder/PermissionCache.h"
23 #include "log/log_main.h"
24
25 namespace android {
26 namespace companion {
27 namespace virtualcamera {
28 namespace {
29
30 class PermissionsProxyImpl : public PermissionsProxy {
31 public:
32 bool checkCallingPermission(const std::string& permission) const override;
33 };
34
checkCallingPermission(const std::string & permission) const35 bool PermissionsProxyImpl::checkCallingPermission(
36 const std::string& permission) const {
37 int32_t uid;
38 int32_t pid;
39 const bool hasPermission = PermissionCache::checkCallingPermission(
40 String16(permission.c_str()), &pid, &uid);
41
42 if (hasPermission) {
43 ALOGV("%s: Checking %s permission for pid %d uid %d: granted", __func__,
44 permission.c_str(), pid, uid);
45 } else {
46 ALOGW("%s: Checking %s permission for pid %d uid %d: denied", __func__,
47 permission.c_str(), pid, uid);
48 }
49
50 return hasPermission;
51 }
52 } // namespace
53
get()54 const PermissionsProxy& PermissionsProxy::get() {
55 static PermissionsProxyImpl sPermissionProxyImpl;
56 return sPermissionProxyImpl;
57 }
58
59 } // namespace virtualcamera
60 } // namespace companion
61 } // namespace android
62