Search in sources :

Example 6 with Inet4Address

use of java.net.Inet4Address in project che by eclipse.

the class DefaultNetworkFinderHelperTest method checkMatchingSubnet.

/**
     * Check that we can find a network ip address by having the subnet
     *
     * @throws SocketException
     */
@Test
public void checkMatchingSubnet() throws SocketException, UnknownHostException {
    DefaultNetworkFinder networkFinder = new DefaultNetworkFinder();
    InetAddress loopBack = InetAddress.getLoopbackAddress();
    if (loopBack instanceof Inet4Address) {
        Optional<InetAddress> matchingAddress = networkFinder.getMatchingInetAddress(loopBack.getHostAddress().substring(0, loopBack.getHostAddress().lastIndexOf('.')));
        assertTrue(matchingAddress.isPresent());
        assertEquals(matchingAddress.get().getHostAddress(), loopBack.getHostAddress());
    }
}
Also used : Inet4Address(java.net.Inet4Address) InetAddress(java.net.InetAddress) Test(org.testng.annotations.Test)

Example 7 with Inet4Address

use of java.net.Inet4Address in project Fling by entertailion.

the class FlingFrame method vlcTranscode.

protected void vlcTranscode(final String file) {
    // Transcoding does not support jumps
    isTranscoding = true;
    // http://caprica.github.io/vlcj/javadoc/2.1.0/index.html
    try {
        // clean up previous session
        if (mediaPlayer != null) {
            mediaPlayer.release();
        }
        if (mediaPlayerFactory != null) {
            mediaPlayerFactory.release();
        }
        mediaPlayerFactory = new MediaPlayerFactory();
        mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();
        // Add a component to be notified of player events
        mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {

            public void opening(MediaPlayer mediaPlayer) {
                Log.d(LOG_TAG, "VLC Transcoding: Opening");
            }

            public void buffering(MediaPlayer mediaPlayer, float newCache) {
                Log.d(LOG_TAG, "VLC Transcoding: Buffering");
            }

            public void playing(MediaPlayer mediaPlayer) {
                Log.d(LOG_TAG, "VLC Transcoding: Playing");
                setDuration((int) (mediaPlayer.getLength() / 1000.0f));
                Log.d(LOG_TAG, "duration=" + duration);
            }

            public void paused(MediaPlayer mediaPlayer) {
                Log.d(LOG_TAG, "VLC Transcoding: Paused");
            }

            public void stopped(MediaPlayer mediaPlayer) {
                Log.d(LOG_TAG, "VLC Transcoding: Stopped");
            }

            public void finished(MediaPlayer mediaPlayer) {
                Log.d(LOG_TAG, "VLC Transcoding: Finished");
            }

            public void error(MediaPlayer mediaPlayer) {
                Log.d(LOG_TAG, "VLC Transcoding: Error");
            }

            public void videoOutput(MediaPlayer mediaPlayer, int newCount) {
                Log.d(LOG_TAG, "VLC Transcoding: VideoOutput");
            }
        });
        // Find a port for VLC HTTP server
        boolean started = false;
        int vlcPort = port + 1;
        while (!started) {
            try {
                ServerSocket serverSocket = new ServerSocket(vlcPort);
                Log.d(LOG_TAG, "Available port for VLC: " + vlcPort);
                started = true;
                serverSocket.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
                vlcPort++;
            } catch (Exception ex) {
                break;
            }
        }
        if (!rampClient.isClosed()) {
            rampClient.stop();
        }
        Inet4Address address = getNetworAddress();
        if (address != null) {
            // Play a particular item, with options if necessary
            final String[] options = { ":sout=#transcode{" + transcodingParameterValues + "}:http{mux=webm,dst=:" + vlcPort + "/cast.webm}", ":sout-keep" };
            // http://192.168.0.8:8087/cast.webm
            final String url = "http://" + address.getHostAddress() + ":" + vlcPort + "/cast.webm";
            Log.d(LOG_TAG, "url=" + url);
            if (true || isChromeCast()) {
                rampClient.launchApp(appId == null ? APP_ID : appId, selectedDialServer);
                // wait for socket to be ready...
                new Thread(new Runnable() {

                    public void run() {
                        while (!rampClient.isStarted() && !rampClient.isClosed()) {
                            try {
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (!rampClient.isClosed()) {
                            mediaPlayer.playMedia(file, options);
                            rampClient.load(url);
                        }
                    }
                }).start();
            } else {
                rampClient.load(url);
            }
        } else {
            Log.d(LOG_TAG, "could not find a network interface");
        }
    } catch (Throwable e) {
        Log.e(LOG_TAG, "vlcTranscode: " + file, e);
    }
}
Also used : Inet4Address(java.net.Inet4Address) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) MediaPlayerFactory(uk.co.caprica.vlcj.player.MediaPlayerFactory) MediaPlayerEventAdapter(uk.co.caprica.vlcj.player.MediaPlayerEventAdapter) MediaPlayer(uk.co.caprica.vlcj.player.MediaPlayer)

