• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
16 #include "accessibility_permission.h"
17 #include <accesstoken_kit.h>
18 #include <ipc_skeleton.h>
19 #include "hilog_wrapper.h"
20 
21 namespace OHOS {
22 namespace Accessibility {
CheckCallingPermission(const std::string & permission)23 bool Permission::CheckCallingPermission(const std::string& permission)
24 {
25     HILOG_DEBUG("permission %{public}s", permission.c_str());
26     if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(IPCSkeleton::GetCallingTokenID(), permission) !=
27         Security::AccessToken::PermissionState::PERMISSION_GRANTED) {
28         HILOG_DEBUG("permission denied");
29         return false;
30     }
31 
32     HILOG_DEBUG("permission ok!");
33     return true;
34 }
35 
IsStartByHdcd()36 bool Permission::IsStartByHdcd()
37 {
38     auto id = IPCSkeleton::GetCallingTokenID();
39     Security::AccessToken::NativeTokenInfo info;
40     auto ret = Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(id, info);
41     if (ret != 0) {
42         HILOG_DEBUG("get native token info failed %{public}d", ret);
43         return false;
44     }
45 
46     if (info.processName.compare("hdcd") == 0) {
47         HILOG_DEBUG("process name is hdcd");
48         return true;
49     }
50 
51     return false;
52 }
53 } // namespace Accessibility
54 } // namespace OHOS