use of android.net.LocalSocket in project android_frameworks_base by DirtyUnicorns.
the class NetworkTest method testBindSocketOfLocalSocketThrows.
@SmallTest
public void testBindSocketOfLocalSocketThrows() throws Exception {
final LocalSocket mLocalClient = new LocalSocket();
mLocalClient.bind(new LocalSocketAddress("testClient"));
assertTrue(mLocalClient.getFileDescriptor().valid());
try {
mNetwork.bindSocket(mLocalClient.getFileDescriptor());
fail("SocketException not thrown");
} catch (SocketException expected) {
}
final LocalServerSocket mLocalServer = new LocalServerSocket("testServer");
mLocalClient.connect(mLocalServer.getLocalSocketAddress());
assertTrue(mLocalClient.isConnected());
try {
mNetwork.bindSocket(mLocalClient.getFileDescriptor());
fail("SocketException not thrown");
} catch (SocketException expected) {
}
}
use of android.net.LocalSocket in project android_frameworks_base by AOSPA.
the class NativeDaemonConnector method listenToSocket.
private void listenToSocket() throws IOException {
LocalSocket socket = null;
try {
socket = new LocalSocket();
LocalSocketAddress address = determineSocketAddress();
socket.connect(address);
InputStream inputStream = socket.getInputStream();
synchronized (mDaemonLock) {
mOutputStream = socket.getOutputStream();
}
mCallbacks.onDaemonConnected();
FileDescriptor[] fdList = null;
byte[] buffer = new byte[BUFFER_SIZE];
int start = 0;
while (true) {
int count = inputStream.read(buffer, start, BUFFER_SIZE - start);
if (count < 0) {
loge("got " + count + " reading with start = " + start);
break;
}
fdList = socket.getAncillaryFileDescriptors();
// Add our starting point to the count and reset the start.
count += start;
start = 0;
for (int i = 0; i < count; i++) {
if (buffer[i] == 0) {
// Note - do not log this raw message since it may contain
// sensitive data
final String rawEvent = new String(buffer, start, i - start, StandardCharsets.UTF_8);
boolean releaseWl = false;
try {
final NativeDaemonEvent event = NativeDaemonEvent.parseRawEvent(rawEvent, fdList);
log("RCV <- {" + event + "}");
if (event.isClassUnsolicited()) {
// TODO: migrate to sending NativeDaemonEvent instances
if (mCallbacks.onCheckHoldWakeLock(event.getCode()) && mWakeLock != null) {
mWakeLock.acquire();
releaseWl = true;
}
Message msg = mCallbackHandler.obtainMessage(event.getCode(), uptimeMillisInt(), 0, event.getRawEvent());
if (mCallbackHandler.sendMessage(msg)) {
releaseWl = false;
}
} else {
mResponseQueue.add(event.getCmdNumber(), event);
}
} catch (IllegalArgumentException e) {
log("Problem parsing message " + e);
} finally {
if (releaseWl) {
mWakeLock.release();
}
}
start = i + 1;
}
}
if (start == 0) {
log("RCV incomplete");
}
// buffer and read again.
if (start != count) {
final int remaining = BUFFER_SIZE - start;
System.arraycopy(buffer, start, buffer, 0, remaining);
start = remaining;
} else {
start = 0;
}
}
} catch (IOException ex) {
throw ex;
} finally {
synchronized (mDaemonLock) {
if (mOutputStream != null) {
try {
loge("closing stream for " + mSocket);
mOutputStream.close();
} catch (IOException e) {
loge("Failed closing output stream: " + e);
}
mOutputStream = null;
}
}
try {
if (socket != null) {
socket.close();
}
} catch (IOException ex) {
loge("Failed closing socket: " + ex);
}
}
}
use of android.net.LocalSocket in project android_frameworks_base by AOSPA.
the class ProcessList method openLmkdSocket.
private static boolean openLmkdSocket() {
try {
sLmkdSocket = new LocalSocket(LocalSocket.SOCKET_SEQPACKET);
sLmkdSocket.connect(new LocalSocketAddress("lmkd", LocalSocketAddress.Namespace.RESERVED));
sLmkdOutputStream = sLmkdSocket.getOutputStream();
} catch (IOException ex) {
Slog.w(TAG, "lowmemorykiller daemon socket open failed");
sLmkdSocket = null;
return false;
}
return true;
}
use of android.net.LocalSocket in project android_frameworks_base by AOSPA.
the class BluetoothSocket method acceptSocket.
private BluetoothSocket acceptSocket(String RemoteAddr) throws IOException {
BluetoothSocket as = new BluetoothSocket(this);
as.mSocketState = SocketState.CONNECTED;
FileDescriptor[] fds = mSocket.getAncillaryFileDescriptors();
if (DBG)
Log.d(TAG, "socket fd passed by stack fds: " + Arrays.toString(fds));
if (fds == null || fds.length != 1) {
Log.e(TAG, "socket fd passed from stack failed, fds: " + Arrays.toString(fds));
as.close();
throw new IOException("bt socket acept failed");
}
as.mPfd = new ParcelFileDescriptor(fds[0]);
as.mSocket = new LocalSocket(fds[0]);
as.mSocketIS = as.mSocket.getInputStream();
as.mSocketOS = as.mSocket.getOutputStream();
as.mAddress = RemoteAddr;
as.mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(RemoteAddr);
as.mPort = mPort;
return as;
}
use of android.net.LocalSocket in project android_frameworks_base by AOSPA.
the class InstallerConnection method connect.
private boolean connect() {
if (mSocket != null) {
return true;
}
Slog.i(TAG, "connecting...");
try {
mSocket = new LocalSocket();
LocalSocketAddress address = new LocalSocketAddress("installd", LocalSocketAddress.Namespace.RESERVED);
mSocket.connect(address);
mIn = mSocket.getInputStream();
mOut = mSocket.getOutputStream();
} catch (IOException ex) {
disconnect();
return false;
}
return true;
}
Aggregations