1 /* 2 * Copyright (c) 2021-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 OHOS_AAFWK_UI_SERVICE_MANAGER_CLIENT_H 17 #define OHOS_AAFWK_UI_SERVICE_MANAGER_CLIENT_H 18 19 #include <mutex> 20 21 #include "iremote_object.h" 22 #include "dialog_callback.h" 23 #include "ui_service_interface.h" 24 #include "ui_service_mgr_errors.h" 25 #include "ui_service_mgr_interface.h" 26 #include "wm_common.h" 27 28 #include "base/utils/macros.h" 29 30 namespace OHOS::Ace { 31 /** 32 * @class UIServiceMgrClient 33 * UIServiceMgrClient is used to access UIService manager services. 34 */ 35 class ACE_FORCE_EXPORT UIServiceMgrClient { 36 public: 37 UIServiceMgrClient(); 38 virtual ~UIServiceMgrClient(); 39 static std::shared_ptr<UIServiceMgrClient> GetInstance(); 40 41 ErrCode RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService); 42 43 ErrCode UnregisterCallBack(const AAFwk::Want& want); 44 45 ErrCode Push(const AAFwk::Want& want, 46 const std::string& name, const std::string& jsonPath, const std::string& data, const std::string& extraData); 47 48 ErrCode Request(const AAFwk::Want& want, const std::string& name, const std::string& data); 49 50 ErrCode ReturnRequest( 51 const AAFwk::Want& want, const std::string& source, const std::string& data, const std::string& extraData); 52 53 ErrCode ShowDialog(const std::string& name, 54 const std::string& params, 55 OHOS::Rosen::WindowType windowType, 56 int32_t x, 57 int32_t y, 58 int32_t width, 59 int32_t height, 60 DialogCallback callback, 61 int32_t* id = nullptr); 62 63 ErrCode CancelDialog(int32_t id); 64 65 ErrCode UpdateDialog(int32_t id, const std::string& data); 66 67 private: 68 /** 69 * Connect UIService manager service. 70 * 71 * @return Returns ERR_OK on success, others on failure. 72 */ 73 ErrCode Connect(); 74 75 static std::mutex mutex_; 76 static std::shared_ptr<UIServiceMgrClient> instance_; 77 sptr<IRemoteObject> remoteObject_; 78 }; 79 } // namespace OHOS::Ace 80 #endif // OHOS_AAFWK_UI_SERVICE_MANAGER_CLIENT_H 81