[MS07.1] Move NetworkStatsCollection/IdentitySet into frameworks

These files are needed for the data migration util system Api
interfaces to allow OEMs to construct NetworkStats* objects.
Thus, they need to be moved into android.net package, and some
of them will be exposed as @SystemApi in T.

Eventually these classes will be moved into the Connectivity
module, but in the mean time they will be temporarily moved to
f/b/package/ConnectivityT for the preparation stage.
However, the tests are already in the module. Therefore for
the S-derived branch, the test cannot see the renamed classes
since any framework CLs will not be auto-merged into this branch.
Thus, the tests need to stay disabled on the S-derived branch,
and will be re-enabled after all files are moved into the module.

Test: TH
Bug: 197717846

Change-Id: I95278a99cf2437ada28001161ceea17a1d32f2a4
This commit is contained in:
Junyu Lai
2021-12-10 07:46:43 +00:00
parent ad166b43df
commit c8c87d4a01
6 changed files with 47 additions and 20 deletions

View File

@@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server.net; package android.net;
import static android.net.ConnectivityManager.TYPE_MOBILE;
import android.net.NetworkIdentity;
import android.service.NetworkIdentitySetProto; import android.service.NetworkIdentitySetProto;
import android.util.proto.ProtoOutputStream; import android.util.proto.ProtoOutputStream;
@@ -25,8 +26,6 @@ import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import static android.net.ConnectivityManager.TYPE_MOBILE;
/** /**
* Identity of a {@code iface}, defined by the set of {@link NetworkIdentity} * Identity of a {@code iface}, defined by the set of {@link NetworkIdentity}
* active on that interface. * active on that interface.
@@ -97,6 +96,9 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
} }
} }
/**
* Method to serialize this object into a {@code DataOutput}.
*/
public void writeToStream(DataOutput out) throws IOException { public void writeToStream(DataOutput out) throws IOException {
out.writeInt(VERSION_ADD_OEM_MANAGED_NETWORK); out.writeInt(VERSION_ADD_OEM_MANAGED_NETWORK);
out.writeInt(size()); out.writeInt(size());
@@ -179,6 +181,9 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
return ident.compareTo(anotherIdent); return ident.compareTo(anotherIdent);
} }
/**
* Method to dump this object into proto debug file.
*/
public void dumpDebug(ProtoOutputStream proto, long tag) { public void dumpDebug(ProtoOutputStream proto, long tag) {
final long start = proto.start(tag); final long start = proto.start(tag);

View File

@@ -11,10 +11,10 @@
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License * limitations under the License.
*/ */
package com.android.server.net; package android.net;
import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY; import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY;
import static android.net.NetworkStats.UID_ALL; import static android.net.NetworkStats.UID_ALL;
@@ -37,7 +37,11 @@ import com.android.server.LocalServices;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
/** Utility methods for controlling access to network stats APIs. */ /**
* Utility methods for controlling access to network stats APIs.
*
* @hide
*/
public final class NetworkStatsAccess { public final class NetworkStatsAccess {
private NetworkStatsAccess() {} private NetworkStatsAccess() {}

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server.net; package android.net;
import static android.net.NetworkStats.DEFAULT_NETWORK_NO; import static android.net.NetworkStats.DEFAULT_NETWORK_NO;
import static android.net.NetworkStats.DEFAULT_NETWORK_YES; import static android.net.NetworkStats.DEFAULT_NETWORK_YES;
@@ -31,13 +31,7 @@ import static android.net.TrafficStats.UID_REMOVED;
import static android.text.format.DateUtils.WEEK_IN_MILLIS; import static android.text.format.DateUtils.WEEK_IN_MILLIS;
import static com.android.internal.net.NetworkUtilsInternal.multiplySafeByRational; import static com.android.internal.net.NetworkUtilsInternal.multiplySafeByRational;
import static com.android.server.net.NetworkStatsService.TAG;
import android.net.NetworkIdentity;
import android.net.NetworkStats;
import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate;
import android.net.TrafficStats;
import android.os.Binder; import android.os.Binder;
import android.service.NetworkStatsCollectionKeyProto; import android.service.NetworkStatsCollectionKeyProto;
import android.service.NetworkStatsCollectionProto; import android.service.NetworkStatsCollectionProto;
@@ -85,8 +79,11 @@ import java.util.Objects;
/** /**
* Collection of {@link NetworkStatsHistory}, stored based on combined key of * Collection of {@link NetworkStatsHistory}, stored based on combined key of
* {@link NetworkIdentitySet}, UID, set, and tag. Knows how to persist itself. * {@link NetworkIdentitySet}, UID, set, and tag. Knows how to persist itself.
*
* @hide
*/ */
public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.Writer { public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.Writer {
private static final String TAG = NetworkStatsCollection.class.getSimpleName();
/** File header magic number: "ANET" */ /** File header magic number: "ANET" */
private static final int FILE_MAGIC = 0x414E4554; private static final int FILE_MAGIC = 0x414E4554;
@@ -366,8 +363,8 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
entry.uid = key.uid; entry.uid = key.uid;
entry.set = key.set; entry.set = key.set;
entry.tag = key.tag; entry.tag = key.tag;
entry.defaultNetwork = key.ident.areAllMembersOnDefaultNetwork() ? entry.defaultNetwork = key.ident.areAllMembersOnDefaultNetwork()
DEFAULT_NETWORK_YES : DEFAULT_NETWORK_NO; ? DEFAULT_NETWORK_YES : DEFAULT_NETWORK_NO;
entry.metered = key.ident.isAnyMemberMetered() ? METERED_YES : METERED_NO; entry.metered = key.ident.isAnyMemberMetered() ? METERED_YES : METERED_NO;
entry.roaming = key.ident.isAnyMemberRoaming() ? ROAMING_YES : ROAMING_NO; entry.roaming = key.ident.isAnyMemberRoaming() ? ROAMING_YES : ROAMING_NO;
entry.rxBytes = historyEntry.rxBytes; entry.rxBytes = historyEntry.rxBytes;
@@ -521,6 +518,12 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
} }
} }
/**
* Read legacy network summary statistics file format into the collection,
* See {@code NetworkStatsService#maybeUpgradeLegacyStatsLocked}.
*
* @deprecated
*/
@Deprecated @Deprecated
public void readLegacyNetwork(File file) throws IOException { public void readLegacyNetwork(File file) throws IOException {
final AtomicFile inputFile = new AtomicFile(file); final AtomicFile inputFile = new AtomicFile(file);
@@ -560,6 +563,12 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
} }
} }
/**
* Read legacy Uid statistics file format into the collection,
* See {@code NetworkStatsService#maybeUpgradeLegacyStatsLocked}.
*
* @deprecated
*/
@Deprecated @Deprecated
public void readLegacyUid(File file, boolean onlyTags) throws IOException { public void readLegacyUid(File file, boolean onlyTags) throws IOException {
final AtomicFile inputFile = new AtomicFile(file); final AtomicFile inputFile = new AtomicFile(file);
@@ -774,19 +783,19 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
public final int set; public final int set;
public final int tag; public final int tag;
private final int hashCode; private final int mHashCode;
public Key(NetworkIdentitySet ident, int uid, int set, int tag) { Key(NetworkIdentitySet ident, int uid, int set, int tag) {
this.ident = ident; this.ident = ident;
this.uid = uid; this.uid = uid;
this.set = set; this.set = set;
this.tag = tag; this.tag = tag;
hashCode = Objects.hash(ident, uid, set, tag); mHashCode = Objects.hash(ident, uid, set, tag);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return hashCode; return mHashCode;
} }
@Override @Override

View File

@@ -22,7 +22,10 @@ import static com.android.internal.util.Preconditions.checkArgument;
import android.app.usage.NetworkStatsManager; import android.app.usage.NetworkStatsManager;
import android.net.DataUsageRequest; import android.net.DataUsageRequest;
import android.net.NetworkIdentitySet;
import android.net.NetworkStats; import android.net.NetworkStats;
import android.net.NetworkStatsAccess;
import android.net.NetworkStatsCollection;
import android.net.NetworkStatsHistory; import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate; import android.net.NetworkTemplate;
import android.os.Bundle; import android.os.Bundle;

View File

@@ -21,8 +21,11 @@ import static android.net.TrafficStats.KB_IN_BYTES;
import static android.net.TrafficStats.MB_IN_BYTES; import static android.net.TrafficStats.MB_IN_BYTES;
import static android.text.format.DateUtils.YEAR_IN_MILLIS; import static android.text.format.DateUtils.YEAR_IN_MILLIS;
import android.net.NetworkIdentitySet;
import android.net.NetworkStats; import android.net.NetworkStats;
import android.net.NetworkStats.NonMonotonicObserver; import android.net.NetworkStats.NonMonotonicObserver;
import android.net.NetworkStatsAccess;
import android.net.NetworkStatsCollection;
import android.net.NetworkStatsHistory; import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate; import android.net.NetworkTemplate;
import android.net.TrafficStats; import android.net.TrafficStats;

View File

@@ -96,11 +96,14 @@ import android.net.INetworkStatsSession;
import android.net.Network; import android.net.Network;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkIdentity; import android.net.NetworkIdentity;
import android.net.NetworkIdentitySet;
import android.net.NetworkSpecifier; import android.net.NetworkSpecifier;
import android.net.NetworkStack; import android.net.NetworkStack;
import android.net.NetworkStateSnapshot; import android.net.NetworkStateSnapshot;
import android.net.NetworkStats; import android.net.NetworkStats;
import android.net.NetworkStats.NonMonotonicObserver; import android.net.NetworkStats.NonMonotonicObserver;
import android.net.NetworkStatsAccess;
import android.net.NetworkStatsCollection;
import android.net.NetworkStatsHistory; import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate; import android.net.NetworkTemplate;
import android.net.TelephonyNetworkSpecifier; import android.net.TelephonyNetworkSpecifier;