xref: /aosp_15_r20/hardware/interfaces/radio/aidl/vts/radio_sap_utils.h (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright (C) 2022 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 #pragma once
17 
18 #include <aidl/Gtest.h>
19 #include <aidl/android/hardware/radio/sap/BnSapCallback.h>
20 #include <aidl/android/hardware/radio/sap/ISap.h>
21 
22 #include "radio_aidl_hal_utils.h"
23 
24 using namespace aidl::android::hardware::radio::sap;
25 
26 class SapTest;
27 
28 /* Callback class for radio sap response */
29 class SapCallback : public BnSapCallback {
30   protected:
31     SapTest& parent_sap;
32 
33   public:
34     SapCallback(SapTest& parent_config);
35     virtual ~SapCallback() = default;
36 
37     int32_t sapResponseSerial;
38     SapResultCode sapResultCode;
39 
40     virtual ::ndk::ScopedAStatus apduResponse(int32_t serial, SapResultCode resultCode,
41                                               const std::vector<uint8_t>& adpuRsp) override;
42 
43     virtual ::ndk::ScopedAStatus connectResponse(int32_t serial, SapConnectRsp sapConnectRsp,
44                                                  int32_t maxMsgSize) override;
45 
46     virtual ::ndk::ScopedAStatus disconnectIndication(int32_t serial,
47                                                       SapDisconnectType sapDisconnectType) override;
48 
49     virtual ::ndk::ScopedAStatus disconnectResponse(int32_t serial) override;
50 
51     virtual ::ndk::ScopedAStatus errorResponse(int32_t serial) override;
52 
53     virtual ::ndk::ScopedAStatus powerResponse(int32_t serial, SapResultCode resultCode) override;
54 
55     virtual ::ndk::ScopedAStatus resetSimResponse(int32_t serial,
56                                                   SapResultCode resultCode) override;
57 
58     virtual ::ndk::ScopedAStatus statusIndication(int32_t serial, SapStatus sapStatus) override;
59 
60     virtual ::ndk::ScopedAStatus transferAtrResponse(int32_t serial, SapResultCode resultCode,
61                                                      const std::vector<uint8_t>& atr) override;
62 
63     virtual ::ndk::ScopedAStatus transferCardReaderStatusResponse(
64             int32_t serial, SapResultCode resultCode, int32_t cardReaderStatus) override;
65 
66     virtual ::ndk::ScopedAStatus transferProtocolResponse(int32_t serial,
67                                                           SapResultCode resultCode) override;
68 };
69 
70 // The main test class for  AIDL SAP.
71 class SapTest : public ::testing::TestWithParam<std::string> {
72   private:
73     std::mutex mtx;
74     std::condition_variable cv;
75     int count;
76 
77   public:
78     virtual void SetUp() override;
79 
80     virtual void TearDown() override;
81 
82     ::testing::AssertionResult CheckAnyOfErrors(SapResultCode err,
83                                                 std::vector<SapResultCode> errors);
84 
85     /* Used as a mechanism to inform the test about data/event callback */
86     void notify(int receivedSerial);
87 
88     /* Test code calls this function to wait for response */
89     std::cv_status wait();
90 
91     /* Sap service */
92     std::shared_ptr<ISap> sap;
93 
94     /* Sap Callback object */
95     std::shared_ptr<SapCallback> sapCb;
96 
97     /* Serial for sap request */
98     int32_t serial;
99 };
100