1 /*
2 * Copyright (c) 2021 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
StartAbility(const Want & want,int requestCode)21 int MockAbilityManagerStub::StartAbility(const Want &want, int requestCode)
22 {
23 HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
24
25 ElementName element = want.GetElement();
26
27 std::string abilityName = element.GetAbilityName();
28 HILOG_INFO("abilityName: %{public}s", abilityName.c_str());
29 if (abilityName == STRING_ABILITY_NAME_INVALID) {
30 return RESOLVE_ABILITY_ERR;
31 }
32
33 std::string bundleName = element.GetBundleName();
34 HILOG_INFO("bundleName: %{public}s", bundleName.c_str());
35 if (bundleName == STRING_BUNDLE_NAME_INVALID) {
36 return RESOLVE_APP_ERR;
37 }
38
39 return ERR_OK;
40 }
41
DumpState(const std::string & args,std::vector<std::string> & state)42 void MockAbilityManagerStub::DumpState(const std::string &args, std::vector<std::string> &state)
43 {
44 HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
45
46 std::vector<std::string> argList;
47 SplitStr(args, " ", argList);
48
49 std::string command = argList[0];
50 if (command == "--all" || command == "-a") {
51 // do nothing
52 } else if (command == "--stack-list" || command == "-l") {
53 // do nothing
54 } else if (command == "--stack" || command == "-s") {
55 state.push_back(argList[1]);
56 } else if (command == "--mission" || command == "-m") {
57 state.push_back(argList[1]);
58 } else {
59 // do nothing
60 }
61 }
62
StopServiceAbility(const Want & want)63 int MockAbilityManagerStub::StopServiceAbility(const Want &want)
64 {
65 HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
66
67 ElementName element = want.GetElement();
68
69 std::string abilityName = element.GetAbilityName();
70 HILOG_INFO("abilityName: %{public}s", abilityName.c_str());
71 if (abilityName == STRING_ABILITY_NAME_INVALID) {
72 return RESOLVE_ABILITY_ERR;
73 }
74
75 std::string bundleName = element.GetBundleName();
76 HILOG_INFO("bundleName: %{public}s", bundleName.c_str());
77 if (bundleName == STRING_BUNDLE_NAME_INVALID) {
78 return RESOLVE_APP_ERR;
79 }
80
81 return ERR_OK;
82 }
83
PowerOff()84 int MockAbilityManagerStub::PowerOff()
85 {
86 HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
87
88 HILOG_INFO("powerState_: %{public}s", powerState_.c_str());
89 if (powerState_ == STRING_STATE_OFF_INVALID) {
90 return POWER_OFF_FAILED;
91 }
92
93 return ERR_OK;
94 }
95
PowerOn()96 int MockAbilityManagerStub::PowerOn()
97 {
98 HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
99
100 HILOG_INFO("powerState_: %{public}s", powerState_.c_str());
101 if (powerState_ == STRING_STATE_ON_INVALID) {
102 return POWER_ON_FAILED;
103 }
104
105 return ERR_OK;
106 }
107