Android4.4 CTS测试Fail项修改总结(一)

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
如果需要验证可以手动打开

Android4.4 CTS测试Fail项修改总结(一)_第1张图片

2、测试android.webkit.cts.GeolocationTest Fail

cts-tf > run cts --class android.webkit.cts.GeolocationTest
12-13 20:00:44 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a
12-13 20:00:44 I/385b4e4a: Created result dir 2014.12.13_20.00.44
12-13 20:00:54 I/385b4e4a: Collecting device info
12-13 20:00:55 I/385b4e4a: -----------------------------------------
12-13 20:00:55 I/385b4e4a: Test package android.webkit started
12-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 position
at 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 position
at 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.zip
12-13 20:03:09 I/385b4e4a: Saved log host_log_5151173227187455527.zip
12-13 20:03:09 I/385b4e4a: android.webkit package complete: Passed 2, Failed 2, Not Executed 0
12-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.xml
12-13 20:03:09 I/385b4e4a: XML test result file generated at 2014.12.13_20.00.44. Passed 2, Failed 2, Not Executed 0
12-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.GeolocationTest
12-13 20:37:39 I/TestInvocation: Starting invocation for 'cts' on build '4.4_r3' on device 385b4e4a
12-13 20:37:39 I/385b4e4a: Created result dir 2014.12.13_20.37.39
12-13 20:37:52 I/385b4e4a: Collecting device info
12-13 20:37:53 I/385b4e4a: -----------------------------------------
12-13 20:37:53 I/385b4e4a: Test package android.webkit started
12-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.zip
12-13 20:38:03 I/385b4e4a: Saved log host_log_8685761807888118162.zip
12-13 20:38:03 I/385b4e4a: android.webkit package complete: Passed 4, Failed 0, Not Executed 0
12-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.xml
12-13 20:38:03 I/385b4e4a: XML test result file generated at 2014.12.13_20.37.39. Passed 4, Failed 0, Not Executed 0
12-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_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

分析结果:是由于机器上预装了iReader V3.5.1,其它平台上安装的V3.2.0没有问题,是因为V3.5.1上添加了“支付宝快捷支付服务”,但又没有进行字符串的国际化,导致获取的Lable比较出现的问题,前面提到的在中文下Pass是因为只有中文的字符串没有英文的,只需要iReader添加英文的就OK,也不清楚为什么iReader团队当时这点事也省了;


你可能感兴趣的:(android,fail,cts,gms)