diff options
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | src/org/apache/http/impl/conn/SingleClientConnManager.java | 4 | ||||
-rw-r--r-- | src/org/apache/http/impl/conn/TcmIdleTimerMonitor.java | 84 | ||||
-rw-r--r-- | src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java | 8 |
4 files changed, 91 insertions, 7 deletions
@@ -65,7 +65,7 @@ apache_http_packages := $(strip \ include $(CLEAR_VARS) LOCAL_MODULE := org.apache.http.legacy.boot LOCAL_MODULE_TAGS := optional -LOCAL_JAVA_LIBRARIES := $(apache_http_java_libs) +LOCAL_JAVA_LIBRARIES := $(apache_http_java_libs) tcmiface LOCAL_SRC_FILES := $(apache_http_src_files) LOCAL_SDK_VERSION := 21 LOCAL_MODULE_TAGS := optional diff --git a/src/org/apache/http/impl/conn/SingleClientConnManager.java b/src/org/apache/http/impl/conn/SingleClientConnManager.java index d8fb956..42928fb 100644 --- a/src/org/apache/http/impl/conn/SingleClientConnManager.java +++ b/src/org/apache/http/impl/conn/SingleClientConnManager.java @@ -108,8 +108,7 @@ public class SingleClientConnManager implements ClientConnectionManager { /** Indicates whether this connection manager is shut down. */ protected volatile boolean isShutDown; - - + private TcmIdleTimerMonitor mIdleMonitor; /** * Creates a new simple connection manager. @@ -131,6 +130,7 @@ public class SingleClientConnManager implements ClientConnectionManager { this.lastReleaseTime = -1L; this.alwaysShutDown = false; //@@@ from params? as argument? this.isShutDown = false; + mIdleMonitor = new TcmIdleTimerMonitor(this); } // <constructor> diff --git a/src/org/apache/http/impl/conn/TcmIdleTimerMonitor.java b/src/org/apache/http/impl/conn/TcmIdleTimerMonitor.java new file mode 100644 index 0000000..ac46948 --- /dev/null +++ b/src/org/apache/http/impl/conn/TcmIdleTimerMonitor.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2014, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.apache.http.impl.conn; + +import dalvik.system.PathClassLoader; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import org.apache.http.conn.ClientConnectionManager; +import java.util.concurrent.TimeUnit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import com.quicinc.tcmiface.DpmTcmIface; + +/** + * @hide + */ +public class TcmIdleTimerMonitor implements DpmTcmIface { + private final Log log = LogFactory.getLog(getClass()); + private org.apache.http.conn.ClientConnectionManager connectionManager; + private static Object tcmClient = null; + private static Method mTcmRegisterMethod = null; + private static Object lockObj = new Object(); + Object result = null; + + /** @hide */ + public TcmIdleTimerMonitor(ClientConnectionManager connManager) { + synchronized(lockObj) { + this.connectionManager = connManager; + //load tcm + try { + if (mTcmRegisterMethod == null || tcmClient == null) { + //load tcm if not already loaded + PathClassLoader tcmClassLoader = + new PathClassLoader("/system/framework/tcmclient.jar", + ClassLoader.getSystemClassLoader()); + Class tcmClass = tcmClassLoader.loadClass("com.qti.tcmclient.DpmTcmClient"); + Method mGetTcmMethod = tcmClass.getDeclaredMethod("getInstance"); + tcmClient = mGetTcmMethod.invoke(null); + mTcmRegisterMethod = tcmClass.getDeclaredMethod("registerTcmMonitor", DpmTcmIface.class); + } + if (mTcmRegisterMethod != null && tcmClient != null) { + result = mTcmRegisterMethod.invoke(tcmClient, this); + } + } catch (ClassNotFoundException e) { + //Ignore ClassNotFound Exception + } catch (Exception e) { + log.debug("Failed to load tcmclient " + e); + } + } + } + + /** @hide */ + public synchronized void OnCloseIdleConn() + { + connectionManager.closeIdleConnections(0, TimeUnit.MILLISECONDS); + } +} // class TcmIdleTimerMonitor diff --git a/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java b/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java index 7d6a560..2b16712 100644 --- a/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java +++ b/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java @@ -47,7 +47,7 @@ import org.apache.http.conn.ManagedClientConnection; import org.apache.http.conn.OperatedClientConnection; import org.apache.http.params.HttpParams; import org.apache.http.impl.conn.DefaultClientConnectionOperator; - +import org.apache.http.impl.conn.TcmIdleTimerMonitor; /** @@ -84,8 +84,8 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { /** The operator for opening and updating connections. */ protected ClientConnectionOperator connOperator; - - + /** The operator for monitoring idle connections. */ + private TcmIdleTimerMonitor mIdleMonitor; /** * Creates a new thread safe connection manager. * @@ -101,7 +101,7 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { this.schemeRegistry = schreg; this.connOperator = createConnectionOperator(schreg); this.connectionPool = createConnectionPool(params); - + mIdleMonitor = new TcmIdleTimerMonitor(this); } // <constructor> |