Initialize CameraX on a background thread.
We saw a situation where CameraX initialization could lock up when trying to obtain system resource. We already fallback to the Camera1Fragment when CameraX isn't initialized, so it should be safe to do this initialization on its own thread.
This commit is contained in:
parent
709ce7e9de
commit
c5767b07a7
1 changed files with 7 additions and 5 deletions
|
@ -386,11 +386,13 @@ public class ApplicationContext extends MultiDexApplication implements DefaultLi
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
private void initializeCameraX() {
|
private void initializeCameraX() {
|
||||||
if (Build.VERSION.SDK_INT >= 21) {
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
try {
|
new Thread(() -> {
|
||||||
CameraX.init(this, Camera2AppConfig.create(this));
|
try {
|
||||||
} catch (Throwable t) {
|
CameraX.init(this, Camera2AppConfig.create(this));
|
||||||
Log.w(TAG, "Failed to initialize CameraX.");
|
} catch (Throwable t) {
|
||||||
}
|
Log.w(TAG, "Failed to initialize CameraX.");
|
||||||
|
}
|
||||||
|
}, "signal-camerax-initialization").start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue