Merge "[MS71] Remove remaining dependencies in SettingsLib"
This commit is contained in:
@@ -27,9 +27,7 @@ import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.text.TextUtils;
|
||||
import android.util.RecurrenceRule;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
@@ -124,7 +122,7 @@ public class NetworkPolicyEditor {
|
||||
if (policy != null) {
|
||||
return policy;
|
||||
} else {
|
||||
return getPolicy(buildUnquotedNetworkTemplate(template));
|
||||
return getPolicy(template);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,21 +205,4 @@ public class NetworkPolicyEditor {
|
||||
policy.clearSnooze();
|
||||
writeAsync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a revised {@link NetworkTemplate} that matches the same rule, but
|
||||
* with an unquoted {@link NetworkTemplate#getNetworkId()}. Used to work
|
||||
* around legacy bugs.
|
||||
*/
|
||||
private static NetworkTemplate buildUnquotedNetworkTemplate(NetworkTemplate template) {
|
||||
if (template == null) return null;
|
||||
final String networkId = template.getNetworkId();
|
||||
final String strippedNetworkId = WifiInfo.sanitizeSsid(networkId);
|
||||
if (!TextUtils.equals(strippedNetworkId, networkId)) {
|
||||
return new NetworkTemplate(
|
||||
template.getMatchRule(), template.getSubscriberId(), strippedNetworkId);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settingslib.net;
|
||||
|
||||
import static android.net.TrafficStats.MB_IN_BYTES;
|
||||
import static android.telephony.TelephonyManager.SIM_STATE_READY;
|
||||
import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
|
||||
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
|
||||
@@ -49,6 +48,7 @@ public class DataUsageController {
|
||||
private static final StringBuilder PERIOD_BUILDER = new StringBuilder(50);
|
||||
private static final java.util.Formatter PERIOD_FORMATTER = new java.util.Formatter(
|
||||
PERIOD_BUILDER, Locale.getDefault());
|
||||
private static final long MB_IN_BYTES = 1024 * 1024;
|
||||
|
||||
private final Context mContext;
|
||||
private final NetworkPolicyManager mPolicyManager;
|
||||
@@ -237,10 +237,8 @@ public class DataUsageController {
|
||||
final int matchRule = networkTemplate.getMatchRule();
|
||||
switch (matchRule) {
|
||||
case NetworkTemplate.MATCH_MOBILE:
|
||||
case NetworkTemplate.MATCH_MOBILE_WILDCARD:
|
||||
return ConnectivityManager.TYPE_MOBILE;
|
||||
case NetworkTemplate.MATCH_WIFI:
|
||||
case NetworkTemplate.MATCH_WIFI_WILDCARD:
|
||||
return ConnectivityManager.TYPE_WIFI;
|
||||
case NetworkTemplate.MATCH_ETHERNET:
|
||||
return ConnectivityManager.TYPE_ETHERNET;
|
||||
|
||||
@@ -63,14 +63,32 @@ public class DataUsageUtils {
|
||||
private static NetworkTemplate getNormalizedMobileTemplate(
|
||||
TelephonyManager telephonyManager, int subId) {
|
||||
final NetworkTemplate mobileTemplate = getMobileTemplateForSubId(telephonyManager, subId);
|
||||
final String[] mergedSubscriberIds = telephonyManager
|
||||
.createForSubscriptionId(subId).getMergedImsisFromGroup();
|
||||
final Set<String> mergedSubscriberIds = Set.of(telephonyManager
|
||||
.createForSubscriptionId(subId).getMergedImsisFromGroup());
|
||||
if (ArrayUtils.isEmpty(mergedSubscriberIds)) {
|
||||
Log.i(TAG, "mergedSubscriberIds is null.");
|
||||
return mobileTemplate;
|
||||
}
|
||||
|
||||
return NetworkTemplate.normalize(mobileTemplate, mergedSubscriberIds);
|
||||
return normalizeMobileTemplate(mobileTemplate, mergedSubscriberIds);
|
||||
}
|
||||
|
||||
private static NetworkTemplate normalizeMobileTemplate(
|
||||
NetworkTemplate template, Set<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 (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(mergedSet)
|
||||
.setWifiNetworkKeys(template.getWifiNetworkKeys())
|
||||
.setMeteredness(NetworkStats.METERED_YES).build();
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
private static NetworkTemplate getMobileTemplateForSubId(
|
||||
|
||||
@@ -53,8 +53,9 @@ public class NetworkCycleDataForUidLoader extends
|
||||
long totalUsage = 0L;
|
||||
long totalForeground = 0L;
|
||||
for (int uid : mUids) {
|
||||
final NetworkStats stats = mNetworkStatsManager.queryDetailsForUid(
|
||||
mNetworkTemplate, start, end, uid);
|
||||
final NetworkStats stats = mNetworkStatsManager.queryDetailsForUidTagState(
|
||||
mNetworkTemplate, start, end, uid, NetworkStats.Bucket.TAG_NONE,
|
||||
NetworkStats.Bucket.STATE_ALL);
|
||||
final long usage = getTotalUsage(stats);
|
||||
if (usage > 0L) {
|
||||
totalUsage += usage;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.settingslib.net;
|
||||
|
||||
import android.app.AppGlobals;
|
||||
import android.app.usage.NetworkStats;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
@@ -116,13 +117,13 @@ public class UidDetailProvider {
|
||||
detail.label = res.getString(R.string.process_kernel_label);
|
||||
detail.icon = pm.getDefaultActivityIcon();
|
||||
return detail;
|
||||
case TrafficStats.UID_REMOVED:
|
||||
case NetworkStats.Bucket.UID_REMOVED:
|
||||
detail.label = res.getString(UserManager.supportsMultipleUsers()
|
||||
? R.string.data_usage_uninstalled_apps_users
|
||||
: R.string.data_usage_uninstalled_apps);
|
||||
detail.icon = pm.getDefaultActivityIcon();
|
||||
return detail;
|
||||
case TrafficStats.UID_TETHERING:
|
||||
case NetworkStats.Bucket.UID_TETHERING:
|
||||
final TetheringManager tm = mContext.getSystemService(TetheringManager.class);
|
||||
detail.label = res.getString(Utils.getTetheringLabel(tm));
|
||||
detail.icon = pm.getDefaultActivityIcon();
|
||||
|
||||
Reference in New Issue
Block a user