androidandroid-cameraandroid-7.1-nougat

Camera.open() gets "Access for <package> has been restricted"


Yet when trying Camera.open(i) for checking camera properties I get

I/CameraService: Camera 0: Access for "package" has been restricted

Apparently this could only happen [1] if application's package or uId has been explicitly restricted from starting AppOpsManager#OP_CAMERA. But why would this happen? After AppOpsManager#checkOp says AppOpsManager#MODE_ALLOWED

Sample code

for (int i = 0; i < numCameras; ++i) {
    List<Size> supportedSizes = null;
    List<int[]> supportedFpsRanges = null;
    Camera camera = null;
    try {
        camera = Camera.open(i);
        Parameters parameters = camera.getParameters();
        supportedSizes = parameters.getSupportedPreviewSizes();
        supportedFpsRanges = getFpsRangesRobust(parameters);
    } catch (Exception e) {
        ...
    } finally {
        if (camera != null) {
            camera.release();
        }
    }

[1] https://github.com/aosp-mirror/platform_frameworks_base/blob/oreo-mr1-release/services/core/java/com/android/server/AppOpsService.java#L2588


Solution

  • Aparently it's a device issue. Nokia 6 / TA-1000, Android 7.1.1

    The scenario

    Is reproducible with any other application, including the default camera app.