summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2021-10-06 22:53:50 +0000
committerXin Li <delphij@google.com>2021-10-06 22:53:50 +0000
commitef22a9dc17b2b413ad5f1d9a2dd939de9b33d8e3 (patch)
tree2931fedfdc6caf679715521c2bbfae56c7e2ccfc
parent23edee830b627c383f6e569aad355a6f783e6264 (diff)
parentefe4290d06cb617b10443795b139add12376011c (diff)
downloadCamera2-ef22a9dc17b2b413ad5f1d9a2dd939de9b33d8e3.tar.gz
Merge Android 12
Bug: 202323961 Merged-In: I950f219dbcb4e125e2eb29d5311241601a673f79 Change-Id: Ib24491911415e448235b7a2ecfefcddf6990c086
-rw-r--r--src/com/android/camera/CaptureModule.java6
-rw-r--r--src/com/android/camera/CaptureModuleUI.java7
-rw-r--r--src/com/android/camera/CaptureModuleUtil.java19
-rw-r--r--src/com/android/camera/PhotoModule.java8
-rw-r--r--src/com/android/camera/TextureViewHelper.java5
-rw-r--r--src/com/android/camera/VideoModule.java12
-rw-r--r--src/com/android/camera/app/CameraAppUI.java5
-rw-r--r--src/com/android/camera/app/OrientationManagerImpl.java6
-rw-r--r--src/com/android/camera/one/OneCamera.java6
-rw-r--r--src/com/android/camera/one/v2/OneCameraImpl.java6
-rw-r--r--src/com/android/camera/one/v2/OneCameraZslImpl.java6
-rw-r--r--src/com/android/camera/one/v2/autofocus/ManualAutoFocusFactory.java27
-rw-r--r--src/com/android/camera/one/v2/commands/UpdateRequestCommand.java76
-rw-r--r--src/com/android/camera/one/v2/common/BasicCameraFactory.java3
-rw-r--r--src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java4
-rw-r--r--src/com/android/camera/settings/ResolutionUtil.java10
-rw-r--r--src/com/android/camera/ui/MainActivityLayout.java6
-rw-r--r--src/com/android/camera/util/AndroidServices.java14
-rw-r--r--src/com/android/camera/util/CameraUtil.java27
19 files changed, 184 insertions, 69 deletions
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index 00a58cd3c..1068bcf52 100644
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -411,7 +411,7 @@ public class CaptureModule extends CameraModule implements
} catch (OneCameraException e) {
Log.e(TAG, "Unable to provide a OneCameraManager. ", e);
}
- mDisplayRotation = CameraUtil.getDisplayRotation();
+ mDisplayRotation = CameraUtil.getDisplayRotation(activity);
mCameraFacing = getFacingFromCameraId(
mSettingsManager.getInteger(mAppController.getModuleScope(), Keys.KEY_CAMERA_ID));
mShowErrorAndFinish = !updateCameraCharacteristics();
@@ -1218,7 +1218,7 @@ public class CaptureModule extends CameraModule implements
Log.d(TAG, "updatePreviewTransform: " + incomingWidth + " x " + incomingHeight);
synchronized (mDimensionLock) {
- int incomingRotation = CameraUtil.getDisplayRotation();
+ int incomingRotation = CameraUtil.getDisplayRotation(mUI.getActivity());
// Check for an actual change:
if (mScreenHeight == incomingHeight && mScreenWidth == incomingWidth &&
incomingRotation == mDisplayRotation && !forceUpdate) {
@@ -1293,7 +1293,7 @@ public class CaptureModule extends CameraModule implements
return;
}
- Size previewBufferSize = mCamera.pickPreviewSize(mPictureSize, mContext);
+ Size previewBufferSize = mCamera.pickPreviewSize(mPictureSize, mUI.getActivity());
mPreviewBufferWidth = previewBufferSize.getWidth();
mPreviewBufferHeight = previewBufferSize.getHeight();
diff --git a/src/com/android/camera/CaptureModuleUI.java b/src/com/android/camera/CaptureModuleUI.java
index cbf19325e..c9a1c6ea9 100644
--- a/src/com/android/camera/CaptureModuleUI.java
+++ b/src/com/android/camera/CaptureModuleUI.java
@@ -94,6 +94,13 @@ public class CaptureModuleUI implements PreviewStatusListener.PreviewAreaChanged
}
/**
+ * Getter for the camera activity this UI is drawn into
+ */
+ public CameraActivity getActivity() {
+ return mActivity;
+ }
+
+ /**
* Getter for the width of the visible area of the preview.
*/
public int getPreviewAreaWidth() {
diff --git a/src/com/android/camera/CaptureModuleUtil.java b/src/com/android/camera/CaptureModuleUtil.java
index 6074dc9e1..d2808abcf 100644
--- a/src/com/android/camera/CaptureModuleUtil.java
+++ b/src/com/android/camera/CaptureModuleUtil.java
@@ -16,6 +16,7 @@
package com.android.camera;
+import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.view.Surface;
@@ -33,9 +34,9 @@ import java.util.ArrayList;
public class CaptureModuleUtil {
private static final Tag TAG = new Tag("CaptureModuleUtil");
- public static int getDeviceNaturalOrientation(Context context) {
+ public static int getDeviceNaturalOrientation(Activity context) {
Configuration config = context.getResources().getConfiguration();
- int rotation = CameraUtil.getDisplayRotation();
+ int rotation = CameraUtil.getDisplayRotation(context);
if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) &&
config.orientation == Configuration.ORIENTATION_LANDSCAPE) ||
@@ -52,8 +53,8 @@ public class CaptureModuleUtil {
* {@link CameraUtil#getOptimalPreviewSize(java.util.List, double)}
* method for the camera1 api.
*/
- public static Size getOptimalPreviewSize(Size[] sizes,double targetRatio) {
- return getOptimalPreviewSize(sizes, targetRatio, null);
+ public static Size getOptimalPreviewSize(Size[] sizes, double targetRatio, Activity context) {
+ return getOptimalPreviewSize(sizes, targetRatio, null, context);
}
/**
@@ -63,7 +64,7 @@ public class CaptureModuleUtil {
* tolerance. If tolerance is 'null', a default tolerance will be used.
*/
public static Size getOptimalPreviewSize(Size[] sizes,
- double targetRatio, Double aspectRatioTolerance) {
+ double targetRatio, Double aspectRatioTolerance, Activity context) {
// TODO(andyhuibers): Don't hardcode this but use device's measurements.
final int MAX_ASPECT_HEIGHT = 1080;
@@ -85,7 +86,7 @@ public class CaptureModuleUtil {
int optimalIndex = CameraUtil
.getOptimalPreviewSizeIndex(camera1Sizes, targetRatio,
- aspectRatioTolerance);
+ aspectRatioTolerance, context);
if (optimalIndex == -1) {
return null;
@@ -106,9 +107,9 @@ public class CaptureModuleUtil {
*/
public static Size pickBufferDimensions(Size[] supportedPreviewSizes,
double bestPreviewAspectRatio,
- Context context) {
+ Activity context) {
// Swap dimensions if the device is not in its natural orientation.
- boolean swapDimens = (CameraUtil.getDisplayRotation() % 180) == 90;
+ boolean swapDimens = (CameraUtil.getDisplayRotation(context) % 180) == 90;
// Swap dimensions if the device's natural orientation doesn't match
// the sensor orientation.
if (CaptureModuleUtil.getDeviceNaturalOrientation(context)
@@ -121,7 +122,7 @@ public class CaptureModuleUtil {
}
Size pick = CaptureModuleUtil.getOptimalPreviewSize(supportedPreviewSizes,
- bestPreviewAspectRatio, null);
+ bestPreviewAspectRatio, null, context);
Log.d(TAG, "Picked buffer size: " + pick.toString());
return pick;
}
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index 6fb8243db..7f42aaac7 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -292,7 +292,7 @@ public class PhotoModule
// down and camera app is opened. Rotation animation will
// take some time and the rotation value we have got may be
// wrong. Framework does not have a callback for this now.
- if (CameraUtil.getDisplayRotation() != mDisplayRotation) {
+ if (CameraUtil.getDisplayRotation(mActivity) != mDisplayRotation) {
setDisplayOrientation();
}
if (SystemClock.uptimeMillis() - mOnResumeTime < 5000) {
@@ -1597,7 +1597,7 @@ public class PhotoModule
@Override
public void updateCameraOrientation() {
- if (mDisplayRotation != CameraUtil.getDisplayRotation()) {
+ if (mDisplayRotation != CameraUtil.getDisplayRotation(mActivity)) {
setDisplayOrientation();
}
}
@@ -1723,7 +1723,7 @@ public class PhotoModule
}
private void setDisplayOrientation() {
- mDisplayRotation = CameraUtil.getDisplayRotation();
+ mDisplayRotation = CameraUtil.getDisplayRotation(mActivity);
Characteristics info =
mActivity.getCameraProvider().getCharacteristics(mCameraId);
mDisplayOrientation = info.getPreviewOrientation(mDisplayRotation);
@@ -2002,7 +2002,7 @@ public class PhotoModule
// the right aspect ratio.
List<Size> sizes = Size.convert(mCameraCapabilities.getSupportedPreviewSizes());
Size optimalSize = CameraUtil.getOptimalPreviewSize(sizes,
- (double) pictureSize.width() / pictureSize.height());
+ (double) pictureSize.width() / pictureSize.height(), mActivity);
Size original = new Size(mCameraSettings.getCurrentPreviewSize());
if (!optimalSize.equals(original)) {
Log.v(TAG, "setting preview size. optimal: " + optimalSize + "original: " + original);
diff --git a/src/com/android/camera/TextureViewHelper.java b/src/com/android/camera/TextureViewHelper.java
index 2125280a3..42c41e102 100644
--- a/src/com/android/camera/TextureViewHelper.java
+++ b/src/com/android/camera/TextureViewHelper.java
@@ -16,6 +16,7 @@
package com.android.camera;
+import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.RectF;
@@ -104,7 +105,7 @@ public class TextureViewHelper implements TextureView.SurfaceTextureListener,
Log.v(TAG, "onLayoutChange");
int width = right - left;
int height = bottom - top;
- int rotation = CameraUtil.getDisplayRotation();
+ int rotation = CameraUtil.getDisplayRotation((Activity) mPreview.getContext());
if (mWidth != width || mHeight != height || mOrientation != rotation) {
mWidth = width;
mHeight = height;
@@ -355,7 +356,7 @@ public class TextureViewHelper implements TextureView.SurfaceTextureListener,
&& (mAppController.getCurrentModuleIndex() == mCameraModeId ||
mAppController.getCurrentModuleIndex() == mCaptureIntentModeId)) {
Log.v(TAG, "Applying Photo Mode, Capture Module, Nexus-4 specific fix for b/19271661");
- mOrientation = CameraUtil.getDisplayRotation();
+ mOrientation = CameraUtil.getDisplayRotation((Activity) mPreview.getContext());
matrix = getPreviewRotationalTransform(mOrientation,
new RectF(0, 0, mWidth, mHeight),
mCaptureLayoutHelper.getPreviewRect());
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index b0dee8d07..17d9fe747 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -253,7 +253,7 @@ public class VideoModule extends CameraModule
// down and camera app is opened. Rotation animation will
// take some time and the rotation value we have got may be
// wrong. Framework does not have a callback for this now.
- if ((CameraUtil.getDisplayRotation() != mDisplayRotation)
+ if ((CameraUtil.getDisplayRotation(mActivity) != mDisplayRotation)
&& !mMediaRecorderRecording && !mSwitchingCamera) {
startPreview();
}
@@ -780,7 +780,7 @@ public class VideoModule extends CameraModule
mCameraSettings = mCameraDevice.getSettings();
Point desiredPreviewSize = getDesiredPreviewSize(
- mCameraCapabilities, mProfile, mUI.getPreviewScreenSize());
+ mCameraCapabilities, mProfile, mUI.getPreviewScreenSize(), mActivity);
mDesiredPreviewWidth = desiredPreviewSize.x;
mDesiredPreviewHeight = desiredPreviewSize.y;
mUI.setPreviewSize(mDesiredPreviewWidth, mDesiredPreviewHeight);
@@ -804,7 +804,7 @@ public class VideoModule extends CameraModule
* opened yet.
*/
private static Point getDesiredPreviewSize(CameraCapabilities capabilities,
- CamcorderProfile profile, Point previewScreenSize) {
+ CamcorderProfile profile, Point previewScreenSize, Activity context) {
if (capabilities.getSupportedVideoSizes() == null ||
capabilities.getSupportedVideoSizes().isEmpty()) {
// Driver doesn't support separate outputs for preview and video.
@@ -843,7 +843,7 @@ public class VideoModule extends CameraModule
}
Size optimalSize = CameraUtil.getOptimalPreviewSize(sizes,
- (double) profile.videoFrameWidth / profile.videoFrameHeight);
+ (double) profile.videoFrameWidth / profile.videoFrameHeight, context);
return new Point(optimalSize.width(), optimalSize.height());
}
@@ -862,7 +862,7 @@ public class VideoModule extends CameraModule
}
private void setDisplayOrientation() {
- mDisplayRotation = CameraUtil.getDisplayRotation();
+ mDisplayRotation = CameraUtil.getDisplayRotation(mActivity);
Characteristics info =
mActivity.getCameraProvider().getCharacteristics(mCameraId);
mCameraDisplayOrientation = info.getPreviewOrientation(mDisplayRotation);
@@ -880,7 +880,7 @@ public class VideoModule extends CameraModule
if (mMediaRecorderRecording) {
return;
}
- if (mDisplayRotation != CameraUtil.getDisplayRotation()) {
+ if (mDisplayRotation != CameraUtil.getDisplayRotation(mActivity)) {
setDisplayOrientation();
}
}
diff --git a/src/com/android/camera/app/CameraAppUI.java b/src/com/android/camera/app/CameraAppUI.java
index 44b4d3b1e..94bb69f09 100644
--- a/src/com/android/camera/app/CameraAppUI.java
+++ b/src/com/android/camera/app/CameraAppUI.java
@@ -16,6 +16,7 @@
package com.android.camera.app;
+import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -924,7 +925,7 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
*/
private void initDisplayListener() {
if (ApiHelper.HAS_DISPLAY_LISTENER) {
- mLastRotation = CameraUtil.getDisplayRotation();
+ mLastRotation = CameraUtil.getDisplayRotation((Activity) mAppRootView.getContext());
mDisplayListener = new DisplayManager.DisplayListener() {
@Override
@@ -935,7 +936,7 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
@Override
public void onDisplayChanged(int displayId) {
int rotation = CameraUtil.getDisplayRotation(
- );
+ (Activity) mAppRootView.getContext());
if ((rotation - mLastRotation + 360) % 360 == 180
&& mPreviewStatusListener != null) {
mPreviewStatusListener.onPreviewFlipped();
diff --git a/src/com/android/camera/app/OrientationManagerImpl.java b/src/com/android/camera/app/OrientationManagerImpl.java
index e81877666..c45873611 100644
--- a/src/com/android/camera/app/OrientationManagerImpl.java
+++ b/src/com/android/camera/app/OrientationManagerImpl.java
@@ -108,7 +108,7 @@ public class OrientationManagerImpl implements OrientationManager {
@Override
public DeviceOrientation getDisplayRotation() {
- return DeviceOrientation.from((360 - CameraUtil.getDisplayRotation()) % 360);
+ return DeviceOrientation.from((360 - CameraUtil.getDisplayRotation(mActivity)) % 360);
}
@Override
@@ -270,8 +270,8 @@ public class OrientationManagerImpl implements OrientationManager {
* @param context current context
* @return whether the default orientation of the device is portrait
*/
- private static boolean isDefaultToPortrait(Context context) {
- Display currentDisplay = AndroidServices.instance().provideWindowManager()
+ private static boolean isDefaultToPortrait(Activity context) {
+ Display currentDisplay = AndroidServices.instance().provideWindowManager(context)
.getDefaultDisplay();
Point displaySize = new Point();
currentDisplay.getSize(displaySize);
diff --git a/src/com/android/camera/one/OneCamera.java b/src/com/android/camera/one/OneCamera.java
index 1f2cb665c..07c368945 100644
--- a/src/com/android/camera/one/OneCamera.java
+++ b/src/com/android/camera/one/OneCamera.java
@@ -16,7 +16,7 @@
package com.android.camera.one;
-import android.content.Context;
+import android.app.Activity;
import android.location.Location;
import android.net.Uri;
import android.view.Surface;
@@ -428,9 +428,9 @@ public interface OneCamera {
* might choose not to obey these and therefore the returned
* preview size might not match the aspect ratio of the given
* size.
- * @param context the android application context
+ * @param context the android activity context
* @return The preview size that best matches the picture aspect ratio that
* will be taken.
*/
- public Size pickPreviewSize(Size pictureSize, Context context);
+ public Size pickPreviewSize(Size pictureSize, Activity context);
}
diff --git a/src/com/android/camera/one/v2/OneCameraImpl.java b/src/com/android/camera/one/v2/OneCameraImpl.java
index 8f0ffef00..d9c6b03a3 100644
--- a/src/com/android/camera/one/v2/OneCameraImpl.java
+++ b/src/com/android/camera/one/v2/OneCameraImpl.java
@@ -17,7 +17,7 @@
package com.android.camera.one.v2;
import android.annotation.TargetApi;
-import android.content.Context;
+import android.app.Activity;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
@@ -719,7 +719,7 @@ public class OneCameraImpl extends AbstractOneCamera {
}
@Override
- public Size pickPreviewSize(Size pictureSize, Context context) {
+ public Size pickPreviewSize(Size pictureSize, Activity context) {
if (pictureSize == null) {
// TODO The default should be selected by the caller, and
// pictureSize should never be null.
@@ -732,7 +732,7 @@ public class OneCameraImpl extends AbstractOneCamera {
// flexible for selecting a matching preview resolution.
Double aspectRatioTolerance = sCaptureImageFormat == ImageFormat.RAW_SENSOR ? 10d : null;
Size size = CaptureModuleUtil.getOptimalPreviewSize(supportedSizes,
- pictureAspectRatio, aspectRatioTolerance);
+ pictureAspectRatio, aspectRatioTolerance, context);
Log.d(TAG, "Selected preview size: " + size);
return size;
}
diff --git a/src/com/android/camera/one/v2/OneCameraZslImpl.java b/src/com/android/camera/one/v2/OneCameraZslImpl.java
index a35a6c1b3..636f3f531 100644
--- a/src/com/android/camera/one/v2/OneCameraZslImpl.java
+++ b/src/com/android/camera/one/v2/OneCameraZslImpl.java
@@ -15,7 +15,7 @@
package com.android.camera.one.v2;
import android.annotation.TargetApi;
-import android.content.Context;
+import android.app.Activity;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.hardware.camera2.CameraAccessException;
@@ -1090,7 +1090,7 @@ public class OneCameraZslImpl extends AbstractOneCamera {
}
@Override
- public Size pickPreviewSize(Size pictureSize, Context context) {
+ public Size pickPreviewSize(Size pictureSize, Activity context) {
if (pictureSize == null) {
// TODO The default should be selected by the caller, and
// pictureSize should never be null.
@@ -1098,7 +1098,7 @@ public class OneCameraZslImpl extends AbstractOneCamera {
}
float pictureAspectRatio = pictureSize.getWidth() / (float) pictureSize.getHeight();
return CaptureModuleUtil.getOptimalPreviewSize(getSupportedPreviewSizes(),
- pictureAspectRatio);
+ pictureAspectRatio, context);
}
@Override
diff --git a/src/com/android/camera/one/v2/autofocus/ManualAutoFocusFactory.java b/src/com/android/camera/one/v2/autofocus/ManualAutoFocusFactory.java
index 1681ddbc8..690058acf 100644
--- a/src/com/android/camera/one/v2/autofocus/ManualAutoFocusFactory.java
+++ b/src/com/android/camera/one/v2/autofocus/ManualAutoFocusFactory.java
@@ -27,6 +27,7 @@ import com.android.camera.one.Settings3A;
import com.android.camera.one.v2.commands.CameraCommand;
import com.android.camera.one.v2.commands.CameraCommandExecutor;
import com.android.camera.one.v2.commands.ResettingRunnableCameraCommand;
+import com.android.camera.one.v2.commands.UpdateRequestCommand;
import com.android.camera.one.v2.core.FrameServer;
import com.android.camera.one.v2.core.RequestBuilder;
import com.android.camera.one.v2.core.RequestTemplate;
@@ -65,6 +66,8 @@ public class ManualAutoFocusFactory {
* @param threadPool The executor on which to schedule delayed tasks.
* @param afHoldSeconds The number of seconds to hold AF after a manual AF
* sweep is triggered.
+ * @param aeSupport Camera device supports AE metering regions
+ * @param afSupport Camera device supports AF and AF metering regions
*/
public static ManualAutoFocusFactory create(Lifetime lifetime, FrameServer frameServer,
CameraCommandExecutor commandExecutor, Supplier<Rect> cropRegion,
@@ -72,7 +75,7 @@ public class ManualAutoFocusFactory {
Runnable previewRunner, RequestBuilder.Factory rootBuilder,
int templateType, Settings3A settings3A,
ScheduledExecutorService threadPool,
- int afHoldSeconds) {
+ int afHoldSeconds, boolean aeSupport, boolean afSupport) {
ConcurrentState<MeteringParameters> currentMeteringParameters = new ConcurrentState<>(
GlobalMeteringParameters.create());
AEMeteringRegion aeMeteringRegion = new AEMeteringRegion(currentMeteringParameters,
@@ -81,17 +84,27 @@ public class ManualAutoFocusFactory {
cropRegion);
RequestTemplate afScanRequestBuilder = new RequestTemplate(rootBuilder);
- afScanRequestBuilder.setParam(CaptureRequest.CONTROL_AE_REGIONS, aeMeteringRegion);
- afScanRequestBuilder.setParam(CaptureRequest.CONTROL_AF_REGIONS, afMeteringRegion);
-
- CameraCommand afScanCommand = new FullAFScanCommand(frameServer, afScanRequestBuilder,
- templateType);
+ if (aeSupport) {
+ afScanRequestBuilder.setParam(CaptureRequest.CONTROL_AE_REGIONS, aeMeteringRegion);
+ }
+ if (afSupport) {
+ afScanRequestBuilder.setParam(CaptureRequest.CONTROL_AF_REGIONS, afMeteringRegion);
+ }
+
+ CameraCommand initialCommand;
+ if (afSupport) {
+ initialCommand = new FullAFScanCommand(frameServer, afScanRequestBuilder,
+ templateType);
+ } else {
+ initialCommand = new UpdateRequestCommand(frameServer, afScanRequestBuilder,
+ templateType);
+ }
ResettingDelayedExecutor afHoldDelayedExecutor = new ResettingDelayedExecutor(
threadPool, afHoldSeconds, TimeUnit.SECONDS);
lifetime.add(afHoldDelayedExecutor);
- CameraCommand afScanHoldResetCommand = new AFScanHoldResetCommand(afScanCommand,
+ CameraCommand afScanHoldResetCommand = new AFScanHoldResetCommand(initialCommand,
afHoldDelayedExecutor, previewRunner, currentMeteringParameters);
Runnable afRunner = new ResettingRunnableCameraCommand(commandExecutor,
diff --git a/src/com/android/camera/one/v2/commands/UpdateRequestCommand.java b/src/com/android/camera/one/v2/commands/UpdateRequestCommand.java
new file mode 100644
index 000000000..9c15248df
--- /dev/null
+++ b/src/com/android/camera/one/v2/commands/UpdateRequestCommand.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera.one.v2.commands;
+
+import android.hardware.camera2.CameraAccessException;
+import android.hardware.camera2.CaptureRequest;
+
+import com.android.camera.one.v2.camera2proxy.CameraCaptureSessionClosedException;
+import com.android.camera.one.v2.commands.CameraCommand;
+import com.android.camera.one.v2.core.FrameServer;
+import com.android.camera.one.v2.core.RequestBuilder;
+import com.android.camera.one.v2.core.ResourceAcquisitionFailedException;
+
+import java.util.Arrays;
+
+import javax.annotation.Nullable;
+import javax.annotation.ParametersAreNonnullByDefault;
+
+/**
+ * Update repeating request.
+ */
+@ParametersAreNonnullByDefault
+public final class UpdateRequestCommand implements CameraCommand {
+ private final FrameServer mFrameServer;
+ private final RequestBuilder.Factory mBuilderFactory;
+ private final int mTemplateType;
+
+ /**
+ * @param frameServer Used for sending requests to the camera.
+ * @param builder Used for building requests.
+ * @param templateType See
+ * {@link android.hardware.camera2.CameraDevice#createCaptureRequest}
+ */
+ public UpdateRequestCommand(FrameServer frameServer, RequestBuilder.Factory builder, int
+ templateType) {
+ mFrameServer = frameServer;
+ mBuilderFactory = builder;
+ mTemplateType = templateType;
+ }
+
+ /**
+ * Update repeating request.
+ */
+ @Override
+ public void run() throws InterruptedException, CameraAccessException,
+ CameraCaptureSessionClosedException, ResourceAcquisitionFailedException {
+ FrameServer.Session session = mFrameServer.tryCreateExclusiveSession();
+ if (session == null) {
+ // If there are already other commands interacting with the
+ // FrameServer just abort.
+ return;
+ }
+
+ try {
+ RequestBuilder builder = mBuilderFactory.create(mTemplateType);
+ session.submitRequest(Arrays.asList(builder.build()),
+ FrameServer.RequestType.REPEATING);
+ } finally {
+ session.close();
+ }
+ }
+}
diff --git a/src/com/android/camera/one/v2/common/BasicCameraFactory.java b/src/com/android/camera/one/v2/common/BasicCameraFactory.java
index 44883eade..c42f447ca 100644
--- a/src/com/android/camera/one/v2/common/BasicCameraFactory.java
+++ b/src/com/android/camera/one/v2/common/BasicCameraFactory.java
@@ -148,7 +148,8 @@ public class BasicCameraFactory {
Lifetime(lifetime), frameServer, cameraCommandExecutor, cropRegion,
sensorOrientation, mPreviewUpdater, requestTemplate,
templateType, new Settings3A(), Executors.newScheduledThreadPool(1),
- 3 /* afHoldSeconds */);
+ 3 /* afHoldSeconds */, cameraCharacteristics.isAutoExposureSupported(),
+ cameraCharacteristics.isAutoFocusSupported());
mManualAutoFocus = manualAutoFocusFactory.provideManualAutoFocus();
Supplier<MeteringRectangle[]> aeRegions =
manualAutoFocusFactory.provideAEMeteringRegion();
diff --git a/src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java b/src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java
index 472378f17..da66d6fee 100644
--- a/src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java
+++ b/src/com/android/camera/one/v2/initialization/GenericOneCameraImpl.java
@@ -16,7 +16,7 @@
package com.android.camera.one.v2.initialization;
-import android.content.Context;
+import android.app.Activity;
import android.view.Surface;
import com.android.camera.async.FilteredCallback;
@@ -184,7 +184,7 @@ class GenericOneCameraImpl implements OneCamera {
}
@Override
- public Size pickPreviewSize(Size pictureSize, Context context) {
+ public Size pickPreviewSize(Size pictureSize, Activity context) {
return mPreviewSizeSelector.pickPreviewSize(pictureSize);
}
}
diff --git a/src/com/android/camera/settings/ResolutionUtil.java b/src/com/android/camera/settings/ResolutionUtil.java
index 632bce0f5..14d1d75d8 100644
--- a/src/com/android/camera/settings/ResolutionUtil.java
+++ b/src/com/android/camera/settings/ResolutionUtil.java
@@ -16,8 +16,10 @@
package com.android.camera.settings;
+import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
+import android.view.Display;
import android.view.WindowManager;
import com.android.camera.exif.Rational;
@@ -405,11 +407,11 @@ public class ResolutionUtil {
return maxSize;
}
- public static DisplayMetrics getDisplayMetrics(Context context) {
+ public static DisplayMetrics getDisplayMetrics(Activity context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
- WindowManager wm = AndroidServices.instance().provideWindowManager();
- if (wm != null) {
- wm.getDefaultDisplay().getMetrics(displayMetrics);
+ Display d = context.getDisplay();
+ if (d != null) {
+ d.getMetrics(displayMetrics);
}
return displayMetrics;
}
diff --git a/src/com/android/camera/ui/MainActivityLayout.java b/src/com/android/camera/ui/MainActivityLayout.java
index 39d2b582d..98f708980 100644
--- a/src/com/android/camera/ui/MainActivityLayout.java
+++ b/src/com/android/camera/ui/MainActivityLayout.java
@@ -150,7 +150,7 @@ public class MainActivityLayout extends FrameLayout {
if (mNonDecorWindowSizeChangedListener != null) {
mNonDecorWindowSizeChangedListener.onNonDecorWindowSizeChanged(
MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec),
- CameraUtil.getDisplayRotation());
+ CameraUtil.getDisplayRotation((Activity) getContext()));
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@@ -166,7 +166,7 @@ public class MainActivityLayout extends FrameLayout {
if (mNonDecorWindowSizeChangedListener != null) {
mNonDecorWindowSizeChangedListener.onNonDecorWindowSizeChanged(
getMeasuredWidth(), getMeasuredHeight(),
- CameraUtil.getDisplayRotation());
+ CameraUtil.getDisplayRotation((Activity) getContext()));
}
}
-} \ No newline at end of file
+}
diff --git a/src/com/android/camera/util/AndroidServices.java b/src/com/android/camera/util/AndroidServices.java
index 0b0b98182..70c35e855 100644
--- a/src/com/android/camera/util/AndroidServices.java
+++ b/src/com/android/camera/util/AndroidServices.java
@@ -17,6 +17,7 @@
package com.android.camera.util;
import android.annotation.TargetApi;
+import android.app.Activity;
import android.app.ActivityManager;
import android.app.KeyguardManager;
import android.app.NotificationManager;
@@ -126,14 +127,21 @@ public class AndroidServices {
return (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
}
- public WindowManager provideWindowManager() {
- return (WindowManager) getSystemService(Context.WINDOW_SERVICE);
+ public WindowManager provideWindowManager(Activity context) {
+ return (WindowManager) getSystemService(Context.WINDOW_SERVICE, context);
}
private Object getSystemService(String service) {
+ return getSystemService(service, null);
+ }
+
+ private Object getSystemService(String service, Context targetContext) {
try {
long start = System.currentTimeMillis();
- Object result = mContext.getSystemService(service);
+ if (targetContext == null) targetContext = mContext;
+
+ Object result = targetContext.getSystemService(service);
+
long duration = System.currentTimeMillis() - start;
if (duration > LOG_THRESHOLD_MILLIS) {
Log.w(TAG, "Warning: providing system service " + service + " took " +
diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java
index 639e63593..b6e11b88a 100644
--- a/src/com/android/camera/util/CameraUtil.java
+++ b/src/com/android/camera/util/CameraUtil.java
@@ -450,8 +450,8 @@ public class CameraUtil {
return new Size((int) width, (int) height);
}
- public static int getDisplayRotation() {
- WindowManager windowManager = AndroidServices.instance().provideWindowManager();
+ public static int getDisplayRotation(Activity context) {
+ WindowManager windowManager = AndroidServices.instance().provideWindowManager(context);
int rotation = windowManager.getDefaultDisplay()
.getRotation();
switch (rotation) {
@@ -467,15 +467,16 @@ public class CameraUtil {
return 0;
}
- private static Size getDefaultDisplaySize() {
- WindowManager windowManager = AndroidServices.instance().provideWindowManager();
+ private static Size getDefaultDisplaySize(Activity context) {
+ WindowManager windowManager = AndroidServices.instance().provideWindowManager(context);
Point res = new Point();
windowManager.getDefaultDisplay().getSize(res);
return new Size(res);
}
- public static Size getOptimalPreviewSize(List<Size> sizes, double targetRatio) {
- int optimalPickIndex = getOptimalPreviewSizeIndex(sizes, targetRatio);
+ public static Size getOptimalPreviewSize(List<Size> sizes, double targetRatio,
+ Activity context) {
+ int optimalPickIndex = getOptimalPreviewSizeIndex(sizes, targetRatio, context);
if (optimalPickIndex == -1) {
return null;
} else {
@@ -494,16 +495,18 @@ public class CameraUtil {
* @param sizes the available preview sizes
* @param targetRatio the target aspect ratio, typically the aspect ratio of
* the picture size
+ * @param context the Activity to use for determining display information
* @return The index into 'previewSizes' for the optimal size, or -1, if no
* matching size was found.
*/
- public static int getOptimalPreviewSizeIndex(List<Size> sizes, double targetRatio) {
+ public static int getOptimalPreviewSizeIndex(List<Size> sizes, double targetRatio,
+ Activity context) {
// Use a very small tolerance because we want an exact match. HTC 4:3
// ratios is over .01 from true 4:3, so this value must be above .01,
// see b/18241645.
final double aspectRatioTolerance = 0.02;
- return getOptimalPreviewSizeIndex(sizes, targetRatio, aspectRatioTolerance);
+ return getOptimalPreviewSizeIndex(sizes, targetRatio, aspectRatioTolerance, context);
}
/**
@@ -516,11 +519,13 @@ public class CameraUtil {
* @param aspectRatioTolerance the tolerance we allow between the selected
* preview size's aspect ratio and the target ratio. If this is
* set to 'null', the default value is used.
+ * @param context the Activity to use for determining display information
* @return The index into 'previewSizes' for the optimal size, or -1, if no
* matching size was found.
*/
public static int getOptimalPreviewSizeIndex(
- List<Size> previewSizes, double targetRatio, Double aspectRatioTolerance) {
+ List<Size> previewSizes, double targetRatio, Double aspectRatioTolerance,
+ Activity context) {
if (previewSizes == null) {
return -1;
}
@@ -528,7 +533,7 @@ public class CameraUtil {
// If no particular aspect ratio tolerance is set, use the default
// value.
if (aspectRatioTolerance == null) {
- return getOptimalPreviewSizeIndex(previewSizes, targetRatio);
+ return getOptimalPreviewSizeIndex(previewSizes, targetRatio, context);
}
int optimalSizeIndex = -1;
@@ -539,7 +544,7 @@ public class CameraUtil {
// wrong size of preview surface. When we change the preview size, the
// new overlay will be created before the old one closed, which causes
// an exception. For now, just get the screen size.
- Size defaultDisplaySize = getDefaultDisplaySize();
+ Size defaultDisplaySize = getDefaultDisplaySize(context);
int targetHeight = Math.min(defaultDisplaySize.getWidth(), defaultDisplaySize.getHeight());
// Try to find an size match aspect ratio and size
for (int i = 0; i < previewSizes.size(); i++) {