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

The following examples show how to use org.fourthline.cling.model.ModelUtil#ANDROID_RUNTIME . 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: DefaultUpnpServiceConfiguration.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected DefaultUpnpServiceConfiguration(int streamListenPort, boolean checkRuntime) {
    if (checkRuntime && ModelUtil.ANDROID_RUNTIME) {
        throw new Error("Unsupported runtime environment, use org.fourthline.cling.android.AndroidUpnpServiceConfiguration");
    }

    this.streamListenPort = streamListenPort;

    defaultExecutorService = createDefaultExecutorService();

    datagramProcessor = createDatagramProcessor();
    soapActionProcessor = createSOAPActionProcessor();
    genaEventProcessor = createGENAEventProcessor();

    deviceDescriptorBinderUDA10 = createDeviceDescriptorBinderUDA10();
    serviceDescriptorBinderUDA10 = createServiceDescriptorBinderUDA10();

    namespace = createNamespace();
}
 
Example 2
Source File: DefaultUpnpServiceConfiguration.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected DefaultUpnpServiceConfiguration(int streamListenPort, boolean checkRuntime) {
    if (checkRuntime && ModelUtil.ANDROID_RUNTIME) {
        throw new Error("Unsupported runtime environment, use org.fourthline.cling.android.AndroidUpnpServiceConfiguration");
    }

    this.streamListenPort = streamListenPort;

    defaultExecutorService = createDefaultExecutorService();

    datagramProcessor = createDatagramProcessor();
    soapActionProcessor = createSOAPActionProcessor();
    genaEventProcessor = createGENAEventProcessor();

    deviceDescriptorBinderUDA10 = createDeviceDescriptorBinderUDA10();
    serviceDescriptorBinderUDA10 = createServiceDescriptorBinderUDA10();

    namespace = createNamespace();
}
 
Example 3
Source File: RemoteDeviceIdentity.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
  public String toString() {
      // Performance optimization, so we don't have to wrap all log("foo " + device) calls with isLoggable
if(ModelUtil.ANDROID_RUNTIME) {
          return "(RemoteDeviceIdentity) UDN: " + getUdn() + ", Descriptor: " + getDescriptorURL();
      }
      return "(" + getClass().getSimpleName() + ") UDN: " + getUdn() + ", Descriptor: " + getDescriptorURL();
  }
 
Example 4
Source File: AVTransportLastChangeParser.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Source[] getSchemaSources() {
    // TODO: Android 2.2 has a broken SchemaFactory, we can't validate
    // http://code.google.com/p/android/issues/detail?id=9491&q=schemafactory&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
    if (!ModelUtil.ANDROID_RUNTIME) {
        return new Source[]{new StreamSource(
                Thread.currentThread().getContextClassLoader().getResourceAsStream(SCHEMA_RESOURCE)
        )};
    }
    return null;
}
 
Example 5
Source File: RenderingControlLastChangeParser.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Source[] getSchemaSources() {
    // TODO: Android 2.2 has a broken SchemaFactory, we can't validate
    // http://code.google.com/p/android/issues/detail?id=9491&q=schemafactory&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
    if (!ModelUtil.ANDROID_RUNTIME) {
        return new Source[]{new StreamSource(
                Thread.currentThread().getContextClassLoader().getResourceAsStream(SCHEMA_RESOURCE)
        )};
    }
    return null;
}
 
Example 6
Source File: RemoteDeviceIdentity.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
  public String toString() {
      // Performance optimization, so we don't have to wrap all log("foo " + device) calls with isLoggable
if(ModelUtil.ANDROID_RUNTIME) {
          return "(RemoteDeviceIdentity) UDN: " + getUdn() + ", Descriptor: " + getDescriptorURL();
      }
      return "(" + getClass().getSimpleName() + ") UDN: " + getUdn() + ", Descriptor: " + getDescriptorURL();
  }
 
Example 7
Source File: AVTransportLastChangeParser.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Source[] getSchemaSources() {
    // TODO: Android 2.2 has a broken SchemaFactory, we can't validate
    // http://code.google.com/p/android/issues/detail?id=9491&q=schemafactory&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
    if (!ModelUtil.ANDROID_RUNTIME) {
        return new Source[]{new StreamSource(
                Thread.currentThread().getContextClassLoader().getResourceAsStream(SCHEMA_RESOURCE)
        )};
    }
    return null;
}
 
Example 8
Source File: RenderingControlLastChangeParser.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Source[] getSchemaSources() {
    // TODO: Android 2.2 has a broken SchemaFactory, we can't validate
    // http://code.google.com/p/android/issues/detail?id=9491&q=schemafactory&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
    if (!ModelUtil.ANDROID_RUNTIME) {
        return new Source[]{new StreamSource(
                Thread.currentThread().getContextClassLoader().getResourceAsStream(SCHEMA_RESOURCE)
        )};
    }
    return null;
}
 
Example 9
Source File: ManagedUpnpServiceConfiguration.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
@PostConstruct
public void init() {

    if (ModelUtil.ANDROID_RUNTIME) {
        throw new Error("Unsupported runtime environment, use org.fourthline.cling.android.AndroidUpnpServiceConfiguration");
    }

    this.streamListenPort = NetworkAddressFactoryImpl.DEFAULT_TCP_HTTP_LISTEN_PORT;

    defaultExecutorService = createDefaultExecutorService();

    soapActionProcessor = createSOAPActionProcessor();
    genaEventProcessor = createGENAEventProcessor();

    deviceDescriptorBinderUDA10 = createDeviceDescriptorBinderUDA10();
    serviceDescriptorBinderUDA10 = createServiceDescriptorBinderUDA10();

    namespace = createNamespace();
}
 
Example 10
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 11
Source File: ManagedUpnpServiceConfiguration.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
@PostConstruct
public void init() {

    if (ModelUtil.ANDROID_RUNTIME) {
        throw new Error("Unsupported runtime environment, use org.fourthline.cling.android.AndroidUpnpServiceConfiguration");
    }

    this.streamListenPort = NetworkAddressFactoryImpl.DEFAULT_TCP_HTTP_LISTEN_PORT;

    defaultExecutorService = createDefaultExecutorService();

    soapActionProcessor = createSOAPActionProcessor();
    genaEventProcessor = createGENAEventProcessor();

    deviceDescriptorBinderUDA10 = createDeviceDescriptorBinderUDA10();
    serviceDescriptorBinderUDA10 = createServiceDescriptorBinderUDA10();

    namespace = createNamespace();
}
 
Example 12
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");
    }
}