Merge "[NS02] Mix in validation of the score"
This commit is contained in:
@@ -33,13 +33,21 @@ public final class NetworkScore implements Parcelable {
|
|||||||
// a migration.
|
// a migration.
|
||||||
private final int mLegacyInt;
|
private final int mLegacyInt;
|
||||||
|
|
||||||
|
// Agent-managed policies
|
||||||
|
// TODO : add them here, starting from 1
|
||||||
|
|
||||||
|
// Bitmask of all the policies applied to this score.
|
||||||
|
private final long mPolicies;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
NetworkScore(final int legacyInt) {
|
NetworkScore(final int legacyInt, final long policies) {
|
||||||
this.mLegacyInt = legacyInt;
|
mLegacyInt = legacyInt;
|
||||||
|
mPolicies = policies;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetworkScore(@NonNull final Parcel in) {
|
private NetworkScore(@NonNull final Parcel in) {
|
||||||
mLegacyInt = in.readInt();
|
mLegacyInt = in.readInt();
|
||||||
|
mPolicies = in.readLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLegacyInt() {
|
public int getLegacyInt() {
|
||||||
@@ -54,6 +62,7 @@ public final class NetworkScore implements Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
public void writeToParcel(@NonNull final Parcel dest, final int flags) {
|
public void writeToParcel(@NonNull final Parcel dest, final int flags) {
|
||||||
dest.writeInt(mLegacyInt);
|
dest.writeInt(mLegacyInt);
|
||||||
|
dest.writeLong(mPolicies);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,6 +88,7 @@ public final class NetworkScore implements Parcelable {
|
|||||||
* A builder for NetworkScore.
|
* A builder for NetworkScore.
|
||||||
*/
|
*/
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
private static final long POLICY_NONE = 0L;
|
||||||
private static final int INVALID_LEGACY_INT = Integer.MIN_VALUE;
|
private static final int INVALID_LEGACY_INT = Integer.MIN_VALUE;
|
||||||
private int mLegacyInt = INVALID_LEGACY_INT;
|
private int mLegacyInt = INVALID_LEGACY_INT;
|
||||||
|
|
||||||
@@ -102,7 +112,7 @@ public final class NetworkScore implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public NetworkScore build() {
|
public NetworkScore build() {
|
||||||
return new NetworkScore(mLegacyInt);
|
return new NetworkScore(mLegacyInt, POLICY_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.server.connectivity;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.net.NetworkScore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents how desirable a network is.
|
||||||
|
*
|
||||||
|
* FullScore is very similar to NetworkScore, but it contains the bits that are managed
|
||||||
|
* by ConnectivityService. This provides static guarantee that all users must know whether
|
||||||
|
* they are handling a score that had the CS-managed bits set.
|
||||||
|
*/
|
||||||
|
public class FullScore {
|
||||||
|
// This will be removed soon. Do *NOT* depend on it for any new code that is not part of
|
||||||
|
// a migration.
|
||||||
|
private final int mLegacyInt;
|
||||||
|
|
||||||
|
// Agent-managed policies are in NetworkScore. They start from 1.
|
||||||
|
// CS-managed policies
|
||||||
|
// This network is validated. CS-managed because the source of truth is in NetworkCapabilities.
|
||||||
|
public static final int POLICY_IS_VALIDATED = 63;
|
||||||
|
|
||||||
|
// Bitmask of all the policies applied to this score.
|
||||||
|
private final long mPolicies;
|
||||||
|
|
||||||
|
FullScore(final int legacyInt, final long policies) {
|
||||||
|
mLegacyInt = legacyInt;
|
||||||
|
mPolicies = policies;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a FullScore from a NetworkScore
|
||||||
|
*/
|
||||||
|
public static FullScore withPolicy(@NonNull final NetworkScore originalScore,
|
||||||
|
final boolean isValidated) {
|
||||||
|
return new FullScore(originalScore.getLegacyInt(),
|
||||||
|
isValidated ? 1L << POLICY_IS_VALIDATED : 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For backward compatibility, get the legacy int.
|
||||||
|
* This will be removed before S is published.
|
||||||
|
*/
|
||||||
|
public int getLegacyInt() {
|
||||||
|
return mLegacyInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Score(" + mLegacyInt + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.server.connectivity;
|
package com.android.server.connectivity;
|
||||||
|
|
||||||
import static android.net.ConnectivityDiagnosticsManager.ConnectivityReport;
|
import static android.net.ConnectivityDiagnosticsManager.ConnectivityReport;
|
||||||
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
|
||||||
import static android.net.NetworkCapabilities.transportNamesOf;
|
import static android.net.NetworkCapabilities.transportNamesOf;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
@@ -303,8 +304,9 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
// validated).
|
// validated).
|
||||||
private boolean mInactive;
|
private boolean mInactive;
|
||||||
|
|
||||||
// This represents the quality of the network.
|
// This represents the quality of the network. As opposed to NetworkScore, FullScore includes
|
||||||
private NetworkScore mScore;
|
// the ConnectivityService-managed bits.
|
||||||
|
private FullScore mScore;
|
||||||
|
|
||||||
// The list of NetworkRequests being satisfied by this Network.
|
// The list of NetworkRequests being satisfied by this Network.
|
||||||
private final SparseArray<NetworkRequest> mNetworkRequests = new SparseArray<>();
|
private final SparseArray<NetworkRequest> mNetworkRequests = new SparseArray<>();
|
||||||
@@ -356,7 +358,7 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
networkInfo = info;
|
networkInfo = info;
|
||||||
linkProperties = lp;
|
linkProperties = lp;
|
||||||
networkCapabilities = nc;
|
networkCapabilities = nc;
|
||||||
mScore = score;
|
mScore = mixInScore(score, nc);
|
||||||
clatd = new Nat464Xlat(this, netd, dnsResolver, deps);
|
clatd = new Nat464Xlat(this, netd, dnsResolver, deps);
|
||||||
mConnService = connService;
|
mConnService = connService;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -890,7 +892,12 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setScore(final NetworkScore score) {
|
public void setScore(final NetworkScore score) {
|
||||||
mScore = score;
|
mScore = mixInScore(score, networkCapabilities);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FullScore mixInScore(@NonNull final NetworkScore score,
|
||||||
|
@NonNull final NetworkCapabilities caps) {
|
||||||
|
return FullScore.withPolicy(score, caps.hasCapability(NET_CAPABILITY_VALIDATED));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user