• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "external_calls.h"
16 #include "ability_manager_client.h"
17 
18 namespace OHOS::uitest {
GetFrontAbility()19     std::vector<std::string> GetFrontAbility()
20     {
21         std::vector<std::string> elements;
22         std::string bundleName, abilityName;
23         auto abilityManagerClientPtr = AAFwk::AbilityManagerClient::GetInstance();
24         if (abilityManagerClientPtr == nullptr) {
25             std::cout<<"AbilityManagerClient is nullptr"<<std::endl;
26             abilityName = "";
27             bundleName = "";
28         } else {
29             auto elementName = abilityManagerClientPtr->GetTopAbility();
30             if (elementName.GetBundleName().empty()) {
31                 std::cout<<"GetTopAbility GetBundleName is nullptr"<<std::endl;
32                 bundleName = "";
33             } else {
34                 bundleName = elementName.GetBundleName();
35             }
36             if (elementName.GetAbilityName().empty()) {
37                 std::cout<<"GetTopAbility GetAbilityName is nullptr"<<std::endl;
38                 abilityName = "";
39             } else {
40                 abilityName = elementName.GetAbilityName();
41             }
42         }
43         elements.push_back(bundleName);
44         elements.push_back(abilityName);
45         return elements;
46     }
47 }