diff --git a/app/src/main/java/com/openipc/pixelpilot/VideoActivity.java b/app/src/main/java/com/openipc/pixelpilot/VideoActivity.java index cacfc1ba..2bbe6615 100644 --- a/app/src/main/java/com/openipc/pixelpilot/VideoActivity.java +++ b/app/src/main/java/com/openipc/pixelpilot/VideoActivity.java @@ -16,6 +16,7 @@ import android.hardware.usb.UsbManager; import android.net.Uri; import android.net.VpnService; +import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.BatteryManager; import android.os.Build; @@ -114,7 +115,6 @@ public class VideoActivity extends AppCompatActivity implements IVideoParamsChan private static final long MODEL_LITE2_BYTES = 23096891L; private static final String PREF_OD_CUSTOM_MODEL_URI = "od_custom_model_uri"; private static final String PREF_OD_CUSTOM_MODEL_NAME = "od_custom_model_name"; - private static WifiManager wifiManager; final Handler handler = new Handler(Looper.getMainLooper()); final Runnable runnable = new Runnable() { public void run() { @@ -170,8 +170,26 @@ public static int getBandwidth(Context context) { Context.MODE_PRIVATE).getInt("bandwidth", 20); } - public static String wirelessInfo() { - int address = wifiManager.getConnectionInfo().getIpAddress(); + /** + * IPv4 address on the device's own wifi, used to tell the user where to push a stream + * when no adapter is attached. Returns null when there is nothing to report. + * + *

Takes a Context rather than reading a static WifiManager that only + * {@link #initializeUI()} assigns: any other caller - or this one before onCreate has got + * that far - hits a NullPointerException, and this is called from + * WfbLinkManager.refreshAdapters(). + */ + public static String wirelessInfo(Context context) { + WifiManager manager = + (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); + if (manager == null) { + return null; + } + WifiInfo info = manager.getConnectionInfo(); + if (info == null) { + return null; + } + int address = info.getIpAddress(); return (address == 0) ? null : Formatter.formatIpAddress(address); } @@ -324,7 +342,6 @@ private void initializeUI() { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); - wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); } // ---------------------------------------------------------------------------- diff --git a/app/src/main/java/com/openipc/pixelpilot/WfbLinkManager.java b/app/src/main/java/com/openipc/pixelpilot/WfbLinkManager.java index 8580be69..7a3b7995 100644 --- a/app/src/main/java/com/openipc/pixelpilot/WfbLinkManager.java +++ b/app/src/main/java/com/openipc/pixelpilot/WfbLinkManager.java @@ -102,7 +102,13 @@ public Map getAttachedAdapters() { } Map res = new HashMap<>(); - for (UsbDevice dev : manager.getDeviceList().values()) { + Map attached = manager.getDeviceList(); + // "No compatible wifi adapter found." is a common report, and the one thing needed to + // act on it - the adapter's vendor and product id - was not obtainable. sysfs is not + // readable by the shell on some devices (Horizon OS for one) and dumpsys usb does not + // list host devices there either, so the app is the only thing that can report it. + Log.i(TAG, "usb devices attached: " + attached.size()); + for (UsbDevice dev : attached.values()) { boolean allowed = false; for (UsbDeviceFilter filter : filters) { if (filter.productId == dev.getProductId() && filter.vendorId == dev.getVendorId()) { @@ -110,6 +116,13 @@ public Map getAttachedAdapters() { break; } } + Log.i(TAG, String.format(" %s %04X:%04X %s %s -> %s", + dev.getDeviceName(), + dev.getVendorId(), + dev.getProductId(), + String.valueOf(dev.getManufacturerName()), + String.valueOf(dev.getProductName()), + allowed ? "supported" : "NOT in usb_device_filter.xml")); if (!allowed) { continue; } @@ -164,7 +177,7 @@ public synchronized void refreshAdapters() { binding.tvMessage.setText(text); binding.tvMessage.setVisibility(View.VISIBLE); - String wifi = VideoActivity.wirelessInfo(); + String wifi = VideoActivity.wirelessInfo(context); if (wifi != null) { String local = "udp://" + wifi + ":5600"; binding.wifiMessage.setText(local);