解决CTS测试项testIsUserAMonkey

Android cts 测试中有一项测试testIsUserAMonkey

解决CTS测试项testIsUserAMonkey_第1张图片

host_log如下:

02-16 09:57:53 I/00003c591ec7205b: android.app.cts.ActivityManagerTest#testIsUserAMonkey FAIL 
junit.framework.AssertionFailedError
at junit.framework.Assert.fail(Assert.java:48)
at junit.framework.Assert.assertTrue(Assert.java:20)
at junit.framework.Assert.assertFalse(Assert.java:34)
at junit.framework.Assert.assertFalse(Assert.java:41)
at android.app.cts.ActivityManagerTest.testIsUserAMonkey(ActivityManagerTest.java:367)
at java.lang.reflect.Method.invoke(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:115)
at android.support.test.internal.runner.junit3.AndroidTestResult.runProtected(AndroidTestResult.java:77)
at junit.framework.TestResult.run(TestResult.java:118)
at android.support.test.internal.runner.junit3.AndroidTestResult.run(AndroidTestResult.java:55)
at junit.framework.TestCase.run(TestCase.java:124)
at android.support.test.internal.runner.junit3.NonLeakyTestSuite$NonLeakyTest.run(NonLeakyTestSuite.java:63)
at android.support.test.internal.runner.junit3.AndroidTestSuite$1.run(AndroidTestSuite.java:98)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

查cts源码ests/tests/app/src/android/app/cts/ActivityManagerTest.java找到测试项

361     /**
362      * Simple test for {@link ActivityManager.isUserAMonkey()} - verifies its false.
363      *
364      * TODO: test positive case
365      */
366     public void testIsUserAMonkey() {
367         assertFalse(ActivityManager.isUserAMonkey());
368     }

根据isUserAMonkey函数在framework下grep -nr isUserAMonkey找到该函数的最终实现

base/services/core/java/com/android/server/am/ActivityManagerService.java:10797

10797     public boolean isUserAMonkey() {
10798         synchronized (this) {
10799             // If there is a controller also implies the user is a monkey.
10800             return (mUserIsMonkey || mController != null);
10801         }
10802     }

可以知道判断isUserAMonkey是mUserIsMonkey 和mController 决定。

在isUserAMonkey函数中加打印发现mUserIsMonkey 值不论fail或者pass都是false.而mController 会是!=null。

进而找到设置mController 函数setActivityController。

在framework层使用命令grep -nr setActivityController

会找到base/core/java/android/app/ActivityManagerNative.java中有这个函数

public void setActivityController(IActivityController watcher) throws RemoteException{}

在这个函数中添加Log.i("xxx", "native setActivityController----",new RuntimeException("here").fillInStackTrace());

打印调用此函数的堆栈信息。


测试后可以在logcat中找到堆栈信息。

最后发现是我们的一个系统应用在开机调用android.app.ActivityManagerProxy.setActivityController

埋了一周的坑被填了。



你可能感兴趣的:(CTS测试总结)