如何跳过ITS测试

测试步骤

CTS Verifier --> CAMERA --> Camera ITS Test

什么是Camera ITS test?

Android Camera Image Test Suite (ITS) is part of Android Compatibility Test Suite (CTS) Verifier and includes tests that verify image content. As of CTS 7.0_r8, CTS Verifier supports ITS test automation via Camera ITS-in-a-box; support for manual tests continues to ensure coverage for all Android device form factors.

ITS就是几条关于camera的测试项,属于CTS-v里的有项。
ITS里总共包括几条测试项,这些测试项测试的难度较大,花费时间较长,过的概率低,所以一般都会要求跳过。

进入ITS的关键代码

xref/cts/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsTestActivity.java

 protected void onCreate(Bundle savedInstanceState) {
332          // Hide the test if all camera devices are legacy
333          CameraManager manager = (CameraManager) this.getSystemService(Context.CAMERA_SERVICE);
334          try {
335              String[] cameraIds = manager.getCameraIdList();
336              mToBeTestedCameraIds = new ArrayList<String>();
337              for (String id : cameraIds) {
338                  CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);
339                  int hwLevel = characteristics.get(
340                          CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
341                  if (hwLevel
342                          != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY &&
343                          hwLevel
344                          != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL) {
345                      mToBeTestedCameraIds.add(id);
346                  }
347              }
348              if (mToBeTestedCameraIds.size() == 0) {
349                  showToast(R.string.all_legacy_devices);
350                  ItsTestActivity.this.getReportLog().setSummary(
351                          "PASS: all cameras on this device are LEGACY or EXTERNAL"
352                          , 1.0, ResultType.NEUTRAL, ResultUnit.NONE);
353                  setTestResultAndFinish(true);
354              }
355          } catch (CameraAccessException e) {
356              Toast.makeText(ItsTestActivity.this,
357                      "Received error from camera service while checking device capabilities: "
358                              + e, Toast.LENGTH_SHORT).show();
359          }
360  
361          super.onCreate(savedInstanceState);
362          getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
363      }  

看351行的描述,当设备上所有的camera是LEGACY or EXTERNAL时,PASS。
判断条件是mToBeTestedCameraIds.size() == 0,
看337~346行的代码得知,关键方法是getCameraCharacteristics()。我们需要从该方法得到不一样的返回值,即camera都是LEGACY or EXTERNAL的。

接下来看该方法的源码:
xref/frameworks/base/core/java/android/hardware/camera2/CameraManager.java

3      @NonNull
264      public CameraCharacteristics getCameraCharacteristics(@NonNull String cameraId)
265              throws CameraAccessException {
266          CameraCharacteristics characteristics = null;
267          if (CameraManagerGlobal.sCameraServiceDisabled) {
268              throw new IllegalArgumentException("No cameras available on device");
269          }
270          synchronized (mLock) {
271              /*
272               * Get the camera characteristics from the camera service directly if it supports it,
273               * otherwise get them from the legacy shim instead.
274               */
275              ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
276              if (cameraService == null) {
277                  throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,
278                          "Camera service is currently unavailable");
279              }
280              try {
281                  if (!supportsCamera2ApiLocked(cameraId)) {
282                      // Legacy backwards compatibility path; build static info from the camera
283                      // parameters
284                      int id = Integer.parseInt(cameraId);
285  
286                      String parameters = cameraService.getLegacyParameters(id);
287  
288                      CameraInfo info = cameraService.getCameraInfo(id);
289  
290                      characteristics = LegacyMetadataMapper.createCharacteristics(parameters, info);
291                  } else {
292                      // Normal path: Get the camera characteristics directly from the camera service
293                      CameraMetadataNative info = cameraService.getCameraCharacteristics(cameraId);
294  
295                      characteristics = new CameraCharacteristics(info);
296                  }
297              } catch (ServiceSpecificException e) {
298                  throwAsPublicException(e);
299              } catch (RemoteException e) {
300                  // Camera service died - act as if the camera was disconnected
301                  throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,
302                          "Camera service is currently unavailable", e);
303              }
304          }
305          return characteristics;
306      }

关键代码在281行的supportsCamera2ApiLocked():

     private boolean supportsCameraApiLocked(String cameraId, int apiVersion) {
780          /*
781           * Possible return values:
782           * - NO_ERROR => CameraX API is supported
783           * - CAMERA_DEPRECATED_HAL => CameraX API is *not* supported (thrown as an exception)
784           * - Remote exception => If the camera service died
785           *
786           * Anything else is an unexpected error we don't want to recover from.
787           */
788          try {
789              ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
790              // If no camera service, no support
791              if (cameraService == null) return false;
792  
793              return cameraService.supportsCameraApi(cameraId, apiVersion);
794          } catch (RemoteException e) {
795              // Camera service is now down, no support for any API level
796          }
797          return false;
798      }
748      private boolean supportsCamera2ApiLocked(String cameraId) {
749          return supportsCameraApiLocked(cameraId, API_VERSION_2);
750      }
52      /**
753       * Queries the camera service if it supports a camera api directly, or needs a shim.
754       *
755       * @param cameraId a non-{@code null} camera identifier
756       * @param apiVersion the version, i.e. {@code API_VERSION_1} or {@code API_VERSION_2}
757       * @return {@code true} if connecting will work for that device version.
758       */
759      private boolean supportsCameraApiLocked(String cameraId, int apiVersion) {
760          /*
761           * Possible return values:
762           * - NO_ERROR => CameraX API is supported
763           * - CAMERA_DEPRECATED_HAL => CameraX API is *not* supported (thrown as an exception)
764           * - Remote exception => If the camera service died
765           *
766           * Anything else is an unexpected error we don't want to recover from.
767           */
768          try {
769              ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
770              // If no camera service, no support
771              if (cameraService == null) return false;
772  
773              return cameraService.supportsCameraApi(cameraId, apiVersion);
774          } catch (RemoteException e) {
775              // Camera service is now down, no support for any API level
776          }
777          return false;
778      }

代码看到这儿就不用继续往下跟了。

跳过ITS 的代码修改

在前面这些代码中的任意一个方法中加上条件判断都行,只是看哪里更简单方便。建议加在supportsCamera2ApiLocked()中,如下所示:

      private boolean supportsCamera2ApiLocked(String cameraId) {
          String className = getTopAppClassName();
          if(className != null && className.equals("com.android.cts.verifier.camera.its.ItsTestActivity"))
              return false;
          else
              return supportsCameraApiLocked(cameraId, API_VERSION_2);
      }
     private String getTopAppClassName() {
          String className = "";
          try {
              final ActivityManager mActivityManager = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
              List<ActivityManager.RunningTaskInfo> rti = mActivityManager.getRunningTasks(1);
              className = rti.get(0).topActivity.getClassName();
          }catch (Exception ignored){
          }
          return className;
      }

说明

这样改很明显就是一种规避手段。
但是这样改简单可行,测试报告与正常测过相同,且不影响其它测试。
目前很多项目都是这样做的。

ref

https://source.android.com/compatibility/cts/camera-its-box

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,864评论 6 494
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,175评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,401评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,170评论 1 286
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,276评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,364评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,401评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,179评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,604评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,902评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,070评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,751评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,380评论 3 319
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,077评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,312评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,924评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,957评论 2 351