CLOUD: Add Networking::Connection::isLimited()

`false` everywhere by default, but works on Android (`true` if not
Wi-Fi).
This commit is contained in:
Alexander Tkachev 2016-07-19 18:43:00 +06:00
parent 0c1c274abd
commit a13e03e988
10 changed files with 184 additions and 21 deletions

View File

@ -162,14 +162,17 @@ MODULE_OBJS += \
ifeq ($(BACKEND),android)
MODULE_OBJS += \
networking/browser/openurl-android.o
networking/browser/openurl-android.o \
networking/connection/islimited-android.o
else
ifdef MACOSX
MODULE_OBJS += \
networking/browser/openurl-osx.o
networking/browser/openurl-osx.o \
networking/connection/islimited-default.o
else
MODULE_OBJS += \
networking/browser/openurl-posix.o
networking/browser/openurl-posix.o \
networking/connection/islimited-default.o
endif
endif
endif
@ -193,14 +196,16 @@ MODULE_OBJS += \
saves/windows/windows-saves.o \
updates/win32/win32-updates.o \
taskbar/win32/win32-taskbar.o \
networking/browser/openurl-windows.o
networking/browser/openurl-windows.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),androidsdl)
MODULE_OBJS += \
events/androidsdl/androidsdl-events.o \
graphics/androidsdl/androidsdl-graphics.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifdef AMIGAOS
@ -208,7 +213,8 @@ MODULE_OBJS += \
fs/amigaos4/amigaos4-fs.o \
fs/amigaos4/amigaos4-fs-factory.o \
midi/camd.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifdef PLAYSTATION3
@ -217,7 +223,8 @@ MODULE_OBJS += \
fs/posix/posix-fs-factory.o \
fs/ps3/ps3-fs-factory.o \
events/ps3sdl/ps3sdl-events.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifdef USE_LINUXCD
@ -228,7 +235,8 @@ endif
ifeq ($(BACKEND),tizen)
MODULE_OBJS += \
timer/tizen/timer.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),ds)
@ -236,35 +244,40 @@ MODULE_OBJS += \
fs/ds/ds-fs.o \
fs/ds/ds-fs-factory.o \
plugins/ds/ds-provider.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),dingux)
MODULE_OBJS += \
events/dinguxsdl/dinguxsdl-events.o \
graphics/dinguxsdl/dinguxsdl-graphics.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),gph)
MODULE_OBJS += \
events/gph/gph-events.o \
graphics/gph/gph-graphics.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),linuxmoto)
MODULE_OBJS += \
events/linuxmotosdl/linuxmotosdl-events.o \
graphics/linuxmotosdl/linuxmotosdl-graphics.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),maemo)
MODULE_OBJS += \
events/maemosdl/maemosdl-events.o \
graphics/maemosdl/maemosdl-graphics.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),n64)
@ -272,14 +285,16 @@ MODULE_OBJS += \
fs/n64/n64-fs.o \
fs/n64/n64-fs-factory.o \
fs/n64/romfsstream.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),openpandora)
MODULE_OBJS += \
events/openpandora/op-events.o \
graphics/openpandora/op-graphics.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),ps2)
@ -287,7 +302,8 @@ MODULE_OBJS += \
fs/ps2/ps2-fs.o \
fs/ps2/ps2-fs-factory.o \
plugins/ps2/ps2-provider.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),psp)
@ -298,20 +314,23 @@ MODULE_OBJS += \
plugins/psp/psp-provider.o \
saves/psp/psp-saves.o \
timer/psp/timer.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),samsungtv)
MODULE_OBJS += \
events/samsungtvsdl/samsungtvsdl-events.o \
graphics/samsungtvsdl/samsungtvsdl-graphics.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),webos)
MODULE_OBJS += \
events/webossdl/webossdl-events.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),wince)
@ -322,7 +341,8 @@ MODULE_OBJS += \
graphics/wincesdl/wincesdl-graphics.o \
mixer/wincesdl/wincesdl-mixer.o \
plugins/win32/win32-provider.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifeq ($(BACKEND),wii)
@ -330,7 +350,8 @@ MODULE_OBJS += \
fs/wii/wii-fs.o \
fs/wii/wii-fs-factory.o \
plugins/wii/wii-provider.o \
networking/browser/openurl-default.o
networking/browser/openurl-default.o \
networking/connection/islimited-default.o
endif
ifdef ENABLE_EVENTRECORDER

View File

