use of android.net.NetworkCapabilities in project android_frameworks_base by AOSPA.
the class ConnectivityService method registerNetworkAgent.
public int registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo, LinkProperties linkProperties, NetworkCapabilities networkCapabilities, int currentScore, NetworkMisc networkMisc) {
enforceConnectivityInternalPermission();
// TODO: Instead of passing mDefaultRequest, provide an API to determine whether a Network
// satisfies mDefaultRequest.
final NetworkAgentInfo nai = new NetworkAgentInfo(messenger, new AsyncChannel(), new Network(reserveNetId()), new NetworkInfo(networkInfo), new LinkProperties(linkProperties), new NetworkCapabilities(networkCapabilities), currentScore, mContext, mTrackerHandler, new NetworkMisc(networkMisc), mDefaultRequest, this);
synchronized (this) {
nai.networkMonitor.systemReady = mSystemReady;
}
addValidationLogs(nai.networkMonitor.getValidationLogs(), nai.network, networkInfo.getExtraInfo());
if (DBG)
log("registerNetworkAgent " + nai);
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_AGENT, nai));
return nai.network.netId;
}
use of android.net.NetworkCapabilities in project android_frameworks_base by AOSPA.
the class ConnectivityService method listenForNetwork.
@Override
public NetworkRequest listenForNetwork(NetworkCapabilities networkCapabilities, Messenger messenger, IBinder binder) {
if (!hasWifiNetworkListenPermission(networkCapabilities)) {
enforceAccessPermission();
}
NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities);
if (!ConnectivityManager.checkChangePermission(mContext)) {
// Apps without the CHANGE_NETWORK_STATE permission can't use background networks, so
// make all their listens include NET_CAPABILITY_FOREGROUND. That way, they will get
// onLost and onAvailable callbacks when networks move in and out of the background.
// There is no need to do this for requests because an app without CHANGE_NETWORK_STATE
// can't request networks.
nc.addCapability(NET_CAPABILITY_FOREGROUND);
}
NetworkRequest networkRequest = new NetworkRequest(nc, TYPE_NONE, nextNetworkRequestId(), NetworkRequest.Type.LISTEN);
NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder);
if (VDBG)
log("listenForNetwork for " + nri);
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri));
return networkRequest;
}
use of android.net.NetworkCapabilities in project android_frameworks_base by AOSPA.
the class ConnectivityService method callCallbackForRequest.
private void callCallbackForRequest(NetworkRequestInfo nri, NetworkAgentInfo networkAgent, int notificationType, int arg1) {
// Default request has no msgr
if (nri.messenger == null)
return;
Bundle bundle = new Bundle();
bundle.putParcelable(NetworkRequest.class.getSimpleName(), new NetworkRequest(nri.request));
Message msg = Message.obtain();
if (notificationType != ConnectivityManager.CALLBACK_UNAVAIL && notificationType != ConnectivityManager.CALLBACK_RELEASED) {
bundle.putParcelable(Network.class.getSimpleName(), networkAgent.network);
}
switch(notificationType) {
case ConnectivityManager.CALLBACK_LOSING:
{
msg.arg1 = arg1;
break;
}
case ConnectivityManager.CALLBACK_CAP_CHANGED:
{
bundle.putParcelable(NetworkCapabilities.class.getSimpleName(), new NetworkCapabilities(networkAgent.networkCapabilities));
break;
}
case ConnectivityManager.CALLBACK_IP_CHANGED:
{
bundle.putParcelable(LinkProperties.class.getSimpleName(), new LinkProperties(networkAgent.linkProperties));
break;
}
}
msg.what = notificationType;
msg.setData(bundle);
try {
if (VDBG) {
log("sending notification " + notifyTypeToName(notificationType) + " for " + nri.request);
}
nri.messenger.send(msg);
} catch (RemoteException e) {
// may occur naturally in the race of binder death.
loge("RemoteException caught trying to send a callback msg for " + nri.request);
}
}
use of android.net.NetworkCapabilities in project android_frameworks_base by AOSPA.
the class ConnectivityService method getFilteredNetworkState.
private NetworkState getFilteredNetworkState(int networkType, int uid, boolean ignoreBlocked) {
if (mLegacyTypeTracker.isTypeSupported(networkType)) {
final NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
final NetworkState state;
if (nai != null) {
state = nai.getNetworkState();
state.networkInfo.setType(networkType);
} else {
final NetworkInfo info = new NetworkInfo(networkType, 0, getNetworkTypeName(networkType), "");
info.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null, null);
info.setIsAvailable(true);
state = new NetworkState(info, new LinkProperties(), new NetworkCapabilities(), null, null, null);
}
filterNetworkStateForUid(state, uid, ignoreBlocked);
return state;
} else {
return NetworkState.EMPTY;
}
}
use of android.net.NetworkCapabilities in project android_frameworks_base by AOSPA.
the class ConnectivityService method createInternetRequestForTransport.
private NetworkRequest createInternetRequestForTransport(int transportType, NetworkRequest.Type type) {
NetworkCapabilities netCap = new NetworkCapabilities();
netCap.addCapability(NET_CAPABILITY_INTERNET);
netCap.addCapability(NET_CAPABILITY_NOT_RESTRICTED);
if (transportType > -1) {
netCap.addTransportType(transportType);
}
return new NetworkRequest(netCap, TYPE_NONE, nextNetworkRequestId(), type);
}
Aggregations