Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions app/src/main/java/com/openipc/pixelpilot/VideoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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.
*
* <p>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);
}

Expand Down Expand Up @@ -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);
}

// ----------------------------------------------------------------------------
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/com/openipc/pixelpilot/WfbLinkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,27 @@ public Map<String, UsbDevice> getAttachedAdapters() {
}

Map<String, UsbDevice> res = new HashMap<>();
for (UsbDevice dev : manager.getDeviceList().values()) {
Map<String, UsbDevice> 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()) {
allowed = true;
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"));
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
if (!allowed) {
continue;
}
Expand Down Expand Up @@ -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);
Expand Down