Ensure autoKi is not stored when keepalive stops or is not started.
In the cases below, the keepalive is already cleaned up internally in
KeepaliveTracker, but are not be cleaned up in
AutomaticOnOffKeepaliveTracker. This means the mAutomaticOnOffKeepalives
list is storing stopped keepalives and the metrics will still conisder
the keepalive as active.
1. In KeepaliveInfo.start, return whether the keepalive is successfully
starting(i.e. mStartedState == STARTING). Check for this in
handleStartKeepalive and return early on failure, without storing the
autoKi. Also check in handleResumeKeepalive.
2. In handleEventSocketKeepalive, return whether the handleStopKeepalive
is called, indicating the keepalive is forced to stop and was not
already STOPPING. This should happen when the state is STARTING but
the network agent returned an unsuccessful event.
3. In handleCheckKeepalivesStillValid, move the checking logic to
AutomaticOnOffKeepaliveTracker so the handleStopKeepalive is called.
Bug: 281646074
Test: atest FrameworksNetTests
Change-Id: I7839464534baed43abbd40b321287132da25b978
3 files changed