• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 android.net;
18 
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 
22 import java.net.InetAddress;
23 
24 /**
25  * Provides the related filtering logic to the {@link NetworkAgent} to match {@link QosSession}s
26  * to their related {@link QosCallback}.
27  *
28  * Used by the {@link com.android.server.ConnectivityService} to validate a {@link QosCallback}
29  * is still able to receive a {@link QosSession}.
30  *
31  * @hide
32  */
33 @SystemApi
34 public abstract class QosFilter {
35 
36     /** @hide */
QosFilter()37     protected QosFilter() {
38         // Ensure that all derived types are known, and known to be properly handled when being
39         // passed to and from NetworkAgent.
40         // For now the only known derived type is QosSocketFilter.
41         if (!(this instanceof QosSocketFilter)) {
42             throw new UnsupportedOperationException(
43                     "Unsupported QosFilter type: " + this.getClass().getName());
44         }
45     }
46 
47     /**
48      * The network used with this filter.
49      *
50      * @return the registered {@link Network}
51      */
52     @NonNull
getNetwork()53     public abstract Network getNetwork();
54 
55     /**
56      * Validates that conditions have not changed such that no further {@link QosSession}s should
57      * be passed back to the {@link QosCallback} associated to this filter.
58      *
59      * @return the error code when present, otherwise the filter is valid
60      *
61      * @hide
62      */
63     @QosCallbackException.ExceptionType
validate()64     public abstract int validate();
65 
66     /**
67      * Determines whether or not the parameters will be matched with source address and port of this
68      * filter.
69      *
70      * @param address the UE side address included in IP packet filter set of a QoS flow assigned
71      *                on {@link Network}.
72      * @param startPort the start of UE side port range included in IP packet filter set of a QoS
73      *                flow assigned on {@link Network}.
74      * @param endPort the end of UE side port range included in IP packet filter set of a QoS flow
75      *                assigned on {@link Network}.
76      * @return whether the parameters match the UE side address and port of the filter
77      */
matchesLocalAddress(@onNull InetAddress address, int startPort, int endPort)78     public abstract boolean matchesLocalAddress(@NonNull InetAddress address,
79             int startPort, int endPort);
80 
81     /**
82      * Determines whether or not the parameters will be matched with remote address and port of
83      * this filter.
84      *
85      * @param address the remote address included in IP packet filter set of a QoS flow
86      *                assigned on {@link Network}.
87      * @param startPort the start of remote port range included in IP packet filter set of a
88      *                 QoS flow assigned on {@link Network}.
89      * @param endPort the end of the remote range included in IP packet filter set of a QoS
90      *                flow assigned on {@link Network}.
91      * @return whether the parameters match the remote address and port of the filter
92      */
matchesRemoteAddress(@onNull InetAddress address, int startPort, int endPort)93     public abstract boolean matchesRemoteAddress(@NonNull InetAddress address,
94             int startPort, int endPort);
95 
96     /**
97      * Determines whether or not the parameter will be matched with this filter.
98      *
99      * @param protocol the protocol such as TCP or UDP included in IP packet filter set of a QoS
100      *                 flow assigned on {@link Network}. Only {@code IPPROTO_TCP} and {@code
101      *                 IPPROTO_UDP} currently supported.
102      * @return whether the parameters match the socket type of the filter
103      */
104     // Since this method is added in U, it's required to be default method for binary compatibility
105     // with existing @SystemApi.
106     // IPPROTO_* are not compile-time constants, so they are not annotated with @IntDef.
matchesProtocol(int protocol)107     public boolean matchesProtocol(int protocol) {
108         return false;
109     }
110 }
111 
112