Ensure NetworkStats migrated snapshot is identical

Read migration snapshot both from the platform API and the legacy
method, and Log.wtf if they are different. Use the legacy method data if
they are.

This ensures that using the migration API is a no-op, and that errors
are reported (through Log.wtf) if it would not have been if used as-is.

Test: NetworkStatsServiceTest
Bug: 230289468
Change-Id: I857ad18183d63d1aa16e89f89eb24009648720a2
Merged-In: I857ad18183d63d1aa16e89f89eb24009648720a2
  (pure cherry-picked from ag/18452103)
This commit is contained in:
Remi NGUYEN VAN
2022-05-17 18:23:00 +09:00
committed by Junyu Lai
parent a388d4bf06
commit c62261f140
3 changed files with 267 additions and 43 deletions

View File

@@ -32,6 +32,7 @@ import static android.text.format.DateUtils.SECOND_IN_MILLIS;
import static com.android.net.module.util.NetworkStatsUtils.multiplySafeByRational;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
@@ -949,6 +950,25 @@ public final class NetworkStatsHistory implements Parcelable {
return writer.toString();
}
/**
* Same as "equals", but not actually called equals as this would affect public API behavior.
* @hide
*/
@Nullable
public boolean isSameAs(NetworkStatsHistory other) {
return bucketCount == other.bucketCount
&& Arrays.equals(bucketStart, other.bucketStart)
// Don't check activeTime since it can change on import due to the importer using
// recordHistory. It's also not exposed by the APIs or present in dumpsys or
// toString().
&& Arrays.equals(rxBytes, other.rxBytes)
&& Arrays.equals(rxPackets, other.rxPackets)
&& Arrays.equals(txBytes, other.txBytes)
&& Arrays.equals(txPackets, other.txPackets)
&& Arrays.equals(operations, other.operations)
&& totalBytes == other.totalBytes;
}
@UnsupportedAppUsage
public static final @android.annotation.NonNull Creator<NetworkStatsHistory> CREATOR = new Creator<NetworkStatsHistory>() {
@Override