• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "liteipc_adapter.h"
20 #include "securec.h"
21 #include "util/abilityms_log.h"
22 
23 namespace OHOS {
AbilityDumpClient(const Want & want)24 AbilityDumpClient::AbilityDumpClient(const Want &want)
25 {
26     if (want.element != nullptr) {
27         SetWantElement(&want_, *(want.element));
28     }
29     if (want.data != nullptr) {
30         SetWantData(&want_, want.data, want.dataLength);
31     }
32     if (want.sid != nullptr) {
33         SetWantSvcIdentity(&want_, *(want.sid));
34     }
35 }
~AbilityDumpClient()36 AbilityDumpClient::~AbilityDumpClient()
37 {
38     ClearWant(&want_);
39 }
40 
GetWant() const41 const Want &AbilityDumpClient::GetWant() const
42 {
43     return want_;
44 }
45 
AbilityDumpTransaction(const char * info) const46 AbilityMsStatus AbilityDumpClient::AbilityDumpTransaction(const char *info) const
47 {
48     if (want_.sid == nullptr) {
49         return AbilityMsStatus::DumpStatus("null SvcIdentity");
50     }
51     PRINTD("AbilityThreadClient", "start");
52     if (info == nullptr) {
53         info = "";
54     }
55     IpcIo req;
56     char data[IPC_IO_DATA_MAX];
57     IpcIoInit(&req, data, IPC_IO_DATA_MAX, 1);
58 #ifdef __LINUX__
59     IpcIoPushString(&req, info);
60 #else
61     BuffPtr buffPtr;
62     buffPtr.buff = const_cast<char *>(info);
63     buffPtr.buffSz = strlen(info) + 1;
64     IpcIoPushDataBuff(&req, &buffPtr);
65 #endif
66     if (Transact(nullptr, *(want_.sid), SCHEDULER_DUMP_ABILITY, &req, nullptr,
67         LITEIPC_FLAG_ONEWAY, nullptr) != LITEIPC_OK) {
68         return AbilityMsStatus::AppTransanctStatus("dump ability ipc error");
69     }
70     return AbilityMsStatus::Ok();
71 }
72 }
73