[adb-wireless] Allow ADB-over-WiFi when WiFi is not default
When other network types with higher priority than wifi is connected alongside wifi, turning on ADB over wifi is not possible. This is happening due to `isWifiConnected()` only checks if wifi is the default network and not if wifi is connected. Often times multiple networks such as ethernet is used in conjuction with wifi, making ADB over wifi not working with the setup. Fix by returning if any available network is a WiFi network. Bug: 173466085 Test: Tested on eve Chrome OS ARCVM, ADB WiFi can be toggled when WiFi is not the default network. Change-Id: I8474a4e8b37a4af0031e1462645509f1e634e9a8
This commit is contained in:
@@ -20,7 +20,8 @@ import android.content.Context;
|
|||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.debug.IAdbManager;
|
import android.debug.IAdbManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.Network;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -141,10 +142,16 @@ public class WirelessDebuggingPreferenceController extends DeveloperOptionsPrefe
|
|||||||
public static boolean isWifiConnected(Context context) {
|
public static boolean isWifiConnected(Context context) {
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(
|
||||||
Context.CONNECTIVITY_SERVICE);
|
Context.CONNECTIVITY_SERVICE);
|
||||||
if (cm != null) {
|
if (cm == null) {
|
||||||
NetworkInfo info = cm.getActiveNetworkInfo();
|
return false;
|
||||||
if (info != null && info.isConnected()) {
|
}
|
||||||
return info.getType() == ConnectivityManager.TYPE_WIFI;
|
for (Network network : cm.getAllNetworks()) {
|
||||||
|
final NetworkCapabilities nc = cm.getNetworkCapabilities(network);
|
||||||
|
if (nc == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user