Example 8 with Inet4Address

use of java.net.Inet4Address in project Fling by entertailion.

the class FlingFrame method getNetworAddress.

/**
	 * Get the network address.
	 * 
	 * @return
	 */
public Inet4Address getNetworAddress() {
    Inet4Address selectedInetAddress = null;
    try {
        InterfaceAddress interfaceAddress = null;
        if (selectedDialServer != null) {
            String address = selectedDialServer.getIpAddress().getHostAddress();
            String prefix = address.substring(0, address.indexOf('.') + 1);
            Log.d(LOG_TAG, "prefix=" + prefix);
            interfaceAddress = getPreferredInetAddress(prefix);
        } else {
            InterfaceAddress oneNineTwoInetAddress = getPreferredInetAddress("192.");
            if (oneNineTwoInetAddress != null) {
                interfaceAddress = oneNineTwoInetAddress;
            } else {
                InterfaceAddress oneSevenTwoInetAddress = getPreferredInetAddress("172.");
                if (oneSevenTwoInetAddress != null) {
                    interfaceAddress = oneSevenTwoInetAddress;
                } else {
                    interfaceAddress = getPreferredInetAddress("10.");
                }
            }
        }
        if (interfaceAddress != null) {
            InetAddress networkAddress = interfaceAddress.getAddress();
            Log.d(LOG_TAG, "networkAddress=" + networkAddress);
            if (networkAddress != null) {
                return (Inet4Address) networkAddress;
            }
        }
    } catch (Exception ex) {
    }
    return selectedInetAddress;
}
Also used : Inet4Address(java.net.Inet4Address) InterfaceAddress(java.net.InterfaceAddress) InetAddress(java.net.InetAddress) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 9 with Inet4Address

use of java.net.Inet4Address in project android_frameworks_base by ParanoidAndroid.

the class NetworkManagementService method modifyRoute.

