use of com.android.internal.net.VpnInfo in project platform_frameworks_base by android.
the class Vpn method getVpnInfo.
/**
* This method should only be called by ConnectivityService. Because it doesn't
* have enough data to fill VpnInfo.primaryUnderlyingIface field.
*/
public synchronized VpnInfo getVpnInfo() {
if (!isRunningLocked()) {
return null;
}
VpnInfo info = new VpnInfo();
info.ownerUid = mOwnerUID;
info.vpnIface = mInterface;
return info;
}
use of com.android.internal.net.VpnInfo in project platform_frameworks_base by android.
the class NetworkStatsRecorder method recordSnapshotLocked.
/**
* Record any delta that occurred since last {@link NetworkStats} snapshot,
* using the given {@link Map} to identify network interfaces. First
* snapshot is considered bootstrap, and is not counted as delta.
*
* @param vpnArray Optional info about the currently active VPN, if any. This is used to
* redistribute traffic from the VPN app to the underlying responsible apps.
* This should always be set to null if the provided snapshot is aggregated
* across all UIDs (e.g. contains UID_ALL buckets), regardless of VPN state.
*/
public void recordSnapshotLocked(NetworkStats snapshot, Map<String, NetworkIdentitySet> ifaceIdent, @Nullable VpnInfo[] vpnArray, long currentTimeMillis) {
final HashSet<String> unknownIfaces = Sets.newHashSet();
// skip recording when snapshot missing
if (snapshot == null)
return;
// assume first snapshot is bootstrap and don't record
if (mLastSnapshot == null) {
mLastSnapshot = snapshot;
return;
}
final NetworkStatsCollection complete = mComplete != null ? mComplete.get() : null;
final NetworkStats delta = NetworkStats.subtract(snapshot, mLastSnapshot, mObserver, mCookie);
final long end = currentTimeMillis;
final long start = end - delta.getElapsedRealtime();
if (vpnArray != null) {
for (VpnInfo info : vpnArray) {
delta.migrateTun(info.ownerUid, info.vpnIface, info.primaryUnderlyingIface);
}
}
NetworkStats.Entry entry = null;
for (int i = 0; i < delta.size(); i++) {
entry = delta.getValues(i, entry);
final NetworkIdentitySet ident = ifaceIdent.get(entry.iface);
if (ident == null) {
unknownIfaces.add(entry.iface);
continue;
}
// skip when no delta occurred
if (entry.isEmpty())
continue;
// only record tag data when requested
if ((entry.tag == TAG_NONE) != mOnlyTags) {
if (mPending != null) {
mPending.recordData(ident, entry.uid, entry.set, entry.tag, start, end, entry);
}
// also record against boot stats when present
if (mSinceBoot != null) {
mSinceBoot.recordData(ident, entry.uid, entry.set, entry.tag, start, end, entry);
}
// also record against complete dataset when present
if (complete != null) {
complete.recordData(ident, entry.uid, entry.set, entry.tag, start, end, entry);
}
}
}
mLastSnapshot = snapshot;
if (LOGV && unknownIfaces.size() > 0) {
Slog.w(TAG, "unknown interfaces " + unknownIfaces + ", ignoring those stats");
}
}
use of com.android.internal.net.VpnInfo in project platform_frameworks_base by android.
the class NetworkStatsService method recordSnapshotLocked.
private void recordSnapshotLocked(long currentTime) throws RemoteException {
// snapshot and record current counters; read UID stats first to
// avoid over counting dev stats.
final NetworkStats uidSnapshot = getNetworkStatsUidDetail();
final NetworkStats xtSnapshot = getNetworkStatsXtAndVt();
final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();
// For xt/dev, we pass a null VPN array because usage is aggregated by UID, so VPN traffic
// can't be reattributed to responsible apps.
mDevRecorder.recordSnapshotLocked(devSnapshot, mActiveIfaces, null, /* vpnArray */
currentTime);
mXtRecorder.recordSnapshotLocked(xtSnapshot, mActiveIfaces, null, /* vpnArray */
currentTime);
// For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps.
VpnInfo[] vpnArray = mConnManager.getAllVpnInfo();
mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime);
mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime);
// We need to make copies of member fields that are sent to the observer to avoid
// a race condition between the service handler thread and the observer's
mStatsObservers.updateStats(xtSnapshot, uidSnapshot, new ArrayMap<>(mActiveIfaces), new ArrayMap<>(mActiveUidIfaces), vpnArray, currentTime);
}
use of com.android.internal.net.VpnInfo in project android_frameworks_base by AOSPA.
the class ConnectivityService method createVpnInfo.
/**
* @return VPN information for accounting, or null if we can't retrieve all required
* information, e.g primary underlying iface.
*/
@Nullable
private VpnInfo createVpnInfo(Vpn vpn) {
VpnInfo info = vpn.getVpnInfo();
if (info == null) {
return null;
}
Network[] underlyingNetworks = vpn.getUnderlyingNetworks();
// the underlyingNetworks list.
if (underlyingNetworks == null) {
NetworkAgentInfo defaultNetwork = getDefaultNetwork();
if (defaultNetwork != null && defaultNetwork.linkProperties != null) {
info.primaryUnderlyingIface = getDefaultNetwork().linkProperties.getInterfaceName();
}
} else if (underlyingNetworks.length > 0) {
LinkProperties linkProperties = getLinkProperties(underlyingNetworks[0]);
if (linkProperties != null) {
info.primaryUnderlyingIface = linkProperties.getInterfaceName();
}
}
return info.primaryUnderlyingIface == null ? null : info;
}
use of com.android.internal.net.VpnInfo in project android_frameworks_base by AOSPA.
the class NetworkStatsService method recordSnapshotLocked.
private void recordSnapshotLocked(long currentTime) throws RemoteException {
// snapshot and record current counters; read UID stats first to
// avoid over counting dev stats.
final NetworkStats uidSnapshot = getNetworkStatsUidDetail();
final NetworkStats xtSnapshot = getNetworkStatsXtAndVt();
final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();
NetPluginDelegate.getTetherStats(uidSnapshot, xtSnapshot, devSnapshot);
if (mConfigEnableDataUsage) {
combineVideoCallEntryValues(uidSnapshot);
}
// For xt/dev, we pass a null VPN array because usage is aggregated by UID, so VPN traffic
// can't be reattributed to responsible apps.
mDevRecorder.recordSnapshotLocked(devSnapshot, mActiveIfaces, null, /* vpnArray */
currentTime);
mXtRecorder.recordSnapshotLocked(xtSnapshot, mActiveIfaces, null, /* vpnArray */
currentTime);
// For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps.
VpnInfo[] vpnArray = mConnManager.getAllVpnInfo();
mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime);
mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime);
// We need to make copies of member fields that are sent to the observer to avoid
// a race condition between the service handler thread and the observer's
mStatsObservers.updateStats(xtSnapshot, uidSnapshot, new ArrayMap<>(mActiveIfaces), new ArrayMap<>(mActiveUidIfaces), vpnArray, currentTime);
}
Aggregations