Android4.4 CTS測試Fail項修改總結(一),android4.4cts
1、測試android.webkit.cts.GeolocationTest Fail
提示:
cts-tf > run cts --class android.webkit.cts.GeolocationTest12-13 16:55:23 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a12-13 16:55:23 I/385b4e4a: Created result dir 2014.12.13_16.55.2312-13 16:55:34 I/385b4e4a: Collecting device info12-13 16:55:35 I/385b4e4a: -----------------------------------------12-13 16:55:35 I/385b4e4a: Test package android.webkit started12-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 settingat 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 := truetags_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=0else # !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=1endif # !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.webkit.cts.GeolocationTest Fail
cts-tf > run cts --class android.webkit.cts.GeolocationTest12-13 20:00:44 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a12-13 20:00:44 I/385b4e4a: Created result dir 2014.12.13_20.00.4412-13 20:00:54 I/385b4e4a: Collecting device info12-13 20:00:55 I/385b4e4a: -----------------------------------------12-13 20:00:55 I/385b4e4a: Test package android.webkit started12-13 20:00:55 I/385b4e4a: -----------------------------------------12-13 20:00:58 I/385b4e4a: android.webkit.cts.GeolocationTest#testGeolocationPermissions PASS 12-13 20:01:59 I/385b4e4a: android.webkit.cts.GeolocationTest#testSimpleGeolocationRequestAcceptAlways FAIL junit.framework.AssertionFailedError: JS didn't get positionat android.cts.util.PollingCheck.check(PollingCheck.java:70)at android.webkit.cts.GeolocationTest.testSimpleGeolocationRequestAcceptAlways(GeolocationTest.java:389)at java.lang.reflect.Method.invokeNative(Native Method)at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)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 20:03:00 I/385b4e4a: android.webkit.cts.GeolocationTest#testSimpleGeolocationRequestAcceptOnce FAIL junit.framework.AssertionFailedError: JS didn't get positionat android.cts.util.PollingCheck.check(PollingCheck.java:70)at android.webkit.cts.GeolocationTest.testSimpleGeolocationRequestAcceptOnce(GeolocationTest.java:298)at java.lang.reflect.Method.invokeNative(Native Method)at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)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 20:03:01 I/385b4e4a: android.webkit.cts.GeolocationTest#testSimpleGeolocationRequestReject PASS 12-13 20:03:07 I/385b4e4a: Saved log device_logcat_2697676003348178928.zip12-13 20:03:09 I/385b4e4a: Saved log host_log_5151173227187455527.zip12-13 20:03:09 I/385b4e4a: android.webkit package complete: Passed 2, Failed 2, Not Executed 012-13 20:03:09 I/385b4e4a: Created xml report file at file:///home/dzt/D/dzt/xxxxxxxxx/xuna/android-cts-4.4_r3-linux_x86-arm/android-cts/tools/./../../android-cts/repository/results/2014.12.13_20.00.44/testResult.xml12-13 20:03:09 I/385b4e4a: XML test result file generated at 2014.12.13_20.00.44. Passed 2, Failed 2, Not Executed 012-13 20:03:09 I/385b4e4a: Time: 0s
是由於《Settings》->《Location access》沒有開啟,開啟後Mode需要選擇High accuracy,如果在室外可以選擇Device only,室內有網路的情況下可以選擇Battery saving,但High accuracy是最全面的。
可以修改/frameworks/base/packages/SettingsProvider/res/values/defaults.xml這個檔案
<bool name="def_bluetooth_on">false</bool> <bool name="def_wifi_display_on">false</bool> <bool name="def_install_non_market_apps">false</bool> <bool name="def_package_verifier_enable">true</bool> <!-- Comma-separated list of location providers. Network location is off by default because it requires user opt-in via Setup Wizard or Settings. --> <!-- 20141213 modify start --> <string name="def_location_providers_allowed" translatable="false">network</string> <!-- 20141213 modify end --> <bool name="assisted_gps_enabled">true</bool> <bool name="def_netstats_enabled">true</bool> <bool name="def_usb_mass_storage_enabled">true</bool>
def_location_providers_allowed可以設定為以下值
<string name="def_location_providers_allowed" translatable="false">network</string>
<string name="def_location_providers_allowed" translatable="false">gps</string>
<string name="def_location_providers_allowed" translatable="false">gps,network</string>
<string name="def_location_providers_allowed" translatable="false"></string>
再測試
cts-tf > run cts --class android.webkit.cts.GeolocationTest12-13 20:37:39 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a12-13 20:37:39 I/385b4e4a: Created result dir 2014.12.13_20.37.3912-13 20:37:52 I/385b4e4a: Collecting device info12-13 20:37:53 I/385b4e4a: -----------------------------------------12-13 20:37:53 I/385b4e4a: Test package android.webkit started12-13 20:37:53 I/385b4e4a: -----------------------------------------12-13 20:37:57 I/385b4e4a: android.webkit.cts.GeolocationTest#testGeolocationPermissions PASS 12-13 20:37:58 I/385b4e4a: android.webkit.cts.GeolocationTest#testSimpleGeolocationRequestAcceptAlways PASS 12-13 20:37:59 I/385b4e4a: android.webkit.cts.GeolocationTest#testSimpleGeolocationRequestAcceptOnce PASS 12-13 20:38:00 I/385b4e4a: android.webkit.cts.GeolocationTest#testSimpleGeolocationRequestReject PASS 12-13 20:38:03 I/385b4e4a: Saved log device_logcat_3654799606164162994.zip12-13 20:38:03 I/385b4e4a: Saved log host_log_8685761807888118162.zip12-13 20:38:03 I/385b4e4a: android.webkit package complete: Passed 4, Failed 0, Not Executed 012-13 20:38:03 I/385b4e4a: Created xml report file at file:///home/dzt/D/dzt/xxxxxxxxx/xuna/android-cts-4.4_r3-linux_x86-arm/android-cts/tools/./../../android-cts/repository/results/2014.12.13_20.37.39/testResult.xml12-13 20:38:03 I/385b4e4a: XML test result file generated at 2014.12.13_20.37.39. Passed 4, Failed 0, Not Executed 012-13 20:38:03 I/385b4e4a: Time: 0s
3、測試android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest FAIL
cts-tf > run cts --class android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest12-13 18:55:28 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a12-13 18:55:28 I/385b4e4a: Created result dir 2014.12.13_18.55.2812-13 18:55:40 I/385b4e4a: Collecting device info12-13 18:55:41 I/385b4e4a: -----------------------------------------12-13 18:55:41 I/385b4e4a: Test package android.content started12-13 18:55:41 I/385b4e4a: -----------------------------------------12-13 18:55:43 I/385b4e4a: android.content.pm.cts.ResolveInfo_DisplayNameComparatorTest#testDisplayNameComparator FAIL junit.framework.AssertionFailedErrorat 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.zip12-13 18:55:47 I/385b4e4a: Saved log host_log_6056597035559363496.zip12-13 18:55:47 I/385b4e4a: android.content package complete: Passed 1, Failed 1, Not Executed 012-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.xml12-13 18:55:47 I/385b4e4a: XML test result file generated at 2014.12.13_18.55.28. Passed 1, Failed 1, Not Executed 012-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_DisplayNameComparatorTest12-13 19:29:41 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a12-13 19:29:41 I/385b4e4a: Created result dir 2014.12.13_19.29.4112-13 19:29:52 I/385b4e4a: Collecting device info12-13 19:29:53 I/385b4e4a: -----------------------------------------12-13 19:29:53 I/385b4e4a: Test package android.content started12-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.zip12-13 19:29:58 I/385b4e4a: Saved log host_log_2145996889870614720.zip12-13 19:29:58 I/385b4e4a: android.content package complete: Passed 2, Failed 0, Not Executed 012-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.xml12-13 19:29:58 I/385b4e4a: XML test result file generated at 2014.12.13_19.29.41. Passed 2, Failed 0, Not Executed 012-13 19:29:58 I/385b4e4a: Time: 0s