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 
     22 /**
     23  * Interface provides the {@link com.android.server.ConnectivityService}
     24  * with three services. Events to the ConnectivityService when
     25  * changes occur, an API for controlling the network and storage
     26  * for network specific information.
     27  *
     28  * The Connectivity will call startMonitoring before any other
     29  * method is called.
     30  *
     31  * {@hide}
     32  */
     33 public interface NetworkStateTracker {
     34 
     35     /**
     36      * -------------------------------------------------------------
     37      * Event Interface back to ConnectivityService.
     38      *
     39      * The events that are to be sent back to the Handler passed
     40      * to startMonitoring when the particular event occurs.
     41      * -------------------------------------------------------------
     42      */
     43 
     44     // Share the event space with ConnectivityService (which we can't see, but
     45     // must send events to).  If you change these, change ConnectivityService
     46     // too.
     47     static final int MIN_NETWORK_STATE_TRACKER_EVENT = 1;
     48     static final int MAX_NETWORK_STATE_TRACKER_EVENT = 100;
     49 
     50     /**
     51      * The network state has changed and the NetworkInfo object
     52      * contains the new state.
     53      *
     54      * msg.what = EVENT_STATE_CHANGED
     55      * msg.obj = NetworkInfo object
     56      */
     57     public static final int EVENT_STATE_CHANGED = 1;
     58 
     59     /**
     60      * msg.what = EVENT_CONFIGURATION_CHANGED
     61      * msg.obj = NetworkInfo object
     62      */
     63     public static final int EVENT_CONFIGURATION_CHANGED = 3;
     64 
     65     /**
     66      * msg.what = EVENT_RESTORE_DEFAULT_NETWORK
     67      * msg.obj = FeatureUser object
     68      */
     69     public static final int EVENT_RESTORE_DEFAULT_NETWORK = 6;
     70 
     71     /**
     72      * -------------------------------------------------------------
     73      * Control Interface
     74      * -------------------------------------------------------------
     75      */
     76     /**
     77      * Begin monitoring data connectivity.
     78      *
     79      * This is the first method called when this interface is used.
     80      *
     81      * @param context is the current Android context
     82      * @param target is the Hander to which to return the events.
     83      */
     84     public void startMonitoring(Context context, Handler target);
     85 
     86     /**
     87      * Fetch NetworkInfo for the network
     88      */
     89     public NetworkInfo getNetworkInfo();
     90 
     91     /**
     92      * Return the LinkProperties for the connection.
     93      *
     94      * @return a copy of the LinkProperties, is never null.
     95      */
     96     public LinkProperties getLinkProperties();
     97 
     98     /**
     99      * A capability is an Integer/String pair, the capabilities
    100      * are defined in the class LinkSocket#Key.
    101      *
    102      * @return a copy of this connections capabilities, may be empty but never null.
    103      */
    104     public LinkCapabilities getLinkCapabilities();
    105 
    106     /**
    107      * Return the system properties name associated with the tcp buffer sizes
    108      * for this network.
    109      */
    110     public String getTcpBufferSizesPropName();
    111 
    112     /**
    113      * Disable connectivity to a network
    114      * @return {@code true} if a teardown occurred, {@code false} if the
    115      * teardown did not occur.
    116      */
    117     public boolean teardown();
    118 
    119     /**
    120      * Reenable connectivity to a network after a {@link #teardown()}.
    121      * @return {@code true} if we're connected or expect to be connected
    122      */
    123     public boolean reconnect();
    124 
    125     /**
    126      * Turn the wireless radio off for a network.
    127      * @param turnOn {@code true} to turn the radio on, {@code false}
    128      */
    129     public boolean setRadio(boolean turnOn);
    130 
    131     /**
    132      * Returns an indication of whether this network is available for
    133      * connections. A value of {@code false} means that some quasi-permanent
    134      * condition prevents connectivity to this network.
    135      *
    136      * NOTE that this is broken on multi-connection devices.  Should be fixed in J release
    137      * TODO - fix on multi-pdp devices
    138      */
    139     public boolean isAvailable();
    140 
    141     /**
    142      * User control of data connection through this network, typically persisted
    143      * internally.
    144      */
    145     public void setUserDataEnable(boolean enabled);
    146 
    147     /**
    148      * Policy control of data connection through this network, typically not
    149      * persisted internally. Usually used when {@link NetworkPolicy#limitBytes}
    150      * is passed.
    151      */
    152     public void setPolicyDataEnable(boolean enabled);
    153 
    154     /**
    155      * -------------------------------------------------------------
    156      * Storage API used by ConnectivityService for saving
    157      * Network specific information.
    158      * -------------------------------------------------------------
    159      */
    160 
    161     /**
    162      * Check if private DNS route is set for the network
    163      */
    164     public boolean isPrivateDnsRouteSet();
    165 
    166     /**
    167      * Set a flag indicating private DNS route is set
    168      */
    169     public void privateDnsRouteSet(boolean enabled);
    170 
    171     /**
    172      * Check if default route is set
    173      */
    174     public boolean isDefaultRouteSet();
    175 
    176     /**
    177      * Set a flag indicating default route is set for the network
    178      */
    179     public void defaultRouteSet(boolean enabled);
    180 
    181     /**
    182      * Check if tear down was requested
    183      */
    184     public boolean isTeardownRequested();
    185 
    186     /**
    187      * Indicate tear down requested from connectivity
    188      */
    189     public void setTeardownRequested(boolean isRequested);
    190 
    191     /**
    192      * An external dependency has been met/unmet
    193      */
    194     public void setDependencyMet(boolean met);
    195 }
    196