NetworkAgentInfo.java revision 7ccd3dfd53d8d45c447398ff137f052865dfd3b3
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 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;
51
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>();
55
56    public final Messenger messenger;
57    public final AsyncChannel asyncChannel;
58
59    public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, NetworkInfo info,
60            LinkProperties lp, NetworkCapabilities nc, int score, Context context, Handler handler,
61            NetworkMisc misc) {
62        this.messenger = messenger;
63        asyncChannel = ac;
64        network = null;
65        networkInfo = info;
66        linkProperties = lp;
67        networkCapabilities = nc;
68        currentScore = score;
69        networkMonitor = new NetworkMonitor(context, handler, this);
70        networkMisc = misc;
71        created = false;
72        validated = false;
73    }
74
75    public void addRequest(NetworkRequest networkRequest) {
76        networkRequests.put(networkRequest.requestId, networkRequest);
77    }
78
79    public boolean isVPN() {
80        return networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN);
81    }
82
83    public String toString() {
84        return "NetworkAgentInfo{ ni{" + networkInfo + "}  network{" +
85                network + "}  lp{" +
86                linkProperties + "}  nc{" +
87                networkCapabilities + "}  Score{" + currentScore + "} }";
88    }
89
90    public String name() {
91        return "NetworkAgentInfo [" + networkInfo.getTypeName() + " (" +
92                networkInfo.getSubtypeName() + ") - " +
93                (network == null ? "null" : network.toString()) + "]";
94    }
95}
96