Android4.4 CTS测试Fail项批改总结(一)
Android4.4 CTS测试Fail项修改总结(一)
这两个Intent
1、测试android.webkit.cts.GeolocationTest Fail
提示:
cts-tf > run cts --class android.webkit.cts.GeolocationTest 12-13 16:55:23 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a 12-13 16:55:23 I/385b4e4a: Created result dir 2014.12.13_16.55.23 12-13 16:55:34 I/385b4e4a: Collecting device info 12-13 16:55:35 I/385b4e4a: ----------------------------------------- 12-13 16:55:35 I/385b4e4a: Test package android.webkit started 12-13 16:55:35 I/385b4e4a: ----------------------------------------- 12-13 16:55:38 I/385b4e4a: android.webkit.cts.GeolocationTest#testGeolocationPermissions FAIL java.lang.SecurityException: Requires ACCESS_MOCK_LOCATION secure setting at android.os.Parcel.readException(Parcel.java:1480) at android.os.Parcel.readException(Parcel.java:1429) at android.location.ILocationManager$Stub$Proxy.addTestProvider(ILocationManager.java:944) at android.location.LocationManager.addTestProvider(LocationManager.java:1205) at android.webkit.cts.GeolocationTest.addTestProviders(GeolocationTest.java:188) at android.webkit.cts.GeolocationTest.setUp(GeolocationTest.java:166) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)提示没有相关的权限
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>如果在《开发者选项》中《允许模拟位置》的开关没有打开,即使加上也是会报错,这个开关的默认值是在/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java中进行设置
// Allow mock locations default, based on build loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION, "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);而ro.allow.mock.location的值是以下配置文件中设置的
文件位于:/build/core.main.mk
## user/userdebug ## user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT)) enable_target_debugging := true tags_to_install := ifneq (,$(user_variant)) # Target is secure in user builds. ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1 ifeq ($(user_variant),userdebug) # Pick up some extra useful tools tags_to_install += debug # Enable Dalvik lock contention logging for userdebug builds. ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500 else # Disable debugging in plain user builds. enable_target_debugging := endif # Turn on Dalvik preoptimization for libdvm.so user builds, but only if not # explicitly disabled and the build is running on Linux (since host # Dalvik isn't built for non-Linux hosts). ifeq (,$(WITH_DEXPREOPT)) ifeq ($(DALVIK_VM_LIB),libdvm.so) ifeq ($(user_variant),user) ifeq ($(HOST_OS),linux) WITH_DEXPREOPT := true endif endif endif endif # Disallow mock locations by default for user builds ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0 else # !user_variant # Turn on checkjni for non-user builds. ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1 # Set device insecure for non-user builds. ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0 # Allow mock locations by default for non user builds ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1 endif # !user_variant当然修改这个CTS Fail有两种方法
1、修改DatabaseHelper.java文件
loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION, 1);
2、修改main.mk文件
# Disallow mock locations by default for user builds ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1如果需要验证可以手动打开
2、测试android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest FAIL
cts-tf > run cts --class android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest 12-13 18:55:28 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a 12-13 18:55:28 I/385b4e4a: Created result dir 2014.12.13_18.55.28 12-13 18:55:40 I/385b4e4a: Collecting device info 12-13 18:55:41 I/385b4e4a: ----------------------------------------- 12-13 18:55:41 I/385b4e4a: Test package android.content started 12-13 18:55:41 I/385b4e4a: ----------------------------------------- 12-13 18:55:43 I/385b4e4a: android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest#testDisplayNameComparator FAIL junit.framework.AssertionFailedError at android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest.testDisplayNameComparator(ResolveInfo_DisplayNameComparatorTest.java:40) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701) 12-13 18:55:43 I/385b4e4a: android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest#testAndroidTestCaseSetupProperly PASS 12-13 18:55:46 I/385b4e4a: Saved log device_logcat_19588081496169516.zip 12-13 18:55:47 I/385b4e4a: Saved log host_log_6056597035559363496.zip 12-13 18:55:47 I/385b4e4a: android.content package complete: Passed 1, Failed 1, Not Executed 0 12-13 18:55:47 I/385b4e4a: Created xml report file at file:///home/android-cts-4.4_r3-linux_x86-arm/android-cts/tools/./../../android-cts/repository/results/2014.12.13_18.55.28/testResult.xml 12-13 18:55:47 I/385b4e4a: XML test result file generated at 2014.12.13_18.55.28. Passed 1, Failed 1, Not Executed 0 12-13 18:55:47 I/385b4e4a: Time: 0s这段测试代码位于:./cts/tests/tests/content/src/android/content/pm/cts/ResolveInfo_DisplayNameComparatorTest.java
/* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cts_8609.pm; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo.DisplayNameComparator; import android.test.AndroidTestCase; import android.util.Log; public class ResolveInfo_DisplayNameComparatorTest extends AndroidTestCase { private static final String MAIN_ACTION_NAME = "android.intent.action.MAIN"; private static final String SERVICE_NAME = "android.content.pm.cts.activity.PMTEST_SERVICE"; public void testDisplayNameComparator() { PackageManager pm = getContext().getPackageManager(); DisplayNameComparator dnc = new DisplayNameComparator(pm); Intent intent = new Intent(MAIN_ACTION_NAME); ResolveInfo activityInfo = pm.resolveActivity(intent, 0); intent = new Intent(SERVICE_NAME); ResolveInfo serviceInfo = pm.resolveService(intent, PackageManager.GET_RESOLVED_FILTER); assertTrue(dnc.compare(activityInfo, serviceInfo) < 0); assertTrue(dnc.compare(activityInfo, activityInfo) == 0); assertTrue(dnc.compare(serviceInfo, activityInfo) > 0); } }非常简单,就是比较两个Intent
这两个Intent
private static final String MAIN_ACTION_NAME = "android.intent.action.MAIN";
private static final String SERVICE_NAME = "android.content.pm.cts.activity.PMTEST_SERVICE";
是在./cts/tests/AndroidManifest.xml中注册的
<activity android:name="android.content.pm.cts.TestPmCompare"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.INFO" /> </intent-filter> </activity> <!--Test for PackageManager--> <service android:name="android.content.pm.cts.TestPmService"> <intent-filter> <action android:name="android.content.pm.cts.activity.PMTEST_SERVICE" /> </intent-filter> </service>这一项跟默认语言有关,我的机器是英文下失败,中文下就能Pass
cts-tf > run cts --class android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest 12-13 19:29:41 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a 12-13 19:29:41 I/385b4e4a: Created result dir 2014.12.13_19.29.41 12-13 19:29:52 I/385b4e4a: Collecting device info 12-13 19:29:53 I/385b4e4a: ----------------------------------------- 12-13 19:29:53 I/385b4e4a: Test package android.content started 12-13 19:29:53 I/385b4e4a: ----------------------------------------- 12-13 19:29:55 I/385b4e4a: android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest#testDisplayNameComparator PASS 12-13 19:29:55 I/385b4e4a: android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest#testAndroidTestCaseSetupProperly PASS 12-13 19:29:58 I/385b4e4a: Saved log device_logcat_2031267185637801005.zip 12-13 19:29:58 I/385b4e4a: Saved log host_log_2145996889870614720.zip 12-13 19:29:58 I/385b4e4a: android.content package complete: Passed 2, Failed 0, Not Executed 0 12-13 19:29:58 I/385b4e4a: Created xml report file at file:///home/android-cts-4.4_r3-linux_x86-arm/android-cts/tools/./../../android-cts/repository/results/2014.12.13_19.29.41/testResult.xml 12-13 19:29:58 I/385b4e4a: XML test result file generated at 2014.12.13_19.29.41. Passed 2, Failed 0, Not Executed 0 12-13 19:29:58 I/385b4e4a: Time: 0s