summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRemi NGUYEN VAN <reminv@google.com>2021-06-25 16:38:05 +0900
committerRemi NGUYEN VAN <reminv@google.com>2021-06-28 09:14:30 +0900
commit1e238a87e9b31be9a08d41ec8d76ad68d82f665c (patch)
tree6b39ae0c1c3e2956ad11d9588b3112e584591582
parentef34fd2e21ced33d54534edbf40980c0297a6d0b (diff)
Fix null PendingIntent in network listens
In S ConnectivityService was changed to use getActiveRequest() to fill EXTRA_NETWORK_REQUEST, but there is no active request in the case of listens. When getActiveRequest() is missing, use the first mRequest instead. This should match previous behavior. Bug: 191713869 Test: atest android.net.cts.ConnectivityManagerTest Change-Id: Id7343a4cc020aba16b7979b16334721c56b2839c
-rw-r--r--service/src/com/android/server/ConnectivityService.java13
-rw-r--r--tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java3
2 files changed, 10 insertions, 6 deletions
diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
index 05bacfaeaf..352d26634c 100644
--- a/service/src/com/android/server/ConnectivityService.java
+++ b/service/src/com/android/server/ConnectivityService.java
@@ -7597,9 +7597,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
// If apps could file multi-layer requests with PendingIntents, they'd need to know
// which of the layer is satisfied alongside with some ID for the request. Hence, if
// such an API is ever implemented, there is no doubt the right request to send in
- // EXTRA_NETWORK_REQUEST is mActiveRequest, and whatever ID would be added would need to
- // be sent as a separate extra.
- intent.putExtra(ConnectivityManager.EXTRA_NETWORK_REQUEST, nri.getActiveRequest());
+ // EXTRA_NETWORK_REQUEST is the active request, and whatever ID would be added would
+ // need to be sent as a separate extra.
+ final NetworkRequest req = nri.isMultilayerRequest()
+ ? nri.getActiveRequest()
+ // Non-multilayer listen requests do not have an active request
+ : nri.mRequests.get(0);
+ if (req == null) {
+ Log.wtf(TAG, "No request in NRI " + nri);
+ }
+ intent.putExtra(ConnectivityManager.EXTRA_NETWORK_REQUEST, req);
nri.mPendingIntentSent = true;
sendIntent(nri.mPendingIntent, intent);
}
diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
index 3220565e84..51290428d3 100644
--- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
@@ -76,7 +76,6 @@ import static android.system.OsConstants.AF_UNSPEC;
import static com.android.compatibility.common.util.SystemUtil.callWithShellPermissionIdentity;
import static com.android.compatibility.common.util.SystemUtil.runShellCommand;
import static com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity;
-import static com.android.modules.utils.build.SdkLevel.isAtLeastS;
import static com.android.networkstack.apishim.ConstantsShim.BLOCKED_REASON_LOCKDOWN_VPN;
import static com.android.networkstack.apishim.ConstantsShim.BLOCKED_REASON_NONE;
import static com.android.testutils.MiscAsserts.assertThrows;
@@ -953,8 +952,6 @@ public class ConnectivityManagerTest {
private void assertPendingIntentRequestMatches(NetworkRequest broadcasted, NetworkRequest filed,
boolean useListen) {
- // TODO: BUG (b/191713869): on S the request extra is null on listens
- if (isAtLeastS() && useListen && broadcasted == null) return;
assertArrayEquals(filed.networkCapabilities.getCapabilities(),
broadcasted.networkCapabilities.getCapabilities());
// TODO: BUG (b/189868426): this should also apply to listens