Loading src/java/com/android/internal/telephony/data/QosCallbackTracker.java +38 −1 Original line number Diff line number Diff line Loading @@ -80,12 +80,20 @@ public class QosCallbackTracker extends Handler { /** * Filter using the remote address. * * @param address The local address. * @param address The remote address. * @param startPort Starting port. * @param endPort Ending port. * @return {@code true} if matches, {@code false} otherwise. */ boolean matchesRemoteAddress(InetAddress address, int startPort, int endPort); /** * Filter using the protocol * * @param protocol ID * @return {@code true} if matches, {@code false} otherwise. */ boolean matchesProtocol(int protocol); } /** Loading Loading @@ -124,6 +132,11 @@ public class QosCallbackTracker extends Handler { return filter.matchesRemoteAddress(address, startPort, endPort); } @Override public boolean matchesProtocol(int protocol) { return filter.matchesProtocol(protocol); } }); } Loading Loading @@ -332,6 +345,21 @@ public class QosCallbackTracker extends Handler { return result; } private boolean matchesByProtocol(@NonNull QosBearerFilter sessionFilter, final @NonNull IFilter filter, boolean hasMatchedFilter) { boolean result = false; int protocol = sessionFilter.getProtocol(); if (protocol == QosBearerFilter.QOS_PROTOCOL_TCP || protocol == QosBearerFilter.QOS_PROTOCOL_UDP) { result = filter.matchesProtocol(protocol); } else { // FWK currently doesn't support filtering based on protocol ID ESP & AH. We will follow // match results of other filters. result = hasMatchedFilter; } return result; } private QosBearerFilter getFilterByPrecedence( @Nullable QosBearerFilter qosFilter, QosBearerFilter sessionFilter) { // Find for the highest precedence filter, lower the value is the higher the precedence Loading Loading @@ -362,6 +390,15 @@ public class QosCallbackTracker extends Handler { hasMatchedFilter = true; } } if (sessionFilter.getProtocol() != QosBearerFilter.QOS_PROTOCOL_UNSPECIFIED) { if (!matchesByProtocol(sessionFilter, filter, hasMatchedFilter)) { unMatched = true; } else { hasMatchedFilter = true; } } if (!unMatched && hasMatchedFilter) { qosFilter = getFilterByPrecedence(qosFilter, sessionFilter); } Loading tests/telephonytests/src/com/android/internal/telephony/data/QosCallbackTrackerTest.java +81 −1 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ public class QosCallbackTrackerTest extends TelephonyTest { class Filter implements QosCallbackTracker.IFilter { InetSocketAddress mLocalAddress; InetSocketAddress mRemoteAddress; int mProtocol = QosBearerFilter.QOS_PROTOCOL_TCP; Filter(@NonNull final InetSocketAddress localAddress) { this.mLocalAddress = localAddress; Loading @@ -87,6 +88,10 @@ public class QosCallbackTrackerTest extends TelephonyTest { && endPort >= mRemoteAddress.getPort() && (address.isAnyLocalAddress() || mRemoteAddress.getAddress().equals(address)); } public boolean matchesProtocol(int protocol) { return mProtocol == protocol; } } // Mocked classes Loading Loading @@ -151,6 +156,13 @@ public class QosCallbackTrackerTest extends TelephonyTest { private static QosBearerFilter createIpv4QosFilter(String localAddress, String remoteAddress, QosBearerFilter.PortRange localPort, QosBearerFilter.PortRange remotePort, int precedence) { return createIpv4QosFilter(localAddress, remoteAddress, localPort, remotePort, QosBearerFilter.QOS_PROTOCOL_TCP, precedence); } private static QosBearerFilter createIpv4QosFilter(String localAddress, String remoteAddress, QosBearerFilter.PortRange localPort, QosBearerFilter.PortRange remotePort, int protocol, int precedence) { ArrayList<LinkAddress> localAddresses = new ArrayList<>(); if (localAddress != null) { localAddresses.add( Loading @@ -163,7 +175,7 @@ public class QosCallbackTrackerTest extends TelephonyTest { } return new QosBearerFilter( localAddresses, remoteAddresses, localPort, remotePort, QosBearerFilter.QOS_PROTOCOL_TCP, 7, 987, 678, protocol, 7, 987, 678, QosBearerFilter.QOS_FILTER_DIRECTION_BIDIRECTIONAL, precedence); } Loading Loading @@ -541,6 +553,74 @@ public class QosCallbackTrackerTest extends TelephonyTest { verify(mINetworkAgentRegistry, times(1)).sendQosSessionLost(eq(1), any(QosSession.class)); } @Test public void testQosSessionFilterProtocol() throws Exception { // QosBearerFilter including protocol ArrayList<QosBearerFilter> qosFilters1 = new ArrayList<>(); qosFilters1.add(createIpv4QosFilter(null, null, null, new QosBearerFilter.PortRange(3200, 3220), QosBearerFilter.QOS_PROTOCOL_UDP, 45)); ArrayList<QosBearerSession> qosSessions = new ArrayList<>(); qosSessions.add(new QosBearerSession(1234, createEpsQos(5, 6, 7, 8), qosFilters1)); mQosCallbackTracker.updateSessions(qosSessions); // Add filter after updateSessions Filter filter = new Filter(new InetSocketAddress( InetAddresses.parseNumericAddress("122.22.22.22"), 1357), new InetSocketAddress(InetAddresses.parseNumericAddress("177.77.77.77"), 3207)); mQosCallbackTracker.addFilter(1, filter); processAllMessages(); verify(mINetworkAgentRegistry, never()).sendEpsQosSessionAvailable(eq(1), any(QosSession.class), any(EpsBearerQosSessionAttributes.class)); // Remove the matching QosBearerFilter qosSessions.remove(0); mQosCallbackTracker.updateSessions(qosSessions); processAllMessages(); verify(mINetworkAgentRegistry, never()).sendQosSessionLost(eq(1), any(QosSession.class)); qosFilters1.clear(); qosFilters1.add(createIpv4QosFilter(null, null, null, new QosBearerFilter.PortRange(3200, 3220), QosBearerFilter.QOS_PROTOCOL_TCP, 45)); qosSessions.clear(); qosSessions.add(new QosBearerSession(1234, createEpsQos(5, 6, 7, 8), qosFilters1)); mQosCallbackTracker.updateSessions(qosSessions); processAllMessages(); verify(mINetworkAgentRegistry, times(1)).sendEpsQosSessionAvailable(eq(1), any(QosSession.class), any(EpsBearerQosSessionAttributes.class)); qosSessions.remove(0); mQosCallbackTracker.updateSessions(qosSessions); processAllMessages(); verify(mINetworkAgentRegistry, times(1)).sendQosSessionLost(eq(1), any(QosSession.class)); } @Test public void testQosSessionFilterProtocolEsp() throws Exception { // QosBearerFilter including protocol ArrayList<QosBearerFilter> qosFilters1 = new ArrayList<>(); qosFilters1.add(createIpv4QosFilter(null, null, null, new QosBearerFilter.PortRange(3200, 3220), QosBearerFilter.QOS_PROTOCOL_ESP, 45)); ArrayList<QosBearerSession> qosSessions = new ArrayList<>(); qosSessions.add(new QosBearerSession(1234, createEpsQos(5, 6, 7, 8), qosFilters1)); mQosCallbackTracker.updateSessions(qosSessions); // Add filter after updateSessions Filter filter = new Filter(new InetSocketAddress( InetAddresses.parseNumericAddress("122.22.22.22"), 1357), new InetSocketAddress(InetAddresses.parseNumericAddress("177.77.77.77"), 3211)); mQosCallbackTracker.addFilter(1, filter); processAllMessages(); verify(mINetworkAgentRegistry, times(1)).sendEpsQosSessionAvailable(eq(1), any(QosSession.class), any(EpsBearerQosSessionAttributes.class)); // Remove the matching QosBearerFilter qosSessions.remove(0); mQosCallbackTracker.updateSessions(qosSessions); processAllMessages(); verify(mINetworkAgentRegistry, times(1)).sendQosSessionLost(eq(1), any(QosSession.class)); } @Test public void testQosMetrics() { final int callbackId = 1; Loading Loading
src/java/com/android/internal/telephony/data/QosCallbackTracker.java +38 −1 Original line number Diff line number Diff line Loading @@ -80,12 +80,20 @@ public class QosCallbackTracker extends Handler { /** * Filter using the remote address. * * @param address The local address. * @param address The remote address. * @param startPort Starting port. * @param endPort Ending port. * @return {@code true} if matches, {@code false} otherwise. */ boolean matchesRemoteAddress(InetAddress address, int startPort, int endPort); /** * Filter using the protocol * * @param protocol ID * @return {@code true} if matches, {@code false} otherwise. */ boolean matchesProtocol(int protocol); } /** Loading Loading @@ -124,6 +132,11 @@ public class QosCallbackTracker extends Handler { return filter.matchesRemoteAddress(address, startPort, endPort); } @Override public boolean matchesProtocol(int protocol) { return filter.matchesProtocol(protocol); } }); } Loading Loading @@ -332,6 +345,21 @@ public class QosCallbackTracker extends Handler { return result; } private boolean matchesByProtocol(@NonNull QosBearerFilter sessionFilter, final @NonNull IFilter filter, boolean hasMatchedFilter) { boolean result = false; int protocol = sessionFilter.getProtocol(); if (protocol == QosBearerFilter.QOS_PROTOCOL_TCP || protocol == QosBearerFilter.QOS_PROTOCOL_UDP) { result = filter.matchesProtocol(protocol); } else { // FWK currently doesn't support filtering based on protocol ID ESP & AH. We will follow // match results of other filters. result = hasMatchedFilter; } return result; } private QosBearerFilter getFilterByPrecedence( @Nullable QosBearerFilter qosFilter, QosBearerFilter sessionFilter) { // Find for the highest precedence filter, lower the value is the higher the precedence Loading Loading @@ -362,6 +390,15 @@ public class QosCallbackTracker extends Handler { hasMatchedFilter = true; } } if (sessionFilter.getProtocol() != QosBearerFilter.QOS_PROTOCOL_UNSPECIFIED) { if (!matchesByProtocol(sessionFilter, filter, hasMatchedFilter)) { unMatched = true; } else { hasMatchedFilter = true; } } if (!unMatched && hasMatchedFilter) { qosFilter = getFilterByPrecedence(qosFilter, sessionFilter); } Loading
tests/telephonytests/src/com/android/internal/telephony/data/QosCallbackTrackerTest.java +81 −1 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ public class QosCallbackTrackerTest extends TelephonyTest { class Filter implements QosCallbackTracker.IFilter { InetSocketAddress mLocalAddress; InetSocketAddress mRemoteAddress; int mProtocol = QosBearerFilter.QOS_PROTOCOL_TCP; Filter(@NonNull final InetSocketAddress localAddress) { this.mLocalAddress = localAddress; Loading @@ -87,6 +88,10 @@ public class QosCallbackTrackerTest extends TelephonyTest { && endPort >= mRemoteAddress.getPort() && (address.isAnyLocalAddress() || mRemoteAddress.getAddress().equals(address)); } public boolean matchesProtocol(int protocol) { return mProtocol == protocol; } } // Mocked classes Loading Loading @@ -151,6 +156,13 @@ public class QosCallbackTrackerTest extends TelephonyTest { private static QosBearerFilter createIpv4QosFilter(String localAddress, String remoteAddress, QosBearerFilter.PortRange localPort, QosBearerFilter.PortRange remotePort, int precedence) { return createIpv4QosFilter(localAddress, remoteAddress, localPort, remotePort, QosBearerFilter.QOS_PROTOCOL_TCP, precedence); } private static QosBearerFilter createIpv4QosFilter(String localAddress, String remoteAddress, QosBearerFilter.PortRange localPort, QosBearerFilter.PortRange remotePort, int protocol, int precedence) { ArrayList<LinkAddress> localAddresses = new ArrayList<>(); if (localAddress != null) { localAddresses.add( Loading @@ -163,7 +175,7 @@ public class QosCallbackTrackerTest extends TelephonyTest { } return new QosBearerFilter( localAddresses, remoteAddresses, localPort, remotePort, QosBearerFilter.QOS_PROTOCOL_TCP, 7, 987, 678, protocol, 7, 987, 678, QosBearerFilter.QOS_FILTER_DIRECTION_BIDIRECTIONAL, precedence); } Loading Loading @@ -541,6 +553,74 @@ public class QosCallbackTrackerTest extends TelephonyTest { verify(mINetworkAgentRegistry, times(1)).sendQosSessionLost(eq(1), any(QosSession.class)); } @Test public void testQosSessionFilterProtocol() throws Exception { // QosBearerFilter including protocol ArrayList<QosBearerFilter> qosFilters1 = new ArrayList<>(); qosFilters1.add(createIpv4QosFilter(null, null, null, new QosBearerFilter.PortRange(3200, 3220), QosBearerFilter.QOS_PROTOCOL_UDP, 45)); ArrayList<QosBearerSession> qosSessions = new ArrayList<>(); qosSessions.add(new QosBearerSession(1234, createEpsQos(5, 6, 7, 8), qosFilters1)); mQosCallbackTracker.updateSessions(qosSessions); // Add filter after updateSessions Filter filter = new Filter(new InetSocketAddress( InetAddresses.parseNumericAddress("122.22.22.22"), 1357), new InetSocketAddress(InetAddresses.parseNumericAddress("177.77.77.77"), 3207)); mQosCallbackTracker.addFilter(1, filter); processAllMessages(); verify(mINetworkAgentRegistry, never()).sendEpsQosSessionAvailable(eq(1), any(QosSession.class), any(EpsBearerQosSessionAttributes.class)); // Remove the matching QosBearerFilter qosSessions.remove(0); mQosCallbackTracker.updateSessions(qosSessions); processAllMessages(); verify(mINetworkAgentRegistry, never()).sendQosSessionLost(eq(1), any(QosSession.class)); qosFilters1.clear(); qosFilters1.add(createIpv4QosFilter(null, null, null, new QosBearerFilter.PortRange(3200, 3220), QosBearerFilter.QOS_PROTOCOL_TCP, 45)); qosSessions.clear(); qosSessions.add(new QosBearerSession(1234, createEpsQos(5, 6, 7, 8), qosFilters1)); mQosCallbackTracker.updateSessions(qosSessions); processAllMessages(); verify(mINetworkAgentRegistry, times(1)).sendEpsQosSessionAvailable(eq(1), any(QosSession.class), any(EpsBearerQosSessionAttributes.class)); qosSessions.remove(0); mQosCallbackTracker.updateSessions(qosSessions); processAllMessages(); verify(mINetworkAgentRegistry, times(1)).sendQosSessionLost(eq(1), any(QosSession.class)); } @Test public void testQosSessionFilterProtocolEsp() throws Exception { // QosBearerFilter including protocol ArrayList<QosBearerFilter> qosFilters1 = new ArrayList<>(); qosFilters1.add(createIpv4QosFilter(null, null, null, new QosBearerFilter.PortRange(3200, 3220), QosBearerFilter.QOS_PROTOCOL_ESP, 45)); ArrayList<QosBearerSession> qosSessions = new ArrayList<>(); qosSessions.add(new QosBearerSession(1234, createEpsQos(5, 6, 7, 8), qosFilters1)); mQosCallbackTracker.updateSessions(qosSessions); // Add filter after updateSessions Filter filter = new Filter(new InetSocketAddress( InetAddresses.parseNumericAddress("122.22.22.22"), 1357), new InetSocketAddress(InetAddresses.parseNumericAddress("177.77.77.77"), 3211)); mQosCallbackTracker.addFilter(1, filter); processAllMessages(); verify(mINetworkAgentRegistry, times(1)).sendEpsQosSessionAvailable(eq(1), any(QosSession.class), any(EpsBearerQosSessionAttributes.class)); // Remove the matching QosBearerFilter qosSessions.remove(0); mQosCallbackTracker.updateSessions(qosSessions); processAllMessages(); verify(mINetworkAgentRegistry, times(1)).sendQosSessionLost(eq(1), any(QosSession.class)); } @Test public void testQosMetrics() { final int callbackId = 1; Loading