Two, listen to whether the current test item is a accelerometer measurement test item
In the first way, we can get the currently active activity similar to listening to the CTS test current test item. But because it is listening to all the activity in the Android system, it greatly reduces the performance of the system, so there is a more efficient way to pinpoint the test items currently being tested by the CTS without significant impact on the system. (Of course, the CTS source code can not be modified, we need to use the Android provided by the native CTS apk for verification)
So here we take the Accelerometer measurement test in order to further analyze the code.
Step one: Find the CTS Verifier tool call the framework or the underlying function to get the data
(Accelerometermeasurementtestactivity.java) OnRun ()-->verifymeasurements ()--( Verifymeasurementsoperation.java) Execute ()-->dowork ()--(Sensormanagertestverifier.java) Msensor.collectevents (100)
Public testsensorevent[] collectevents (int eventcount, String debuginfo) { this.registerlistener (debuginfo); Testsensorevent[] Events = this.getevents (EventCount, debuginfo); This.unregisterlistener (); return events; }
public void Registerlistener (String debuginfo) { Boolean result = Msensormanager.registerlistener ( Meventlistener, msensorundertest, Msamplingrateinus, mreportlatencyinus); String message = Sensorctshelper.formatassertionmessage ( "Registerlistener", msensorundertest, Debuginfo); Assert.asserttrue (message, result); }
From the code above we can find that the listener is registered and canceled while the test is in progress, and by tracing the listener, the listener is registered in Sensromanager, and Sensormanager is an abstract class. The class that implements Sensormanager in the system is only Systemsensormanager.java, and in that class there is only protected Boolean Registerlistenerimpl ( Sensoreventlistener Listener, sensor sensor,
int Delayus, Handler Handler, int maxbatchreportlatencyus, int reservedflags) are rewritten, so that means all CTS tests will pass through here, So if we can get the currently active application here and use the type in the sensor to determine the exact location of the test item being tested, the current CTS is testing the item.
Specific implementation methods:
Private Boolean isacclerometermeasurementtest () {if (Mappcontextimpl = = null) {return false;} Final Activitymanager am = (activitymanager) mappcontextimpl.getsystemservice (Context.activity_service); if (AM = = null ) {return false;} list<runningappprocessinfo> list = Am.getrunningappprocesses (); if ((list!=null) && (list.size ()! = 0)) { Runningappprocessinfo toprunningprocess = list.get (0); if ((toprunningprocess!=null) && (toprunningprocess.processname!=null) && TopRunningProcess.processName.equals ("Com.android.cts.verifier")) {if (isacclerometermeasurementfocus () = = 1) { return true;} } } return false; }
if ((sensor = null) && (Sensor.gettype () ==sensor.type_accelerometer) && Isacclerometermeasurementtest ()) { }
Monitor Android CTS test Item solution (II)