use of android.os.INetworkManagementService in project android_frameworks_base by ParanoidAndroid.
the class EthernetDataTracker method disconnect.
public void disconnect() {
NetworkUtils.stopDhcp(mIface);
mLinkProperties.clear();
mNetworkInfo.setIsAvailable(false);
mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, mHwAddr);
Message msg = mCsHandler.obtainMessage(EVENT_CONFIGURATION_CHANGED, mNetworkInfo);
msg.sendToTarget();
msg = mCsHandler.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo);
msg.sendToTarget();
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);
try {
service.clearInterfaceAddresses(mIface);
} catch (Exception e) {
Log.e(TAG, "Failed to clear addresses or disable ipv6" + e);
}
}
use of android.os.INetworkManagementService in project XobotOS by xamarin.
the class EthernetDataTracker method startMonitoring.
/**
* Begin monitoring connectivity
*/
public void startMonitoring(Context context, Handler target) {
mContext = context;
mCsHandler = target;
// register for notifications from NetworkManagement Service
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);
mInterfaceObserver = new InterfaceObserver(this);
// enable and try to connect to an ethernet interface that
// already exists
sIfaceMatch = context.getResources().getString(com.android.internal.R.string.config_ethernet_iface_regex);
try {
final String[] ifaces = service.listInterfaces();
for (String iface : ifaces) {
if (iface.matches(sIfaceMatch)) {
mIface = iface;
InterfaceConfiguration config = service.getInterfaceConfig(iface);
mLinkUp = config.isActive();
reconnect();
break;
}
}
} catch (RemoteException e) {
Log.e(TAG, "Could not get list of interfaces " + e);
}
try {
service.registerObserver(mInterfaceObserver);
} catch (RemoteException e) {
Log.e(TAG, "Could not register InterfaceObserver " + e);
}
}
use of android.os.INetworkManagementService in project XobotOS by xamarin.
the class BluetoothPanProfileHandler method enableTethering.
// configured when we start tethering
private String enableTethering(String iface) {
debugLog("updateTetherState:" + iface);
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
String[] bluetoothRegexs = cm.getTetherableBluetoothRegexs();
// bring toggle the interfaces
String[] currentIfaces = new String[0];
try {
currentIfaces = service.listInterfaces();
} catch (Exception e) {
Log.e(TAG, "Error listing Interfaces :" + e);
return null;
}
boolean found = false;
for (String currIface : currentIfaces) {
if (currIface.equals(iface)) {
found = true;
break;
}
}
if (!found)
return null;
String address = createNewTetheringAddressLocked();
if (address == null)
return null;
InterfaceConfiguration ifcg = null;
try {
ifcg = service.getInterfaceConfig(iface);
if (ifcg != null) {
InetAddress addr = null;
if (ifcg.addr == null || (addr = ifcg.addr.getAddress()) == null || addr.equals(NetworkUtils.numericToInetAddress("0.0.0.0")) || addr.equals(NetworkUtils.numericToInetAddress("::0"))) {
addr = NetworkUtils.numericToInetAddress(address);
}
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
ifcg.addr = new LinkAddress(addr, BLUETOOTH_PREFIX_LENGTH);
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("running", "");
ifcg.interfaceFlags = ifcg.interfaceFlags.replace(" ", " ");
service.setInterfaceConfig(iface, ifcg);
if (cm.tether(iface) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
Log.e(TAG, "Error tethering " + iface);
}
}
} catch (Exception e) {
Log.e(TAG, "Error configuring interface " + iface + ", :" + e);
return null;
}
return address;
}
Aggregations