Address some IDE warnings in ConnectivityService
Unused arguments, non-final members, unannotated members, typos. This doesn't try to remove all warnings, but just opportunistically fixes some. Bug: 238139913 Test: ConnectivityServiceTest Change-Id: Ia5e905a0244cfb5f72c06d0c0be3458c42b27a52
This commit is contained in:
@@ -380,7 +380,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// See ConnectivitySettingsManager.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS
|
// See ConnectivitySettingsManager.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS
|
||||||
private final int mReleasePendingIntentDelayMs;
|
private final int mReleasePendingIntentDelayMs;
|
||||||
|
|
||||||
private MockableSystemProperties mSystemProperties;
|
private final MockableSystemProperties mSystemProperties;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected final PermissionMonitor mPermissionMonitor;
|
protected final PermissionMonitor mPermissionMonitor;
|
||||||
@@ -396,7 +396,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
* Stale copy of uid blocked reasons provided by NPMS. As long as they are accessed only in
|
* Stale copy of uid blocked reasons provided by NPMS. As long as they are accessed only in
|
||||||
* internal handler thread, they don't need a lock.
|
* internal handler thread, they don't need a lock.
|
||||||
*/
|
*/
|
||||||
private SparseIntArray mUidBlockedReasons = new SparseIntArray();
|
private final SparseIntArray mUidBlockedReasons = new SparseIntArray();
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ConnectivityResources mResources;
|
private final ConnectivityResources mResources;
|
||||||
@@ -412,9 +412,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected INetd mNetd;
|
protected INetd mNetd;
|
||||||
private DscpPolicyTracker mDscpPolicyTracker = null;
|
private DscpPolicyTracker mDscpPolicyTracker = null;
|
||||||
private NetworkStatsManager mStatsManager;
|
private final NetworkStatsManager mStatsManager;
|
||||||
private NetworkPolicyManager mPolicyManager;
|
private final NetworkPolicyManager mPolicyManager;
|
||||||
private final NetdCallback mNetdCallback;
|
|
||||||
private final BpfNetMaps mBpfNetMaps;
|
private final BpfNetMaps mBpfNetMaps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -780,7 +779,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
private boolean mSystemReady;
|
private boolean mSystemReady;
|
||||||
private Intent mInitialBroadcast;
|
private Intent mInitialBroadcast;
|
||||||
|
|
||||||
private PowerManager.WakeLock mNetTransitionWakeLock;
|
private final PowerManager.WakeLock mNetTransitionWakeLock;
|
||||||
private final PowerManager.WakeLock mPendingIntentWakeLock;
|
private final PowerManager.WakeLock mPendingIntentWakeLock;
|
||||||
|
|
||||||
// A helper object to track the current default HTTP proxy. ConnectivityService needs to tell
|
// A helper object to track the current default HTTP proxy. ConnectivityService needs to tell
|
||||||
@@ -790,10 +789,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
final private SettingsObserver mSettingsObserver;
|
final private SettingsObserver mSettingsObserver;
|
||||||
|
|
||||||
private UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
|
|
||||||
// the set of network types that can only be enabled by system/sig apps
|
// the set of network types that can only be enabled by system/sig apps
|
||||||
private List<Integer> mProtectedNetworks;
|
private final List<Integer> mProtectedNetworks;
|
||||||
|
|
||||||
private Set<String> mWolSupportedInterfaces;
|
private Set<String> mWolSupportedInterfaces;
|
||||||
|
|
||||||
@@ -803,10 +802,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
private final LocationPermissionChecker mLocationPermissionChecker;
|
private final LocationPermissionChecker mLocationPermissionChecker;
|
||||||
|
|
||||||
private KeepaliveTracker mKeepaliveTracker;
|
private final KeepaliveTracker mKeepaliveTracker;
|
||||||
private QosCallbackTracker mQosCallbackTracker;
|
private final QosCallbackTracker mQosCallbackTracker;
|
||||||
private NetworkNotificationManager mNotifier;
|
private final NetworkNotificationManager mNotifier;
|
||||||
private LingerMonitor mLingerMonitor;
|
private final LingerMonitor mLingerMonitor;
|
||||||
|
|
||||||
// sequence number of NetworkRequests
|
// sequence number of NetworkRequests
|
||||||
private int mNextNetworkRequestId = NetworkRequest.FIRST_REQUEST_ID;
|
private int mNextNetworkRequestId = NetworkRequest.FIRST_REQUEST_ID;
|
||||||
@@ -834,7 +833,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
private final IpConnectivityLog mMetricsLog;
|
private final IpConnectivityLog mMetricsLog;
|
||||||
|
|
||||||
@GuardedBy("mBandwidthRequests")
|
@GuardedBy("mBandwidthRequests")
|
||||||
private final SparseArray<Integer> mBandwidthRequests = new SparseArray(10);
|
private final SparseArray<Integer> mBandwidthRequests = new SparseArray<>(10);
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final MultinetworkPolicyTracker mMultinetworkPolicyTracker;
|
final MultinetworkPolicyTracker mMultinetworkPolicyTracker;
|
||||||
@@ -893,7 +892,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
* - getRestoreTimerForType(type) is also synchronized on mTypeLists.
|
* - getRestoreTimerForType(type) is also synchronized on mTypeLists.
|
||||||
* - dump is thread-safe with respect to concurrent add and remove calls.
|
* - dump is thread-safe with respect to concurrent add and remove calls.
|
||||||
*/
|
*/
|
||||||
private final ArrayList<NetworkAgentInfo> mTypeLists[];
|
private final ArrayList<NetworkAgentInfo>[] mTypeLists;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ConnectivityService mService;
|
private final ConnectivityService mService;
|
||||||
|
|
||||||
@@ -1096,8 +1095,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// send out another legacy broadcast - currently only used for suspend/unsuspend
|
// send out another legacy broadcast - currently only used for suspend/unsuspend toggle
|
||||||
// toggle
|
|
||||||
public void update(NetworkAgentInfo nai) {
|
public void update(NetworkAgentInfo nai) {
|
||||||
final boolean isDefault = mService.isDefaultNetwork(nai);
|
final boolean isDefault = mService.isDefaultNetwork(nai);
|
||||||
final DetailedState state = nai.networkInfo.getDetailedState();
|
final DetailedState state = nai.networkInfo.getDetailedState();
|
||||||
@@ -1221,31 +1219,25 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
public void incrementCountOrThrow(final int uid) {
|
public void incrementCountOrThrow(final int uid) {
|
||||||
synchronized (mUidToNetworkRequestCount) {
|
synchronized (mUidToNetworkRequestCount) {
|
||||||
incrementCountOrThrow(uid, 1 /* numToIncrement */);
|
final int newRequestCount = mUidToNetworkRequestCount.get(uid, 0) + 1;
|
||||||
|
if (newRequestCount >= mMaxCountPerUid
|
||||||
|
// HACK : the system server is allowed to go over the request count limit
|
||||||
|
// when it is creating requests on behalf of another app (but not itself,
|
||||||
|
// so it can still detect its own request leaks). This only happens in the
|
||||||
|
// per-app API flows in which case the old requests for that particular
|
||||||
|
// UID will be removed soon.
|
||||||
|
// TODO : with the removal of the legacy transact() method, exempting the
|
||||||
|
// system server UID should no longer be necessary. Make sure this is the
|
||||||
|
// case and remove this test.
|
||||||
|
&& (Process.myUid() == uid || Process.myUid() != Binder.getCallingUid())) {
|
||||||
|
throw new ServiceSpecificException(
|
||||||
|
ConnectivityManager.Errors.TOO_MANY_REQUESTS,
|
||||||
|
"Uid " + uid + " exceeded its allotted requests limit");
|
||||||
|
}
|
||||||
|
mUidToNetworkRequestCount.put(uid, newRequestCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void incrementCountOrThrow(final int uid, final int numToIncrement) {
|
|
||||||
final int newRequestCount =
|
|
||||||
mUidToNetworkRequestCount.get(uid, 0) + numToIncrement;
|
|
||||||
if (newRequestCount >= mMaxCountPerUid
|
|
||||||
// HACK : the system server is allowed to go over the request count limit
|
|
||||||
// when it is creating requests on behalf of another app (but not itself,
|
|
||||||
// so it can still detect its own request leaks). This only happens in the
|
|
||||||
// per-app API flows in which case the old requests for that particular
|
|
||||||
// UID will be removed soon.
|
|
||||||
// TODO : instead of this hack, addPerAppDefaultNetworkRequests and other
|
|
||||||
// users of transact() should unregister the requests to decrease the count
|
|
||||||
// before they increase it again by creating a new NRI. Then remove the
|
|
||||||
// transact() method.
|
|
||||||
&& (Process.myUid() == uid || Process.myUid() != Binder.getCallingUid())) {
|
|
||||||
throw new ServiceSpecificException(
|
|
||||||
ConnectivityManager.Errors.TOO_MANY_REQUESTS,
|
|
||||||
"Uid " + uid + " exceeded its allotted requests limit");
|
|
||||||
}
|
|
||||||
mUidToNetworkRequestCount.put(uid, newRequestCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the request count of the given uid.
|
* Decrements the request count of the given uid.
|
||||||
*
|
*
|
||||||
@@ -1253,21 +1245,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
public void decrementCount(final int uid) {
|
public void decrementCount(final int uid) {
|
||||||
synchronized (mUidToNetworkRequestCount) {
|
synchronized (mUidToNetworkRequestCount) {
|
||||||
decrementCount(uid, 1 /* numToDecrement */);
|
/* numToDecrement */
|
||||||
|
final int newRequestCount = mUidToNetworkRequestCount.get(uid, 0) - 1;
|
||||||
|
if (newRequestCount < 0) {
|
||||||
|
logwtf("BUG: too small request count " + newRequestCount + " for UID " + uid);
|
||||||
|
} else if (newRequestCount == 0) {
|
||||||
|
mUidToNetworkRequestCount.delete(uid);
|
||||||
|
} else {
|
||||||
|
mUidToNetworkRequestCount.put(uid, newRequestCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void decrementCount(final int uid, final int numToDecrement) {
|
|
||||||
final int newRequestCount =
|
|
||||||
mUidToNetworkRequestCount.get(uid, 0) - numToDecrement;
|
|
||||||
if (newRequestCount < 0) {
|
|
||||||
logwtf("BUG: too small request count " + newRequestCount + " for UID " + uid);
|
|
||||||
} else if (newRequestCount == 0) {
|
|
||||||
mUidToNetworkRequestCount.delete(uid);
|
|
||||||
} else {
|
|
||||||
mUidToNetworkRequestCount.put(uid, newRequestCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1376,7 +1365,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @see CarrierPrivilegeAuthenticator
|
* @see CarrierPrivilegeAuthenticator
|
||||||
|
*
|
||||||
|
* This method returns null in versions before T, where carrier privilege
|
||||||
|
* authentication is not supported.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public CarrierPrivilegeAuthenticator makeCarrierPrivilegeAuthenticator(
|
public CarrierPrivilegeAuthenticator makeCarrierPrivilegeAuthenticator(
|
||||||
@NonNull final Context context, @NonNull final TelephonyManager tm) {
|
@NonNull final Context context, @NonNull final TelephonyManager tm) {
|
||||||
if (SdkLevel.isAtLeastT()) {
|
if (SdkLevel.isAtLeastT()) {
|
||||||
@@ -1396,7 +1389,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the BpfNetMaps implementation to use in ConnectivityService.
|
* Get the BpfNetMaps implementation to use in ConnectivityService.
|
||||||
* @param netd
|
* @param netd a netd binder
|
||||||
* @return BpfNetMaps implementation.
|
* @return BpfNetMaps implementation.
|
||||||
*/
|
*/
|
||||||
public BpfNetMaps getBpfNetMaps(Context context, INetd netd) {
|
public BpfNetMaps getBpfNetMaps(Context context, INetd netd) {
|
||||||
@@ -1581,9 +1574,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
mNetworkActivityTracker = new LegacyNetworkActivityTracker(mContext, mHandler, mNetd);
|
mNetworkActivityTracker = new LegacyNetworkActivityTracker(mContext, mHandler, mNetd);
|
||||||
|
|
||||||
mNetdCallback = new NetdCallback();
|
final NetdCallback netdCallback = new NetdCallback();
|
||||||
try {
|
try {
|
||||||
mNetd.registerUnsolicitedEventListener(mNetdCallback);
|
mNetd.registerUnsolicitedEventListener(netdCallback);
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
loge("Error registering event listener :" + e);
|
loge("Error registering event listener :" + e);
|
||||||
}
|
}
|
||||||
@@ -1722,11 +1715,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mHandler.sendEmptyMessage(EVENT_INGRESS_RATE_LIMIT_CHANGED);
|
mHandler.sendEmptyMessage(EVENT_INGRESS_RATE_LIMIT_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAlwaysOnNetworkRequest(NetworkRequest networkRequest, int id) {
|
|
||||||
final boolean enable = mContext.getResources().getBoolean(id);
|
|
||||||
handleAlwaysOnNetworkRequest(networkRequest, enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleAlwaysOnNetworkRequest(
|
private void handleAlwaysOnNetworkRequest(
|
||||||
NetworkRequest networkRequest, String settingName, boolean defaultValue) {
|
NetworkRequest networkRequest, String settingName, boolean defaultValue) {
|
||||||
final boolean enable = toBool(Settings.Global.getInt(
|
final boolean enable = toBool(Settings.Global.getInt(
|
||||||
@@ -1769,12 +1757,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
Settings.Global.getUriFor(Settings.Global.HTTP_PROXY),
|
Settings.Global.getUriFor(Settings.Global.HTTP_PROXY),
|
||||||
EVENT_APPLY_GLOBAL_HTTP_PROXY);
|
EVENT_APPLY_GLOBAL_HTTP_PROXY);
|
||||||
|
|
||||||
// Watch for whether or not to keep mobile data always on.
|
// Watch for whether to keep mobile data always on.
|
||||||
mSettingsObserver.observe(
|
mSettingsObserver.observe(
|
||||||
Settings.Global.getUriFor(ConnectivitySettingsManager.MOBILE_DATA_ALWAYS_ON),
|
Settings.Global.getUriFor(ConnectivitySettingsManager.MOBILE_DATA_ALWAYS_ON),
|
||||||
EVENT_CONFIGURE_ALWAYS_ON_NETWORKS);
|
EVENT_CONFIGURE_ALWAYS_ON_NETWORKS);
|
||||||
|
|
||||||
// Watch for whether or not to keep wifi always on.
|
// Watch for whether to keep wifi always on.
|
||||||
mSettingsObserver.observe(
|
mSettingsObserver.observe(
|
||||||
Settings.Global.getUriFor(ConnectivitySettingsManager.WIFI_ALWAYS_REQUESTED),
|
Settings.Global.getUriFor(ConnectivitySettingsManager.WIFI_ALWAYS_REQUESTED),
|
||||||
EVENT_CONFIGURE_ALWAYS_ON_NETWORKS);
|
EVENT_CONFIGURE_ALWAYS_ON_NETWORKS);
|
||||||
@@ -1804,6 +1792,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@Nullable
|
||||||
protected NetworkAgentInfo getNetworkAgentInfoForNetwork(Network network) {
|
protected NetworkAgentInfo getNetworkAgentInfoForNetwork(Network network) {
|
||||||
if (network == null) {
|
if (network == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -1818,6 +1807,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: determine what to do when more than one VPN applies to |uid|.
|
// TODO: determine what to do when more than one VPN applies to |uid|.
|
||||||
|
@Nullable
|
||||||
private NetworkAgentInfo getVpnForUid(int uid) {
|
private NetworkAgentInfo getVpnForUid(int uid) {
|
||||||
synchronized (mNetworkForNetId) {
|
synchronized (mNetworkForNetId) {
|
||||||
for (int i = 0; i < mNetworkForNetId.size(); i++) {
|
for (int i = 0; i < mNetworkForNetId.size(); i++) {
|
||||||
@@ -1830,6 +1820,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Network[] getVpnUnderlyingNetworks(int uid) {
|
private Network[] getVpnUnderlyingNetworks(int uid) {
|
||||||
if (mLockdownEnabled) return null;
|
if (mLockdownEnabled) return null;
|
||||||
final NetworkAgentInfo nai = getVpnForUid(uid);
|
final NetworkAgentInfo nai = getVpnForUid(uid);
|
||||||
@@ -1941,6 +1932,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
* active
|
* active
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public NetworkInfo getActiveNetworkInfo() {
|
public NetworkInfo getActiveNetworkInfo() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
final int uid = mDeps.getCallingUid();
|
final int uid = mDeps.getCallingUid();
|
||||||
@@ -1952,17 +1944,20 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Network getActiveNetwork() {
|
public Network getActiveNetwork() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
return getActiveNetworkForUidInternal(mDeps.getCallingUid(), false);
|
return getActiveNetworkForUidInternal(mDeps.getCallingUid(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Network getActiveNetworkForUid(int uid, boolean ignoreBlocked) {
|
public Network getActiveNetworkForUid(int uid, boolean ignoreBlocked) {
|
||||||
enforceNetworkStackPermission(mContext);
|
enforceNetworkStackPermission(mContext);
|
||||||
return getActiveNetworkForUidInternal(uid, ignoreBlocked);
|
return getActiveNetworkForUidInternal(uid, ignoreBlocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Network getActiveNetworkForUidInternal(final int uid, boolean ignoreBlocked) {
|
private Network getActiveNetworkForUidInternal(final int uid, boolean ignoreBlocked) {
|
||||||
final NetworkAgentInfo vpnNai = getVpnForUid(uid);
|
final NetworkAgentInfo vpnNai = getVpnForUid(uid);
|
||||||
if (vpnNai != null) {
|
if (vpnNai != null) {
|
||||||
@@ -1981,6 +1976,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public NetworkInfo getActiveNetworkInfoForUid(int uid, boolean ignoreBlocked) {
|
public NetworkInfo getActiveNetworkInfoForUid(int uid, boolean ignoreBlocked) {
|
||||||
enforceNetworkStackPermission(mContext);
|
enforceNetworkStackPermission(mContext);
|
||||||
final NetworkAgentInfo nai = getNetworkAgentInfoForUid(uid);
|
final NetworkAgentInfo nai = getNetworkAgentInfoForUid(uid);
|
||||||
@@ -2017,6 +2013,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public NetworkInfo getNetworkInfo(int networkType) {
|
public NetworkInfo getNetworkInfo(int networkType) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
final int uid = mDeps.getCallingUid();
|
final int uid = mDeps.getCallingUid();
|
||||||
@@ -2035,6 +2032,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public NetworkInfo getNetworkInfoForUid(Network network, int uid, boolean ignoreBlocked) {
|
public NetworkInfo getNetworkInfoForUid(Network network, int uid, boolean ignoreBlocked) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
||||||
@@ -2057,6 +2055,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Network getNetworkForType(int networkType) {
|
public Network getNetworkForType(int networkType) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if (!mLegacyTypeTracker.isTypeSupported(networkType)) {
|
if (!mLegacyTypeTracker.isTypeSupported(networkType)) {
|
||||||
@@ -2074,6 +2073,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public Network[] getAllNetworks() {
|
public Network[] getAllNetworks() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
synchronized (mNetworkForNetId) {
|
synchronized (mNetworkForNetId) {
|
||||||
@@ -2534,7 +2534,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
snapshot.getNetwork(), snapshot.getSubscriberId()));
|
snapshot.getNetwork(), snapshot.getSubscriberId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.toArray(new NetworkState[result.size()]);
|
return result.toArray(new NetworkState[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2632,7 +2632,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
try {
|
try {
|
||||||
addr = InetAddress.getByAddress(hostAddress);
|
addr = InetAddress.getByAddress(hostAddress);
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
if (DBG) log("requestRouteToHostAddress got " + e.toString());
|
if (DBG) log("requestRouteToHostAddress got " + e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2643,7 +2643,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
|
||||||
if (nai == null) {
|
if (nai == null) {
|
||||||
if (mLegacyTypeTracker.isTypeSupported(networkType) == false) {
|
if (!mLegacyTypeTracker.isTypeSupported(networkType)) {
|
||||||
if (DBG) log("requestRouteToHostAddress on unsupported network: " + networkType);
|
if (DBG) log("requestRouteToHostAddress on unsupported network: " + networkType);
|
||||||
} else {
|
} else {
|
||||||
if (DBG) log("requestRouteToHostAddress on down network: " + networkType);
|
if (DBG) log("requestRouteToHostAddress on down network: " + networkType);
|
||||||
@@ -2736,7 +2736,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// the caller thread of registerNetworkAgent. Thus, it's not allowed to register netd
|
// the caller thread of registerNetworkAgent. Thus, it's not allowed to register netd
|
||||||
// event callback for certain nai. e.g. cellular. Register here to pass to
|
// event callback for certain nai. e.g. cellular. Register here to pass to
|
||||||
// NetworkMonitor instead.
|
// NetworkMonitor instead.
|
||||||
// TODO: Move the Dns Event to NetworkMonitor. NetdEventListenerService only allow one
|
// TODO: Move the Dns Event to NetworkMonitor. NetdEventListenerService only allows one
|
||||||
// callback from each caller type. Need to re-factor NetdEventListenerService to allow
|
// callback from each caller type. Need to re-factor NetdEventListenerService to allow
|
||||||
// multiple NetworkMonitor registrants.
|
// multiple NetworkMonitor registrants.
|
||||||
if (nai != null && nai.satisfies(mDefaultRequest.mRequests.get(0))) {
|
if (nai != null && nai.satisfies(mDefaultRequest.mRequests.get(0))) {
|
||||||
@@ -3101,8 +3101,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_CONFIGURE_ALWAYS_ON_NETWORKS));
|
mHandler.sendMessage(mHandler.obtainMessage(EVENT_CONFIGURE_ALWAYS_ON_NETWORKS));
|
||||||
|
|
||||||
// Update mobile data preference if necessary.
|
// Update mobile data preference if necessary.
|
||||||
// Note that empty uid list can be skip here only because no uid rules applied before system
|
// Note that updating can be skipped here if the list is empty only because no uid
|
||||||
// ready. Normally, the empty uid list means to clear the uids rules on netd.
|
// rules are applied before system ready. Normally, the empty uid list means to clear
|
||||||
|
// the uids rules on netd.
|
||||||
if (!ConnectivitySettingsManager.getMobileDataPreferredUids(mContext).isEmpty()) {
|
if (!ConnectivitySettingsManager.getMobileDataPreferredUids(mContext).isEmpty()) {
|
||||||
updateMobileDataPreferredUids();
|
updateMobileDataPreferredUids();
|
||||||
}
|
}
|
||||||
@@ -3216,7 +3217,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dumpNetworkDiagnostics(IndentingPrintWriter pw) {
|
private void dumpNetworkDiagnostics(IndentingPrintWriter pw) {
|
||||||
final List<NetworkDiagnostics> netDiags = new ArrayList<NetworkDiagnostics>();
|
final List<NetworkDiagnostics> netDiags = new ArrayList<>();
|
||||||
final long DIAG_TIME_MS = 5000;
|
final long DIAG_TIME_MS = 5000;
|
||||||
for (NetworkAgentInfo nai : networksSortedById()) {
|
for (NetworkAgentInfo nai : networksSortedById()) {
|
||||||
PrivateDnsConfig privateDnsCfg = mDnsManager.getPrivateDnsConfig(nai.network);
|
PrivateDnsConfig privateDnsCfg = mDnsManager.getPrivateDnsConfig(nai.network);
|
||||||
@@ -3952,7 +3953,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(@NonNull Message msg) {
|
||||||
if (!maybeHandleNetworkMonitorMessage(msg)
|
if (!maybeHandleNetworkMonitorMessage(msg)
|
||||||
&& !maybeHandleNetworkAgentInfoMessage(msg)) {
|
&& !maybeHandleNetworkAgentInfoMessage(msg)) {
|
||||||
maybeHandleNetworkAgentMessage(msg);
|
maybeHandleNetworkAgentMessage(msg);
|
||||||
@@ -4421,12 +4422,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
config = new NativeNetworkConfig(nai.network.getNetId(), NativeNetworkType.VIRTUAL,
|
config = new NativeNetworkConfig(nai.network.getNetId(), NativeNetworkType.VIRTUAL,
|
||||||
INetd.PERMISSION_NONE,
|
INetd.PERMISSION_NONE,
|
||||||
(nai.networkAgentConfig == null || !nai.networkAgentConfig.allowBypass),
|
!nai.networkAgentConfig.allowBypass /* secure */,
|
||||||
getVpnType(nai), nai.networkAgentConfig.excludeLocalRouteVpn);
|
getVpnType(nai), nai.networkAgentConfig.excludeLocalRouteVpn);
|
||||||
} else {
|
} else {
|
||||||
config = new NativeNetworkConfig(nai.network.getNetId(), NativeNetworkType.PHYSICAL,
|
config = new NativeNetworkConfig(nai.network.getNetId(), NativeNetworkType.PHYSICAL,
|
||||||
getNetworkPermission(nai.networkCapabilities), /*secure=*/ false,
|
getNetworkPermission(nai.networkCapabilities),
|
||||||
VpnManager.TYPE_VPN_NONE, /*excludeLocalRoutes=*/ false);
|
false /* secure */,
|
||||||
|
VpnManager.TYPE_VPN_NONE,
|
||||||
|
false /* excludeLocalRoutes */);
|
||||||
}
|
}
|
||||||
mNetd.networkCreate(config);
|
mNetd.networkCreate(config);
|
||||||
mDnsResolver.createNetworkCache(nai.network.getNetId());
|
mDnsResolver.createNetworkCache(nai.network.getNetId());
|
||||||
@@ -8324,8 +8327,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
releasePendingNetworkRequestWithDelay(pendingIntent);
|
releasePendingNetworkRequestWithDelay(pendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// networkAgent is only allowed to be null if notificationType is
|
||||||
|
// CALLBACK_UNAVAIL. This is because UNAVAIL is about no network being
|
||||||
|
// available, while all other cases are about some particular network.
|
||||||
private void callCallbackForRequest(@NonNull final NetworkRequestInfo nri,
|
private void callCallbackForRequest(@NonNull final NetworkRequestInfo nri,
|
||||||
@NonNull final NetworkAgentInfo networkAgent, final int notificationType,
|
@Nullable final NetworkAgentInfo networkAgent, final int notificationType,
|
||||||
final int arg1) {
|
final int arg1) {
|
||||||
if (nri.mMessenger == null) {
|
if (nri.mMessenger == null) {
|
||||||
// Default request has no msgr. Also prevents callbacks from being invoked for
|
// Default request has no msgr. Also prevents callbacks from being invoked for
|
||||||
@@ -9488,9 +9494,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
final UnderlyingNetworkInfo[] underlyingNetworkInfos = getAllVpnInfo();
|
final UnderlyingNetworkInfo[] underlyingNetworkInfos = getAllVpnInfo();
|
||||||
try {
|
try {
|
||||||
final ArrayList<NetworkStateSnapshot> snapshots = new ArrayList<>();
|
final ArrayList<NetworkStateSnapshot> snapshots = new ArrayList<>();
|
||||||
for (final NetworkStateSnapshot snapshot : getAllNetworkStateSnapshots()) {
|
snapshots.addAll(getAllNetworkStateSnapshots());
|
||||||
snapshots.add(snapshot);
|
|
||||||
}
|
|
||||||
mStatsManager.notifyNetworkStatus(getDefaultNetworks(),
|
mStatsManager.notifyNetworkStatus(getDefaultNetworks(),
|
||||||
snapshots, activeIface, Arrays.asList(underlyingNetworkInfos));
|
snapshots, activeIface, Arrays.asList(underlyingNetworkInfos));
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
@@ -9877,14 +9881,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
private static class NetworkTestedResults {
|
private static class NetworkTestedResults {
|
||||||
private final int mNetId;
|
private final int mNetId;
|
||||||
private final int mTestResult;
|
private final int mTestResult;
|
||||||
private final long mTimestampMillis;
|
|
||||||
@Nullable private final String mRedirectUrl;
|
@Nullable private final String mRedirectUrl;
|
||||||
|
|
||||||
private NetworkTestedResults(
|
private NetworkTestedResults(
|
||||||
int netId, int testResult, long timestampMillis, @Nullable String redirectUrl) {
|
int netId, int testResult, long timestampMillis, @Nullable String redirectUrl) {
|
||||||
mNetId = netId;
|
mNetId = netId;
|
||||||
mTestResult = testResult;
|
mTestResult = testResult;
|
||||||
mTimestampMillis = timestampMillis;
|
|
||||||
mRedirectUrl = redirectUrl;
|
mRedirectUrl = redirectUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10308,14 +10310,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInterfaceLinkStateChanged(String iface, boolean up) {
|
public void onInterfaceLinkStateChanged(@NonNull String iface, boolean up) {
|
||||||
for (NetworkAgentInfo nai : mNetworkAgentInfos) {
|
for (NetworkAgentInfo nai : mNetworkAgentInfos) {
|
||||||
nai.clatd.interfaceLinkStateChanged(iface, up);
|
nai.clatd.interfaceLinkStateChanged(iface, up);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInterfaceRemoved(String iface) {
|
public void onInterfaceRemoved(@NonNull String iface) {
|
||||||
for (NetworkAgentInfo nai : mNetworkAgentInfos) {
|
for (NetworkAgentInfo nai : mNetworkAgentInfos) {
|
||||||
nai.clatd.interfaceRemoved(iface);
|
nai.clatd.interfaceRemoved(iface);
|
||||||
}
|
}
|
||||||
@@ -10338,10 +10340,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@GuardedBy("mActiveIdleTimers")
|
@GuardedBy("mActiveIdleTimers")
|
||||||
private boolean mNetworkActive;
|
private boolean mNetworkActive;
|
||||||
@GuardedBy("mActiveIdleTimers")
|
@GuardedBy("mActiveIdleTimers")
|
||||||
private final ArrayMap<String, IdleTimerParams> mActiveIdleTimers = new ArrayMap();
|
private final ArrayMap<String, IdleTimerParams> mActiveIdleTimers = new ArrayMap<>();
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
|
|
||||||
private class IdleTimerParams {
|
private static class IdleTimerParams {
|
||||||
public final int timeout;
|
public final int timeout;
|
||||||
public final int transportType;
|
public final int transportType;
|
||||||
|
|
||||||
@@ -10387,7 +10389,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
try {
|
try {
|
||||||
mNetworkActivityListeners.getBroadcastItem(i).onNetworkActive();
|
mNetworkActivityListeners.getBroadcastItem(i).onNetworkActive();
|
||||||
} catch (RemoteException | RuntimeException e) {
|
} catch (RemoteException | RuntimeException e) {
|
||||||
loge("Fail to send network activie to listener " + e);
|
loge("Fail to send network activity to listener " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -10608,8 +10610,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void registerQosCallbackInternal(@NonNull final QosFilter filter,
|
public void registerQosCallbackInternal(@NonNull final QosFilter filter,
|
||||||
@NonNull final IQosCallback callback, @NonNull final NetworkAgentInfo nai) {
|
@NonNull final IQosCallback callback, @NonNull final NetworkAgentInfo nai) {
|
||||||
if (filter == null) throw new IllegalArgumentException("filter must be non-null");
|
Objects.requireNonNull(filter, "filter must be non-null");
|
||||||
if (callback == null) throw new IllegalArgumentException("callback must be non-null");
|
Objects.requireNonNull(callback, "callback must be non-null");
|
||||||
|
|
||||||
if (!nai.networkCapabilities.hasCapability(NET_CAPABILITY_NOT_RESTRICTED)) {
|
if (!nai.networkCapabilities.hasCapability(NET_CAPABILITY_NOT_RESTRICTED)) {
|
||||||
// TODO: Check allowed list here and ensure that either a) any QoS callback registered
|
// TODO: Check allowed list here and ensure that either a) any QoS callback registered
|
||||||
@@ -10687,8 +10689,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
+ "or the device owner must be set. ");
|
+ "or the device owner must be set. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<ProfileNetworkPreferenceList.Preference> preferenceList =
|
final List<ProfileNetworkPreferenceList.Preference> preferenceList = new ArrayList<>();
|
||||||
new ArrayList<ProfileNetworkPreferenceList.Preference>();
|
|
||||||
boolean hasDefaultPreference = false;
|
boolean hasDefaultPreference = false;
|
||||||
for (final ProfileNetworkPreference preference : preferences) {
|
for (final ProfileNetworkPreference preference : preferences) {
|
||||||
final NetworkCapabilities nc;
|
final NetworkCapabilities nc;
|
||||||
@@ -10769,7 +10770,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
uidRangeSet = UidRangeUtils.removeRangeSetFromUidRange(profileUids,
|
uidRangeSet = UidRangeUtils.removeRangeSetFromUidRange(profileUids,
|
||||||
disallowUidRangeSet);
|
disallowUidRangeSet);
|
||||||
} else {
|
} else {
|
||||||
uidRangeSet = new ArraySet<UidRange>();
|
uidRangeSet = new ArraySet<>();
|
||||||
uidRangeSet.add(profileUids);
|
uidRangeSet.add(profileUids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10778,8 +10779,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
private boolean isEnterpriseIdentifierValid(
|
private boolean isEnterpriseIdentifierValid(
|
||||||
@NetworkCapabilities.EnterpriseId int identifier) {
|
@NetworkCapabilities.EnterpriseId int identifier) {
|
||||||
if ((identifier >= NET_ENTERPRISE_ID_1)
|
if ((identifier >= NET_ENTERPRISE_ID_1) && (identifier <= NET_ENTERPRISE_ID_5)) {
|
||||||
&& (identifier <= NET_ENTERPRISE_ID_5)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user