Search in sources :

Example 1 with LocalServerSocket

use of android.net.LocalServerSocket in project android_frameworks_base by ParanoidAndroid.

the class ZygoteInit method registerZygoteSocket.

/**
     * Registers a server socket for zygote command connections
     *
     * @throws RuntimeException when open fails
     */
private static void registerZygoteSocket() {
    if (sServerSocket == null) {
        int fileDesc;
        try {
            String env = System.getenv(ANDROID_SOCKET_ENV);
            fileDesc = Integer.parseInt(env);
        } catch (RuntimeException ex) {
            throw new RuntimeException(ANDROID_SOCKET_ENV + " unset or invalid", ex);
        }
        try {
            sServerSocket = new LocalServerSocket(createFileDescriptor(fileDesc));
        } catch (IOException ex) {
            throw new RuntimeException("Error binding to local socket '" + fileDesc + "'", ex);
        }
    }
}
Also used : LocalServerSocket(android.net.LocalServerSocket) IOException(java.io.IOException)

Example 2 with LocalServerSocket

use of android.net.LocalServerSocket in project platform_frameworks_base by android.

the class NetworkManagementServiceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    // TODO: make this unnecessary. runtest might already make it unnecessary.
    System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());
    // Set up a sheltered test environment.
    BroadcastInterceptingContext context = new BroadcastInterceptingContext(getContext());
    mServerSocket = new LocalServerSocket(SOCKET_NAME);
    // Start the service and wait until it connects to our socket.
    mNMService = NetworkManagementService.create(context, SOCKET_NAME);
    mSocket = mServerSocket.accept();
    mOutputStream = mSocket.getOutputStream();
}
Also used : LocalServerSocket(android.net.LocalServerSocket) BroadcastInterceptingContext(com.android.internal.util.test.BroadcastInterceptingContext)

Example 3 with LocalServerSocket

use of android.net.LocalServerSocket in project fqrouter by fqrouter.

the class SocksVpnService method listenFdServerSocket.

private void listenFdServerSocket(final FileDescriptor tunFD) throws Exception {
    final LocalServerSocket fdServerSocket = new LocalServerSocket("fdsock2");
    try {
        ExecutorService executorService = Executors.newFixedThreadPool(16);
        int count = 0;
        while (isRunning()) {
            try {
                final LocalSocket fdSocket = fdServerSocket.accept();
                executorService.submit(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            passFileDescriptor(fdSocket, tunFD);
                        } catch (Exception e) {
                            LogUtils.e("failed to handle fdsock", e);
                        }
                    }
                });
                count += 1;
                if (count % 200 == 0) {
                    garbageCollectFds();
                }
            } catch (Exception e) {
                LogUtils.e("failed to handle fdsock", e);
            }
        }
        executorService.shutdown();
    } finally {
        fdServerSocket.close();
    }
}
Also used : LocalServerSocket(android.net.LocalServerSocket) ExecutorService(java.util.concurrent.ExecutorService) LocalSocket(android.net.LocalSocket)

Example 4 with LocalServerSocket

use of android.net.LocalServerSocket in project XobotOS by xamarin.

the class ZygoteInit method registerZygoteSocket.

/**
     * Registers a server socket for zygote command connections
     *
     * @throws RuntimeException when open fails
     */
private static void registerZygoteSocket() {
    if (sServerSocket == null) {
        int fileDesc;
        try {
            String env = System.getenv(ANDROID_SOCKET_ENV);
            fileDesc = Integer.parseInt(env);
        } catch (RuntimeException ex) {
            throw new RuntimeException(ANDROID_SOCKET_ENV + " unset or invalid", ex);
        }
        try {
            sServerSocket = new LocalServerSocket(createFileDescriptor(fileDesc));
        } catch (IOException ex) {
            throw new RuntimeException("Error binding to local socket '" + fileDesc + "'", ex);
        }
    }
}
Also used : LocalServerSocket(android.net.LocalServerSocket) IOException(java.io.IOException)

Example 5 with LocalServerSocket

use of android.net.LocalServerSocket in project XobotOS by xamarin.

the class PhoneFactory method makeDefaultPhone.

/**
     * FIXME replace this with some other way of making these
     * instances
     */
