Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 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 | |
Paul Jensen | ca8f16a | 2014-05-09 12:47:55 -0400 | [diff] [blame] | 19 | import android.content.Context; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 20 | import android.net.LinkProperties; |
| 21 | import android.net.Network; |
| 22 | import android.net.NetworkCapabilities; |
| 23 | import android.net.NetworkInfo; |
| 24 | import android.net.NetworkRequest; |
Paul Jensen | ca8f16a | 2014-05-09 12:47:55 -0400 | [diff] [blame] | 25 | import android.os.Handler; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 26 | import android.os.Messenger; |
| 27 | import android.util.SparseArray; |
| 28 | |
| 29 | import com.android.internal.util.AsyncChannel; |
Paul Jensen | ca8f16a | 2014-05-09 12:47:55 -0400 | [diff] [blame] | 30 | import com.android.server.connectivity.NetworkMonitor; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 31 | |
| 32 | import 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 | */ |
| 40 | public class NetworkAgentInfo { |
| 41 | public NetworkInfo networkInfo; |
| 42 | public final Network network; |
| 43 | public LinkProperties linkProperties; |
| 44 | public NetworkCapabilities networkCapabilities; |
| 45 | public int currentScore; |
Paul Jensen | ca8f16a | 2014-05-09 12:47:55 -0400 | [diff] [blame] | 46 | public final NetworkMonitor networkMonitor; |
| 47 | |
Robert Greenwalt | 71bf33a | 2014-05-15 18:07:26 -0700 | [diff] [blame^] | 48 | /** |
| 49 | * Indicates we need to send CONNECTIVITY_ACTION broadcasts for this network. |
| 50 | * For example the built-in default network request and any requsts coming from |
| 51 | * the deprecated startUsingNetworkFeature API will have this set. Networks |
| 52 | * responding to the new requestNetwork API will rely on point to point callbacks. |
| 53 | * |
| 54 | * Gets set if any legacy requests get affiliated with this network and |
| 55 | * stays set for life so we send disconnected bcasts to match the connected, |
| 56 | * even if the legacy request has moved on. |
| 57 | */ |
| 58 | public boolean needsBroadcasts = false; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 59 | |
| 60 | // The list of NetworkRequests being satisfied by this Network. |
| 61 | public final SparseArray<NetworkRequest> networkRequests = new SparseArray<NetworkRequest>(); |
Robert Greenwalt | 9258c64 | 2014-03-26 16:47:06 -0700 | [diff] [blame] | 62 | public final ArrayList<NetworkRequest> networkLingered = new ArrayList<NetworkRequest>(); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 63 | |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 64 | public final Messenger messenger; |
| 65 | public final AsyncChannel asyncChannel; |
| 66 | |
| 67 | public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, int netId, NetworkInfo info, |
Paul Jensen | ca8f16a | 2014-05-09 12:47:55 -0400 | [diff] [blame] | 68 | LinkProperties lp, NetworkCapabilities nc, int score, Context context, |
| 69 | Handler handler) { |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 70 | this.messenger = messenger; |
| 71 | asyncChannel = ac; |
| 72 | network = new Network(netId); |
| 73 | networkInfo = info; |
| 74 | linkProperties = lp; |
| 75 | networkCapabilities = nc; |
| 76 | currentScore = score; |
Paul Jensen | ca8f16a | 2014-05-09 12:47:55 -0400 | [diff] [blame] | 77 | networkMonitor = new NetworkMonitor(context, handler, this); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Robert Greenwalt | 71bf33a | 2014-05-15 18:07:26 -0700 | [diff] [blame^] | 80 | public void addRequest(NetworkRequest networkRequest) { |
| 81 | if (networkRequest.needsBroadcasts) needsBroadcasts = true; |
| 82 | |
| 83 | networkRequests.put(networkRequest.requestId, networkRequest); |
| 84 | } |
| 85 | |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 86 | public String toString() { |
| 87 | return "NetworkAgentInfo{ ni{" + networkInfo + "} network{" + |
| 88 | network + "} lp{" + |
| 89 | linkProperties + "} nc{" + |
| 90 | networkCapabilities + "} Score{" + currentScore + "} }"; |
| 91 | } |
| 92 | |
| 93 | public String name() { |
| 94 | return "NetworkAgentInfo [" + networkInfo.getTypeName() + " (" + |
| 95 | networkInfo.getSubtypeName() + ")]"; |
| 96 | } |
| 97 | } |