• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "mock_ability_manager_stub.h"
17 
18 using namespace OHOS::AAFwk;
19 using namespace OHOS::AppExecFwk;
20 
21 namespace {
22 const std::string STRING_ABILITY_NAME_INVALID = "invalid_ability";
23 const std::string STRING_BUNDLE_NAME_INVALID = "invalid_bundle";
24 }  // namespace
25 
StartAbility(const Want & want,int32_t userId,int requestCode)26 int MockAbilityManagerStub::StartAbility(const Want &want, int32_t userId, int requestCode)
27 {
28     HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
29 
30     AppExecFwk::ElementName element = want.GetElement();
31 
32     std::string abilityName = element.GetAbilityName();
33     HILOG_INFO("abilityName: %{public}s", abilityName.c_str());
34     if (abilityName == STRING_ABILITY_NAME_INVALID) {
35         return RESOLVE_ABILITY_ERR;
36     }
37 
38     std::string bundleName = element.GetBundleName();
39     HILOG_INFO("bundleName: %{public}s", bundleName.c_str());
40     if (bundleName == STRING_BUNDLE_NAME_INVALID) {
41         return RESOLVE_APP_ERR;
42     }
43 
44     auto isDebugApp = want.GetBoolParam("debugApp", false);
45     HILOG_INFO("isDebugApp: %{public}d", isDebugApp);
46 
47     return ERR_OK;
48 }
49 
DumpState(const std::string & args,std::vector<std::string> & state)50 void MockAbilityManagerStub::DumpState(const std::string &args, std::vector<std::string> &state)
51 {
52     HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
53 
54     std::vector<std::string> argList;
55     SplitStr(args, " ", argList);
56 
57     std::string command = argList[0];
58     if (command == "--all" || command == "-a") {
59         // do nothing
60     } else if (command == "--stack-list" || command == "-l") {
61         // do nothing
62     } else if (command == "--stack" || command == "-s") {
63         state.push_back(argList[1]);
64     } else if (command == "--mission" || command == "-m") {
65         state.push_back(argList[1]);
66     } else {
67         // do nothing
68     }
69 }
70 
StopServiceAbility(const Want & want,int32_t userId)71 int MockAbilityManagerStub::StopServiceAbility(const Want &want, int32_t userId)
72 {
73     HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
74 
75     AppExecFwk::ElementName element = want.GetElement();
76 
77     std::string abilityName = element.GetAbilityName();
78     HILOG_INFO("abilityName: %{public}s", abilityName.c_str());
79     if (abilityName == STRING_ABILITY_NAME_INVALID) {
80         return RESOLVE_ABILITY_ERR;
81     }
82 
83     std::string bundleName = element.GetBundleName();
84     HILOG_INFO("bundleName: %{public}s", bundleName.c_str());
85     if (bundleName == STRING_BUNDLE_NAME_INVALID) {
86         return RESOLVE_APP_ERR;
87     }
88 
89     return ERR_OK;
90 }
91