Test Solution for listening to Android CTS (2)

Source: Internet
Author: User

Test Solution for listening to Android CTS (2)

2. Check whether the current Test item is an Accelerometer Measurement Test.

As described in the first method, we can obtain the current test item of the Activity in the active state, which is similar to the test item of the CTS test. However, because it monitors all the activities in the Android system, the system performance is greatly reduced. Therefore, there is a more efficient way to precisely locate the test items currently being tested by CTS, it will not have a great impact on the system. (Of course, The CTS Source Code cannot be modified. We need to use the native cts apk provided by Android for verification)

Here we use the Accelerometer Measurement Test to further analyze the code.

Step 1: Find the CTS Verifier tool to call the Framework or underlying function to obtain 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 a listener is registered and canceled during the test, and the listener is registered in SensroManager by tracking the listener, sensorManager is an abstract class, while the class that implements SensorManager in the system is only SystemSensorManager. java, only protected boolean registerListenerImpl (SensorEventListener listener, Sensor sensor,
Int delayUs, Handler handler, int maxBatchReportLatencyUs, int reservedFlags) is overwritten, so that all CTS tests will pass here, therefore, if we can obtain the currently active application and use the TYPE in the Sensor to determine the test item to locate it accurately, the current CTS is testing the test 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
 
   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()){        }


Related Article

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.