• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 ACCESSTOKEN_TOKEN_ID_MANAGER_H
17 #define ACCESSTOKEN_TOKEN_ID_MANAGER_H
18 
19 #include <set>
20 #include <vector>
21 
22 #include "access_token.h"
23 #include "nocopyable.h"
24 #include "rwlock.h"
25 
26 namespace OHOS {
27 namespace Security {
28 namespace AccessToken {
29 static constexpr unsigned int TOKEN_RANDOM_MASK = (1 << 20) - 1;
30 static const int MAX_CREATE_TOKEN_ID_RETRY = 1000;
31 
32 class AccessTokenIDManager final {
33 public:
34     static AccessTokenIDManager& GetInstance();
35     virtual ~AccessTokenIDManager() = default;
36 
37     int AddTokenId(AccessTokenID id, ATokenTypeEnum type);
38     AccessTokenID CreateAndRegisterTokenId(ATokenTypeEnum type, int dlpType);
39     int RegisterTokenId(AccessTokenID id, ATokenTypeEnum type);
40     void ReleaseTokenId(AccessTokenID id);
41     ATokenTypeEnum GetTokenIdType(AccessTokenID id);
42     int GetTokenIdDlpFlag(AccessTokenID id);
43     static ATokenTypeEnum GetTokenIdTypeEnum(AccessTokenID id);
44     void GetHapTokenIdList(std::vector<AccessTokenID>& idList);
45 
46 private:
47     AccessTokenIDManager() = default;
48     DISALLOW_COPY_AND_MOVE(AccessTokenIDManager);
49     AccessTokenID CreateTokenId(ATokenTypeEnum type, int dlpType) const;
50 
51     OHOS::Utils::RWLock tokenIdLock_;
52     std::set<AccessTokenID> tokenIdSet_;
53 };
54 } // namespace AccessToken
55 } // namespace Security
56 } // namespace OHOS
57 #endif // ACCESSTOKEN_TOKEN_ID_MANAGER_H
58