NetworkAgentInfo.java revision eec75412a971a5ccb769364120c769c331946eb3
1/* 2 * Copyright (C) 2014 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 17package com.android.server.connectivity; 18 19import android.content.Context; 20import android.net.LinkProperties; 21import android.net.Network; 22import android.net.NetworkCapabilities; 23import android.net.NetworkInfo; 24import android.net.NetworkMisc; 25import android.net.NetworkRequest; 26import android.os.Handler; 27import android.os.Messenger; 28import android.util.SparseArray; 29 30import com.android.internal.util.AsyncChannel; 31import com.android.server.connectivity.NetworkMonitor; 32 33import java.util.ArrayList; 34 35/** 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. 40 */ 41public class NetworkAgentInfo { 42 public NetworkInfo networkInfo; 43 public final 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 51 // The list of NetworkRequests being satisfied by this Network. 52 public final SparseArray<NetworkRequest> networkRequests = new SparseArray<NetworkRequest>(); 53 public final ArrayList<NetworkRequest> networkLingered = new ArrayList<NetworkRequest>(); 54 55 public final Messenger messenger; 56 public final AsyncChannel asyncChannel; 57 58 public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, int netId, NetworkInfo info, 59 LinkProperties lp, NetworkCapabilities nc, int score, Context context, Handler handler, 60 NetworkMisc misc) { 61 this.messenger = messenger; 62 asyncChannel = ac; 63 network = new Network(netId); 64 networkInfo = info; 65 linkProperties = lp; 66 networkCapabilities = nc; 67 currentScore = score; 68 networkMonitor = new NetworkMonitor(context, handler, this); 69 networkMisc = misc; 70 created = false; 71 } 72 73 public void addRequest(NetworkRequest networkRequest) { 74 networkRequests.put(networkRequest.requestId, networkRequest); 75 } 76 77 public boolean isVPN() { 78 return networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN); 79 } 80 81 public String toString() { 82 return "NetworkAgentInfo{ ni{" + networkInfo + "} network{" + 83 network + "} lp{" + 84 linkProperties + "} nc{" + 85 networkCapabilities + "} Score{" + currentScore + "} }"; 86 } 87 88 public String name() { 89 return "NetworkAgentInfo [" + networkInfo.getTypeName() + " (" + 90 networkInfo.getSubtypeName() + ") - " + network.toString() + "]"; 91 } 92} 93