android.net.LocalSocketAddress Java Examples

The following examples show how to use android.net.LocalSocketAddress. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecoverySystemService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private LocalSocket connectService() {
    LocalSocket socket = new LocalSocket();
    boolean done = false;
    // The uncrypt socket will be created by init upon receiving the
    // service request. It may not be ready by this point. So we will
    // keep retrying until success or reaching timeout.
    for (int retry = 0; retry < SOCKET_CONNECTION_MAX_RETRY; retry++) {
        try {
            socket.connect(new LocalSocketAddress(UNCRYPT_SOCKET,
                    LocalSocketAddress.Namespace.RESERVED));
            done = true;
            break;
        } catch (IOException ignored) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Slog.w(TAG, "Interrupted:", e);
            }
        }
    }
    if (!done) {
        Slog.e(TAG, "Timed out connecting to uncrypt socket");
        return null;
    }
    return socket;
}
 
Example #2
Source File: MediaStream.java    From spydroid-ipcamera with GNU General Public License v3.0 6 votes vote down vote up
protected void createSockets() throws IOException {

		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);
	}
 
Example #3
Source File: ShadowsocksVpnThread.java    From Maying with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        ShadowsocksApplication.app.track(e);
        return false;
    }
}
 
Example #4
Source File: TrafficMonitorThread.java    From Maying with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        return false;
    }
}
 
Example #5
Source File: ShadowsocksVpnThread.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        app.track(e);
        return false;
    }
}
 
Example #6
Source File: TrafficMonitorThread.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        return false;
    }
}
 
Example #7
Source File: ZygoteProcess.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Starts a new zygote process as a child of this zygote. This is used to create
 * secondary zygotes that inherit data from the zygote that this object
 * communicates with. This returns a new ZygoteProcess representing a connection
 * to the newly created zygote. Throws an exception if the zygote cannot be started.
 */
public ChildZygoteProcess startChildZygote(final String processClass,
                                           final String niceName,
                                           int uid, int gid, int[] gids,
                                           int runtimeFlags,
                                           String seInfo,
                                           String abi,
                                           String instructionSet) {
    // Create an unguessable address in the global abstract namespace.
    final LocalSocketAddress serverAddress = new LocalSocketAddress(
            processClass + "/" + UUID.randomUUID().toString());

    final String[] extraArgs = {Zygote.CHILD_ZYGOTE_SOCKET_NAME_ARG + serverAddress.getName()};

    Process.ProcessStartResult result;
    try {
        result = startViaZygote(processClass, niceName, uid, gid,
                gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo,
                abi, instructionSet, null /* appDataDir */, null /* invokeWith */,
                true /* startChildZygote */, extraArgs);
    } catch (ZygoteStartFailedEx ex) {
        throw new RuntimeException("Starting child-zygote through Zygote failed", ex);
    }

    return new ChildZygoteProcess(serverAddress, result.pid);
}
 
Example #8
Source File: ZygoteProcess.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Try connecting to the Zygote over and over again until we hit a time-out.
 * @param address The name of the socket to connect to.
 */
public static void waitForConnectionToZygote(LocalSocketAddress address) {
    for (int n = 20; n >= 0; n--) {
        try {
            final ZygoteState zs = ZygoteState.connect(address);
            zs.close();
            return;
        } catch (IOException ioe) {
            Log.w(LOG_TAG,
                    "Got error connecting to zygote, retrying. msg= " + ioe.getMessage());
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException ie) {
        }
    }
    Slog.wtf(LOG_TAG, "Failed to connect to Zygote through socket " + address.getName());
}
 
Example #9
Source File: MediaStream.java    From libstreaming with Apache License 2.0 5 votes vote down vote up
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]);
		}
	}
 
Example #10
Source File: ProcessList.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: NativeDaemonConnector.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private LocalSocketAddress determineSocketAddress() {
    // If we're testing, set up a socket in a namespace that's accessible to test code.
    // In order to ensure that unprivileged apps aren't able to impersonate native daemons on
    // production devices, even if said native daemons ill-advisedly pick a socket name that
    // starts with __test__, only allow this on debug builds.
    if (mSocket.startsWith("__test__") && Build.IS_DEBUGGABLE) {
        return new LocalSocketAddress(mSocket);
    } else {
        return new LocalSocketAddress(mSocket, LocalSocketAddress.Namespace.RESERVED);
    }
}
 
Example #12
Source File: ZygoteProcess.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Try connecting to the Zygote over and over again until we hit a time-out.
 * @param socketName The name of the socket to connect to.
 */
public static void waitForConnectionToZygote(String socketName) {
    final LocalSocketAddress address =
            new LocalSocketAddress(socketName, LocalSocketAddress.Namespace.RESERVED);
    waitForConnectionToZygote(address);
}
 
Example #13
Source File: ZygoteProcess.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public LocalSocketAddress getPrimarySocketAddress() {
    return mSocket;
}
 
Example #14
Source File: ZygoteProcess.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public ZygoteProcess(LocalSocketAddress primarySocket, LocalSocketAddress secondarySocket) {
    mSocket = primarySocket;
    mSecondarySocket = secondarySocket;
}
 
Example #15
Source File: ZygoteProcess.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public ZygoteProcess(String primarySocket, String secondarySocket) {
    this(new LocalSocketAddress(primarySocket, LocalSocketAddress.Namespace.RESERVED),
            new LocalSocketAddress(secondarySocket, LocalSocketAddress.Namespace.RESERVED));
}
 
Example #16
Source File: ChildZygoteProcess.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
ChildZygoteProcess(LocalSocketAddress socketAddress, int pid) {
    super(socketAddress, null);
    mPid = pid;
}
 
Example #17
Source File: LocalSocketUtil.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
public LocalSocketUtil(String name) throws UnknownHostException,
		IOException {
	socket = new LocalSocket();
	socket.connect(new LocalSocketAddress(name));
}
 
Example #18
Source File: SamsungMulticlientRilExecutor.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
public LocalSocketThread(String socketPath) {
    mSocketPath = new LocalSocketAddress(socketPath);
    mInputStream = null;
    mOutputStream = null;
    mMessages = new HashMap<>();
}
 
Example #19
Source File: RelayTunnel.java    From gnirehtet with Apache License 2.0 4 votes vote down vote up
public void connect() throws IOException {
    localSocket.connect(new LocalSocketAddress(LOCAL_ABSTRACT_NAME));
    readClientId(localSocket.getInputStream());
}