• 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 #ifdef EVENTHANDLER_ENABLE
23 #include "access_event_handler.h"
24 #endif
25 #include "access_token.h"
26 #include "accesstoken_common_log.h"
27 #include "active_change_response_info.h"
28 #include "perm_active_status_callback_death_recipient.h"
29 #include "perm_active_status_change_callback_proxy.h"
30 
31 namespace OHOS {
32 namespace Security {
33 namespace AccessToken {
34 struct CallbackData {
CallbackDataCallbackData35     CallbackData() : permList_(), callbackObject_(nullptr)
36     {}
CallbackDataCallbackData37     CallbackData(const std::vector<std::string>& permList, sptr<IRemoteObject> callback)
38         : permList_(permList), callbackObject_(callback)
39     {}
40 
41     AccessTokenID registerTokenId {0};
42     std::vector<std::string> permList_;
43     sptr<IRemoteObject> callbackObject_;
44 };
45 
46 class ActiveStatusCallbackManager {
47 public:
48     virtual ~ActiveStatusCallbackManager();
49     ActiveStatusCallbackManager();
50     static ActiveStatusCallbackManager& GetInstance();
51 
52     int32_t AddCallback(
53         AccessTokenID regiterTokenId, const std::vector<std::string>& permList, const sptr<IRemoteObject>& callback);
54     int32_t RemoveCallback(const sptr<IRemoteObject>& callback);
55     bool NeedCalled(const std::vector<std::string>& permList, const std::string& permName);
56     void ExecuteCallbackAsync(ActiveChangeResponse& info);
57 #ifdef EVENTHANDLER_ENABLE
58     void InitEventHandler(const std::shared_ptr<AccessEventHandler>& eventHandler);
59 #endif
60     void ActiveStatusChange(ActiveChangeResponse& info);
61 private:
62     std::mutex mutex_;
63     std::vector<CallbackData> callbackDataList_;
64     sptr<IRemoteObject::DeathRecipient> callbackDeathRecipient_;
65 #ifdef EVENTHANDLER_ENABLE
66     std::shared_ptr<AccessEventHandler> eventHandler_;
67 #endif
68 };
69 } // namespace AccessToken
70 } // namespace Security
71 } // namespace OHOS
72 #endif // ACTIVE_STATUS_CHANGE_CALLBACK_MANAGER_H
73