Search in sources :

Example 21 with LocalSocket

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;
}
Also used : LocalSocketAddress(android.net.LocalSocketAddress) LocalSocket(android.net.LocalSocket) Method(java.lang.reflect.Method) IOException(java.io.IOException) IOException(java.io.IOException)

Example 22 with LocalSocket

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) {
    }
}
Also used : SocketException(java.net.SocketException) LocalServerSocket(android.net.LocalServerSocket) LocalSocketAddress(android.net.LocalSocketAddress) LocalSocket(android.net.LocalSocket) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 23 with LocalSocket

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;
}
Also used : LocalSocket(android.net.LocalSocket) IOException(java.io.IOException) RemoteException(android.os.RemoteException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 24 with LocalSocket

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;
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) LocalSocket(android.net.LocalSocket) IOException(java.io.IOException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 25 with LocalSocket

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]);
    }
}
Also used : Random(java.util.Random) LocalServerSocket(android.net.LocalServerSocket) LocalSocketAddress(android.net.LocalSocketAddress) ParcelFileDescriptor(android.os.ParcelFileDescriptor) LocalSocket(android.net.LocalSocket) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint)

Aggregations

LocalSocket (android.net.LocalSocket)51 IOException (java.io.IOException)44 LocalSocketAddress (android.net.LocalSocketAddress)32 FileDescriptor (java.io.FileDescriptor)26 ParcelFileDescriptor (android.os.ParcelFileDescriptor)17 LocalServerSocket (android.net.LocalServerSocket)14 SmallTest (android.test.suitebuilder.annotation.SmallTest)11 RemoteException (android.os.RemoteException)10 InputStream (java.io.InputStream)8 Credentials (android.net.Credentials)6 Message (android.os.Message)6 SocketException (java.net.SocketException)6 BufferedWriter (java.io.BufferedWriter)2 DataInputStream (java.io.DataInputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 SuppressLint (android.annotation.SuppressLint)1 InterruptedIOException (java.io.InterruptedIOException)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1