[DK2-3]Do not attemp to stop keepalive on nonexistent network
Bug: 266771129
Test: atest FrameworksNetTests
Change-Id: I42cfe0720eddac70d76abbb340ea427f2d714c3a
diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
index cd4421b..330a1da 100755
--- a/service/src/com/android/server/ConnectivityService.java
+++ b/service/src/com/android/server/ConnectivityService.java
@@ -5576,6 +5576,10 @@
// Sent by KeepaliveTracker to process an app request on the state machine thread.
case NetworkAgent.CMD_STOP_SOCKET_KEEPALIVE: {
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork((Network) msg.obj);
+ if (nai == null) {
+ Log.e(TAG, "Attempt to stop keepalive on nonexistent network");
+ return;
+ }
int slot = msg.arg1;
int reason = msg.arg2;
mKeepaliveTracker.handleStopKeepalive(nai, slot, reason);
diff --git a/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java b/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java
index b6627c6..46fff6c 100644
--- a/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java
+++ b/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java
@@ -397,7 +397,7 @@
/**
* Handle stop keepalives on the specific network with given slot.
*/
- public void handleStopKeepalive(NetworkAgentInfo nai, int slot, int reason) {
+ public void handleStopKeepalive(@NonNull NetworkAgentInfo nai, int slot, int reason) {
final AutomaticOnOffKeepalive autoKi = findAutomaticOnOffKeepalive(nai.network, slot);
if (null == autoKi) {
Log.e(TAG, "Attempt to stop nonexistent keepalive " + slot + " on " + nai);