Remove phone from telephony network request
The new TelephonyNetworkProvider would be per-device
instead of per-phone. On dual SIM device, the telephony network
provider would be the singleton communicating with connectivity
service and two TelephonyNetworkController.
Therefore we need to remove the phone depdency from
TelephonyNetworkRequest at the provider layer. This is the preliminary
change before adding TelephonyNetworkProvider.
Flag: EXEMPT refactor
Bug: 343370895
Test: atest TelephonyNetworkFactoryTest DataNetworkTest
Test: Basic telephony functionality tests
Change-Id: Ifc562b6e17c5b5d8817d95192b9352ad4544bec8
diff --git a/src/java/com/android/internal/telephony/data/DataNetworkController.java b/src/java/com/android/internal/telephony/data/DataNetworkController.java
index 4d1786b..2572e2f 100644
--- a/src/java/com/android/internal/telephony/data/DataNetworkController.java
+++ b/src/java/com/android/internal/telephony/data/DataNetworkController.java
@@ -1299,6 +1299,13 @@
* @param networkRequest The network request.
*/
private void onAddNetworkRequest(@NonNull TelephonyNetworkRequest networkRequest) {
+ // TelephonyNetworkRequest at TelephonyNetworkProvider layer does not have config assigned
+ // (Because TelephonyNetworkProvider is a singleton across all SIMs. We are not able to
+ // retrieve the right carrier config for it.). So as soon as the request arrives
+ // DataNetworkController, we need to update the config in the request so it can update
+ // some of its config-dependent properties like request priority.
+ networkRequest.updateDataConfig(mDataConfigManager);
+
// To detect IMS back-to-back release-request anomaly event
if (mLastImsOperationIsRelease) {
mLastImsOperationIsRelease = false;
@@ -1746,7 +1753,9 @@
// Check if request is unmetered (WiFi or unmetered APN).
evaluation.addDataAllowedReason(DataAllowedReason.UNMETERED_USAGE);
} else if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WWAN) {
- if (!networkRequest.isMeteredRequest()) {
+ boolean isMeteredRequest = mDataConfigManager.isAnyMeteredCapability(
+ networkRequest.getCapabilities(), mServiceState.getDataRoaming());
+ if (!isMeteredRequest) {
evaluation.addDataAllowedReason(DataAllowedReason.UNMETERED_USAGE);
}
}
diff --git a/src/java/com/android/internal/telephony/data/TelephonyNetworkRequest.java b/src/java/com/android/internal/telephony/data/TelephonyNetworkRequest.java
index 67639eb..a43367e 100644
--- a/src/java/com/android/internal/telephony/data/TelephonyNetworkRequest.java
+++ b/src/java/com/android/internal/telephony/data/TelephonyNetworkRequest.java
@@ -137,10 +137,6 @@
CAPABILITY_ATTRIBUTE_APN_SETTING | CAPABILITY_ATTRIBUTE_TRAFFIC_DESCRIPTOR_DNN)
);
- /** The phone instance. */
- @NonNull
- private final Phone mPhone;
-
/**
* Native network request from the clients. See {@link NetworkRequest};
*/
@@ -164,8 +160,8 @@
/**
* Data config manager for retrieving data config.
*/
- @NonNull
- private final DataConfigManager mDataConfigManager;
+ @Nullable
+ private DataConfigManager mDataConfigManager;
/**
* The attached data network. Note that the data network could be in any state. {@code null}
@@ -205,7 +201,19 @@
*/
public TelephonyNetworkRequest(@NonNull NetworkRequest request, @NonNull Phone phone,
@NonNull FeatureFlags featureFlags) {
- mPhone = phone;
+ this(request, featureFlags);
+ mDataConfigManager = phone.getDataNetworkController().getDataConfigManager();
+ updatePriority();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param request The native network request from the clients.
+ * @param featureFlags The feature flag
+ */
+ public TelephonyNetworkRequest(@NonNull NetworkRequest request,
+ @NonNull FeatureFlags featureFlags) {
mNativeNetworkRequest = request;
mFeatureFlags = featureFlags;
@@ -222,7 +230,15 @@
// to satisfy it.
mState = REQUEST_STATE_UNSATISFIED;
mCreatedTimeMillis = SystemClock.elapsedRealtime();
- mDataConfigManager = phone.getDataNetworkController().getDataConfigManager();
+ }
+
+ /**
+ * Update the associated data config manager.
+ *
+ * @param dataConfigManager Data config manager
+ */
+ public void updateDataConfig(@NonNull DataConfigManager dataConfigManager) {
+ mDataConfigManager = dataConfigManager;
updatePriority();
}
@@ -315,13 +331,15 @@
if (mNativeNetworkRequest.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
&& !mNativeNetworkRequest.hasTransport(
NetworkCapabilities.TRANSPORT_SATELLITE)) {
- if (Arrays.stream(getCapabilities()).noneMatch(mDataConfigManager
- .getForcedCellularTransportCapabilities()::contains)) {
- // If the request is explicitly for the cellular, then the data profile
- // needs to support cellular.
- if (!dataProfile.getApnSetting().isForInfrastructure(
- ApnSetting.INFRASTRUCTURE_CELLULAR)) {
- return false;
+ if (mDataConfigManager != null) {
+ if (Arrays.stream(getCapabilities()).noneMatch(mDataConfigManager
+ .getForcedCellularTransportCapabilities()::contains)) {
+ // If the request is explicitly for the cellular, then the data profile
+ // needs to support cellular.
+ if (!dataProfile.getApnSetting().isForInfrastructure(
+ ApnSetting.INFRASTRUCTURE_CELLULAR)) {
+ return false;
+ }
}
}
} else if (mNativeNetworkRequest.hasTransport(
@@ -371,10 +389,12 @@
* Update the priority from data config manager.
*/
public void updatePriority() {
- mPriority = Arrays.stream(mNativeNetworkRequest.getCapabilities())
- .map(mDataConfigManager::getNetworkCapabilityPriority)
- .max()
- .orElse(0);
+ if (mDataConfigManager != null) {
+ mPriority = Arrays.stream(mNativeNetworkRequest.getCapabilities())
+ .map(mDataConfigManager::getNetworkCapabilityPriority)
+ .max()
+ .orElse(0);
+ }
}
/**
@@ -387,6 +407,7 @@
@NetCapability
public int getHighestPriorityApnTypeNetworkCapability() {
if (!hasAttribute(CAPABILITY_ATTRIBUTE_APN_SETTING)) return -1;
+ if (mDataConfigManager == null) return -1;
return Arrays.stream(getCapabilities()).boxed()
.filter(cap -> DataUtils.networkCapabilityToApnType(cap) != ApnSetting.TYPE_NONE)
.max(Comparator.comparingInt(mDataConfigManager::getNetworkCapabilityPriority))
@@ -403,6 +424,7 @@
*/
@NetCapability
public int getHighestPrioritySupportedNetworkCapability() {
+ if (mDataConfigManager == null) return -1;
return Arrays.stream(getCapabilities()).boxed()
.filter(CAPABILITY_ATTRIBUTE_MAP::containsKey)
.max(Comparator.comparingInt(mDataConfigManager::getNetworkCapabilityPriority))
@@ -487,14 +509,6 @@
}
/**
- * @return {@code true} if this network request can result in bringing up a metered network.
- */
- public boolean isMeteredRequest() {
- return mDataConfigManager.isAnyMeteredCapability(
- getCapabilities(), mPhone.getServiceState().getDataRoaming());
- }
-
- /**
* Get Os/App id from the network request.
*
* @return Os/App id. {@code null} if the request does not have traffic descriptor based network
@@ -547,7 +561,7 @@
return "[" + mNativeNetworkRequest + ", mPriority=" + mPriority
+ ", state=" + requestStateToString(mState)
+ ", mAttachedDataNetwork=" + (mAttachedDataNetwork != null
- ? mAttachedDataNetwork.name() : null) + ", isMetered=" + isMeteredRequest()
+ ? mAttachedDataNetwork.name() : null)
+ ", created time=" + DataUtils.elapsedTimeToString(mCreatedTimeMillis)
+ ", evaluation result=" + mEvaluation + "]";
}