• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 ACTIVE_STATUS_CHANGE_CALLBACK_MANAGER_H
17 #define ACTIVE_STATUS_CHANGE_CALLBACK_MANAGER_H
18 
19 #include <mutex>
20 #include <vector>
21 
22 #include "access_token.h"
23 #include "accesstoken_log.h"
24 #include "perm_active_status_callback_death_recipient.h"
25 #include "perm_active_status_change_callback_proxy.h"
26 
27 namespace OHOS {
28 namespace Security {
29 namespace AccessToken {
30 struct CallbackData {
CallbackDataCallbackData31     CallbackData() : permList_(), callbackObject_(nullptr)
32     {}
CallbackDataCallbackData33     CallbackData(const std::vector<std::string>& permList, sptr<IRemoteObject> callback)
34         : permList_(permList), callbackObject_(callback)
35     {}
36 
37     std::vector<std::string> permList_;
38     sptr<IRemoteObject> callbackObject_;
39 };
40 
41 class ActiveStatusCallbackManager {
42 public:
43     virtual ~ActiveStatusCallbackManager();
44     ActiveStatusCallbackManager();
45     static ActiveStatusCallbackManager& GetInstance();
46 
47     int32_t AddCallback(
48         const std::vector<std::string>& permList, const sptr<IRemoteObject>& callback);
49     int32_t RemoveCallback(const sptr<IRemoteObject>& callback);
50     bool NeedCalled(const std::vector<std::string>& permList, const std::string& permName);
51     void ExecuteCallbackAsync(
52         AccessTokenID tokenId, const std::string& permName, const std::string& deviceId, ActiveChangeType changeType);
53 
54 private:
55     std::mutex mutex_;
56     std::vector<CallbackData> callbackDataList_;
57     sptr<IRemoteObject::DeathRecipient> callbackDeathRecipient_;
58 };
59 } // namespace AccessToken
60 } // namespace Security
61 } // namespace OHOS
62 #endif // ACTIVE_STATUS_CHANGE_CALLBACK_MANAGER_H
63