Internal API for system apps to determine default network for other apps
Callers with CONNECTIVITY_INTERNAL permission can read off the netId
that an application is assigned to by default.
Necessary for making connections as the default network for a client
app eg. when downloading stuff on its behalf.
Bug: 27074270
Change-Id: I8d35e8e99126875f55f3c545090326f3e9be43fb
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 95d3cc3..8967508 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -1006,7 +1006,16 @@
@Override
public Network getActiveNetwork() {
enforceAccessPermission();
- final int uid = Binder.getCallingUid();
+ return getActiveNetworkForUidInternal(Binder.getCallingUid());
+ }
+
+ @Override
+ public Network getActiveNetworkForUid(int uid) {
+ enforceConnectivityInternalPermission();
+ return getActiveNetworkForUidInternal(uid);
+ }
+
+ private Network getActiveNetworkForUidInternal(final int uid) {
final int user = UserHandle.getUserId(uid);
int vpnNetId = NETID_UNSET;
synchronized (mVpns) {