1 /* 2 * Copyright (C) 2018 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 <VtsHalHidlTargetTestEnvBase.h> 21 #include <chrono> 22 #include <condition_variable> 23 #include <mutex> 24 25 #include <android/hardware/radio/config/1.0/IRadioConfig.h> 26 #include <android/hardware/radio/config/1.0/IRadioConfigIndication.h> 27 #include <android/hardware/radio/config/1.0/IRadioConfigResponse.h> 28 #include <android/hardware/radio/config/1.0/types.h> 29 30 #include "vts_test_util.h" 31 32 using namespace ::android::hardware::radio::config::V1_0; 33 34 using ::android::hardware::Return; 35 using ::android::hardware::Void; 36 using ::android::hardware::hidl_string; 37 using ::android::hardware::hidl_vec; 38 using ::android::hardware::radio::V1_0::RadioIndicationType; 39 using ::android::hardware::radio::V1_0::RadioResponseInfo; 40 using ::android::hardware::radio::V1_0::RadioResponseType; 41 using ::android::sp; 42 43 #define TIMEOUT_PERIOD 75 44 #define RADIO_SERVICE_NAME "slot1" 45 46 class RadioConfigHidlTest; 47 48 /* Callback class for radio config response */ 49 class RadioConfigResponse : public IRadioConfigResponse { 50 protected: 51 RadioConfigHidlTest& parent; 52 53 public: 54 RadioResponseInfo rspInfo; 55 56 RadioConfigResponse(RadioConfigHidlTest& parent); 57 virtual ~RadioConfigResponse() = default; 58 59 Return<void> getSimSlotsStatusResponse( 60 const RadioResponseInfo& info, 61 const ::android::hardware::hidl_vec<SimSlotStatus>& slotStatus); 62 63 Return<void> setSimSlotsMappingResponse(const RadioResponseInfo& info); 64 }; 65 66 /* Callback class for radio config indication */ 67 class RadioConfigIndication : public IRadioConfigIndication { 68 protected: 69 RadioConfigHidlTest& parent; 70 71 public: 72 RadioConfigIndication(RadioConfigHidlTest& parent); 73 virtual ~RadioConfigIndication() = default; 74 75 Return<void> simSlotsStatusChanged( 76 RadioIndicationType type, const ::android::hardware::hidl_vec<SimSlotStatus>& slotStatus); 77 }; 78 79 // Test environment for Radio HIDL HAL. 80 class RadioConfigHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { 81 public: 82 // get the test environment singleton 83 static RadioConfigHidlEnvironment* Instance() { 84 static RadioConfigHidlEnvironment* instance = new RadioConfigHidlEnvironment; 85 return instance; 86 } 87 virtual void registerTestServices() override { registerTestService<IRadioConfig>(); } 88 89 private: 90 RadioConfigHidlEnvironment() {} 91 }; 92 93 // The main test class for Radio config HIDL. 94 class RadioConfigHidlTest : public ::testing::VtsHalHidlTargetTestBase { 95 protected: 96 std::mutex mtx_; 97 std::condition_variable cv_; 98 int count_; 99 100 public: 101 virtual void SetUp() override; 102 103 /* Used as a mechanism to inform the test about data/event callback */ 104 void notify(); 105 106 /* Test code calls this function to wait for response */ 107 std::cv_status wait(); 108 109 /* radio config service handle */ 110 sp<IRadioConfig> radioConfig; 111 112 /* radio config response handle */ 113 sp<RadioConfigResponse> radioConfigRsp; 114 115 /* radio config indication handle */ 116 sp<RadioConfigIndication> radioConfigInd; 117 }; 118