Commit bb398c45 authored by dogmaphobic's avatar dogmaphobic

Keep Android screen on while a vehicle is connected.

parent 760255d7
<?xml version="1.0"?> <?xml version="1.0"?>
<manifest package="org.mavlink.qgroundcontrol" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="2.8.0" android:versionCode="2152" android:installLocation="auto"> <manifest package="org.mavlink.qgroundcontrol" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="2.8.0" android:versionCode="2152" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:icon="@drawable/icon"> <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:icon="@drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qgroundcontrol.qgchelper.UsbDeviceJNI" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="sensorLandscape" android:launchMode="singleTask"> <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qgroundcontrol.qgchelper.UsbDeviceJNI" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="sensorLandscape" android:launchMode="singleTask" android:keepScreenOn="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
......
...@@ -43,6 +43,7 @@ import android.content.IntentFilter; ...@@ -43,6 +43,7 @@ import android.content.IntentFilter;
import android.hardware.usb.*; import android.hardware.usb.*;
import android.widget.Toast; import android.widget.Toast;
import android.util.Log; import android.util.Log;
import android.os.PowerManager;
//-- Text To Speech //-- Text To Speech
import android.os.Bundle; import android.os.Bundle;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
...@@ -53,7 +54,7 @@ import org.qtproject.qt5.android.bindings.QtApplication; ...@@ -53,7 +54,7 @@ import org.qtproject.qt5.android.bindings.QtApplication;
public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListener 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 UsbDeviceJNI m_instance;
private static UsbManager m_manager; // ANDROID USB HOST CLASS private static UsbManager m_manager; // ANDROID USB HOST CLASS
private static List<UsbSerialDriver> m_devices; // LIST OF CURRENT DEVICES private static List<UsbSerialDriver> m_devices; // LIST OF CURRENT DEVICES
...@@ -65,6 +66,7 @@ public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListe ...@@ -65,6 +66,7 @@ public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListe
private final static ExecutorService m_Executor = Executors.newSingleThreadExecutor(); private final static ExecutorService m_Executor = Executors.newSingleThreadExecutor();
private static final String TAG = "QGC_UsbDeviceJNI"; private static final String TAG = "QGC_UsbDeviceJNI";
private static TextToSpeech m_tts; private static TextToSpeech m_tts;
private static PowerManager.WakeLock m_wl;
private final static UsbIoManager.Listener m_Listener = private final static UsbIoManager.Listener m_Listener =
new UsbIoManager.Listener() new UsbIoManager.Listener()
...@@ -113,6 +115,8 @@ public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListe ...@@ -113,6 +115,8 @@ public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListe
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
m_tts = new TextToSpeech(this,this); 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 @Override
...@@ -130,6 +134,24 @@ public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListe ...@@ -130,6 +134,24 @@ public class UsbDeviceJNI extends QtActivity implements TextToSpeech.OnInitListe
m_tts.speak(msg, TextToSpeech.QUEUE_FLUSH, null); 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 // Find all current devices that match the device filter described in the androidmanifest.xml and the
......
...@@ -30,9 +30,15 @@ ...@@ -30,9 +30,15 @@
#include "UAS.h" #include "UAS.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#if defined __android__
#include <QtAndroidExtras/QtAndroidExtras>
#include <QtAndroidExtras/QAndroidJniObject>
#endif
QGC_LOGGING_CATEGORY(MultiVehicleManagerLog, "MultiVehicleManagerLog") QGC_LOGGING_CATEGORY(MultiVehicleManagerLog, "MultiVehicleManagerLog")
const char* MultiVehicleManager::_gcsHeartbeatEnabledKey = "gcsHeartbeatEnabled"; const char* MultiVehicleManager::_gcsHeartbeatEnabledKey = "gcsHeartbeatEnabled";
static const char* kJniClassName = "org/qgroundcontrol/qgchelper/UsbDeviceJNI";
MultiVehicleManager::MultiVehicleManager(QGCApplication* app) MultiVehicleManager::MultiVehicleManager(QGCApplication* app)
: QGCTool(app) : QGCTool(app)
...@@ -108,6 +114,15 @@ void MultiVehicleManager::_vehicleHeartbeatInfo(LinkInterface* link, int vehicle ...@@ -108,6 +114,15 @@ void MultiVehicleManager::_vehicleHeartbeatInfo(LinkInterface* link, int vehicle
emit vehicleAdded(vehicle); emit vehicleAdded(vehicle);
setActiveVehicle(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<void>(kJniClassName, "keepScreenOn", "()V");
}
#endif
} }
/// This slot is connected to the Vehicle::allLinksDestroyed signal such that the Vehicle is deleted /// This slot is connected to the Vehicle::allLinksDestroyed signal such that the Vehicle is deleted
...@@ -141,6 +156,14 @@ void MultiVehicleManager::_deleteVehiclePhase1(Vehicle* vehicle) ...@@ -141,6 +156,14 @@ void MultiVehicleManager::_deleteVehiclePhase1(Vehicle* vehicle)
emit parameterReadyVehicleAvailableChanged(false); emit parameterReadyVehicleAvailableChanged(false);
emit vehicleRemoved(vehicle); 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<void>(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 // 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. // 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 // Even though the above signals should unload any Qml which has references, that Qml will not be destroyed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment