Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Ignore type 0 capture fails on Android, and added capture timeout.
  • Loading branch information
BeMacized committed Jan 13, 2021
commit 739645451a69d37566a80188093c165497de7a23
4 changes: 4 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.6+1

* Fixes picture captures causing a crash on some Huawei devices.

## 0.6.6

* Adds auto focus support for Android and iOS implementations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,20 @@ public void onCaptureFailed(
return;
}
String reason;
boolean fatalFailure = false;
switch (failure.getReason()) {
case CaptureFailure.REASON_ERROR:
reason = "An error happened in the framework";
break;
case CaptureFailure.REASON_FLUSHED:
reason = "The capture has failed due to an abortCaptures() call";
fatalFailure = true;
break;
default:
reason = "Unknown reason";
}
pictureCaptureRequest.error("captureFailure", reason, null);
Log.w("Camera", "pictureCaptureCallback.onCaptureFailed(): " + reason);
if (fatalFailure) pictureCaptureRequest.error("captureFailure", reason, null);
}

private void processCapture(CaptureResult result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.flutter.plugins.camera;

import android.os.Handler;
import androidx.annotation.Nullable;
import io.flutter.plugin.common.MethodChannel;

Expand All @@ -19,17 +20,25 @@ enum State {
error,
}

private static final int REQUEST_TIMEOUT = 5000;
private final Handler handler;
private final MethodChannel.Result result;
private State state;

public PictureCaptureRequest(MethodChannel.Result result) {
this.result = result;
state = State.idle;
this.handler = new Handler();
}

public void setState(State state) {
if (isFinished()) throw new IllegalStateException("Request has already been finished");
this.state = state;
if (state != State.idle && state != State.finished && state != State.error) {
this.resetTimeout();
} else {
clearTimeout();
}
}

public State getState() {
Expand All @@ -42,14 +51,33 @@ public boolean isFinished() {

public void finish(String absolutePath) {
if (isFinished()) throw new IllegalStateException("Request has already been finished");
clearTimeout();
result.success(absolutePath);
state = State.finished;
}

public void error(
String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
if (isFinished()) throw new IllegalStateException("Request has already been finished");
clearTimeout();
result.error(errorCode, errorMessage, errorDetails);
state = State.error;
}

private final Runnable timeoutCallback =
new Runnable() {
@Override
public void run() {
error("captureTimeout", "Picture capture request timed out", state.toString());
}
};

private void resetTimeout() {
clearTimeout();
handler.postDelayed(timeoutCallback, REQUEST_TIMEOUT);
}

private void clearTimeout() {
handler.removeCallbacks(timeoutCallback);
}
}
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera
description: A Flutter plugin for getting information about and controlling the
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
and streaming image buffers to dart.
version: 0.6.6
version: 0.6.6+1
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera

dependencies:
Expand Down