use of android.net.LocalSocket in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class SamsungMulticlientRilExecutor method detect.
@Override
public DetectResult detect() {
String gsmVerRilImpl = "";
try {
Class clazz;
clazz = Class.forName("android.os.SystemProperties");
Method method = clazz.getDeclaredMethod("get", String.class, String.class);
gsmVerRilImpl = (String) method.invoke(null, "gsm.version.ril-impl", "");
} catch (Exception ignore) {
log.debug("ignore this exception?", ignore);
}
// WARNING may have bad consequences...
if (!gsmVerRilImpl.matches("Samsung\\s+RIL\\(IPC\\).*")) {
return DetectResult.Unavailable("gsm.version.ril-impl = " + gsmVerRilImpl);
}
LocalSocket s = new LocalSocket();
try {
s.connect(new LocalSocketAddress(MULTICLIENT_SOCKET));
} catch (IOException e) {
log.warn(e.getMessage());
return DetectResult.Unavailable("Multiclient socket is not available\n" + "gsm.version.ril-impl = " + gsmVerRilImpl);
} finally {
try {
s.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
return DetectResult.AVAILABLE;
}
use of android.net.LocalSocket in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
the class BluetoothSocket method bindListen.
/**
* Currently returns unix errno instead of throwing IOException,
* so that BluetoothAdapter can check the error code for EADDRINUSE
*/
/*package*/
int bindListen() {
int ret;
if (mSocketState == SocketState.CLOSED)
return EBADFD;
IBluetooth bluetoothProxy = BluetoothAdapter.getDefaultAdapter().getBluetoothService(null);
if (bluetoothProxy == null) {
Log.e(TAG, "bindListen fail, reason: bluetooth is off");
return -1;
}
try {
mPfd = bluetoothProxy.createSocketChannel(mType, mServiceName, mUuid, mPort, getSecurityFlags());
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
return -1;
}
// read out port number
try {
synchronized (this) {
if (DBG)
Log.d(TAG, "bindListen(), SocketState: " + mSocketState + ", mPfd: " + mPfd);
if (mSocketState != SocketState.INIT)
return EBADFD;
if (mPfd == null)
return -1;
FileDescriptor fd = mPfd.getFileDescriptor();
if (DBG)
Log.d(TAG, "bindListen(), new LocalSocket ");
mSocket = new LocalSocket(fd);
if (DBG)
Log.d(TAG, "bindListen(), new LocalSocket.getInputStream() ");
mSocketIS = mSocket.getInputStream();
mSocketOS = mSocket.getOutputStream();
}
if (DBG)
Log.d(TAG, "bindListen(), readInt mSocketIS: " + mSocketIS);
int channel = readInt(mSocketIS);
synchronized (this) {
if (mSocketState == SocketState.INIT)
mSocketState = SocketState.LISTENING;
}
if (DBG)
Log.d(TAG, "channel: " + channel);
if (mPort <= -1) {
mPort = channel;
}
// else ASSERT(mPort == channel)
ret = 0;
} catch (IOException e) {
if (mPfd != null) {
try {
mPfd.close();
} catch (IOException e1) {
Log.e(TAG, "bindListen, close mPfd: " + e1);
}
mPfd = null;
}
Log.e(TAG, "bindListen, fail to get port number, exception: " + e);
return -1;
}
return ret;
}
use of android.net.LocalSocket in project android_frameworks_base by crdroidandroid.
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 libstreaming by fyhertz.
the class MediaStream method createSockets.
protected void createSockets() throws IOException {
if (sPipeApi == PIPE_API_LS) {
final String LOCAL_ADDR = "net.majorkernelpanic.streaming-";
for (int i = 0; i < 10; i++) {
try {
mSocketId = new Random().nextInt();
mLss = new LocalServerSocket(LOCAL_ADDR + mSocketId);
break;
} catch (IOException e1) {
}
}
mReceiver = new LocalSocket();
mReceiver.connect(new LocalSocketAddress(LOCAL_ADDR + mSocketId));
mReceiver.setReceiveBufferSize(500000);
mReceiver.setSoTimeout(3000);
mSender = mLss.accept();
mSender.setSendBufferSize(500000);
} else {
Log.e(TAG, "parcelFileDescriptors createPipe version = Lollipop");
mParcelFileDescriptors = ParcelFileDescriptor.createPipe();
mParcelRead = new ParcelFileDescriptor(mParcelFileDescriptors[0]);
mParcelWrite = new ParcelFileDescriptor(mParcelFileDescriptors[1]);
}
}
Aggregations