Search in sources :

Example 1 with DetailedState

use of android.net.NetworkInfo.DetailedState in project android_frameworks_base by ResurrectionRemix.

the class ConnectivityService method requestRouteToHostAddress.

/**
     * Ensure that a network route exists to deliver traffic to the specified
     * host via the specified network interface.
     * @param networkType the type of the network over which traffic to the
     * specified host is to be routed
     * @param hostAddress the IP address of the host to which the route is
     * desired
     * @return {@code true} on success, {@code false} on failure
     */
@Override
public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress) {
    enforceChangePermission();
    if (mProtectedNetworks.contains(networkType)) {
        enforceConnectivityInternalPermission();
    }
    InetAddress addr;
    try {
        addr = InetAddress.getByAddress(hostAddress);
    } catch (UnknownHostException e) {
        if (DBG)
            log("requestRouteToHostAddress got " + e.toString());
        return false;
    }
    if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
        if (DBG)
            log("requestRouteToHostAddress on invalid network: " + networkType);
        return false;
    }
    NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
    if (nai == null) {
        if (mLegacyTypeTracker.isTypeSupported(networkType) == false) {
            if (DBG)
                log("requestRouteToHostAddress on unsupported network: " + networkType);
        } else {
            if (DBG)
                log("requestRouteToHostAddress on down network: " + networkType);
        }
        return false;
    }
    DetailedState netState;
    synchronized (nai) {
        netState = nai.networkInfo.getDetailedState();
    }
    if (netState != DetailedState.CONNECTED && netState != DetailedState.CAPTIVE_PORTAL_CHECK) {
        if (VDBG) {
            log("requestRouteToHostAddress on down network " + "(" + networkType + ") - dropped" + " netState=" + netState);
        }
        return false;
    }
    final int uid = Binder.getCallingUid();
    final long token = Binder.clearCallingIdentity();
    try {
        LinkProperties lp;
        int netId;
        synchronized (nai) {
            lp = nai.linkProperties;
            netId = nai.network.netId;
        }
        boolean ok = addLegacyRouteToHost(lp, addr, netId, uid);
        if (DBG)
            log("requestRouteToHostAddress ok=" + ok);
        return ok;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) DetailedState(android.net.NetworkInfo.DetailedState) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties)

Example 2 with DetailedState

use of android.net.NetworkInfo.DetailedState in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityService method requestRouteToHostAddress.

/**
     * Ensure that a network route exists to deliver traffic to the specified
     * host via the specified network interface.
     * @param networkType the type of the network over which traffic to the
     * specified host is to be routed
     * @param hostAddress the IP address of the host to which the route is
     * desired
     * @return {@code true} on success, {@code false} on failure
     */
@Override
public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress) {
    enforceChangePermission();
    if (mProtectedNetworks.contains(networkType)) {
        enforceConnectivityInternalPermission();
    }
    InetAddress addr;
    try {
        addr = InetAddress.getByAddress(hostAddress);
    } catch (UnknownHostException e) {
        if (DBG)
            log("requestRouteToHostAddress got " + e.toString());
        return false;
    }
    if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
        if (DBG)
            log("requestRouteToHostAddress on invalid network: " + networkType);
        return false;
    }
    NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
    if (nai == null) {
        if (mLegacyTypeTracker.isTypeSupported(networkType) == false) {
            if (DBG)
                log("requestRouteToHostAddress on unsupported network: " + networkType);
        } else {
            if (DBG)
                log("requestRouteToHostAddress on down network: " + networkType);
        }
        return false;
    }
    DetailedState netState;
    synchronized (nai) {
        netState = nai.networkInfo.getDetailedState();
    }
    if (netState != DetailedState.CONNECTED && netState != DetailedState.CAPTIVE_PORTAL_CHECK) {
        if (VDBG) {
            log("requestRouteToHostAddress on down network " + "(" + networkType + ") - dropped" + " netState=" + netState);
        }
        return false;
    }
    final int uid = Binder.getCallingUid();
    final long token = Binder.clearCallingIdentity();
    try {
        LinkProperties lp;
        int netId;
        synchronized (nai) {
            lp = nai.linkProperties;
            netId = nai.network.netId;
        }
        boolean ok = addLegacyRouteToHost(lp, addr, netId, uid);
        if (DBG)
            log("requestRouteToHostAddress ok=" + ok);
        return ok;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) DetailedState(android.net.NetworkInfo.DetailedState) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties)

Example 3 with DetailedState

use of android.net.NetworkInfo.DetailedState in project platform_frameworks_base by android.

the class ConnectivityService method requestRouteToHostAddress.

/**
     * Ensure that a network route exists to deliver traffic to the specified
     * host via the specified network interface.
     * @param networkType the type of the network over which traffic to the
     * specified host is to be routed
     * @param hostAddress the IP address of the host to which the route is
     * desired
     * @return {@code true} on success, {@code false} on failure
     */
