diff --git a/core/java/android/app/usage/NetworkStatsManager.java b/core/java/android/app/usage/NetworkStatsManager.java index 0b21196f5d..9f46f207d6 100644 --- a/core/java/android/app/usage/NetworkStatsManager.java +++ b/core/java/android/app/usage/NetworkStatsManager.java @@ -20,6 +20,7 @@ import static com.android.internal.util.Preconditions.checkNotNull; import android.annotation.Nullable; import android.annotation.SystemService; +import android.annotation.TestApi; import android.app.usage.NetworkStats.Bucket; import android.content.Context; import android.net.ConnectivityManager; @@ -111,7 +112,9 @@ public class NetworkStatsManager { /** @hide */ public static final int FLAG_POLL_ON_OPEN = 1 << 0; /** @hide */ - public static final int FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN = 1 << 1; + public static final int FLAG_POLL_FORCE = 1 << 1; + /** @hide */ + public static final int FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN = 1 << 2; private int mFlags; @@ -140,6 +143,16 @@ public class NetworkStatsManager { } } + /** @hide */ + @TestApi + public void setPollForce(boolean pollForce) { + if (pollForce) { + mFlags |= FLAG_POLL_FORCE; + } else { + mFlags &= ~FLAG_POLL_FORCE; + } + } + /** @hide */ public void setAugmentWithSubscriptionPlan(boolean augmentWithSubscriptionPlan) { if (augmentWithSubscriptionPlan) { diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index 7ee17bc2f8..9ef6c66b07 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -116,7 +116,6 @@ import android.provider.Settings; import android.provider.Settings.Global; import android.service.NetworkInterfaceProto; import android.service.NetworkStatsServiceDumpProto; -import android.telephony.SubscriptionManager; import android.telephony.SubscriptionPlan; import android.telephony.TelephonyManager; import android.text.format.DateUtils; @@ -545,7 +544,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { final int usedFlags = isRateLimitedForPoll(callingUid) ? flags & (~NetworkStatsManager.FLAG_POLL_ON_OPEN) : flags; - if ((usedFlags & NetworkStatsManager.FLAG_POLL_ON_OPEN) != 0) { + if ((usedFlags & (NetworkStatsManager.FLAG_POLL_ON_OPEN + | NetworkStatsManager.FLAG_POLL_FORCE)) != 0) { final long ident = Binder.clearCallingIdentity(); try { performPoll(FLAG_PERSIST_ALL); @@ -679,22 +679,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private SubscriptionPlan resolveSubscriptionPlan(NetworkTemplate template, int flags) { SubscriptionPlan plan = null; if ((flags & NetworkStatsManager.FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN) != 0 - && (template.getMatchRule() == NetworkTemplate.MATCH_MOBILE) && mSettings.getAugmentEnabled()) { if (LOGD) Slog.d(TAG, "Resolving plan for " + template); final long token = Binder.clearCallingIdentity(); try { - final SubscriptionManager sm = mContext.getSystemService(SubscriptionManager.class); - final TelephonyManager tm = mContext.getSystemService(TelephonyManager.class); - for (int subId : sm.getActiveSubscriptionIdList()) { - if (template.matchesSubscriberId(tm.getSubscriberId(subId))) { - if (LOGD) Slog.d(TAG, "Found active matching subId " + subId); - final List plans = sm.getSubscriptionPlans(subId); - if (!plans.isEmpty()) { - plan = plans.get(0); - } - } - } + plan = LocalServices.getService(NetworkPolicyManagerInternal.class) + .getSubscriptionPlan(template); } finally { Binder.restoreCallingIdentity(token); }