[MS49] Remove NetworkStats hidden Api usages

This includes:
1. Remove unused INetworkStatsService and NetworkStatsHistory.
2. Replace NetworkTemplate usages with builder.
3. Replace TrafficStats references to DataUnit.
4. Reimplement NetworkTemplate#normalize.

Test: make RunSettingsRoboTests
Bug: 204830222

  (cherry-picked from ag/16724040)

Change-Id: I8efecda5df403e9ed588daecd169cb3498d213a2
Merged-In: I8efecda5df403e9ed588daecd169cb3498d213a2
This commit is contained in:
Junyu Lai
2022-01-10 12:30:16 +00:00
committed by Frank Li
parent cd2bbccf3a
commit e539db77c4
12 changed files with 40 additions and 31 deletions

View File

@@ -24,6 +24,8 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import androidx.annotation.NonNull;
import com.android.internal.util.ArrayUtils;
import java.util.List;
@@ -70,7 +72,24 @@ public class DataUsageLib {
return mobileTemplate;
}
return NetworkTemplate.normalize(mobileTemplate, mergedSubscriberIds);
return normalizeMobileTemplate(mobileTemplate, mergedSubscriberIds);
}
private static NetworkTemplate normalizeMobileTemplate(
@NonNull NetworkTemplate template, @NonNull String[] mergedSet) {
if (template.getSubscriberIds().isEmpty()) return template;
// The input template should have at most 1 subscriberId.
final String subscriberId = template.getSubscriberIds().iterator().next();
if (Set.of(mergedSet).contains(subscriberId)) {
// Requested template subscriber is part of the merge group; return
// a template that matches all merged subscribers.
return new NetworkTemplate.Builder(template.getMatchRule())
.setSubscriberIds(Set.of(mergedSet))
.setMeteredness(template.getMeteredness()).build();
}
return template;
}
public static NetworkTemplate getMobileTemplateForSubId(