Java Code Examples for org.fourthline.cling.model.ModelUtil#ANDROID_EMULATOR

The following examples show how to use org.fourthline.cling.model.ModelUtil#ANDROID_EMULATOR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidRouter.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public AndroidRouter(UpnpServiceConfiguration configuration,
                     ProtocolFactory protocolFactory,
                     Context context) throws InitializationException {
    super(configuration, protocolFactory);

    this.context = context;
    this.wifiManager = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE));
    this.networkInfo = NetworkUtils.getConnectedNetworkInfo(context);

    // Only register for network connectivity changes if we are not running on emulator
    if (!ModelUtil.ANDROID_EMULATOR) {
        this.broadcastReceiver = new ConnectivityBroadcastReceiver();
        context.registerReceiver(broadcastReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
    }
}
 
Example 2
Source File: AndroidRouter.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public AndroidRouter(UpnpServiceConfiguration configuration,
                     ProtocolFactory protocolFactory,
                     Context context) throws InitializationException {
    super(configuration, protocolFactory);

    this.context = context;
    this.wifiManager = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE));
    this.networkInfo = NetworkUtils.getConnectedNetworkInfo(context);

    // Only register for network connectivity changes if we are not running on emulator
    if (!ModelUtil.ANDROID_EMULATOR) {
        this.broadcastReceiver = new ConnectivityBroadcastReceiver();
        context.registerReceiver(broadcastReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
    }
}
 
Example 3
Source File: StreamClientImpl.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException {
    this.configuration = configuration;

    if (ModelUtil.ANDROID_EMULATOR || ModelUtil.ANDROID_RUNTIME) {
        /*
        See the fantastic PERMITTED_USER_METHODS here:

        https://android.googlesource.com/platform/libcore/+/android-4.0.1_r1.2/luni/src/main/java/java/net/HttpURLConnection.java

        We'd have to basically copy the whole Android code, and have a dependency on
        libcore.*, and do much more hacking to allow more HTTP methods. This is the same
        problem we are hacking below for the JDK but at least there we don't have a
        dependency issue for compiling Cling. These guys all suck, there is no list
        of "permitted" HTTP methods. HttpURLConnection and the whole stream handler
        factory stuff is the worst Java API ever created.
        */
        throw new InitializationException(
            "This client does not work on Android. The design of HttpURLConnection is broken, we "
                + "can not add additional 'permitted' HTTP methods. Read the Cling manual."
        );
    }

    log.fine("Using persistent HTTP stream client connections: " + configuration.isUsePersistentConnections());
    System.setProperty("http.keepAlive", Boolean.toString(configuration.isUsePersistentConnections()));

    // Hack the environment to allow additional HTTP methods
    if (System.getProperty(HACK_STREAM_HANDLER_SYSTEM_PROPERTY) == null) {
        log.fine("Setting custom static URLStreamHandlerFactory to work around bad JDK defaults");
        try {
            // Use reflection to avoid dependency on sun.net package so this class at least
            // loads on Android, even if it doesn't work...
            URL.setURLStreamHandlerFactory(
                (URLStreamHandlerFactory) Class.forName(
                    "org.fourthline.cling.transport.impl.FixedSunURLStreamHandler"
                ).newInstance()
            );
        } catch (Throwable t) {
            throw new InitializationException(
                "Failed to set modified URLStreamHandlerFactory in this environment."
                    + " Can't use bundled default client based on HTTPURLConnection, see manual."
            );
        }
        System.setProperty(HACK_STREAM_HANDLER_SYSTEM_PROPERTY, "alreadyWorkedAroundTheEvilJDK");
    }
}
 
Example 4
Source File: NetworkUtils.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
static public boolean isWifi(NetworkInfo networkInfo) {
    return isNetworkType(networkInfo, ConnectivityManager.TYPE_WIFI) || ModelUtil.ANDROID_EMULATOR;
}
 
Example 5
Source File: StreamClientImpl.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException {
    this.configuration = configuration;

    if (ModelUtil.ANDROID_EMULATOR || ModelUtil.ANDROID_RUNTIME) {
        /*
        See the fantastic PERMITTED_USER_METHODS here:

        https://android.googlesource.com/platform/libcore/+/android-4.0.1_r1.2/luni/src/main/java/java/net/HttpURLConnection.java

        We'd have to basically copy the whole Android code, and have a dependency on
        libcore.*, and do much more hacking to allow more HTTP methods. This is the same
        problem we are hacking below for the JDK but at least there we don't have a
        dependency issue for compiling Cling. These guys all suck, there is no list
        of "permitted" HTTP methods. HttpURLConnection and the whole stream handler
        factory stuff is the worst Java API ever created.
        */
        throw new InitializationException(
            "This client does not work on Android. The design of HttpURLConnection is broken, we "
                + "can not add additional 'permitted' HTTP methods. Read the Cling manual."
        );
    }

    log.fine("Using persistent HTTP stream client connections: " + configuration.isUsePersistentConnections());
    System.setProperty("http.keepAlive", Boolean.toString(configuration.isUsePersistentConnections()));

    // Hack the environment to allow additional HTTP methods
    if (System.getProperty(HACK_STREAM_HANDLER_SYSTEM_PROPERTY) == null) {
        log.fine("Setting custom static URLStreamHandlerFactory to work around bad JDK defaults");
        try {
            // Use reflection to avoid dependency on sun.net package so this class at least
            // loads on Android, even if it doesn't work...
            URL.setURLStreamHandlerFactory(
                (URLStreamHandlerFactory) Class.forName(
                    "org.fourthline.cling.transport.impl.FixedSunURLStreamHandler"
                ).newInstance()
            );
        } catch (Throwable t) {
            throw new InitializationException(
                "Failed to set modified URLStreamHandlerFactory in this environment."
                    + " Can't use bundled default client based on HTTPURLConnection, see manual."
            );
        }
        System.setProperty(HACK_STREAM_HANDLER_SYSTEM_PROPERTY, "alreadyWorkedAroundTheEvilJDK");
    }
}
 
Example 6
Source File: NetworkUtils.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
static public boolean isWifi(NetworkInfo networkInfo) {
    return isNetworkType(networkInfo, ConnectivityManager.TYPE_WIFI) || ModelUtil.ANDROID_EMULATOR;
}