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());
}
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);
}
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());
}
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());
}
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);
}
Aggregations