Loading core/java/android/net/IConnectivityManager.aidl +0 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.net.NetworkRequest; import android.net.NetworkState; import android.net.ProxyInfo; import android.net.UidRange; import android.net.VpnInfo; import android.net.QosSocketInfo; import android.os.Bundle; import android.os.IBinder; Loading core/java/android/net/INetworkStatsService.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import android.net.NetworkState; import android.net.NetworkStats; import android.net.NetworkStatsHistory; import android.net.NetworkTemplate; import android.net.VpnInfo; import android.net.UnderlyingNetworkInfo; import android.net.netstats.provider.INetworkStatsProvider; import android.net.netstats.provider.INetworkStatsProviderCallback; import android.os.IBinder; Loading Loading @@ -70,7 +70,7 @@ interface INetworkStatsService { in Network[] defaultNetworks, in NetworkState[] networkStates, in String activeIface, in VpnInfo[] vpnInfos); in UnderlyingNetworkInfo[] underlyingNetworkInfos); /** Force update of statistics. */ @UnsupportedAppUsage void forceUpdate(); Loading core/java/android/net/VpnInfo.aidl→core/java/android/net/UnderlyingNetworkInfo.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -16,4 +16,4 @@ package android.net; parcelable VpnInfo; parcelable UnderlyingNetworkInfo; core/java/android/net/VpnInfo.java→core/java/android/net/UnderlyingNetworkInfo.java +110 −0 Original line number Diff line number Diff line Loading @@ -17,43 +17,51 @@ package android.net; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import java.util.Arrays; import java.util.ArrayList; import java.util.List; import java.util.Objects; /** * A lightweight container used to carry information of the ongoing VPN. * Internal use only. * A lightweight container used to carry information on the networks that underly a given * virtual network. * * @hide */ public class VpnInfo implements Parcelable { public final class UnderlyingNetworkInfo implements Parcelable { /** The owner of this network. */ public final int ownerUid; @Nullable public final String vpnIface; @Nullable public final String[] underlyingIfaces; /** The interface name of this network. */ @NonNull public final String iface; /** The names of the interfaces underlying this network. */ @NonNull public final List<String> underlyingIfaces; public VpnInfo(int ownerUid, @Nullable String vpnIface, @Nullable String[] underlyingIfaces) { public UnderlyingNetworkInfo(int ownerUid, @NonNull String iface, @NonNull List<String> underlyingIfaces) { Objects.requireNonNull(iface); Objects.requireNonNull(underlyingIfaces); this.ownerUid = ownerUid; this.vpnIface = vpnIface; this.iface = iface; this.underlyingIfaces = underlyingIfaces; } private VpnInfo(@NonNull Parcel in) { private UnderlyingNetworkInfo(@NonNull Parcel in) { this.ownerUid = in.readInt(); this.vpnIface = in.readString(); this.underlyingIfaces = in.createStringArray(); this.iface = in.readString(); this.underlyingIfaces = new ArrayList<>(); in.readList(this.underlyingIfaces, null /*classLoader*/); } @Override public String toString() { return "VpnInfo{" return "UnderlyingNetworkInfo{" + "ownerUid=" + ownerUid + ", vpnIface='" + vpnIface + '\'' + ", underlyingIfaces='" + Arrays.toString(underlyingIfaces) + '\'' + ", iface='" + iface + '\'' + ", underlyingIfaces='" + underlyingIfaces.toString() + '\'' + '}'; } Loading @@ -65,22 +73,38 @@ public class VpnInfo implements Parcelable { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(ownerUid); dest.writeString(vpnIface); dest.writeStringArray(underlyingIfaces); dest.writeString(iface); dest.writeList(underlyingIfaces); } @NonNull public static final Parcelable.Creator<VpnInfo> CREATOR = new Parcelable.Creator<VpnInfo>() { public static final Parcelable.Creator<UnderlyingNetworkInfo> CREATOR = new Parcelable.Creator<UnderlyingNetworkInfo>() { @NonNull @Override public VpnInfo createFromParcel(@NonNull Parcel in) { return new VpnInfo(in); public UnderlyingNetworkInfo createFromParcel(@NonNull Parcel in) { return new UnderlyingNetworkInfo(in); } @NonNull @Override public VpnInfo[] newArray(int size) { return new VpnInfo[size]; public UnderlyingNetworkInfo[] newArray(int size) { return new UnderlyingNetworkInfo[size]; } }; @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof UnderlyingNetworkInfo)) return false; final UnderlyingNetworkInfo that = (UnderlyingNetworkInfo) o; return ownerUid == that.ownerUid && Objects.equals(iface, that.iface) && Objects.equals(underlyingIfaces, that.underlyingIfaces); } @Override public int hashCode() { return Objects.hash(ownerUid, iface, underlyingIfaces); } } services/core/java/com/android/server/ConnectivityService.java +15 −14 Original line number Diff line number Diff line Loading @@ -132,8 +132,8 @@ import android.net.SocketKeepalive; import android.net.TetheringManager; import android.net.UidRange; import android.net.UidRangeParcel; import android.net.UnderlyingNetworkInfo; import android.net.Uri; import android.net.VpnInfo; import android.net.VpnManager; import android.net.VpnService; import android.net.metrics.INetdEventListener; Loading Loading @@ -4854,28 +4854,28 @@ public class ConnectivityService extends IConnectivityManager.Stub * * <p>Must be called on the handler thread. */ private VpnInfo[] getAllVpnInfo() { private UnderlyingNetworkInfo[] getAllVpnInfo() { ensureRunningOnConnectivityServiceThread(); synchronized (mVpns) { if (mLockdownEnabled) { return new VpnInfo[0]; return new UnderlyingNetworkInfo[0]; } } List<VpnInfo> infoList = new ArrayList<>(); List<UnderlyingNetworkInfo> infoList = new ArrayList<>(); for (NetworkAgentInfo nai : mNetworkAgentInfos) { VpnInfo info = createVpnInfo(nai); UnderlyingNetworkInfo info = createVpnInfo(nai); if (info != null) { infoList.add(info); } } return infoList.toArray(new VpnInfo[infoList.size()]); return infoList.toArray(new UnderlyingNetworkInfo[infoList.size()]); } /** * @return VPN information for accounting, or null if we can't retrieve all required * information, e.g underlying ifaces. */ private VpnInfo createVpnInfo(NetworkAgentInfo nai) { private UnderlyingNetworkInfo createVpnInfo(NetworkAgentInfo nai) { if (!nai.isVPN()) return null; Network[] underlyingNetworks = nai.declaredUnderlyingNetworks; Loading Loading @@ -4907,11 +4907,11 @@ public class ConnectivityService extends IConnectivityManager.Stub // Must be non-null or NetworkStatsService will crash. // Cannot happen in production code because Vpn only registers the NetworkAgent after the // tun or ipsec interface is created. // TODO: Remove this check. if (nai.linkProperties.getInterfaceName() == null) return null; return new VpnInfo(nai.networkCapabilities.getOwnerUid(), nai.linkProperties.getInterfaceName(), interfaces.toArray(new String[0])); return new UnderlyingNetworkInfo(nai.networkCapabilities.getOwnerUid(), nai.linkProperties.getInterfaceName(), interfaces); } /** Loading Loading @@ -8001,10 +8001,10 @@ public class ConnectivityService extends IConnectivityManager.Stub activeIface = activeLinkProperties.getInterfaceName(); } final VpnInfo[] vpnInfos = getAllVpnInfo(); final UnderlyingNetworkInfo[] underlyingNetworkInfos = getAllVpnInfo(); try { mStatsService.forceUpdateIfaces( getDefaultNetworks(), getAllNetworkState(), activeIface, vpnInfos); mStatsService.forceUpdateIfaces(getDefaultNetworks(), getAllNetworkState(), activeIface, underlyingNetworkInfos); } catch (Exception ignored) { } } Loading Loading @@ -8264,6 +8264,7 @@ public class ConnectivityService extends IConnectivityManager.Stub return getVpnIfOwner(mDeps.getCallingUid()); } // TODO: stop calling into Vpn.java and get this information from data in this class. @GuardedBy("mVpns") private Vpn getVpnIfOwner(int uid) { final int user = UserHandle.getUserId(uid); Loading @@ -8272,7 +8273,7 @@ public class ConnectivityService extends IConnectivityManager.Stub if (vpn == null) { return null; } else { final VpnInfo info = vpn.getVpnInfo(); final UnderlyingNetworkInfo info = vpn.getUnderlyingNetworkInfo(); return (info == null || info.ownerUid != uid) ? null : vpn; } } Loading Loading
core/java/android/net/IConnectivityManager.aidl +0 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.net.NetworkRequest; import android.net.NetworkState; import android.net.ProxyInfo; import android.net.UidRange; import android.net.VpnInfo; import android.net.QosSocketInfo; import android.os.Bundle; import android.os.IBinder; Loading
core/java/android/net/INetworkStatsService.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import android.net.NetworkState; import android.net.NetworkStats; import android.net.NetworkStatsHistory; import android.net.NetworkTemplate; import android.net.VpnInfo; import android.net.UnderlyingNetworkInfo; import android.net.netstats.provider.INetworkStatsProvider; import android.net.netstats.provider.INetworkStatsProviderCallback; import android.os.IBinder; Loading Loading @@ -70,7 +70,7 @@ interface INetworkStatsService { in Network[] defaultNetworks, in NetworkState[] networkStates, in String activeIface, in VpnInfo[] vpnInfos); in UnderlyingNetworkInfo[] underlyingNetworkInfos); /** Force update of statistics. */ @UnsupportedAppUsage void forceUpdate(); Loading
core/java/android/net/VpnInfo.aidl→core/java/android/net/UnderlyingNetworkInfo.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -16,4 +16,4 @@ package android.net; parcelable VpnInfo; parcelable UnderlyingNetworkInfo;
core/java/android/net/VpnInfo.java→core/java/android/net/UnderlyingNetworkInfo.java +110 −0 Original line number Diff line number Diff line Loading @@ -17,43 +17,51 @@ package android.net; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import java.util.Arrays; import java.util.ArrayList; import java.util.List; import java.util.Objects; /** * A lightweight container used to carry information of the ongoing VPN. * Internal use only. * A lightweight container used to carry information on the networks that underly a given * virtual network. * * @hide */ public class VpnInfo implements Parcelable { public final class UnderlyingNetworkInfo implements Parcelable { /** The owner of this network. */ public final int ownerUid; @Nullable public final String vpnIface; @Nullable public final String[] underlyingIfaces; /** The interface name of this network. */ @NonNull public final String iface; /** The names of the interfaces underlying this network. */ @NonNull public final List<String> underlyingIfaces; public VpnInfo(int ownerUid, @Nullable String vpnIface, @Nullable String[] underlyingIfaces) { public UnderlyingNetworkInfo(int ownerUid, @NonNull String iface, @NonNull List<String> underlyingIfaces) { Objects.requireNonNull(iface); Objects.requireNonNull(underlyingIfaces); this.ownerUid = ownerUid; this.vpnIface = vpnIface; this.iface = iface; this.underlyingIfaces = underlyingIfaces; } private VpnInfo(@NonNull Parcel in) { private UnderlyingNetworkInfo(@NonNull Parcel in) { this.ownerUid = in.readInt(); this.vpnIface = in.readString(); this.underlyingIfaces = in.createStringArray(); this.iface = in.readString(); this.underlyingIfaces = new ArrayList<>(); in.readList(this.underlyingIfaces, null /*classLoader*/); } @Override public String toString() { return "VpnInfo{" return "UnderlyingNetworkInfo{" + "ownerUid=" + ownerUid + ", vpnIface='" + vpnIface + '\'' + ", underlyingIfaces='" + Arrays.toString(underlyingIfaces) + '\'' + ", iface='" + iface + '\'' + ", underlyingIfaces='" + underlyingIfaces.toString() + '\'' + '}'; } Loading @@ -65,22 +73,38 @@ public class VpnInfo implements Parcelable { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(ownerUid); dest.writeString(vpnIface); dest.writeStringArray(underlyingIfaces); dest.writeString(iface); dest.writeList(underlyingIfaces); } @NonNull public static final Parcelable.Creator<VpnInfo> CREATOR = new Parcelable.Creator<VpnInfo>() { public static final Parcelable.Creator<UnderlyingNetworkInfo> CREATOR = new Parcelable.Creator<UnderlyingNetworkInfo>() { @NonNull @Override public VpnInfo createFromParcel(@NonNull Parcel in) { return new VpnInfo(in); public UnderlyingNetworkInfo createFromParcel(@NonNull Parcel in) { return new UnderlyingNetworkInfo(in); } @NonNull @Override public VpnInfo[] newArray(int size) { return new VpnInfo[size]; public UnderlyingNetworkInfo[] newArray(int size) { return new UnderlyingNetworkInfo[size]; } }; @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof UnderlyingNetworkInfo)) return false; final UnderlyingNetworkInfo that = (UnderlyingNetworkInfo) o; return ownerUid == that.ownerUid && Objects.equals(iface, that.iface) && Objects.equals(underlyingIfaces, that.underlyingIfaces); } @Override public int hashCode() { return Objects.hash(ownerUid, iface, underlyingIfaces); } }
services/core/java/com/android/server/ConnectivityService.java +15 −14 Original line number Diff line number Diff line Loading @@ -132,8 +132,8 @@ import android.net.SocketKeepalive; import android.net.TetheringManager; import android.net.UidRange; import android.net.UidRangeParcel; import android.net.UnderlyingNetworkInfo; import android.net.Uri; import android.net.VpnInfo; import android.net.VpnManager; import android.net.VpnService; import android.net.metrics.INetdEventListener; Loading Loading @@ -4854,28 +4854,28 @@ public class ConnectivityService extends IConnectivityManager.Stub * * <p>Must be called on the handler thread. */ private VpnInfo[] getAllVpnInfo() { private UnderlyingNetworkInfo[] getAllVpnInfo() { ensureRunningOnConnectivityServiceThread(); synchronized (mVpns) { if (mLockdownEnabled) { return new VpnInfo[0]; return new UnderlyingNetworkInfo[0]; } } List<VpnInfo> infoList = new ArrayList<>(); List<UnderlyingNetworkInfo> infoList = new ArrayList<>(); for (NetworkAgentInfo nai : mNetworkAgentInfos) { VpnInfo info = createVpnInfo(nai); UnderlyingNetworkInfo info = createVpnInfo(nai); if (info != null) { infoList.add(info); } } return infoList.toArray(new VpnInfo[infoList.size()]); return infoList.toArray(new UnderlyingNetworkInfo[infoList.size()]); } /** * @return VPN information for accounting, or null if we can't retrieve all required * information, e.g underlying ifaces. */ private VpnInfo createVpnInfo(NetworkAgentInfo nai) { private UnderlyingNetworkInfo createVpnInfo(NetworkAgentInfo nai) { if (!nai.isVPN()) return null; Network[] underlyingNetworks = nai.declaredUnderlyingNetworks; Loading Loading @@ -4907,11 +4907,11 @@ public class ConnectivityService extends IConnectivityManager.Stub // Must be non-null or NetworkStatsService will crash. // Cannot happen in production code because Vpn only registers the NetworkAgent after the // tun or ipsec interface is created. // TODO: Remove this check. if (nai.linkProperties.getInterfaceName() == null) return null; return new VpnInfo(nai.networkCapabilities.getOwnerUid(), nai.linkProperties.getInterfaceName(), interfaces.toArray(new String[0])); return new UnderlyingNetworkInfo(nai.networkCapabilities.getOwnerUid(), nai.linkProperties.getInterfaceName(), interfaces); } /** Loading Loading @@ -8001,10 +8001,10 @@ public class ConnectivityService extends IConnectivityManager.Stub activeIface = activeLinkProperties.getInterfaceName(); } final VpnInfo[] vpnInfos = getAllVpnInfo(); final UnderlyingNetworkInfo[] underlyingNetworkInfos = getAllVpnInfo(); try { mStatsService.forceUpdateIfaces( getDefaultNetworks(), getAllNetworkState(), activeIface, vpnInfos); mStatsService.forceUpdateIfaces(getDefaultNetworks(), getAllNetworkState(), activeIface, underlyingNetworkInfos); } catch (Exception ignored) { } } Loading Loading @@ -8264,6 +8264,7 @@ public class ConnectivityService extends IConnectivityManager.Stub return getVpnIfOwner(mDeps.getCallingUid()); } // TODO: stop calling into Vpn.java and get this information from data in this class. @GuardedBy("mVpns") private Vpn getVpnIfOwner(int uid) { final int user = UserHandle.getUserId(uid); Loading @@ -8272,7 +8273,7 @@ public class ConnectivityService extends IConnectivityManager.Stub if (vpn == null) { return null; } else { final VpnInfo info = vpn.getVpnInfo(); final UnderlyingNetworkInfo info = vpn.getUnderlyingNetworkInfo(); return (info == null || info.ownerUid != uid) ? null : vpn; } } Loading