Skip to content

Commit d26d49f

Browse files
Merge pull request #637 from TakayukiHoshi1984/bugfix_android_10_camera
Android10でのCamera周りの挙動修正
2 parents ce3c1bb + 40b8e67 commit d26d49f

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.media.ImageReader;
2424
import android.os.Handler;
2525
import android.os.HandlerThread;
26+
import android.os.Looper;
2627
import android.support.annotation.NonNull;
2728
import android.support.annotation.Nullable;
2829
import android.util.Log;
@@ -79,8 +80,6 @@ void notifyEvent(final CameraEvent event) {
7980

8081
private final CameraManager mCameraManager;
8182

82-
private final HandlerThread mBackgroundThread = new HandlerThread("background");
83-
8483
private final HandlerThread mSessionConfigurationThread = new HandlerThread("session-config");
8584

8685
private final Handler mBackgroundHandler;
@@ -123,8 +122,7 @@ void notifyEvent(final CameraEvent event) {
123122
final @NonNull String cameraId) throws CameraAccessException {
124123
mCameraId = cameraId;
125124
mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
126-
mBackgroundThread.start();
127-
mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
125+
mBackgroundHandler = new Handler(Looper.getMainLooper());
128126
mSessionConfigurationThread.start();
129127
mSessionConfigurationHandler = new Handler(mSessionConfigurationThread.getLooper());
130128
mOptions = initOptions();
@@ -189,7 +187,6 @@ public boolean isRecording() {
189187

190188
public synchronized void destroy() {
191189
close();
192-
mBackgroundThread.quit();
193190
mSessionConfigurationThread.quit();
194191
}
195192

@@ -691,7 +688,8 @@ private void onCaptureResult(final CaptureResult result, final boolean isComplet
691688
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
692689
mIsAeReady = aeState == null
693690
|| aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED
694-
|| aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED;
691+
|| aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED
692+
|| aeState == CaptureRequest.CONTROL_AE_STATE_PRECAPTURE;
695693
}
696694
mIsCaptureReady |= isCompleted;
697695
if (DEBUG) {

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.util.List;
5656
import java.util.Locale;
5757

58+
5859
public class Camera2Recorder extends AbstractCamera2Recorder implements HostDevicePhotoRecorder, HostDeviceStreamRecorder {
5960

6061
/**
@@ -532,18 +533,15 @@ private void registerVideo(final File videoFile) {
532533
values.put(MediaStore.Video.Media.ARTIST, "DeviceConnect");
533534
values.put(MediaStore.Video.Media.MIME_TYPE, "video/avc");
534535
values.put(MediaStore.Video.Media.DATA, videoFile.toString());
535-
long thumbnailId = registerVideoThumbnail(videoFile);
536-
if (thumbnailId > -1) {
537-
values.put(MediaStore.Video.Media.MINI_THUMB_MAGIC, thumbnailId);
538-
}
539536
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
540537

541538
// 動画IDをサムネイルDBに挿入.
542539
try {
543-
if (uri != null && thumbnailId > -1) {
540+
if (uri != null) {
544541
String id = uri.getLastPathSegment();
545542
if (id != null) {
546543
long videoId = Long.parseLong(id);
544+
long thumbnailId = registerVideoThumbnail(videoFile, videoId);
547545
boolean updated = updateThumbnailInfo(thumbnailId, videoId);
548546
if (updated) {
549547
if (DEBUG) {
@@ -569,7 +567,7 @@ private void registerVideo(final File videoFile) {
569567
}
570568
}
571569

572-
private long registerVideoThumbnail(final File videoFile) {
570+
private long registerVideoThumbnail(final File videoFile, final long videoId) {
573571
String videoFilePath = videoFile.getAbsolutePath();
574572
final int kind = MediaStore.Images.Thumbnails.MINI_KIND;
575573
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(videoFilePath, kind);
@@ -588,6 +586,7 @@ private long registerVideoThumbnail(final File videoFile) {
588586
values.put(MediaStore.Video.Thumbnails.WIDTH, thumbnail.getWidth());
589587
values.put(MediaStore.Video.Thumbnails.HEIGHT, thumbnail.getHeight());
590588
values.put(MediaStore.Video.Thumbnails.KIND, kind);
589+
values.put(MediaStore.Video.Thumbnails.VIDEO_ID, videoId);
591590
ContentResolver resolver = getContext().getApplicationContext().getContentResolver();
592591
Uri uri = resolver.insert(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, values);
593592
if (uri == null) {

0 commit comments

Comments
 (0)