1 /*
2 * Copyright (c) 2020 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 "ability_dump_task.h"
17
18 namespace OHOS {
AbilityDumpTask(AbilityMgrContext * context,const AbilityDumpClient * client)19 AbilityDumpTask::AbilityDumpTask(AbilityMgrContext *context, const AbilityDumpClient *client)
20 : AbilityTask(context), client_(client)
21 {
22 }
23
Execute()24 AbilityMsStatus AbilityDumpTask::Execute()
25 {
26 PRINTD("AbilityDumpTask", "start");
27 if (abilityMgrContext_ == nullptr || client_ == nullptr) {
28 return AbilityMsStatus::TaskStatus("dump", "invalid argument");
29 }
30 AbilityStackManager &stackManager = AbilityStackManager::GetInstance();
31 if (client_->GetWant().element != nullptr) {
32 // If query target ability
33 const PageAbilityRecord *targetAbility =
34 stackManager.FindPageAbility(*abilityMgrContext_, client_->GetWant());
35 if (targetAbility == nullptr) {
36 return client_->AbilityDumpTransaction("Ability not found\n");
37 }
38 return targetAbility->DumpAbilitySlice(client_->GetWant());
39 } else {
40 // Query all ability
41 #ifdef OHOS_DEBUG
42 AbilityMsStatus status = stackManager.DumpAllAbilityRecord(*abilityMgrContext_);
43 return client_->AbilityDumpTransaction(status.Dump());
44 #else
45 return client_->AbilityDumpTransaction("Dump is not available in release\n");
46 #endif
47 }
48 }
49 } // namespace OHOS
50