Loading services/core/java/com/android/server/am/LmkdConnection.java +45 −18 Original line number Diff line number Diff line Loading @@ -91,10 +91,18 @@ public class LmkdConnection { @GuardedBy("mLmkdSocketLock") private LocalSocket mLmkdSocket = null; // socket I/O streams @GuardedBy("mLmkdSocketLock") // mutex to synchronize socket output stream with socket creation/destruction private final Object mLmkdOutputStreamLock = new Object(); // socket output stream @GuardedBy("mLmkdOutputStreamLock") private OutputStream mLmkdOutputStream = null; @GuardedBy("mLmkdSocketLock") // mutex to synchronize socket input stream with socket creation/destruction private final Object mLmkdInputStreamLock = new Object(); // socket input stream @GuardedBy("mLmkdInputStreamLock") private InputStream mLmkdInputStream = null; // buffer to store incoming data Loading Loading @@ -148,9 +156,13 @@ public class LmkdConnection { return false; } // connection established synchronized(mLmkdOutputStreamLock) { synchronized(mLmkdInputStreamLock) { mLmkdSocket = socket; mLmkdOutputStream = ostream; mLmkdInputStream = istream; } } mMsgQueue.addOnFileDescriptorEventListener(mLmkdSocket.getFileDescriptor(), EVENT_INPUT | EVENT_ERROR, new MessageQueue.OnFileDescriptorEventListener() { Loading @@ -177,8 +189,14 @@ public class LmkdConnection { mMsgQueue.removeOnFileDescriptorEventListener( mLmkdSocket.getFileDescriptor()); IoUtils.closeQuietly(mLmkdSocket); synchronized(mLmkdOutputStreamLock) { synchronized(mLmkdInputStreamLock) { mLmkdOutputStream = null; mLmkdInputStream = null; mLmkdSocket = null; } } } // wake up reply waiters if any synchronized (mReplyBufLock) { if (mReplyBuf != null) { Loading Loading @@ -262,25 +280,34 @@ public class LmkdConnection { } private boolean write(ByteBuffer buf) { synchronized (mLmkdSocketLock) { boolean result = false; synchronized(mLmkdOutputStreamLock) { if (mLmkdOutputStream != null) { try { mLmkdOutputStream.write(buf.array(), 0, buf.position()); result = true; } catch (IOException ex) { return false; } return true; } } return result; } private int read(ByteBuffer buf) { synchronized (mLmkdSocketLock) { int result = -1; synchronized(mLmkdInputStreamLock) { if (mLmkdInputStream != null) { try { return mLmkdInputStream.read(buf.array(), 0, buf.array().length); result = mLmkdInputStream.read(buf.array(), 0, buf.array().length); } catch (IOException ex) { } return -1; } } return result; } /** * Exchange a request/reply packets with lmkd Loading Loading
services/core/java/com/android/server/am/LmkdConnection.java +45 −18 Original line number Diff line number Diff line Loading @@ -91,10 +91,18 @@ public class LmkdConnection { @GuardedBy("mLmkdSocketLock") private LocalSocket mLmkdSocket = null; // socket I/O streams @GuardedBy("mLmkdSocketLock") // mutex to synchronize socket output stream with socket creation/destruction private final Object mLmkdOutputStreamLock = new Object(); // socket output stream @GuardedBy("mLmkdOutputStreamLock") private OutputStream mLmkdOutputStream = null; @GuardedBy("mLmkdSocketLock") // mutex to synchronize socket input stream with socket creation/destruction private final Object mLmkdInputStreamLock = new Object(); // socket input stream @GuardedBy("mLmkdInputStreamLock") private InputStream mLmkdInputStream = null; // buffer to store incoming data Loading Loading @@ -148,9 +156,13 @@ public class LmkdConnection { return false; } // connection established synchronized(mLmkdOutputStreamLock) { synchronized(mLmkdInputStreamLock) { mLmkdSocket = socket; mLmkdOutputStream = ostream; mLmkdInputStream = istream; } } mMsgQueue.addOnFileDescriptorEventListener(mLmkdSocket.getFileDescriptor(), EVENT_INPUT | EVENT_ERROR, new MessageQueue.OnFileDescriptorEventListener() { Loading @@ -177,8 +189,14 @@ public class LmkdConnection { mMsgQueue.removeOnFileDescriptorEventListener( mLmkdSocket.getFileDescriptor()); IoUtils.closeQuietly(mLmkdSocket); synchronized(mLmkdOutputStreamLock) { synchronized(mLmkdInputStreamLock) { mLmkdOutputStream = null; mLmkdInputStream = null; mLmkdSocket = null; } } } // wake up reply waiters if any synchronized (mReplyBufLock) { if (mReplyBuf != null) { Loading Loading @@ -262,25 +280,34 @@ public class LmkdConnection { } private boolean write(ByteBuffer buf) { synchronized (mLmkdSocketLock) { boolean result = false; synchronized(mLmkdOutputStreamLock) { if (mLmkdOutputStream != null) { try { mLmkdOutputStream.write(buf.array(), 0, buf.position()); result = true; } catch (IOException ex) { return false; } return true; } } return result; } private int read(ByteBuffer buf) { synchronized (mLmkdSocketLock) { int result = -1; synchronized(mLmkdInputStreamLock) { if (mLmkdInputStream != null) { try { return mLmkdInputStream.read(buf.array(), 0, buf.array().length); result = mLmkdInputStream.read(buf.array(), 0, buf.array().length); } catch (IOException ex) { } return -1; } } return result; } /** * Exchange a request/reply packets with lmkd Loading