Search in sources :

Example 41 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by ResurrectionRemix.

the class ConnectivityService method requestNetwork.

@Override
public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities, Messenger messenger, int timeoutMs, IBinder binder, int legacyType) {
    final NetworkRequest.Type type = (networkCapabilities == null) ? NetworkRequest.Type.TRACK_DEFAULT : NetworkRequest.Type.REQUEST;
    // the system default network.
    if (type == NetworkRequest.Type.TRACK_DEFAULT) {
        networkCapabilities = new NetworkCapabilities(mDefaultRequest.networkCapabilities);
        enforceAccessPermission();
    } else {
        networkCapabilities = new NetworkCapabilities(networkCapabilities);
        enforceNetworkRequestPermissions(networkCapabilities);
        // TODO: this is incorrect. We mark the request as metered or not depending on the state
        // of the app when the request is filed, but we never change the request if the app
        // changes network state. http://b/29964605
        enforceMeteredApnPolicy(networkCapabilities);
    }
    ensureRequestableCapabilities(networkCapabilities);
    if (timeoutMs < 0 || timeoutMs > ConnectivityManager.MAX_NETWORK_REQUEST_TIMEOUT_MS) {
        throw new IllegalArgumentException("Bad timeout specified");
    }
    if (NetworkCapabilities.MATCH_ALL_REQUESTS_NETWORK_SPECIFIER.equals(networkCapabilities.getNetworkSpecifier())) {
        throw new IllegalArgumentException("Invalid network specifier - must not be '" + NetworkCapabilities.MATCH_ALL_REQUESTS_NETWORK_SPECIFIER + "'");
    }
    NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, legacyType, nextNetworkRequestId(), type);
    NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder);
    if (DBG)
        log("requestNetwork for " + nri);
    mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_REQUEST, nri));
    if (timeoutMs > 0) {
        mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_TIMEOUT_NETWORK_REQUEST, nri), timeoutMs);
    }
    return networkRequest;
}
Also used : NetworkRequest(android.net.NetworkRequest) NetworkCapabilities(android.net.NetworkCapabilities)

Example 42 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by ResurrectionRemix.

the class ConnectivityService method callCallbackForRequest.

private void callCallbackForRequest(NetworkRequestInfo nri, NetworkAgentInfo networkAgent, int notificationType, int arg1) {
    // Default request has no msgr
    if (nri.messenger == null)
        return;
    Bundle bundle = new Bundle();
    bundle.putParcelable(NetworkRequest.class.getSimpleName(), new NetworkRequest(nri.request));
    Message msg = Message.obtain();
    if (notificationType != ConnectivityManager.CALLBACK_UNAVAIL && notificationType != ConnectivityManager.CALLBACK_RELEASED) {
        bundle.putParcelable(Network.class.getSimpleName(), networkAgent.network);
    }
    switch(notificationType) {
        case ConnectivityManager.CALLBACK_LOSING:
            {
                msg.arg1 = arg1;
                break;
            }
        case ConnectivityManager.CALLBACK_CAP_CHANGED:
            {
                bundle.putParcelable(NetworkCapabilities.class.getSimpleName(), new NetworkCapabilities(networkAgent.networkCapabilities));
                break;
            }
        case ConnectivityManager.CALLBACK_IP_CHANGED:
            {
                bundle.putParcelable(LinkProperties.class.getSimpleName(), new LinkProperties(networkAgent.linkProperties));
                break;
            }
    }
    msg.what = notificationType;
    msg.setData(bundle);
    try {
        if (VDBG) {
            log("sending notification " + notifyTypeToName(notificationType) + " for " + nri.request);
        }
        nri.messenger.send(msg);
    } catch (RemoteException e) {
        // may occur naturally in the race of binder death.
        loge("RemoteException caught trying to send a callback msg for " + nri.request);
    }
}
Also used : Message(android.os.Message) WakeupMessage(com.android.internal.util.WakeupMessage) Bundle(android.os.Bundle) Network(android.net.Network) NetworkRequest(android.net.NetworkRequest) RemoteException(android.os.RemoteException) NetworkCapabilities(android.net.NetworkCapabilities) LinkProperties(android.net.LinkProperties)

