• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/hardware/radio/1.1/IRadio.h>
18 #include <radio_hidl_hal_utils_v1_2.h>
19 
SetUp()20 void RadioHidlTest_v1_2::SetUp() {
21     radio_v1_2 =
22         ::testing::VtsHalHidlTargetTestBase::getService<::android::hardware::radio::V1_2::IRadio>(
23             RadioHidlEnvironment::Instance()
24                 ->getServiceName<::android::hardware::radio::V1_2::IRadio>(
25                     hidl_string(RADIO_SERVICE_NAME)));
26     if (radio_v1_2 == NULL) {
27         sleep(60);
28         radio_v1_2 = ::testing::VtsHalHidlTargetTestBase::getService<
29             ::android::hardware::radio::V1_2::IRadio>(
30             RadioHidlEnvironment::Instance()
31                 ->getServiceName<::android::hardware::radio::V1_2::IRadio>(
32                     hidl_string(RADIO_SERVICE_NAME)));
33     }
34     ASSERT_NE(nullptr, radio_v1_2.get());
35 
36     radioRsp_v1_2 = new (std::nothrow) RadioResponse_v1_2(*this);
37     ASSERT_NE(nullptr, radioRsp_v1_2.get());
38 
39     count_ = 0;
40     logicalSlotId = -1;
41 
42     radioInd_v1_2 = new (std::nothrow) RadioIndication_v1_2(*this);
43     ASSERT_NE(nullptr, radioInd_v1_2.get());
44 
45     radio_v1_2->setResponseFunctions(radioRsp_v1_2, radioInd_v1_2);
46 
47     updateSimCardStatus();
48     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
49     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
50     EXPECT_EQ(RadioError::NONE, radioRsp_v1_2->rspInfo.error);
51 
52     /* Enforce Vts Testing with Sim Status Present only. */
53     EXPECT_EQ(CardState::PRESENT, cardStatus.base.cardState);
54 
55     radioConfig = ::testing::VtsHalHidlTargetTestBase::getService<
56             ::android::hardware::radio::config::V1_1::IRadioConfig>();
57 
58     /* Enforce Vts tesing with RadioConfig for network scan excemption. */
59     // Some devices can only perform network scan on logical modem that currently used for packet
60     // data. This exemption is removed in HAL version 1.4. See b/135243177 for additional info.
61     if (radioConfig != NULL) {
62         // RadioConfig 1.1 available, some devices fall in excepmtion category.
63         ASSERT_NE(nullptr, radioConfig.get());
64 
65         radioConfigRsp = new (std::nothrow) RadioConfigResponse(*this);
66         ASSERT_NE(nullptr, radioConfigRsp.get());
67 
68         /* Set radio config response functions */
69         radioConfig->setResponseFunctions(radioConfigRsp, nullptr);
70 
71         /* set preferred data modem */
72         setPreferredDataModem();
73 
74         /* get current logical sim id */
75         getLogicalSimId();
76     }
77 }
78 
getLogicalSimId()79 void RadioHidlTest_v1_2::getLogicalSimId() {
80     serial = GetRandomSerialNumber();
81     radioConfig->getSimSlotsStatus(serial);
82     EXPECT_EQ(std::cv_status::no_timeout, wait());
83     EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
84     EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
85 
86     ASSERT_TRUE(CheckAnyOfErrors(radioConfigRsp->rspInfo.error,
87                                  {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
88 
89     if (radioConfigRsp->rspInfo.error != RadioError ::NONE) {
90         ALOGI("Failed to get sim slot status, rspInfo.error = %s\n",
91               toString(radioConfigRsp->rspInfo.error).c_str());
92         return;
93     }
94 
95     if (cardStatus.physicalSlotId < 0 ||
96         cardStatus.physicalSlotId >= radioConfigRsp->simSlotStatus.size()) {
97         ALOGI("Physical slot id: %d is out of range", cardStatus.physicalSlotId);
98         return;
99     }
100 
101     logicalSlotId = radioConfigRsp->simSlotStatus[cardStatus.physicalSlotId].logicalSlotId;
102 }
103 
104 /*
105  * Set preferred data modem
106  */
setPreferredDataModem()107 void RadioHidlTest_v1_2::setPreferredDataModem() {
108     serial = GetRandomSerialNumber();
109     // Even for single sim device, the setPreferredDataModem should still success. Enforce dds on
110     // first logical modem.
111     radioConfig->setPreferredDataModem(serial, DDS_LOGICAL_SLOT_INDEX);
112     EXPECT_EQ(std::cv_status::no_timeout, wait());
113     EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
114     EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
115 
116     ASSERT_TRUE(CheckAnyOfErrors(
117             radioConfigRsp->rspInfo.error,
118             {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
119 }
120 
121 /*
122  * Notify that the response message is received.
123  */
notify(int receivedSerial)124 void RadioHidlTest_v1_2::notify(int receivedSerial) {
125     std::unique_lock<std::mutex> lock(mtx_);
126     if (serial == receivedSerial) {
127         count_++;
128         cv_.notify_one();
129     }
130 }
131 
132 /*
133  * Wait till the response message is notified or till TIMEOUT_PERIOD.
134  */
wait()135 std::cv_status RadioHidlTest_v1_2::wait() {
136     std::unique_lock<std::mutex> lock(mtx_);
137 
138     std::cv_status status = std::cv_status::no_timeout;
139     auto now = std::chrono::system_clock::now();
140     while (count_ == 0) {
141         status = cv_.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
142         if (status == std::cv_status::timeout) {
143             return status;
144         }
145     }
146     count_--;
147     return status;
148 }
149 
updateSimCardStatus()150 void RadioHidlTest_v1_2::updateSimCardStatus() {
151     serial = GetRandomSerialNumber();
152     radio_v1_2->getIccCardStatus(serial);
153     EXPECT_EQ(std::cv_status::no_timeout, wait());
154 }
155 
stopNetworkScan()156 void RadioHidlTest_v1_2::stopNetworkScan() {
157     sp<::android::hardware::radio::V1_1::IRadio> radio_v1_1;
158 
159     radio_v1_1 = ::testing::VtsHalHidlTargetTestBase::getService<
160             ::android::hardware::radio::V1_1::IRadio>(
161             RadioHidlEnvironment::Instance()
162                     ->getServiceName<::android::hardware::radio::V1_1::IRadio>(
163                             hidl_string(RADIO_SERVICE_NAME)));
164     if (radio_v1_1 == NULL) {
165         sleep(60);
166         radio_v1_1 = ::testing::VtsHalHidlTargetTestBase::getService<
167                 ::android::hardware::radio::V1_1::IRadio>(
168                 RadioHidlEnvironment::Instance()
169                         ->getServiceName<::android::hardware::radio::V1_1::IRadio>(
170                                 hidl_string(RADIO_SERVICE_NAME)));
171     }
172     ASSERT_NE(nullptr, radio_v1_1.get());
173 
174     serial = GetRandomSerialNumber();
175 
176     radio_v1_1->stopNetworkScan(serial);
177     EXPECT_EQ(std::cv_status::no_timeout, wait());
178 }
179