[CTS]PhoneNumberUtilsTest-- testGetMethods&&ManagedProfileTest-- testManagedContacts
2016-07-23 12:41
483 查看
[CTS]android.telephony.cts.PhoneNumberUtilsTest– testGetMethods
[CTS]com.android.cts.devicepolicy.ManagedProfileTest– testManagedContacts
这个两个CTS错误都是因为系统开启了contacts同步导致的,我们就具体分析第一个问题,Android6.0 QCOM
通过查看 assertNull方法我们可以知道,预期是想传入一个null对象,但是实际上跑CTS的时候我们传入了非null对象,所以PhoneNumberUtils.getNumberFromIntent(intent, context)为非null对象,通过下面的代码我们可以发现
PhoneNumberUtils.getNumberFromIntent(intent, context) 的数据来自于系统联系人数据库,并且最终会调用ContactsProvider2.queryLocal方法查询数据,这个就有点儿奇怪了,跑CTS的时候contacts应用里面应该是没有数据才对,通过查看手机中的联系人我们可以发现,里面确实保存了一个联系人并且号码为:+16175551212,并且它的账户类型为SIM,这下真相大白了,这个联系人信息是从哪SIM导入到数据库的,因为当SIM卡插入手机时,会将里面的联系人数据保存在联系人本地数据库。
第二个问题的错误信息如下:与contacts是自动同步时成的phone账号有关。
[CTS]com.android.cts.devicepolicy.ManagedProfileTest– testManagedContacts
这个两个CTS错误都是因为系统开启了contacts同步导致的,我们就具体分析第一个问题,Android6.0 QCOM
错误信息如下
cts-tf > run cts -c android.telephony.cts.PhoneNumberUtilsTest -m testGetMethods --skip-preconditions android.telephony.cts.PhoneNumberUtilsTest#testGetMethods FAIL junit.framework.AssertionFailedError: Expected: <null> but was: +16175551212 //通过这行打印我们可以知道,预期结果是传入null但是我们传入了一串数字 at junit.framework.Assert.fail(Assert.java:50) at junit.framework.Assert.assertTrue(Assert.java:20) at junit.framework.Assert.assertNull(Assert.java:237) at junit.framework.Assert.assertNull(Assert.java:230) at android.telephony.cts.PhoneNumberUtilsTest.testGetMethods(PhoneNumberUtilsTest.java:138) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:168) 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)
分析流程
通过log信息我们查看PhoneNumberUtilsTest.java:138行代码如下:public void testGetMethods() throws RemoteException { // Test getStrippedReversed assertNull(PhoneNumberUtils.getStrippedReversed(null)); assertEquals("14145550071", PhoneNumberUtils.getStrippedReversed("1-700-555-4141")); assertEquals("14145550071", PhoneNumberUtils.getStrippedReversed("1-700-555-4141,1234")); assertEquals("14145550071", PhoneNumberUtils.getStrippedReversed("1-700-555-4141;1234")); assertEquals("NN145550071", PhoneNumberUtils.getStrippedReversed("1-700-555-41NN")); assertEquals("", PhoneNumberUtils.getStrippedReversed("")); assertEquals("#130#*+", PhoneNumberUtils.getStrippedReversed("+*#031#")); // Test getFormatTypeForLocale int formatType = PhoneNumberUtils.getFormatTypeForLocale(Locale.CHINA); assertEquals(PhoneNumberUtils.FORMAT_UNKNOWN, formatType); formatType = PhoneNumberUtils.getFormatTypeForLocale(Locale.US); assertEquals(PhoneNumberUtils.FORMAT_NANP, formatType); formatType = PhoneNumberUtils.getFormatTypeForLocale(Locale.JAPAN); assertEquals(PhoneNumberUtils.FORMAT_JAPAN, formatType); // Test getNumberFromIntent, query nothing, return null. Intent intent = new Intent(); intent.setData(Contacts.People.CONTENT_URI);//CONTENT_URI = Uri.parse("content://contacts/people") Context context = getContext(); assertNull(PhoneNumberUtils.getNumberFromIntent(intent, context));//错误发生在这一行 intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+18005555555")); assertEquals("+18005555555", PhoneNumberUtils.getNumberFromIntent(intent, getContext())); ContentResolver cr = getContext().getContentResolver(); Uri personRecord = null; Uri phoneRecord = null; try { // insert a contact with phone number ContentValues values = new ContentValues(); values.put(People.NAME, "CTS test contact"); personRecord = cr.insert(People.CONTENT_URI, values); Uri phoneUri = Uri.withAppendedPath(personRecord, People.Phones.CONTENT_DIRECTORY); values.clear(); values.put(People.Phones.TYPE, People.Phones.TYPE_HOME); values.put(People.Phones.NUMBER, "+18005552871"); phoneRecord = cr.insert(phoneUri, values); intent = new Intent(Intent.ACTION_DIAL, phoneRecord); assertEquals("+18005552871", PhoneNumberUtils.getNumberFromIntent(intent, getContext())); } finally { if (personRecord != null) { cr.delete(personRecord, null, null); } if (phoneRecord != null) { cr.delete(phoneRecord, null, null); } } }
通过查看 assertNull方法我们可以知道,预期是想传入一个null对象,但是实际上跑CTS的时候我们传入了非null对象,所以PhoneNumberUtils.getNumberFromIntent(intent, context)为非null对象,通过下面的代码我们可以发现
/** * The content:// style URL for this table * @deprecated see {@link android.provider.ContactsContract} */ @Deprecated public static final Uri CONTENT_URI = Uri.parse("content://contacts/people"); <provider android:name="ContactsProvider2" //联系人数据库 android:authorities="contacts;com.android.contacts" android:label="@string/provider_label" android:multiprocess="false" android:exported="true" android:grantUriPermissions="true" android:readPermission="android.permission.READ_CONTACTS" android:writePermission="android.permission.WRITE_CONTACTS">
PhoneNumberUtils.getNumberFromIntent(intent, context) 的数据来自于系统联系人数据库,并且最终会调用ContactsProvider2.queryLocal方法查询数据,这个就有点儿奇怪了,跑CTS的时候contacts应用里面应该是没有数据才对,通过查看手机中的联系人我们可以发现,里面确实保存了一个联系人并且号码为:+16175551212,并且它的账户类型为SIM,这下真相大白了,这个联系人信息是从哪SIM导入到数据库的,因为当SIM卡插入手机时,会将里面的联系人数据保存在联系人本地数据库。
解决办法
我们只需要将自动同步功能关闭就可以解决这个问题,修改如下:一、android/vendor/qcom/proprietary/qrdplus/Extension/config/default.prop //将true改为false //persist.env.contacts.autosync=true persist.env.contacts.autosync=false 二、android/vendor/qcom/proprietary/qrdplus/Extension/res-overlay/vendor/qcom/proprietary/telephony-apps/SimContacts/res/values/config.xml //将true改为false <resources> <!-- Configuration to set enable/disable SIM contacts auto sync --> //<bool name="sim_contacts_auto_sync">true</bool> <bool name="sim_contacts_auto_sync">false</bool> </resources>
第二个问题的错误信息如下:与contacts是自动同步时成的phone账号有关。
04-21 15:52:47 I/bc17b500: com.android.cts.devicepolicy.ManagedProfileTest#testManagedContacts FAIL junit.framework.AssertionFailedError at junit.framework.Assert.fail(Assert.java:48) at junit.framework.Assert.assertTrue(Assert.java:20) at junit.framework.Assert.assertTrue(Assert.java:27) at com.android.cts.devicepolicy.ManagedProfileTest.testManagedContacts(ManagedProfileTest.java:444) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at junit.framework.TestCase.runTest(TestCase.java:168) at junit.framework.TestCase.runBare(TestCase.java:134) at com.android.tradefed.testtype.DeviceTestResult$1.protect(DeviceTestResult.java:81) at com.android.tradefed.testtype.DeviceTestResult.runProtected(DeviceTestResult.java:56) at com.android.tradefed.testtype.DeviceTestResult.run(DeviceTestResult.java:85) at junit.framework.TestCase.run(TestCase.java:124) at com.android.tradefed.testtype.DeviceTestCase.run(DeviceTestCase.java:117) at com.android.cts.tradefed.testtype.JarHostTest$TestRunnable.run(JarHostTest.java:248) at com.android.tradefed.util.RunUtil$RunnableNotifier.run(RunUtil.java:378) 04-21 15:51:53 I/BaseDevicePolicyTest: Test com.android.cts.managedprofile.ContactsTest#testManagedProfilePhoneLookup_canNotAccessPrimaryContact: PASSED 04-21 15:51:54 I/BaseDevicePolicyTest: Test com.android.cts.managedprofile.ContactsTest#testManagedProfileEmailLookup_canNotAccessPrimaryContact: PASSED 04-21 15:51:56 I/BaseDevicePolicyTest: Test com.android.cts.managedprofile.ContactsTest#testManagedProfileEnterprisePhoneLookup_canAccessEnterpriseContact: FAILURE 04-21 15:51:56 W/BaseDevicePolicyTest: java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.android.cts.managedprofile.ContactsTest$ContactInfo.displayName' on a null object reference at com.android.cts.managedprofile.ContactsTest.testManagedProfileEnterprisePhoneLookup_canAccessEnterpriseContact(ContactsTest.java:311) at java.lang.reflect.Method.invoke(Native Method)
相关文章推荐
- 小希的礼物
- 减小Gcc编译程序的体积
- Trie树详解
- 373. Find K Pairs with Smallest Sums && 378. Kth Smallest Element in a Sorted Matrix
- linux ls正则表达式
- 【Mariadb】centos7搭建mariadb Galera集群
- Android提高启动速度的实现方法 7.23
- soft raid5阅读笔记之七--MD中的bitmap
- map.c 添加注释
- H5学习之4 拖拽元素 放置元素2
- 状态模式(State)
- ios创建空项目
- vector::begin
- Openstack贡献者须知 2 — 社区工作运作 & 代码贡献流程
- 解决磁盘io紧张的一种临时方法
- 通道类型
- Git 一篇搞定基本操作
- 文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别
- Redis教程分享系列:1.Redis基础入门
- ggplot2--legend图例的修改