1 /*
2 * Copyright (c) 2022 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 "test_observer_stub.h"
17 #include "hilog_wrapper.h"
18
19 namespace OHOS {
20 namespace AAFwk {
TestObserverStub()21 TestObserverStub::TestObserverStub()
22 {
23 HILOG_INFO("test observer stub instance is created");
24 }
25
~TestObserverStub()26 TestObserverStub::~TestObserverStub()
27 {
28 HILOG_INFO("test observer stub instance is destroyed");
29 }
30
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int TestObserverStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
32 {
33 if (data.ReadInterfaceToken() != GetDescriptor()) {
34 HILOG_ERROR("local descriptor is not equal to remote");
35 return ERR_TRANSACTION_FAILED;
36 }
37 switch (code) {
38 case static_cast<uint32_t>(ITestObserver::Message::AA_TEST_STATUS): {
39 std::string msg = data.ReadString();
40 int64_t resultCode = data.ReadInt64();
41 TestStatus(msg, resultCode);
42 break;
43 }
44 case static_cast<uint32_t>(ITestObserver::Message::AA_TEST_FINISHED): {
45 std::string msg = data.ReadString();
46 int64_t resultCode = data.ReadInt64();
47 TestFinished(msg, resultCode);
48 break;
49 }
50 case static_cast<uint32_t>(ITestObserver::Message::AA_EXECUTE_SHELL_COMMAND): {
51 std::string cmd = data.ReadString();
52 int64_t timeoutSecs = data.ReadInt64();
53 ShellCommandResult result = ExecuteShellCommand(cmd, timeoutSecs);
54 if (!reply.WriteParcelable(&result)) {
55 HILOG_ERROR("Failed to write reply ShellCommandResult!");
56 return ERR_INVALID_VALUE;
57 }
58 break;
59 }
60 default:
61 HILOG_WARN("event receive stub receives unknown code, code = %{public}u", code);
62 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
63 }
64
65 return NO_ERROR;
66 }
67 } // namespace AAFwk
68 } // namespace OHOS
69