Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: turn off camerax info logs #1325

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ jobs:
- uses: subosito/flutter-action@v2
with:
cache: true
# TODO: move the code to the new tall style once Flutter 3.29 is the new minimum.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting action is using the latest stable Flutter version, 3.29.0.
That opts us into Dart 3.7 which includes new tall-style formatting.

# https://github.com/juliansteenbakker/mobile_scanner/issues/1326
flutter-version: '3.27'
- name: Format
run: dart format --set-exit-if-changed .
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## NEXT

Improvements:
* [Android] Turn off logging for CameraX, except for the `Log.ERROR` logging level.

## 7.0.0-beta.6

**BREAKING CHANGES:**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import android.hardware.display.DisplayManager
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.util.Size
import android.view.Surface
import androidx.annotation.VisibleForTesting
import androidx.camera.camera2.Camera2Config
import androidx.camera.core.Camera
import androidx.camera.core.CameraSelector
import androidx.camera.core.CameraXConfig
import androidx.camera.core.ExperimentalGetImage
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.ImageProxy
Expand All @@ -42,7 +45,6 @@ import dev.steenbakker.mobile_scanner.utils.serialize
import io.flutter.view.TextureRegistry
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import

import kotlinx.coroutines.launch
import java.io.ByteArrayOutputStream
import java.io.IOException
Expand All @@ -58,6 +60,10 @@ class MobileScanner(
private val barcodeScannerFactory: (options: BarcodeScannerOptions?) -> BarcodeScanner = ::defaultBarcodeScannerFactory,
) {

init {
configureCameraProcessProvider()
}

/// Internal variables
private var cameraProvider: ProcessCameraProvider? = null
private var camera: Camera? = null
Expand All @@ -78,6 +84,20 @@ class MobileScanner(
private var isPaused = false

companion object {
// Configure the `ProcessCameraProvider` to only log errors.
// This prevents the informational log spam from CameraX.
private fun configureCameraProcessProvider() {
try {
val config = CameraXConfig.Builder.fromConfig(Camera2Config.defaultConfig()).apply {
Copy link
Collaborator Author

@navaronbracke navaronbracke Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses the default Camera2 config and extends it with the override for logging level.

Per the docs in https://developer.android.com/reference/androidx/camera/lifecycle/ProcessCameraProvider#configureInstance(androidx.camera.core.CameraXConfig)

we can only do this once, though, since it is a singleton.

setMinimumLoggingLevel(Log.ERROR)
}
ProcessCameraProvider.configureInstance(config.build())
} catch (_: IllegalStateException) {
// The ProcessCameraProvider was already configured.
// Do nothing.
}
}

/**
* Create a barcode scanner from the given options.
*/
Expand Down