diff --git a/core/java/android/net/NetworkCapabilities.java b/core/java/android/net/NetworkCapabilities.java
index 0fbffbac5d..ec87091504 100644
--- a/core/java/android/net/NetworkCapabilities.java
+++ b/core/java/android/net/NetworkCapabilities.java
@@ -900,9 +900,17 @@ public final class NetworkCapabilities implements Parcelable {
*
For NetworkCapability instances being sent from ConnectivityService, this value MUST be
* reset to Process.INVALID_UID unless all the following conditions are met:
*
+ *
The caller is the network owner, AND one of the following sets of requirements is met:
+ *
*
- * - The destination app is the network owner
- *
- The destination app has the ACCESS_FINE_LOCATION permission granted
+ *
- The described Network is a VPN
+ *
+ *
+ * OR:
+ *
+ *
+ * - The calling app is the network owner
+ *
- The calling app has the ACCESS_FINE_LOCATION permission granted
*
- The user's location toggle is on
*
*
@@ -928,7 +936,16 @@ public final class NetworkCapabilities implements Parcelable {
/**
* Retrieves the UID of the app that owns this network.
*
- * For user privacy reasons, this field will only be populated if:
+ *
For user privacy reasons, this field will only be populated if the following conditions
+ * are met:
+ *
+ *
The caller is the network owner, AND one of the following sets of requirements is met:
+ *
+ *
+ * - The described Network is a VPN
+ *
+ *
+ * OR:
*
*
* - The calling app is the network owner
@@ -936,8 +953,8 @@ public final class NetworkCapabilities implements Parcelable {
*
- The user's location toggle is on
*
*
- * Instances of NetworkCapabilities sent to apps without the appropriate permissions will
- * have this field cleared out.
+ * Instances of NetworkCapabilities sent to apps without the appropriate permissions will have
+ * this field cleared out.
*/
public int getOwnerUid() {
return mOwnerUid;
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index ec53502cca..320f3fbae0 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -1698,6 +1698,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
return newNc;
}
+ // Allow VPNs to see ownership of their own VPN networks - not location sensitive.
+ if (nc.hasTransport(TRANSPORT_VPN)) {
+ // Owner UIDs already checked above. No need to re-check.
+ return newNc;
+ }
+
Binder.withCleanCallingIdentity(
() -> {
if (!mLocationPermissionChecker.checkLocationPermission(