1/*
2 * Copyright (c) 2024 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 <string>
17#include <vector>
18#include <ability_manager_client.h>
19#include "app_manager_utils.h"
20#include "power_log.h"
21
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27using namespace OHOS;
28using namespace PowerMgr;
29using namespace AAFwk;
30
31void PowerConnectAbility(const Want& want, const sptr<IAbilityConnection>& connect, int32_t userId)
32{
33    auto amsClient = AbilityManagerClient::GetInstance();
34    if (amsClient == nullptr) {
35        POWER_HILOGW(FEATURE_UTIL, "AbilityManagerClient is nullptr");
36        return;
37    }
38    ErrCode result = amsClient->ConnectAbility(want, connect, userId);
39    if (result != ERR_OK) {
40        POWER_HILOGW(FEATURE_UTIL, "ConnectAbility systemui dialog failed, result = %{public}d", result);
41        return;
42    }
43    POWER_HILOGI(FEATURE_UTIL, "ConnectAbility systemui dialog success.");
44}
45
46void PowerStartAbility(const Want& want)
47{
48    auto amsClient = AbilityManagerClient::GetInstance();
49    if (amsClient == nullptr) {
50        POWER_HILOGW(FEATURE_UTIL, "AbilityManagerClient is nullptr");
51        return;
52    }
53    ErrCode result = amsClient->StartAbility(want);
54    if (result != ERR_OK) {
55        POWER_HILOGW(FEATURE_UTIL, "StartAbility systemui dialog failed, result = %{public}d", result);
56        return;
57    }
58    POWER_HILOGI(FEATURE_UTIL, "StartAbility systemui dialog success.");
59}
60
61void PowerGetForegroundApplications(std::vector<OHOS::AppExecFwk::AppStateData>& appsData)
62{
63    AppManagerUtils::GetForegroundApplications(appsData);
64}
65
66bool PowerIsForegroundApplication(const std::string& appName)
67{
68    return AppManagerUtils::IsForegroundApplication(appName);
69}
70
71#ifdef __cplusplus
72}
73#endif
74