1 /* 2 * Copyright 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 package com.android.internal.telephony.data; 18 19 import static org.junit.Assert.assertNotEquals; 20 21 import android.net.InetAddresses; 22 import android.net.LinkAddress; 23 import android.os.Parcel; 24 import android.telephony.PreciseDataConnectionState; 25 import android.telephony.data.ApnSetting; 26 import android.telephony.data.DataCallResponse; 27 import android.telephony.data.EpsQos; 28 import android.telephony.data.Qos; 29 import android.telephony.data.TrafficDescriptor; 30 import android.test.AndroidTestCase; 31 32 import androidx.test.filters.SmallTest; 33 34 import java.util.ArrayList; 35 import java.util.Arrays; 36 37 public class DataCallResponseTest extends AndroidTestCase { 38 private static final String FAKE_ADDRESS = "99.88.77.66"; 39 private static final String FAKE_DNS = "55.66.77.88"; 40 private static final String FAKE_DNN = "FAKE_DNN"; 41 private static final String FAKE_DNN_2 = "FAKE_DNN_2"; 42 private static final String FAKE_GATEWAY = "11.22.33.44"; 43 private static final String FAKE_IFNAME = "FAKE IFNAME"; 44 private static final String FAKE_PCSCF_ADDRESS = "22.33.44.55"; 45 // 97a498e3fc925c9489860333d06e4e470a454e5445525052495345. 46 // [OsAppId.ANDROID_OS_ID, "ENTERPRISE", 1] 47 private static final byte[] FAKE_OS_APP_ID = {-105, -92, -104, -29, -4, -110, 92, 48 -108, -119, -122, 3, 51, -48, 110, 78, 71, 10, 69, 78, 84, 69, 49 82, 80, 82, 73, 83, 69}; 50 // 97a498e3fc925c9489860333d06e4e470a454e544552505249534532. 51 // [OsAppId.ANDROID_OS_ID, "ENTERPRISE", 2] 52 private static final byte[] FAKE_OS_APP_ID_2 = {-105, -92, -104, -29, -4, -110, 92, 53 -108, -119, -122, 3, 51, -48, 110, 78, 71, 10, 69, 78, 84, 69, 54 82, 80, 82, 73, 83, 69, 50}; 55 56 @SmallTest testParcel()57 public void testParcel() { 58 DataCallResponse response = new DataCallResponse.Builder() 59 .setCause(0) 60 .setRetryDurationMillis(-1L) 61 .setId(1) 62 .setLinkStatus(2) 63 .setProtocolType(ApnSetting.PROTOCOL_IP) 64 .setInterfaceName(FAKE_IFNAME) 65 .setAddresses(Arrays.asList( 66 new LinkAddress(InetAddresses.parseNumericAddress(FAKE_ADDRESS), 0))) 67 .setDnsAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_DNS))) 68 .setGatewayAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_GATEWAY))) 69 .setPcscfAddresses( 70 Arrays.asList(InetAddresses.parseNumericAddress(FAKE_PCSCF_ADDRESS))) 71 .setMtuV4(1440) 72 .setMtuV6(1440) 73 .setDefaultQos(new EpsQos( 74 new Qos.QosBandwidth(-1, -1), new Qos.QosBandwidth(-1, -1), -1)) 75 .setQosBearerSessions(new ArrayList<>()) 76 .setTrafficDescriptors( 77 Arrays.asList(new TrafficDescriptor(FAKE_DNN, FAKE_OS_APP_ID))) 78 .setNetworkValidationStatus( 79 PreciseDataConnectionState.NETWORK_VALIDATION_UNSUPPORTED) 80 .build(); 81 82 Parcel p = Parcel.obtain(); 83 response.writeToParcel(p, 0); 84 p.setDataPosition(0); 85 86 DataCallResponse newResponse = new DataCallResponse(p); 87 assertEquals(response, newResponse); 88 } 89 90 @SmallTest testEqualsAndHashCode()91 public void testEqualsAndHashCode() { 92 DataCallResponse response = new DataCallResponse.Builder() 93 .setCause(0) 94 .setRetryDurationMillis(-1L) 95 .setId(1) 96 .setLinkStatus(2) 97 .setProtocolType(ApnSetting.PROTOCOL_IP) 98 .setInterfaceName(FAKE_IFNAME) 99 .setAddresses(Arrays.asList( 100 new LinkAddress(InetAddresses.parseNumericAddress(FAKE_ADDRESS), 0))) 101 .setDnsAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_DNS))) 102 .setGatewayAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_GATEWAY))) 103 .setPcscfAddresses( 104 Arrays.asList(InetAddresses.parseNumericAddress(FAKE_PCSCF_ADDRESS))) 105 .setMtuV4(1440) 106 .setMtuV6(1400) 107 .setTrafficDescriptors( 108 Arrays.asList(new TrafficDescriptor(FAKE_DNN, FAKE_OS_APP_ID))) 109 .setNetworkValidationStatus( 110 PreciseDataConnectionState.NETWORK_VALIDATION_IN_PROGRESS) 111 .build(); 112 113 DataCallResponse response1 = new DataCallResponse.Builder() 114 .setCause(0) 115 .setRetryDurationMillis(-1L) 116 .setId(1) 117 .setLinkStatus(2) 118 .setProtocolType(ApnSetting.PROTOCOL_IP) 119 .setInterfaceName(FAKE_IFNAME) 120 .setAddresses(Arrays.asList( 121 new LinkAddress(InetAddresses.parseNumericAddress(FAKE_ADDRESS), 0))) 122 .setDnsAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_DNS))) 123 .setGatewayAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_GATEWAY))) 124 .setPcscfAddresses( 125 Arrays.asList(InetAddresses.parseNumericAddress(FAKE_PCSCF_ADDRESS))) 126 .setMtuV4(1440) 127 .setMtuV6(1400) 128 .setTrafficDescriptors( 129 Arrays.asList(new TrafficDescriptor(FAKE_DNN, FAKE_OS_APP_ID))) 130 .setNetworkValidationStatus( 131 PreciseDataConnectionState.NETWORK_VALIDATION_IN_PROGRESS) 132 .build(); 133 134 assertEquals(response, response); 135 assertEquals(response, response1); 136 assertEquals(response.hashCode(), response1.hashCode()); 137 138 DataCallResponse response2 = new DataCallResponse.Builder() 139 .setCause(1) 140 .setRetryDurationMillis(-1L) 141 .setId(1) 142 .setLinkStatus(3) 143 .setProtocolType(ApnSetting.PROTOCOL_IP) 144 .setInterfaceName(FAKE_IFNAME) 145 .setAddresses(Arrays.asList( 146 new LinkAddress(InetAddresses.parseNumericAddress(FAKE_ADDRESS), 0))) 147 .setDnsAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_DNS), 148 InetAddresses.parseNumericAddress(FAKE_DNS))) 149 .setGatewayAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_GATEWAY))) 150 .setPcscfAddresses(Arrays.asList( 151 InetAddresses.parseNumericAddress(FAKE_PCSCF_ADDRESS), 152 InetAddresses.parseNumericAddress(FAKE_PCSCF_ADDRESS))) 153 .setMtuV4(1441) 154 .setMtuV6(1440) 155 .setTrafficDescriptors(Arrays.asList( 156 new TrafficDescriptor(FAKE_DNN, FAKE_OS_APP_ID), 157 new TrafficDescriptor(FAKE_DNN_2, FAKE_OS_APP_ID_2))) 158 .setNetworkValidationStatus(PreciseDataConnectionState.NETWORK_VALIDATION_SUCCESS) 159 .build(); 160 161 assertNotSame(response1, response2); 162 assertNotSame(response1, null); 163 assertNotSame(response1, new String[1]); 164 assertNotEquals(response1.getNetworkValidationStatus(), 165 response2.getNetworkValidationStatus()); 166 assertNotSame(response1.hashCode(), response2.hashCode()); 167 168 DataCallResponse response3 = new DataCallResponse.Builder() 169 .setCause(1) 170 .setRetryDurationMillis(-1L) 171 .setId(1) 172 .setLinkStatus(3) 173 .setProtocolType(ApnSetting.PROTOCOL_IP) 174 .setInterfaceName(FAKE_IFNAME) 175 .setAddresses(Arrays.asList( 176 new LinkAddress(InetAddresses.parseNumericAddress(FAKE_ADDRESS), 0))) 177 .setDnsAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_DNS), 178 InetAddresses.parseNumericAddress(FAKE_DNS))) 179 .setGatewayAddresses(Arrays.asList(InetAddresses.parseNumericAddress(FAKE_GATEWAY))) 180 .setPcscfAddresses(Arrays.asList( 181 InetAddresses.parseNumericAddress(FAKE_PCSCF_ADDRESS), 182 InetAddresses.parseNumericAddress(FAKE_PCSCF_ADDRESS))) 183 .setMtuV4(1441) 184 .setMtuV6(1440) 185 .setTrafficDescriptors(Arrays.asList( 186 new TrafficDescriptor(FAKE_DNN_2, FAKE_OS_APP_ID_2), 187 new TrafficDescriptor(FAKE_DNN, FAKE_OS_APP_ID))) 188 .setNetworkValidationStatus(PreciseDataConnectionState.NETWORK_VALIDATION_SUCCESS) 189 .build(); 190 191 assertEquals(response2, response3); 192 assertEquals(response2.getNetworkValidationStatus(), 193 response3.getNetworkValidationStatus()); 194 assertEquals(response2.hashCode(), response3.hashCode()); 195 } 196 } 197