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 "client/ability_dump_client.h"
17 
18 #include "ability_kit_command.h"
19 #include "ipc_skeleton.h"
20 #include "rpc_errno.h"
21 #include "securec.h"
22 #include "util/abilityms_log.h"
23 
24 namespace OHOS {
AbilityDumpClient(const Want & want)25 AbilityDumpClient::AbilityDumpClient(const Want &want)
26 {
27     if (want.element != nullptr) {
28         SetWantElement(&want_, *(want.element));
29     }
30     if (want.data != nullptr) {
31         SetWantData(&want_, want.data, want.dataLength);
32     }
33     if (want.sid != nullptr) {
34         SetWantSvcIdentity(&want_, *(want.sid));
35     }
36 }
~AbilityDumpClient()37 AbilityDumpClient::~AbilityDumpClient()
38 {
39     ClearWant(&want_);
40 }
41 
GetWant() const42 const Want &AbilityDumpClient::GetWant() const
43 {
44     return want_;
45 }
46 
AbilityDumpTransaction(const char * info) const47 AbilityMsStatus AbilityDumpClient::AbilityDumpTransaction(const char *info) const
48 {
49     if (want_.sid == nullptr) {
50         return AbilityMsStatus::DumpStatus("null SvcIdentity");
51     }
52     PRINTD("AbilityThreadClient", "start");
53     if (info == nullptr) {
54         info = "";
55     }
56     IpcIo req;
57     char data[MAX_IO_SIZE];
58     IpcIoInit(&req, data, MAX_IO_SIZE, 1);
59     WriteString(&req, info);
60     MessageOption option;
61     MessageOptionInit(&option);
62     option.flags = TF_OP_ASYNC;
63     if (SendRequest(*(want_.sid), SCHEDULER_DUMP_ABILITY, &req, nullptr, option, nullptr) != ERR_NONE) {
64         return AbilityMsStatus::AppTransanctStatus("dump ability ipc error");
65     }
66     return AbilityMsStatus::Ok();
67 }
68 }
69