use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method getAllNetworkState.
@Override
public NetworkState[] getAllNetworkState() {
enforceAccessPermission();
final int uid = Binder.getCallingUid();
final ArrayList<NetworkState> result = Lists.newArrayList();
synchronized (mRulesLock) {
for (NetworkStateTracker tracker : mNetTrackers) {
if (tracker != null) {
final NetworkInfo info = getFilteredNetworkInfo(tracker, uid);
result.add(new NetworkState(info, tracker.getLinkProperties(), tracker.getLinkCapabilities()));
}
}
}
return result.toArray(new NetworkState[result.size()]);
}
use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method handleDisconnect.
/**
* Handle a {@code DISCONNECTED} event. If this pertains to the non-active
* network, we ignore it. If it is for the active network, we send out a
* broadcast. But first, we check whether it might be possible to connect
* to a different network.
* @param info the {@code NetworkInfo} for the network
*/
private void handleDisconnect(NetworkInfo info) {
int prevNetType = info.getType();
mNetTrackers[prevNetType].setTeardownRequested(false);
// Remove idletimer previously setup in {@code handleConnect}
removeDataActivityTracking(prevNetType);
/*
* If the disconnected network is not the active one, then don't report
* this as a loss of connectivity. What probably happened is that we're
* getting the disconnect for a network that we explicitly disabled
* in accordance with network preference policies.
*/
if (!mNetConfigs[prevNetType].isDefault()) {
List<Integer> pids = mNetRequestersPids[prevNetType];
for (Integer pid : pids) {
// will remove them because the net's no longer connected
// need to do this now as only now do we know the pids and
// can properly null things that are no longer referenced.
reassessPidDns(pid.intValue(), false);
}
}
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, new NetworkInfo(info));
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());
if (info.isFailover()) {
intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
info.setFailover(false);
}
if (info.getReason() != null) {
intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
}
if (info.getExtraInfo() != null) {
intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, info.getExtraInfo());
}
if (mNetConfigs[prevNetType].isDefault()) {
tryFailover(prevNetType);
if (mActiveDefaultNetwork != -1) {
NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
} else {
// we're not connected anymore
mDefaultInetConditionPublished = 0;
intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
}
}
intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
// Reset interface if no other connections are using the same interface
boolean doReset = true;
LinkProperties linkProperties = mNetTrackers[prevNetType].getLinkProperties();
if (linkProperties != null) {
String oldIface = linkProperties.getInterfaceName();
if (TextUtils.isEmpty(oldIface) == false) {
for (NetworkStateTracker networkStateTracker : mNetTrackers) {
if (networkStateTracker == null)
continue;
NetworkInfo networkInfo = networkStateTracker.getNetworkInfo();
if (networkInfo.isConnected() && networkInfo.getType() != prevNetType) {
LinkProperties l = networkStateTracker.getLinkProperties();
if (l == null)
continue;
if (oldIface.equals(l.getInterfaceName())) {
doReset = false;
break;
}
}
}
}
}
// do this before we broadcast the change
handleConnectivityChange(prevNetType, doReset);
final Intent immediateIntent = new Intent(intent);
immediateIntent.setAction(CONNECTIVITY_ACTION_IMMEDIATE);
sendStickyBroadcast(immediateIntent);
sendStickyBroadcastDelayed(intent, getConnectivityChangeDelay());
/*
* If the failover network is already connected, then immediately send
* out a followup broadcast indicating successful failover
*/
if (mActiveDefaultNetwork != -1) {
sendConnectedBroadcastDelayed(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(), getConnectivityChangeDelay());
}
}
use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method getFilteredNetworkInfo.
/**
* Return a filtered {@link NetworkInfo}, potentially marked
* {@link DetailedState#BLOCKED} based on
* {@link #isNetworkBlocked(NetworkStateTracker, int)}.
*/
private NetworkInfo getFilteredNetworkInfo(NetworkStateTracker tracker, int uid) {
NetworkInfo info = tracker.getNetworkInfo();
if (isNetworkBlocked(tracker, uid)) {
// network is blocked; clone and override state
info = new NetworkInfo(info);
info.setDetailedState(DetailedState.BLOCKED, null, null);
}
if (mLockdownTracker != null) {
info = mLockdownTracker.augmentNetworkInfo(info);
}
return info;
}
use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method handleInetConditionHoldEnd.
private void handleInetConditionHoldEnd(int netType, int sequence) {
if (DBG) {
log("handleInetConditionHoldEnd: net=" + netType + ", condition=" + mDefaultInetCondition + ", published condition=" + mDefaultInetConditionPublished);
}
mInetConditionChangeInFlight = false;
if (mActiveDefaultNetwork == -1) {
if (DBG)
log("handleInetConditionHoldEnd: no active default network - ignoring");
return;
}
if (mDefaultConnectionSequence != sequence) {
if (DBG)
log("handleInetConditionHoldEnd: event hold for obsolete network - ignoring");
return;
}
// TODO: Figure out why this optimization sometimes causes a
// change in mDefaultInetCondition to be missed and the
// UI to not be updated.
//if (mDefaultInetConditionPublished == mDefaultInetCondition) {
// if (DBG) log("no change in condition - aborting");
// return;
//}
NetworkInfo networkInfo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
if (networkInfo.isConnected() == false) {
if (DBG)
log("handleInetConditionHoldEnd: default network not connected - ignoring");
return;
}
mDefaultInetConditionPublished = mDefaultInetCondition;
sendInetConditionBroadcast(networkInfo);
return;
}
use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method handleMobileProvisioningAction.
private void handleMobileProvisioningAction(String url) {
// Notication mark notification as not visible
setProvNotificationVisible(false, ConnectivityManager.TYPE_NONE, null, null);
// If provisioning network handle as a special case,
// otherwise launch browser with the intent directly.
NetworkInfo ni = getProvisioningNetworkInfo();
if ((ni != null) && ni.isConnectedToProvisioningNetwork()) {
if (DBG)
log("handleMobileProvisioningAction: on provisioning network");
MobileDataStateTracker mdst = (MobileDataStateTracker) mNetTrackers[ConnectivityManager.TYPE_MOBILE];
mdst.enableMobileProvisioning(url);
} else {
if (DBG)
log("handleMobileProvisioningAction: on default network");
Intent newIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
newIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
try {
mContext.startActivity(newIntent);
} catch (ActivityNotFoundException e) {
loge("handleMobileProvisioningAction: startActivity failed" + e);
}
}
}
Aggregations