• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 CONSTANT_H
17 #define CONSTANT_H
18 
19 #include <map>
20 #include <string>
21 
22 namespace OHOS {
23 namespace Security {
24 namespace AccessToken {
25 class Constant {
26 public:
27     enum OpCode {
28         OP_INVALID = -1,
29         OP_ANSWER_CALL = 0,
30         OP_READ_CALENDAR = 1,
31         OP_WRITE_CALENDAR = 2,
32         OP_SEND_MESSAGES = 3,
33         OP_WRITE_CALL_LOG = 4,
34         OP_READ_CALL_LOG = 5,
35         OP_READ_CELL_MESSAGES = 6,
36         OP_MICROPHONE = 7,
37         OP_RECEIVE_WAP_MESSAGES = 8,
38         OP_RECEIVE_SMS = 9,
39         OP_RECEIVE_MMS = 10,
40         OP_READ_MESSAGES = 11,
41         OP_READ_CONTACTS = 12,
42         OP_WRITE_CONTACTS = 13,
43         OP_LOCATION_IN_BACKGROUND = 14,
44         OP_LOCATION = 15,
45         OP_MEDIA_LOCATION = 16,
46         OP_APPROXIMATELY_LOCATION = 17,
47         OP_CAMERA = 18,
48         OP_READ_MEDIA = 19,
49         OP_WRITE_MEDIA = 20,
50         OP_ACTIVITY_MOTION = 21,
51         OP_READ_HEALTH_DATA = 22,
52         OP_MANAGE_VOICEMAIL = 23,
53         OP_DISTRIBUTED_DATASYNC = 24,
54         OP_READ_IMAGEVIDEO = 25,
55         OP_READ_AUDIO = 26,
56         OP_READ_DOCUMENT = 27,
57         OP_WRITE_IMAGEVIDEO = 28,
58         OP_WRITE_AUDIO = 29,
59         OP_WRITE_DOCUMENT = 30,
60         OP_READ_WHOLE_CALENDAR = 31,
61         OP_WRITE_WHOLE_CALENDAR = 32,
62         OP_APP_TRACKING_CONSENT = 33,
63         OP_GET_INSTALLED_BUNDLE_LIST = 34,
64         OP_ACCESS_BLUETOOTH = 35,
65         OP_READ_PASTEBOARD = 36,
66         OP_READ_WRITE_DOWNLOAD_DIRECTORY = 37,
67         OP_READ_WRITE_DOCUMENTS_DIRECTORY = 38,
68         OP_READ_WRITE_DESKTOP_DIRECTORY = 39,
69         OP_ACCESS_NEARLINK = 40,
70         OP_CAPTURE_SCREEN = 41,
71         SHORT_TERM_WRITE_IMAGEVIDEO = 42,
72         CAMERA_BACKGROUND = 43,
73         OP_CUSTOM_SCREEN_CAPTURE = 44,
74         // 以下声明仅用于下载 桌面 文档文件夹权限的访问记录使用,需要和普通权限做区分
75         OP_READ_WRITE_DOWNLOAD_DIRECTORY_MEDIA_READ = 100,
76         OP_READ_WRITE_DOWNLOAD_DIRECTORY_MEDIA_WRITE = 101,
77         OP_READ_WRITE_DOWNLOAD_DIRECTORY_OTHER_READ = 102,
78         OP_READ_WRITE_DOWNLOAD_DIRECTORY_OTHER_WRITE = 103,
79         OP_READ_WRITE_DOCUMENTS_DIRECTORY_MEDIA_READ = 104,
80         OP_READ_WRITE_DOCUMENTS_DIRECTORY_MEDIA_WRITE = 105,
81         OP_READ_WRITE_DOCUMENTS_DIRECTORY_OTHER_READ = 106,
82         OP_READ_WRITE_DOCUMENTS_DIRECTORY_OTHER_WRITE = 107,
83         OP_READ_WRITE_DESKTOP_DIRECTORY_MEDIA_READ = 108,
84         OP_READ_WRITE_DESKTOP_DIRECTORY_MEDIA_WRITE = 109,
85         OP_READ_WRITE_DESKTOP_DIRECTORY_OTHER_READ = 110,
86         OP_READ_WRITE_DESKTOP_DIRECTORY_OTHER_WRITE = 111,
87     };
88 
89     enum ErrorCode {
90         FAILURE = -1,
91         SUCCESS = 0,
92     };
93 
94     const static int64_t MILLISECONDS = 1000; // 1s = 1000ms
95     const static int64_t ONE_DAY_MILLISECONDS = 24 * 60 * 60 * MILLISECONDS; // 1s = 1000ms
96     const static std::map<std::string, int32_t> PERMISSION_OPCODE_MAP;
97 public:
98     static bool TransferPermissionToOpcode(const std::string& permissionName, int32_t& opCode);
99     static bool TransferOpcodeToPermission(int32_t opCode, std::string& permissionName);
100 };
101 } // namespace AccessToken
102 } // namespace Security
103 } // namespace OHOS
104 
105 #endif // CONSTANT_H
106