Make testServiceForegroundDuration test more stable

The BatteryStatsValidationTest#testServiceForegroundDuration test has
dependecy to the runtime of the runDeviceTests() method.
By comparing with the real time of the cts test instead of a hard-coded
value, external system impact is eliminated.

The signal to BatteryStats that the service is no longer running is
sent just before runDeviceTests() ends.
BatteryStatsImpl.TimeBase.setRunning(false ...), is called from
ActivityManagerService.finishInstrumentationLocked.
Triggered by Instrumentation.finish().

Test: run cts -m CtsIncidentHostTestCases -t
Bug: 70787319
com.android.server.cts.BatteryStatsValidationTest#testServiceForegroundDuration
Change-Id: I715473b9fe5865f2242978bd30c77e4ac586cd0e
1 file changed