-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
*/ | ||
|
There was a problem hiding this comment.
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.