1bae4d13cSopenharmony_ci/* 2bae4d13cSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3bae4d13cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bae4d13cSopenharmony_ci * you may not use this file except in compliance with the License. 5bae4d13cSopenharmony_ci * You may obtain a copy of the License at 6bae4d13cSopenharmony_ci * 7bae4d13cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bae4d13cSopenharmony_ci * 9bae4d13cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bae4d13cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bae4d13cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bae4d13cSopenharmony_ci * See the License for the specific language governing permissions and 13bae4d13cSopenharmony_ci * limitations under the License. 14bae4d13cSopenharmony_ci */ 15bae4d13cSopenharmony_ci 16bae4d13cSopenharmony_ci#ifndef PERMISSION_UTIL_H 17bae4d13cSopenharmony_ci#define PERMISSION_UTIL_H 18bae4d13cSopenharmony_ci 19bae4d13cSopenharmony_ci#include <string> 20bae4d13cSopenharmony_ci#include <unordered_map> 21bae4d13cSopenharmony_ci 22bae4d13cSopenharmony_ci#include "access_token.h" 23bae4d13cSopenharmony_ci#include "singleton.h" 24bae4d13cSopenharmony_ci 25bae4d13cSopenharmony_cinamespace OHOS { 26bae4d13cSopenharmony_cinamespace Sensors { 27bae4d13cSopenharmony_ciconst std::string ACCELEROMETER_PERMISSION = "ohos.permission.ACCELEROMETER"; 28bae4d13cSopenharmony_ciconst std::string GYROSCOPE_PERMISSION = "ohos.permission.GYROSCOPE"; 29bae4d13cSopenharmony_ciconst std::string ACTIVITY_MOTION_PERMISSION = "ohos.permission.ACTIVITY_MOTION"; 30bae4d13cSopenharmony_ciconst std::string READ_HEALTH_DATA_PERMISSION = "ohos.permission.READ_HEALTH_DATA"; 31bae4d13cSopenharmony_ciconst std::string MANAGE_SENSOR_PERMISSION = "ohos.permission.MANAGE_SENSOR"; 32bae4d13cSopenharmony_ci 33bae4d13cSopenharmony_ciusing namespace Security::AccessToken; 34bae4d13cSopenharmony_ciclass PermissionUtil : public Singleton<PermissionUtil> { 35bae4d13cSopenharmony_cipublic: 36bae4d13cSopenharmony_ci PermissionUtil() = default; 37bae4d13cSopenharmony_ci virtual ~PermissionUtil() {}; 38bae4d13cSopenharmony_ci int32_t CheckSensorPermission(AccessTokenID callerToken, int32_t sensorTypeId); 39bae4d13cSopenharmony_ci bool IsNativeToken(AccessTokenID callerToken); 40bae4d13cSopenharmony_ci int32_t CheckManageSensorPermission(AccessTokenID callerToken); 41bae4d13cSopenharmony_ci 42bae4d13cSopenharmony_ciprivate: 43bae4d13cSopenharmony_ci void AddPermissionRecord(AccessTokenID tokenID, const std::string &permissionName, bool status); 44bae4d13cSopenharmony_ci static std::unordered_map<int32_t, std::string> sensorPermissions_; 45bae4d13cSopenharmony_ci}; 46bae4d13cSopenharmony_ci} // namespace Sensors 47bae4d13cSopenharmony_ci} // namespace OHOS 48bae4d13cSopenharmony_ci#endif // PERMISSION_UTIL_H 49