Merge "Added a virtual interface for Video Telephony call usage counting" into nyc-mr1-dev
This commit is contained in:
@@ -2286,11 +2286,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
|
|
||||||
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
|
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
|
||||||
|
|
||||||
// roaming networks are always considered metered
|
|
||||||
if (ident.getRoaming()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final NetworkPolicy policy;
|
final NetworkPolicy policy;
|
||||||
synchronized (mNetworkPoliciesSecondLock) {
|
synchronized (mNetworkPoliciesSecondLock) {
|
||||||
policy = findPolicyForNetworkNL(ident);
|
policy = findPolicyForNetworkNL(ident);
|
||||||
@@ -2300,7 +2295,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
return policy.metered;
|
return policy.metered;
|
||||||
} else {
|
} else {
|
||||||
final int type = state.networkInfo.getType();
|
final int type = state.networkInfo.getType();
|
||||||
if (isNetworkTypeMobile(type) || type == TYPE_WIMAX) {
|
if ((isNetworkTypeMobile(type) && ident.getMetered()) || type == TYPE_WIMAX) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import static android.net.NetworkStats.IFACE_ALL;
|
|||||||
import static android.net.NetworkStats.SET_ALL;
|
import static android.net.NetworkStats.SET_ALL;
|
||||||
import static android.net.NetworkStats.SET_DEFAULT;
|
import static android.net.NetworkStats.SET_DEFAULT;
|
||||||
import static android.net.NetworkStats.SET_FOREGROUND;
|
import static android.net.NetworkStats.SET_FOREGROUND;
|
||||||
|
import static android.net.NetworkStats.TAG_ALL;
|
||||||
import static android.net.NetworkStats.TAG_NONE;
|
import static android.net.NetworkStats.TAG_NONE;
|
||||||
import static android.net.NetworkStats.UID_ALL;
|
import static android.net.NetworkStats.UID_ALL;
|
||||||
import static android.net.NetworkTemplate.buildTemplateMobileWildcard;
|
import static android.net.NetworkTemplate.buildTemplateMobileWildcard;
|
||||||
@@ -79,6 +80,7 @@ import android.net.INetworkManagementEventObserver;
|
|||||||
import android.net.INetworkStatsService;
|
import android.net.INetworkStatsService;
|
||||||
import android.net.INetworkStatsSession;
|
import android.net.INetworkStatsSession;
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.NetworkIdentity;
|
import android.net.NetworkIdentity;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkState;
|
import android.net.NetworkState;
|
||||||
@@ -178,6 +180,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
private static final String PREFIX_UID = "uid";
|
private static final String PREFIX_UID = "uid";
|
||||||
private static final String PREFIX_UID_TAG = "uid_tag";
|
private static final String PREFIX_UID_TAG = "uid_tag";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Virtual network interface for video telephony. This is for VT data usage counting purpose.
|
||||||
|
*/
|
||||||
|
public static final String VT_INTERFACE = "vt_data0";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings that can be changed externally.
|
* Settings that can be changed externally.
|
||||||
*/
|
*/
|
||||||
@@ -967,6 +974,23 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
if (baseIface != null) {
|
if (baseIface != null) {
|
||||||
findOrCreateNetworkIdentitySet(mActiveIfaces, baseIface).add(ident);
|
findOrCreateNetworkIdentitySet(mActiveIfaces, baseIface).add(ident);
|
||||||
findOrCreateNetworkIdentitySet(mActiveUidIfaces, baseIface).add(ident);
|
findOrCreateNetworkIdentitySet(mActiveUidIfaces, baseIface).add(ident);
|
||||||
|
|
||||||
|
// Build a separate virtual interface for VT (Video Telephony) data usage.
|
||||||
|
// Only do this when IMS is not metered, but VT is metered.
|
||||||
|
// If IMS is metered, then the IMS network usage has already included VT usage.
|
||||||
|
// VT is considered always metered in framework's layer. If VT is not metered
|
||||||
|
// per carrier's policy, modem will report 0 usage for VT calls.
|
||||||
|
if (state.networkCapabilities.hasCapability(
|
||||||
|
NetworkCapabilities.NET_CAPABILITY_IMS) && !ident.getMetered()) {
|
||||||
|
|
||||||
|
// Copy the identify from IMS one but mark it as metered.
|
||||||
|
NetworkIdentity vtIdent = new NetworkIdentity(ident.getType(),
|
||||||
|
ident.getSubType(), ident.getSubscriberId(), ident.getNetworkId(),
|
||||||
|
ident.getRoaming(), true);
|
||||||
|
findOrCreateNetworkIdentitySet(mActiveIfaces, VT_INTERFACE).add(vtIdent);
|
||||||
|
findOrCreateNetworkIdentitySet(mActiveUidIfaces, VT_INTERFACE).add(vtIdent);
|
||||||
|
}
|
||||||
|
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
mobileIfaces.add(baseIface);
|
mobileIfaces.add(baseIface);
|
||||||
}
|
}
|
||||||
@@ -1006,7 +1030,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
// snapshot and record current counters; read UID stats first to
|
// snapshot and record current counters; read UID stats first to
|
||||||
// avoid over counting dev stats.
|
// avoid over counting dev stats.
|
||||||
final NetworkStats uidSnapshot = getNetworkStatsUidDetail();
|
final NetworkStats uidSnapshot = getNetworkStatsUidDetail();
|
||||||
final NetworkStats xtSnapshot = mNetworkManager.getNetworkStatsSummaryXt();
|
final NetworkStats xtSnapshot = getNetworkStatsXtAndVt();
|
||||||
final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();
|
final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();
|
||||||
|
|
||||||
|
|
||||||
@@ -1311,6 +1335,42 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
return uidSnapshot;
|
return uidSnapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return snapshot of current XT plus VT statistics.
|
||||||
|
*/
|
||||||
|
private NetworkStats getNetworkStatsXtAndVt() throws RemoteException {
|
||||||
|
final NetworkStats xtSnapshot = mNetworkManager.getNetworkStatsSummaryXt();
|
||||||
|
|
||||||
|
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(
|
||||||
|
Context.TELEPHONY_SERVICE);
|
||||||
|
|
||||||
|
long usage = tm.getVtDataUsage();
|
||||||
|
|
||||||
|
if (LOGV) Slog.d(TAG, "VT call data usage = " + usage);
|
||||||
|
|
||||||
|
final NetworkStats vtSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 1);
|
||||||
|
|
||||||
|
final NetworkStats.Entry entry = new NetworkStats.Entry();
|
||||||
|
entry.iface = VT_INTERFACE;
|
||||||
|
entry.uid = -1;
|
||||||
|
entry.set = TAG_ALL;
|
||||||
|
entry.tag = TAG_NONE;
|
||||||
|
|
||||||
|
// Since modem only tell us the total usage instead of each usage for RX and TX,
|
||||||
|
// we need to split it up (though it might not quite accurate). At
|
||||||
|
// least we can make sure the data usage report to the user will still be accurate.
|
||||||
|
entry.rxBytes = usage / 2;
|
||||||
|
entry.rxPackets = 0;
|
||||||
|
entry.txBytes = usage - entry.rxBytes;
|
||||||
|
entry.txPackets = 0;
|
||||||
|
vtSnapshot.combineValues(entry);
|
||||||
|
|
||||||
|
// Merge VT int XT
|
||||||
|
xtSnapshot.combineAllValues(vtSnapshot);
|
||||||
|
|
||||||
|
return xtSnapshot;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return snapshot of current tethering statistics. Will return empty
|
* Return snapshot of current tethering statistics. Will return empty
|
||||||
* {@link NetworkStats} if any problems are encountered.
|
* {@link NetworkStats} if any problems are encountered.
|
||||||
|
|||||||
@@ -5519,5 +5519,24 @@ public class TelephonyManager {
|
|||||||
Log.e(TAG, "Error calling ITelephony#carrierActionSetRadioEnabled", e);
|
Log.e(TAG, "Error calling ITelephony#carrierActionSetRadioEnabled", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get aggregated video call data usage since boot.
|
||||||
|
* Permissions android.Manifest.permission.READ_NETWORK_USAGE_HISTORY is required.
|
||||||
|
* @return total data usage in bytes
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public long getVtDataUsage() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ITelephony service = getITelephony();
|
||||||
|
if (service != null) {
|
||||||
|
return service.getVtDataUsage();
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "Error calling getVtDataUsage", e);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1150,4 +1150,12 @@ interface ITelephony {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
void carrierActionSetRadioEnabled(int subId, boolean enabled);
|
void carrierActionSetRadioEnabled(int subId, boolean enabled);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get aggregated video call data usage since boot.
|
||||||
|
* Permissions android.Manifest.permission.READ_NETWORK_USAGE_HISTORY is required.
|
||||||
|
* @return total data usage in bytes
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
long getVtDataUsage();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user