Hold a high performance Wi-Fi lock while streaming

This commit is contained in:
Cameron Gutman 2014-06-19 18:26:33 -07:00
parent 411931cc27
commit 329a938bf8
2 changed files with 18 additions and 1 deletions

View File

@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" /> <uses-feature android:name="android.hardware.touchscreen" android:required="false" />

View File

@ -19,6 +19,7 @@ import android.content.SharedPreferences;
import android.graphics.Point; import android.graphics.Point;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.view.Display; import android.view.Display;
@ -56,6 +57,8 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
private boolean connecting = false; private boolean connecting = false;
private boolean connected = false; private boolean connected = false;
private WifiManager.WifiLock wifiLock;
private int drFlags = 0; private int drFlags = 0;
public static final String PREFS_FILE_NAME = "gameprefs"; public static final String PREFS_FILE_NAME = "gameprefs";
@ -153,6 +156,12 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
// Warn the user if they're on a metered connection // Warn the user if they're on a metered connection
checkDataConnection(); checkDataConnection();
// Make sure Wi-Fi is fully powered up
WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiLock = wifiMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Limelight");
wifiLock.setReferenceCounted(false);
wifiLock.acquire();
// Start the connection // Start the connection
conn = new NvConnection(Game.this.getIntent().getStringExtra("host"), Game.this, conn = new NvConnection(Game.this.getIntent().getStringExtra("host"), Game.this,
new StreamConfiguration(width, height, refreshRate, bitrate * 1000), PlatformBinding.getCryptoProvider(this)); new StreamConfiguration(width, height, refreshRate, bitrate * 1000), PlatformBinding.getCryptoProvider(this));
@ -214,6 +223,13 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
finish(); finish();
} }
@Override
protected void onDestroy() {
super.onDestroy();
wifiLock.release();
}
private static byte getModifierState(KeyEvent event) { private static byte getModifierState(KeyEvent event) {
byte modifier = 0; byte modifier = 0;
if (event.isShiftPressed()) { if (event.isShiftPressed()) {