@ -0,0 +1,35 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "backends/networking/connection/islimited.h"
#include "backends/platform/android/jni.h"
namespace Networking {
namespace Connection {
bool isLimited() {
return JNI::isConnectionLimited();
}
} // End of namespace Connection
} // End of namespace Networking

View File

@ -0,0 +1,36 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "backends/networking/connection/islimited.h"
#include "common/textconsole.h"
namespace Networking {
namespace Connection {
bool isLimited() {
warning("Networking::Connection::isLimited(): not limited by default");
return false;
}
} // End of namespace Connection
} // End of namespace Networking

View File

@ -0,0 +1,34 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef NETWORKING_CONNECTION_ISLIMITED_H
#define NETWORKING_CONNECTION_ISLIMITED_H
namespace Networking {
namespace Connection {
bool isLimited();
} // End of namespace Connection
} // End of namespace Networking
#endif /*NETWORKING_CONNECTION_ISLIMITED_H*/

View File

@ -77,6 +77,7 @@ bool JNI::_ready_for_events = 0;
jmethodID JNI::_MID_getDPI = 0;
jmethodID JNI::_MID_displayMessageOnOSD = 0;
jmethodID JNI::_MID_openUrl = 0;
jmethodID JNI::_MID_isConnectionLimited = 0;
jmethodID JNI::_MID_setWindowCaption = 0;
jmethodID JNI::_MID_showVirtualKeyboard = 0;
jmethodID JNI::_MID_getSysArchives = 0;
@ -252,6 +253,22 @@ bool JNI::openUrl(const char *url) {
return success;
}
bool JNI::isConnectionLimited() {
bool limited = false;
JNIEnv *env = JNI::getEnv();
limited = env->CallBooleanMethod(_jobj, _MID_isConnectionLimited);
if (env->ExceptionCheck()) {
LOGE("Failed to check whether connection's limited");
env->ExceptionDescribe();
env->ExceptionClear();
limited = true;
}
return limited;
}
void JNI::setWindowCaption(const char *caption) {
JNIEnv *env = JNI::getEnv();
jstring java_caption = env->NewStringUTF(caption);
@ -432,6 +449,7 @@ void JNI::create(JNIEnv *env, jobject self, jobject asset_manager,
FIND_METHOD(, getDPI, "([F)V");
FIND_METHOD(, displayMessageOnOSD, "(Ljava/lang/String;)V");
FIND_METHOD(, openUrl, "(Ljava/lang/String;)V");
FIND_METHOD(, isConnectionLimited, "()Z");
FIND_METHOD(, showVirtualKeyboard, "(Z)V");
FIND_METHOD(, getSysArchives, "()[Ljava/lang/String;");
FIND_METHOD(, initSurface, "()Ljavax/microedition/khronos/egl/EGLSurface;");

View File

@ -59,6 +59,7 @@ public:
static void getDPI(float *values);
static void displayMessageOnOSD(const char *msg);
static bool openUrl(const char *url);
static bool isConnectionLimited();
static void showVirtualKeyboard(bool enable);
static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority);
@ -91,6 +92,7 @@ private:
static jmethodID _MID_getDPI;
static jmethodID _MID_displayMessageOnOSD;
static jmethodID _MID_openUrl;
static jmethodID _MID_isConnectionLimited;
static jmethodID _MID_setWindowCaption;
static jmethodID _MID_showVirtualKeyboard;
static jmethodID _MID_getSysArchives;

View File

@ -54,6 +54,7 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
abstract protected void getDPI(float[] values);
abstract protected void displayMessageOnOSD(String msg);
abstract protected void openUrl(String url);
abstract protected boolean isConnectionLimited();
abstract protected void setWindowCaption(String caption);
abstract protected void showVirtualKeyboard(boolean enable);
abstract protected String[] getSysArchives();

View File

@ -2,10 +2,13 @@ package org.scummvm.scummvm;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
@ -80,6 +83,15 @@ public class ScummVMActivity extends Activity {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
@Override
protected boolean isConnectionLimited() {
WifiManager wifiMgr = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if (wifiMgr != null && wifiMgr.isWifiEnabled()) {
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
return (wifiInfo == null || wifiInfo.getNetworkId() == -1); //WiFi is on, but it's not connected to any network
}
return true;
}
@Override
protected void setWindowCaption(final String caption) {

View File

@ -40,6 +40,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" android:required="true"/>
<uses-feature android:name="android.hardware.screen.landscape"
android:required="false" />

View File

@ -40,6 +40,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" android:required="true"/>
<uses-feature android:name="android.hardware.screen.landscape"
android:required="false" />