@Override
public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress) {
    enforceChangePermission();
    if (mProtectedNetworks.contains(networkType)) {
        enforceConnectivityInternalPermission();
    }
    InetAddress addr;
    try {
        addr = InetAddress.getByAddress(hostAddress);
    } catch (UnknownHostException e) {
        if (DBG)
            log("requestRouteToHostAddress got " + e.toString());
        return false;
    }
    if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
        if (DBG)
            log("requestRouteToHostAddress on invalid network: " + networkType);
        return false;
    }
    NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
    if (nai == null) {
        if (mLegacyTypeTracker.isTypeSupported(networkType) == false) {
            if (DBG)
                log("requestRouteToHostAddress on unsupported network: " + networkType);
        } else {
            if (DBG)
                log("requestRouteToHostAddress on down network: " + networkType);
        }
        return false;
    }
    DetailedState netState;
    synchronized (nai) {
        netState = nai.networkInfo.getDetailedState();
    }
    if (netState != DetailedState.CONNECTED && netState != DetailedState.CAPTIVE_PORTAL_CHECK) {
        if (VDBG) {
            log("requestRouteToHostAddress on down network " + "(" + networkType + ") - dropped" + " netState=" + netState);
        }
        return false;
    }
    final int uid = Binder.getCallingUid();
    final long token = Binder.clearCallingIdentity();
    try {
        LinkProperties lp;
        int netId;
        synchronized (nai) {
            lp = nai.linkProperties;
            netId = nai.network.netId;
        }
        boolean ok = addLegacyRouteToHost(lp, addr, netId, uid);
        if (DBG)
            log("requestRouteToHostAddress ok=" + ok);
        return ok;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) DetailedState(android.net.NetworkInfo.DetailedState) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties)

Example 4 with DetailedState

use of android.net.NetworkInfo.DetailedState in project frostwire by frostwire.

the class EngineBroadcastReceiver method handleConnectivityChange.

private void handleConnectivityChange(Intent intent) {
    NetworkInfo networkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
    DetailedState detailedState = networkInfo.getDetailedState();
    switch(detailedState) {
        case CONNECTED:
            handleConnectedNetwork(networkInfo);
            handleNetworkStatusChange();
            reopenNetworkSockets();
            break;
        case DISCONNECTED:
            handleDisconnectedNetwork(networkInfo);
            handleNetworkStatusChange();
            reopenNetworkSockets();
            break;
        case CONNECTING:
        case DISCONNECTING:
            handleNetworkStatusChange();
            break;
        default:
            break;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) DetailedState(android.net.NetworkInfo.DetailedState)

Example 5 with DetailedState

use of android.net.NetworkInfo.DetailedState in project android_frameworks_base by crdroidandroid.

the class ConnectivityService method requestRouteToHostAddress.

/**
     * Ensure that a network route exists to deliver traffic to the specified
     * host via the specified network interface.
     * @param networkType the type of the network over which traffic to the
     * specified host is to be routed
     * @param hostAddress the IP address of the host to which the route is
     * desired
     * @return {@code true} on success, {@code false} on failure
     */
@Override
public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress) {
    enforceChangePermission();
    if (mProtectedNetworks.contains(networkType)) {
        enforceConnectivityInternalPermission();
    }
    InetAddress addr;
    try {
        addr = InetAddress.getByAddress(hostAddress);
    } catch (UnknownHostException e) {
        if (DBG)
            log("requestRouteToHostAddress got " + e.toString());
        return false;
    }
    if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
        if (DBG)
            log("requestRouteToHostAddress on invalid network: " + networkType);
        return false;
    }
    NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
    if (nai == null) {
        if (mLegacyTypeTracker.isTypeSupported(networkType) == false) {
            if (DBG)
                log("requestRouteToHostAddress on unsupported network: " + networkType);
        } else {
            if (DBG)
                log("requestRouteToHostAddress on down network: " + networkType);
        }
        return false;
    }
    DetailedState netState;
    synchronized (nai) {
        netState = nai.networkInfo.getDetailedState();
    }
    if (netState != DetailedState.CONNECTED && netState != DetailedState.CAPTIVE_PORTAL_CHECK) {
        if (VDBG) {
            log("requestRouteToHostAddress on down network " + "(" + networkType + ") - dropped" + " netState=" + netState);
        }
        return false;
    }
    final int uid = Binder.getCallingUid();
    final long token = Binder.clearCallingIdentity();
    try {
        LinkProperties lp;
        int netId;
        synchronized (nai) {
            lp = nai.linkProperties;
            netId = nai.network.netId;
        }
        boolean ok = addLegacyRouteToHost(lp, addr, netId, uid);
        if (DBG)
            log("requestRouteToHostAddress ok=" + ok);
        return ok;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) DetailedState(android.net.NetworkInfo.DetailedState) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties)

Aggregations

DetailedState (android.net.NetworkInfo.DetailedState)9 LinkProperties (android.net.LinkProperties)6 InetAddress (java.net.InetAddress)6 UnknownHostException (java.net.UnknownHostException)6 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)5 Resources (android.content.res.Resources)2 WifiInfo (android.net.wifi.WifiInfo)2 ViewGroup (android.view.ViewGroup)2 Context (android.content.Context)1 NetworkInfo (android.net.NetworkInfo)1 NetworkStateTracker (android.net.NetworkStateTracker)1 StaticIpConfiguration (android.net.StaticIpConfiguration)1 WifiConfiguration (android.net.wifi.WifiConfiguration)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CheckBox (android.widget.CheckBox)1 ScrollView (android.widget.ScrollView)1 Spinner (android.widget.Spinner)1 TextView (android.widget.TextView)1 AccessPoint (com.android.settingslib.wifi.AccessPoint)1