Home | History | Annotate | Download | only in net
      1 /*
      2  * Copyright (C) 2008 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 android.net;
     18 
     19 import android.content.Context;
     20 import android.os.Handler;
     21 import android.os.Messenger;
     22 
     23 import static com.android.internal.util.Protocol.BASE_NETWORK_STATE_TRACKER;
     24 
     25 /**
     26  * Interface provides the {@link com.android.server.ConnectivityService}
     27  * with three services. Events to the ConnectivityService when
     28  * changes occur, an API for controlling the network and storage
     29  * for network specific information.
     30  *
     31  * The Connectivity will call startMonitoring before any other
     32  * method is called.
     33  *
     34  * {@hide}
     35  */
     36 public interface NetworkStateTracker {
     37 
     38     /**
     39      * -------------------------------------------------------------
     40      * Event Interface back to ConnectivityService.
     41      *
     42      * The events that are to be sent back to the Handler passed
     43      * to startMonitoring when the particular event occurs.
     44      * -------------------------------------------------------------
     45      */
     46 
     47     /**
     48      * The network state has changed and the NetworkInfo object
     49      * contains the new state.
     50      *
     51      * msg.what = EVENT_STATE_CHANGED
     52      * msg.obj = NetworkInfo object
     53      */
     54     public static final int EVENT_STATE_CHANGED = BASE_NETWORK_STATE_TRACKER;
     55 
     56     /**
     57      * msg.what = EVENT_CONFIGURATION_CHANGED
     58      * msg.obj = NetworkInfo object
     59      */
     60     public static final int EVENT_CONFIGURATION_CHANGED = BASE_NETWORK_STATE_TRACKER + 1;
     61 
     62     /**
     63      * msg.what = EVENT_RESTORE_DEFAULT_NETWORK
     64      * msg.obj = FeatureUser object
     65      */
     66     public static final int EVENT_RESTORE_DEFAULT_NETWORK = BASE_NETWORK_STATE_TRACKER + 2;
     67 
     68     /**
     69      * msg.what = EVENT_NETWORK_SUBTYPE_CHANGED
     70      * msg.obj = NetworkInfo object
     71      */
     72     public static final int EVENT_NETWORK_SUBTYPE_CHANGED = BASE_NETWORK_STATE_TRACKER + 3;
     73 
     74     /**
     75      * msg.what = EVENT_NETWORK_CONNECTED
     76      * msg.obj = LinkProperties object
     77      */
     78     public static final int EVENT_NETWORK_CONNECTED = BASE_NETWORK_STATE_TRACKER + 4;
     79 
     80     /**
     81      * msg.what = EVENT_NETWORK_CONNECTION_DISCONNECTED
     82      * msg.obj = LinkProperties object, same iface name
     83      */
     84     public static final int EVENT_NETWORK_DISCONNECTED = BASE_NETWORK_STATE_TRACKER + 5;
     85 
     86 
     87     /**
     88      * -------------------------------------------------------------
     89      * Control Interface
     90      * -------------------------------------------------------------
     91      */
     92     /**
     93      * Begin monitoring data connectivity.
     94      *
     95      * This is the first method called when this interface is used.
     96      *
     97      * @param context is the current Android context
     98      * @param target is the Hander to which to return the events.
     99      */
    100     public void startMonitoring(Context context, Handler target);
    101 
    102     /**
    103      * Fetch NetworkInfo for the network
    104      */
    105     public NetworkInfo getNetworkInfo();
    106 
    107     /**
    108      * Return the LinkProperties for the connection.
    109      *
    110      * @return a copy of the LinkProperties, is never null.
    111      */
    112     public LinkProperties getLinkProperties();
    113 
    114     /**
    115      * A capability is an Integer/String pair, the capabilities
    116      * are defined in the class LinkSocket#Key.
    117      *
    118      * @return a copy of this connections capabilities, may be empty but never null.
    119      */
    120     public LinkCapabilities getLinkCapabilities();
    121 
    122     /**
    123      * Return the system properties name associated with the tcp buffer sizes
    124      * for this network.
    125      */
    126     public String getTcpBufferSizesPropName();
    127 
    128     /**
    129      * Disable connectivity to a network
    130      * @return {@code true} if a teardown occurred, {@code false} if the
    131      * teardown did not occur.
    132      */
    133     public boolean teardown();
    134 
    135     /**
    136      * Reenable connectivity to a network after a {@link #teardown()}.
    137      * @return {@code true} if we're connected or expect to be connected
    138      */
    139     public boolean reconnect();
    140 
    141     /**
    142      * Ready to switch on to the network after captive portal check
    143      */
    144     public void captivePortalCheckComplete();
    145 
    146     /**
    147      * Captive portal check has completed
    148      */
    149     public void captivePortalCheckCompleted(boolean isCaptive);
    150 
    151     /**
    152      * Turn the wireless radio off for a network.
    153      * @param turnOn {@code true} to turn the radio on, {@code false}
    154      */
    155     public boolean setRadio(boolean turnOn);
    156 
    157     /**
    158      * Returns an indication of whether this network is available for
    159      * connections. A value of {@code false} means that some quasi-permanent
    160      * condition prevents connectivity to this network.
    161      *
    162      * NOTE that this is broken on multi-connection devices.  Should be fixed in J release
    163      * TODO - fix on multi-pdp devices
    164      */
    165     public boolean isAvailable();
    166 
    167     /**
    168      * User control of data connection through this network, typically persisted
    169      * internally.
    170      */
    171     public void setUserDataEnable(boolean enabled);
    172 
    173     /**
    174      * Policy control of data connection through this network, typically not
    175      * persisted internally. Usually used when {@link NetworkPolicy#limitBytes}
    176      * is passed.
    177      */
    178     public void setPolicyDataEnable(boolean enabled);
    179 
    180     /**
    181      * -------------------------------------------------------------
    182      * Storage API used by ConnectivityService for saving
    183      * Network specific information.
    184      * -------------------------------------------------------------
    185      */
    186 
    187     /**
    188      * Check if private DNS route is set for the network
    189      */
    190     public boolean isPrivateDnsRouteSet();
    191 
    192     /**
    193      * Set a flag indicating private DNS route is set
    194      */
    195     public void privateDnsRouteSet(boolean enabled);
    196 
    197     /**
    198      * Check if default route is set
    199      */
    200     public boolean isDefaultRouteSet();
    201 
    202     /**
    203      * Set a flag indicating default route is set for the network
    204      */
    205     public void defaultRouteSet(boolean enabled);
    206 
    207     /**
    208      * Check if tear down was requested
    209      */
    210     public boolean isTeardownRequested();
    211 
    212     /**
    213      * Indicate tear down requested from connectivity
    214      */
    215     public void setTeardownRequested(boolean isRequested);
    216 
    217     /**
    218      * An external dependency has been met/unmet
    219      */
    220     public void setDependencyMet(boolean met);
    221 
    222     /**
    223      * Informs the state tracker that another interface is stacked on top of it.
    224      **/
    225     public void addStackedLink(LinkProperties link);
    226 
    227     /**
    228      * Informs the state tracker that a stacked interface has been removed.
    229      **/
    230     public void removeStackedLink(LinkProperties link);
    231 
    232     /*
    233      * Called once to setup async channel between this and
    234      * the underlying network specific code.
    235      */
    236     public void supplyMessenger(Messenger messenger);
    237 }
    238