2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.server.connectivity;
19 import android.content.Context;
20 import android.net.LinkProperties;
21 import android.net.Network;
22 import android.net.NetworkCapabilities;
23 import android.net.NetworkInfo;
24 import android.net.NetworkMisc;
25 import android.net.NetworkRequest;
26 import android.os.Handler;
27 import android.os.Messenger;
28 import android.util.SparseArray;
30 import com.android.internal.util.AsyncChannel;
31 import com.android.server.connectivity.NetworkMonitor;
33 import java.util.ArrayList;
36 * A bag class used by ConnectivityService for holding a collection of most recent
37 * information published by a particular NetworkAgent as well as the
38 * AsyncChannel/messenger for reaching that NetworkAgent and lists of NetworkRequests
39 * interested in using it.
41 public class NetworkAgentInfo {
42 public NetworkInfo networkInfo;
43 public Network network;
44 public LinkProperties linkProperties;
45 public NetworkCapabilities networkCapabilities;
46 public int currentScore;
47 public final NetworkMonitor networkMonitor;
48 public final NetworkMisc networkMisc;
49 public boolean created;
50 public boolean validated;
52 // The list of NetworkRequests being satisfied by this Network.
53 public final SparseArray<NetworkRequest> networkRequests = new SparseArray<NetworkRequest>();
54 public final ArrayList<NetworkRequest> networkLingered = new ArrayList<NetworkRequest>();
56 public final Messenger messenger;
57 public final AsyncChannel asyncChannel;
59 public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, NetworkInfo info,
60 LinkProperties lp, NetworkCapabilities nc, int score, Context context, Handler handler,
62 this.messenger = messenger;
67 networkCapabilities = nc;
69 networkMonitor = new NetworkMonitor(context, handler, this);
75 public void addRequest(NetworkRequest networkRequest) {
76 networkRequests.put(networkRequest.requestId, networkRequest);
79 public boolean isVPN() {
80 return networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN);
83 public String toString() {
84 return "NetworkAgentInfo{ ni{" + networkInfo + "} network{" +
86 linkProperties + "} nc{" +
87 networkCapabilities + "} Score{" + currentScore + "} }";
90 public String name() {
91 return "NetworkAgentInfo [" + networkInfo.getTypeName() + " (" +
92 networkInfo.getSubtypeName() + ") - " +
93 (network == null ? "null" : network.toString()) + "]";