import com.android.internal.telephony.ITelephony;
import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.util.MessageUtils;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Protocol;
NetworkRequest request = getObject(message, NetworkRequest.class);
Network network = getObject(message, Network.class);
if (DBG) {
- Log.d(TAG, whatToString(message.what) + " for network " + network);
+ Log.d(TAG, getCallbackName(message.what) + " for network " + network);
}
switch (message.what) {
case CALLBACK_PRECHECK: {
- NetworkCallback callback = getCallback(request, "PRECHECK");
+ NetworkCallback callback = getCallback(message);
if (callback != null) {
callback.onPreCheck(network);
}
break;
}
case CALLBACK_AVAILABLE: {
- NetworkCallback callback = getCallback(request, "AVAILABLE");
+ NetworkCallback callback = getCallback(message);
if (callback != null) {
callback.onAvailable(network);
}
break;
}
case CALLBACK_LOSING: {
- NetworkCallback callback = getCallback(request, "LOSING");
+ NetworkCallback callback = getCallback(message);
if (callback != null) {
callback.onLosing(network, message.arg1);
}
break;
}
case CALLBACK_LOST: {
- NetworkCallback callback = getCallback(request, "LOST");
+ NetworkCallback callback = getCallback(message);
if (callback != null) {
callback.onLost(network);
}
break;
}
case CALLBACK_UNAVAIL: {
- NetworkCallback callback = getCallback(request, "UNAVAIL");
+ NetworkCallback callback = getCallback(message);
if (callback != null) {
callback.onUnavailable();
}
break;
}
case CALLBACK_CAP_CHANGED: {
- NetworkCallback callback = getCallback(request, "CAP_CHANGED");
+ NetworkCallback callback = getCallback(message);
if (callback != null) {
NetworkCapabilities cap = getObject(message, NetworkCapabilities.class);
callback.onCapabilitiesChanged(network, cap);
break;
}
case CALLBACK_IP_CHANGED: {
- NetworkCallback callback = getCallback(request, "IP_CHANGED");
+ NetworkCallback callback = getCallback(message);
if (callback != null) {
LinkProperties lp = getObject(message, LinkProperties.class);
callback.onLinkPropertiesChanged(network, lp);
break;
}
case CALLBACK_SUSPENDED: {
- NetworkCallback callback = getCallback(request, "SUSPENDED");
+ NetworkCallback callback = getCallback(message);
if (callback != null) {
callback.onNetworkSuspended(network);
}
break;
}
case CALLBACK_RESUMED: {
- NetworkCallback callback = getCallback(request, "RESUMED");
+ NetworkCallback callback = getCallback(message);
if (callback != null) {
callback.onNetworkResumed(network);
}
return (T) msg.getData().getParcelable(c.getSimpleName());
}
- private NetworkCallback getCallback(NetworkRequest req, String name) {
+ private NetworkCallback getCallback(Message msg) {
+ final NetworkRequest req = getObject(msg, NetworkRequest.class);
final NetworkCallback callback;
synchronized(sCallbacks) {
callback = sCallbacks.get(req);
}
if (callback == null) {
- Log.w(TAG, "callback not found for " + name + " message");
+ Log.w(TAG, "callback not found for " + getCallbackName(msg.what) + " message");
}
return callback;
}
throw e.rethrowFromSystemServer();
}
}
-
- /**
- * A holder class for debug info (mapping CALLBACK values to field names). This is stored
- * in a holder for two reasons:
- * 1) The reflection necessary to establish the map can't be run at compile-time. Thus, this
- * code will make the enclosing class not compile-time initializeable, deferring its
- * initialization to zygote startup. This leads to dirty (but shared) memory.
- * As this is debug info, use a holder that isn't initialized by default. This way the map
- * will be created on demand, while ConnectivityManager can be compile-time initialized.
- * 2) Static initialization is still preferred for its strong thread safety guarantees without
- * requiring a lock.
- */
- private static class NoPreloadHolder {
- public static final SparseArray<String> sMagicDecoderRing = MessageUtils.findMessageNames(
- new Class[]{ConnectivityManager.class}, new String[]{"CALLBACK_"});
- }
-
- static {
- // When debug is enabled, aggressively initialize the holder by touching the field (which
- // will guarantee static initialization).
- if (CallbackHandler.DBG) {
- Object dummy = NoPreloadHolder.sMagicDecoderRing;
- }
- }
-
- private static final String whatToString(int what) {
- return NoPreloadHolder.sMagicDecoderRing.get(what, Integer.toString(what));
- }
}
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
import static android.net.NetworkPolicyManager.RULE_TEMPORARY_ALLOW_METERED;
import static android.net.NetworkPolicyManager.uidRulesToString;
+import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.Nullable;
import android.app.BroadcastOptions;
Slog.e(TAG, s);
}
- private static <T> T checkNotNull(T value, String message) {
- if (value == null) {
- throw new NullPointerException(message);
- }
- return value;
- }
-
/**
* Prepare for a VPN application.
* VPN permissions are checked in the {@link Vpn} class. If the caller is not {@code userId},
msg.setData(bundle);
try {
if (VDBG) {
- log("sending notification " + notifyTypeToName(notificationType) +
- " for " + nri.request);
+ String notification = ConnectivityManager.getCallbackName(notificationType);
+ log("sending notification " + notification + " for " + nri.request);
}
nri.messenger.send(msg);
} catch (RemoteException e) {
}
protected void notifyNetworkCallbacks(NetworkAgentInfo networkAgent, int notifyType, int arg1) {
- if (VDBG) log("notifyType " + notifyTypeToName(notifyType) + " for " + networkAgent.name());
+ if (VDBG) {
+ String notification = ConnectivityManager.getCallbackName(notifyType);
+ log("notifyType " + notification + " for " + networkAgent.name());
+ }
for (int i = 0; i < networkAgent.numNetworkRequests(); i++) {
NetworkRequest nr = networkAgent.requestAt(i);
NetworkRequestInfo nri = mNetworkRequests.get(nr);
notifyNetworkCallbacks(networkAgent, notifyType, 0);
}
- private String notifyTypeToName(int notifyType) {
- switch (notifyType) {
- case ConnectivityManager.CALLBACK_PRECHECK: return "PRECHECK";
- case ConnectivityManager.CALLBACK_AVAILABLE: return "AVAILABLE";
- case ConnectivityManager.CALLBACK_LOSING: return "LOSING";
- case ConnectivityManager.CALLBACK_LOST: return "LOST";
- case ConnectivityManager.CALLBACK_UNAVAIL: return "UNAVAILABLE";
- case ConnectivityManager.CALLBACK_CAP_CHANGED: return "CAP_CHANGED";
- case ConnectivityManager.CALLBACK_IP_CHANGED: return "IP_CHANGED";
- case ConnectivityManager.CALLBACK_RELEASED: return "RELEASED";
- }
- return "UNKNOWN";
- }
-
/**
* Notify NetworkStatsService that the set of active ifaces has changed, or that one of the
* properties tracked by NetworkStatsService on an active iface has changed.