diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index ed0d31ea19313b058c6c461c44c89f810efc2626..d9fc4fc403a4a4f6eae4af5b155fcd4f960f4e13 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -1,7 +1,7 @@ - + diff --git a/android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java b/android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java index 962428ed15e7f58bde2bf42f6dcfe7b4642857b6..b3157061d33fbe9ceab16b2a26b455639e4d1f04 100644 --- a/android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java +++ b/android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java @@ -43,6 +43,7 @@ import android.content.IntentFilter; import android.hardware.usb.*; import android.widget.Toast; import android.util.Log; +import android.os.PowerManager; //-- Text To Speech import android.os.Bundle; import android.speech.tts.TextToSpeech; @@ -53,7 +54,7 @@ import org.qtproject.qt5.android.bindings.QtApplication; public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListener { - public static int BAD_PORT = 0; + public static int BAD_PORT = 0; private static UsbDeviceJNI m_instance; private static UsbManager m_manager; // ANDROID USB HOST CLASS private static List m_devices; // LIST OF CURRENT DEVICES @@ -65,6 +66,7 @@ public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListe private final static ExecutorService m_Executor = Executors.newSingleThreadExecutor(); private static final String TAG = "QGC_UsbDeviceJNI"; private static TextToSpeech m_tts; + private static PowerManager.WakeLock m_wl; private final static UsbIoManager.Listener m_Listener = new UsbIoManager.Listener() @@ -113,6 +115,8 @@ public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListe public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); m_tts = new TextToSpeech(this,this); + PowerManager pm = (PowerManager)m_instance.getSystemService(Context.POWER_SERVICE); + m_wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "QGroundControl"); } @Override @@ -130,6 +134,24 @@ public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListe m_tts.speak(msg, TextToSpeech.QUEUE_FLUSH, null); } + public static void keepScreenOn() + { + if(m_wl != null) { + m_wl.acquire(); + Log.i(TAG, "SCREEN_BRIGHT_WAKE_LOCK acquired."); + } else { + Log.i(TAG, "SCREEN_BRIGHT_WAKE_LOCK not acquired!!!"); + } + } + + public static void restoreScreenOn() + { + if(m_wl != null) { + m_wl.release(); + Log.i(TAG, "SCREEN_BRIGHT_WAKE_LOCK released."); + } + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////// // // Find all current devices that match the device filter described in the androidmanifest.xml and the diff --git a/src/Vehicle/MultiVehicleManager.cc b/src/Vehicle/MultiVehicleManager.cc index 3e324d599d9a2b2d6f416deff45aef29f2251c47..7646e92e82fb5248337c4374c735898592892de0 100644 --- a/src/Vehicle/MultiVehicleManager.cc +++ b/src/Vehicle/MultiVehicleManager.cc @@ -32,10 +32,19 @@ #include +#if defined __android__ +#include +#include +#endif + QGC_LOGGING_CATEGORY(MultiVehicleManagerLog, "MultiVehicleManagerLog") const char* MultiVehicleManager::_gcsHeartbeatEnabledKey = "gcsHeartbeatEnabled"; +#if defined __android__ +static const char* kJniClassName = "org/qgroundcontrol/qgchelper/UsbDeviceJNI"; +#endif + MultiVehicleManager::MultiVehicleManager(QGCApplication* app) : QGCTool(app) , _activeVehicleAvailable(false) @@ -110,6 +119,15 @@ void MultiVehicleManager::_vehicleHeartbeatInfo(LinkInterface* link, int vehicle emit vehicleAdded(vehicle); setActiveVehicle(vehicle); + +#if defined __android__ + if(_vehicles.count() == 1) { + //-- Once a vehicle is connected, keep Android screen from going off + qCDebug(MultiVehicleManagerLog) << "QAndroidJniObject::keepScreenOn"; + QAndroidJniObject::callStaticMethod(kJniClassName, "keepScreenOn", "()V"); + } +#endif + } /// This slot is connected to the Vehicle::allLinksDestroyed signal such that the Vehicle is deleted @@ -143,6 +161,14 @@ void MultiVehicleManager::_deleteVehiclePhase1(Vehicle* vehicle) emit parameterReadyVehicleAvailableChanged(false); emit vehicleRemoved(vehicle); +#if defined __android__ + if(_vehicles.count() == 0) { + //-- Once no vehicles are connected, we no longer need to keep Android screen from going off + qCDebug(MultiVehicleManagerLog) << "QAndroidJniObject::restoreScreenOn"; + QAndroidJniObject::callStaticMethod(kJniClassName, "restoreScreenOn", "()V"); + } +#endif + // We must let the above signals flow through the system as well as get back to the main loop event queue // before we can actually delete the Vehicle. The reason is that Qml may be holding on the references to it. // Even though the above signals should unload any Qml which has references, that Qml will not be destroyed