Search in sources :

Example 1 with IWifiManager

use of android.net.wifi.IWifiManager in project android_frameworks_base by DirtyUnicorns.

the class WifiCommand method run.

public void run(String[] args) {
    boolean validCommand = false;
    if (args.length >= 2) {
        boolean flag = false;
        if ("enable".equals(args[1])) {
            flag = true;
            validCommand = true;
        } else if ("disable".equals(args[1])) {
            flag = false;
            validCommand = true;
        }
        if (validCommand) {
            IWifiManager wifiMgr = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
            try {
                wifiMgr.setWifiEnabled("com.android.shell", flag);
            } catch (RemoteException e) {
                System.err.println("Wi-Fi operation failed: " + e);
            }
            return;
        }
    }
    System.err.println(longHelp());
}
Also used : RemoteException(android.os.RemoteException) IWifiManager(android.net.wifi.IWifiManager)

Example 2 with IWifiManager

use of android.net.wifi.IWifiManager in project android_frameworks_base by AOSPA.

the class AccessPoint method getSummary.

public static String getSummary(Context context, String ssid, DetailedState state, boolean isEphemeral, String passpointProvider) {
    if (state == DetailedState.CONNECTED && ssid == null) {
        if (TextUtils.isEmpty(passpointProvider) == false) {
            // Special case for connected + passpoint networks.
            String format = context.getString(R.string.connected_via_passpoint);
            return String.format(format, passpointProvider);
        } else if (isEphemeral) {
            // Special case for connected + ephemeral networks.
            return context.getString(R.string.connected_via_wfa);
        }
    }
    // Case when there is wifi connected without internet connectivity.
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (state == DetailedState.CONNECTED) {
        IWifiManager wifiManager = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
        NetworkCapabilities nc = null;
        try {
            nc = cm.getNetworkCapabilities(wifiManager.getCurrentNetwork());
        } catch (RemoteException e) {
        }
        if (nc != null) {
            if (nc.hasCapability(nc.NET_CAPABILITY_CAPTIVE_PORTAL)) {
                return context.getString(com.android.internal.R.string.network_available_sign_in);
            } else if (!nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) {
                return context.getString(R.string.wifi_connected_no_internet);
            }
        }
    }
    if (state == null) {
        Log.w(TAG, "state is null, returning empty summary");
        return "";
    }
    String[] formats = context.getResources().getStringArray((ssid == null) ? R.array.wifi_status : R.array.wifi_status_with_ssid);
    int index = state.ordinal();
    if (index >= formats.length || formats[index].length() == 0) {
        return "";
    }
    return String.format(formats[index], ssid);
}
Also used : ConnectivityManager(android.net.ConnectivityManager) SpannableString(android.text.SpannableString) RemoteException(android.os.RemoteException) NetworkCapabilities(android.net.NetworkCapabilities) IWifiManager(android.net.wifi.IWifiManager)

Example 3 with IWifiManager

use of android.net.wifi.IWifiManager in project android_frameworks_base by ParanoidAndroid.

the class WifiCommand method run.

public void run(String[] args) {
    boolean validCommand = false;
    if (args.length >= 2) {
        boolean flag = false;
        if ("enable".equals(args[1])) {
            flag = true;
            validCommand = true;
        } else if ("disable".equals(args[1])) {
            flag = false;
            validCommand = true;
        } else if ("prefer".equals(args[1])) {
            IConnectivityManager connMgr = IConnectivityManager.Stub.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
            try {
                connMgr.setNetworkPreference(ConnectivityManager.TYPE_WIFI);
            } catch (RemoteException e) {
                System.err.println("Failed to set preferred network: " + e);
            }
            return;
        }
        if (validCommand) {
            IWifiManager wifiMgr = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
            try {
                wifiMgr.setWifiEnabled(flag);
            } catch (RemoteException e) {
                System.err.println("Wi-Fi operation failed: " + e);
            }
            return;
        }
    }
    System.err.println(longHelp());
}
Also used : IConnectivityManager(android.net.IConnectivityManager) RemoteException(android.os.RemoteException) IWifiManager(android.net.wifi.IWifiManager)

Example 4 with IWifiManager

use of android.net.wifi.IWifiManager in project platform_frameworks_base by android.

the class WifiCommand method run.

public void run(String[] args) {
    boolean validCommand = false;
    if (args.length >= 2) {
        boolean flag = false;
        if ("enable".equals(args[1])) {
            flag = true;
            validCommand = true;
        } else if ("disable".equals(args[1])) {
            flag = false;
            validCommand = true;
        }
        if (validCommand) {
            IWifiManager wifiMgr = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
            try {
                wifiMgr.setWifiEnabled("com.android.shell", flag);
            } catch (RemoteException e) {
                System.err.println("Wi-Fi operation failed: " + e);
            }
            return;
        }
    }
    System.err.println(longHelp());
}
Also used : RemoteException(android.os.RemoteException) IWifiManager(android.net.wifi.IWifiManager)

Example 5 with IWifiManager

use of android.net.wifi.IWifiManager in project platform_frameworks_base by android.

the class AccessPoint method getSummary.

public static String getSummary(Context context, String ssid, DetailedState state, boolean isEphemeral, String passpointProvider) {
    if (state == DetailedState.CONNECTED && ssid == null) {
        if (TextUtils.isEmpty(passpointProvider) == false) {
            // Special case for connected + passpoint networks.
            String format = context.getString(R.string.connected_via_passpoint);
            return String.format(format, passpointProvider);
        } else if (isEphemeral) {
            // Special case for connected + ephemeral networks.
            return context.getString(R.string.connected_via_wfa);
        }
    }
    // Case when there is wifi connected without internet connectivity.
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (state == DetailedState.CONNECTED) {
        IWifiManager wifiManager = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
        Network nw;
        try {
            nw = wifiManager.getCurrentNetwork();
        } catch (RemoteException e) {
            nw = null;
        }
        NetworkCapabilities nc = cm.getNetworkCapabilities(nw);
        if (nc != null && !nc.hasCapability(nc.NET_CAPABILITY_VALIDATED)) {
            return context.getString(R.string.wifi_connected_no_internet);
        }
    }
    String[] formats = context.getResources().getStringArray((ssid == null) ? R.array.wifi_status : R.array.wifi_status_with_ssid);
    int index = state.ordinal();
    if (index >= formats.length || formats[index].length() == 0) {
        return "";
    }
    return String.format(formats[index], ssid);
}
Also used : ConnectivityManager(android.net.ConnectivityManager) Network(android.net.Network) SpannableString(android.text.SpannableString) RemoteException(android.os.RemoteException) NetworkCapabilities(android.net.NetworkCapabilities) IWifiManager(android.net.wifi.IWifiManager)

Aggregations

IWifiManager (android.net.wifi.IWifiManager)12 RemoteException (android.os.RemoteException)12 ConnectivityManager (android.net.ConnectivityManager)5 NetworkCapabilities (android.net.NetworkCapabilities)5 SpannableString (android.text.SpannableString)5 IConnectivityManager (android.net.IConnectivityManager)1 Network (android.net.Network)1 WifiInfo (android.net.wifi.WifiInfo)1