Search in sources :

Example 76 with NetworkInfo

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

the class NetworkStatsServiceTest method buildWifiState.

private static NetworkState buildWifiState(boolean isMetered) {
    final NetworkInfo info = new NetworkInfo(TYPE_WIFI, 0, null, null);
    info.setDetailedState(DetailedState.CONNECTED, null, null);
    final LinkProperties prop = new LinkProperties();
    prop.setInterfaceName(TEST_IFACE);
    final NetworkCapabilities capabilities = new NetworkCapabilities();
    if (!isMetered) {
        capabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
    }
    return new NetworkState(info, prop, capabilities, null, null, TEST_SSID);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties) NetworkCapabilities(android.net.NetworkCapabilities)

Example 77 with NetworkInfo

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

the class NetworkStatsServiceTest method buildMobile3gState.

private static NetworkState buildMobile3gState(String subscriberId, boolean isRoaming) {
    final NetworkInfo info = new NetworkInfo(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UMTS, null, null);
    info.setDetailedState(DetailedState.CONNECTED, null, null);
    info.setRoaming(isRoaming);
    final LinkProperties prop = new LinkProperties();
    prop.setInterfaceName(TEST_IFACE);
    final NetworkCapabilities capabilities = new NetworkCapabilities();
    return new NetworkState(info, prop, capabilities, null, subscriberId, null);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties) NetworkCapabilities(android.net.NetworkCapabilities)

Example 78 with NetworkInfo

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

the class LingerMonitorTest method nai.

NetworkAgentInfo nai(int netId, int transport, int networkType, String networkTypeName) {
    NetworkInfo info = new NetworkInfo(networkType, 0, networkTypeName, "");
    NetworkCapabilities caps = new NetworkCapabilities();
    caps.addCapability(0);
    caps.addTransportType(transport);
    NetworkAgentInfo nai = new NetworkAgentInfo(null, null, new Network(netId), info, null, caps, 50, mCtx, null, mMisc, null, mConnService);
    nai.everValidated = true;
    return nai;
}
Also used : NetworkInfo(android.net.NetworkInfo) Network(android.net.Network) NetworkCapabilities(android.net.NetworkCapabilities)

Example 79 with NetworkInfo

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

the class ConnectivityController method updateConstraintsSatisfied.

private boolean updateConstraintsSatisfied(JobStatus jobStatus) {
    final boolean ignoreBlocked = (jobStatus.getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) != 0;
    final NetworkInfo info = mConnManager.getActiveNetworkInfoForUid(jobStatus.getSourceUid(), ignoreBlocked);
    final boolean connected = (info != null) && info.isConnected();
    final boolean unmetered = connected && !info.isMetered();
    final boolean notRoaming = connected && !info.isRoaming();
    boolean changed = false;
    changed |= jobStatus.setConnectivityConstraintSatisfied(connected);
    changed |= jobStatus.setUnmeteredConstraintSatisfied(unmetered);
    changed |= jobStatus.setNotRoamingConstraintSatisfied(notRoaming);
    return changed;
}
Also used : NetworkInfo(android.net.NetworkInfo)

Example 80 with NetworkInfo

use of android.net.NetworkInfo in project Android-CleanArchitecture by android10.

the class AutoLoadImageView method isThereInternetConnection.

/**
   * Checks if the device has any active internet connection.
   *
   * @return true device with internet connection, otherwise false.
   */
private boolean isThereInternetConnection() {
    boolean isConnected;
    final ConnectivityManager connectivityManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    isConnected = (networkInfo != null && networkInfo.isConnectedOrConnecting());
    return isConnected;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Aggregations

NetworkInfo (android.net.NetworkInfo)489 ConnectivityManager (android.net.ConnectivityManager)257 Intent (android.content.Intent)44 LinkProperties (android.net.LinkProperties)38 NetworkState (android.net.NetworkState)26 Test (org.junit.Test)24 PendingIntent (android.app.PendingIntent)22 NetworkCapabilities (android.net.NetworkCapabilities)18 Network (android.net.Network)17 LargeTest (android.test.suitebuilder.annotation.LargeTest)17 RemoteException (android.os.RemoteException)16 Context (android.content.Context)15 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)15 WifiInfo (android.net.wifi.WifiInfo)13 Bundle (android.os.Bundle)13 TestUtils.mockNetworkInfo (com.squareup.picasso.TestUtils.mockNetworkInfo)12 IOException (java.io.IOException)11 WifiManager (android.net.wifi.WifiManager)9 IntentFilter (android.content.IntentFilter)6 SharedPreferences (android.content.SharedPreferences)6