OSDN Git Service

Implement ConnectivityManager.reportBadNetwork() to trigger network validation.
[android-x86/frameworks-base.git] / services / core / java / com / android / server / connectivity / NetworkAgentInfo.java
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
17 package com.android.server.connectivity;
18
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;
29
30 import com.android.internal.util.AsyncChannel;
31 import com.android.server.connectivity.NetworkMonitor;
32
33 import 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  */
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;
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 }