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