• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #define LOG_TAG "UdmfDialog"
16 
17 #include "udmf_dialog.h"
18 
19 #include "ability_connect_callback_stub.h"
20 #include "ability_manager_proxy.h"
21 #include "error_code.h"
22 #include "in_process_call_wrapper.h"
23 #include "iservice_registry.h"
24 #include "log_print.h"
25 #include "system_ability_definition.h"
26 #ifdef SCENE_BOARD_ENABLE
27 #include "window_manager_lite.h"
28 #else
29 #include "window_manager.h"
30 #endif
31 
32 namespace OHOS::UDMF {
33 using namespace OHOS::AAFwk;
34 
GetInstance()35 ProgressDialog &ProgressDialog::GetInstance()
36 {
37     static ProgressDialog instance;
38     return instance;
39 }
40 
GetFocusedAppInfo(void) const41 ProgressDialog::FocusedAppInfo ProgressDialog::GetFocusedAppInfo(void) const
42 {
43     FocusedAppInfo appInfo = { 0 };
44     Rosen::FocusChangeInfo info;
45 #ifdef SCENE_BOARD_ENABLE
46     Rosen::WindowManagerLite::GetInstance().GetFocusWindowInfo(info);
47 #else
48     Rosen::WindowManager::GetInstance().GetFocusWindowInfo(info);
49 #endif
50     appInfo.windowId = info.windowId_;
51     appInfo.abilityToken = info.abilityToken_;
52     return appInfo;
53 }
54 
GetAbilityManagerService()55 sptr<IAbilityManager> ProgressDialog::GetAbilityManagerService()
56 {
57     auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
58     if (systemAbilityManager == nullptr) {
59         ZLOGE("Failed to get ability manager.");
60         return nullptr;
61     }
62     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
63     if (!remoteObject) {
64         ZLOGE("Failed to get ability manager service.");
65         return nullptr;
66     }
67     return iface_cast<IAbilityManager>(remoteObject);
68 }
69 
ShowProgress(const ProgressMessageInfo & message)70 int32_t ProgressDialog::ShowProgress(const ProgressMessageInfo &message)
71 {
72     ZLOGD("Begin.");
73     auto abilityManager = GetAbilityManagerService();
74     if (abilityManager == nullptr) {
75         ZLOGE("Get ability manager failed.");
76         return E_ERROR;
77     }
78 
79     Want want;
80     want.SetElementName(PASTEBOARD_DIALOG_APP, PASTEBOARD_PROGRESS_ABILITY);
81     want.SetAction(PASTEBOARD_PROGRESS_ABILITY);
82     want.SetParam("promptText", message.promptText);
83     want.SetParam("remoteDeviceName", message.remoteDeviceName);
84     want.SetParam("progressKey", message.progressKey);
85     want.SetParam("isRemote", message.isRemote);
86     want.SetParam("windowId", message.windowId);
87     want.SetParam("ipcCallback", message.clientCallback);
88     if (message.callerToken != nullptr) {
89         want.SetParam("tokenKey", message.callerToken);
90     } else {
91         ZLOGW("CallerToken is nullptr.");
92     }
93 
94     int32_t status = IN_PROCESS_CALL(abilityManager->StartAbility(want));
95     if (status != 0) {
96         ZLOGE("Start progress failed, status:%{public}d.", status);
97     }
98     return status;
99 }
100 } // namespace OHOS::UDMF