1049e185fSopenharmony_ci/*
2049e185fSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3049e185fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4049e185fSopenharmony_ci * you may not use this file except in compliance with the License.
5049e185fSopenharmony_ci * You may obtain a copy of the License at
6049e185fSopenharmony_ci *
7049e185fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8049e185fSopenharmony_ci *
9049e185fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10049e185fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11049e185fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12049e185fSopenharmony_ci * See the License for the specific language governing permissions and
13049e185fSopenharmony_ci * limitations under the License.
14049e185fSopenharmony_ci */
15049e185fSopenharmony_ci#include <list>
16049e185fSopenharmony_ci#include <map>
17049e185fSopenharmony_ci
18049e185fSopenharmony_ci#include "accesstoken_kit.h"
19049e185fSopenharmony_ci#include "ipc_skeleton.h"
20049e185fSopenharmony_ci#include "media_log.h"
21049e185fSopenharmony_ci#include "media_permission.h"
22049e185fSopenharmony_ci
23049e185fSopenharmony_cinamespace {
24049e185fSopenharmony_ciconstexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "MediaPermission"};
25049e185fSopenharmony_ci};
26049e185fSopenharmony_ci
27049e185fSopenharmony_cinamespace OHOS {
28049e185fSopenharmony_cinamespace Media {
29049e185fSopenharmony_ciconst int32_t ROOT_UID = 0;
30049e185fSopenharmony_ci
31049e185fSopenharmony_ciint32_t MediaPermission::CheckMicPermission()
32049e185fSopenharmony_ci{
33049e185fSopenharmony_ci    auto callerUid = IPCSkeleton::GetCallingUid();
34049e185fSopenharmony_ci    if (callerUid == ROOT_UID) {
35049e185fSopenharmony_ci        MEDIA_LOGI("Root user. Permission Granted");
36049e185fSopenharmony_ci        return Security::AccessToken::PERMISSION_GRANTED;
37049e185fSopenharmony_ci    }
38049e185fSopenharmony_ci    Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID();
39049e185fSopenharmony_ci    return Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, "ohos.permission.MICROPHONE");
40049e185fSopenharmony_ci}
41049e185fSopenharmony_ci
42049e185fSopenharmony_ciint32_t MediaPermission::CheckNetWorkPermission(int32_t appUid, int32_t appPid, uint32_t appTokenId)
43049e185fSopenharmony_ci{
44049e185fSopenharmony_ci    if (appUid == ROOT_UID) {
45049e185fSopenharmony_ci        MEDIA_LOGI("Root user. Permission Granted");
46049e185fSopenharmony_ci        return Security::AccessToken::PERMISSION_GRANTED;
47049e185fSopenharmony_ci    }
48049e185fSopenharmony_ci    MEDIA_LOGD("enter and check appUid: %{public}d", appUid);
49049e185fSopenharmony_ci    Security::AccessToken::AccessTokenID tokenCaller = appTokenId;
50049e185fSopenharmony_ci    return Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, "ohos.permission.INTERNET");
51049e185fSopenharmony_ci}
52049e185fSopenharmony_ci
53049e185fSopenharmony_ciint32_t MediaPermission::CheckNetWorkPermission()
54049e185fSopenharmony_ci{
55049e185fSopenharmony_ci    auto callerUid = IPCSkeleton::GetCallingUid();
56049e185fSopenharmony_ci    if (callerUid == ROOT_UID) {
57049e185fSopenharmony_ci        MEDIA_LOGI("Root user. Permission Granted");
58049e185fSopenharmony_ci        return Security::AccessToken::PERMISSION_GRANTED;
59049e185fSopenharmony_ci    }
60049e185fSopenharmony_ci    Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID();
61049e185fSopenharmony_ci    return Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, "ohos.permission.INTERNET");
62049e185fSopenharmony_ci}
63049e185fSopenharmony_ci
64049e185fSopenharmony_ciint32_t MediaPermission::CheckReadMediaPermission()
65049e185fSopenharmony_ci{
66049e185fSopenharmony_ci    auto callerUid = IPCSkeleton::GetCallingUid();
67049e185fSopenharmony_ci    if (callerUid == ROOT_UID) {
68049e185fSopenharmony_ci        MEDIA_LOGI("Root user. Permission Granted");
69049e185fSopenharmony_ci        return Security::AccessToken::PERMISSION_GRANTED;
70049e185fSopenharmony_ci    }
71049e185fSopenharmony_ci    Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID();
72049e185fSopenharmony_ci    return Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, "ohos.permission.READ_MEDIA");
73049e185fSopenharmony_ci}
74049e185fSopenharmony_ci}
75049e185fSopenharmony_ci}