Merge "[MS49] Remove NetworkStats hidden Api usages" am: dac3f891ae
am: 21d08383c0
am: eb68eb5ec3
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/1943133 Change-Id: Ib436a34bf1f094013b8ceb5f8acc67091117e668
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.INetworkStatsService;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.os.INetworkManagementService;
|
||||
@@ -51,8 +50,6 @@ public class BillingCyclePreferenceController extends BasePreferenceController {
|
||||
TemplatePreference.NetworkServices services = new TemplatePreference.NetworkServices();
|
||||
services.mNetworkService = INetworkManagementService.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
|
||||
services.mStatsService = INetworkStatsService.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
|
||||
services.mPolicyManager = mContext.getSystemService(NetworkPolicyManager.class);
|
||||
services.mPolicyEditor = new NetworkPolicyEditor(services.mPolicyManager);
|
||||
services.mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
||||
|
@@ -17,13 +17,13 @@ package com.android.settings.datausage;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.TrafficStats;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DataUnit;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -46,7 +46,7 @@ public class ChartDataUsagePreference extends Preference {
|
||||
|
||||
// The resolution we show on the graph so that we can squash things down to ints.
|
||||
// Set to half a meg for now.
|
||||
private static final long RESOLUTION = TrafficStats.MB_IN_BYTES / 2;
|
||||
private static final long RESOLUTION = DataUnit.MEBIBYTES.toBytes(1) / 2;
|
||||
|
||||
private final int mWarningColor;
|
||||
private final int mLimitColor;
|
||||
|
@@ -15,7 +15,6 @@
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.INetworkStatsService;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.os.Bundle;
|
||||
@@ -44,8 +43,6 @@ public abstract class DataUsageBaseFragment extends DashboardFragment {
|
||||
|
||||
services.mNetworkService = INetworkManagementService.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
|
||||
services.mStatsService = INetworkStatsService.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
|
||||
services.mPolicyManager = (NetworkPolicyManager) context
|
||||
.getSystemService(Context.NETWORK_POLICY_SERVICE);
|
||||
|
||||
|
@@ -14,11 +14,9 @@
|
||||
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import static android.app.usage.NetworkStats.Bucket.UID_REMOVED;
|
||||
import static android.app.usage.NetworkStats.Bucket.UID_TETHERING;
|
||||
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
|
||||
import static android.net.NetworkStatsHistory.FIELD_RX_BYTES;
|
||||
import static android.net.NetworkStatsHistory.FIELD_TX_BYTES;
|
||||
import static android.net.TrafficStats.UID_REMOVED;
|
||||
import static android.net.TrafficStats.UID_TETHERING;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
@@ -91,7 +89,6 @@ public class DataUsageList extends DataUsageBaseFragment
|
||||
private static final String KEY_APPS_GROUP = "apps_group";
|
||||
private static final String KEY_TEMPLATE = "template";
|
||||
private static final String KEY_APP = "app";
|
||||
private static final String KEY_FIELDS = "fields";
|
||||
|
||||
@VisibleForTesting
|
||||
static final int LOADER_CHART_DATA = 2;
|
||||
@@ -299,7 +296,6 @@ public class DataUsageList extends DataUsageBaseFragment
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(KEY_TEMPLATE, template);
|
||||
args.putParcelable(KEY_APP, null);
|
||||
args.putInt(KEY_FIELDS, FIELD_RX_BYTES | FIELD_TX_BYTES);
|
||||
return args;
|
||||
}
|
||||
|
||||
|
@@ -53,7 +53,7 @@ public class DataUsagePreference extends Preference implements TemplatePreferenc
|
||||
mTemplate = template;
|
||||
mSubId = subId;
|
||||
final DataUsageController controller = getDataUsageController();
|
||||
if (mTemplate.isMatchRuleMobile()) {
|
||||
if (mTemplate.getMatchRule() == NetworkTemplate.MATCH_MOBILE) {
|
||||
setTitle(R.string.app_cellular_data_usage);
|
||||
} else {
|
||||
final DataUsageController.DataUsageInfo usageInfo =
|
||||
@@ -78,13 +78,14 @@ public class DataUsagePreference extends Preference implements TemplatePreferenc
|
||||
final SubSettingLauncher launcher;
|
||||
args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
|
||||
args.putInt(DataUsageList.EXTRA_SUB_ID, mSubId);
|
||||
args.putInt(DataUsageList.EXTRA_NETWORK_TYPE, mTemplate.isMatchRuleMobile()
|
||||
args.putInt(DataUsageList.EXTRA_NETWORK_TYPE, mTemplate.getMatchRule()
|
||||
== NetworkTemplate.MATCH_MOBILE
|
||||
? ConnectivityManager.TYPE_MOBILE : ConnectivityManager.TYPE_WIFI);
|
||||
launcher = new SubSettingLauncher(getContext())
|
||||
.setArguments(args)
|
||||
.setDestination(DataUsageList.class.getName())
|
||||
.setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN);
|
||||
if (mTemplate.isMatchRuleMobile()) {
|
||||
if (mTemplate.getMatchRule() == NetworkTemplate.MATCH_MOBILE) {
|
||||
launcher.setTitleRes(R.string.app_cellular_data_usage);
|
||||
} else {
|
||||
launcher.setTitleRes(mTitleRes);
|
||||
|
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import android.net.INetworkStatsService;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.os.INetworkManagementService;
|
||||
@@ -30,7 +29,6 @@ public interface TemplatePreference {
|
||||
|
||||
class NetworkServices {
|
||||
INetworkManagementService mNetworkService;
|
||||
INetworkStatsService mStatsService;
|
||||
NetworkPolicyManager mPolicyManager;
|
||||
TelephonyManager mTelephonyManager;
|
||||
SubscriptionManager mSubscriptionManager;
|
||||
|
@@ -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(
|
||||
|
@@ -21,7 +21,6 @@ import android.app.usage.StorageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.net.TrafficStats;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -29,6 +28,7 @@ import android.os.storage.StorageManager;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.DataUnit;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -42,7 +42,7 @@ public abstract class MigrateEstimateTask extends AsyncTask<Void, Void, Long> {
|
||||
/**
|
||||
* Assume roughly a Class 10 card.
|
||||
*/
|
||||
private static final long SPEED_ESTIMATE_BPS = 10 * TrafficStats.MB_IN_BYTES;
|
||||
private static final long SPEED_ESTIMATE_BPS = DataUnit.MEBIBYTES.toBytes(10);
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
|
@@ -24,12 +24,12 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.TrafficStats;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.util.DataUnit;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.widget.Toast;
|
||||
@@ -389,7 +389,8 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
attributedSize -= otherData.duplicateCodeSize;
|
||||
}
|
||||
|
||||
final long systemSize = Math.max(TrafficStats.GB_IN_BYTES, mUsedBytes - attributedSize);
|
||||
final long systemSize = Math.max(DataUnit.GIBIBYTES.toBytes(1),
|
||||
mUsedBytes - attributedSize);
|
||||
mSystemPreference.setStorageSize(systemSize, mTotalSize);
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,7 @@ package com.android.settings.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
@@ -438,7 +438,7 @@ public class AppDataUsageTest {
|
||||
|
||||
assertThat(mFragment.mTemplate.getMatchRule())
|
||||
.isEqualTo(NetworkTemplate.MATCH_WIFI);
|
||||
assertNull(mFragment.mTemplate.getSubscriberId());
|
||||
assertTrue(mFragment.mTemplate.getSubscriberIds().isEmpty());
|
||||
assertThat(mFragment.mTemplate.getNetworkId())
|
||||
.isEqualTo(NetworkTemplate.WIFI_NETWORKID_ALL);
|
||||
}
|
||||
|
@@ -26,10 +26,10 @@ import static org.mockito.Mockito.spy;
|
||||
import android.app.usage.NetworkStatsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.TrafficStats;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.DataUnit;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
@@ -128,7 +128,7 @@ public class DataUsagePreferenceControllerTest {
|
||||
public void updateState_shouldUseIECUnit() {
|
||||
final DataUsageController.DataUsageInfo usageInfo =
|
||||
new DataUsageController.DataUsageInfo();
|
||||
usageInfo.usageLevel = TrafficStats.MB_IN_BYTES;
|
||||
usageInfo.usageLevel = DataUnit.MEBIBYTES.toBytes(1);
|
||||
doReturn(usageInfo).when(mController).getDataUsageInfo(any());
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
@@ -33,9 +33,9 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.net.TrafficStats;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.DataUnit;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
@@ -62,7 +62,7 @@ public class StorageAsyncLoaderTest {
|
||||
private static final String PACKAGE_NAME_1 = "com.blah.test";
|
||||
private static final String PACKAGE_NAME_2 = "com.blah.test2";
|
||||
private static final String PACKAGE_NAME_3 = "com.blah.test3";
|
||||
private static final long DEFAULT_QUOTA = 64 * TrafficStats.MB_IN_BYTES;
|
||||
private static final long DEFAULT_QUOTA = DataUnit.MEBIBYTES.toBytes(64);
|
||||
|
||||
@Mock
|
||||
private StorageStatsSource mSource;
|
||||
|
Reference in New Issue
Block a user