NetworkAgentInfo.java revision ca8f16ad14819ba17f5ff3d2e2bf6fbc9bbaa9f7
17b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt/*
27b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * Copyright (C) 2014 The Android Open Source Project
37b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt *
47b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * Licensed under the Apache License, Version 2.0 (the "License");
57b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * you may not use this file except in compliance with the License.
67b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * You may obtain a copy of the License at
77b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt *
87b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt *      http://www.apache.org/licenses/LICENSE-2.0
97b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt *
107b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * Unless required by applicable law or agreed to in writing, software
117b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * distributed under the License is distributed on an "AS IS" BASIS,
127b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * See the License for the specific language governing permissions and
147b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * limitations under the License.
157b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt */
167b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
177b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltpackage com.android.server.connectivity;
187b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
19ca8f16ad14819ba17f5ff3d2e2bf6fbc9bbaa9f7Paul Jensenimport android.content.Context;
207b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltimport android.net.LinkProperties;
217b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltimport android.net.Network;
227b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltimport android.net.NetworkCapabilities;
237b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltimport android.net.NetworkInfo;
247b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltimport android.net.NetworkRequest;
25ca8f16ad14819ba17f5ff3d2e2bf6fbc9bbaa9f7Paul Jensenimport android.os.Handler;
267b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltimport android.os.Messenger;
277b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltimport android.util.SparseArray;
287b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
297b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltimport com.android.internal.util.AsyncChannel;
30ca8f16ad14819ba17f5ff3d2e2bf6fbc9bbaa9f7Paul Jensenimport com.android.server.connectivity.NetworkMonitor;
317b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
327b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltimport java.util.ArrayList;
337b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
347b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt/**
357b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * A bag class used by ConnectivityService for holding a collection of most recent
367b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * information published by a particular NetworkAgent as well as the
377b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * AsyncChannel/messenger for reaching that NetworkAgent and lists of NetworkRequests
387b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * interested in using it.
397b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt */
407b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwaltpublic class NetworkAgentInfo {
417b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public NetworkInfo networkInfo;
427b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public final Network network;
437b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public LinkProperties linkProperties;
447b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public NetworkCapabilities networkCapabilities;
457b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public int currentScore;
46ca8f16ad14819ba17f5ff3d2e2bf6fbc9bbaa9f7Paul Jensen    public final NetworkMonitor networkMonitor;
47ca8f16ad14819ba17f5ff3d2e2bf6fbc9bbaa9f7Paul Jensen
487b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
497b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    // The list of NetworkRequests being satisfied by this Network.
507b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public final SparseArray<NetworkRequest> networkRequests = new SparseArray<NetworkRequest>();
517b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
527b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    // The list of NetworkListens listening for changes on this Network.
537b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public final ArrayList<NetworkRequest> networkListens = new ArrayList<NetworkRequest>();
547b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public final Messenger messenger;
557b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public final AsyncChannel asyncChannel;
567b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
577b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, int netId, NetworkInfo info,
58ca8f16ad14819ba17f5ff3d2e2bf6fbc9bbaa9f7Paul Jensen            LinkProperties lp, NetworkCapabilities nc, int score, Context context,
59ca8f16ad14819ba17f5ff3d2e2bf6fbc9bbaa9f7Paul Jensen            Handler handler) {
607b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt        this.messenger = messenger;
617b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt        asyncChannel = ac;
627b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt        network = new Network(netId);
637b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt        networkInfo = info;
647b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt        linkProperties = lp;
657b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt        networkCapabilities = nc;
667b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt        currentScore = score;
67ca8f16ad14819ba17f5ff3d2e2bf6fbc9bbaa9f7Paul Jensen        networkMonitor = new NetworkMonitor(context, handler, this);
687b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    }
697b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
707b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public String toString() {
717b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt        return "NetworkAgentInfo{ ni{" + networkInfo + "}  network{" +
727b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt                network + "}  lp{" +
737b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt                linkProperties + "}  nc{" +
747b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt                networkCapabilities + "}  Score{" + currentScore + "} }";
757b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    }
767b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt
777b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    public String name() {
787b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt        return "NetworkAgentInfo [" + networkInfo.getTypeName() + " (" +
797b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt                networkInfo.getSubtypeName() + ")]";
807b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt    }
817b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt}
82