Browse Source

Take MulticastLock on Android to ensure broadcast packets can be received (#9199)

* Take MulticastLock on Android to ensure broadcast packets can be received.  This may belong in Qt for Android.  See QTBUG-73138

* Use a more descriptive name for the WiFiManager Multicast Lock
QGC4.4
brad112358 4 years ago committed by GitHub
parent
commit
3b7dd6e87c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      android/AndroidManifest.xml
  2. 18
      android/src/org/mavlink/qgroundcontrol/QGCActivity.java

3
android/AndroidManifest.xml

@ -54,6 +54,9 @@
<!-- Needed to keep working while 'asleep' --> <!-- Needed to keep working while 'asleep' -->
<uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- Need MulticastLock to receive broadcast UDP packets -->
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application. <!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions. --> Remove the comment if you do not require these default permissions. -->
<!-- %%INSERT_PERMISSIONS --> <!-- %%INSERT_PERMISSIONS -->

18
android/src/org/mavlink/qgroundcontrol/QGCActivity.java

@ -52,6 +52,7 @@ import android.hardware.usb.UsbManager;
import android.widget.Toast; import android.widget.Toast;
import android.util.Log; import android.util.Log;
import android.os.PowerManager; import android.os.PowerManager;
import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.view.WindowManager; import android.view.WindowManager;
@ -76,6 +77,7 @@ public class QGCActivity extends QtActivity
private static PendingIntent _usbPermissionIntent = null; private static PendingIntent _usbPermissionIntent = null;
private TaiSync taiSync = null; private TaiSync taiSync = null;
private Timer probeAccessoriesTimer = null; private Timer probeAccessoriesTimer = null;
private static WifiManager.MulticastLock _wifiMulticastLock;
public static Context m_context; public static Context m_context;
@ -222,6 +224,18 @@ public class QGCActivity extends QtActivity
// Create intent for usb permission request // Create intent for usb permission request
_usbPermissionIntent = PendingIntent.getBroadcast(_instance, 0, new Intent(ACTION_USB_PERMISSION), 0); _usbPermissionIntent = PendingIntent.getBroadcast(_instance, 0, new Intent(ACTION_USB_PERMISSION), 0);
// Workaround for QTBUG-73138
if (_wifiMulticastLock == null)
{
WifiManager wifi = (WifiManager) _instance.getSystemService(Context.WIFI_SERVICE);
_wifiMulticastLock = wifi.createMulticastLock("QGroundControl");
_wifiMulticastLock.setReferenceCounted(true);
}
_wifiMulticastLock.acquire();
Log.d(TAG, "Multicast lock: " + _wifiMulticastLock.toString());
try { try {
taiSync = new TaiSync(); taiSync = new TaiSync();
@ -259,6 +273,10 @@ public class QGCActivity extends QtActivity
} }
unregisterReceiver(mOpenAccessoryReceiver); unregisterReceiver(mOpenAccessoryReceiver);
try { try {
if (_wifiMulticastLock != null) {
_wifiMulticastLock.release();
Log.d(TAG, "Multicast lock released.");
}
if(_wakeLock != null) { if(_wakeLock != null) {
_wakeLock.release(); _wakeLock.release();
} }

Loading…
Cancel
Save