Example 43 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by ResurrectionRemix.

the class ConnectivityService method removeDataActivityTracking.

/**
     * Remove data activity tracking when network disconnects.
     */
private void removeDataActivityTracking(NetworkAgentInfo networkAgent) {
    final String iface = networkAgent.linkProperties.getInterfaceName();
    final NetworkCapabilities caps = networkAgent.networkCapabilities;
    if (iface != null && (caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI))) {
        try {
            // the call fails silently if no idletimer setup for this interface
            mNetd.removeIdleTimer(iface);
        } catch (Exception e) {
            loge("Exception in removeDataActivityTracking " + e);
        }
    }
}
Also used : NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString) NetworkCapabilities(android.net.NetworkCapabilities) RemoteException(android.os.RemoteException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 44 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by ResurrectionRemix.

the class ConnectivityService method getFilteredNetworkState.

private NetworkState getFilteredNetworkState(int networkType, int uid, boolean ignoreBlocked) {
    if (mLegacyTypeTracker.isTypeSupported(networkType)) {
        final NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
        final NetworkState state;
        if (nai != null) {
            state = nai.getNetworkState();
            state.networkInfo.setType(networkType);
        } else {
            final NetworkInfo info = new NetworkInfo(networkType, 0, getNetworkTypeName(networkType), "");
            info.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null, null);
            info.setIsAvailable(true);
            state = new NetworkState(info, new LinkProperties(), new NetworkCapabilities(), null, null, null);
        }
        filterNetworkStateForUid(state, uid, ignoreBlocked);
        return state;
    } else {
        return NetworkState.EMPTY;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties) NetworkCapabilities(android.net.NetworkCapabilities)

Example 45 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by ResurrectionRemix.

the class NetworkControllerImpl method updateConnectivity.

/**
     * Update the Inet conditions and what network we are connected to.
     */
private void updateConnectivity() {
    mConnectedTransports.clear();
    mValidatedTransports.clear();
    for (NetworkCapabilities nc : mConnectivityManager.getDefaultNetworkCapabilitiesForUser(mCurrentUserId)) {
        for (int transportType : nc.getTransportTypes()) {
            mConnectedTransports.set(transportType);
            if (nc.hasCapability(NET_CAPABILITY_VALIDATED)) {
                mValidatedTransports.set(transportType);
            }
        }
    }
    if (CHATTY) {
        Log.d(TAG, "updateConnectivity: mConnectedTransports=" + mConnectedTransports);
        Log.d(TAG, "updateConnectivity: mValidatedTransports=" + mValidatedTransports);
    }
    mInetCondition = !mValidatedTransports.isEmpty();
    pushConnectivityToSignals();
}
Also used : NetworkCapabilities(android.net.NetworkCapabilities)

Aggregations

NetworkCapabilities (android.net.NetworkCapabilities)114 NetworkRequest (android.net.NetworkRequest)53 Network (android.net.Network)27 RemoteException (android.os.RemoteException)25 LinkProperties (android.net.LinkProperties)23 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)20 NetworkInfo (android.net.NetworkInfo)18 ConnectivityManager (android.net.ConnectivityManager)15 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)10 NetworkState (android.net.NetworkState)8 HandlerThread (android.os.HandlerThread)8 NetworkMisc (android.net.NetworkMisc)5 IWifiManager (android.net.wifi.IWifiManager)5 WifiManager (android.net.wifi.WifiManager)5 Bundle (android.os.Bundle)5 Message (android.os.Message)5 ServiceState (android.telephony.ServiceState)5 SignalStrength (android.telephony.SignalStrength)5