15ccb8f90Sopenharmony_ci/*
25ccb8f90Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
35ccb8f90Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45ccb8f90Sopenharmony_ci * you may not use this file except in compliance with the License.
55ccb8f90Sopenharmony_ci * You may obtain a copy of the License at
65ccb8f90Sopenharmony_ci *
75ccb8f90Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85ccb8f90Sopenharmony_ci *
95ccb8f90Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105ccb8f90Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115ccb8f90Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125ccb8f90Sopenharmony_ci * See the License for the specific language governing permissions and
135ccb8f90Sopenharmony_ci * limitations under the License.
145ccb8f90Sopenharmony_ci */
155ccb8f90Sopenharmony_ci
165ccb8f90Sopenharmony_ci#include <string>
175ccb8f90Sopenharmony_ci#include <vector>
185ccb8f90Sopenharmony_ci#include <ability_manager_client.h>
195ccb8f90Sopenharmony_ci#include "app_manager_utils.h"
205ccb8f90Sopenharmony_ci#include "power_log.h"
215ccb8f90Sopenharmony_ci
225ccb8f90Sopenharmony_ci
235ccb8f90Sopenharmony_ci#ifdef __cplusplus
245ccb8f90Sopenharmony_ciextern "C" {
255ccb8f90Sopenharmony_ci#endif
265ccb8f90Sopenharmony_ci
275ccb8f90Sopenharmony_ciusing namespace OHOS;
285ccb8f90Sopenharmony_ciusing namespace PowerMgr;
295ccb8f90Sopenharmony_ciusing namespace AAFwk;
305ccb8f90Sopenharmony_ci
315ccb8f90Sopenharmony_civoid PowerConnectAbility(const Want& want, const sptr<IAbilityConnection>& connect, int32_t userId)
325ccb8f90Sopenharmony_ci{
335ccb8f90Sopenharmony_ci    auto amsClient = AbilityManagerClient::GetInstance();
345ccb8f90Sopenharmony_ci    if (amsClient == nullptr) {
355ccb8f90Sopenharmony_ci        POWER_HILOGW(FEATURE_UTIL, "AbilityManagerClient is nullptr");
365ccb8f90Sopenharmony_ci        return;
375ccb8f90Sopenharmony_ci    }
385ccb8f90Sopenharmony_ci    ErrCode result = amsClient->ConnectAbility(want, connect, userId);
395ccb8f90Sopenharmony_ci    if (result != ERR_OK) {
405ccb8f90Sopenharmony_ci        POWER_HILOGW(FEATURE_UTIL, "ConnectAbility systemui dialog failed, result = %{public}d", result);
415ccb8f90Sopenharmony_ci        return;
425ccb8f90Sopenharmony_ci    }
435ccb8f90Sopenharmony_ci    POWER_HILOGI(FEATURE_UTIL, "ConnectAbility systemui dialog success.");
445ccb8f90Sopenharmony_ci}
455ccb8f90Sopenharmony_ci
465ccb8f90Sopenharmony_civoid PowerStartAbility(const Want& want)
475ccb8f90Sopenharmony_ci{
485ccb8f90Sopenharmony_ci    auto amsClient = AbilityManagerClient::GetInstance();
495ccb8f90Sopenharmony_ci    if (amsClient == nullptr) {
505ccb8f90Sopenharmony_ci        POWER_HILOGW(FEATURE_UTIL, "AbilityManagerClient is nullptr");
515ccb8f90Sopenharmony_ci        return;
525ccb8f90Sopenharmony_ci    }
535ccb8f90Sopenharmony_ci    ErrCode result = amsClient->StartAbility(want);
545ccb8f90Sopenharmony_ci    if (result != ERR_OK) {
555ccb8f90Sopenharmony_ci        POWER_HILOGW(FEATURE_UTIL, "StartAbility systemui dialog failed, result = %{public}d", result);
565ccb8f90Sopenharmony_ci        return;
575ccb8f90Sopenharmony_ci    }
585ccb8f90Sopenharmony_ci    POWER_HILOGI(FEATURE_UTIL, "StartAbility systemui dialog success.");
595ccb8f90Sopenharmony_ci}
605ccb8f90Sopenharmony_ci
615ccb8f90Sopenharmony_civoid PowerGetForegroundApplications(std::vector<OHOS::AppExecFwk::AppStateData>& appsData)
625ccb8f90Sopenharmony_ci{
635ccb8f90Sopenharmony_ci    AppManagerUtils::GetForegroundApplications(appsData);
645ccb8f90Sopenharmony_ci}
655ccb8f90Sopenharmony_ci
665ccb8f90Sopenharmony_cibool PowerIsForegroundApplication(const std::string& appName)
675ccb8f90Sopenharmony_ci{
685ccb8f90Sopenharmony_ci    return AppManagerUtils::IsForegroundApplication(appName);
695ccb8f90Sopenharmony_ci}
705ccb8f90Sopenharmony_ci
715ccb8f90Sopenharmony_ci#ifdef __cplusplus
725ccb8f90Sopenharmony_ci}
735ccb8f90Sopenharmony_ci#endif
74