summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSusheel Yadagiri <syadagir@codeaurora.org>2014-10-06 10:38:29 -0700
committerLinux Build Service Account <lnxbuild@localhost>2015-10-06 03:20:40 -0600
commitadbbf08b69c5534ce1bb740a55cadb007a5b4408 (patch)
tree524a47bb6d919bc129a155f1be37e2854d7060f5
parent80540ef1af51ed239d0c50e077c17163261b70aa (diff)
downloadandroid_external_apache-http-adbbf08b69c5534ce1bb740a55cadb007a5b4408.tar.gz
android_external_apache-http-adbbf08b69c5534ce1bb740a55cadb007a5b4408.tar.bz2
android_external_apache-http-adbbf08b69c5534ce1bb740a55cadb007a5b4408.zip
Add TCM (TCP Connection Management) support
TCM service indicates to close the TCP idle connections on time so that the application servers do not time out on connection and wake the modem cellular data connection up and cost power. Change-Id: I0c041eb46f9d4be1b9fbce677b8da5cb458a85b0
-rw-r--r--Android.mk2
-rw-r--r--src/org/apache/http/impl/conn/SingleClientConnManager.java4
-rw-r--r--src/org/apache/http/impl/conn/TcmIdleTimerMonitor.java84
-rw-r--r--src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java8
4 files changed, 91 insertions, 7 deletions
diff --git a/Android.mk b/Android.mk
index 9dffd55..f2a219e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -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>