[CTS10R3] CtsProviderUiTestCases fail

问题描述

CtsProviderUiTestCases
android.providerui.cts.MediaStoreUiTest#testImageCaptureWithInadequeteLocationPermissions[0]
android.providerui.cts.MediaStoreUiTest#testGetDocumentUri[0]
android.providerui.cts.MediaStoreUiTest#testGetDocumentUri_ThrowsWithoutPermission[0]
android.providerui.cts.MediaStoreUiTest#testGetDocumentUri_Symmetry[0]
Fail:
java.lang.AssertionError: Expected to get a IMAGE_CAPTURE result; your camera app should respond to the CAMERA and DPAD_CENTER keycodes

解决方案

 
原因是Google Android 10 上新增了testcase,以下是相关change 信息

Make testImageCaptureWithInadequeteLocationPermissions check ACTION_IMAGE_CAPTURE_SECURE also.

Bug: 142412890

Test: atest

MediaStoreUiTest.java#testImageCaptureWithInadequeteLocationPermissions

Merged-In: I21f3d910d58a17c4db6f048f0eefc10fe63b6c6a

Change-Id: I21f3d910d58a17c4db6f048f0eefc10fe63b6c6a

Signed-off-by: Jayant Chowdhary <jchowdhary@google.com> (cherry picked from commit 53a52c3d805d93b4807421fb3480548212afa48e) 

 相关代码

xref/cts/tests/providerui/src/android/providerui/cts/MediaStoreUiTest.java

236      /**

237       * Verify that whoever handles {@link MediaStore#ACTION_IMAGE_CAPTURE} can
238       * correctly write the contents into a passed {@code content://} Uri.
239       */
240      @Test
241      public void testImageCaptureWithInadequeteLocationPermissions() throws Exception {
242          Set<String> perms = new HashSet<>();
243          perms.add(ACCESS_COARSE_LOCATION);
244          perms.add(ACCESS_BACKGROUND_LOCATION);
245          perms.add(ACCESS_MEDIA_LOCATION);
246          testImageCaptureWithoutLocation(perms, MediaStore.ACTION_IMAGE_CAPTURE);
247          testImageCaptureWithoutLocation(perms, MediaStore.ACTION_IMAGE_CAPTURE_SECURE);
248      }

249       /**

250       * Helper function to verify that whoever handles {@link MediaStore#ACTION_IMAGE_CAPTURE} can

251       * correctly write the contents into a passed {@code content://} Uri, without location
252       * information, necessarily, when ACCESS_FINE_LOCATION permissions aren't given.
253       */
254      private void testImageCaptureWithoutLocation(Set<String> locationPermissions, String intentStr)
255              throws Exception {
256          assertFalse("testImageCaptureWithoutLocation should not be passed ACCESS_FINE_LOCATION",
257                  locationPermissions.contains(ACCESS_FINE_LOCATION));
258          if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
259              Log.d(TAG, "Skipping due to lack of camera");
260              return;
261          }
262
263          String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
264
265          final File targetDir = new File(mContext.getFilesDir(), "debug");
266          final File target = new File(targetDir, timeStamp  + "capture.jpg");
267
268          targetDir.mkdirs();
269          assertFalse(target.exists());
270
271          final Intent intent = new Intent(intentStr);
272          intent.putExtra(MediaStore.EXTRA_OUTPUT,
273                  FileProvider.getUriForFile(mContext, "android.providerui.cts.fileprovider", target));
274
275          // Figure out who is going to answer the phone
276          final ResolveInfo ri = mContext.getPackageManager().resolveActivity(intent, 0);
277          final String answeringPkg = ri.activityInfo.packageName;
278          Log.d(TAG, "We're probably launching " + ri);
279
280          final PackageInfo pi = mContext.getPackageManager().getPackageInfo(answeringPkg,
281                  PackageManager.GET_PERMISSIONS);
282          final Set<String> answeringReq = new HashSet<>();
283          answeringReq.addAll(Arrays.asList(pi.requestedPermissions));
284          // Grant the 'answering' app all the permissions they might want.
285          maybeGrantRuntimePermission(answeringPkg, answeringReq, CAMERA);
286          maybeGrantRuntimePermission(answeringPkg, answeringReq, ACCESS_FINE_LOCATION);
287          maybeGrantRuntimePermission(answeringPkg, answeringReq, ACCESS_COARSE_LOCATION);
288          maybeGrantRuntimePermission(answeringPkg, answeringReq, ACCESS_BACKGROUND_LOCATION);
289          maybeGrantRuntimePermission(answeringPkg, answeringReq, RECORD_AUDIO);
290          maybeGrantRuntimePermission(answeringPkg, answeringReq, READ_EXTERNAL_STORAGE);
291          maybeGrantRuntimePermission(answeringPkg, answeringReq, WRITE_EXTERNAL_STORAGE);
292          SystemClock.sleep(DateUtils.SECOND_IN_MILLIS);
293
294          grantSelfRequisitePermissions(locationPermissions);
295
296          Result result = getImageCaptureIntentResult(intent, answeringPkg);
297
298          assertTrue("exists", target.exists());
299          assertTrue("has data", target.length() > 65536);
300
301          // At the very least we expect photos generated by the device to have
302          // sane baseline EXIF data
303          final ExifInterface exif = new ExifInterface(new FileInputStream(target));
304          assertAttribute(exif, ExifInterface.TAG_MAKE);
305          assertAttribute(exif, ExifInterface.TAG_MODEL);
306          assertAttribute(exif, ExifInterface.TAG_DATETIME);
307          float[] latLong = new float[2];
308          Boolean hasLocation = exif.getLatLong(latLong);
309          assertTrue("Should not contain location information latitude: " + latLong[0] +
310                  " longitude: " + latLong[1], !hasLocation);
311      }

Case 的流程是TC 会有一个GetResultActivity ,以这个Activity 来起intent 拍照,intent 里面包含有一个uriapp 拍完照片之后将照片保存到这个uri 指定的图片上,TC 拿到这个uri 指向的图片,检查exif 是否包含location。如果包含location case 就会fail

注意事项:

1.注意296 行的地方getResults null 会报fail,常见的原因是GetResultActivityIntent Camera,Camera 拍照完成之后没有setResults ,对于mtk camera 来说就是起Intent MediaStore.CAPTURE_IMAGE_SECURE,之后 没有使用IntentPhotoMode 来做拍照和保存,可以在ModeManager 里面查看到相关的log

2.另外 310 行的地方检查 exif 信息如果包含location 也会fail,需要修改的地方是,如果MediaStore.CAPTURE_IMAGE_SECURE 拍照,并且没有ACCESS_FINE_LOCATION permission,不能往CaptureRequest.Builder 里面builder.set(CaptureRequest.JPEG_GPS_LOCATION, mICameraContext.getLocation());

mtk camera 请参照 以上注意事项修改

mtk camera 请客户申请patchALPS05016434

如何确定是否是mtk camera ?

[Answer]可以在cts logs 目录下查看device_logcat_test 文件,搜索关键字CameraService ,如果包含包名com.mediatek.camera”,则是mtkcamera

例如:02-12 15:01:14.449888   677 22643 I CameraService: CameraService::connect call (PID -1 "com.mediatek.camera", camera ID 1) for HAL version default and Camera API version 2

微信扫码打赏

作者: RESSRC

个人资源站

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据