• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 TOKEN_MODIFY_NOTIFIER_H
17 #define TOKEN_MODIFY_NOTIFIER_H
18 
19 #include <atomic>
20 #include <set>
21 #include <vector>
22 
23 #include "access_token.h"
24 #include "i_token_sync_callback.h"
25 #include "nocopyable.h"
26 #include "rwlock.h"
27 #include "thread_pool.h"
28 #include "callback_death_recipients.h"
29 
30 namespace OHOS {
31 namespace Security {
32 namespace AccessToken {
33 class TokenModifyNotifier final {
34 public:
35     static TokenModifyNotifier& GetInstance();
36     ~TokenModifyNotifier();
37     void AddHapTokenObservation(AccessTokenID tokenID);
38     void NotifyTokenDelete(AccessTokenID tokenID);
39     void NotifyTokenModify(AccessTokenID tokenID);
40     void NotifyTokenChangedIfNeed();
41     void NotifyTokenSyncTask();
42     int32_t GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID);
43     int32_t RegisterTokenSyncCallback(const sptr<IRemoteObject>& callback);
44     void UnRegisterTokenSyncCallback();
45 
46 private:
47     TokenModifyNotifier();
48     DISALLOW_COPY_AND_MOVE(TokenModifyNotifier);
49 
50     bool hasInited_;
51     OHOS::Utils::RWLock initLock_;
52     OHOS::Utils::RWLock listLock_;
53     OHOS::Utils::RWLock notifyLock_;
54     OHOS::ThreadPool notifyTokenWorker_;
55     std::set<AccessTokenID> observationSet_;
56     std::vector<AccessTokenID> deleteTokenList_;
57     std::vector<AccessTokenID> modifiedTokenList_;
58     sptr<ITokenSyncCallback> tokenSyncCallbackObject_ = nullptr;
59 #ifdef TOKEN_SYNC_ENABLE
60     sptr<TokenSyncCallbackDeathRecipient> tokenSyncCallbackDeathRecipient_ = nullptr;
61 #endif
62 };
63 } // namespace AccessToken
64 } // namespace Security
65 } // namespace OHOS
66 #endif // TOKEN_MODIFY_NOTIFIER_H
67