blob: 43b63e8209f88543555b41fbb0b35767edd24014 [file] [log] [blame]
Sarah Chin91997ac2021-12-29 00:35:12 -08001/*
2 * Copyright (C) 2021 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#include <android/binder_manager.h>
19
20#include "radio_config_utils.h"
21
22#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
23
24void RadioConfigTest::SetUp() {
25 std::string serviceName = GetParam();
26
Sarah Chin91997ac2021-12-29 00:35:12 -080027 radio_config = IRadioConfig::fromBinder(
28 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
29 ASSERT_NE(nullptr, radio_config.get());
30
31 radioRsp_config = ndk::SharedRefBase::make<RadioConfigResponse>(*this);
32 ASSERT_NE(nullptr, radioRsp_config.get());
33
34 count_ = 0;
35
36 radioInd_config = ndk::SharedRefBase::make<RadioConfigIndication>(*this);
37 ASSERT_NE(nullptr, radioInd_config.get());
38
39 radio_config->setResponseFunctions(radioRsp_config, radioInd_config);
40}
41
42/*
43 * Test IRadioConfig.getHalDeviceCapabilities() for the response returned.
44 */
45TEST_P(RadioConfigTest, getHalDeviceCapabilities) {
46 serial = GetRandomSerialNumber();
47 ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial);
48 ASSERT_OK(res);
49 ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n",
50 toString(radioRsp_config->rspInfo.error).c_str());
51}
Sarah Chin52de0ad2022-01-28 01:02:16 -080052
53/*
54 * Test IRadioConfig.getSimSlotsStatus() for the response returned.
55 */
56TEST_P(RadioConfigTest, getSimSlotsStatus) {
57 serial = GetRandomSerialNumber();
58 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
59 ASSERT_OK(res);
60 ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
61 toString(radioRsp_config->rspInfo.error).c_str());
62}
63
64/*
65 * Test IRadioConfig.getPhoneCapability() for the response returned.
66 */
67TEST_P(RadioConfigTest, getPhoneCapability) {
68 serial = GetRandomSerialNumber();
69 ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial);
70 ASSERT_OK(res);
71 EXPECT_EQ(std::cv_status::no_timeout, wait());
72 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
73 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
74 ALOGI("getPhoneCapability, rspInfo.error = %s\n",
75 toString(radioRsp_config->rspInfo.error).c_str());
76
77 ASSERT_TRUE(CheckAnyOfErrors(
78 radioRsp_config->rspInfo.error,
79 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
80
81 if (radioRsp_config->rspInfo.error == RadioError ::NONE) {
82 // maxActiveData should be greater than or equal to maxActiveInternetData.
83 EXPECT_GE(radioRsp_config->phoneCap.maxActiveData,
84 radioRsp_config->phoneCap.maxActiveInternetData);
85 // maxActiveData and maxActiveInternetData should be 0 or positive numbers.
86 EXPECT_GE(radioRsp_config->phoneCap.maxActiveInternetData, 0);
87 }
88}
89
90/*
91 * Test IRadioConfig.setPreferredDataModem() for the response returned.
92 */
93TEST_P(RadioConfigTest, setPreferredDataModem) {
94 serial = GetRandomSerialNumber();
95 ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial);
96 ASSERT_OK(res);
97 EXPECT_EQ(std::cv_status::no_timeout, wait());
98 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
99 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
100 ALOGI("getPhoneCapability, rspInfo.error = %s\n",
101 toString(radioRsp_config->rspInfo.error).c_str());
102
103 ASSERT_TRUE(CheckAnyOfErrors(
104 radioRsp_config->rspInfo.error,
105 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
106
107 if (radioRsp_config->rspInfo.error != RadioError ::NONE) {
108 return;
109 }
110
111 if (radioRsp_config->phoneCap.logicalModemIds.size() == 0) {
112 return;
113 }
114
115 // We get phoneCapability. Send setPreferredDataModem command
116 serial = GetRandomSerialNumber();
117 uint8_t modemId = radioRsp_config->phoneCap.logicalModemIds[0];
118 res = radio_config->setPreferredDataModem(serial, modemId);
119
120 ASSERT_OK(res);
121 EXPECT_EQ(std::cv_status::no_timeout, wait());
122 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
123 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
124 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
125 toString(radioRsp_config->rspInfo.error).c_str());
126
127 ASSERT_TRUE(CheckAnyOfErrors(
128 radioRsp_config->rspInfo.error,
129 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
130}
131
132/*
133 * Test IRadioConfig.setPreferredDataModem() with invalid arguments.
134 */
135TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) {
136 serial = GetRandomSerialNumber();
137 uint8_t modemId = -1;
138 ndk::ScopedAStatus res = radio_config->setPreferredDataModem(serial, modemId);
139
140 ASSERT_OK(res);
141 EXPECT_EQ(std::cv_status::no_timeout, wait());
142 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
143 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
144 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
145 toString(radioRsp_config->rspInfo.error).c_str());
146
147 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error,
148 {RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE,
149 RadioError::INTERNAL_ERR}));
150}