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