Merge "Fix flaky test: testDataMigration_differentFromFallback" into main
This commit is contained in:
@@ -63,6 +63,7 @@ import static android.text.format.DateUtils.HOUR_IN_MILLIS;
|
|||||||
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
||||||
import static android.text.format.DateUtils.SECOND_IN_MILLIS;
|
import static android.text.format.DateUtils.SECOND_IN_MILLIS;
|
||||||
|
|
||||||
|
import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE;
|
||||||
import static com.android.net.module.util.NetworkCapabilitiesUtils.getDisplayTransport;
|
import static com.android.net.module.util.NetworkCapabilitiesUtils.getDisplayTransport;
|
||||||
import static com.android.net.module.util.NetworkStatsUtils.LIMIT_GLOBAL_ALERT;
|
import static com.android.net.module.util.NetworkStatsUtils.LIMIT_GLOBAL_ALERT;
|
||||||
|
|
||||||
@@ -3248,7 +3249,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
* Default external settings that read from
|
* Default external settings that read from
|
||||||
* {@link android.provider.Settings.Global}.
|
* {@link android.provider.Settings.Global}.
|
||||||
*/
|
*/
|
||||||
private static class DefaultNetworkStatsSettings implements NetworkStatsSettings {
|
@VisibleForTesting(visibility = PRIVATE)
|
||||||
|
static class DefaultNetworkStatsSettings implements NetworkStatsSettings {
|
||||||
DefaultNetworkStatsSettings() {}
|
DefaultNetworkStatsSettings() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ import static org.mockito.AdditionalMatchers.aryEq;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
@@ -240,7 +239,9 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
private @Mock INetd mNetd;
|
private @Mock INetd mNetd;
|
||||||
private @Mock TetheringManager mTetheringManager;
|
private @Mock TetheringManager mTetheringManager;
|
||||||
private @Mock NetworkStatsFactory mStatsFactory;
|
private @Mock NetworkStatsFactory mStatsFactory;
|
||||||
private @Mock NetworkStatsSettings mSettings;
|
@NonNull
|
||||||
|
private final TestNetworkStatsSettings mSettings =
|
||||||
|
new TestNetworkStatsSettings(HOUR_IN_MILLIS, WEEK_IN_MILLIS);
|
||||||
private @Mock IBinder mUsageCallbackBinder;
|
private @Mock IBinder mUsageCallbackBinder;
|
||||||
private TestableUsageCallback mUsageCallback;
|
private TestableUsageCallback mUsageCallback;
|
||||||
private @Mock AlarmManager mAlarmManager;
|
private @Mock AlarmManager mAlarmManager;
|
||||||
@@ -533,7 +534,6 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
mStatsDir = null;
|
mStatsDir = null;
|
||||||
|
|
||||||
mNetd = null;
|
mNetd = null;
|
||||||
mSettings = null;
|
|
||||||
|
|
||||||
mSession.close();
|
mSession.close();
|
||||||
mService = null;
|
mService = null;
|
||||||
@@ -1765,7 +1765,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setCombineSubtypeEnabled(boolean enable) {
|
private void setCombineSubtypeEnabled(boolean enable) {
|
||||||
doReturn(enable).when(mSettings).getCombineSubtypeEnabled();
|
mSettings.setCombineSubtypeEnabled(enable);
|
||||||
mHandler.post(() -> mContentObserver.onChange(false, Settings.Global
|
mHandler.post(() -> mContentObserver.onChange(false, Settings.Global
|
||||||
.getUriFor(Settings.Global.NETSTATS_COMBINE_SUBTYPE_ENABLED)));
|
.getUriFor(Settings.Global.NETSTATS_COMBINE_SUBTYPE_ENABLED)));
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
@@ -2289,21 +2289,80 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
mockSettings(HOUR_IN_MILLIS, WEEK_IN_MILLIS);
|
mockSettings(HOUR_IN_MILLIS, WEEK_IN_MILLIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mockSettings(long bucketDuration, long deleteAge) throws Exception {
|
private void mockSettings(long bucketDuration, long deleteAge) {
|
||||||
doReturn(HOUR_IN_MILLIS).when(mSettings).getPollInterval();
|
mSettings.setConfig(new Config(bucketDuration, deleteAge, deleteAge));
|
||||||
doReturn(0L).when(mSettings).getPollDelay();
|
}
|
||||||
doReturn(true).when(mSettings).getSampleEnabled();
|
|
||||||
doReturn(false).when(mSettings).getCombineSubtypeEnabled();
|
|
||||||
|
|
||||||
final Config config = new Config(bucketDuration, deleteAge, deleteAge);
|
// Note that this object will be accessed from test main thread and service handler thread.
|
||||||
doReturn(config).when(mSettings).getXtConfig();
|
// Thus, it has to be thread safe in order to prevent from flakiness.
|
||||||
doReturn(config).when(mSettings).getUidConfig();
|
private static class TestNetworkStatsSettings
|
||||||
doReturn(config).when(mSettings).getUidTagConfig();
|
extends NetworkStatsService.DefaultNetworkStatsSettings {
|
||||||
|
|
||||||
doReturn(MB_IN_BYTES).when(mSettings).getGlobalAlertBytes(anyLong());
|
@NonNull
|
||||||
doReturn(MB_IN_BYTES).when(mSettings).getXtPersistBytes(anyLong());
|
private volatile Config mConfig;
|
||||||
doReturn(MB_IN_BYTES).when(mSettings).getUidPersistBytes(anyLong());
|
private final AtomicBoolean mCombineSubtypeEnabled = new AtomicBoolean();
|
||||||
doReturn(MB_IN_BYTES).when(mSettings).getUidTagPersistBytes(anyLong());
|
|
||||||
|
TestNetworkStatsSettings(long bucketDuration, long deleteAge) {
|
||||||
|
mConfig = new Config(bucketDuration, deleteAge, deleteAge);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setConfig(@NonNull Config config) {
|
||||||
|
mConfig = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getPollDelay() {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getGlobalAlertBytes(long def) {
|
||||||
|
return MB_IN_BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Config getXtConfig() {
|
||||||
|
return mConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Config getUidConfig() {
|
||||||
|
return mConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Config getUidTagConfig() {
|
||||||
|
return mConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getXtPersistBytes(long def) {
|
||||||
|
return MB_IN_BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getUidPersistBytes(long def) {
|
||||||
|
return MB_IN_BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getUidTagPersistBytes(long def) {
|
||||||
|
return MB_IN_BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getCombineSubtypeEnabled() {
|
||||||
|
return mCombineSubtypeEnabled.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCombineSubtypeEnabled(boolean enable) {
|
||||||
|
mCombineSubtypeEnabled.set(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getAugmentEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertStatsFilesExist(boolean exist) {
|
private void assertStatsFilesExist(boolean exist) {
|
||||||
|
|||||||
Reference in New Issue
Block a user