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 
76     enum ErrorCode {
77         FAILURE = -1,
78         SUCCESS = 0,
79     };
80 
81     const static int64_t MILLISECONDS = 1000; // 1s = 1000ms
82     const static int64_t ONE_DAY_MILLISECONDS = 24 * 60 * 60 * MILLISECONDS; // 1s = 1000ms
83     const static std::map<std::string, int32_t> PERMISSION_OPCODE_MAP;
84 public:
85     static bool TransferPermissionToOpcode(const std::string& permissionName, int32_t& opCode);
86     static bool TransferOpcodeToPermission(int32_t opCode, std::string& permissionName);
87 };
88 } // namespace AccessToken
89 } // namespace Security
90 } // namespace OHOS
91 
92 #endif // CONSTANT_H
93