Address comment at ag/18491259 and ag/18486388
Test: TH Bug: 230289468 Change-Id: Id91fabb47b542d8526d6aa787b5947238c3934fb Merged-In: Id91fabb47b542d8526d6aa787b5947238c3934fb (cherry-picked from ag/18579048)
This commit is contained in:
@@ -628,30 +628,14 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the persistent counter that counts total import legacy stats attempts.
|
* Create a persistent counter for given directory and name.
|
||||||
*/
|
*/
|
||||||
// TODO: Refactor multiple create counter functions into one.
|
public PersistentInt createPersistentCounter(@NonNull Path dir, @NonNull String name)
|
||||||
public PersistentInt createImportLegacyAttemptsCounter(@NonNull Path path)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// TODO: Modify PersistentInt to call setStartTime every time a write is made.
|
// TODO: Modify PersistentInt to call setStartTime every time a write is made.
|
||||||
// Create and pass a real logger here.
|
// Create and pass a real logger here.
|
||||||
return new PersistentInt(path.toString(), null /* logger */);
|
final String path = dir.resolve(name).toString();
|
||||||
}
|
return new PersistentInt(path, null /* logger */);
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the persistent counter that counts total import legacy stats successes.
|
|
||||||
*/
|
|
||||||
public PersistentInt createImportLegacySuccessesCounter(@NonNull Path path)
|
|
||||||
throws IOException {
|
|
||||||
return new PersistentInt(path.toString(), null /* logger */);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the persistent counter that counts total import legacy stats fallbacks.
|
|
||||||
*/
|
|
||||||
public PersistentInt createImportLegacyFallbacksCounter(@NonNull Path path)
|
|
||||||
throws IOException {
|
|
||||||
return new PersistentInt(path.toString(), null /* logger */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -929,12 +913,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mImportLegacyAttemptsCounter = mDeps.createImportLegacyAttemptsCounter(
|
mImportLegacyAttemptsCounter = mDeps.createPersistentCounter(mStatsDir.toPath(),
|
||||||
mStatsDir.toPath().resolve(NETSTATS_IMPORT_ATTEMPTS_COUNTER_NAME));
|
NETSTATS_IMPORT_ATTEMPTS_COUNTER_NAME);
|
||||||
mImportLegacySuccessesCounter = mDeps.createImportLegacySuccessesCounter(
|
mImportLegacySuccessesCounter = mDeps.createPersistentCounter(mStatsDir.toPath(),
|
||||||
mStatsDir.toPath().resolve(NETSTATS_IMPORT_SUCCESSES_COUNTER_NAME));
|
NETSTATS_IMPORT_SUCCESSES_COUNTER_NAME);
|
||||||
mImportLegacyFallbacksCounter = mDeps.createImportLegacyFallbacksCounter(
|
mImportLegacyFallbacksCounter = mDeps.createPersistentCounter(mStatsDir.toPath(),
|
||||||
mStatsDir.toPath().resolve(NETSTATS_IMPORT_FALLBACKS_COUNTER_NAME));
|
NETSTATS_IMPORT_FALLBACKS_COUNTER_NAME);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.wtf(TAG, "Failed to create persistent counters, skip.", e);
|
Log.wtf(TAG, "Failed to create persistent counters, skip.", e);
|
||||||
return;
|
return;
|
||||||
@@ -951,12 +935,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If fallbacks is not zero, proceed with reading only to give signals from dogfooders.
|
// If fallbacks is not zero, proceed with reading only to give signals from dogfooders.
|
||||||
// TODO: Remove fallbacks counter check before T formal release.
|
// TODO(b/233752318): Remove fallbacks counter check before T formal release.
|
||||||
if (attempts >= targetAttempts && fallbacks == 0) return;
|
if (attempts >= targetAttempts && fallbacks == 0) return;
|
||||||
|
|
||||||
if (attempts >= targetAttempts) {
|
final boolean dryRunImportOnly = (attempts >= targetAttempts);
|
||||||
|
if (dryRunImportOnly) {
|
||||||
Log.i(TAG, "Starting import : only perform read");
|
Log.i(TAG, "Starting import : only perform read");
|
||||||
} else{
|
} else {
|
||||||
Log.i(TAG, "Starting import : attempts " + attempts + "/" + targetAttempts);
|
Log.i(TAG, "Starting import : attempts " + attempts + "/" + targetAttempts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1030,7 +1015,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
// For cases where the fallbacks is not zero but target attempts counts reached,
|
// For cases where the fallbacks is not zero but target attempts counts reached,
|
||||||
// only perform reads above and return here.
|
// only perform reads above and return here.
|
||||||
if (attempts >= targetAttempts) return;
|
if (dryRunImportOnly) return;
|
||||||
|
|
||||||
// Find the latest end time.
|
// Find the latest end time.
|
||||||
for (final MigrationInfo migration : migrations) {
|
for (final MigrationInfo migration : migrations) {
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ import static android.text.format.DateUtils.WEEK_IN_MILLIS;
|
|||||||
|
|
||||||
import static com.android.net.module.util.NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
import static com.android.net.module.util.NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
||||||
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
|
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
|
||||||
|
import static com.android.server.net.NetworkStatsService.NETSTATS_IMPORT_ATTEMPTS_COUNTER_NAME;
|
||||||
|
import static com.android.server.net.NetworkStatsService.NETSTATS_IMPORT_FALLBACKS_COUNTER_NAME;
|
||||||
|
import static com.android.server.net.NetworkStatsService.NETSTATS_IMPORT_SUCCESSES_COUNTER_NAME;
|
||||||
import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2;
|
import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -152,6 +155,7 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
@@ -383,21 +387,18 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PersistentInt createImportLegacyAttemptsCounter(
|
public PersistentInt createPersistentCounter(@androidx.annotation.NonNull Path dir,
|
||||||
@androidx.annotation.NonNull Path path) {
|
@androidx.annotation.NonNull String name) throws IOException {
|
||||||
|
switch (name) {
|
||||||
|
case NETSTATS_IMPORT_ATTEMPTS_COUNTER_NAME:
|
||||||
return mImportLegacyAttemptsCounter;
|
return mImportLegacyAttemptsCounter;
|
||||||
}
|
case NETSTATS_IMPORT_SUCCESSES_COUNTER_NAME:
|
||||||
|
|
||||||
@Override
|
|
||||||
public PersistentInt createImportLegacySuccessesCounter(
|
|
||||||
@androidx.annotation.NonNull Path path) {
|
|
||||||
return mImportLegacySuccessesCounter;
|
return mImportLegacySuccessesCounter;
|
||||||
}
|
case NETSTATS_IMPORT_FALLBACKS_COUNTER_NAME:
|
||||||
|
|
||||||
@Override
|
|
||||||
public PersistentInt createImportLegacyFallbacksCounter(
|
|
||||||
@androidx.annotation.NonNull Path path) {
|
|
||||||
return mImportLegacyFallbacksCounter;
|
return mImportLegacyFallbacksCounter;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown counter name: " + name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user