NetworkAgentInfo.java revision 2c7bf2cb46024eb87aec4b5ac0fa15477cc14f7a
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.NetworkRequest;
25import android.os.Handler;
26import android.os.Messenger;
27import android.util.SparseArray;
28
29import com.android.internal.util.AsyncChannel;
30import com.android.server.connectivity.NetworkMonitor;
31
32import java.util.ArrayList;
33
34/**
35 * A bag class used by ConnectivityService for holding a collection of most recent
36 * information published by a particular NetworkAgent as well as the
37 * AsyncChannel/messenger for reaching that NetworkAgent and lists of NetworkRequests
38 * interested in using it.
39 */
40public class NetworkAgentInfo {
41    public NetworkInfo networkInfo;
42    public final Network network;
43    public LinkProperties linkProperties;
44    public NetworkCapabilities networkCapabilities;
45    public int currentScore;
46    public final NetworkMonitor networkMonitor;
47
48    // The list of NetworkRequests being satisfied by this Network.
49    public final SparseArray<NetworkRequest> networkRequests = new SparseArray<NetworkRequest>();
50    public final ArrayList<NetworkRequest> networkLingered = new ArrayList<NetworkRequest>();
51
52    public final Messenger messenger;
53    public final AsyncChannel asyncChannel;
54
55    public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, int netId, NetworkInfo info,
56            LinkProperties lp, NetworkCapabilities nc, int score, Context context,
57            Handler handler) {
58        this.messenger = messenger;
59        asyncChannel = ac;
60        network = new Network(netId);
61        networkInfo = info;
62        linkProperties = lp;
63        networkCapabilities = nc;
64        currentScore = score;
65        networkMonitor = new NetworkMonitor(context, handler, this);
66    }
67
68    public void addRequest(NetworkRequest networkRequest) {
69        networkRequests.put(networkRequest.requestId, networkRequest);
70    }
71
72    public String toString() {
73        return "NetworkAgentInfo{ ni{" + networkInfo + "}  network{" +
74                network + "}  lp{" +
75                linkProperties + "}  nc{" +
76                networkCapabilities + "}  Score{" + currentScore + "} }";
77    }
78
79    public String name() {
80        return "NetworkAgentInfo [" + networkInfo.getTypeName() + " (" +
81                networkInfo.getSubtypeName() + ") - " + network.toString() + "]";
82    }
83}
84