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 
44 #ifdef EVENTHANDLER_ENABLE
45     std::shared_ptr<AccessEventHandler> GetSendEventHandler() const;
46     std::shared_ptr<AccessEventHandler> GetRecvEventHandler() const;
47 #endif
48     int GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) override;
49     int DeleteRemoteHapTokenInfo(AccessTokenID tokenID) override;
50     int UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo) override;
51 
52 private:
53     bool Initialize();
54 
55 #ifdef EVENTHANDLER_ENABLE
56     std::shared_ptr<AppExecFwk::EventRunner> sendRunner_;
57     std::shared_ptr<AppExecFwk::EventRunner> recvRunner_;
58     std::shared_ptr<AccessEventHandler> sendHandler_;
59     std::shared_ptr<AccessEventHandler> recvHandler_;
60 #endif
61     ServiceRunningState state_;
62 };
63 } // namespace AccessToken
64 } // namespace Security
65 } // namespace OHOS
66 #endif // TOKEN_SYNC_MANAGER_SERVICE_H
67