• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "hilog_wrapper.h"
21 #include "if_system_ability_manager.h"
22 #include "ipc_skeleton.h"
23 #include "iservice_registry.h"
24 #include "string_ex.h"
25 #include "system_ability_definition.h"
26 
27 // external dependence
28 #include "ability_manager_client.h"
29 #include "display_manager.h"
30 
31 namespace OHOS {
32 namespace Ace {
33 using DialogCallback = std::function<void(int32_t id, const std::string& event, const std::string& param)>;
34 std::shared_ptr<UIServiceMgrClient> UIServiceMgrClient::instance_ = nullptr;
35 int UIServiceMgrClient::pid_ = 0;
36 std::string UIServiceMgrClient::code_ = "0";
37 std::mutex UIServiceMgrClient::mutex_;
38 bool UIServiceMgrClient::appRunning_ = true;
39 namespace {
40 const std::string EVENT_WAITING_CODE = "0";
41 const std::string EVENT_CLOSE_CODE = "1";
42 }
43 
GetInstance()44 std::shared_ptr<UIServiceMgrClient> UIServiceMgrClient::GetInstance()
45 {
46     if (instance_ == nullptr) {
47         std::lock_guard<std::mutex> lock_l(mutex_);
48         if (instance_ == nullptr) {
49             instance_ = std::make_shared<UIServiceMgrClient>();
50         }
51     }
52     return instance_;
53 }
54 
UIServiceMgrClient()55 UIServiceMgrClient::UIServiceMgrClient()
56 {}
57 
~UIServiceMgrClient()58 UIServiceMgrClient::~UIServiceMgrClient()
59 {}
60 
RegisterCallBack(const AAFwk::Want & want,const sptr<IUIService> & uiService)61 ErrCode UIServiceMgrClient::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService)
62 {
63     return 0;
64 }
65 
UnregisterCallBack(const AAFwk::Want & want)66 ErrCode UIServiceMgrClient::UnregisterCallBack(const AAFwk::Want& want)
67 {
68     return 0;
69 }
70 
Push(const AAFwk::Want & want,const std::string & name,const std::string & jsonPath,const std::string & data,const std::string & extraData)71 ErrCode UIServiceMgrClient::Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
72     const std::string& data, const std::string& extraData)
73 {
74     return 0;
75 }
76 
Request(const AAFwk::Want & want,const std::string & name,const std::string & data)77 ErrCode UIServiceMgrClient::Request(const AAFwk::Want& want, const std::string& name, const std::string& data)
78 {
79     return 0;
80 }
81 
ReturnRequest(const AAFwk::Want & want,const std::string & source,const std::string & data,const std::string & extraData)82 ErrCode UIServiceMgrClient::ReturnRequest(const AAFwk::Want& want, const std::string& source,
83     const std::string& data, const std::string& extraData)
84 {
85     return 0;
86 }
87 
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)88 ErrCode UIServiceMgrClient::ShowDialog(const std::string& name, const std::string& params,
89     OHOS::Rosen::WindowType windowType, int x, int y, int width, int height, DialogCallback callback, int* id)
90 {
91     if (code_ == EVENT_WAITING_CODE) {
92         appRunning_ = true;
93         HILOG_INFO("Waiting caller kill the process");
94         return 0;
95     }
96     if (code_ == EVENT_CLOSE_CODE) {
97         HILOG_INFO("kill the process");
98         kill(pid_, SIGKILL);
99         appRunning_ = false;
100     }
101     return 0;
102 }
103 
CancelDialog(int32_t id)104 ErrCode UIServiceMgrClient::CancelDialog(int32_t id)
105 {
106     return 0;
107 }
108 
UpdateDialog(int32_t id,const std::string & data)109 ErrCode UIServiceMgrClient::UpdateDialog(int32_t id, const std::string& data)
110 {
111     return 0;
112 }
113 
ShowAppPickerDialog(const AAFwk::Want & want,const std::vector<AppExecFwk::AbilityInfo> & abilityInfos,int32_t userId)114 ErrCode UIServiceMgrClient::ShowAppPickerDialog(
115     const AAFwk::Want& want, const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, int32_t userId)
116 {
117     return 0;
118 }
119 
Connect()120 ErrCode UIServiceMgrClient::Connect()
121 {
122     return 0;
123 }
124 
GetPickerDialogParam(const AAFwk::Want & want,const std::vector<AppExecFwk::AbilityInfo> & abilityInfos,bool wideScreen) const125 const std::string UIServiceMgrClient::GetPickerDialogParam(
126     const AAFwk::Want& want, const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, bool wideScreen) const
127 {
128     return "";
129 }
130 
GetDisplayPosition(int32_t & offsetX,int32_t & offsetY,int32_t & width,int32_t & height,bool & wideScreen)131 void UIServiceMgrClient::GetDisplayPosition(
132     int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height, bool& wideScreen)
133 {
134     return;
135 }
136 }  // namespace Ace
137 }  // namespace OHOS
138