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 TOKEN_SYNC_MANAGER_SERVICE_H
17 #define TOKEN_SYNC_MANAGER_SERVICE_H
18 
19 #include <string>
20 
21 #ifdef EVENTHANDLER_ENABLE
22 #include "event_handler.h"
23 #include "access_event_handler.h"
24 #endif
25 #include "hap_token_info_for_sync_parcel.h"
26 #include "iremote_object.h"
27 #include "nocopyable.h"
28 #include "singleton.h"
29 #include "system_ability.h"
30 #include "token_sync_manager_stub.h"
31 
32 namespace OHOS {
33 namespace Security {
34 namespace AccessToken {
35 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
36 class TokenSyncManagerService final : public SystemAbility, public TokenSyncManagerStub {
37     DECLARE_DELAYED_SINGLETON(TokenSyncManagerService);
38     DECLEAR_SYSTEM_ABILITY(TokenSyncManagerService);
39 
40 public:
41     void OnStart() override;
42     void OnStop() override;
43     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
44 
45 #ifdef EVENTHANDLER_ENABLE
46     std::shared_ptr<AccessEventHandler> GetSendEventHandler() const;
47     std::shared_ptr<AccessEventHandler> GetRecvEventHandler() const;
48 #endif
49     int GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) override;
50     int DeleteRemoteHapTokenInfo(AccessTokenID tokenID) override;
51     int UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo) override;
52 
53 private:
54     bool Initialize();
55 
56 #ifdef EVENTHANDLER_ENABLE
57     std::shared_ptr<AppExecFwk::EventRunner> sendRunner_;
58     std::shared_ptr<AppExecFwk::EventRunner> recvRunner_;
59     std::shared_ptr<AccessEventHandler> sendHandler_;
60     std::shared_ptr<AccessEventHandler> recvHandler_;
61 #endif
62     ServiceRunningState state_;
63 };
64 } // namespace AccessToken
65 } // namespace Security
66 } // namespace OHOS
67 #endif // TOKEN_SYNC_MANAGER_SERVICE_H
68