blob: 634bca3c60e3dd83b45a85efb241eaadaf3d5e62 [file] [log] [blame]
Jan Sebechlebskyde6f16f2023-11-29 09:27:36 +01001/*
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.h"
24
25namespace android {
26namespace companion {
27namespace virtualcamera {
28namespace {
29
30class PermissionsProxyImpl : public PermissionsProxy {
31 public:
32 bool checkCallingPermission(const std::string& permission) const override;
33};
34
35bool 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 ALOGV("%s: Checking %s permission for pid %d uid %d: %s", __func__,
43 permission.c_str(), pid, uid, hasPermission ? "granted" : "denied");
44 return hasPermission;
45}
46} // namespace
47
48const PermissionsProxy& PermissionsProxy::get() {
49 static PermissionsProxyImpl sPermissionProxyImpl;
50 return sPermissionProxyImpl;
51}
52
53} // namespace virtualcamera
54} // namespace companion
55} // namespace android