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 #define LOG_TAG "RadioTest"
17
18 #include <vts_test_util.h>
19 #include <iostream>
20 #include "VtsCoreUtil.h"
21
GetRandomSerialNumber()22 int GetRandomSerialNumber() {
23 return rand();
24 }
25
CheckAnyOfErrors(RadioError err,std::vector<RadioError> errors,CheckFlag flag)26 ::testing::AssertionResult CheckAnyOfErrors(RadioError err, std::vector<RadioError> errors,
27 CheckFlag flag) {
28 const static vector<RadioError> generalErrors = {
29 RadioError::RADIO_NOT_AVAILABLE, RadioError::NO_MEMORY,
30 RadioError::INTERNAL_ERR, RadioError::SYSTEM_ERR,
31 RadioError::REQUEST_NOT_SUPPORTED, RadioError::CANCELLED};
32 if (flag == CHECK_GENERAL_ERROR || flag == CHECK_OEM_AND_GENERAL_ERROR) {
33 for (size_t i = 0; i < generalErrors.size(); i++) {
34 if (err == generalErrors[i]) {
35 return testing::AssertionSuccess();
36 }
37 }
38 }
39 if (flag == CHECK_OEM_ERROR || flag == CHECK_OEM_AND_GENERAL_ERROR) {
40 if (err >= RadioError::OEM_ERROR_1 && err <= RadioError::OEM_ERROR_25) {
41 return testing::AssertionSuccess();
42 }
43 }
44 for (size_t i = 0; i < errors.size(); i++) {
45 if (err == errors[i]) {
46 return testing::AssertionSuccess();
47 }
48 }
49 return testing::AssertionFailure() << "RadioError:" + toString(err) + " is returned";
50 }
51
CheckAnyOfErrors(SapResultCode err,std::vector<SapResultCode> errors)52 ::testing::AssertionResult CheckAnyOfErrors(SapResultCode err, std::vector<SapResultCode> errors) {
53 for (size_t i = 0; i < errors.size(); i++) {
54 if (err == errors[i]) {
55 return testing::AssertionSuccess();
56 }
57 }
58 return testing::AssertionFailure() << "SapError:" + toString(err) + " is returned";
59 }
60
61 // Runs "pm list features" and attempts to find the specified feature in its output.
deviceSupportsFeature(const char * feature)62 bool deviceSupportsFeature(const char* feature) {
63 bool hasFeature = false;
64 FILE* p = popen("/system/bin/pm list features", "re");
65 if (p) {
66 char* line = NULL;
67 size_t len = 0;
68 while (getline(&line, &len, p) > 0) {
69 if (strstr(line, feature)) {
70 hasFeature = true;
71 break;
72 }
73 }
74 pclose(p);
75 } else {
76 __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, "popen failed: %d", errno);
77 _exit(EXIT_FAILURE);
78 }
79 __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Feature %s: %ssupported", feature,
80 hasFeature ? "" : "not ");
81 return hasFeature;
82 }
83
isDsDsEnabled()84 bool isDsDsEnabled() {
85 return testing::checkSubstringInCommandOutput("getprop persist.radio.multisim.config", "dsds");
86 }
87
isTsTsEnabled()88 bool isTsTsEnabled() {
89 return testing::checkSubstringInCommandOutput("getprop persist.radio.multisim.config", "tsts");
90 }
91
isVoiceInService(RegState state)92 bool isVoiceInService(RegState state) {
93 return ::android::hardware::radio::V1_0::RegState::REG_HOME == state ||
94 ::android::hardware::radio::V1_0::RegState::REG_ROAMING == state;
95 }
96
isVoiceEmergencyOnly(RegState state)97 bool isVoiceEmergencyOnly(RegState state) {
98 return ::android::hardware::radio::V1_0::RegState::NOT_REG_MT_NOT_SEARCHING_OP_EM == state ||
99 ::android::hardware::radio::V1_0::RegState::NOT_REG_MT_SEARCHING_OP_EM == state ||
100 ::android::hardware::radio::V1_0::RegState::REG_DENIED_EM == state ||
101 ::android::hardware::radio::V1_0::RegState::UNKNOWN_EM == state;
102 }