public static void makeDefaultPhone(Context context) {
    synchronized (Phone.class) {
        if (!sMadeDefaults) {
            sLooper = Looper.myLooper();
            sContext = context;
            if (sLooper == null) {
                throw new RuntimeException("PhoneFactory.makeDefaultPhone must be called from Looper thread");
            }
            int retryCount = 0;
            for (; ; ) {
                boolean hasException = false;
                retryCount++;
                try {
                    // use UNIX domain socket to
                    // prevent subsequent initialization
                    new LocalServerSocket("com.android.internal.telephony");
                } catch (java.io.IOException ex) {
                    hasException = true;
                }
                if (!hasException) {
                    break;
                } else if (retryCount > SOCKET_OPEN_MAX_RETRY) {
                    throw new RuntimeException("PhoneFactory probably already running");
                } else {
                    try {
                        Thread.sleep(SOCKET_OPEN_RETRY_MILLIS);
                    } catch (InterruptedException er) {
                    }
                }
            }
            sPhoneNotifier = new DefaultPhoneNotifier();
            // Get preferred network mode
            int preferredNetworkMode = RILConstants.PREFERRED_NETWORK_MODE;
            if (BaseCommands.getLteOnCdmaModeStatic() == Phone.LTE_ON_CDMA_TRUE) {
                preferredNetworkMode = Phone.NT_MODE_GLOBAL;
            }
            int networkMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.PREFERRED_NETWORK_MODE, preferredNetworkMode);
            Log.i(LOG_TAG, "Network Mode set to " + Integer.toString(networkMode));
            // Get cdmaSubscription
            // TODO: Change when the ril will provides a way to know at runtime
            //       the configuration, bug 4202572. And the ril issues the
            //       RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED, bug 4295439.
            int cdmaSubscription;
            int lteOnCdma = BaseCommands.getLteOnCdmaModeStatic();
            switch(lteOnCdma) {
                case Phone.LTE_ON_CDMA_FALSE:
                    cdmaSubscription = RILConstants.SUBSCRIPTION_FROM_NV;
                    Log.i(LOG_TAG, "lteOnCdma is 0 use SUBSCRIPTION_FROM_NV");
                    break;
                case Phone.LTE_ON_CDMA_TRUE:
                    cdmaSubscription = RILConstants.SUBSCRIPTION_FROM_RUIM;
                    Log.i(LOG_TAG, "lteOnCdma is 1 use SUBSCRIPTION_FROM_RUIM");
                    break;
                case Phone.LTE_ON_CDMA_UNKNOWN:
                default:
                    //Get cdmaSubscription mode from Settings.System
                    cdmaSubscription = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.PREFERRED_CDMA_SUBSCRIPTION, preferredCdmaSubscription);
                    Log.i(LOG_TAG, "lteOnCdma not set, using PREFERRED_CDMA_SUBSCRIPTION");
                    break;
            }
            Log.i(LOG_TAG, "Cdma Subscription set to " + cdmaSubscription);
            //reads the system properties and makes commandsinterface
            sCommandsInterface = new RIL(context, networkMode, cdmaSubscription);
            int phoneType = getPhoneType(networkMode);
            if (phoneType == Phone.PHONE_TYPE_GSM) {
                Log.i(LOG_TAG, "Creating GSMPhone");
                sProxyPhone = new PhoneProxy(new GSMPhone(context, sCommandsInterface, sPhoneNotifier));
            } else if (phoneType == Phone.PHONE_TYPE_CDMA) {
                switch(BaseCommands.getLteOnCdmaModeStatic()) {
                    case Phone.LTE_ON_CDMA_TRUE:
                        Log.i(LOG_TAG, "Creating CDMALTEPhone");
                        sProxyPhone = new PhoneProxy(new CDMALTEPhone(context, sCommandsInterface, sPhoneNotifier));
                        break;
                    case Phone.LTE_ON_CDMA_FALSE:
                    default:
                        Log.i(LOG_TAG, "Creating CDMAPhone");
                        sProxyPhone = new PhoneProxy(new CDMAPhone(context, sCommandsInterface, sPhoneNotifier));
                        break;
                }
            }
            sMadeDefaults = true;
        }
    }
}
Also used : CDMAPhone(com.android.internal.telephony.cdma.CDMAPhone) LocalServerSocket(android.net.LocalServerSocket) CDMALTEPhone(com.android.internal.telephony.cdma.CDMALTEPhone) GSMPhone(com.android.internal.telephony.gsm.GSMPhone) CDMAPhone(com.android.internal.telephony.cdma.CDMAPhone) SipPhone(com.android.internal.telephony.sip.SipPhone) CDMALTEPhone(com.android.internal.telephony.cdma.CDMALTEPhone) GSMPhone(com.android.internal.telephony.gsm.GSMPhone)

Aggregations

LocalServerSocket (android.net.LocalServerSocket)26 IOException (java.io.IOException)15 LocalSocket (android.net.LocalSocket)13 LocalSocketAddress (android.net.LocalSocketAddress)12 SmallTest (android.test.suitebuilder.annotation.SmallTest)11 FileDescriptor (java.io.FileDescriptor)11 Credentials (android.net.Credentials)6 SocketException (java.net.SocketException)5 SuppressLint (android.annotation.SuppressLint)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 CDMALTEPhone (com.android.internal.telephony.cdma.CDMALTEPhone)1 CDMAPhone (com.android.internal.telephony.cdma.CDMAPhone)1 GSMPhone (com.android.internal.telephony.gsm.GSMPhone)1 SipPhone (com.android.internal.telephony.sip.SipPhone)1 BroadcastInterceptingContext (com.android.internal.util.test.BroadcastInterceptingContext)1 InterruptedIOException (java.io.InterruptedIOException)1 BindException (java.net.BindException)1 Random (java.util.Random)1 ExecutorService (java.util.concurrent.ExecutorService)1 Nonnull (javax.annotation.Nonnull)1