• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 OHOS_ROSEN_MOCK_SESSION_MANAGER_SERVICE_H
17 #define OHOS_ROSEN_MOCK_SESSION_MANAGER_SERVICE_H
18 
19 #include <system_ability.h>
20 
21 #include "wm_single_instance.h"
22 #include "zidl/mock_session_manager_service_stub.h"
23 #include "zidl/session_manager_service_recover_interface.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class MockSessionManagerService : public SystemAbility, public MockSessionManagerServiceStub {
28 DECLARE_SYSTEM_ABILITY(MockSessionManagerService);
29 WM_DECLARE_SINGLE_INSTANCE_BASE(MockSessionManagerService);
30 public:
31     bool SetSessionManagerService(const sptr<IRemoteObject>& sessionManagerService);
32     void NotifySceneBoardAvailable() override;
33     sptr<IRemoteObject> GetSessionManagerService() override;
34     sptr<IRemoteObject> GetScreenSessionManagerLite() override;
35     sptr<IRemoteObject> GetSceneSessionManager();
36     void RegisterSMSRecoverListener(const sptr<IRemoteObject>& listener) override;
37     void UnregisterSMSRecoverListener() override;
38     void UnregisterSMSRecoverListener(int64_t pid);
39     void RegisterSMSLiteRecoverListener(const sptr<IRemoteObject>& listener) override;
40     void UnregisterSMSLiteRecoverListener() override;
41     void UnregisterSMSLiteRecoverListener(int64_t pid);
42     void OnStart() override;
43     int Dump(int fd, const std::vector<std::u16string> &args) override;
44     void OnWMSConnectionChanged(int32_t userId, int32_t screenId, bool isConnected);
45     void NotifyWMSConnected(int32_t userId, int32_t screenId);
NotifyNotKillService()46     void NotifyNotKillService()
47     {
48         if (smsDeathRecipient_ != nullptr) {
49             smsDeathRecipient_->needKillService_ = false;
50         }
51     }
52 
53 protected:
54     MockSessionManagerService();
55     virtual ~MockSessionManagerService() = default;
56 
57 private:
58     bool RegisterMockSessionManagerService();
59     void NotifySceneBoardAvailableToClient();
60     void NotifySceneBoardAvailableToLiteClient();
61     int DumpSessionInfo(const std::vector<std::string>& args, std::string& dumpInfo);
62     void ShowHelpInfo(std::string& dumpInfo);
63     void ShowAceDumpHelp(std::string& dumpInfo);
64     void ShowIllegalArgsInfo(std::string& dumpInfo);
65 
66     static void WriteStringToFile(int32_t pid, const char* str);
67 
68     class SMSDeathRecipient : public IRemoteObject::DeathRecipient {
69     public:
70         void OnRemoteDied(const wptr<IRemoteObject>& object) override;
71         bool IsSceneBoardTestMode();
72         void SetId(int32_t userId, int32_t screenId);
73         bool needKillService_ { true };
74 
75     private:
76         int32_t userId_ = 0;
77         int32_t screenId_ = 0;
78     };
79 
80     sptr<IRemoteObject> sessionManagerService_;
81     sptr<IRemoteObject> screenSessionManager_;
82     sptr<IRemoteObject> sceneSessionManager_;
83     sptr<SMSDeathRecipient> smsDeathRecipient_;
84 
85     std::recursive_mutex smsRecoverListenerLock_;
86     std::map<int64_t, sptr<ISessionManagerServiceRecoverListener>> smsRecoverListenerMap_;
87 
88     std::recursive_mutex smsLiteRecoverListenerLock_;
89     std::map<int64_t, sptr<ISessionManagerServiceRecoverListener>> smsLiteRecoverListenerMap_;
90 
91     int32_t currentUserId_ = 0;
92     int32_t currentScreenId_ = 0;
93     bool isWMSConnected_ = false;
94 };
95 } // namespace Rosen
96 } // namespace OHOS
97 
98 #endif // OHOS_ROSEN_MOCK_SESSION_MANAGER_SERVICE_H
99