• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "ability_info.h"
22 #include "iremote_object.h"
23 #include "dialog_callback_interface.h"
24 #include "ui_service_interface.h"
25 #include "ui_service_mgr_errors.h"
26 #include "ui_service_mgr_interface.h"
27 #include "uri.h"
28 
29 namespace OHOS {
30 namespace Ace {
31 /**
32  * @class UIServiceMgrClient
33  * UIServiceMgrClient is used to access UIService manager services.
34  */
35 class 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                        int x,
57                        int y,
58                        int width,
59                        int height,
60                        DialogCallback callback,
61                        int* id = nullptr);
62 
63     ErrCode CancelDialog(int32_t id);
64 
65     ErrCode ShowAppPickerDialog(
66         const AAFwk::Want& want, const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, int32_t userId);
67 
68 private:
69     /**
70      * Connect UIService manager service.
71      *
72      * @return Returns ERR_OK on success, others on failure.
73      */
74     ErrCode Connect();
75 
76     const std::string GetPickerDialogParam(const AAFwk::Want& want,
77         const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, bool wideScreen = true) const;
78     void GetDisplayPosition(
79         int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height, bool& wideScreen);
80 
81     static std::mutex mutex_;
82     static std::shared_ptr<UIServiceMgrClient> instance_;
83     sptr<IRemoteObject> remoteObject_;
84 };
85 }  // namespace Ace
86 }  // namespace OHOS
87 #endif  // OHOS_AAFWK_UI_SERVICE_MANAGER_CLIENT_H
88