OSDN Git Service

Merge cherrypicks of [3134552, 3130583, 3131953, 3131954, 3131955, 3131956, 3131957...
[android-x86/hardware-interfaces.git] / radio / 1.0 / vts / functional / sap_hidl_hal_utils.h
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <android-base/logging.h>
18
19 #include <VtsHalHidlTargetTestBase.h>
20 #include <chrono>
21 #include <condition_variable>
22 #include <mutex>
23
24 #include <android/hardware/radio/1.0/ISap.h>
25 #include <android/hardware/radio/1.0/ISapCallback.h>
26 #include <android/hardware/radio/1.0/types.h>
27
28 #include "vts_test_util.h"
29
30 using namespace ::android::hardware::radio::V1_0;
31
32 using ::android::hardware::hidl_string;
33 using ::android::hardware::hidl_vec;
34 using ::android::hardware::Return;
35 using ::android::hardware::Void;
36 using ::android::sp;
37
38 #define TIMEOUT_PERIOD 40
39 #define SAP_SERVICE_NAME "slot1"
40
41 class SapHidlTest;
42
43 /* Callback class for sap response */
44 class SapCallback : public ISapCallback {
45    private:
46     SapHidlTest& parent;
47
48    public:
49     SapResultCode sapResultCode;
50     int32_t sapResponseToken;
51
52     SapCallback(SapHidlTest& parent);
53
54     virtual ~SapCallback() = default;
55
56     Return<void> connectResponse(int32_t token, SapConnectRsp sapConnectRsp, int32_t maxMsgSize);
57
58     Return<void> disconnectResponse(int32_t token);
59
60     Return<void> disconnectIndication(int32_t token, SapDisconnectType disconnectType);
61
62     Return<void> apduResponse(int32_t token, SapResultCode resultCode,
63                               const ::android::hardware::hidl_vec<uint8_t>& apduRsp);
64
65     Return<void> transferAtrResponse(int32_t token, SapResultCode resultCode,
66                                      const ::android::hardware::hidl_vec<uint8_t>& atr);
67
68     Return<void> powerResponse(int32_t token, SapResultCode resultCode);
69
70     Return<void> resetSimResponse(int32_t token, SapResultCode resultCode);
71
72     Return<void> statusIndication(int32_t token, SapStatus status);
73
74     Return<void> transferCardReaderStatusResponse(int32_t token, SapResultCode resultCode,
75                                                   int32_t cardReaderStatus);
76
77     Return<void> errorResponse(int32_t token);
78
79     Return<void> transferProtocolResponse(int32_t token, SapResultCode resultCode);
80 };
81
82 // The main test class for Sap HIDL.
83 class SapHidlTest : public ::testing::VtsHalHidlTargetTestBase {
84    private:
85     std::mutex mtx;
86     std::condition_variable cv;
87     int count;
88
89    public:
90     virtual void SetUp() override;
91
92     virtual void TearDown() override;
93
94     /* Used as a mechanism to inform the test about data/event callback */
95     void notify();
96
97     /* Test code calls this function to wait for response */
98     std::cv_status wait();
99
100     /* Sap service */
101     sp<ISap> sap;
102
103     /* Sap Callback object */
104     sp<SapCallback> sapCb;
105 };
106
107 // A class for test environment setup
108 class SapHidlEnvironment : public ::testing::Environment {
109    public:
110     virtual void SetUp() {}
111     virtual void TearDown() {}
112 };