private void modifyRoute(String interfaceName, String action, RouteInfo route, String type) {
    final Command cmd = new Command("interface", "route", action, interfaceName, type);
    // create triplet: dest-ip-addr prefixlength gateway-ip-addr
    final LinkAddress la = route.getDestination();
    cmd.appendArg(la.getAddress().getHostAddress());
    cmd.appendArg(la.getNetworkPrefixLength());
    if (route.getGateway() == null) {
        if (la.getAddress() instanceof Inet4Address) {
            cmd.appendArg("0.0.0.0");
        } else {
            cmd.appendArg("::0");
        }
    } else {
        cmd.appendArg(route.getGateway().getHostAddress());
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : LinkAddress(android.net.LinkAddress) Inet4Address(java.net.Inet4Address) Command(com.android.server.NativeDaemonConnector.Command)

Example 10 with Inet4Address

use of java.net.Inet4Address in project XPrivacy by M66B.

the class Requirements method check.

@SuppressWarnings("unchecked")
public static void check(final ActivityBase context) {
    // Check Android version
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
        alertDialogBuilder.setTitle(R.string.app_name);
        alertDialogBuilder.setMessage(R.string.app_wrongandroid);
        alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher));
        alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent androidIntent = new Intent(Intent.ACTION_VIEW);
                androidIntent.setData(Uri.parse("https://github.com/M66B/XPrivacy#installation"));
                context.startActivity(androidIntent);
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }
    // Check if XPrivacy is enabled
    if (Util.isXposedEnabled()) {
        // Check privacy client
        try {
            if (PrivacyService.checkClient()) {
                List<String> listError = (List<String>) PrivacyService.getClient().check();
                if (listError.size() > 0)
                    sendSupportInfo(TextUtils.join("\r\n", listError), context);
            }
        } catch (Throwable ex) {
            sendSupportInfo(ex.toString(), context);
        }
    } else {
        // @formatter:off
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
        alertDialogBuilder.setTitle(R.string.app_name);
        alertDialogBuilder.setMessage(R.string.app_notenabled);
        alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher));
        alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent xInstallerIntent = new Intent("de.robv.android.xposed.installer.OPEN_SECTION").setPackage("de.robv.android.xposed.installer").putExtra("section", "modules").putExtra("module", context.getPackageName()).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(xInstallerIntent);
            }
        });
        // @formatter:on
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }
    // Check pro enabler
    Version version = Util.getProEnablerVersion(context);
    if (version != null && !Util.isValidProEnablerVersion(version)) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
        alertDialogBuilder.setTitle(R.string.app_name);
        alertDialogBuilder.setMessage(R.string.app_wrongenabler);
        alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher));
        alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent storeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName() + ".pro"));
                context.startActivity(storeIntent);
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }
    // Check incompatible apps
    checkCompatibility(context);
    // Check activity thread
    try {
        Class<?> clazz = Class.forName("android.app.ActivityThread", false, null);
        try {
            clazz.getDeclaredMethod("unscheduleGcIdler");
        } catch (NoSuchMethodException ex) {
            reportClass(clazz, context);
        }
    } catch (ClassNotFoundException ex) {
        sendSupportInfo(ex.toString(), context);
    }
    // Check activity thread receiver data
    try {
        Class<?> clazz = Class.forName("android.app.ActivityThread$ReceiverData", false, null);
        if (!checkField(clazz, "intent"))
            reportClass(clazz, context);
    } catch (ClassNotFoundException ex) {
        try {
            reportClass(Class.forName("android.app.ActivityThread", false, null), context);
        } catch (ClassNotFoundException exex) {
            sendSupportInfo(exex.toString(), context);
        }
    }
    // Check file utils
    try {
        Class<?> clazz = Class.forName("android.os.FileUtils", false, null);
        try {
            clazz.getDeclaredMethod("setPermissions", String.class, int.class, int.class, int.class);
        } catch (NoSuchMethodException ex) {
            reportClass(clazz, context);
        }
    } catch (ClassNotFoundException ex) {
        sendSupportInfo(ex.toString(), context);
    }
    // Check interface address
    if (!checkField(InterfaceAddress.class, "address") || !checkField(InterfaceAddress.class, "broadcastAddress") || (PrivacyService.getClient() != null && PrivacyManager.getDefacedProp(0, "InetAddress") == null))
        reportClass(InterfaceAddress.class, context);
    // Check package manager service
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        try {
            Class<?> clazz = Class.forName("com.android.server.pm.PackageManagerService", false, null);
            try {
                try {
                    clazz.getDeclaredMethod("getPackageUid", String.class, int.class);
                } catch (NoSuchMethodException ignored) {
                    clazz.getDeclaredMethod("getPackageUid", String.class);
                }
            } catch (NoSuchMethodException ex) {
                reportClass(clazz, context);
            }
        } catch (ClassNotFoundException ex) {
            sendSupportInfo(ex.toString(), context);
        }
    // Check GPS status
    if (!checkField(GpsStatus.class, "mSatellites"))
        reportClass(GpsStatus.class, context);
    // Check service manager
    try {
        Class<?> clazz = Class.forName("android.os.ServiceManager", false, null);
        try {
            // @formatter:off
            // public static void addService(String name, IBinder service)
            // public static void addService(String name, IBinder service, boolean allowIsolated)
            // public static String[] listServices()
            // public static IBinder checkService(String name)
            // @formatter:on
            Method listServices = clazz.getDeclaredMethod("listServices");
            Method getService = clazz.getDeclaredMethod("getService", String.class);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
                clazz.getDeclaredMethod("addService", String.class, IBinder.class, boolean.class);
            else
                clazz.getDeclaredMethod("addService", String.class, IBinder.class);
            // Get services
            Map<String, String> mapService = new HashMap<String, String>();
            String[] services = (String[]) listServices.invoke(null);
            if (services != null)
                for (String service : services) if (service != null) {
                    IBinder binder = (IBinder) getService.invoke(null, service);
                    String descriptor = (binder == null ? null : binder.getInterfaceDescriptor());
                    mapService.put(service, descriptor);
                }
            if (mapService.size() > 0) {
                // Check services
                int i = 0;
                List<String> listMissing = new ArrayList<String>();
                for (String name : XBinder.cServiceName) {
                    String descriptor = XBinder.cServiceDescriptor.get(i++);
                    if (descriptor != null && !XBinder.cServiceOptional.contains(name)) {
                        // Check name
                        boolean checkDescriptor = false;
                        if (name.equals("telephony.registry")) {
                            if (mapService.containsKey(name))
                                checkDescriptor = true;
                            else if (!mapService.containsKey("telephony.msim.registry"))
                                listMissing.add(name);
                        } else if (name.equals("telephony.msim.registry")) {
                            if (mapService.containsKey(name))
                                checkDescriptor = true;
                            else if (!mapService.containsKey("telephony.registry"))
                                listMissing.add(name);
                        } else if (name.equals("bluetooth")) {
                            if (mapService.containsKey(name))
                                checkDescriptor = true;
                            else if (!mapService.containsKey("bluetooth_manager"))
                                listMissing.add(name);
                        } else if (name.equals("bluetooth_manager")) {
                            if (mapService.containsKey(name))
                                checkDescriptor = true;
                            else if (!mapService.containsKey("bluetooth"))
                                listMissing.add(name);
                        } else {
                            if (mapService.containsKey(name))
                                checkDescriptor = true;
                            else
                                listMissing.add(name);
                        }
                        // Check descriptor
                        if (checkDescriptor) {
                            String d = mapService.get(name);
                            if (d != null && !d.equals(descriptor))
                                listMissing.add(descriptor);
                        }
                    }
                }
                // Check result
                if (listMissing.size() > 0) {
                    List<String> listService = new ArrayList<String>();
                    for (String service : mapService.keySet()) listService.add(String.format("%s: %s", service, mapService.get(service)));
                    sendSupportInfo("Missing:\r\n" + TextUtils.join("\r\n", listMissing) + "\r\n\r\nAvailable:\r\n" + TextUtils.join("\r\n", listService), context);
                }
            }
        } catch (NoSuchMethodException ex) {
            reportClass(clazz, context);
        } catch (Throwable ex) {
            Util.bug(null, ex);
        }
    } catch (ClassNotFoundException ex) {
        sendSupportInfo(ex.toString(), context);
    }
    // Check wifi info
    if (!checkField(WifiInfo.class, "mSupplicantState") || !checkField(WifiInfo.class, "mBSSID") || !checkField(WifiInfo.class, "mIpAddress") || !checkField(WifiInfo.class, "mMacAddress") || !(checkField(WifiInfo.class, "mSSID") || checkField(WifiInfo.class, "mWifiSsid")))
        reportClass(WifiInfo.class, context);
    // Check mWifiSsid.octets
    if (checkField(WifiInfo.class, "mWifiSsid"))
        try {
            Class<?> clazz = Class.forName("android.net.wifi.WifiSsid", false, null);
            try {
                clazz.getDeclaredMethod("createFromAsciiEncoded", String.class);
            } catch (NoSuchMethodException ex) {
                reportClass(clazz, context);
            }
        } catch (ClassNotFoundException ex) {
            sendSupportInfo(ex.toString(), context);
        }
    // Check Inet4Address/ANY
    try {
        Inet4Address.class.getDeclaredField("ANY");
    } catch (Throwable ex) {
        reportClass(Inet4Address.class, context);
    }
    // Check context services
    checkService(context, Context.ACCOUNT_SERVICE, new String[] { "android.accounts.AccountManager", "com.intel.arkham.ExtendAccountManager", /* Asus */
    "android.privacy.surrogate.PrivacyAccountManager" });
    checkService(context, Context.ACTIVITY_SERVICE, new String[] { "android.app.ActivityManager", "android.app.ActivityManagerEx" });
    checkService(context, Context.CLIPBOARD_SERVICE, new String[] { "android.content.ClipboardManager" });
    checkService(context, Context.CONNECTIVITY_SERVICE, new String[] { "android.net.ConnectivityManager", "android.net.ConnectivityManagerEx", "android.net.MultiSimConnectivityManager", "android.privacy.surrogate.PrivacyConnectivityManager" });
    checkService(context, Context.LOCATION_SERVICE, new String[] { "android.location.LocationManager", "android.location.ZTEPrivacyLocationManager", "android.privacy.surrogate.PrivacyLocationManager" });
    Class<?> serviceClass = context.getPackageManager().getClass();
    if (!"android.app.ApplicationPackageManager".equals(serviceClass.getName()) && !"amazon.content.pm.AmazonPackageManagerImpl".equals(serviceClass.getName()))
        reportClass(serviceClass, context);
    checkService(context, Context.SENSOR_SERVICE, new String[] { "android.hardware.SensorManager", "android.hardware.SystemSensorManager" });
    checkService(context, Context.TELEPHONY_SERVICE, new String[] { "android.telephony.TelephonyManager", "android.telephony.MSimTelephonyManager", "android.telephony.MultiSimTelephonyManager", "android.telephony.ZTEPrivacyTelephonyManager", "android.telephony.ZTEPrivacyMSimTelephonyManager", "com.motorola.android.telephony.MotoTelephonyManager", "android.privacy.surrogate.PrivacyTelephonyManager" });
    checkService(context, Context.WINDOW_SERVICE, new String[] { "android.view.WindowManagerImpl", "android.view.Window$LocalWindowManager", "amazon.view.AmazonWindowManagerImpl" });
    checkService(context, Context.WIFI_SERVICE, new String[] { "android.net.wifi.WifiManager", "com.amazon.net.AmazonWifiManager", "com.amazon.android.service.AmazonWifiManager", "android.privacy.surrogate.PrivacyWifiManager" });
}
Also used : AlertDialog(android.app.AlertDialog) GpsStatus(android.location.GpsStatus) DialogInterface(android.content.DialogInterface) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IBinder(android.os.IBinder) ArrayList(java.util.ArrayList) List(java.util.List) Inet4Address(java.net.Inet4Address) InterfaceAddress(java.net.InterfaceAddress) Intent(android.content.Intent) Method(java.lang.reflect.Method) WifiInfo(android.net.wifi.WifiInfo)

Aggregations

Inet4Address (java.net.Inet4Address)184 InetAddress (java.net.InetAddress)85 Inet6Address (java.net.Inet6Address)45 NetworkInterface (java.net.NetworkInterface)39 UnknownHostException (java.net.UnknownHostException)28 LinkAddress (android.net.LinkAddress)24 SocketException (java.net.SocketException)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)19 InterfaceAddress (java.net.InterfaceAddress)17 ByteBuffer (java.nio.ByteBuffer)17 RouteInfo (android.net.RouteInfo)12 LinkProperties (android.net.LinkProperties)7 InetSocketAddress (java.net.InetSocketAddress)6 Test (org.junit.Test)6 WifiDisplay (android.hardware.display.WifiDisplay)5 WifiDisplaySessionInfo (android.hardware.display.WifiDisplaySessionInfo)5 DhcpResults (android.net.DhcpResults)5 IpConfiguration (android.net.IpConfiguration)5 IpAssignment (android.net.IpConfiguration.IpAssignment)5