Merge "Re-use existing thread" into jb-mr1.1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1f6cf5fade
@@ -508,6 +508,10 @@ public class WifiManager {
|
|||||||
private Messenger mWifiServiceMessenger;
|
private Messenger mWifiServiceMessenger;
|
||||||
private final CountDownLatch mConnected = new CountDownLatch(1);
|
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.
|
* Create a new WifiManager instance.
|
||||||
* Applications will almost always want to use
|
* Applications will almost always want to use
|
||||||
@@ -1365,9 +1369,14 @@ public class WifiManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandlerThread t = new HandlerThread("WifiManager");
|
synchronized (sThreadRefLock) {
|
||||||
t.start();
|
if (++sThreadRefCount == 1) {
|
||||||
mHandler = new ServiceHandler(t.getLooper());
|
sHandlerThread = new HandlerThread("WifiManager");
|
||||||
|
sHandlerThread.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mHandler = new ServiceHandler(sHandlerThread.getLooper());
|
||||||
mAsyncChannel.connect(mContext, mHandler, mWifiServiceMessenger);
|
mAsyncChannel.connect(mContext, mHandler, mWifiServiceMessenger);
|
||||||
try {
|
try {
|
||||||
mConnected.await();
|
mConnected.await();
|
||||||
@@ -1983,8 +1992,10 @@ public class WifiManager {
|
|||||||
|
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
try {
|
try {
|
||||||
if (mHandler != null && mHandler.getLooper() != null) {
|
synchronized (sThreadRefLock) {
|
||||||
mHandler.getLooper().quit();
|
if (--sThreadRefCount == 0 && sHandlerThread != null) {
|
||||||
|
sHandlerThread.getLooper().quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
super.finalize();
|
super.finalize();
|
||||||
|
|||||||
Reference in New Issue
Block a user