Monitor Android CTS test Item solution (II)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.