summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2012-11-07 13:02:08 -0800
committerIrfan Sheriff <isheriff@google.com>2012-11-07 13:02:08 -0800
commitcd3d75f35db669f9671d251a36b51cef8a7ca009 (patch)
tree4d75ac834ad9ce765e0d48a78c9ae71ddc9b1d18 /wifi
parent511d5346ced4b37e4ba68e0bd089d4dad8b3bff7 (diff)
downloadframeworks_base-cd3d75f35db669f9671d251a36b51cef8a7ca009.zip
frameworks_base-cd3d75f35db669f9671d251a36b51cef8a7ca009.tar.gz
frameworks_base-cd3d75f35db669f9671d251a36b51cef8a7ca009.tar.bz2
Re-use existing thread
Bug: 7377541 Change-Id: I097f2288ebfc2b4a9782cbced19d9c36d0703acb
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java21
1 files changed, 16 insertions, 5 deletions
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index b871cdc..0e29882 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -508,6 +508,10 @@ public class WifiManager {
private Messenger mWifiServiceMessenger;
private final CountDownLatch mConnected = new CountDownLatch(1);
+ private static Object sThreadRefLock = new Object();
+ private static int sThreadRefCount;
+ private static HandlerThread sHandlerThread;
+
/**
* Create a new WifiManager instance.
* Applications will almost always want to use
@@ -1365,9 +1369,14 @@ public class WifiManager {
return;
}
- HandlerThread t = new HandlerThread("WifiManager");
- t.start();
- mHandler = new ServiceHandler(t.getLooper());
+ synchronized (sThreadRefLock) {
+ if (++sThreadRefCount == 1) {
+ sHandlerThread = new HandlerThread("WifiManager");
+ sHandlerThread.start();
+ }
+ }
+
+ mHandler = new ServiceHandler(sHandlerThread.getLooper());
mAsyncChannel.connect(mContext, mHandler, mWifiServiceMessenger);
try {
mConnected.await();
@@ -1983,8 +1992,10 @@ public class WifiManager {
protected void finalize() throws Throwable {
try {
- if (mHandler != null && mHandler.getLooper() != null) {
- mHandler.getLooper().quit();
+ synchronized (sThreadRefLock) {
+ if (--sThreadRefCount == 0 && sHandlerThread != null) {
+ sHandlerThread.getLooper().quit();
+ }
}
} finally {
super.finalize();