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());
}
}
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);
}
}
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;
}
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();
}
}
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" });
}
Aggregations