use of android.net.NetworkStateTracker in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method handleConnect.
private void handleConnect(NetworkInfo info) {
final int newNetType = info.getType();
setupDataActivityTracking(newNetType);
// snapshot isFailover, because sendConnectedBroadcast() resets it
boolean isFailover = info.isFailover();
final NetworkStateTracker thisNet = mNetTrackers[newNetType];
final String thisIface = thisNet.getLinkProperties().getInterfaceName();
if (VDBG) {
log("handleConnect: E newNetType=" + newNetType + " thisIface=" + thisIface + " isFailover" + isFailover);
}
// kill the one not preferred
if (mNetConfigs[newNetType].isDefault()) {
if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != newNetType) {
if (isNewNetTypePreferredOverCurrentNetType(newNetType)) {
// tear down the other
NetworkStateTracker otherNet = mNetTrackers[mActiveDefaultNetwork];
if (DBG) {
log("Policy requires " + otherNet.getNetworkInfo().getTypeName() + " teardown");
}
if (!teardown(otherNet)) {
loge("Network declined teardown request");
teardown(thisNet);
return;
}
} else {
// don't accept this one
if (VDBG) {
log("Not broadcasting CONNECT_ACTION " + "to torn down network " + info.getTypeName());
}
teardown(thisNet);
return;
}
}
synchronized (ConnectivityService.this) {
// new network
if (mNetTransitionWakeLock.isHeld()) {
mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_CLEAR_NET_TRANSITION_WAKELOCK, mNetTransitionWakeLockSerialNumber, 0), 1000);
}
}
mActiveDefaultNetwork = newNetType;
// this will cause us to come up initially as unconnected and switching
// to connected after our normal pause unless somebody reports us as reall
// disconnected
mDefaultInetConditionPublished = 0;
mDefaultConnectionSequence++;
mInetConditionChangeInFlight = false;
// Don't do this - if we never sign in stay, grey
//reportNetworkCondition(mActiveDefaultNetwork, 100);
}
thisNet.setTeardownRequested(false);
updateNetworkSettings(thisNet);
handleConnectivityChange(newNetType, false);
sendConnectedBroadcastDelayed(info, getConnectivityChangeDelay());
// notify battery stats service about this network
if (thisIface != null) {
try {
BatteryStatsService.getService().noteNetworkInterfaceType(thisIface, newNetType);
} catch (RemoteException e) {
// ignored; service lives in system_server
}
}
}
use of android.net.NetworkStateTracker in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method startUsingNetworkFeature.
// javadoc from interface
public int startUsingNetworkFeature(int networkType, String feature, IBinder binder) {
long startTime = 0;
if (DBG) {
startTime = SystemClock.elapsedRealtime();
}
if (VDBG) {
log("startUsingNetworkFeature for net " + networkType + ": " + feature + ", uid=" + Binder.getCallingUid());
}
enforceChangePermission();
try {
if (!ConnectivityManager.isNetworkTypeValid(networkType) || mNetConfigs[networkType] == null) {
return PhoneConstants.APN_REQUEST_FAILED;
}
FeatureUser f = new FeatureUser(networkType, feature, binder);
// TODO - move this into individual networktrackers
int usedNetworkType = convertFeatureToNetworkType(networkType, feature);
if (mLockdownEnabled) {
// endpoint, mark them as unavailable.
return PhoneConstants.APN_TYPE_NOT_AVAILABLE;
}
if (mProtectedNetworks.contains(usedNetworkType)) {
enforceConnectivityInternalPermission();
}
// if UID is restricted, don't allow them to bring up metered APNs
final boolean networkMetered = isNetworkMeteredUnchecked(usedNetworkType);
final int uidRules;
synchronized (mRulesLock) {
uidRules = mUidRules.get(Binder.getCallingUid(), RULE_ALLOW_ALL);
}
if (networkMetered && (uidRules & RULE_REJECT_METERED) != 0) {
return PhoneConstants.APN_REQUEST_FAILED;
}
NetworkStateTracker network = mNetTrackers[usedNetworkType];
if (network != null) {
Integer currentPid = new Integer(getCallingPid());
if (usedNetworkType != networkType) {
NetworkInfo ni = network.getNetworkInfo();
if (ni.isAvailable() == false) {
if (!TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN_ALWAYS)) {
if (DBG)
log("special network not available ni=" + ni.getTypeName());
return PhoneConstants.APN_TYPE_NOT_AVAILABLE;
} else {
// else make the attempt anyway - probably giving REQUEST_STARTED below
if (DBG) {
log("special network not available, but try anyway ni=" + ni.getTypeName());
}
}
}
int restoreTimer = getRestoreDefaultNetworkDelay(usedNetworkType);
synchronized (this) {
boolean addToList = true;
if (restoreTimer < 0) {
// make sure we don't add duplicate entry with the same request.
for (FeatureUser u : mFeatureUsers) {
if (u.isSameUser(f)) {
// Duplicate user is found. Do not add.
addToList = false;
break;
}
}
}
if (addToList)
mFeatureUsers.add(f);
if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
// this gets used for per-pid dns when connected
mNetRequestersPids[usedNetworkType].add(currentPid);
}
}
if (restoreTimer >= 0) {
mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_RESTORE_DEFAULT_NETWORK, f), restoreTimer);
}
if ((ni.isConnectedOrConnecting() == true) && !network.isTeardownRequested()) {
if (ni.isConnected() == true) {
final long token = Binder.clearCallingIdentity();
try {
// add the pid-specific dns
handleDnsConfigurationChange(usedNetworkType);
if (VDBG)
log("special network already active");
} finally {
Binder.restoreCallingIdentity(token);
}
return PhoneConstants.APN_ALREADY_ACTIVE;
}
if (VDBG)
log("special network already connecting");
return PhoneConstants.APN_REQUEST_STARTED;
}
if (DBG) {
log("startUsingNetworkFeature reconnecting to " + networkType + ": " + feature);
}
if (network.reconnect()) {
if (DBG)
log("startUsingNetworkFeature X: return APN_REQUEST_STARTED");
return PhoneConstants.APN_REQUEST_STARTED;
} else {
if (DBG)
log("startUsingNetworkFeature X: return APN_REQUEST_FAILED");
return PhoneConstants.APN_REQUEST_FAILED;
}
} else {
// need to remember this unsupported request so we respond appropriately on stop
synchronized (this) {
mFeatureUsers.add(f);
if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
// this gets used for per-pid dns when connected
mNetRequestersPids[usedNetworkType].add(currentPid);
}
}
if (DBG)
log("startUsingNetworkFeature X: return -1 unsupported feature.");
return -1;
}
}
if (DBG)
log("startUsingNetworkFeature X: return APN_TYPE_NOT_AVAILABLE");
return PhoneConstants.APN_TYPE_NOT_AVAILABLE;
} finally {
if (DBG) {
final long execTime = SystemClock.elapsedRealtime() - startTime;
if (execTime > 250) {
loge("startUsingNetworkFeature took too long: " + execTime + "ms");
} else {
if (VDBG)
log("startUsingNetworkFeature took " + execTime + "ms");
}
}
}
}
Aggregations