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 #include "ui_service_mgr_client_mock.h"
17 
18 #include <csignal>
19 
20 #include "ability_manager_client.h"
21 #include "dialog_callback_stub.h"
22 #include "display_manager.h"
23 #include "if_system_ability_manager.h"
24 #include "ipc_skeleton.h"
25 #include "iservice_registry.h"
26 #include "string_ex.h"
27 #include "system_ability_definition.h"
28 
29 namespace OHOS {
30 namespace Ace {
31 std::shared_ptr<UIServiceMgrClient> UIServiceMgrClient::instance_ = nullptr;
32 std::mutex UIServiceMgrClient::mutex_;
33 namespace {
34 const std::string EVENT_CHOOSE_CODE = "EVENT_CHOOSE_APP";
35 const std::string EVENT_CLOSE_CODE = "EVENT_CLOSE";
36 const std::string EVENT_MULT_APP_CHOOSE = "EVENT_MULT_APP_CHOOSE";
37 const std::string EVENT_MULT_APP_CLOSE = "EVENT_MULT_APP_CLOSE";
38 const std::string EVENT_TIPS_APP = "EVENT_TIPS_APP";
39 }
40 
GetInstance()41 std::shared_ptr<UIServiceMgrClient> UIServiceMgrClient::GetInstance()
42 {
43     if (instance_ == nullptr) {
44         std::lock_guard<std::mutex> lock_l(mutex_);
45         if (instance_ == nullptr) {
46             instance_ = std::make_shared<UIServiceMgrClient>();
47         }
48     }
49     return instance_;
50 }
51 
UIServiceMgrClient()52 UIServiceMgrClient::UIServiceMgrClient()
53 {}
54 
~UIServiceMgrClient()55 UIServiceMgrClient::~UIServiceMgrClient()
56 {}
57 
RegisterCallBack(const AAFwk::Want & want,const sptr<IUIService> & uiService)58 ErrCode UIServiceMgrClient::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService)
59 {
60     return 0;
61 }
62 
UnregisterCallBack(const AAFwk::Want & want)63 ErrCode UIServiceMgrClient::UnregisterCallBack(const AAFwk::Want& want)
64 {
65     return 0;
66 }
67 
Push(const AAFwk::Want & want,const std::string & name,const std::string & jsonPath,const std::string & data,const std::string & extraData)68 ErrCode UIServiceMgrClient::Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
69     const std::string& data, const std::string& extraData)
70 {
71     return 0;
72 }
73 
Request(const AAFwk::Want & want,const std::string & name,const std::string & data)74 ErrCode UIServiceMgrClient::Request(const AAFwk::Want& want, const std::string& name, const std::string& data)
75 {
76     return 0;
77 }
78 
ReturnRequest(const AAFwk::Want & want,const std::string & source,const std::string & data,const std::string & extraData)79 ErrCode UIServiceMgrClient::ReturnRequest(const AAFwk::Want& want, const std::string& source,
80     const std::string& data, const std::string& extraData)
81 {
82     return 0;
83 }
84 
ShowDialog(const std::string & name,const std::string & params,OHOS::Rosen::WindowType windowType,int x,int y,int width,int height,DialogCallback callback,int * id)85 ErrCode UIServiceMgrClient::ShowDialog(const std::string& name, const std::string& params,
86     OHOS::Rosen::WindowType windowType, int x, int y, int width, int height, DialogCallback callback, int* id)
87 {
88     isCallBack_ = false;
89     if (code_ == EVENT_MULT_APP_CHOOSE) {
90         params_ = params;
91         auto jsonObj = nlohmann::json::parse(params, nullptr, false);
92         auto hapListObj = nlohmann::json::array();
93         hapListObj = jsonObj["hapList"];
94         auto aObj = hapListObj[0];
95         std::string callbackParams = aObj["bundle"].dump() + ";" + aObj["ability"].dump();
96         callback(0, EVENT_CHOOSE_CODE, callbackParams);
97         return ERR_OK;
98     }
99 
100     if (code_ == EVENT_MULT_APP_CLOSE) {
101         params_ = params;
102         callback(0, EVENT_CLOSE_CODE, "");
103         return ERR_OK;
104     }
105 
106     if (code_ == EVENT_TIPS_APP) {
107         params_ = params;
108         callback(0, EVENT_CLOSE_CODE, "");
109         return ERR_OK;
110     }
111 
112     return 0;
113 }
114 
CancelDialog(int32_t id)115 ErrCode UIServiceMgrClient::CancelDialog(int32_t id)
116 {
117     if (id == 0) {
118         isCallBack_ = true;
119         return 0;
120     }
121     return -1;
122 }
123 
UpdateDialog(int32_t id,const std::string & data)124 ErrCode UIServiceMgrClient::UpdateDialog(int32_t id, const std::string& data)
125 {
126     return 0;
127 }
128 
ShowAppPickerDialog(const AAFwk::Want & want,const std::vector<AppExecFwk::AbilityInfo> & abilityInfos,int32_t userId)129 ErrCode UIServiceMgrClient::ShowAppPickerDialog(
130     const AAFwk::Want& want, const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, int32_t userId)
131 {
132     return 0;
133 }
134 
Connect()135 ErrCode UIServiceMgrClient::Connect()
136 {
137     return 0;
138 }
139 
GetPickerDialogParam(const AAFwk::Want & want,const std::vector<AppExecFwk::AbilityInfo> & abilityInfos,bool wideScreen) const140 const std::string UIServiceMgrClient::GetPickerDialogParam(
141     const AAFwk::Want& want, const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, bool wideScreen) const
142 {
143     return "";
144 }
145 
GetDisplayPosition(int32_t & offsetX,int32_t & offsetY,int32_t & width,int32_t & height,bool & wideScreen)146 void UIServiceMgrClient::GetDisplayPosition(
147     int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height, bool& wideScreen)
148 {
149     return;
150 }
151 }  // namespace Ace
152 }  // namespace OHOS
153