1/* 2 * Copyright (c) 2021 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#ifndef PERMISSION_UTIL_H 17#define PERMISSION_UTIL_H 18 19#include <string> 20#include <unordered_map> 21 22#include "access_token.h" 23#include "singleton.h" 24 25namespace OHOS { 26namespace Sensors { 27const std::string ACCELEROMETER_PERMISSION = "ohos.permission.ACCELEROMETER"; 28const std::string GYROSCOPE_PERMISSION = "ohos.permission.GYROSCOPE"; 29const std::string ACTIVITY_MOTION_PERMISSION = "ohos.permission.ACTIVITY_MOTION"; 30const std::string READ_HEALTH_DATA_PERMISSION = "ohos.permission.READ_HEALTH_DATA"; 31const std::string MANAGE_SENSOR_PERMISSION = "ohos.permission.MANAGE_SENSOR"; 32 33using namespace Security::AccessToken; 34class PermissionUtil : public Singleton<PermissionUtil> { 35public: 36 PermissionUtil() = default; 37 virtual ~PermissionUtil() {}; 38 int32_t CheckSensorPermission(AccessTokenID callerToken, int32_t sensorTypeId); 39 bool IsNativeToken(AccessTokenID callerToken); 40 int32_t CheckManageSensorPermission(AccessTokenID callerToken); 41 42private: 43 void AddPermissionRecord(AccessTokenID tokenID, const std::string &permissionName, bool status); 44 static std::unordered_map<int32_t, std::string> sensorPermissions_; 45}; 46} // namespace Sensors 47} // namespace OHOS 48#endif // PERMISSION_UTIL_H 49