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