最近在项目过程,如下fail项
nfcPanel_correctPackage
nfcPanel_doneClosesPanel
记录一下解决思路和过程,首先是配置CTS环境,这个是基础,wwindow/linux 都可以配置,大部分测试都可以在自己的电脑进行,当然有些需要特殊网络环境。
配置环境很重要,解决CTS问题也是一个debug的过程,电脑上没有验证环境,很影响解决问题的效率。
对于CTS问题,电脑上能复现,基本上就解决了一大半,对于一个必现的问题,后面只是时间问题
1.CTS环境配置
CTS环境准备和运行
https://source.android.google.cn/compatibility/cts/setup?hl=zh-cn
https://source.android.google.cn/compatibility/cts/run?hl=zh-cn
环境配置主要是adb/appt/jdk
2.问题分析
找到对应的代码文件,直接在源代码的cts/tests/目录下面用grep命令搜
以nfcPanel_correctPackage为例
@Test
public void nfcPanel_doneClosesPanel() {
// Launch panel
launchNfcPanel();
String currentPackage = mDevice.getCurrentPackageName();
assertThat(currentPackage).isEqualTo(mSettingsPackage);
// Click the done button
pressDone();
// Assert that we have left the panel
currentPackage = mDevice.getCurrentPackageName();
assertThat(currentPackage).isNotEqualTo(mSettingsPackage);
}
代码逻辑比较简单,通过Settings.Panel.ACTION_NFC这个action来启动nfc panel,然后和包名是否是预期的
private void launchNfcPanel() {
assumeTrue(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC));
launchPanel(Settings.Panel.ACTION_NFC);
}
private void launchPanel(String action) {
// Start from the home screen
mDevice.pressHome();
mDevice.wait(Until.hasObject(By.pkg(mLauncherPackage).depth(0)), TIMEOUT);
Intent intent = new Intent(action);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK); // Clear out any previous instances
mContext.startActivity(intent);
// Wait for the app to appear
mDevice.wait(Until.hasObject(By.pkg(mSettingsPackage).depth(0)), TIMEOUT);
}
电脑上也很容易复现,通过
adb shell am start -a android.settings.panel.action.NFC
从AndroidManifest.xml里面可以看出,action启动的是SettingsPanelActivity,加载PanelFragment
mPanel = FeatureFactory.getFactory(activity)
.getPanelFeatureProvider()
.getPanel(activity, panelType, mediaPackageName);
此处启动的是NFC ,对应NfcPanel,控制显示的是在NfcPreferenceController
public int getAvailabilityStatus() {
return mNfcAdapter != null
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
由于之前的定制修改,此处返回了UNSUPPORTED_ON_DEVICE,修改后验证可以pass