blob: c6e175d2a881d7998108ba68ac64440f4bcc7b36 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.hardware;
18
Eino-Ville Talvala06a77182017-09-15 12:43:24 -070019import static android.system.OsConstants.*;
20
jiabin503e1fd2018-04-19 16:39:44 -070021import android.annotation.Nullable;
Wu-cheng Li10e09c62011-07-18 09:09:41 +080022import android.annotation.SdkConstant;
23import android.annotation.SdkConstant.SdkConstantType;
Mathew Inwood5132cc12018-08-08 15:50:55 +010024import android.annotation.UnsupportedAppUsage;
Eino-Ville Talvala06a77182017-09-15 12:43:24 -070025import android.app.ActivityThread;
jiabin503e1fd2018-04-19 16:39:44 -070026import android.app.AppOpsManager;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070027import android.content.Context;
Mathias Agopiana696f5d2010-02-17 17:53:09 -080028import android.graphics.ImageFormat;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080029import android.graphics.Point;
Wu-cheng Li30771b72011-04-02 06:19:46 +080030import android.graphics.Rect;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -080031import android.graphics.SurfaceTexture;
jiabin503e1fd2018-04-19 16:39:44 -070032import android.media.AudioAttributes;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070033import android.media.IAudioService;
Mathew Inwood45d2c252018-09-14 12:35:36 +010034import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.os.Handler;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070036import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.os.Looper;
38import android.os.Message;
jiabin503e1fd2018-04-19 16:39:44 -070039import android.os.Process;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -070040import android.os.RemoteException;
41import android.os.ServiceManager;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -070042import android.renderscript.Allocation;
43import android.renderscript.Element;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -070044import android.renderscript.RSIllegalArgumentException;
Eino-Ville Talvala06a77182017-09-15 12:43:24 -070045import android.renderscript.RenderScript;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -070046import android.renderscript.Type;
Ali Utku Selen0a120182011-02-09 14:11:22 +010047import android.text.TextUtils;
Eino-Ville Talvala06a77182017-09-15 12:43:24 -070048import android.util.Log;
Wu-cheng Libde61a52011-06-07 18:23:14 +080049import android.view.Surface;
50import android.view.SurfaceHolder;
51
jiabin503e1fd2018-04-19 16:39:44 -070052import com.android.internal.annotations.GuardedBy;
53import com.android.internal.app.IAppOpsCallback;
54import com.android.internal.app.IAppOpsService;
55
Wu-cheng Libde61a52011-06-07 18:23:14 +080056import java.io.IOException;
57import java.lang.ref.WeakReference;
58import java.util.ArrayList;
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -070059import java.util.LinkedHashMap;
Wu-cheng Libde61a52011-06-07 18:23:14 +080060import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
62/**
Dan Egnorbfcbeff2010-07-12 15:12:54 -070063 * The Camera class is used to set image capture settings, start/stop preview,
64 * snap pictures, and retrieve frames for encoding for video. This class is a
65 * client for the Camera service, which manages the actual camera hardware.
Scott Maindf4578e2009-09-10 12:22:07 -070066 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070067 * <p>To access the device camera, you must declare the
Wu-cheng Li7478ea62009-09-16 18:52:55 +080068 * {@link android.Manifest.permission#CAMERA} permission in your Android
Scott Maindf4578e2009-09-10 12:22:07 -070069 * Manifest. Also be sure to include the
70 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
Dan Egnorbfcbeff2010-07-12 15:12:54 -070071 * manifest element to declare camera features used by your application.
Wu-cheng Li7478ea62009-09-16 18:52:55 +080072 * For example, if you use the camera and auto-focus feature, your Manifest
Scott Maindf4578e2009-09-10 12:22:07 -070073 * should include the following:</p>
74 * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
75 * &lt;uses-feature android:name="android.hardware.camera" />
76 * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
77 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -070078 * <p>To take pictures with this class, use the following steps:</p>
79 *
80 * <ol>
Dan Egnor341ff132010-07-20 11:30:17 -070081 * <li>Obtain an instance of Camera from {@link #open(int)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -070082 *
83 * <li>Get existing (default) settings with {@link #getParameters()}.
84 *
85 * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
86 * {@link #setParameters(Camera.Parameters)}.
87 *
Eino-Ville Talvala6c91e2c2016-03-25 11:54:39 -070088 * <li>Call {@link #setDisplayOrientation(int)} to ensure correct orientation of preview.
Dan Egnorbfcbeff2010-07-12 15:12:54 -070089 *
90 * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
91 * {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera
92 * will be unable to start the preview.
93 *
94 * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
95 * preview surface. Preview must be started before you can take a picture.
96 *
97 * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
98 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
99 * capture a photo. Wait for the callbacks to provide the actual image data.
100 *
101 * <li>After taking a picture, preview display will have stopped. To take more
102 * photos, call {@link #startPreview()} again first.
103 *
104 * <li>Call {@link #stopPreview()} to stop updating the preview surface.
105 *
106 * <li><b>Important:</b> Call {@link #release()} to release the camera for
107 * use by other applications. Applications should release the camera
108 * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
109 * it in {@link android.app.Activity#onResume()}).
110 * </ol>
111 *
112 * <p>To quickly switch to video recording mode, use these steps:</p>
113 *
114 * <ol>
115 * <li>Obtain and initialize a Camera and start preview as described above.
116 *
117 * <li>Call {@link #unlock()} to allow the media process to access the camera.
118 *
119 * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
120 * See {@link android.media.MediaRecorder} information about video recording.
121 *
122 * <li>When finished recording, call {@link #reconnect()} to re-acquire
123 * and re-lock the camera.
124 *
125 * <li>If desired, restart preview and take more photos or videos.
126 *
127 * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
128 * </ol>
129 *
130 * <p>This class is not thread-safe, and is meant for use from one event thread.
131 * Most long-running operations (preview, focus, photo capture, etc) happen
132 * asynchronously and invoke callbacks as necessary. Callbacks will be invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700133 * on the event thread {@link #open(int)} was called from. This class's methods
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700134 * must never be called from multiple threads at once.</p>
135 *
Scott Maindf4578e2009-09-10 12:22:07 -0700136 * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
137 * may have different hardware specifications, such as megapixel ratings and
138 * auto-focus capabilities. In order for your application to be compatible with
Wu-cheng Li7478ea62009-09-16 18:52:55 +0800139 * more devices, you should not make assumptions about the device camera
Scott Maindf4578e2009-09-10 12:22:07 -0700140 * specifications.</p>
Joe Fernandez6c5c3c32011-10-18 14:57:05 -0700141 *
142 * <div class="special reference">
143 * <h3>Developer Guides</h3>
144 * <p>For more information about using cameras, read the
145 * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p>
146 * </div>
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700147 *
148 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
149 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700151@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152public class Camera {
153 private static final String TAG = "Camera";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800154
Wu-cheng Lid2c29292010-05-28 17:32:41 +0800155 // These match the enums in frameworks/base/include/camera/Camera.h
Benny Wongda83f462009-08-12 12:01:27 -0500156 private static final int CAMERA_MSG_ERROR = 0x001;
157 private static final int CAMERA_MSG_SHUTTER = 0x002;
158 private static final int CAMERA_MSG_FOCUS = 0x004;
159 private static final int CAMERA_MSG_ZOOM = 0x008;
160 private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010;
161 private static final int CAMERA_MSG_VIDEO_FRAME = 0x020;
162 private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040;
163 private static final int CAMERA_MSG_RAW_IMAGE = 0x080;
164 private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800165 private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800166 private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800167 private static final int CAMERA_MSG_FOCUS_MOVE = 0x800;
Sauhard Pandec44f2d92015-07-09 14:47:34 -0700168 /* ### QC ADD-ONS: START */
169 private static final int CAMERA_MSG_STATS_DATA = 0x1000;
170 private static final int CAMERA_MSG_META_DATA = 0x2000;
171 /* ### QC ADD-ONS: END */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172
Mathew Inwood45d2c252018-09-14 12:35:36 +0100173 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Ashok Bhat4838e332014-01-03 14:37:19 +0000174 private long mNativeContext; // accessed by native methods
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 private EventHandler mEventHandler;
176 private ShutterCallback mShutterCallback;
177 private PictureCallback mRawImageCallback;
178 private PictureCallback mJpegCallback;
179 private PreviewCallback mPreviewCallback;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700180 private boolean mUsingPreviewAllocation;
Dave Sparkse8b26e12009-07-14 10:35:40 -0700181 private PictureCallback mPostviewCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 private AutoFocusCallback mAutoFocusCallback;
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800183 private AutoFocusMoveCallback mAutoFocusMoveCallback;
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800184 private OnZoomChangeListener mZoomListener;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800185 private FaceDetectionListener mFaceListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 private ErrorCallback mErrorCallback;
Yin-Chia Yeha07cd322018-05-31 12:11:42 -0700187 private ErrorCallback mDetailedErrorCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 private boolean mOneShot;
Andrew Harp94927df2009-10-20 01:47:05 -0400189 private boolean mWithBuffer;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800190 private boolean mFaceDetectionRunning = false;
Igor Murashkina1d66272014-06-20 11:22:11 -0700191 private final Object mAutoFocusCallbackLock = new Object();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800192
jiabin503e1fd2018-04-19 16:39:44 -0700193 private final Object mShutterSoundLock = new Object();
194 // for AppOps
195 private @Nullable IAppOpsService mAppOps;
196 private IAppOpsCallback mAppOpsCallback;
197 @GuardedBy("mShutterSoundLock")
198 private boolean mHasAppOpsPlayAudio = true;
199 @GuardedBy("mShutterSoundLock")
200 private boolean mShutterSoundEnabledFromApp = true;
201
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700202 private static final int NO_ERROR = 0;
Sauhard Pandec44f2d92015-07-09 14:47:34 -0700203 private static final int EACCESS = -13;
204 private static final int ENODEV = -19;
205 private static final int EBUSY = -16;
206 private static final int EINVAL = -22;
207 private static final int ENOSYS = -38;
208 private static final int EUSERS = -87;
209 private static final int EOPNOTSUPP = -95;
210 /* ### QC ADD-ONS: START */
211 private CameraDataCallback mCameraDataCallback;
212 private CameraMetaDataCallback mCameraMetaDataCallback;
213 /* ### QC ADD-ONS: END */
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 /**
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800216 * Broadcast Action: A new picture is taken by the camera, and the entry of
217 * the picture has been added to the media store.
218 * {@link android.content.Intent#getData} is URI of the picture.
Dianne Hackborn5da9e942017-03-10 13:30:06 -0800219 *
220 * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and
221 * applications are recommended to use
222 * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri}
223 * instead.</p>
224 *
225 * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought
226 * back, but only for <em>registered</em> receivers. Apps that are actively running can
Dianne Hackbornc1541952017-04-27 10:55:49 -0700227 * again listen to the broadcast if they want an immediate clear signal about a picture
Dianne Hackborn5da9e942017-03-10 13:30:06 -0800228 * being taken, however anything doing heavy work (or needing to be launched) as a result of
229 * this should still use JobScheduler.</p>
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800230 */
231 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
232 public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
233
234 /**
235 * Broadcast Action: A new video is recorded by the camera, and the entry
236 * of the video has been added to the media store.
237 * {@link android.content.Intent#getData} is URI of the video.
Dianne Hackborn5da9e942017-03-10 13:30:06 -0800238 *
239 * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and
240 * applications are recommended to use
241 * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri}
242 * instead.</p>
243 *
244 * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought
245 * back, but only for <em>registered</em> receivers. Apps that are actively running can
Dianne Hackbornc1541952017-04-27 10:55:49 -0700246 * again listen to the broadcast if they want an immediate clear signal about a video
Dianne Hackborn5da9e942017-03-10 13:30:06 -0800247 * being taken, however anything doing heavy work (or needing to be launched) as a result of
248 * this should still use JobScheduler.</p>
Wu-cheng Li10e09c62011-07-18 09:09:41 +0800249 */
250 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
251 public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
252
253 /**
Zhijun He4c913802014-06-16 16:42:35 -0700254 * Camera HAL device API version 1.0
255 * @hide
256 */
Mathew Inwood5132cc12018-08-08 15:50:55 +0100257 @UnsupportedAppUsage
Zhijun He4c913802014-06-16 16:42:35 -0700258 public static final int CAMERA_HAL_API_VERSION_1_0 = 0x100;
259
260 /**
261 * A constant meaning the normal camera connect/open will be used.
Zhijun He4c913802014-06-16 16:42:35 -0700262 */
Igor Murashkina1d66272014-06-20 11:22:11 -0700263 private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2;
Zhijun He4c913802014-06-16 16:42:35 -0700264
265 /**
266 * Used to indicate HAL version un-specified.
267 */
268 private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
Igor Murashkina1d66272014-06-20 11:22:11 -0700269
Zhijun He4c913802014-06-16 16:42:35 -0700270 /**
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800271 * Hardware face detection. It does not use much CPU.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800272 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800273 private static final int CAMERA_FACE_DETECTION_HW = 0;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800274
275 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800276 * Software face detection. It uses some CPU.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800277 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +0800278 private static final int CAMERA_FACE_DETECTION_SW = 1;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800279
280 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700281 * Returns the number of physical cameras available on this device.
Yin-Chia Yeh564ae822018-02-08 16:24:27 -0800282 * The return value of this method might change dynamically if the device
283 * supports external cameras and an external camera is connected or
284 * disconnected.
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700285 *
Shuzhen Wange7d3cd02018-05-31 11:41:39 -0700286 * If there is a
287 * {@link android.hardware.camera2.CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA
288 * logical multi-camera} in the system, to maintain app backward compatibility, this method will
Shuzhen Wang64ed1012019-03-28 14:30:33 -0700289 * only expose one camera per facing for all logical camera and physical camera groups.
Shuzhen Wange7d3cd02018-05-31 11:41:39 -0700290 * Use camera2 API to see all cameras.
291 *
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700292 * @return total number of accessible camera devices, or 0 if there are no
293 * cameras or an error was encountered enumerating them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 */
Chih-Chung Change25cc652010-05-06 16:36:58 +0800295 public native static int getNumberOfCameras();
296
297 /**
Dan Egnor341ff132010-07-20 11:30:17 -0700298 * Returns the information about a particular camera.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800299 * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700300 *
301 * @throws RuntimeException if an invalid ID is provided, or if there is an
302 * error retrieving the information (generally due to a hardware or other
303 * low-level failure).
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800304 */
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -0700305 public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
306 _getCameraInfo(cameraId, cameraInfo);
307 IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
308 IAudioService audioService = IAudioService.Stub.asInterface(b);
309 try {
310 if (audioService.isCameraSoundForced()) {
311 // Only set this when sound is forced; otherwise let native code
312 // decide.
313 cameraInfo.canDisableShutterSound = false;
314 }
315 } catch (RemoteException e) {
316 Log.e(TAG, "Audio service is unavailable for queries");
317 }
318 }
319 private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800320
321 /**
322 * Information about a camera
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700323 *
324 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
325 * applications.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800326 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700327 @Deprecated
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800328 public static class CameraInfo {
Wu-cheng Li78366602010-09-15 14:08:15 -0700329 /**
330 * The facing of the camera is opposite to that of the screen.
331 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800332 public static final int CAMERA_FACING_BACK = 0;
Wu-cheng Li78366602010-09-15 14:08:15 -0700333
334 /**
335 * The facing of the camera is the same as that of the screen.
336 */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800337 public static final int CAMERA_FACING_FRONT = 1;
338
Sauhard Pandec44f2d92015-07-09 14:47:34 -0700339 /* ### QC ADD-ONS: START TBD*/
340 /** @hide
341 * camera is in ZSL mode.
342 */
343 public static final int CAMERA_SUPPORT_MODE_ZSL = 2;
344
345 /** @hide
346 * camera is in non-ZSL mode.
347 */
348 public static final int CAMERA_SUPPORT_MODE_NONZSL = 3;
349 /* ### QC ADD-ONS: END */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800350 /**
Joe Fernandez464cb212011-10-04 16:56:47 -0700351 * The direction that the camera faces. It should be
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800352 * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
353 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700354 public int facing;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800355
356 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700357 * <p>The orientation of the camera image. The value is the angle that the
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800358 * camera image needs to be rotated clockwise so it shows correctly on
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700359 * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800360 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700361 * <p>For example, suppose a device has a naturally tall screen. The
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +0800362 * back-facing camera sensor is mounted in landscape. You are looking at
363 * the screen. If the top side of the camera sensor is aligned with the
364 * right edge of the screen in natural orientation, the value should be
365 * 90. If the top side of a front-facing camera sensor is aligned with
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700366 * the right of the screen, the value should be 270.</p>
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800367 *
368 * @see #setDisplayOrientation(int)
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -0800369 * @see Parameters#setRotation(int)
370 * @see Parameters#setPreviewSize(int, int)
371 * @see Parameters#setPictureSize(int, int)
372 * @see Parameters#setJpegThumbnailSize(int, int)
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800373 */
Wu-cheng Li78366602010-09-15 14:08:15 -0700374 public int orientation;
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -0700375
376 /**
377 * <p>Whether the shutter sound can be disabled.</p>
378 *
379 * <p>On some devices, the camera shutter sound cannot be turned off
380 * through {@link #enableShutterSound enableShutterSound}. This field
381 * can be used to determine whether a call to disable the shutter sound
382 * will succeed.</p>
383 *
384 * <p>If this field is set to true, then a call of
385 * {@code enableShutterSound(false)} will be successful. If set to
386 * false, then that call will fail, and the shutter sound will be played
387 * when {@link Camera#takePicture takePicture} is called.</p>
388 */
389 public boolean canDisableShutterSound;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800390 };
391
392 /**
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800393 * Creates a new Camera object to access a particular hardware camera. If
394 * the same camera is opened by other applications, this will throw a
395 * RuntimeException.
396 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700397 * <p>You must call {@link #release()} when you are done using the camera,
398 * otherwise it will remain locked and be unavailable to other applications.
399 *
Dan Egnor341ff132010-07-20 11:30:17 -0700400 * <p>Your application should only have one Camera object active at a time
401 * for a particular hardware camera.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700402 *
403 * <p>Callbacks from other methods are delivered to the event loop of the
404 * thread which called open(). If this thread has no event loop, then
405 * callbacks are delivered to the main application event loop. If there
406 * is no main application event loop, callbacks are not delivered.
407 *
408 * <p class="caution"><b>Caution:</b> On some devices, this method may
409 * take a long time to complete. It is best to call this method from a
410 * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
411 * blocking the main application UI thread.
412 *
Dan Egnor341ff132010-07-20 11:30:17 -0700413 * @param cameraId the hardware camera to access, between 0 and
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800414 * {@link #getNumberOfCameras()}-1.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700415 * @return a new Camera object, connected, locked and ready for use.
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800416 * @throws RuntimeException if opening the camera fails (for example, if the
417 * camera is in use by another process or device policy manager has
418 * disabled the camera).
Wu-cheng Lifacc8ce2011-06-17 13:09:40 +0800419 * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800420 */
421 public static Camera open(int cameraId) {
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800422 return new Camera(cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 }
424
Chih-Chung Change25cc652010-05-06 16:36:58 +0800425 /**
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800426 * Creates a new Camera object to access the first back-facing camera on the
427 * device. If the device does not have a back-facing camera, this returns
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700428 * null. Otherwise acts like the {@link #open(int)} call.
429 *
430 * @return a new Camera object for the first back-facing camera, or null if there is no
431 * backfacing camera
Wu-cheng Li78366602010-09-15 14:08:15 -0700432 * @see #open(int)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800433 */
434 public static Camera open() {
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800435 int numberOfCameras = getNumberOfCameras();
436 CameraInfo cameraInfo = new CameraInfo();
437 for (int i = 0; i < numberOfCameras; i++) {
438 getCameraInfo(i, cameraInfo);
439 if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800440 return new Camera(i);
Wu-cheng Lia48b70f2010-11-09 01:55:44 +0800441 }
442 }
443 return null;
Chih-Chung Change25cc652010-05-06 16:36:58 +0800444 }
445
Zhijun He4c913802014-06-16 16:42:35 -0700446 /**
447 * Creates a new Camera object to access a particular hardware camera with
448 * given hal API version. If the same camera is opened by other applications
449 * or the hal API version is not supported by this device, this will throw a
450 * RuntimeException.
451 * <p>
452 * You must call {@link #release()} when you are done using the camera,
453 * otherwise it will remain locked and be unavailable to other applications.
454 * <p>
455 * Your application should only have one Camera object active at a time for
456 * a particular hardware camera.
457 * <p>
458 * Callbacks from other methods are delivered to the event loop of the
459 * thread which called open(). If this thread has no event loop, then
460 * callbacks are delivered to the main application event loop. If there is
461 * no main application event loop, callbacks are not delivered.
462 * <p class="caution">
463 * <b>Caution:</b> On some devices, this method may take a long time to
464 * complete. It is best to call this method from a worker thread (possibly
465 * using {@link android.os.AsyncTask}) to avoid blocking the main
466 * application UI thread.
467 *
468 * @param cameraId The hardware camera to access, between 0 and
469 * {@link #getNumberOfCameras()}-1.
Igor Murashkina1d66272014-06-20 11:22:11 -0700470 * @param halVersion The HAL API version this camera device to be opened as.
Zhijun He4c913802014-06-16 16:42:35 -0700471 * @return a new Camera object, connected, locked and ready for use.
Igor Murashkina1d66272014-06-20 11:22:11 -0700472 *
473 * @throws IllegalArgumentException if the {@code halVersion} is invalid
474 *
Zhijun He4c913802014-06-16 16:42:35 -0700475 * @throws RuntimeException if opening the camera fails (for example, if the
476 * camera is in use by another process or device policy manager has disabled
477 * the camera).
Igor Murashkina1d66272014-06-20 11:22:11 -0700478 *
Zhijun He4c913802014-06-16 16:42:35 -0700479 * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
Igor Murashkina1d66272014-06-20 11:22:11 -0700480 * @see #CAMERA_HAL_API_VERSION_1_0
Zhijun He4c913802014-06-16 16:42:35 -0700481 *
482 * @hide
483 */
Mathew Inwood5132cc12018-08-08 15:50:55 +0100484 @UnsupportedAppUsage
Zhijun He4c913802014-06-16 16:42:35 -0700485 public static Camera openLegacy(int cameraId, int halVersion) {
Igor Murashkina1d66272014-06-20 11:22:11 -0700486 if (halVersion < CAMERA_HAL_API_VERSION_1_0) {
487 throw new IllegalArgumentException("Invalid HAL version " + halVersion);
488 }
489
Zhijun He4c913802014-06-16 16:42:35 -0700490 return new Camera(cameraId, halVersion);
491 }
492
493 /**
494 * Create a legacy camera object.
495 *
496 * @param cameraId The hardware camera to access, between 0 and
497 * {@link #getNumberOfCameras()}-1.
498 * @param halVersion The HAL API version this camera device to be opened as.
499 */
500 private Camera(int cameraId, int halVersion) {
Igor Murashkina1d66272014-06-20 11:22:11 -0700501 int err = cameraInitVersion(cameraId, halVersion);
Zhijun He4c913802014-06-16 16:42:35 -0700502 if (checkInitErrors(err)) {
Lazar Trsic8ea56f62015-07-07 17:31:20 +0200503 if (err == -EACCES) {
504 throw new RuntimeException("Fail to connect to camera service");
505 } else if (err == -ENODEV) {
506 throw new RuntimeException("Camera initialization failed");
507 } else if (err == -ENOSYS) {
508 throw new RuntimeException("Camera initialization failed because some methods"
509 + " are not implemented");
510 } else if (err == -EOPNOTSUPP) {
511 throw new RuntimeException("Camera initialization failed because the hal"
512 + " version is not supported by this device");
513 } else if (err == -EINVAL) {
514 throw new RuntimeException("Camera initialization failed because the input"
515 + " arugments are invalid");
516 } else if (err == -EBUSY) {
517 throw new RuntimeException("Camera initialization failed because the camera"
518 + " device was already opened");
519 } else if (err == -EUSERS) {
520 throw new RuntimeException("Camera initialization failed because the max"
521 + " number of camera devices were already opened");
Zhijun He4c913802014-06-16 16:42:35 -0700522 }
Lazar Trsic8ea56f62015-07-07 17:31:20 +0200523 // Should never hit this.
524 throw new RuntimeException("Unknown camera error");
Zhijun He4c913802014-06-16 16:42:35 -0700525 }
526 }
527
Igor Murashkina1d66272014-06-20 11:22:11 -0700528 private int cameraInitVersion(int cameraId, int halVersion) {
Zhijun He4c913802014-06-16 16:42:35 -0700529 mShutterCallback = null;
530 mRawImageCallback = null;
531 mJpegCallback = null;
532 mPreviewCallback = null;
533 mPostviewCallback = null;
534 mUsingPreviewAllocation = false;
535 mZoomListener = null;
Sauhard Pandec44f2d92015-07-09 14:47:34 -0700536 /* ### QC ADD-ONS: START */
537 mCameraDataCallback = null;
538 mCameraMetaDataCallback = null;
539 /* ### QC ADD-ONS: END */
Zhijun He4c913802014-06-16 16:42:35 -0700540
541 Looper looper;
542 if ((looper = Looper.myLooper()) != null) {
543 mEventHandler = new EventHandler(this, looper);
544 } else if ((looper = Looper.getMainLooper()) != null) {
545 mEventHandler = new EventHandler(this, looper);
546 } else {
547 mEventHandler = null;
548 }
549
Svetoslavfbf0eca2015-05-01 16:52:41 -0700550 return native_setup(new WeakReference<Camera>(this), cameraId, halVersion,
551 ActivityThread.currentOpPackageName());
Zhijun He4c913802014-06-16 16:42:35 -0700552 }
553
Igor Murashkina1d66272014-06-20 11:22:11 -0700554 private int cameraInitNormal(int cameraId) {
555 return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT);
556 }
557
558 /**
559 * Connect to the camera service using #connectLegacy
560 *
561 * <p>
562 * This acts the same as normal except that it will return
563 * the detailed error code if open fails instead of
564 * converting everything into {@code NO_INIT}.</p>
565 *
566 * <p>Intended to use by the camera2 shim only, do <i>not</i> use this for other code.</p>
567 *
568 * @return a detailed errno error code, or {@code NO_ERROR} on success
569 *
570 * @hide
571 */
572 public int cameraInitUnspecified(int cameraId) {
573 return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_UNSPECIFIED);
574 }
575
576 /** used by Camera#open, Camera#open(int) */
Wu-cheng Li7bc1b212012-04-19 12:23:31 +0800577 Camera(int cameraId) {
Igor Murashkina1d66272014-06-20 11:22:11 -0700578 int err = cameraInitNormal(cameraId);
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700579 if (checkInitErrors(err)) {
Lazar Trsic8ea56f62015-07-07 17:31:20 +0200580 if (err == -EACCES) {
581 throw new RuntimeException("Fail to connect to camera service");
582 } else if (err == -ENODEV) {
583 throw new RuntimeException("Camera initialization failed");
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700584 }
Lazar Trsic8ea56f62015-07-07 17:31:20 +0200585 // Should never hit this.
586 throw new RuntimeException("Unknown camera error");
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700587 }
jiabin503e1fd2018-04-19 16:39:44 -0700588 initAppOps();
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700589 }
590
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700591
592 /**
593 * @hide
594 */
595 public static boolean checkInitErrors(int err) {
596 return err != NO_ERROR;
597 }
598
599 /**
600 * @hide
601 */
602 public static Camera openUninitialized() {
603 return new Camera();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800605
Wu-cheng Li1c04a332011-11-22 18:21:18 +0800606 /**
607 * An empty Camera for testing purpose.
608 */
Daichi Hirono2dba5c82018-06-25 11:16:41 +0900609 Camera() {}
jiabin503e1fd2018-04-19 16:39:44 -0700610
611 private void initAppOps() {
612 IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE);
613 mAppOps = IAppOpsService.Stub.asInterface(b);
614 // initialize mHasAppOpsPlayAudio
615 updateAppOpsPlayAudio();
616 // register a callback to monitor whether the OP_PLAY_AUDIO is still allowed
617 mAppOpsCallback = new IAppOpsCallbackWrapper(this);
618 try {
619 mAppOps.startWatchingMode(AppOpsManager.OP_PLAY_AUDIO,
620 ActivityThread.currentPackageName(), mAppOpsCallback);
621 } catch (RemoteException e) {
622 Log.e(TAG, "Error registering appOps callback", e);
623 mHasAppOpsPlayAudio = false;
624 }
625 }
626
627 private void releaseAppOps() {
628 try {
629 if (mAppOps != null) {
630 mAppOps.stopWatchingMode(mAppOpsCallback);
631 }
632 } catch (Exception e) {
633 // nothing to do here, the object is supposed to be released anyway
634 }
Wu-cheng Li1c04a332011-11-22 18:21:18 +0800635 }
636
Igor Murashkina1d66272014-06-20 11:22:11 -0700637 @Override
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800638 protected void finalize() {
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -0800639 release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800641
Mathew Inwood5132cc12018-08-08 15:50:55 +0100642 @UnsupportedAppUsage
Zhijun He4c913802014-06-16 16:42:35 -0700643 private native final int native_setup(Object camera_this, int cameraId, int halVersion,
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800644 String packageName);
645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 private native final void native_release();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648
649 /**
650 * Disconnects and releases the Camera object resources.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700651 *
652 * <p>You must call this as soon as you're done with the Camera object.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800654 public final void release() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 native_release();
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800656 mFaceDetectionRunning = false;
jiabin503e1fd2018-04-19 16:39:44 -0700657 releaseAppOps();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 }
659
660 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700661 * Unlocks the camera to allow another process to access it.
662 * Normally, the camera is locked to the process with an active Camera
663 * object until {@link #release()} is called. To allow rapid handoff
664 * between processes, you can call this method to release the camera
665 * temporarily for another process to use; once the other process is done
666 * you can call {@link #reconnect()} to reclaim the camera.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700668 * <p>This must be done before calling
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800669 * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
670 * called after recording starts.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700672 * <p>If you are not recording video, you probably do not need this method.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700674 * @throws RuntimeException if the camera cannot be unlocked.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 */
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800676 public native final void unlock();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700679 * Re-locks the camera to prevent other processes from accessing it.
680 * Camera objects are locked by default unless {@link #unlock()} is
681 * called. Normally {@link #reconnect()} is used instead.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800682 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800683 * <p>Since API level 14, camera is automatically locked for applications in
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800684 * {@link android.media.MediaRecorder#start()}. Applications can use the
685 * camera (ex: zoom) after recording starts. There is no need to call this
686 * after recording starts or stops.
687 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700688 * <p>If you are not recording video, you probably do not need this method.
689 *
690 * @throws RuntimeException if the camera cannot be re-locked (for
691 * example, if the camera is still in use by another process).
692 */
693 public native final void lock();
694
695 /**
696 * Reconnects to the camera service after another process used it.
697 * After {@link #unlock()} is called, another process may use the
698 * camera; when the process is done, you must reconnect to the camera,
699 * which will re-acquire the lock and allow you to continue using the
700 * camera.
701 *
Wu-cheng Li53b30912011-10-12 19:43:51 +0800702 * <p>Since API level 14, camera is automatically locked for applications in
Wu-cheng Li42419ce2011-06-01 17:22:24 +0800703 * {@link android.media.MediaRecorder#start()}. Applications can use the
704 * camera (ex: zoom) after recording starts. There is no need to call this
705 * after recording starts or stops.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700706 *
707 * <p>If you are not recording video, you probably do not need this method.
708 *
709 * @throws IOException if a connection cannot be re-established (for
710 * example, if the camera is still in use by another process).
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700711 * @throws RuntimeException if release() has been called on this Camera
712 * instance.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700713 */
714 public native final void reconnect() throws IOException;
715
716 /**
717 * Sets the {@link Surface} to be used for live preview.
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800718 * Either a surface or surface texture is necessary for preview, and
719 * preview is necessary to take pictures. The same surface can be re-set
720 * without harm. Setting a preview surface will un-set any preview surface
721 * texture that was set via {@link #setPreviewTexture}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700722 *
723 * <p>The {@link SurfaceHolder} must already contain a surface when this
724 * method is called. If you are using {@link android.view.SurfaceView},
725 * you will need to register a {@link SurfaceHolder.Callback} with
726 * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
727 * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
728 * calling setPreviewDisplay() or starting preview.
729 *
730 * <p>This method must be called before {@link #startPreview()}. The
731 * one exception is that if the preview surface is not set (or set to null)
732 * before startPreview() is called, then this method may be called once
733 * with a non-null parameter to set the preview surface. (This allows
734 * camera setup and surface creation to happen in parallel, saving time.)
735 * The preview surface may not otherwise change while preview is running.
736 *
737 * @param holder containing the Surface on which to place the preview,
738 * or null to remove the preview surface
739 * @throws IOException if the method fails (for example, if the surface
740 * is unavailable or unsuitable).
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700741 * @throws RuntimeException if release() has been called on this Camera
742 * instance.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 */
744 public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800745 if (holder != null) {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700746 setPreviewSurface(holder.getSurface());
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800747 } else {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700748 setPreviewSurface((Surface)null);
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800749 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 }
751
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700752 /**
753 * @hide
754 */
Mathew Inwood45d2c252018-09-14 12:35:36 +0100755 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700756 public native final void setPreviewSurface(Surface surface) throws IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757
758 /**
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800759 * Sets the {@link SurfaceTexture} to be used for live preview.
760 * Either a surface or surface texture is necessary for preview, and
761 * preview is necessary to take pictures. The same surface texture can be
762 * re-set without harm. Setting a preview surface texture will un-set any
763 * preview surface that was set via {@link #setPreviewDisplay}.
764 *
765 * <p>This method must be called before {@link #startPreview()}. The
766 * one exception is that if the preview surface texture is not set (or set
767 * to null) before startPreview() is called, then this method may be called
768 * once with a non-null parameter to set the preview surface. (This allows
769 * camera setup and surface creation to happen in parallel, saving time.)
770 * The preview surface texture may not otherwise change while preview is
771 * running.
772 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -0700773 * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
Eino-Ville Talvalae309a0f2011-03-21 11:04:34 -0700774 * SurfaceTexture set as the preview texture have an unspecified zero point,
775 * and cannot be directly compared between different cameras or different
776 * instances of the same camera, or across multiple runs of the same
777 * program.
778 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800779 * <p>If you are using the preview data to create video or still images,
780 * strongly consider using {@link android.media.MediaActionSound} to
781 * properly indicate image capture or recording start/stop to the user.</p>
782 *
783 * @see android.media.MediaActionSound
784 * @see android.graphics.SurfaceTexture
785 * @see android.view.TextureView
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800786 * @param surfaceTexture the {@link SurfaceTexture} to which the preview
787 * images are to be sent or null to remove the current preview surface
788 * texture
789 * @throws IOException if the method fails (for example, if the surface
790 * texture is unavailable or unsuitable).
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700791 * @throws RuntimeException if release() has been called on this Camera
792 * instance.
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800793 */
Glenn Kastendbc289d2011-02-09 10:15:44 -0800794 public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800795
796 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700797 * Callback interface used to deliver copies of preview frames as
798 * they are displayed.
799 *
800 * @see #setPreviewCallback(Camera.PreviewCallback)
801 * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
802 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
803 * @see #startPreview()
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700804 *
805 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
806 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -0700808 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 public interface PreviewCallback
810 {
811 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700812 * Called as preview frames are displayed. This callback is invoked
Dan Egnor341ff132010-07-20 11:30:17 -0700813 * on the event thread {@link #open(int)} was called from.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700815 * <p>If using the {@link android.graphics.ImageFormat#YV12} format,
816 * refer to the equations in {@link Camera.Parameters#setPreviewFormat}
817 * for the arrangement of the pixel data in the preview callback
818 * buffers.
819 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700820 * @param data the contents of the preview frame in the format defined
Mathias Agopiana696f5d2010-02-17 17:53:09 -0800821 * by {@link android.graphics.ImageFormat}, which can be queried
Scott Maindf4578e2009-09-10 12:22:07 -0700822 * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
Scott Mainda0a56d2009-09-10 18:08:37 -0700823 * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800824 * is never called, the default will be the YCbCr_420_SP
825 * (NV21) format.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700826 * @param camera the Camera service object.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 */
828 void onPreviewFrame(byte[] data, Camera camera);
829 };
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700832 * Starts capturing and drawing preview frames to the screen.
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800833 * Preview will not actually start until a surface is supplied
834 * with {@link #setPreviewDisplay(SurfaceHolder)} or
835 * {@link #setPreviewTexture(SurfaceTexture)}.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700836 *
837 * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
838 * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
839 * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
840 * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
841 * will be called when preview data becomes available.
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700842 *
843 * @throws RuntimeException if starting preview fails; usually this would be
844 * because of a hardware or other low-level error, or because release()
Yin-Chia Yeh428256d2019-01-23 15:27:47 -0800845 * has been called on this Camera instance. The QCIF (176x144) exception
846 * mentioned in {@link Parameters#setPreviewSize setPreviewSize} and
847 * {@link Parameters#setPictureSize setPictureSize} can also cause this
848 * exception be thrown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 */
850 public native final void startPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700853 * Stops capturing and drawing preview frames to the surface, and
854 * resets the camera for a future call to {@link #startPreview()}.
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700855 *
856 * @throws RuntimeException if stopping preview fails; usually this would be
857 * because of a hardware or other low-level error, or because release()
858 * has been called on this Camera instance.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 */
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800860 public final void stopPreview() {
861 _stopPreview();
862 mFaceDetectionRunning = false;
Chih-yu Huang664d72e2011-09-23 18:59:38 +0800863
864 mShutterCallback = null;
865 mRawImageCallback = null;
866 mPostviewCallback = null;
867 mJpegCallback = null;
Wu-cheng Lif05c1d62012-05-02 23:29:47 +0800868 synchronized (mAutoFocusCallbackLock) {
869 mAutoFocusCallback = null;
870 }
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800871 mAutoFocusMoveCallback = null;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800872 }
873
874 private native final void _stopPreview();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 /**
877 * Return current preview state.
878 *
879 * FIXME: Unhide before release
880 * @hide
881 */
Mathew Inwood5132cc12018-08-08 15:50:55 +0100882 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 public native final boolean previewEnabled();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +0800884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800886 * <p>Installs a callback to be invoked for every preview frame in addition
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700887 * to displaying them on the screen. The callback will be repeatedly called
888 * for as long as preview is active. This method can be called at any time,
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800889 * even while preview is live. Any other preview callbacks are
890 * overridden.</p>
891 *
892 * <p>If you are using the preview data to create video or still images,
893 * strongly consider using {@link android.media.MediaActionSound} to
894 * properly indicate image capture or recording start/stop to the user.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700896 * @param cb a callback object that receives a copy of each preview frame,
897 * or null to stop receiving callbacks.
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700898 * @throws RuntimeException if release() has been called on this Camera
899 * instance.
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800900 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 */
902 public final void setPreviewCallback(PreviewCallback cb) {
903 mPreviewCallback = cb;
904 mOneShot = false;
Andrew Harp94927df2009-10-20 01:47:05 -0400905 mWithBuffer = false;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700906 if (cb != null) {
907 mUsingPreviewAllocation = false;
908 }
Dave Sparksa6118c62009-10-13 02:28:54 -0700909 // Always use one-shot mode. We fake camera preview mode by
910 // doing one-shot preview continuously.
Andrew Harp94927df2009-10-20 01:47:05 -0400911 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 }
913
914 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800915 * <p>Installs a callback to be invoked for the next preview frame in
916 * addition to displaying it on the screen. After one invocation, the
917 * callback is cleared. This method can be called any time, even when
918 * preview is live. Any other preview callbacks are overridden.</p>
919 *
920 * <p>If you are using the preview data to create video or still images,
921 * strongly consider using {@link android.media.MediaActionSound} to
922 * properly indicate image capture or recording start/stop to the user.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700924 * @param cb a callback object that receives a copy of the next preview frame,
925 * or null to stop receiving callbacks.
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700926 * @throws RuntimeException if release() has been called on this Camera
927 * instance.
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800928 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 */
930 public final void setOneShotPreviewCallback(PreviewCallback cb) {
Andrew Harp94927df2009-10-20 01:47:05 -0400931 mPreviewCallback = cb;
932 mOneShot = true;
933 mWithBuffer = false;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700934 if (cb != null) {
935 mUsingPreviewAllocation = false;
936 }
Andrew Harp94927df2009-10-20 01:47:05 -0400937 setHasPreviewCallback(cb != null, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 }
939
Andrew Harp94927df2009-10-20 01:47:05 -0400940 private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
941
942 /**
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800943 * <p>Installs a callback to be invoked for every preview frame, using
944 * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700945 * displaying them on the screen. The callback will be repeatedly called
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800946 * for as long as preview is active and buffers are available. Any other
947 * preview callbacks are overridden.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400948 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700949 * <p>The purpose of this method is to improve preview efficiency and frame
950 * rate by allowing preview frame memory reuse. You must call
951 * {@link #addCallbackBuffer(byte[])} at some point -- before or after
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800952 * calling this method -- or no callbacks will received.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400953 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800954 * <p>The buffer queue will be cleared if this method is called with a null
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700955 * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800956 * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is
957 * called.</p>
958 *
959 * <p>If you are using the preview data to create video or still images,
960 * strongly consider using {@link android.media.MediaActionSound} to
961 * properly indicate image capture or recording start/stop to the user.</p>
Andrew Harp94927df2009-10-20 01:47:05 -0400962 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700963 * @param cb a callback object that receives a copy of the preview frame,
964 * or null to stop receiving callbacks and clear the buffer queue.
Eino-Ville Talvala06a77182017-09-15 12:43:24 -0700965 * @throws RuntimeException if release() has been called on this Camera
966 * instance.
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700967 * @see #addCallbackBuffer(byte[])
Eino-Ville Talvala108708b2012-03-05 11:00:43 -0800968 * @see android.media.MediaActionSound
Andrew Harp94927df2009-10-20 01:47:05 -0400969 */
970 public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
971 mPreviewCallback = cb;
972 mOneShot = false;
973 mWithBuffer = true;
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700974 if (cb != null) {
975 mUsingPreviewAllocation = false;
976 }
Andrew Harp94927df2009-10-20 01:47:05 -0400977 setHasPreviewCallback(cb != null, true);
978 }
979
980 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +0800981 * Adds a pre-allocated buffer to the preview callback buffer queue.
982 * Applications can add one or more buffers to the queue. When a preview
Dan Egnorbfcbeff2010-07-12 15:12:54 -0700983 * frame arrives and there is still at least one available buffer, the
984 * buffer will be used and removed from the queue. Then preview callback is
985 * invoked with the buffer. If a frame arrives and there is no buffer left,
986 * the frame is discarded. Applications should add buffers back when they
987 * finish processing the data in them.
Wu-cheng Lic10275a2010-03-09 13:49:21 -0800988 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -0700989 * <p>For formats besides YV12, the size of the buffer is determined by
990 * multiplying the preview image width, height, and bytes per pixel. The
991 * width and height can be read from
992 * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be
993 * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} /
994 * 8, using the image format from
995 * {@link Camera.Parameters#getPreviewFormat()}.
996 *
997 * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the
998 * size can be calculated using the equations listed in
999 * {@link Camera.Parameters#setPreviewFormat}.
Andrew Harp94927df2009-10-20 01:47:05 -04001000 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001001 * <p>This method is only necessary when
James Donge00cab72011-02-17 16:38:06 -08001002 * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001003 * {@link #setPreviewCallback(PreviewCallback)} or
1004 * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
James Donge00cab72011-02-17 16:38:06 -08001005 * are automatically allocated. When a supplied buffer is too small to
1006 * hold the preview frame data, preview callback will return null and
1007 * the buffer will be removed from the buffer queue.
Andrew Harp94927df2009-10-20 01:47:05 -04001008 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -07001009 * @param callbackBuffer the buffer to add to the queue. The size of the
1010 * buffer must match the values described above.
Wu-cheng Li5b9bcda2010-03-07 14:59:28 -08001011 * @see #setPreviewCallbackWithBuffer(PreviewCallback)
Andrew Harp94927df2009-10-20 01:47:05 -04001012 */
James Donge00cab72011-02-17 16:38:06 -08001013 public final void addCallbackBuffer(byte[] callbackBuffer)
1014 {
1015 _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
1016 }
1017
1018 /**
1019 * Adds a pre-allocated buffer to the raw image callback buffer queue.
1020 * Applications can add one or more buffers to the queue. When a raw image
1021 * frame arrives and there is still at least one available buffer, the
1022 * buffer will be used to hold the raw image data and removed from the
1023 * queue. Then raw image callback is invoked with the buffer. If a raw
1024 * image frame arrives but there is no buffer left, the frame is
1025 * discarded. Applications should add buffers back when they finish
1026 * processing the data in them by calling this method again in order
1027 * to avoid running out of raw image callback buffers.
1028 *
1029 * <p>The size of the buffer is determined by multiplying the raw image
1030 * width, height, and bytes per pixel. The width and height can be
1031 * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
1032 * can be computed from
1033 * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
1034 * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
1035 *
1036 * <p>This method is only necessary when the PictureCallbck for raw image
1037 * is used while calling {@link #takePicture(Camera.ShutterCallback,
1038 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
1039 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07001040 * <p>Please note that by calling this method, the mode for
1041 * application-managed callback buffers is triggered. If this method has
1042 * never been called, null will be returned by the raw image callback since
1043 * there is no image callback buffer available. Furthermore, When a supplied
1044 * buffer is too small to hold the raw image data, raw image callback will
1045 * return null and the buffer will be removed from the buffer queue.
James Donge00cab72011-02-17 16:38:06 -08001046 *
1047 * @param callbackBuffer the buffer to add to the raw image callback buffer
1048 * queue. The size should be width * height * (bits per pixel) / 8. An
1049 * null callbackBuffer will be ignored and won't be added to the queue.
1050 *
1051 * @see #takePicture(Camera.ShutterCallback,
1052 * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
1053 *
1054 * {@hide}
1055 */
Mathew Inwood5132cc12018-08-08 15:50:55 +01001056 @UnsupportedAppUsage
James Donge00cab72011-02-17 16:38:06 -08001057 public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
1058 {
1059 addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
1060 }
1061
Mathew Inwood5132cc12018-08-08 15:50:55 +01001062 @UnsupportedAppUsage
James Donge00cab72011-02-17 16:38:06 -08001063 private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
1064 {
1065 // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
1066 if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
1067 msgType != CAMERA_MSG_RAW_IMAGE) {
1068 throw new IllegalArgumentException(
1069 "Unsupported message type: " + msgType);
1070 }
1071
1072 _addCallbackBuffer(callbackBuffer, msgType);
1073 }
1074
1075 private native final void _addCallbackBuffer(
1076 byte[] callbackBuffer, int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077
Eino-Ville Talvala7005b672013-04-02 15:46:38 -07001078 /**
1079 * <p>Create a {@link android.renderscript RenderScript}
1080 * {@link android.renderscript.Allocation Allocation} to use as a
1081 * destination of preview callback frames. Use
1082 * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use
1083 * the created Allocation as a destination for camera preview frames.</p>
1084 *
1085 * <p>The Allocation will be created with a YUV type, and its contents must
1086 * be accessed within Renderscript with the {@code rsGetElementAtYuv_*}
1087 * accessor methods. Its size will be based on the current
1088 * {@link Parameters#getPreviewSize preview size} configured for this
1089 * camera.</p>
1090 *
1091 * @param rs the RenderScript context for this Allocation.
1092 * @param usage additional usage flags to set for the Allocation. The usage
1093 * flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always
1094 * be set on the created Allocation, but additional flags may be provided
1095 * here.
1096 * @return a new YUV-type Allocation with dimensions equal to the current
1097 * preview size.
1098 * @throws RSIllegalArgumentException if the usage flags are not compatible
1099 * with an YUV Allocation.
1100 * @see #setPreviewCallbackAllocation
1101 * @hide
1102 */
1103 public final Allocation createPreviewAllocation(RenderScript rs, int usage)
1104 throws RSIllegalArgumentException {
1105 Parameters p = getParameters();
1106 Size previewSize = p.getPreviewSize();
1107 Type.Builder yuvBuilder = new Type.Builder(rs,
1108 Element.createPixel(rs,
1109 Element.DataType.UNSIGNED_8,
1110 Element.DataKind.PIXEL_YUV));
1111 // Use YV12 for wide compatibility. Changing this requires also
1112 // adjusting camera service's format selection.
1113 yuvBuilder.setYuvFormat(ImageFormat.YV12);
1114 yuvBuilder.setX(previewSize.width);
1115 yuvBuilder.setY(previewSize.height);
1116
1117 Allocation a = Allocation.createTyped(rs, yuvBuilder.create(),
1118 usage | Allocation.USAGE_IO_INPUT);
1119
1120 return a;
1121 }
1122
1123 /**
1124 * <p>Set an {@link android.renderscript.Allocation Allocation} as the
1125 * target of preview callback data. Use this method for efficient processing
1126 * of camera preview data with RenderScript. The Allocation must be created
1127 * with the {@link #createPreviewAllocation createPreviewAllocation }
1128 * method.</p>
1129 *
1130 * <p>Setting a preview allocation will disable any active preview callbacks
1131 * set by {@link #setPreviewCallback setPreviewCallback} or
1132 * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and
1133 * vice versa. Using a preview allocation still requires an active standard
1134 * preview target to be set, either with
1135 * {@link #setPreviewTexture setPreviewTexture} or
1136 * {@link #setPreviewDisplay setPreviewDisplay}.</p>
1137 *
1138 * <p>To be notified when new frames are available to the Allocation, use
1139 * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To
1140 * update the frame currently accessible from the Allocation to the latest
1141 * preview frame, call
1142 * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p>
1143 *
1144 * <p>To disable preview into the Allocation, call this method with a
1145 * {@code null} parameter.</p>
1146 *
1147 * <p>Once a preview allocation is set, the preview size set by
1148 * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If
1149 * you wish to change the preview size, first remove the preview allocation
1150 * by calling {@code setPreviewCallbackAllocation(null)}, then change the
1151 * preview size, create a new preview Allocation with
1152 * {@link #createPreviewAllocation createPreviewAllocation}, and set it as
1153 * the new preview callback allocation target.</p>
1154 *
1155 * <p>If you are using the preview data to create video or still images,
1156 * strongly consider using {@link android.media.MediaActionSound} to
1157 * properly indicate image capture or recording start/stop to the user.</p>
1158 *
1159 * @param previewAllocation the allocation to use as destination for preview
1160 * @throws IOException if configuring the camera to use the Allocation for
1161 * preview fails.
1162 * @throws IllegalArgumentException if the Allocation's dimensions or other
1163 * parameters don't meet the requirements.
1164 * @see #createPreviewAllocation
1165 * @see #setPreviewCallback
1166 * @see #setPreviewCallbackWithBuffer
1167 * @hide
1168 */
1169 public final void setPreviewCallbackAllocation(Allocation previewAllocation)
1170 throws IOException {
1171 Surface previewSurface = null;
1172 if (previewAllocation != null) {
1173 Parameters p = getParameters();
1174 Size previewSize = p.getPreviewSize();
1175 if (previewSize.width != previewAllocation.getType().getX() ||
1176 previewSize.height != previewAllocation.getType().getY()) {
1177 throw new IllegalArgumentException(
1178 "Allocation dimensions don't match preview dimensions: " +
1179 "Allocation is " +
1180 previewAllocation.getType().getX() +
1181 ", " +
1182 previewAllocation.getType().getY() +
1183 ". Preview is " + previewSize.width + ", " +
1184 previewSize.height);
1185 }
1186 if ((previewAllocation.getUsage() &
1187 Allocation.USAGE_IO_INPUT) == 0) {
1188 throw new IllegalArgumentException(
1189 "Allocation usage does not include USAGE_IO_INPUT");
1190 }
1191 if (previewAllocation.getType().getElement().getDataKind() !=
1192 Element.DataKind.PIXEL_YUV) {
1193 throw new IllegalArgumentException(
1194 "Allocation is not of a YUV type");
1195 }
1196 previewSurface = previewAllocation.getSurface();
1197 mUsingPreviewAllocation = true;
1198 } else {
1199 mUsingPreviewAllocation = false;
1200 }
1201 setPreviewCallbackSurface(previewSurface);
1202 }
1203
1204 private native final void setPreviewCallbackSurface(Surface s);
1205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 private class EventHandler extends Handler
1207 {
Igor Murashkina1d66272014-06-20 11:22:11 -07001208 private final Camera mCamera;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209
David Brazdil982df3b2019-03-07 17:41:03 +00001210 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 public EventHandler(Camera c, Looper looper) {
1212 super(looper);
1213 mCamera = c;
1214 }
1215
1216 @Override
1217 public void handleMessage(Message msg) {
1218 switch(msg.what) {
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001219 case CAMERA_MSG_SHUTTER:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 if (mShutterCallback != null) {
1221 mShutterCallback.onShutter();
1222 }
1223 return;
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001224
1225 case CAMERA_MSG_RAW_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -07001226 if (mRawImageCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 return;
1230
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001231 case CAMERA_MSG_COMPRESSED_IMAGE:
Dave Sparkse8b26e12009-07-14 10:35:40 -07001232 if (mJpegCallback != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001236
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001237 case CAMERA_MSG_PREVIEW_FRAME:
Eino-Ville Talvalaca367b72012-05-30 16:01:33 -07001238 PreviewCallback pCb = mPreviewCallback;
1239 if (pCb != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 if (mOneShot) {
Dave Sparksa6118c62009-10-13 02:28:54 -07001241 // Clear the callback variable before the callback
1242 // in case the app calls setPreviewCallback from
1243 // the callback function
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 mPreviewCallback = null;
Andrew Harp94927df2009-10-20 01:47:05 -04001245 } else if (!mWithBuffer) {
Dave Sparksa6118c62009-10-13 02:28:54 -07001246 // We're faking the camera preview mode to prevent
1247 // the app from being flooded with preview frames.
1248 // Set to oneshot mode again.
Andrew Harp94927df2009-10-20 01:47:05 -04001249 setHasPreviewCallback(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 }
Eino-Ville Talvalaca367b72012-05-30 16:01:33 -07001251 pCb.onPreviewFrame((byte[])msg.obj, mCamera);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 }
1253 return;
1254
Dave Sparkse8b26e12009-07-14 10:35:40 -07001255 case CAMERA_MSG_POSTVIEW_FRAME:
1256 if (mPostviewCallback != null) {
1257 mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
1258 }
1259 return;
1260
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001261 case CAMERA_MSG_FOCUS:
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001262 AutoFocusCallback cb = null;
1263 synchronized (mAutoFocusCallbackLock) {
1264 cb = mAutoFocusCallback;
1265 }
1266 if (cb != null) {
1267 boolean success = msg.arg1 == 0 ? false : true;
1268 cb.onAutoFocus(success, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001269 }
1270 return;
1271
1272 case CAMERA_MSG_ZOOM:
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001273 if (mZoomListener != null) {
1274 mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 return;
1277
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001278 case CAMERA_MSG_PREVIEW_METADATA:
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001279 if (mFaceListener != null) {
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001280 mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001281 }
1282 return;
1283
Dave Sparksc62f9bd2009-06-26 13:33:32 -07001284 case CAMERA_MSG_ERROR :
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 Log.e(TAG, "Error " + msg.arg1);
Yin-Chia Yeha07cd322018-05-31 12:11:42 -07001286 if (mDetailedErrorCallback != null) {
1287 mDetailedErrorCallback.onError(msg.arg1, mCamera);
1288 } else if (mErrorCallback != null) {
1289 if (msg.arg1 == CAMERA_ERROR_DISABLED) {
1290 mErrorCallback.onError(CAMERA_ERROR_EVICTED, mCamera);
1291 } else {
1292 mErrorCallback.onError(msg.arg1, mCamera);
1293 }
Dave Sparkse8b26e12009-07-14 10:35:40 -07001294 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 return;
1296
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001297 case CAMERA_MSG_FOCUS_MOVE:
1298 if (mAutoFocusMoveCallback != null) {
1299 mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera);
1300 }
1301 return;
Sauhard Pandec44f2d92015-07-09 14:47:34 -07001302 /* ### QC ADD-ONS: START */
1303 case CAMERA_MSG_STATS_DATA:
1304 int statsdata[] = new int[257];
1305 for(int i =0; i<257; i++ ) {
1306 statsdata[i] = byteToInt( (byte[])msg.obj, i*4);
1307 }
1308 if (mCameraDataCallback != null) {
1309 mCameraDataCallback.onCameraData(statsdata, mCamera);
1310 }
1311 return;
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001312
Sauhard Pandec44f2d92015-07-09 14:47:34 -07001313 case CAMERA_MSG_META_DATA:
1314 if (mCameraMetaDataCallback != null) {
1315 mCameraMetaDataCallback.onCameraMetaData((byte[])msg.obj, mCamera);
1316 }
1317 return;
1318 /* ### QC ADD-ONS: END */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 default:
1320 Log.e(TAG, "Unknown message type " + msg.what);
1321 return;
1322 }
1323 }
1324 }
1325
Mathew Inwood5132cc12018-08-08 15:50:55 +01001326 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 private static void postEventFromNative(Object camera_ref,
1328 int what, int arg1, int arg2, Object obj)
1329 {
1330 Camera c = (Camera)((WeakReference)camera_ref).get();
1331 if (c == null)
1332 return;
1333
1334 if (c.mEventHandler != null) {
1335 Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
1336 c.mEventHandler.sendMessage(m);
1337 }
1338 }
1339
1340 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001341 * Callback interface used to notify on completion of camera auto focus.
1342 *
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001343 * <p>Devices that do not support auto-focus will receive a "fake"
1344 * callback to this interface. If your application needs auto-focus and
Scott Maindf4578e2009-09-10 12:22:07 -07001345 * should not be installed on devices <em>without</em> auto-focus, you must
1346 * declare that your app uses the
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001347 * {@code android.hardware.camera.autofocus} feature, in the
Scott Maindf4578e2009-09-10 12:22:07 -07001348 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1349 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001350 *
1351 * @see #autoFocus(AutoFocusCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001352 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1353 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001355 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 public interface AutoFocusCallback
1357 {
1358 /**
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001359 * Called when the camera auto focus completes. If the camera
1360 * does not support auto-focus and autoFocus is called,
1361 * onAutoFocus will be called immediately with a fake value of
1362 * <code>success</code> set to <code>true</code>.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001363 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08001364 * The auto-focus routine does not lock auto-exposure and auto-white
1365 * balance after it completes.
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001366 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367 * @param success true if focus was successful, false if otherwise
1368 * @param camera the Camera service object
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001369 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
1370 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 */
1372 void onAutoFocus(boolean success, Camera camera);
Wu-cheng Li53b30912011-10-12 19:43:51 +08001373 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374
1375 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001376 * Starts camera auto-focus and registers a callback function to run when
1377 * the camera is focused. This method is only valid when preview is active
1378 * (between {@link #startPreview()} and before {@link #stopPreview()}).
1379 *
1380 * <p>Callers should check
1381 * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
1382 * this method should be called. If the camera does not support auto-focus,
1383 * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
Wu-cheng Li36322db2009-09-18 18:59:21 +08001384 * callback will be called immediately.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001385 *
Scott Mainda0a56d2009-09-10 18:08:37 -07001386 * <p>If your application should not be installed
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001387 * on devices without auto-focus, you must declare that your application
1388 * uses auto-focus with the
Scott Maindf4578e2009-09-10 12:22:07 -07001389 * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1390 * manifest element.</p>
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001391 *
Wu-cheng Li068ef422009-09-27 13:19:36 -07001392 * <p>If the current flash mode is not
1393 * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001394 * fired during auto-focus, depending on the driver and camera hardware.<p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08001395 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001396 * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()}
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08001397 * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
1398 * do not change during and after autofocus. But auto-focus routine may stop
1399 * auto-exposure and auto-white balance transiently during focusing.
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001400 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001401 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
1402 * image capture with {@link #takePicture(Camera.ShutterCallback,
1403 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
1404 * the focus position. Applications must call cancelAutoFocus to reset the
1405 * focus.</p>
1406 *
Eino-Ville Talvala108708b2012-03-05 11:00:43 -08001407 * <p>If autofocus is successful, consider using
1408 * {@link android.media.MediaActionSound} to properly play back an autofocus
1409 * success sound to the user.</p>
1410 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 * @param cb the callback to run
Eino-Ville Talvala06a77182017-09-15 12:43:24 -07001412 * @throws RuntimeException if starting autofocus fails; usually this would
1413 * be because of a hardware or other low-level error, or because
1414 * release() has been called on this Camera instance.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001415 * @see #cancelAutoFocus()
Eino-Ville Talvala83d33522011-05-13 10:25:00 -07001416 * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
1417 * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
Eino-Ville Talvala108708b2012-03-05 11:00:43 -08001418 * @see android.media.MediaActionSound
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 */
1420 public final void autoFocus(AutoFocusCallback cb)
1421 {
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001422 synchronized (mAutoFocusCallbackLock) {
James Dong248ba232012-04-28 21:30:46 -07001423 mAutoFocusCallback = cb;
James Dong248ba232012-04-28 21:30:46 -07001424 }
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001425 native_autoFocus();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 }
1427 private native final void native_autoFocus();
1428
1429 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001430 * Cancels any auto-focus function in progress.
1431 * Whether or not auto-focus is currently in progress,
1432 * this function will return the focus position to the default.
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001433 * If the camera does not support auto-focus, this is a no-op.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001434 *
Eino-Ville Talvala06a77182017-09-15 12:43:24 -07001435 * @throws RuntimeException if canceling autofocus fails; usually this would
1436 * be because of a hardware or other low-level error, or because
1437 * release() has been called on this Camera instance.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001438 * @see #autoFocus(Camera.AutoFocusCallback)
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001439 */
1440 public final void cancelAutoFocus()
1441 {
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001442 synchronized (mAutoFocusCallbackLock) {
James Dong248ba232012-04-28 21:30:46 -07001443 mAutoFocusCallback = null;
James Dong248ba232012-04-28 21:30:46 -07001444 }
Wu-cheng Lif05c1d62012-05-02 23:29:47 +08001445 native_cancelAutoFocus();
1446 // CAMERA_MSG_FOCUS should be removed here because the following
1447 // scenario can happen:
1448 // - An application uses the same thread for autoFocus, cancelAutoFocus
1449 // and looper thread.
1450 // - The application calls autoFocus.
1451 // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue.
1452 // Before event handler's handleMessage() is invoked, the application
1453 // calls cancelAutoFocus and autoFocus.
1454 // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus
1455 // has been completed. But in fact it is not.
1456 //
1457 // As documented in the beginning of the file, apps should not use
1458 // multiple threads to call autoFocus and cancelAutoFocus at the same
1459 // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS
1460 // message after native_cancelAutoFocus is called.
1461 mEventHandler.removeMessages(CAMERA_MSG_FOCUS);
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001462 }
1463 private native final void native_cancelAutoFocus();
1464
1465 /**
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001466 * Callback interface used to notify on auto focus start and stop.
1467 *
Wu-cheng Li65745392012-04-12 18:07:16 +08001468 * <p>This is only supported in continuous autofocus modes -- {@link
1469 * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link
1470 * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show
1471 * autofocus animation based on this.</p>
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001472 *
1473 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1474 * applications.
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001475 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001476 @Deprecated
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001477 public interface AutoFocusMoveCallback
1478 {
1479 /**
1480 * Called when the camera auto focus starts or stops.
1481 *
1482 * @param start true if focus starts to move, false if focus stops to move
Wu-cheng Li65745392012-04-12 18:07:16 +08001483 * @param camera the Camera service object
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001484 */
1485 void onAutoFocusMoving(boolean start, Camera camera);
1486 }
1487
1488 /**
1489 * Sets camera auto-focus move callback.
1490 *
1491 * @param cb the callback to run
Eino-Ville Talvala06a77182017-09-15 12:43:24 -07001492 * @throws RuntimeException if enabling the focus move callback fails;
1493 * usually this would be because of a hardware or other low-level error,
1494 * or because release() has been called on this Camera instance.
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001495 */
1496 public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) {
1497 mAutoFocusMoveCallback = cb;
1498 enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0);
1499 }
1500
1501 private native void enableFocusMoveCallback(int enable);
1502
1503 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001504 * Callback interface used to signal the moment of actual image capture.
1505 *
1506 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001507 *
1508 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1509 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001511 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 public interface ShutterCallback
1513 {
1514 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001515 * Called as near as possible to the moment when a photo is captured
1516 * from the sensor. This is a good opportunity to play a shutter sound
1517 * or give other feedback of camera operation. This may be some time
1518 * after the photo was triggered, but some time before the actual data
1519 * is available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 */
1521 void onShutter();
1522 }
1523
1524 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001525 * Callback interface used to supply image data from a photo capture.
1526 *
1527 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001528 *
1529 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1530 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001532 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 public interface PictureCallback {
1534 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001535 * Called when image data is available after a picture is taken.
1536 * The format of the data depends on the context of the callback
1537 * and {@link Camera.Parameters} settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001538 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 * @param data a byte array of the picture data
1540 * @param camera the Camera service object
1541 */
1542 void onPictureTaken(byte[] data, Camera camera);
1543 };
1544
1545 /**
Eino-Ville Talvala06a77182017-09-15 12:43:24 -07001546 * Equivalent to <pre>takePicture(Shutter, raw, null, jpeg)</pre>.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001547 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001548 * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 */
1550 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1551 PictureCallback jpeg) {
Dave Sparkse8b26e12009-07-14 10:35:40 -07001552 takePicture(shutter, raw, null, jpeg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 }
James Donge00cab72011-02-17 16:38:06 -08001554 private native final void native_takePicture(int msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555
Dave Sparkse8b26e12009-07-14 10:35:40 -07001556 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001557 * Triggers an asynchronous image capture. The camera service will initiate
1558 * a series of callbacks to the application as the image capture progresses.
1559 * The shutter callback occurs after the image is captured. This can be used
1560 * to trigger a sound to let the user know that image has been captured. The
1561 * raw callback occurs when the raw image data is available (NOTE: the data
James Donge00cab72011-02-17 16:38:06 -08001562 * will be null if there is no raw image callback buffer available or the
1563 * raw image callback buffer is not large enough to hold the raw image).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001564 * The postview callback occurs when a scaled, fully processed postview
1565 * image is available (NOTE: not all hardware supports this). The jpeg
1566 * callback occurs when the compressed image is available. If the
1567 * application does not need a particular callback, a null can be passed
1568 * instead of a callback method.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001569 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001570 * <p>This method is only valid when preview is active (after
1571 * {@link #startPreview()}). Preview will be stopped after the image is
1572 * taken; callers must call {@link #startPreview()} again if they want to
Wu-cheng Li42419ce2011-06-01 17:22:24 +08001573 * re-start preview or take more pictures. This should not be called between
1574 * {@link android.media.MediaRecorder#start()} and
1575 * {@link android.media.MediaRecorder#stop()}.
Wu-cheng Li40057ce2009-12-02 18:57:29 +08001576 *
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001577 * <p>After calling this method, you must not call {@link #startPreview()}
1578 * or take another picture until the JPEG callback has returned.
1579 *
1580 * @param shutter the callback for image capture moment, or null
1581 * @param raw the callback for raw (uncompressed) image data, or null
Dave Sparkse8b26e12009-07-14 10:35:40 -07001582 * @param postview callback with postview image data, may be null
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001583 * @param jpeg the callback for JPEG image data, or null
Eino-Ville Talvala06a77182017-09-15 12:43:24 -07001584 * @throws RuntimeException if starting picture capture fails; usually this
1585 * would be because of a hardware or other low-level error, or because
1586 * release() has been called on this Camera instance.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001587 */
1588 public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1589 PictureCallback postview, PictureCallback jpeg) {
1590 mShutterCallback = shutter;
1591 mRawImageCallback = raw;
1592 mPostviewCallback = postview;
1593 mJpegCallback = jpeg;
James Donge00cab72011-02-17 16:38:06 -08001594
1595 // If callback is not set, do not send me callbacks.
1596 int msgType = 0;
1597 if (mShutterCallback != null) {
1598 msgType |= CAMERA_MSG_SHUTTER;
1599 }
1600 if (mRawImageCallback != null) {
1601 msgType |= CAMERA_MSG_RAW_IMAGE;
1602 }
1603 if (mPostviewCallback != null) {
1604 msgType |= CAMERA_MSG_POSTVIEW_FRAME;
1605 }
1606 if (mJpegCallback != null) {
1607 msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
1608 }
1609
1610 native_takePicture(msgType);
Wu-cheng Lie9c6c9c2012-05-29 16:47:44 +08001611 mFaceDetectionRunning = false;
Dave Sparkse8b26e12009-07-14 10:35:40 -07001612 }
1613
1614 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001615 * Zooms to the requested value smoothly. The driver will notify {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001616 * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
1617 * the time. For example, suppose the current zoom is 0 and startSmoothZoom
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001618 * is called with value 3. The
1619 * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
1620 * method will be called three times with zoom values 1, 2, and 3.
1621 * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
1622 * Applications should not call startSmoothZoom again or change the zoom
1623 * value before zoom stops. If the supplied zoom value equals to the current
1624 * zoom value, no zoom callback will be generated. This method is supported
1625 * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
1626 * returns true.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001627 *
1628 * @param value zoom value. The valid range is 0 to {@link
1629 * android.hardware.Camera.Parameters#getMaxZoom}.
Wu-cheng Li0ca25192010-03-29 16:21:12 +08001630 * @throws IllegalArgumentException if the zoom value is invalid.
1631 * @throws RuntimeException if the method fails.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001632 * @see #setZoomChangeListener(OnZoomChangeListener)
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001633 */
1634 public native final void startSmoothZoom(int value);
1635
1636 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001637 * Stops the smooth zoom. Applications should wait for the {@link
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001638 * OnZoomChangeListener} to know when the zoom is actually stopped. This
1639 * method is supported if {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001640 * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
Wu-cheng Li0ca25192010-03-29 16:21:12 +08001641 *
1642 * @throws RuntimeException if the method fails.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001643 */
1644 public native final void stopSmoothZoom();
1645
1646 /**
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001647 * Set the clockwise rotation of preview display in degrees. This affects
1648 * the preview frames and the picture displayed after snapshot. This method
1649 * is useful for portrait mode applications. Note that preview display of
Wu-cheng Lib982fb42010-10-19 17:19:09 +08001650 * front-facing cameras is flipped horizontally before the rotation, that
1651 * is, the image is reflected along the central vertical axis of the camera
1652 * sensor. So the users can see themselves as looking into a mirror.
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001653 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001654 * <p>This does not affect the order of byte array passed in {@link
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001655 * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
1656 * method is not allowed to be called during preview.
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001657 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08001658 * <p>If you want to make the camera image show in the same orientation as
1659 * the display, you can use the following code.
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001660 * <pre>
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001661 * public static void setCameraDisplayOrientation(Activity activity,
1662 * int cameraId, android.hardware.Camera camera) {
1663 * android.hardware.Camera.CameraInfo info =
1664 * new android.hardware.Camera.CameraInfo();
1665 * android.hardware.Camera.getCameraInfo(cameraId, info);
1666 * int rotation = activity.getWindowManager().getDefaultDisplay()
1667 * .getRotation();
1668 * int degrees = 0;
1669 * switch (rotation) {
1670 * case Surface.ROTATION_0: degrees = 0; break;
1671 * case Surface.ROTATION_90: degrees = 90; break;
1672 * case Surface.ROTATION_180: degrees = 180; break;
1673 * case Surface.ROTATION_270: degrees = 270; break;
1674 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001675 *
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001676 * int result;
1677 * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
1678 * result = (info.orientation + degrees) % 360;
1679 * result = (360 - result) % 360; // compensate the mirror
1680 * } else { // back-facing
1681 * result = (info.orientation - degrees + 360) % 360;
1682 * }
Chih-Chung Chang724c5222010-06-14 18:57:15 +08001683 * camera.setDisplayOrientation(result);
1684 * }
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001685 * </pre>
Wu-cheng Lid3033622011-10-07 13:13:54 +08001686 *
1687 * <p>Starting from API level 14, this method can be called when preview is
1688 * active.
1689 *
Eino-Ville Talvala6c91e2c2016-03-25 11:54:39 -07001690 * <p><b>Note: </b>Before API level 24, the default value for orientation is 0. Starting in
1691 * API level 24, the default orientation will be such that applications in forced-landscape mode
1692 * will have correct preview orientation, which may be either a default of 0 or
1693 * 180. Applications that operate in portrait mode or allow for changing orientation must still
1694 * call this method after each orientation change to ensure correct preview display in all
1695 * cases.</p>
1696 *
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001697 * @param degrees the angle that the picture will be rotated clockwise.
Eino-Ville Talvala6c91e2c2016-03-25 11:54:39 -07001698 * Valid values are 0, 90, 180, and 270.
Eino-Ville Talvala06a77182017-09-15 12:43:24 -07001699 * @throws RuntimeException if setting orientation fails; usually this would
1700 * be because of a hardware or other low-level error, or because
1701 * release() has been called on this Camera instance.
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08001702 * @see #setPreviewDisplay(SurfaceHolder)
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001703 */
1704 public native final void setDisplayOrientation(int degrees);
1705
1706 /**
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001707 * <p>Enable or disable the default shutter sound when taking a picture.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001708 *
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001709 * <p>By default, the camera plays the system-defined camera shutter sound
1710 * when {@link #takePicture} is called. Using this method, the shutter sound
1711 * can be disabled. It is strongly recommended that an alternative shutter
1712 * sound is played in the {@link ShutterCallback} when the system shutter
1713 * sound is disabled.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001714 *
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001715 * <p>Note that devices may not always allow disabling the camera shutter
1716 * sound. If the shutter sound state cannot be set to the desired value,
1717 * this method will return false. {@link CameraInfo#canDisableShutterSound}
1718 * can be used to determine whether the device will allow the shutter sound
1719 * to be disabled.</p>
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001720 *
1721 * @param enabled whether the camera should play the system shutter sound
1722 * when {@link #takePicture takePicture} is called.
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001723 * @return {@code true} if the shutter sound state was successfully
1724 * changed. {@code false} if the shutter sound state could not be
1725 * changed. {@code true} is also returned if shutter sound playback
1726 * is already set to the requested state.
Eino-Ville Talvala06a77182017-09-15 12:43:24 -07001727 * @throws RuntimeException if the call fails; usually this would be because
1728 * of a hardware or other low-level error, or because release() has been
1729 * called on this Camera instance.
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001730 * @see #takePicture
Eino-Ville Talvala487acdf2012-09-24 11:30:24 -07001731 * @see CameraInfo#canDisableShutterSound
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001732 * @see ShutterCallback
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001733 */
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001734 public final boolean enableShutterSound(boolean enabled) {
jiabine059e452018-05-07 15:16:44 -07001735 boolean canDisableShutterSound = true;
1736 IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
1737 IAudioService audioService = IAudioService.Stub.asInterface(b);
1738 try {
1739 if (audioService.isCameraSoundForced()) {
1740 canDisableShutterSound = false;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001741 }
jiabine059e452018-05-07 15:16:44 -07001742 } catch (RemoteException e) {
1743 Log.e(TAG, "Audio service is unavailable for queries");
1744 }
1745 if (!enabled && !canDisableShutterSound) {
1746 return false;
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001747 }
jiabin503e1fd2018-04-19 16:39:44 -07001748 synchronized (mShutterSoundLock) {
jiabine059e452018-05-07 15:16:44 -07001749 mShutterSoundEnabledFromApp = enabled;
1750 // Return the result of _enableShutterSound(enabled) in all cases.
1751 // If the shutter sound can be disabled, disable it when the device is in DnD mode.
jiabin503e1fd2018-04-19 16:39:44 -07001752 boolean ret = _enableShutterSound(enabled);
jiabine059e452018-05-07 15:16:44 -07001753 if (enabled && !mHasAppOpsPlayAudio) {
1754 Log.i(TAG, "Shutter sound is not allowed by AppOpsManager");
1755 if (canDisableShutterSound) {
1756 _enableShutterSound(false);
1757 }
jiabin503e1fd2018-04-19 16:39:44 -07001758 }
1759 return ret;
1760 }
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001761 }
1762
Igor Murashkin66533622014-08-19 14:51:47 -07001763 /**
1764 * Disable the shutter sound unconditionally.
1765 *
1766 * <p>
1767 * This is only guaranteed to work for legacy cameras
1768 * (i.e. initialized with {@link #cameraInitUnspecified}). Trying to call this on
1769 * a regular camera will force a conditional check in the camera service.
1770 * </p>
1771 *
1772 * @return {@code true} if the shutter sound state was successfully
1773 * changed. {@code false} if the shutter sound state could not be
1774 * changed. {@code true} is also returned if shutter sound playback
1775 * is already set to the requested state.
1776 *
1777 * @hide
1778 */
1779 public final boolean disableShutterSound() {
1780 return _enableShutterSound(/*enabled*/false);
1781 }
1782
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001783 private native final boolean _enableShutterSound(boolean enabled);
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001784
jiabin503e1fd2018-04-19 16:39:44 -07001785 private static class IAppOpsCallbackWrapper extends IAppOpsCallback.Stub {
1786 private final WeakReference<Camera> mWeakCamera;
1787
1788 IAppOpsCallbackWrapper(Camera camera) {
1789 mWeakCamera = new WeakReference<Camera>(camera);
1790 }
1791
1792 @Override
1793 public void opChanged(int op, int uid, String packageName) {
1794 if (op == AppOpsManager.OP_PLAY_AUDIO) {
1795 final Camera camera = mWeakCamera.get();
1796 if (camera != null) {
1797 camera.updateAppOpsPlayAudio();
1798 }
1799 }
1800 }
1801 }
1802
1803 private void updateAppOpsPlayAudio() {
1804 synchronized (mShutterSoundLock) {
1805 boolean oldHasAppOpsPlayAudio = mHasAppOpsPlayAudio;
1806 try {
1807 int mode = AppOpsManager.MODE_IGNORED;
1808 if (mAppOps != null) {
1809 mode = mAppOps.checkAudioOperation(AppOpsManager.OP_PLAY_AUDIO,
1810 AudioAttributes.USAGE_ASSISTANCE_SONIFICATION,
1811 Process.myUid(), ActivityThread.currentPackageName());
1812 }
1813 mHasAppOpsPlayAudio = mode == AppOpsManager.MODE_ALLOWED;
1814 } catch (RemoteException e) {
1815 Log.e(TAG, "AppOpsService check audio operation failed");
1816 mHasAppOpsPlayAudio = false;
1817 }
1818 if (oldHasAppOpsPlayAudio != mHasAppOpsPlayAudio) {
1819 if (!mHasAppOpsPlayAudio) {
jiabine059e452018-05-07 15:16:44 -07001820 IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
1821 IAudioService audioService = IAudioService.Stub.asInterface(b);
1822 try {
1823 if (audioService.isCameraSoundForced()) {
1824 return;
1825 }
1826 } catch (RemoteException e) {
1827 Log.e(TAG, "Audio service is unavailable for queries");
1828 }
jiabin503e1fd2018-04-19 16:39:44 -07001829 _enableShutterSound(false);
1830 } else {
jiabine059e452018-05-07 15:16:44 -07001831 enableShutterSound(mShutterSoundEnabledFromApp);
jiabin503e1fd2018-04-19 16:39:44 -07001832 }
1833 }
1834 }
1835 }
1836
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001837 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001838 * Callback interface for zoom changes during a smooth zoom operation.
1839 *
1840 * @see #setZoomChangeListener(OnZoomChangeListener)
1841 * @see #startSmoothZoom(int)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001842 *
1843 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1844 * applications.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001845 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001846 @Deprecated
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001847 public interface OnZoomChangeListener
Dave Sparkse8b26e12009-07-14 10:35:40 -07001848 {
1849 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07001850 * Called when the zoom value has changed during a smooth zoom.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001851 *
1852 * @param zoomValue the current zoom value. In smooth zoom mode, camera
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001853 * calls this for every new zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001854 * @param stopped whether smooth zoom is stopped. If the value is true,
1855 * this is the last zoom update for the application.
Dave Sparkse8b26e12009-07-14 10:35:40 -07001856 * @param camera the Camera service object
1857 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001858 void onZoomChange(int zoomValue, boolean stopped, Camera camera);
Dave Sparkse8b26e12009-07-14 10:35:40 -07001859 };
1860
1861 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001862 * Registers a listener to be notified when the zoom value is updated by the
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001863 * camera driver during smooth zoom.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001864 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001865 * @param listener the listener to notify
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08001866 * @see #startSmoothZoom(int)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001867 */
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001868 public final void setZoomChangeListener(OnZoomChangeListener listener)
Dave Sparkse8b26e12009-07-14 10:35:40 -07001869 {
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08001870 mZoomListener = listener;
Dave Sparkse8b26e12009-07-14 10:35:40 -07001871 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08001872
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001873 /**
1874 * Callback interface for face detected in the preview frame.
1875 *
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001876 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1877 * applications.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001878 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001879 @Deprecated
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001880 public interface FaceDetectionListener
1881 {
1882 /**
1883 * Notify the listener of the detected faces in the preview frame.
1884 *
Wu-cheng Li53b30912011-10-12 19:43:51 +08001885 * @param faces The detected faces in a list
Joe Fernandez464cb212011-10-04 16:56:47 -07001886 * @param camera The {@link Camera} service object
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001887 */
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001888 void onFaceDetection(Face[] faces, Camera camera);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001889 }
1890
1891 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001892 * Registers a listener to be notified about the faces detected in the
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001893 * preview frame.
1894 *
1895 * @param listener the listener to notify
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001896 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001897 */
1898 public final void setFaceDetectionListener(FaceDetectionListener listener)
1899 {
1900 mFaceListener = listener;
1901 }
1902
1903 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001904 * Starts the face detection. This should be called after preview is started.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001905 * The camera will notify {@link FaceDetectionListener} of the detected
1906 * faces in the preview frame. The detected faces may be the same as the
1907 * previous ones. Applications should call {@link #stopFaceDetection} to
1908 * stop the face detection. This method is supported if {@link
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001909 * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001910 * If the face detection has started, apps should not call this again.
1911 *
Wu-cheng Li8c136702011-08-12 20:25:00 +08001912 * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001913 * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
Wu-cheng Li8c136702011-08-12 20:25:00 +08001914 * have no effect. The camera uses the detected faces to do auto-white balance,
1915 * auto exposure, and autofocus.
1916 *
1917 * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
1918 * will stop sending face callbacks. The last face callback indicates the
1919 * areas used to do autofocus. After focus completes, face detection will
1920 * resume sending face callbacks. If the apps call {@link
1921 * #cancelAutoFocus()}, the face callbacks will also resume.</p>
1922 *
1923 * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
1924 * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
1925 * preview with {@link #startPreview()}, the apps should call this method
1926 * again to resume face detection.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001927 *
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001928 * @throws IllegalArgumentException if the face detection is unsupported.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001929 * @throws RuntimeException if the method fails or the face detection is
1930 * already running.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001931 * @see FaceDetectionListener
1932 * @see #stopFaceDetection()
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001933 * @see Parameters#getMaxNumDetectedFaces()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001934 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001935 public final void startFaceDetection() {
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001936 if (mFaceDetectionRunning) {
1937 throw new RuntimeException("Face detection is already running");
1938 }
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001939 _startFaceDetection(CAMERA_FACE_DETECTION_HW);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001940 mFaceDetectionRunning = true;
1941 }
1942
1943 /**
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001944 * Stops the face detection.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001945 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001946 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001947 */
1948 public final void stopFaceDetection() {
1949 _stopFaceDetection();
1950 mFaceDetectionRunning = false;
1951 }
1952
1953 private native final void _startFaceDetection(int type);
1954 private native final void _stopFaceDetection();
1955
1956 /**
Joe Fernandez464cb212011-10-04 16:56:47 -07001957 * Information about a face identified through camera face detection.
Wu-cheng Li53b30912011-10-12 19:43:51 +08001958 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001959 * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a
1960 * list of face objects for use in focusing and metering.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001961 *
Joe Fernandez464cb212011-10-04 16:56:47 -07001962 * @see FaceDetectionListener
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001963 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1964 * applications.
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001965 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07001966 @Deprecated
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001967 public static class Face {
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001968 /**
1969 * Create an empty face.
1970 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001971 public Face() {
1972 }
1973
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001974 /**
1975 * Bounds of the face. (-1000, -1000) represents the top-left of the
1976 * camera field of view, and (1000, 1000) represents the bottom-right of
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08001977 * the field of view. For example, suppose the size of the viewfinder UI
1978 * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0).
Wu-cheng Li8c136702011-08-12 20:25:00 +08001979 * The corresponding viewfinder rect should be (0, 0, 400, 240). It is
1980 * guaranteed left < right and top < bottom. The coordinates can be
1981 * smaller than -1000 or bigger than 1000. But at least one vertex will
1982 * be within (-1000, -1000) and (1000, 1000).
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001983 *
1984 * <p>The direction is relative to the sensor orientation, that is, what
1985 * the sensor sees. The direction is not affected by the rotation or
Wu-cheng Li8c136702011-08-12 20:25:00 +08001986 * mirroring of {@link #setDisplayOrientation(int)}. The face bounding
1987 * rectangle does not provide any information about face orientation.</p>
1988 *
1989 * <p>Here is the matrix to convert driver coordinates to View coordinates
1990 * in pixels.</p>
1991 * <pre>
1992 * Matrix matrix = new Matrix();
1993 * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
1994 * // Need mirror for front camera.
1995 * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
1996 * matrix.setScale(mirror ? -1 : 1, 1);
1997 * // This is the value for android.hardware.Camera.setDisplayOrientation.
1998 * matrix.postRotate(displayOrientation);
1999 * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
2000 * // UI coordinates range from (0, 0) to (width, height).
2001 * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
2002 * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
2003 * </pre>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08002004 *
Joe Fernandez464cb212011-10-04 16:56:47 -07002005 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08002006 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08002007 public Rect rect;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08002008
2009 /**
Eino-Ville Talvala8df3b2b2012-09-15 14:30:12 -07002010 * <p>The confidence level for the detection of the face. The range is 1 to
2011 * 100. 100 is the highest confidence.</p>
2012 *
2013 * <p>Depending on the device, even very low-confidence faces may be
2014 * listed, so applications should filter out faces with low confidence,
2015 * depending on the use case. For a typical point-and-shoot camera
2016 * application that wishes to display rectangles around detected faces,
2017 * filtering out faces with confidence less than 50 is recommended.</p>
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08002018 *
Joe Fernandez464cb212011-10-04 16:56:47 -07002019 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08002020 */
Wu-cheng Libb1e2752011-07-30 05:00:37 +08002021 public int score;
Wei Huad52b3082011-08-19 13:01:51 -07002022
2023 /**
2024 * An unique id per face while the face is visible to the tracker. If
2025 * the face leaves the field-of-view and comes back, it will get a new
2026 * id. This is an optional field, may not be supported on all devices.
2027 * If not supported, id will always be set to -1. The optional fields
2028 * are supported as a set. Either they are all valid, or none of them
2029 * are.
2030 */
2031 public int id = -1;
2032
2033 /**
2034 * The coordinates of the center of the left eye. The coordinates are in
2035 * the same space as the ones for {@link #rect}. This is an optional
2036 * field, may not be supported on all devices. If not supported, the
2037 * value will always be set to null. The optional fields are supported
2038 * as a set. Either they are all valid, or none of them are.
2039 */
2040 public Point leftEye = null;
2041
2042 /**
2043 * The coordinates of the center of the right eye. The coordinates are
2044 * in the same space as the ones for {@link #rect}.This is an optional
2045 * field, may not be supported on all devices. If not supported, the
2046 * value will always be set to null. The optional fields are supported
2047 * as a set. Either they are all valid, or none of them are.
2048 */
2049 public Point rightEye = null;
2050
2051 /**
2052 * The coordinates of the center of the mouth. The coordinates are in
2053 * the same space as the ones for {@link #rect}. This is an optional
2054 * field, may not be supported on all devices. If not supported, the
2055 * value will always be set to null. The optional fields are supported
2056 * as a set. Either they are all valid, or none of them are.
2057 */
2058 public Point mouth = null;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08002059 }
2060
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002061 /**
2062 * Unspecified camera error.
2063 * @see Camera.ErrorCallback
2064 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 public static final int CAMERA_ERROR_UNKNOWN = 1;
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002066
2067 /**
Ruben Brunke91b9252015-04-14 13:38:06 -07002068 * Camera was disconnected due to use by higher priority user.
2069 * @see Camera.ErrorCallback
2070 */
2071 public static final int CAMERA_ERROR_EVICTED = 2;
2072
2073 /**
Yin-Chia Yeha07cd322018-05-31 12:11:42 -07002074 * Camera was disconnected due to device policy change or client
2075 * application going to background.
2076 * @see Camera.ErrorCallback
2077 *
2078 * @hide
2079 */
2080 public static final int CAMERA_ERROR_DISABLED = 3;
2081
2082 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002083 * Media server died. In this case, the application must release the
2084 * Camera object and instantiate a new one.
2085 * @see Camera.ErrorCallback
2086 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 public static final int CAMERA_ERROR_SERVER_DIED = 100;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002090 * Callback interface for camera error notification.
2091 *
2092 * @see #setErrorCallback(ErrorCallback)
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002093 *
2094 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2095 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002097 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 public interface ErrorCallback
2099 {
2100 /**
2101 * Callback for camera errors.
2102 * @param error error code:
2103 * <ul>
2104 * <li>{@link #CAMERA_ERROR_UNKNOWN}
2105 * <li>{@link #CAMERA_ERROR_SERVER_DIED}
2106 * </ul>
2107 * @param camera the Camera service object
2108 */
2109 void onError(int error, Camera camera);
2110 };
2111
2112 /**
2113 * Registers a callback to be invoked when an error occurs.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002114 * @param cb The callback to run
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 */
2116 public final void setErrorCallback(ErrorCallback cb)
2117 {
2118 mErrorCallback = cb;
2119 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002120
Yin-Chia Yeha07cd322018-05-31 12:11:42 -07002121 /**
2122 * Registers a callback to be invoked when an error occurs.
2123 * The detailed error callback may contain error code that
2124 * gives more detailed information about the error.
2125 *
2126 * When a detailed callback is set, the callback set via
2127 * #setErrorCallback(ErrorCallback) will stop receiving
2128 * onError call.
2129 *
2130 * @param cb The callback to run
2131 *
2132 * @hide
2133 */
2134 public final void setDetailedErrorCallback(ErrorCallback cb)
2135 {
2136 mDetailedErrorCallback = cb;
2137 }
2138
Mathew Inwood5132cc12018-08-08 15:50:55 +01002139 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 private native final void native_setParameters(String params);
Mathew Inwood5132cc12018-08-08 15:50:55 +01002141 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002142 private native final String native_getParameters();
2143
2144 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002145 * Changes the settings for this Camera service.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002146 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 * @param params the Parameters to use for this Camera service
Wu-cheng Li99a3f3e2010-11-19 15:56:16 +08002148 * @throws RuntimeException if any parameter is invalid or not supported.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002149 * @see #getParameters()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 */
2151 public void setParameters(Parameters params) {
Eino-Ville Talvala7005b672013-04-02 15:46:38 -07002152 // If using preview allocations, don't allow preview size changes
2153 if (mUsingPreviewAllocation) {
2154 Size newPreviewSize = params.getPreviewSize();
2155 Size currentPreviewSize = getParameters().getPreviewSize();
2156 if (newPreviewSize.width != currentPreviewSize.width ||
2157 newPreviewSize.height != currentPreviewSize.height) {
2158 throw new IllegalStateException("Cannot change preview size" +
2159 " while a preview allocation is configured.");
2160 }
2161 }
2162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002163 native_setParameters(params.flatten());
2164 }
2165
2166 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002167 * Returns the current settings for this Camera service.
2168 * If modifications are made to the returned Parameters, they must be passed
2169 * to {@link #setParameters(Camera.Parameters)} to take effect.
2170 *
Eino-Ville Talvala06a77182017-09-15 12:43:24 -07002171 * @throws RuntimeException if reading parameters fails; usually this would
2172 * be because of a hardware or other low-level error, or because
2173 * release() has been called on this Camera instance.
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002174 * @see #setParameters(Camera.Parameters)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002175 */
2176 public Parameters getParameters() {
2177 Parameters p = new Parameters();
2178 String s = native_getParameters();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 p.unflatten(s);
2180 return p;
2181 }
2182
Sauhard Pandec44f2d92015-07-09 14:47:34 -07002183 /** @hide
2184 * Returns the current cct value of white balance.
2185 *
2186 * If it's in AWB mode, cct is determined by stats/awb module.
2187 *
2188 * If it's in Manual WB mode, it actually returns cct value
2189 * set by user via {@link #setParameters(Camera.Parameters)}.
2190 */
2191 public int getWBCurrentCCT() {
2192 Parameters p = new Parameters();
2193 String s = native_getParameters();
2194 p.unflatten(s);
2195
2196 int cct = 0;
2197 if (p.getWBCurrentCCT() != null) {
2198 cct = Integer.parseInt(p.getWBCurrentCCT());
2199 }
2200
2201 return cct;
2202 }
2203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 /**
Wu-cheng Li1c04a332011-11-22 18:21:18 +08002205 * Returns an empty {@link Parameters} for testing purpose.
2206 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002207 * @return a Parameter object.
Wu-cheng Li1c04a332011-11-22 18:21:18 +08002208 *
2209 * @hide
2210 */
Mathew Inwood5132cc12018-08-08 15:50:55 +01002211 @UnsupportedAppUsage
Wu-cheng Li1c04a332011-11-22 18:21:18 +08002212 public static Parameters getEmptyParameters() {
2213 Camera camera = new Camera();
2214 return camera.new Parameters();
2215 }
2216
Sauhard Pandec44f2d92015-07-09 14:47:34 -07002217 /* ### QC ADD-ONS: START */
2218 private static int byteToInt(byte[] b, int offset) {
2219 int value = 0;
2220 for (int i = 0; i < 4; i++) {
2221 int shift = (4 - 1 - i) * 8;
2222 value += (b[(3-i) + offset] & 0x000000FF) << shift;
2223 }
2224 return value;
2225 }
2226 /** @hide
2227 * Handles the callback for when Camera Data is available.
2228 * data is read from the camera.
2229 */
2230 public interface CameraDataCallback {
2231 /**
2232 * Callback for when camera data is available.
2233 *
2234 * @param data a int array of the camera data
2235 * @param camera the Camera service object
2236 */
2237 void onCameraData(int[] data, Camera camera);
2238 };
2239
2240 /** @hide
2241 * Set camera histogram mode and registers a callback function to run.
2242 * Only valid after startPreview() has been called.
2243 *
2244 * @param cb the callback to run
2245 */
2246 public final void setHistogramMode(CameraDataCallback cb)
2247 {
2248 mCameraDataCallback = cb;
2249 native_setHistogramMode(cb!=null);
2250 }
2251 private native final void native_setHistogramMode(boolean mode);
2252
2253 /** @hide
2254 * Set camera histogram command to send data.
2255 *
2256 */
2257 public final void sendHistogramData()
2258 {
2259 native_sendHistogramData();
2260 }
2261 private native final void native_sendHistogramData();
2262
2263 /** @hide
2264 * Handles the callback for when Camera Meta Data is available.
2265 * Meta data is read from the camera.
2266 */
2267 public interface CameraMetaDataCallback {
2268 /**
2269 * Callback for when camera meta data is available.
2270 *
2271 * @param data a byte array of the camera meta data
2272 * @param camera the Camera service object
2273 */
2274 void onCameraMetaData(byte[] data, Camera camera);
2275 };
2276
2277 /** @hide
2278 * Set camera meta data and registers a callback function to run.
2279 * Only valid after startPreview() has been called.
2280 *
2281 * @param cb the callback to run
2282 */
2283 public final void setMetadataCb(CameraMetaDataCallback cb)
2284 {
2285 mCameraMetaDataCallback = cb;
2286 native_setMetadataCb(cb!=null);
2287 }
2288 private native final void native_setMetadataCb(boolean mode);
2289
2290 /** @hide
2291 * Set camera face detection command to send meta data.
2292 */
2293 public final void sendMetaData()
2294 {
2295 native_sendMetaData();
2296 }
2297 private native final void native_sendMetaData();
2298
2299 /** @hide
2300 * Configure longshot mode. Available only in ZSL.
2301 *
2302 * @param enable enable/disable this mode
2303 */
2304 public final void setLongshot(boolean enable)
2305 {
2306 native_setLongshot(enable);
2307 }
2308 private native final void native_setLongshot(boolean enable);
2309
2310 /** @hide
2311 * Handles the Touch Co-ordinate.
2312 */
2313 public class Coordinate {
2314 /**
2315 * Sets the x,y co-ordinates for a touch event
2316 *
2317 * @param x the x co-ordinate (pixels)
2318 * @param y the y co-ordinate (pixels)
2319 */
2320 public Coordinate(int x, int y) {
2321 xCoordinate = x;
2322 yCoordinate = y;
2323 }
2324 /**
2325 * Compares {@code obj} to this co-ordinate.
2326 *
2327 * @param obj the object to compare this co-ordinate with.
2328 * @return {@code true} if the xCoordinate and yCoordinate of {@code obj} is the
2329 * same as those of this coordinate. {@code false} otherwise.
2330 */
2331 @Override
2332 public boolean equals(Object obj) {
2333 if (!(obj instanceof Coordinate)) {
2334 return false;
2335 }
2336 Coordinate c = (Coordinate) obj;
2337 return xCoordinate == c.xCoordinate && yCoordinate == c.yCoordinate;
2338 }
2339
2340 /** x co-ordinate for the touch event*/
2341 public int xCoordinate;
2342
2343 /** y co-ordinate for the touch event */
2344 public int yCoordinate;
2345 };
2346
2347 /** @hide
2348 * Returns the current focus position.
2349 *
2350 * If it's in AF mode, it's the lens position after af is done.
2351 *
2352 * If it's in Manual Focus mode, it actually returns the value
2353 * set by user via {@link #setParameters(Camera.Parameters)}.
2354 */
2355 public int getCurrentFocusPosition() {
2356 Parameters p = new Parameters();
2357 String s = native_getParameters();
2358 p.unflatten(s);
2359
2360 int focus_pos = -1;
2361 if (p.getCurrentFocusPosition() != null) {
2362 focus_pos = Integer.parseInt(p.getCurrentFocusPosition());
2363 }
2364 return focus_pos;
2365 }
2366
2367 /* ### QC ADD-ONS: END */
Wu-cheng Li1c04a332011-11-22 18:21:18 +08002368 /**
Igor Murashkindf6242e2014-07-01 18:06:13 -07002369 * Returns a copied {@link Parameters}; for shim use only.
2370 *
2371 * @param parameters a non-{@code null} parameters
2372 * @return a Parameter object, with all the parameters copied from {@code parameters}.
2373 *
2374 * @throws NullPointerException if {@code parameters} was {@code null}
2375 * @hide
2376 */
2377 public static Parameters getParametersCopy(Camera.Parameters parameters) {
2378 if (parameters == null) {
2379 throw new NullPointerException("parameters must not be null");
2380 }
2381
2382 Camera camera = parameters.getOuter();
2383 Parameters p = camera.new Parameters();
2384 p.copyFrom(parameters);
2385
2386 return p;
2387 }
2388
2389 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002390 * Image size (width and height dimensions).
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002391 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2392 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002394 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 public class Size {
2396 /**
2397 * Sets the dimensions for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002398 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 * @param w the photo width (pixels)
2400 * @param h the photo height (pixels)
2401 */
2402 public Size(int w, int h) {
2403 width = w;
2404 height = h;
2405 }
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002406 /**
2407 * Compares {@code obj} to this size.
2408 *
2409 * @param obj the object to compare this size with.
2410 * @return {@code true} if the width and height of {@code obj} is the
2411 * same as those of this size. {@code false} otherwise.
2412 */
2413 @Override
2414 public boolean equals(Object obj) {
2415 if (!(obj instanceof Size)) {
2416 return false;
2417 }
2418 Size s = (Size) obj;
2419 return width == s.width && height == s.height;
2420 }
2421 @Override
2422 public int hashCode() {
2423 return width * 32713 + height;
2424 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 /** width of the picture */
2426 public int width;
2427 /** height of the picture */
2428 public int height;
2429 };
2430
2431 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002432 * <p>The Area class is used for choosing specific metering and focus areas for
2433 * the camera to use when calculating auto-exposure, auto-white balance, and
2434 * auto-focus.</p>
2435 *
2436 * <p>To find out how many simultaneous areas a given camera supports, use
2437 * {@link Parameters#getMaxNumMeteringAreas()} and
2438 * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
2439 * selection is unsupported, these methods will return 0.</p>
2440 *
2441 * <p>Each Area consists of a rectangle specifying its bounds, and a weight
2442 * that determines its importance. The bounds are relative to the camera's
2443 * current field of view. The coordinates are mapped so that (-1000, -1000)
2444 * is always the top-left corner of the current field of view, and (1000,
2445 * 1000) is always the bottom-right corner of the current field of
2446 * view. Setting Areas with bounds outside that range is not allowed. Areas
2447 * with zero or negative width or height are not allowed.</p>
2448 *
2449 * <p>The weight must range from 1 to 1000, and represents a weight for
2450 * every pixel in the area. This means that a large metering area with
2451 * the same weight as a smaller area will have more effect in the
2452 * metering result. Metering areas can overlap and the driver
2453 * will add the weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08002454 *
Wu-cheng Libde61a52011-06-07 18:23:14 +08002455 * @see Parameters#setFocusAreas(List)
2456 * @see Parameters#getFocusAreas()
2457 * @see Parameters#getMaxNumFocusAreas()
2458 * @see Parameters#setMeteringAreas(List)
2459 * @see Parameters#getMeteringAreas()
2460 * @see Parameters#getMaxNumMeteringAreas()
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002461 *
2462 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2463 * applications.
Wu-cheng Li30771b72011-04-02 06:19:46 +08002464 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002465 @Deprecated
Wu-cheng Li30771b72011-04-02 06:19:46 +08002466 public static class Area {
2467 /**
2468 * Create an area with specified rectangle and weight.
2469 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002470 * @param rect the bounds of the area.
2471 * @param weight the weight of the area.
Wu-cheng Li30771b72011-04-02 06:19:46 +08002472 */
2473 public Area(Rect rect, int weight) {
2474 this.rect = rect;
2475 this.weight = weight;
2476 }
2477 /**
2478 * Compares {@code obj} to this area.
2479 *
2480 * @param obj the object to compare this area with.
2481 * @return {@code true} if the rectangle and weight of {@code obj} is
2482 * the same as those of this area. {@code false} otherwise.
2483 */
2484 @Override
2485 public boolean equals(Object obj) {
2486 if (!(obj instanceof Area)) {
2487 return false;
2488 }
2489 Area a = (Area) obj;
2490 if (rect == null) {
2491 if (a.rect != null) return false;
2492 } else {
2493 if (!rect.equals(a.rect)) return false;
2494 }
2495 return weight == a.weight;
2496 }
2497
Wu-cheng Libde61a52011-06-07 18:23:14 +08002498 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002499 * Bounds of the area. (-1000, -1000) represents the top-left of the
2500 * camera field of view, and (1000, 1000) represents the bottom-right of
2501 * the field of view. Setting bounds outside that range is not
2502 * allowed. Bounds with zero or negative width or height are not
2503 * allowed.
Wu-cheng Libde61a52011-06-07 18:23:14 +08002504 *
2505 * @see Parameters#getFocusAreas()
2506 * @see Parameters#getMeteringAreas()
2507 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08002508 public Rect rect;
2509
Wu-cheng Libde61a52011-06-07 18:23:14 +08002510 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07002511 * Weight of the area. The weight must range from 1 to 1000, and
2512 * represents a weight for every pixel in the area. This means that a
2513 * large metering area with the same weight as a smaller area will have
2514 * more effect in the metering result. Metering areas can overlap and
2515 * the driver will add the weights in the overlap region.
Wu-cheng Libde61a52011-06-07 18:23:14 +08002516 *
2517 * @see Parameters#getFocusAreas()
2518 * @see Parameters#getMeteringAreas()
2519 */
Wu-cheng Li30771b72011-04-02 06:19:46 +08002520 public int weight;
Wu-cheng Libde61a52011-06-07 18:23:14 +08002521 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08002522
2523 /**
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002524 * Camera service settings.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002525 *
2526 * <p>To make camera parameters take effect, applications have to call
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002527 * {@link Camera#setParameters(Camera.Parameters)}. For example, after
2528 * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
2529 * actually changed until {@link Camera#setParameters(Camera.Parameters)}
2530 * is called with the changed parameters object.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002531 *
2532 * <p>Different devices may have different camera capabilities, such as
2533 * picture size or flash modes. The application should query the camera
2534 * capabilities before setting parameters. For example, the application
Dan Egnorbfcbeff2010-07-12 15:12:54 -07002535 * should call {@link Camera.Parameters#getSupportedColorEffects()} before
2536 * calling {@link Camera.Parameters#setColorEffect(String)}. If the
2537 * camera does not support color effects,
2538 * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002539 *
2540 * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2541 * applications.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 */
Eino-Ville Talvalab942b052014-07-10 17:45:03 -07002543 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 public class Parameters {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002545 // Parameter keys to communicate with the camera driver.
2546 private static final String KEY_PREVIEW_SIZE = "preview-size";
2547 private static final String KEY_PREVIEW_FORMAT = "preview-format";
2548 private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
Wu-cheng Li454630f2010-08-11 16:48:05 -07002549 private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002550 private static final String KEY_PICTURE_SIZE = "picture-size";
2551 private static final String KEY_PICTURE_FORMAT = "picture-format";
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08002552 private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002553 private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
2554 private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
2555 private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
2556 private static final String KEY_JPEG_QUALITY = "jpeg-quality";
2557 private static final String KEY_ROTATION = "rotation";
2558 private static final String KEY_GPS_LATITUDE = "gps-latitude";
2559 private static final String KEY_GPS_LONGITUDE = "gps-longitude";
2560 private static final String KEY_GPS_ALTITUDE = "gps-altitude";
2561 private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
Ray Chen055c9862010-02-23 10:45:42 +08002562 private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002563 private static final String KEY_WHITE_BALANCE = "whitebalance";
2564 private static final String KEY_EFFECT = "effect";
2565 private static final String KEY_ANTIBANDING = "antibanding";
2566 private static final String KEY_SCENE_MODE = "scene-mode";
2567 private static final String KEY_FLASH_MODE = "flash-mode";
Wu-cheng Li36322db2009-09-18 18:59:21 +08002568 private static final String KEY_FOCUS_MODE = "focus-mode";
Wu-cheng Li30771b72011-04-02 06:19:46 +08002569 private static final String KEY_FOCUS_AREAS = "focus-areas";
2570 private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08002571 private static final String KEY_FOCAL_LENGTH = "focal-length";
2572 private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
2573 private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
Wu-cheng Liff723b62010-02-09 13:38:19 +08002574 private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
Wu-cheng Li24b326a2010-02-20 17:47:04 +08002575 private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
2576 private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
2577 private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002578 private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
2579 private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07002580 private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
2581 private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08002582 private static final String KEY_METERING_AREAS = "metering-areas";
2583 private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002584 private static final String KEY_ZOOM = "zoom";
2585 private static final String KEY_MAX_ZOOM = "max-zoom";
2586 private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
2587 private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
2588 private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002589 private static final String KEY_FOCUS_DISTANCES = "focus-distances";
James Dongdd0b16c2010-09-21 16:23:48 -07002590 private static final String KEY_VIDEO_SIZE = "video-size";
2591 private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
2592 "preferred-preview-size-for-video";
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08002593 private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
2594 private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08002595 private static final String KEY_RECORDING_HINT = "recording-hint";
Wu-cheng Li98bb2512011-08-30 21:33:10 +08002596 private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07002597 private static final String KEY_VIDEO_STABILIZATION = "video-stabilization";
2598 private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002599
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002600 // Parameter key suffix for supported values.
2601 private static final String SUPPORTED_VALUES_SUFFIX = "-values";
2602
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002603 private static final String TRUE = "true";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07002604 private static final String FALSE = "false";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08002605
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002606 // Values for white balance settings.
2607 public static final String WHITE_BALANCE_AUTO = "auto";
2608 public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
2609 public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
2610 public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
2611 public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
2612 public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
2613 public static final String WHITE_BALANCE_TWILIGHT = "twilight";
2614 public static final String WHITE_BALANCE_SHADE = "shade";
Sauhard Pandec44f2d92015-07-09 14:47:34 -07002615 /** @hide
2616 * wb manual cct mode.
2617 */
2618 public static final String WHITE_BALANCE_MANUAL_CCT = "manual-cct";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002619
2620 // Values for color effect settings.
2621 public static final String EFFECT_NONE = "none";
2622 public static final String EFFECT_MONO = "mono";
2623 public static final String EFFECT_NEGATIVE = "negative";
2624 public static final String EFFECT_SOLARIZE = "solarize";
2625 public static final String EFFECT_SEPIA = "sepia";
2626 public static final String EFFECT_POSTERIZE = "posterize";
2627 public static final String EFFECT_WHITEBOARD = "whiteboard";
2628 public static final String EFFECT_BLACKBOARD = "blackboard";
2629 public static final String EFFECT_AQUA = "aqua";
2630
2631 // Values for antibanding settings.
2632 public static final String ANTIBANDING_AUTO = "auto";
2633 public static final String ANTIBANDING_50HZ = "50hz";
2634 public static final String ANTIBANDING_60HZ = "60hz";
2635 public static final String ANTIBANDING_OFF = "off";
2636
2637 // Values for flash mode settings.
2638 /**
2639 * Flash will not be fired.
2640 */
2641 public static final String FLASH_MODE_OFF = "off";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002642
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002643 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07002644 * Flash will be fired automatically when required. The flash may be fired
2645 * during preview, auto-focus, or snapshot depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002646 */
2647 public static final String FLASH_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002648
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002649 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07002650 * Flash will always be fired during snapshot. The flash may also be
2651 * fired during preview or auto-focus depending on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002652 */
2653 public static final String FLASH_MODE_ON = "on";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002654
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002655 /**
2656 * Flash will be fired in red-eye reduction mode.
2657 */
2658 public static final String FLASH_MODE_RED_EYE = "red-eye";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002659
Wu-cheng Li36322db2009-09-18 18:59:21 +08002660 /**
Wu-cheng Li068ef422009-09-27 13:19:36 -07002661 * Constant emission of light during preview, auto-focus and snapshot.
2662 * This can also be used for video recording.
Wu-cheng Li36322db2009-09-18 18:59:21 +08002663 */
Wu-cheng Li068ef422009-09-27 13:19:36 -07002664 public static final String FLASH_MODE_TORCH = "torch";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002665
Sauhard Pandec44f2d92015-07-09 14:47:34 -07002666 /** @hide
2667 * Scene mode is off.
2668 */
2669 public static final String SCENE_MODE_ASD = "asd";
2670
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002671 /**
2672 * Scene mode is off.
2673 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002674 public static final String SCENE_MODE_AUTO = "auto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002675
2676 /**
2677 * Take photos of fast moving objects. Same as {@link
2678 * #SCENE_MODE_SPORTS}.
2679 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002680 public static final String SCENE_MODE_ACTION = "action";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002681
2682 /**
2683 * Take people pictures.
2684 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002685 public static final String SCENE_MODE_PORTRAIT = "portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002686
2687 /**
2688 * Take pictures on distant objects.
2689 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002690 public static final String SCENE_MODE_LANDSCAPE = "landscape";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002691
2692 /**
2693 * Take photos at night.
2694 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002695 public static final String SCENE_MODE_NIGHT = "night";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002696
2697 /**
2698 * Take people pictures at night.
2699 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002700 public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002701
2702 /**
2703 * Take photos in a theater. Flash light is off.
2704 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002705 public static final String SCENE_MODE_THEATRE = "theatre";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002706
2707 /**
2708 * Take pictures on the beach.
2709 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002710 public static final String SCENE_MODE_BEACH = "beach";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002711
2712 /**
2713 * Take pictures on the snow.
2714 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002715 public static final String SCENE_MODE_SNOW = "snow";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002716
2717 /**
2718 * Take sunset photos.
2719 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002720 public static final String SCENE_MODE_SUNSET = "sunset";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002721
2722 /**
2723 * Avoid blurry pictures (for example, due to hand shake).
2724 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002725 public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002726
2727 /**
2728 * For shooting firework displays.
2729 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002730 public static final String SCENE_MODE_FIREWORKS = "fireworks";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002731
2732 /**
2733 * Take photos of fast moving objects. Same as {@link
2734 * #SCENE_MODE_ACTION}.
2735 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002736 public static final String SCENE_MODE_SPORTS = "sports";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002737
2738 /**
2739 * Take indoor low-light shot.
2740 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002741 public static final String SCENE_MODE_PARTY = "party";
Wu-cheng Li00e21f82010-05-28 16:43:38 +08002742
2743 /**
2744 * Capture the naturally warm color of scenes lit by candles.
2745 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002746 public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
Sauhard Pandec44f2d92015-07-09 14:47:34 -07002747 /** @hide
2748 * SCENE_MODE_BACKLIGHT
2749 **/
2750 public static final String SCENE_MODE_BACKLIGHT = "backlight";
2751 /** @hide
2752 * SCENE_MODE_FLOWERS
2753 **/
2754 public static final String SCENE_MODE_FLOWERS = "flowers";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002755
Wu-cheng Lic58b4232010-03-29 17:21:28 +08002756 /**
2757 * Applications are looking for a barcode. Camera driver will be
2758 * optimized for barcode reading.
2759 */
2760 public static final String SCENE_MODE_BARCODE = "barcode";
2761
Wu-cheng Li36322db2009-09-18 18:59:21 +08002762 /**
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07002763 * Capture a scene using high dynamic range imaging techniques. The
2764 * camera will return an image that has an extended dynamic range
2765 * compared to a regular capture. Capturing such an image may take
2766 * longer than a regular capture.
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07002767 */
2768 public static final String SCENE_MODE_HDR = "hdr";
2769
2770 /**
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07002771 * Auto-focus mode. Applications should call {@link
2772 * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
Wu-cheng Li36322db2009-09-18 18:59:21 +08002773 */
2774 public static final String FOCUS_MODE_AUTO = "auto";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002775
Wu-cheng Li36322db2009-09-18 18:59:21 +08002776 /**
2777 * Focus is set at infinity. Applications should not call
2778 * {@link #autoFocus(AutoFocusCallback)} in this mode.
2779 */
2780 public static final String FOCUS_MODE_INFINITY = "infinity";
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07002781
2782 /**
2783 * Macro (close-up) focus mode. Applications should call
2784 * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
2785 * mode.
2786 */
Wu-cheng Li36322db2009-09-18 18:59:21 +08002787 public static final String FOCUS_MODE_MACRO = "macro";
Wu-cheng Li36f68b82009-09-28 16:14:58 -07002788
Wu-cheng Li36322db2009-09-18 18:59:21 +08002789 /**
2790 * Focus is fixed. The camera is always in this mode if the focus is not
2791 * adjustable. If the camera has auto-focus, this mode can fix the
2792 * focus, which is usually at hyperfocal distance. Applications should
2793 * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
2794 */
2795 public static final String FOCUS_MODE_FIXED = "fixed";
2796
Sauhard Pandec44f2d92015-07-09 14:47:34 -07002797 /** @hide
2798 * Normal focus mode. Applications should call
2799 * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
2800 * mode.
2801 */
2802 public static final String FOCUS_MODE_NORMAL = "normal";
2803
Wu-cheng Lic58b4232010-03-29 17:21:28 +08002804 /**
2805 * Extended depth of field (EDOF). Focusing is done digitally and
2806 * continuously. Applications should not call {@link
2807 * #autoFocus(AutoFocusCallback)} in this mode.
2808 */
2809 public static final String FOCUS_MODE_EDOF = "edof";
2810
Wu-cheng Li699fe932010-08-05 11:50:25 -07002811 /**
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002812 * Continuous auto focus mode intended for video recording. The camera
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002813 * continuously tries to focus. This is the best choice for video
2814 * recording because the focus changes smoothly . Applications still can
2815 * call {@link #takePicture(Camera.ShutterCallback,
2816 * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
2817 * subject may not be in focus. Auto focus starts when the parameter is
Wu-cheng Li53b30912011-10-12 19:43:51 +08002818 * set.
2819 *
2820 * <p>Since API level 14, applications can call {@link
2821 * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
2822 * immediately return with a boolean that indicates whether the focus is
2823 * sharp or not. The focus position is locked after autoFocus call. If
2824 * applications want to resume the continuous focus, cancelAutoFocus
2825 * must be called. Restarting the preview will not resume the continuous
2826 * autofocus. To stop continuous focus, applications should change the
2827 * focus mode to other modes.
2828 *
2829 * @see #FOCUS_MODE_CONTINUOUS_PICTURE
Wu-cheng Li699fe932010-08-05 11:50:25 -07002830 */
Wu-cheng Lid45cb722010-09-20 16:15:32 -07002831 public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
Wu-cheng Li699fe932010-08-05 11:50:25 -07002832
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002833 /**
2834 * Continuous auto focus mode intended for taking pictures. The camera
2835 * continuously tries to focus. The speed of focus change is more
2836 * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
Wu-cheng Li53b30912011-10-12 19:43:51 +08002837 * starts when the parameter is set.
2838 *
Wu-cheng Li0f4f97b2011-10-27 18:07:01 +08002839 * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
2840 * this mode. If the autofocus is in the middle of scanning, the focus
2841 * callback will return when it completes. If the autofocus is not
2842 * scanning, the focus callback will immediately return with a boolean
2843 * that indicates whether the focus is sharp or not. The apps can then
2844 * decide if they want to take a picture immediately or to change the
2845 * focus mode to auto, and run a full autofocus cycle. The focus
2846 * position is locked after autoFocus call. If applications want to
2847 * resume the continuous focus, cancelAutoFocus must be called.
2848 * Restarting the preview will not resume the continuous autofocus. To
2849 * stop continuous focus, applications should change the focus mode to
2850 * other modes.
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002851 *
2852 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Lib9ac75d2011-08-16 21:14:16 +08002853 */
2854 public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
2855
Sauhard Pandec44f2d92015-07-09 14:47:34 -07002856 /** @hide
2857 * manual focus mode
2858 */
2859 public static final String FOCUS_MODE_MANUAL_POSITION = "manual";
2860
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08002861 // Indices for focus distance array.
2862 /**
2863 * The array index of near focus distance for use with
2864 * {@link #getFocusDistances(float[])}.
2865 */
2866 public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
2867
2868 /**
2869 * The array index of optimal focus distance for use with
2870 * {@link #getFocusDistances(float[])}.
2871 */
2872 public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
2873
2874 /**
2875 * The array index of far focus distance for use with
2876 * {@link #getFocusDistances(float[])}.
2877 */
2878 public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
2879
Wu-cheng Lica099612010-05-06 16:47:30 +08002880 /**
Wu-cheng Li454630f2010-08-11 16:48:05 -07002881 * The array index of minimum preview fps for use with {@link
2882 * #getPreviewFpsRange(int[])} or {@link
2883 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07002884 */
2885 public static final int PREVIEW_FPS_MIN_INDEX = 0;
2886
2887 /**
2888 * The array index of maximum preview fps for use with {@link
2889 * #getPreviewFpsRange(int[])} or {@link
2890 * #getSupportedPreviewFpsRange()}.
Wu-cheng Li454630f2010-08-11 16:48:05 -07002891 */
2892 public static final int PREVIEW_FPS_MAX_INDEX = 1;
2893
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002894 // Formats for setPreviewFormat and setPictureFormat.
2895 private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
2896 private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
Sauhard Pandec44f2d92015-07-09 14:47:34 -07002897 private static final String PIXEL_FORMAT_YUV420SP_ADRENO = "yuv420sp-adreno";
Chih-Chung Changeb68c462009-09-18 18:37:44 +08002898 private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
Wu-cheng Li10a1b302011-02-22 15:49:25 +08002899 private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002900 private static final String PIXEL_FORMAT_RGB565 = "rgb565";
2901 private static final String PIXEL_FORMAT_JPEG = "jpeg";
Wu-cheng Li70fb9082011-08-02 17:49:50 +08002902 private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb";
Sauhard Pandec44f2d92015-07-09 14:47:34 -07002903 private static final String PIXEL_FORMAT_RAW = "raw";
2904 private static final String PIXEL_FORMAT_YV12 = "yv12";
2905 private static final String PIXEL_FORMAT_NV12 = "nv12";
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002906
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002907 /**
2908 * Order matters: Keys that are {@link #set(String, String) set} later
2909 * will take precedence over keys that are set earlier (if the two keys
2910 * conflict with each other).
2911 *
2912 * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it
2913 * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later
2914 * is the one that will take precedence.
2915 * </p>
2916 */
2917 private final LinkedHashMap<String, String> mMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918
2919 private Parameters() {
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07002920 mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 }
2922
2923 /**
Igor Murashkindf6242e2014-07-01 18:06:13 -07002924 * Overwrite existing parameters with a copy of the ones from {@code other}.
2925 *
2926 * <b>For use by the legacy shim only.</b>
2927 *
2928 * @hide
2929 */
Mathew Inwood5132cc12018-08-08 15:50:55 +01002930 @UnsupportedAppUsage
Igor Murashkindf6242e2014-07-01 18:06:13 -07002931 public void copyFrom(Parameters other) {
2932 if (other == null) {
2933 throw new NullPointerException("other must not be null");
2934 }
2935
2936 mMap.putAll(other.mMap);
2937 }
2938
2939 private Camera getOuter() {
2940 return Camera.this;
2941 }
2942
Ruben Brunkd1f113d2014-07-11 11:46:20 -07002943
2944 /**
2945 * Value equality check.
2946 *
2947 * @hide
2948 */
2949 public boolean same(Parameters other) {
2950 if (this == other) {
2951 return true;
2952 }
2953 return other != null && Parameters.this.mMap.equals(other.mMap);
2954 }
2955
Igor Murashkindf6242e2014-07-01 18:06:13 -07002956 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 * Writes the current Parameters to the log.
2958 * @hide
2959 * @deprecated
2960 */
Igor Murashkina1d66272014-06-20 11:22:11 -07002961 @Deprecated
Mathew Inwood5132cc12018-08-08 15:50:55 +01002962 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 public void dump() {
2964 Log.e(TAG, "dump: size=" + mMap.size());
2965 for (String k : mMap.keySet()) {
2966 Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
2967 }
2968 }
2969
2970 /**
2971 * Creates a single string with all the parameters set in
2972 * this Parameters object.
2973 * <p>The {@link #unflatten(String)} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002974 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 * @return a String with all values from this Parameters object, in
2976 * semi-colon delimited key-value pairs
2977 */
2978 public String flatten() {
Ali Utku Selen0a120182011-02-09 14:11:22 +01002979 StringBuilder flattened = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 for (String k : mMap.keySet()) {
2981 flattened.append(k);
2982 flattened.append("=");
2983 flattened.append(mMap.get(k));
2984 flattened.append(";");
2985 }
2986 // chop off the extra semicolon at the end
2987 flattened.deleteCharAt(flattened.length()-1);
2988 return flattened.toString();
2989 }
2990
2991 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002992 * Takes a flattened string of parameters and adds each one to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 * this Parameters object.
2994 * <p>The {@link #flatten()} method does the reverse.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08002995 *
2996 * @param flattened a String of parameters (key-value paired) that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 * are semi-colon delimited
2998 */
2999 public void unflatten(String flattened) {
3000 mMap.clear();
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003001
Ali Utku Selen0a120182011-02-09 14:11:22 +01003002 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';');
3003 splitter.setString(flattened);
3004 for (String kv : splitter) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 int pos = kv.indexOf('=');
3006 if (pos == -1) {
3007 continue;
3008 }
3009 String k = kv.substring(0, pos);
3010 String v = kv.substring(pos + 1);
3011 mMap.put(k, v);
3012 }
3013 }
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003015 public void remove(String key) {
3016 mMap.remove(key);
3017 }
3018
3019 /**
3020 * Sets a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003021 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 * @param key the key name for the parameter
3023 * @param value the String value of the parameter
3024 */
3025 public void set(String key, String value) {
Eino-Ville Talvalacb569232012-03-12 11:36:58 -07003026 if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) {
3027 Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003028 return;
3029 }
Eino-Ville Talvalacb569232012-03-12 11:36:58 -07003030 if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) {
3031 Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 return;
3033 }
3034
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07003035 put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036 }
3037
3038 /**
3039 * Sets an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003040 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003041 * @param key the key name for the parameter
3042 * @param value the int value of the parameter
3043 */
3044 public void set(String key, int value) {
Igor Murashkin7d9a8ff2014-03-18 18:14:41 -07003045 put(key, Integer.toString(value));
3046 }
3047
3048 private void put(String key, String value) {
3049 /*
3050 * Remove the key if it already exists.
3051 *
3052 * This way setting a new value for an already existing key will always move
3053 * that key to be ordered the latest in the map.
3054 */
3055 mMap.remove(key);
3056 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
3058
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003059 private void set(String key, List<Area> areas) {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08003060 if (areas == null) {
3061 set(key, "(0,0,0,0,0)");
3062 } else {
3063 StringBuilder buffer = new StringBuilder();
3064 for (int i = 0; i < areas.size(); i++) {
3065 Area area = areas.get(i);
3066 Rect rect = area.rect;
3067 buffer.append('(');
3068 buffer.append(rect.left);
3069 buffer.append(',');
3070 buffer.append(rect.top);
3071 buffer.append(',');
3072 buffer.append(rect.right);
3073 buffer.append(',');
3074 buffer.append(rect.bottom);
3075 buffer.append(',');
3076 buffer.append(area.weight);
3077 buffer.append(')');
3078 if (i != areas.size() - 1) buffer.append(',');
3079 }
3080 set(key, buffer.toString());
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003081 }
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08003082 }
3083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 /**
3085 * Returns the value of a String parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003086 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 * @param key the key name for the parameter
3088 * @return the String value of the parameter
3089 */
3090 public String get(String key) {
3091 return mMap.get(key);
3092 }
3093
3094 /**
3095 * Returns the value of an integer parameter.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003096 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003097 * @param key the key name for the parameter
3098 * @return the int value of the parameter
3099 */
3100 public int getInt(String key) {
3101 return Integer.parseInt(mMap.get(key));
3102 }
3103
3104 /**
Wu-cheng Li26274fa2011-05-05 14:36:28 +08003105 * Sets the dimensions for preview pictures. If the preview has already
3106 * started, applications should stop the preview first before changing
3107 * preview size.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003108 *
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08003109 * The sides of width and height are based on camera orientation. That
3110 * is, the preview size is the size before it is rotated by display
3111 * orientation. So applications need to consider the display orientation
3112 * while setting preview size. For example, suppose the camera supports
3113 * both 480x320 and 320x480 preview sizes. The application wants a 3:2
3114 * preview ratio. If the display orientation is set to 0 or 180, preview
3115 * size should be set to 480x320. If the display orientation is set to
3116 * 90 or 270, preview size should be set to 320x480. The display
3117 * orientation should also be considered while setting picture size and
3118 * thumbnail size.
3119 *
Yin-Chia Yeh428256d2019-01-23 15:27:47 -08003120 * Exception on 176x144 (QCIF) resolution:
3121 * Camera devices usually have a fixed capability for downscaling from
3122 * larger resolution to smaller, and the QCIF resolution sometimes
3123 * is not fully supported due to this limitation on devices with
3124 * high-resolution image sensors. Therefore, trying to configure a QCIF
3125 * preview size with any picture or video size larger than 1920x1080
3126 * (either width or height) might not be supported, and
3127 * {@link #setParameters(Camera.Parameters)} might throw a
3128 * RuntimeException if it is not.
3129 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 * @param width the width of the pictures, in pixels
3131 * @param height the height of the pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08003132 * @see #setDisplayOrientation(int)
3133 * @see #getCameraInfo(int, CameraInfo)
3134 * @see #setPictureSize(int, int)
3135 * @see #setJpegThumbnailSize(int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136 */
3137 public void setPreviewSize(int width, int height) {
3138 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003139 set(KEY_PREVIEW_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 }
3141
3142 /**
3143 * Returns the dimensions setting for preview pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003144 *
James Dongdd0b16c2010-09-21 16:23:48 -07003145 * @return a Size object with the width and height setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 * for the preview picture
3147 */
3148 public Size getPreviewSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003149 String pair = get(KEY_PREVIEW_SIZE);
3150 return strToSize(pair);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 }
3152
3153 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003154 * Gets the supported preview sizes.
3155 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003156 * @return a list of Size object. This method will always return a list
Wu-cheng Li9c799382009-12-04 19:59:18 +08003157 * with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003158 */
3159 public List<Size> getSupportedPreviewSizes() {
3160 String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
3161 return splitSize(str);
3162 }
3163
3164 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003165 * <p>Gets the supported video frame sizes that can be used by
3166 * MediaRecorder.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07003167 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003168 * <p>If the returned list is not null, the returned list will contain at
James Dongdd0b16c2010-09-21 16:23:48 -07003169 * least one Size and one of the sizes in the returned list must be
3170 * passed to MediaRecorder.setVideoSize() for camcorder application if
3171 * camera is used as the video source. In this case, the size of the
3172 * preview can be different from the resolution of the recorded video
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003173 * during video recording.</p>
James Dongdd0b16c2010-09-21 16:23:48 -07003174 *
Yin-Chia Yeh428256d2019-01-23 15:27:47 -08003175 * <p>Exception on 176x144 (QCIF) resolution:
3176 * Camera devices usually have a fixed capability for downscaling from
3177 * larger resolution to smaller, and the QCIF resolution sometimes
3178 * is not fully supported due to this limitation on devices with
3179 * high-resolution image sensors. Therefore, trying to configure a QCIF
3180 * video resolution with any preview or picture size larger than
3181 * 1920x1080 (either width or height) might not be supported, and
3182 * {@link #setParameters(Camera.Parameters)} will throw a
3183 * RuntimeException if it is not.</p>
3184 *
James Dongdd0b16c2010-09-21 16:23:48 -07003185 * @return a list of Size object if camera has separate preview and
3186 * video output; otherwise, null is returned.
3187 * @see #getPreferredPreviewSizeForVideo()
3188 */
3189 public List<Size> getSupportedVideoSizes() {
3190 String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
3191 return splitSize(str);
3192 }
3193
3194 /**
3195 * Returns the preferred or recommended preview size (width and height)
3196 * in pixels for video recording. Camcorder applications should
3197 * set the preview size to a value that is not larger than the
3198 * preferred preview size. In other words, the product of the width
3199 * and height of the preview size should not be larger than that of
3200 * the preferred preview size. In addition, we recommend to choose a
3201 * preview size that has the same aspect ratio as the resolution of
3202 * video to be recorded.
3203 *
3204 * @return the preferred preview size (width and height) in pixels for
3205 * video recording if getSupportedVideoSizes() does not return
3206 * null; otherwise, null is returned.
3207 * @see #getSupportedVideoSizes()
3208 */
3209 public Size getPreferredPreviewSizeForVideo() {
3210 String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
3211 return strToSize(pair);
3212 }
3213
3214 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003215 * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08003216 * applications set both width and height to 0, EXIF will not contain
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003217 * thumbnail.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003218 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003219 * <p>Applications need to consider the display orientation. See {@link
3220 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08003221 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 * @param width the width of the thumbnail, in pixels
3223 * @param height the height of the thumbnail, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08003224 * @see #setPreviewSize(int,int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003226 public void setJpegThumbnailSize(int width, int height) {
3227 set(KEY_JPEG_THUMBNAIL_WIDTH, width);
3228 set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 }
3230
3231 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003232 * Returns the dimensions for EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003234 * @return a Size object with the height and width setting for the EXIF
3235 * thumbnails
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003237 public Size getJpegThumbnailSize() {
3238 return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
3239 getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003240 }
3241
3242 /**
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08003243 * Gets the supported jpeg thumbnail sizes.
3244 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003245 * @return a list of Size object. This method will always return a list
Wu-cheng Li4c4300c2010-01-23 15:45:39 +08003246 * with at least two elements. Size 0,0 (no thumbnail) is always
3247 * supported.
3248 */
3249 public List<Size> getSupportedJpegThumbnailSizes() {
3250 String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
3251 return splitSize(str);
3252 }
3253
3254 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003255 * Sets the quality of the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003257 * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
3258 * to 100, with 100 being the best.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003260 public void setJpegThumbnailQuality(int quality) {
3261 set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 }
3263
3264 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003265 * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003267 * @return the JPEG quality setting of the EXIF thumbnail.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 */
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003269 public int getJpegThumbnailQuality() {
3270 return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
3271 }
3272
3273 /**
3274 * Sets Jpeg quality of captured picture.
3275 *
3276 * @param quality the JPEG quality of captured picture. The range is 1
3277 * to 100, with 100 being the best.
3278 */
3279 public void setJpegQuality(int quality) {
3280 set(KEY_JPEG_QUALITY, quality);
3281 }
3282
3283 /**
3284 * Returns the quality setting for the JPEG picture.
3285 *
3286 * @return the JPEG picture quality setting.
3287 */
3288 public int getJpegQuality() {
3289 return getInt(KEY_JPEG_QUALITY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003290 }
3291
3292 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08003293 * Sets the rate at which preview frames are received. This is the
3294 * target frame rate. The actual frame rate depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003295 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 * @param fps the frame rate (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07003297 * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07003299 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 public void setPreviewFrameRate(int fps) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003301 set(KEY_PREVIEW_FRAME_RATE, fps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 }
3303
3304 /**
Wu-cheng Lia18e9012010-02-10 13:05:29 +08003305 * Returns the setting for the rate at which preview frames are
3306 * received. This is the target frame rate. The actual frame rate
3307 * depends on the driver.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003308 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 * @return the frame rate setting (frames per second)
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07003310 * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07003312 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003313 public int getPreviewFrameRate() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003314 return getInt(KEY_PREVIEW_FRAME_RATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 }
3316
3317 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003318 * Gets the supported preview frame rates.
3319 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003320 * @return a list of supported preview frame rates. null if preview
3321 * frame rate setting is not supported.
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07003322 * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003323 */
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07003324 @Deprecated
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003325 public List<Integer> getSupportedPreviewFrameRates() {
3326 String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
3327 return splitInt(str);
3328 }
3329
3330 /**
Hai Guo4a68e3c2012-12-05 21:50:28 +08003331 * Sets the minimum and maximum preview fps. This controls the rate of
Wu-cheng Li1620d112010-08-27 15:09:20 -07003332 * preview frames received in {@link PreviewCallback}. The minimum and
Wu-cheng Li454630f2010-08-11 16:48:05 -07003333 * maximum preview fps must be one of the elements from {@link
3334 * #getSupportedPreviewFpsRange}.
3335 *
3336 * @param min the minimum preview fps (scaled by 1000).
3337 * @param max the maximum preview fps (scaled by 1000).
3338 * @throws RuntimeException if fps range is invalid.
3339 * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
3340 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07003341 */
3342 public void setPreviewFpsRange(int min, int max) {
3343 set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
3344 }
3345
3346 /**
3347 * Returns the current minimum and maximum preview fps. The values are
3348 * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
3349 *
3350 * @return range the minimum and maximum preview fps (scaled by 1000).
3351 * @see #PREVIEW_FPS_MIN_INDEX
3352 * @see #PREVIEW_FPS_MAX_INDEX
3353 * @see #getSupportedPreviewFpsRange()
Wu-cheng Li454630f2010-08-11 16:48:05 -07003354 */
3355 public void getPreviewFpsRange(int[] range) {
3356 if (range == null || range.length != 2) {
3357 throw new IllegalArgumentException(
Wu-cheng Li5f1e69c2010-08-18 11:39:12 -07003358 "range must be an array with two elements.");
Wu-cheng Li454630f2010-08-11 16:48:05 -07003359 }
3360 splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
3361 }
3362
3363 /**
3364 * Gets the supported preview fps (frame-per-second) ranges. Each range
3365 * contains a minimum fps and maximum fps. If minimum fps equals to
3366 * maximum fps, the camera outputs frames in fixed frame rate. If not,
3367 * the camera outputs frames in auto frame rate. The actual frame rate
3368 * fluctuates between the minimum and the maximum. The values are
3369 * multiplied by 1000 and represented in integers. For example, if frame
3370 * rate is 26.623 frames per second, the value is 26623.
3371 *
3372 * @return a list of supported preview fps ranges. This method returns a
3373 * list with at least one element. Every element is an int array
3374 * of two values - minimum fps and maximum fps. The list is
3375 * sorted from small to large (first by maximum fps and then
3376 * minimum fps).
3377 * @see #PREVIEW_FPS_MIN_INDEX
3378 * @see #PREVIEW_FPS_MAX_INDEX
Wu-cheng Li454630f2010-08-11 16:48:05 -07003379 */
3380 public List<int[]> getSupportedPreviewFpsRange() {
3381 String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
3382 return splitRange(str);
3383 }
3384
3385 /**
Wu-cheng Li7478ea62009-09-16 18:52:55 +08003386 * Sets the image format for preview pictures.
Scott Mainda0a56d2009-09-10 18:08:37 -07003387 * <p>If this is never called, the default format will be
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003388 * {@link android.graphics.ImageFormat#NV21}, which
Scott Maindf4578e2009-09-10 12:22:07 -07003389 * uses the NV21 encoding format.</p>
Wu-cheng Li7478ea62009-09-16 18:52:55 +08003390 *
Eino-Ville Talvala95151632012-05-02 16:21:18 -07003391 * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of
3392 * the available preview formats.
3393 *
3394 * <p>It is strongly recommended that either
3395 * {@link android.graphics.ImageFormat#NV21} or
3396 * {@link android.graphics.ImageFormat#YV12} is used, since
3397 * they are supported by all camera devices.</p>
3398 *
3399 * <p>For YV12, the image buffer that is received is not necessarily
3400 * tightly packed, as there may be padding at the end of each row of
3401 * pixel data, as described in
3402 * {@link android.graphics.ImageFormat#YV12}. For camera callback data,
3403 * it can be assumed that the stride of the Y and UV data is the
3404 * smallest possible that meets the alignment requirements. That is, if
3405 * the preview size is <var>width x height</var>, then the following
3406 * equations describe the buffer index for the beginning of row
3407 * <var>y</var> for the Y plane and row <var>c</var> for the U and V
3408 * planes:
3409 *
Neil Fuller71fbb812015-11-30 09:51:33 +00003410 * <pre>{@code
Eino-Ville Talvala95151632012-05-02 16:21:18 -07003411 * yStride = (int) ceil(width / 16.0) * 16;
3412 * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16;
3413 * ySize = yStride * height;
3414 * uvSize = uvStride * height / 2;
3415 * yRowIndex = yStride * y;
3416 * uRowIndex = ySize + uvSize + uvStride * c;
3417 * vRowIndex = ySize + uvStride * c;
Neil Fuller71fbb812015-11-30 09:51:33 +00003418 * size = ySize + uvSize * 2;
Eino-Ville Talvala95151632012-05-02 16:21:18 -07003419 * }
Neil Fuller71fbb812015-11-30 09:51:33 +00003420 *</pre>
Eino-Ville Talvala95151632012-05-02 16:21:18 -07003421 *
3422 * @param pixel_format the desired preview picture format, defined by
3423 * one of the {@link android.graphics.ImageFormat} constants. (E.g.,
3424 * <var>ImageFormat.NV21</var> (default), or
3425 * <var>ImageFormat.YV12</var>)
3426 *
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003427 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07003428 * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 */
3430 public void setPreviewFormat(int pixel_format) {
3431 String s = cameraFormatForPixelFormat(pixel_format);
3432 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003433 throw new IllegalArgumentException(
3434 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 }
3436
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003437 set(KEY_PREVIEW_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003438 }
3439
3440 /**
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003441 * Returns the image format for preview frames got from
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003442 * {@link PreviewCallback}.
Wu-cheng Li7478ea62009-09-16 18:52:55 +08003443 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003444 * @return the preview format.
3445 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07003446 * @see #setPreviewFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447 */
3448 public int getPreviewFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003449 return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
3450 }
3451
3452 /**
Wu-cheng Lif9293e72011-02-25 13:35:10 +08003453 * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
3454 * is always supported. {@link android.graphics.ImageFormat#YV12}
3455 * is always supported since API level 12.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003456 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003457 * @return a list of supported preview formats. This method will always
3458 * return a list with at least one element.
3459 * @see android.graphics.ImageFormat
Eino-Ville Talvala95151632012-05-02 16:21:18 -07003460 * @see #setPreviewFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003461 */
3462 public List<Integer> getSupportedPreviewFormats() {
3463 String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
Chih-Chung Changeb68c462009-09-18 18:37:44 +08003464 ArrayList<Integer> formats = new ArrayList<Integer>();
3465 for (String s : split(str)) {
3466 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003467 if (f == ImageFormat.UNKNOWN) continue;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08003468 formats.add(f);
3469 }
3470 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003471 }
3472
3473 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003474 * <p>Sets the dimensions for pictures.</p>
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003475 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07003476 * <p>Applications need to consider the display orientation. See {@link
3477 * #setPreviewSize(int,int)} for reference.</p>
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08003478 *
Yin-Chia Yeh428256d2019-01-23 15:27:47 -08003479 * <p>Exception on 176x144 (QCIF) resolution:
3480 * Camera devices usually have a fixed capability for downscaling from
3481 * larger resolution to smaller, and the QCIF resolution sometimes
3482 * is not fully supported due to this limitation on devices with
3483 * high-resolution image sensors. Therefore, trying to configure a QCIF
3484 * picture size with any preview or video size larger than 1920x1080
3485 * (either width or height) might not be supported, and
3486 * {@link #setParameters(Camera.Parameters)} might throw a
3487 * RuntimeException if it is not.</p>
3488 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003489 * @param width the width for pictures, in pixels
3490 * @param height the height for pictures, in pixels
Wu-cheng Lic157e0c2010-10-07 18:36:07 +08003491 * @see #setPreviewSize(int,int)
3492 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 */
3494 public void setPictureSize(int width, int height) {
3495 String v = Integer.toString(width) + "x" + Integer.toString(height);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003496 set(KEY_PICTURE_SIZE, v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003497 }
3498
3499 /**
3500 * Returns the dimension setting for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003501 *
3502 * @return a Size object with the height and width setting
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003503 * for pictures
3504 */
3505 public Size getPictureSize() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003506 String pair = get(KEY_PICTURE_SIZE);
3507 return strToSize(pair);
3508 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003509
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003510 /**
3511 * Gets the supported picture sizes.
3512 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003513 * @return a list of supported picture sizes. This method will always
3514 * return a list with at least one element.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003515 */
3516 public List<Size> getSupportedPictureSizes() {
3517 String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
3518 return splitSize(str);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 }
3520
3521 /**
3522 * Sets the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003523 *
3524 * @param pixel_format the desired picture format
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003525 * (<var>ImageFormat.NV21</var>,
3526 * <var>ImageFormat.RGB_565</var>, or
3527 * <var>ImageFormat.JPEG</var>)
3528 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 */
3530 public void setPictureFormat(int pixel_format) {
3531 String s = cameraFormatForPixelFormat(pixel_format);
3532 if (s == null) {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003533 throw new IllegalArgumentException(
3534 "Invalid pixel_format=" + pixel_format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 }
3536
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003537 set(KEY_PICTURE_FORMAT, s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003538 }
3539
3540 /**
3541 * Returns the image format for pictures.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003542 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003543 * @return the picture format
3544 * @see android.graphics.ImageFormat
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 */
3546 public int getPictureFormat() {
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003547 return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
3548 }
3549
3550 /**
3551 * Gets the supported picture formats.
3552 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003553 * @return supported picture formats. This method will always return a
3554 * list with at least one element.
3555 * @see android.graphics.ImageFormat
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003556 */
3557 public List<Integer> getSupportedPictureFormats() {
Wu-cheng Li9c799382009-12-04 19:59:18 +08003558 String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
3559 ArrayList<Integer> formats = new ArrayList<Integer>();
3560 for (String s : split(str)) {
3561 int f = pixelFormatForCameraFormat(s);
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003562 if (f == ImageFormat.UNKNOWN) continue;
Wu-cheng Li9c799382009-12-04 19:59:18 +08003563 formats.add(f);
3564 }
3565 return formats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 }
3567
3568 private String cameraFormatForPixelFormat(int pixel_format) {
3569 switch(pixel_format) {
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003570 case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP;
3571 case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP;
3572 case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I;
Wu-cheng Li10a1b302011-02-22 15:49:25 +08003573 case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P;
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003574 case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565;
3575 case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG;
3576 default: return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 }
3578 }
3579
3580 private int pixelFormatForCameraFormat(String format) {
3581 if (format == null)
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003582 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003584 if (format.equals(PIXEL_FORMAT_YUV422SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003585 return ImageFormat.NV16;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003587 if (format.equals(PIXEL_FORMAT_YUV420SP))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003588 return ImageFormat.NV21;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003589
Chih-Chung Changeb68c462009-09-18 18:37:44 +08003590 if (format.equals(PIXEL_FORMAT_YUV422I))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003591 return ImageFormat.YUY2;
Chih-Chung Changeb68c462009-09-18 18:37:44 +08003592
Wu-cheng Li10a1b302011-02-22 15:49:25 +08003593 if (format.equals(PIXEL_FORMAT_YUV420P))
3594 return ImageFormat.YV12;
3595
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003596 if (format.equals(PIXEL_FORMAT_RGB565))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003597 return ImageFormat.RGB_565;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003599 if (format.equals(PIXEL_FORMAT_JPEG))
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003600 return ImageFormat.JPEG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601
Mathias Agopiana696f5d2010-02-17 17:53:09 -08003602 return ImageFormat.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 }
3604
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003605 /**
Wu-cheng Li8969ea12012-04-20 17:38:09 +08003606 * Sets the clockwise rotation angle in degrees relative to the
3607 * orientation of the camera. This affects the pictures returned from
3608 * JPEG {@link PictureCallback}. The camera driver may set orientation
3609 * in the EXIF header without rotating the picture. Or the driver may
3610 * rotate the picture and the EXIF thumbnail. If the Jpeg picture is
Igor Murashkina1b02db2013-06-11 15:25:20 -07003611 * rotated, the orientation in the EXIF header will be missing or 1 (row
3612 * #0 is top and column #0 is left side).
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003613 *
Igor Murashkina1b02db2013-06-11 15:25:20 -07003614 * <p>
3615 * If applications want to rotate the picture to match the orientation
3616 * of what users see, apps should use
3617 * {@link android.view.OrientationEventListener} and
3618 * {@link android.hardware.Camera.CameraInfo}. The value from
3619 * OrientationEventListener is relative to the natural orientation of
3620 * the device. CameraInfo.orientation is the angle between camera
3621 * orientation and natural device orientation. The sum of the two is the
3622 * rotation angle for back-facing camera. The difference of the two is
3623 * the rotation angle for front-facing camera. Note that the JPEG
3624 * pictures of front-facing cameras are not mirrored as in preview
3625 * display.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003626 *
Igor Murashkina1b02db2013-06-11 15:25:20 -07003627 * <p>
3628 * For example, suppose the natural orientation of the device is
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003629 * portrait. The device is rotated 270 degrees clockwise, so the device
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08003630 * orientation is 270. Suppose a back-facing camera sensor is mounted in
3631 * landscape and the top side of the camera sensor is aligned with the
3632 * right edge of the display in natural orientation. So the camera
3633 * orientation is 90. The rotation should be set to 0 (270 + 90).
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003634 *
Brad Fitzpatrick69ea4e12011-01-05 11:13:40 -08003635 * <p>The reference code is as follows.
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003636 *
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -08003637 * <pre>
Scott Main9a10bf02011-08-24 19:09:48 -07003638 * public void onOrientationChanged(int orientation) {
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003639 * if (orientation == ORIENTATION_UNKNOWN) return;
3640 * android.hardware.Camera.CameraInfo info =
3641 * new android.hardware.Camera.CameraInfo();
3642 * android.hardware.Camera.getCameraInfo(cameraId, info);
3643 * orientation = (orientation + 45) / 90 * 90;
Wu-cheng Li2fe6fca2010-10-15 14:42:23 +08003644 * int rotation = 0;
3645 * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
3646 * rotation = (info.orientation - orientation + 360) % 360;
3647 * } else { // back-facing camera
3648 * rotation = (info.orientation + orientation) % 360;
3649 * }
3650 * mParameters.setRotation(rotation);
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003651 * }
Eino-Ville Talvalae0cc55a2011-11-08 10:12:09 -08003652 * </pre>
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003653 *
3654 * @param rotation The rotation angle in degrees relative to the
3655 * orientation of the camera. Rotation can only be 0,
3656 * 90, 180 or 270.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003657 * @throws IllegalArgumentException if rotation value is invalid.
3658 * @see android.view.OrientationEventListener
Wu-cheng Li2fb818c2010-09-13 20:02:01 -07003659 * @see #getCameraInfo(int, CameraInfo)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003660 */
3661 public void setRotation(int rotation) {
3662 if (rotation == 0 || rotation == 90 || rotation == 180
3663 || rotation == 270) {
3664 set(KEY_ROTATION, Integer.toString(rotation));
3665 } else {
3666 throw new IllegalArgumentException(
3667 "Invalid rotation=" + rotation);
3668 }
3669 }
3670
3671 /**
3672 * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
3673 * header.
3674 *
3675 * @param latitude GPS latitude coordinate.
3676 */
3677 public void setGpsLatitude(double latitude) {
3678 set(KEY_GPS_LATITUDE, Double.toString(latitude));
3679 }
3680
3681 /**
3682 * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
3683 * header.
3684 *
3685 * @param longitude GPS longitude coordinate.
3686 */
3687 public void setGpsLongitude(double longitude) {
3688 set(KEY_GPS_LONGITUDE, Double.toString(longitude));
3689 }
3690
3691 /**
3692 * Sets GPS altitude. This will be stored in JPEG EXIF header.
3693 *
3694 * @param altitude GPS altitude in meters.
3695 */
3696 public void setGpsAltitude(double altitude) {
3697 set(KEY_GPS_ALTITUDE, Double.toString(altitude));
3698 }
3699
3700 /**
3701 * Sets GPS timestamp. This will be stored in JPEG EXIF header.
3702 *
3703 * @param timestamp GPS timestamp (UTC in seconds since January 1,
3704 * 1970).
3705 */
3706 public void setGpsTimestamp(long timestamp) {
3707 set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
3708 }
3709
3710 /**
Eino-Ville Talvalad8407272015-11-08 18:27:20 -08003711 * Sets GPS processing method. The method will be stored in a UTF-8 string up to 31 bytes
3712 * long, in the JPEG EXIF header.
Ray Chen055c9862010-02-23 10:45:42 +08003713 *
3714 * @param processing_method The processing method to get this location.
3715 */
3716 public void setGpsProcessingMethod(String processing_method) {
3717 set(KEY_GPS_PROCESSING_METHOD, processing_method);
3718 }
3719
3720 /**
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003721 * Removes GPS latitude, longitude, altitude, and timestamp from the
3722 * parameters.
3723 */
3724 public void removeGpsData() {
Sauhard Pandec44f2d92015-07-09 14:47:34 -07003725 remove(KEY_QC_GPS_LATITUDE_REF);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003726 remove(KEY_GPS_LATITUDE);
Sauhard Pandec44f2d92015-07-09 14:47:34 -07003727 remove(KEY_QC_GPS_LONGITUDE_REF);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003728 remove(KEY_GPS_LONGITUDE);
Sauhard Pandec44f2d92015-07-09 14:47:34 -07003729 remove(KEY_QC_GPS_ALTITUDE_REF);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003730 remove(KEY_GPS_ALTITUDE);
3731 remove(KEY_GPS_TIMESTAMP);
Ray Chen055c9862010-02-23 10:45:42 +08003732 remove(KEY_GPS_PROCESSING_METHOD);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003733 }
3734
3735 /**
3736 * Gets the current white balance setting.
3737 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003738 * @return current white balance. null if white balance setting is not
3739 * supported.
3740 * @see #WHITE_BALANCE_AUTO
3741 * @see #WHITE_BALANCE_INCANDESCENT
3742 * @see #WHITE_BALANCE_FLUORESCENT
3743 * @see #WHITE_BALANCE_WARM_FLUORESCENT
3744 * @see #WHITE_BALANCE_DAYLIGHT
3745 * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
3746 * @see #WHITE_BALANCE_TWILIGHT
3747 * @see #WHITE_BALANCE_SHADE
3748 *
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003749 */
3750 public String getWhiteBalance() {
3751 return get(KEY_WHITE_BALANCE);
3752 }
3753
3754 /**
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003755 * Sets the white balance. Changing the setting will release the
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08003756 * auto-white balance lock. It is recommended not to change white
3757 * balance and AWB lock at the same time.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003758 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003759 * @param value new white balance.
3760 * @see #getWhiteBalance()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07003761 * @see #setAutoWhiteBalanceLock(boolean)
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003762 */
3763 public void setWhiteBalance(String value) {
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08003764 String oldValue = get(KEY_WHITE_BALANCE);
3765 if (same(value, oldValue)) return;
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003766 set(KEY_WHITE_BALANCE, value);
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07003767 set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003768 }
3769
3770 /**
3771 * Gets the supported white balance.
3772 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003773 * @return a list of supported white balance. null if white balance
3774 * setting is not supported.
3775 * @see #getWhiteBalance()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003776 */
3777 public List<String> getSupportedWhiteBalance() {
3778 String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
3779 return split(str);
3780 }
3781
3782 /**
3783 * Gets the current color effect setting.
3784 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003785 * @return current color effect. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003786 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003787 * @see #EFFECT_NONE
3788 * @see #EFFECT_MONO
3789 * @see #EFFECT_NEGATIVE
3790 * @see #EFFECT_SOLARIZE
3791 * @see #EFFECT_SEPIA
3792 * @see #EFFECT_POSTERIZE
3793 * @see #EFFECT_WHITEBOARD
3794 * @see #EFFECT_BLACKBOARD
3795 * @see #EFFECT_AQUA
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003796 */
3797 public String getColorEffect() {
3798 return get(KEY_EFFECT);
3799 }
3800
3801 /**
3802 * Sets the current color effect setting.
3803 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003804 * @param value new color effect.
3805 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003806 */
3807 public void setColorEffect(String value) {
3808 set(KEY_EFFECT, value);
3809 }
3810
3811 /**
3812 * Gets the supported color effects.
3813 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003814 * @return a list of supported color effects. null if color effect
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003815 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003816 * @see #getColorEffect()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003817 */
3818 public List<String> getSupportedColorEffects() {
3819 String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
3820 return split(str);
3821 }
3822
3823
3824 /**
3825 * Gets the current antibanding setting.
3826 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003827 * @return current antibanding. null if antibanding setting is not
3828 * supported.
3829 * @see #ANTIBANDING_AUTO
3830 * @see #ANTIBANDING_50HZ
3831 * @see #ANTIBANDING_60HZ
3832 * @see #ANTIBANDING_OFF
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003833 */
3834 public String getAntibanding() {
3835 return get(KEY_ANTIBANDING);
3836 }
3837
3838 /**
3839 * Sets the antibanding.
3840 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003841 * @param antibanding new antibanding value.
3842 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003843 */
3844 public void setAntibanding(String antibanding) {
3845 set(KEY_ANTIBANDING, antibanding);
3846 }
3847
3848 /**
3849 * Gets the supported antibanding values.
3850 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003851 * @return a list of supported antibanding values. null if antibanding
3852 * setting is not supported.
3853 * @see #getAntibanding()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003854 */
3855 public List<String> getSupportedAntibanding() {
3856 String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
3857 return split(str);
3858 }
3859
3860 /**
3861 * Gets the current scene mode setting.
3862 *
3863 * @return one of SCENE_MODE_XXX string constant. null if scene mode
3864 * setting is not supported.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003865 * @see #SCENE_MODE_AUTO
3866 * @see #SCENE_MODE_ACTION
3867 * @see #SCENE_MODE_PORTRAIT
3868 * @see #SCENE_MODE_LANDSCAPE
3869 * @see #SCENE_MODE_NIGHT
3870 * @see #SCENE_MODE_NIGHT_PORTRAIT
3871 * @see #SCENE_MODE_THEATRE
3872 * @see #SCENE_MODE_BEACH
3873 * @see #SCENE_MODE_SNOW
3874 * @see #SCENE_MODE_SUNSET
3875 * @see #SCENE_MODE_STEADYPHOTO
3876 * @see #SCENE_MODE_FIREWORKS
3877 * @see #SCENE_MODE_SPORTS
3878 * @see #SCENE_MODE_PARTY
3879 * @see #SCENE_MODE_CANDLELIGHT
Eino-Ville Talvalada2f0ea2012-09-10 12:03:35 -07003880 * @see #SCENE_MODE_BARCODE
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003881 */
3882 public String getSceneMode() {
3883 return get(KEY_SCENE_MODE);
3884 }
3885
3886 /**
Wu-cheng Lic58b4232010-03-29 17:21:28 +08003887 * Sets the scene mode. Changing scene mode may override other
3888 * parameters (such as flash mode, focus mode, white balance). For
3889 * example, suppose originally flash mode is on and supported flash
3890 * modes are on/off. In night scene mode, both flash mode and supported
3891 * flash mode may be changed to off. After setting scene mode,
Wu-cheng Li2988ab72009-09-30 17:08:19 -07003892 * applications should call getParameters to know if some parameters are
3893 * changed.
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003894 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003895 * @param value scene mode.
3896 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003897 */
3898 public void setSceneMode(String value) {
3899 set(KEY_SCENE_MODE, value);
3900 }
3901
3902 /**
3903 * Gets the supported scene modes.
3904 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003905 * @return a list of supported scene modes. null if scene mode setting
3906 * is not supported.
3907 * @see #getSceneMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003908 */
3909 public List<String> getSupportedSceneModes() {
3910 String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
3911 return split(str);
3912 }
3913
3914 /**
3915 * Gets the current flash mode setting.
3916 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003917 * @return current flash mode. null if flash mode setting is not
3918 * supported.
3919 * @see #FLASH_MODE_OFF
3920 * @see #FLASH_MODE_AUTO
3921 * @see #FLASH_MODE_ON
3922 * @see #FLASH_MODE_RED_EYE
3923 * @see #FLASH_MODE_TORCH
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003924 */
3925 public String getFlashMode() {
3926 return get(KEY_FLASH_MODE);
3927 }
3928
3929 /**
3930 * Sets the flash mode.
3931 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003932 * @param value flash mode.
3933 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003934 */
3935 public void setFlashMode(String value) {
3936 set(KEY_FLASH_MODE, value);
3937 }
3938
3939 /**
3940 * Gets the supported flash modes.
3941 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003942 * @return a list of supported flash modes. null if flash mode setting
3943 * is not supported.
3944 * @see #getFlashMode()
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08003945 */
3946 public List<String> getSupportedFlashModes() {
3947 String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
3948 return split(str);
3949 }
3950
Wu-cheng Li36322db2009-09-18 18:59:21 +08003951 /**
3952 * Gets the current focus mode setting.
3953 *
Wu-cheng Li699fe932010-08-05 11:50:25 -07003954 * @return current focus mode. This method will always return a non-null
3955 * value. Applications should call {@link
3956 * #autoFocus(AutoFocusCallback)} to start the focus if focus
3957 * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003958 * @see #FOCUS_MODE_AUTO
3959 * @see #FOCUS_MODE_INFINITY
3960 * @see #FOCUS_MODE_MACRO
3961 * @see #FOCUS_MODE_FIXED
Wu-cheng Lif008f3e2010-08-17 13:44:35 -07003962 * @see #FOCUS_MODE_EDOF
Wu-cheng Lid45cb722010-09-20 16:15:32 -07003963 * @see #FOCUS_MODE_CONTINUOUS_VIDEO
Wu-cheng Li36322db2009-09-18 18:59:21 +08003964 */
3965 public String getFocusMode() {
3966 return get(KEY_FOCUS_MODE);
3967 }
3968
3969 /**
3970 * Sets the focus mode.
3971 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003972 * @param value focus mode.
3973 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08003974 */
3975 public void setFocusMode(String value) {
3976 set(KEY_FOCUS_MODE, value);
3977 }
3978
3979 /**
3980 * Gets the supported focus modes.
3981 *
Wu-cheng Li3f4639a2010-04-04 15:05:41 +08003982 * @return a list of supported focus modes. This method will always
3983 * return a list with at least one element.
3984 * @see #getFocusMode()
Wu-cheng Li36322db2009-09-18 18:59:21 +08003985 */
3986 public List<String> getSupportedFocusModes() {
3987 String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
3988 return split(str);
3989 }
3990
Wu-cheng Li36f68b82009-09-28 16:14:58 -07003991 /**
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08003992 * Gets the focal length (in millimeter) of the camera.
3993 *
Yin-Chia Yehbb85e1c2018-02-27 11:50:48 -08003994 * @return the focal length. Returns -1.0 when the device
3995 * doesn't report focal length information.
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08003996 */
3997 public float getFocalLength() {
3998 return Float.parseFloat(get(KEY_FOCAL_LENGTH));
3999 }
4000
4001 /**
4002 * Gets the horizontal angle of view in degrees.
4003 *
Yin-Chia Yeh564ae822018-02-08 16:24:27 -08004004 * @return horizontal angle of view. Returns -1.0 when the device
4005 * doesn't report view angle information.
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08004006 */
4007 public float getHorizontalViewAngle() {
4008 return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
4009 }
4010
4011 /**
4012 * Gets the vertical angle of view in degrees.
4013 *
Yin-Chia Yeh564ae822018-02-08 16:24:27 -08004014 * @return vertical angle of view. Returns -1.0 when the device
4015 * doesn't report view angle information.
Wu-cheng Li6c8d2762010-01-27 22:55:14 +08004016 */
4017 public float getVerticalViewAngle() {
4018 return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
4019 }
4020
4021 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004022 * Gets the current exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08004023 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004024 * @return current exposure compensation index. The range is {@link
4025 * #getMinExposureCompensation} to {@link
4026 * #getMaxExposureCompensation}. 0 means exposure is not
4027 * adjusted.
Wu-cheng Liff723b62010-02-09 13:38:19 +08004028 */
4029 public int getExposureCompensation() {
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004030 return getInt(KEY_EXPOSURE_COMPENSATION, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08004031 }
4032
4033 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004034 * Sets the exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08004035 *
Wu-cheng Li0402e7d2010-02-26 15:04:55 +08004036 * @param value exposure compensation index. The valid value range is
4037 * from {@link #getMinExposureCompensation} (inclusive) to {@link
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004038 * #getMaxExposureCompensation} (inclusive). 0 means exposure is
4039 * not adjusted. Application should call
4040 * getMinExposureCompensation and getMaxExposureCompensation to
4041 * know if exposure compensation is supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08004042 */
4043 public void setExposureCompensation(int value) {
4044 set(KEY_EXPOSURE_COMPENSATION, value);
4045 }
4046
4047 /**
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004048 * Gets the maximum exposure compensation index.
Wu-cheng Liff723b62010-02-09 13:38:19 +08004049 *
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004050 * @return maximum exposure compensation index (>=0). If both this
4051 * method and {@link #getMinExposureCompensation} return 0,
4052 * exposure compensation is not supported.
Wu-cheng Liff723b62010-02-09 13:38:19 +08004053 */
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004054 public int getMaxExposureCompensation() {
4055 return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
4056 }
4057
4058 /**
4059 * Gets the minimum exposure compensation index.
4060 *
4061 * @return minimum exposure compensation index (<=0). If both this
4062 * method and {@link #getMaxExposureCompensation} return 0,
4063 * exposure compensation is not supported.
4064 */
4065 public int getMinExposureCompensation() {
4066 return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
4067 }
4068
4069 /**
4070 * Gets the exposure compensation step.
4071 *
4072 * @return exposure compensation step. Applications can get EV by
4073 * multiplying the exposure compensation index and step. Ex: if
4074 * exposure compensation index is -6 and step is 0.333333333, EV
4075 * is -2.
4076 */
4077 public float getExposureCompensationStep() {
4078 return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
Wu-cheng Liff723b62010-02-09 13:38:19 +08004079 }
4080
4081 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004082 * <p>Sets the auto-exposure lock state. Applications should check
4083 * {@link #isAutoExposureLockSupported} before using this method.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07004084 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004085 * <p>If set to true, the camera auto-exposure routine will immediately
4086 * pause until the lock is set to false. Exposure compensation settings
4087 * changes will still take effect while auto-exposure is locked.</p>
4088 *
4089 * <p>If auto-exposure is already locked, setting this to true again has
4090 * no effect (the driver will not recalculate exposure values).</p>
4091 *
4092 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
4093 * image capture with {@link #takePicture(Camera.ShutterCallback,
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08004094 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
4095 * lock.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004096 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08004097 * <p>Exposure compensation, auto-exposure lock, and auto-white balance
4098 * lock can be used to capture an exposure-bracketed burst of images,
4099 * for example.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004100 *
4101 * <p>Auto-exposure state, including the lock state, will not be
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07004102 * maintained after camera {@link #release()} is called. Locking
4103 * auto-exposure after {@link #open()} but before the first call to
4104 * {@link #startPreview()} will not allow the auto-exposure routine to
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004105 * run at all, and may result in severely over- or under-exposed
4106 * images.</p>
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07004107 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07004108 * @param toggle new state of the auto-exposure lock. True means that
4109 * auto-exposure is locked, false means that the auto-exposure
4110 * routine is free to run normally.
4111 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004112 * @see #getAutoExposureLock()
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07004113 */
4114 public void setAutoExposureLock(boolean toggle) {
4115 set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
4116 }
4117
4118 /**
4119 * Gets the state of the auto-exposure lock. Applications should check
4120 * {@link #isAutoExposureLockSupported} before using this method. See
4121 * {@link #setAutoExposureLock} for details about the lock.
4122 *
4123 * @return State of the auto-exposure lock. Returns true if
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08004124 * auto-exposure is currently locked, and false otherwise.
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07004125 *
4126 * @see #setAutoExposureLock(boolean)
4127 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07004128 */
4129 public boolean getAutoExposureLock() {
4130 String str = get(KEY_AUTO_EXPOSURE_LOCK);
4131 return TRUE.equals(str);
4132 }
4133
4134 /**
4135 * Returns true if auto-exposure locking is supported. Applications
4136 * should call this before trying to lock auto-exposure. See
4137 * {@link #setAutoExposureLock} for details about the lock.
4138 *
4139 * @return true if auto-exposure lock is supported.
4140 * @see #setAutoExposureLock(boolean)
4141 *
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -07004142 */
4143 public boolean isAutoExposureLockSupported() {
4144 String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
4145 return TRUE.equals(str);
4146 }
4147
4148 /**
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004149 * <p>Sets the auto-white balance lock state. Applications should check
4150 * {@link #isAutoWhiteBalanceLockSupported} before using this
4151 * method.</p>
4152 *
4153 * <p>If set to true, the camera auto-white balance routine will
4154 * immediately pause until the lock is set to false.</p>
4155 *
4156 * <p>If auto-white balance is already locked, setting this to true
4157 * again has no effect (the driver will not recalculate white balance
4158 * values).</p>
4159 *
4160 * <p>Stopping preview with {@link #stopPreview()}, or triggering still
4161 * image capture with {@link #takePicture(Camera.ShutterCallback,
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08004162 * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
4163 * the lock.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004164 *
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07004165 * <p> Changing the white balance mode with {@link #setWhiteBalance}
4166 * will release the auto-white balance lock if it is set.</p>
4167 *
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08004168 * <p>Exposure compensation, AE lock, and AWB lock can be used to
4169 * capture an exposure-bracketed burst of images, for example.
4170 * Auto-white balance state, including the lock state, will not be
4171 * maintained after camera {@link #release()} is called. Locking
4172 * auto-white balance after {@link #open()} but before the first call to
4173 * {@link #startPreview()} will not allow the auto-white balance routine
4174 * to run at all, and may result in severely incorrect color in captured
4175 * images.</p>
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004176 *
4177 * @param toggle new state of the auto-white balance lock. True means
4178 * that auto-white balance is locked, false means that the
4179 * auto-white balance routine is free to run normally.
4180 *
4181 * @see #getAutoWhiteBalanceLock()
Eino-Ville Talvala16b67132011-08-18 13:57:49 -07004182 * @see #setWhiteBalance(String)
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004183 */
4184 public void setAutoWhiteBalanceLock(boolean toggle) {
4185 set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
4186 }
4187
4188 /**
4189 * Gets the state of the auto-white balance lock. Applications should
4190 * check {@link #isAutoWhiteBalanceLockSupported} before using this
4191 * method. See {@link #setAutoWhiteBalanceLock} for details about the
4192 * lock.
4193 *
4194 * @return State of the auto-white balance lock. Returns true if
4195 * auto-white balance is currently locked, and false
Wu-cheng Lib4f95be2011-09-22 11:43:28 +08004196 * otherwise.
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004197 *
4198 * @see #setAutoWhiteBalanceLock(boolean)
4199 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004200 */
4201 public boolean getAutoWhiteBalanceLock() {
4202 String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
4203 return TRUE.equals(str);
4204 }
4205
4206 /**
4207 * Returns true if auto-white balance locking is supported. Applications
4208 * should call this before trying to lock auto-white balance. See
4209 * {@link #setAutoWhiteBalanceLock} for details about the lock.
4210 *
4211 * @return true if auto-white balance lock is supported.
4212 * @see #setAutoWhiteBalanceLock(boolean)
4213 *
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -07004214 */
4215 public boolean isAutoWhiteBalanceLockSupported() {
4216 String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
4217 return TRUE.equals(str);
4218 }
4219
4220 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004221 * Gets current zoom value. This also works when smooth zoom is in
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004222 * progress. Applications should check {@link #isZoomSupported} before
4223 * using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004224 *
4225 * @return the current zoom value. The range is 0 to {@link
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004226 * #getMaxZoom}. 0 means the camera is not zoomed.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004227 */
4228 public int getZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004229 return getInt(KEY_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004230 }
4231
4232 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004233 * Sets current zoom value. If the camera is zoomed (value > 0), the
4234 * actual picture size may be smaller than picture size setting.
4235 * Applications can check the actual picture size after picture is
4236 * returned from {@link PictureCallback}. The preview size remains the
4237 * same in zoom. Applications should check {@link #isZoomSupported}
4238 * before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004239 *
4240 * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004241 */
4242 public void setZoom(int value) {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004243 set(KEY_ZOOM, value);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004244 }
4245
4246 /**
4247 * Returns true if zoom is supported. Applications should call this
4248 * before using other zoom methods.
4249 *
4250 * @return true if zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004251 */
4252 public boolean isZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004253 String str = get(KEY_ZOOM_SUPPORTED);
4254 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004255 }
4256
4257 /**
4258 * Gets the maximum zoom value allowed for snapshot. This is the maximum
4259 * value that applications can set to {@link #setZoom(int)}.
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004260 * Applications should call {@link #isZoomSupported} before using this
4261 * method. This value may change in different preview size. Applications
4262 * should call this again after setting preview size.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004263 *
4264 * @return the maximum zoom value supported by the camera.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004265 */
4266 public int getMaxZoom() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004267 return getInt(KEY_MAX_ZOOM, 0);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004268 }
4269
4270 /**
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004271 * Gets the zoom ratios of all zoom values. Applications should check
4272 * {@link #isZoomSupported} before using this method.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004273 *
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004274 * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
4275 * returned as 320. The number of elements is {@link
4276 * #getMaxZoom} + 1. The list is sorted from small to large. The
4277 * first element is always 100. The last element is the zoom
4278 * ratio of the maximum zoom value.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004279 */
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004280 public List<Integer> getZoomRatios() {
4281 return splitInt(get(KEY_ZOOM_RATIOS));
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004282 }
4283
4284 /**
4285 * Returns true if smooth zoom is supported. Applications should call
4286 * this before using other smooth zoom methods.
4287 *
4288 * @return true if smooth zoom is supported.
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004289 */
4290 public boolean isSmoothZoomSupported() {
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -08004291 String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
4292 return TRUE.equals(str);
Wu-cheng Li36f68b82009-09-28 16:14:58 -07004293 }
4294
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004295 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004296 * <p>Gets the distances from the camera to where an object appears to be
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004297 * in focus. The object is sharpest at the optimal focus distance. The
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004298 * depth of field is the far focus distance minus near focus distance.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004299 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004300 * <p>Focus distances may change after calling {@link
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004301 * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
4302 * #startPreview()}. Applications can call {@link #getParameters()}
4303 * and this method anytime to get the latest focus distances. If the
Wu-cheng Lid45cb722010-09-20 16:15:32 -07004304 * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004305 * from time to time.</p>
Wu-cheng Li699fe932010-08-05 11:50:25 -07004306 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004307 * <p>This method is intended to estimate the distance between the camera
Wu-cheng Li699fe932010-08-05 11:50:25 -07004308 * and the subject. After autofocus, the subject distance may be within
4309 * near and far focus distance. However, the precision depends on the
4310 * camera hardware, autofocus algorithm, the focus area, and the scene.
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004311 * The error can be large and it should be only used as a reference.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004312 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004313 * <p>Far focus distance >= optimal focus distance >= near focus distance.
Wu-cheng Li185cc452010-05-20 15:36:13 +08004314 * If the focus distance is infinity, the value will be
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004315 * {@code Float.POSITIVE_INFINITY}.</p>
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004316 *
4317 * @param output focus distances in meters. output must be a float
4318 * array with three elements. Near focus distance, optimal focus
4319 * distance, and far focus distance will be filled in the array.
Wu-cheng Li185cc452010-05-20 15:36:13 +08004320 * @see #FOCUS_DISTANCE_NEAR_INDEX
4321 * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
4322 * @see #FOCUS_DISTANCE_FAR_INDEX
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004323 */
4324 public void getFocusDistances(float[] output) {
4325 if (output == null || output.length != 3) {
4326 throw new IllegalArgumentException(
Ken Wakasaf76a50c2012-03-09 19:56:35 +09004327 "output must be a float array with three elements.");
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004328 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07004329 splitFloat(get(KEY_FOCUS_DISTANCES), output);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004330 }
4331
Wu-cheng Li30771b72011-04-02 06:19:46 +08004332 /**
4333 * Gets the maximum number of focus areas supported. This is the maximum
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08004334 * length of the list in {@link #setFocusAreas(List)} and
4335 * {@link #getFocusAreas()}.
Wu-cheng Li30771b72011-04-02 06:19:46 +08004336 *
4337 * @return the maximum number of focus areas supported by the camera.
4338 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08004339 */
4340 public int getMaxNumFocusAreas() {
4341 return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
4342 }
4343
4344 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004345 * <p>Gets the current focus areas. Camera driver uses the areas to decide
4346 * focus.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08004347 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004348 * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08004349 * call {@link #getMaxNumFocusAreas()} to know the maximum number of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004350 * focus areas first. If the value is 0, focus area is not supported.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08004351 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004352 * <p>Each focus area is a rectangle with specified weight. The direction
Wu-cheng Li30771b72011-04-02 06:19:46 +08004353 * is relative to the sensor orientation, that is, what the sensor sees.
4354 * The direction is not affected by the rotation or mirroring of
4355 * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
4356 * range from -1000 to 1000. (-1000, -1000) is the upper left point.
Wu-cheng Libde61a52011-06-07 18:23:14 +08004357 * (1000, 1000) is the lower right point. The width and height of focus
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004358 * areas cannot be 0 or negative.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08004359 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004360 * <p>The weight must range from 1 to 1000. The weight should be
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07004361 * interpreted as a per-pixel weight - all pixels in the area have the
4362 * specified weight. This means a small area with the same weight as a
4363 * larger area will have less influence on the focusing than the larger
4364 * area. Focus areas can partially overlap and the driver will add the
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004365 * weights in the overlap region.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08004366 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004367 * <p>A special case of a {@code null} focus area list means the driver is
4368 * free to select focus targets as it wants. For example, the driver may
4369 * use more signals to select focus areas and change them
4370 * dynamically. Apps can set the focus area list to {@code null} if they
4371 * want the driver to completely control focusing.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08004372 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004373 * <p>Focus areas are relative to the current field of view
Wu-cheng Li30771b72011-04-02 06:19:46 +08004374 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
4375 * represents the top of the currently visible camera frame. The focus
4376 * area cannot be set to be outside the current field of view, even
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004377 * when using zoom.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08004378 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004379 * <p>Focus area only has effect if the current focus mode is
Wu-cheng Li53b30912011-10-12 19:43:51 +08004380 * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO},
4381 * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or
4382 * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p>
Wu-cheng Li30771b72011-04-02 06:19:46 +08004383 *
4384 * @return a list of current focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08004385 */
4386 public List<Area> getFocusAreas() {
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004387 return splitArea(get(KEY_FOCUS_AREAS));
Wu-cheng Li30771b72011-04-02 06:19:46 +08004388 }
4389
4390 /**
4391 * Sets focus areas. See {@link #getFocusAreas()} for documentation.
4392 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08004393 * @param focusAreas the focus areas
Wu-cheng Li30771b72011-04-02 06:19:46 +08004394 * @see #getFocusAreas()
Wu-cheng Li30771b72011-04-02 06:19:46 +08004395 */
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004396 public void setFocusAreas(List<Area> focusAreas) {
4397 set(KEY_FOCUS_AREAS, focusAreas);
4398 }
4399
4400 /**
4401 * Gets the maximum number of metering areas supported. This is the
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08004402 * maximum length of the list in {@link #setMeteringAreas(List)} and
4403 * {@link #getMeteringAreas()}.
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004404 *
4405 * @return the maximum number of metering areas supported by the camera.
4406 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004407 */
4408 public int getMaxNumMeteringAreas() {
4409 return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
4410 }
4411
4412 /**
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004413 * <p>Gets the current metering areas. Camera driver uses these areas to
4414 * decide exposure.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004415 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004416 * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08004417 * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
4418 * metering areas first. If the value is 0, metering area is not
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004419 * supported.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004420 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004421 * <p>Each metering area is a rectangle with specified weight. The
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004422 * direction is relative to the sensor orientation, that is, what the
4423 * sensor sees. The direction is not affected by the rotation or
4424 * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
4425 * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
Wu-cheng Libde61a52011-06-07 18:23:14 +08004426 * point. (1000, 1000) is the lower right point. The width and height of
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004427 * metering areas cannot be 0 or negative.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004428 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004429 * <p>The weight must range from 1 to 1000, and represents a weight for
Eino-Ville Talvala4e396e02011-04-21 09:23:15 -07004430 * every pixel in the area. This means that a large metering area with
4431 * the same weight as a smaller area will have more effect in the
4432 * metering result. Metering areas can partially overlap and the driver
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004433 * will add the weights in the overlap region.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004434 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004435 * <p>A special case of a {@code null} metering area list means the driver
4436 * is free to meter as it chooses. For example, the driver may use more
4437 * signals to select metering areas and change them dynamically. Apps
4438 * can set the metering area list to {@code null} if they want the
4439 * driver to completely control metering.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004440 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004441 * <p>Metering areas are relative to the current field of view
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004442 * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
4443 * represents the top of the currently visible camera frame. The
4444 * metering area cannot be set to be outside the current field of view,
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004445 * even when using zoom.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004446 *
Eino-Ville Talvala32a972c2011-06-07 10:34:56 -07004447 * <p>No matter what metering areas are, the final exposure are compensated
4448 * by {@link #setExposureCompensation(int)}.</p>
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004449 *
4450 * @return a list of current metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004451 */
4452 public List<Area> getMeteringAreas() {
Wu-cheng Lid8aab932011-06-21 11:50:43 +08004453 return splitArea(get(KEY_METERING_AREAS));
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004454 }
4455
4456 /**
4457 * Sets metering areas. See {@link #getMeteringAreas()} for
4458 * documentation.
4459 *
Wu-cheng Li7b1c5c82011-04-15 19:16:52 +08004460 * @param meteringAreas the metering areas
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004461 * @see #getMeteringAreas()
Wu-cheng Lie98e4c82011-04-12 19:34:29 +08004462 */
4463 public void setMeteringAreas(List<Area> meteringAreas) {
4464 set(KEY_METERING_AREAS, meteringAreas);
Wu-cheng Li30771b72011-04-02 06:19:46 +08004465 }
4466
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08004467 /**
4468 * Gets the maximum number of detected faces supported. This is the
4469 * maximum length of the list returned from {@link FaceDetectionListener}.
4470 * If the return value is 0, face detection of the specified type is not
4471 * supported.
4472 *
4473 * @return the maximum number of detected face supported by the camera.
Joe Fernandez464cb212011-10-04 16:56:47 -07004474 * @see #startFaceDetection()
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08004475 */
Wu-cheng Lic0c683b2011-08-04 00:11:00 +08004476 public int getMaxNumDetectedFaces() {
4477 return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08004478 }
4479
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08004480 /**
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08004481 * Sets recording mode hint. This tells the camera that the intent of
4482 * the application is to record videos {@link
4483 * android.media.MediaRecorder#start()}, not to take still pictures
4484 * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
4485 * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
4486 * allow MediaRecorder.start() to start faster or with fewer glitches on
4487 * output. This should be called before starting preview for the best
4488 * result, but can be changed while the preview is active. The default
4489 * value is false.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08004490 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08004491 * The app can still call takePicture() when the hint is true or call
4492 * MediaRecorder.start() when the hint is false. But the performance may
4493 * be worse.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08004494 *
Wu-cheng Li9c53f1c2011-08-02 17:26:58 +08004495 * @param hint true if the apps intend to record videos using
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08004496 * {@link android.media.MediaRecorder}.
Wu-cheng Li25d8fb52011-08-02 13:20:36 +08004497 */
4498 public void setRecordingHint(boolean hint) {
4499 set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
4500 }
4501
Wu-cheng Li98bb2512011-08-30 21:33:10 +08004502 /**
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08004503 * <p>Returns true if video snapshot is supported. That is, applications
Wu-cheng Li98bb2512011-08-30 21:33:10 +08004504 * can call {@link #takePicture(Camera.ShutterCallback,
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08004505 * Camera.PictureCallback, Camera.PictureCallback,
4506 * Camera.PictureCallback)} during recording. Applications do not need
4507 * to call {@link #startPreview()} after taking a picture. The preview
4508 * will be still active. Other than that, taking a picture during
4509 * recording is identical to taking a picture normally. All settings and
4510 * methods related to takePicture work identically. Ex:
4511 * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()},
4512 * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The
4513 * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and
4514 * {@link #FLASH_MODE_ON} also still work, but the video will record the
4515 * flash.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08004516 *
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08004517 * <p>Applications can set shutter callback as null to avoid the shutter
Wu-cheng Li98bb2512011-08-30 21:33:10 +08004518 * sound. It is also recommended to set raw picture and post view
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08004519 * callbacks to null to avoid the interrupt of preview display.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08004520 *
Eino-Ville Talvala1cab31a2012-11-05 10:33:55 -08004521 * <p>Field-of-view of the recorded video may be different from that of the
4522 * captured pictures. The maximum size of a video snapshot may be
4523 * smaller than that for regular still captures. If the current picture
4524 * size is set higher than can be supported by video snapshot, the
4525 * picture will be captured at the maximum supported size instead.</p>
Wu-cheng Li98bb2512011-08-30 21:33:10 +08004526 *
4527 * @return true if video snapshot is supported.
Wu-cheng Li98bb2512011-08-30 21:33:10 +08004528 */
4529 public boolean isVideoSnapshotSupported() {
4530 String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED);
4531 return TRUE.equals(str);
4532 }
4533
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004534 /**
4535 * <p>Enables and disables video stabilization. Use
4536 * {@link #isVideoStabilizationSupported} to determine if calling this
4537 * method is valid.</p>
4538 *
4539 * <p>Video stabilization reduces the shaking due to the motion of the
4540 * camera in both the preview stream and in recorded videos, including
4541 * data received from the preview callback. It does not reduce motion
4542 * blur in images captured with
4543 * {@link Camera#takePicture takePicture}.</p>
4544 *
4545 * <p>Video stabilization can be enabled and disabled while preview or
4546 * recording is active, but toggling it may cause a jump in the video
4547 * stream that may be undesirable in a recorded video.</p>
4548 *
4549 * @param toggle Set to true to enable video stabilization, and false to
4550 * disable video stabilization.
4551 * @see #isVideoStabilizationSupported()
4552 * @see #getVideoStabilization()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004553 */
4554 public void setVideoStabilization(boolean toggle) {
4555 set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE);
4556 }
4557
4558 /**
4559 * Get the current state of video stabilization. See
4560 * {@link #setVideoStabilization} for details of video stabilization.
4561 *
4562 * @return true if video stabilization is enabled
4563 * @see #isVideoStabilizationSupported()
4564 * @see #setVideoStabilization(boolean)
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004565 */
4566 public boolean getVideoStabilization() {
4567 String str = get(KEY_VIDEO_STABILIZATION);
4568 return TRUE.equals(str);
4569 }
4570
4571 /**
4572 * Returns true if video stabilization is supported. See
4573 * {@link #setVideoStabilization} for details of video stabilization.
4574 *
4575 * @return true if video stabilization is supported
4576 * @see #setVideoStabilization(boolean)
4577 * @see #getVideoStabilization()
Eino-Ville Talvala037abb82011-10-11 12:41:58 -07004578 */
4579 public boolean isVideoStabilizationSupported() {
4580 String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED);
4581 return TRUE.equals(str);
4582 }
4583
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004584 // Splits a comma delimited string to an ArrayList of String.
4585 // Return null if the passing string is null or the size is 0.
4586 private ArrayList<String> split(String str) {
4587 if (str == null) return null;
4588
Ali Utku Selen0a120182011-02-09 14:11:22 +01004589 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4590 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004591 ArrayList<String> substrings = new ArrayList<String>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01004592 for (String s : splitter) {
4593 substrings.add(s);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004594 }
4595 return substrings;
4596 }
4597
4598 // Splits a comma delimited string to an ArrayList of Integer.
4599 // Return null if the passing string is null or the size is 0.
4600 private ArrayList<Integer> splitInt(String str) {
4601 if (str == null) return null;
4602
Ali Utku Selen0a120182011-02-09 14:11:22 +01004603 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4604 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004605 ArrayList<Integer> substrings = new ArrayList<Integer>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01004606 for (String s : splitter) {
4607 substrings.add(Integer.parseInt(s));
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004608 }
4609 if (substrings.size() == 0) return null;
4610 return substrings;
4611 }
4612
Wu-cheng Li454630f2010-08-11 16:48:05 -07004613 private void splitInt(String str, int[] output) {
4614 if (str == null) return;
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004615
Ali Utku Selen0a120182011-02-09 14:11:22 +01004616 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4617 splitter.setString(str);
Wu-cheng Li454630f2010-08-11 16:48:05 -07004618 int index = 0;
Ali Utku Selen0a120182011-02-09 14:11:22 +01004619 for (String s : splitter) {
4620 output[index++] = Integer.parseInt(s);
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004621 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07004622 }
4623
4624 // Splits a comma delimited string to an ArrayList of Float.
4625 private void splitFloat(String str, float[] output) {
4626 if (str == null) return;
4627
Ali Utku Selen0a120182011-02-09 14:11:22 +01004628 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4629 splitter.setString(str);
Wu-cheng Li454630f2010-08-11 16:48:05 -07004630 int index = 0;
Ali Utku Selen0a120182011-02-09 14:11:22 +01004631 for (String s : splitter) {
4632 output[index++] = Float.parseFloat(s);
Wu-cheng Li454630f2010-08-11 16:48:05 -07004633 }
Wu-cheng Lie339c5e2010-05-13 19:31:02 +08004634 }
4635
Wu-cheng Li24b326a2010-02-20 17:47:04 +08004636 // Returns the value of a float parameter.
4637 private float getFloat(String key, float defaultValue) {
4638 try {
4639 return Float.parseFloat(mMap.get(key));
4640 } catch (NumberFormatException ex) {
4641 return defaultValue;
4642 }
4643 }
4644
4645 // Returns the value of a integer parameter.
4646 private int getInt(String key, int defaultValue) {
4647 try {
4648 return Integer.parseInt(mMap.get(key));
4649 } catch (NumberFormatException ex) {
4650 return defaultValue;
4651 }
4652 }
4653
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004654 // Splits a comma delimited string to an ArrayList of Size.
4655 // Return null if the passing string is null or the size is 0.
4656 private ArrayList<Size> splitSize(String str) {
4657 if (str == null) return null;
4658
Ali Utku Selen0a120182011-02-09 14:11:22 +01004659 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
4660 splitter.setString(str);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004661 ArrayList<Size> sizeList = new ArrayList<Size>();
Ali Utku Selen0a120182011-02-09 14:11:22 +01004662 for (String s : splitter) {
4663 Size size = strToSize(s);
Wu-cheng Li9b6a8ab2009-08-17 18:19:25 +08004664 if (size != null) sizeList.add(size);
4665 }
4666 if (sizeList.size() == 0) return null;
4667 return sizeList;
4668 }
4669
4670 // Parses a string (ex: "480x320") to Size object.
4671 // Return null if the passing string is null.
4672 private Size strToSize(String str) {
4673 if (str == null) return null;
4674
4675 int pos = str.indexOf('x');
4676 if (pos != -1) {
4677 String width = str.substring(0, pos);
4678 String height = str.substring(pos + 1);
4679 return new Size(Integer.parseInt(width),
4680 Integer.parseInt(height));
4681 }
4682 Log.e(TAG, "Invalid size parameter string=" + str);
4683 return null;
4684 }
Wu-cheng Li454630f2010-08-11 16:48:05 -07004685
4686 // Splits a comma delimited string to an ArrayList of int array.
4687 // Example string: "(10000,26623),(10000,30000)". Return null if the
4688 // passing string is null or the size is 0.
4689 private ArrayList<int[]> splitRange(String str) {
4690 if (str == null || str.charAt(0) != '('
4691 || str.charAt(str.length() - 1) != ')') {
4692 Log.e(TAG, "Invalid range list string=" + str);
4693 return null;
4694 }
4695
4696 ArrayList<int[]> rangeList = new ArrayList<int[]>();
4697 int endIndex, fromIndex = 1;
4698 do {
4699 int[] range = new int[2];
4700 endIndex = str.indexOf("),(", fromIndex);
4701 if (endIndex == -1) endIndex = str.length() - 1;
4702 splitInt(str.substring(fromIndex, endIndex), range);
4703 rangeList.add(range);
4704 fromIndex = endIndex + 3;
4705 } while (endIndex != str.length() - 1);
4706
4707 if (rangeList.size() == 0) return null;
4708 return rangeList;
4709 }
Wu-cheng Li30771b72011-04-02 06:19:46 +08004710
4711 // Splits a comma delimited string to an ArrayList of Area objects.
4712 // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004713 // the passing string is null or the size is 0 or (0,0,0,0,0).
Mathew Inwood5132cc12018-08-08 15:50:55 +01004714 @UnsupportedAppUsage
Wu-cheng Li30771b72011-04-02 06:19:46 +08004715 private ArrayList<Area> splitArea(String str) {
4716 if (str == null || str.charAt(0) != '('
4717 || str.charAt(str.length() - 1) != ')') {
4718 Log.e(TAG, "Invalid area string=" + str);
4719 return null;
4720 }
4721
4722 ArrayList<Area> result = new ArrayList<Area>();
4723 int endIndex, fromIndex = 1;
4724 int[] array = new int[5];
4725 do {
4726 endIndex = str.indexOf("),(", fromIndex);
4727 if (endIndex == -1) endIndex = str.length() - 1;
4728 splitInt(str.substring(fromIndex, endIndex), array);
4729 Rect rect = new Rect(array[0], array[1], array[2], array[3]);
4730 result.add(new Area(rect, array[4]));
4731 fromIndex = endIndex + 3;
4732 } while (endIndex != str.length() - 1);
4733
4734 if (result.size() == 0) return null;
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004735
4736 if (result.size() == 1) {
Wu-cheng Libde61a52011-06-07 18:23:14 +08004737 Area area = result.get(0);
Wu-cheng Lif715bf92011-04-14 14:04:18 +08004738 Rect rect = area.rect;
4739 if (rect.left == 0 && rect.top == 0 && rect.right == 0
4740 && rect.bottom == 0 && area.weight == 0) {
4741 return null;
4742 }
4743 }
4744
Wu-cheng Li30771b72011-04-02 06:19:46 +08004745 return result;
4746 }
Wu-cheng Lib838d8d2011-11-17 20:12:23 +08004747
4748 private boolean same(String s1, String s2) {
4749 if (s1 == null && s2 == null) return true;
4750 if (s1 != null && s1.equals(s2)) return true;
4751 return false;
4752 }
Sauhard Pandec44f2d92015-07-09 14:47:34 -07004753 /* ### QC ADD-ONS: START */
4754
4755 /* ### QC ADDED PARAMETER KEYS*/
4756 private static final String KEY_QC_HFR_SIZE = "hfr-size";
4757 private static final String KEY_QC_PREVIEW_FRAME_RATE_MODE = "preview-frame-rate-mode";
4758 private static final String KEY_QC_PREVIEW_FRAME_RATE_AUTO_MODE = "frame-rate-auto";
4759 private static final String KEY_QC_PREVIEW_FRAME_RATE_FIXED_MODE = "frame-rate-fixed";
4760 private static final String KEY_QC_GPS_LATITUDE_REF = "gps-latitude-ref";
4761 private static final String KEY_QC_GPS_LONGITUDE_REF = "gps-longitude-ref";
4762 private static final String KEY_QC_GPS_ALTITUDE_REF = "gps-altitude-ref";
4763 private static final String KEY_QC_GPS_STATUS = "gps-status";
4764 private static final String KEY_QC_EXIF_DATETIME = "exif-datetime";
4765 private static final String KEY_QC_TOUCH_AF_AEC = "touch-af-aec";
4766 private static final String KEY_QC_TOUCH_INDEX_AEC = "touch-index-aec";
4767 private static final String KEY_QC_TOUCH_INDEX_AF = "touch-index-af";
4768 private static final String KEY_QC_MANUAL_FOCUS_POSITION = "manual-focus-position";
4769 private static final String KEY_QC_MANUAL_FOCUS_POS_TYPE = "manual-focus-pos-type";
4770 private static final String KEY_QC_SCENE_DETECT = "scene-detect";
4771 private static final String KEY_QC_ISO_MODE = "iso";
4772 private static final String KEY_QC_EXPOSURE_TIME = "exposure-time";
4773 private static final String KEY_QC_MIN_EXPOSURE_TIME = "min-exposure-time";
4774 private static final String KEY_QC_MAX_EXPOSURE_TIME = "max-exposure-time";
4775 private static final String KEY_QC_LENSSHADE = "lensshade";
4776 private static final String KEY_QC_HISTOGRAM = "histogram";
4777 private static final String KEY_QC_SKIN_TONE_ENHANCEMENT = "skinToneEnhancement";
4778 private static final String KEY_QC_AUTO_EXPOSURE = "auto-exposure";
4779 private static final String KEY_QC_SHARPNESS = "sharpness";
4780 private static final String KEY_QC_MAX_SHARPNESS = "max-sharpness";
4781 private static final String KEY_QC_CONTRAST = "contrast";
4782 private static final String KEY_QC_MAX_CONTRAST = "max-contrast";
4783 private static final String KEY_QC_SATURATION = "saturation";
4784 private static final String KEY_QC_MAX_SATURATION = "max-saturation";
4785 private static final String KEY_QC_DENOISE = "denoise";
4786 private static final String KEY_QC_CONTINUOUS_AF = "continuous-af";
4787 private static final String KEY_QC_SELECTABLE_ZONE_AF = "selectable-zone-af";
4788 private static final String KEY_QC_FACE_DETECTION = "face-detection";
4789 private static final String KEY_QC_MEMORY_COLOR_ENHANCEMENT = "mce";
4790 private static final String KEY_QC_REDEYE_REDUCTION = "redeye-reduction";
4791 private static final String KEY_QC_ZSL = "zsl";
4792 private static final String KEY_QC_CAMERA_MODE = "camera-mode";
4793 private static final String KEY_QC_VIDEO_HIGH_FRAME_RATE = "video-hfr";
4794 private static final String KEY_QC_VIDEO_HDR = "video-hdr";
4795 private static final String KEY_QC_POWER_MODE = "power-mode";
4796 private static final String KEY_QC_POWER_MODE_SUPPORTED = "power-mode-supported";
4797 private static final String KEY_QC_WB_MANUAL_CCT = "wb-manual-cct";
4798 private static final String KEY_QC_MIN_WB_CCT = "min-wb-cct";
4799 private static final String KEY_QC_MAX_WB_CCT = "max-wb-cct";
4800 private static final String KEY_QC_AUTO_HDR_ENABLE = "auto-hdr-enable";
4801 private static final String KEY_QC_VIDEO_ROTATION = "video-rotation";
4802
4803 /** @hide
4804 * KEY_QC_AE_BRACKET_HDR
4805 **/
4806 public static final String KEY_QC_AE_BRACKET_HDR = "ae-bracket-hdr";
4807
4808 /* ### QC ADDED PARAMETER VALUES*/
4809
4810 // Values for touch af/aec settings.
4811 /** @hide
4812 * TOUCH_AF_AEC_OFF
4813 **/
4814 public static final String TOUCH_AF_AEC_OFF = "touch-off";
4815 /** @hide
4816 * TOUCH_AF_AEC_ON
4817 **/
4818 public static final String TOUCH_AF_AEC_ON = "touch-on";
4819
4820 // Values for auto exposure settings.
4821 /** @hide
4822 * Auto exposure frame-avg
4823 **/
4824 public static final String AUTO_EXPOSURE_FRAME_AVG = "frame-average";
4825 /** @hide
4826 * Auto exposure center weighted
4827 **/
4828 public static final String AUTO_EXPOSURE_CENTER_WEIGHTED = "center-weighted";
4829 /** @hide
4830 * Auto exposure spot metering
4831 **/
4832 public static final String AUTO_EXPOSURE_SPOT_METERING = "spot-metering";
4833
4834 //Values for ISO settings
4835 /** @hide
4836 * ISO_AUTO
4837 **/
4838 public static final String ISO_AUTO = "auto";
4839 /** @hide
4840 * ISO_HJR
4841 **/
4842 public static final String ISO_HJR = "ISO_HJR";
4843 /** @hide
4844 * ISO_100
4845 **/
4846 public static final String ISO_100 = "ISO100";
4847 /** @hide
4848 * ISO_200
4849 **/
4850 public static final String ISO_200 = "ISO200";
4851 /** @hide
4852 * ISO_400
4853 **/
4854 public static final String ISO_400 = "ISO400";
4855 /** @hide
4856 * ISO_800
4857 **/
4858 public static final String ISO_800 = "ISO800";
4859 /** @hide
4860 * ISO_1600
4861 **/
4862 public static final String ISO_1600 = "ISO1600";
4863
4864 /** @hide
4865 * ISO_3200
4866 **/
4867 public static final String ISO_3200 = "ISO3200";
4868
4869 //Values for Lens Shading
4870 /** @hide
4871 * LENSSHADE_ENABLE
4872 **/
4873 public static final String LENSSHADE_ENABLE = "enable";
4874 /** @hide
4875 * LENSSHADE_DISABLE
4876 **/
4877 public static final String LENSSHADE_DISABLE= "disable";
4878
4879 //Values for Histogram
4880 /** @hide
4881 * Histogram enable
4882 **/
4883 public static final String HISTOGRAM_ENABLE = "enable";
4884 /** @hide
4885 * Histogram disable
4886 **/
4887 public static final String HISTOGRAM_DISABLE= "disable";
4888
4889 //Values for Skin Tone Enhancement
4890 /** @hide
4891 * SKIN_TONE_ENHANCEMENT_ENABLE
4892 **/
4893 public static final String SKIN_TONE_ENHANCEMENT_ENABLE = "enable";
4894 /** @hide
4895 * SKIN_TONE_ENHANCEMENT_DISABLE
4896 **/
4897 public static final String SKIN_TONE_ENHANCEMENT_DISABLE= "disable";
4898
4899 // Values for MCE settings.
4900 /** @hide
4901 * MCE_ENaBLE
4902 **/
4903 public static final String MCE_ENABLE = "enable";
4904 /** @hide
4905 * MCE_DISABLE
4906 **/
4907 public static final String MCE_DISABLE = "disable";
4908
4909 // Values for ZSL settings.
4910 /** @hide
4911 * ZSL_ON
4912 **/
4913 public static final String ZSL_ON = "on";
4914 /** @hide
4915 * ZSL_OFF
4916 **/
4917 public static final String ZSL_OFF = "off";
4918
4919 // Values for HDR Bracketing settings.
4920
4921 /** @hide
4922 * AEC bracketing off
4923 **/
4924 public static final String AE_BRACKET_HDR_OFF = "Off";
4925 /** @hide
4926 * AEC bracketing hdr
4927 **/
4928 public static final String AE_BRACKET_HDR = "HDR";
4929 /** @hide
4930 * AEC bracketing aec-bracket
4931 **/
4932 public static final String AE_BRACKET = "AE-Bracket";
4933
4934 // Values for Power mode.
4935 /** @hide
4936 * LOW_POWER
4937 **/
4938 public static final String LOW_POWER = "Low_Power";
4939 /** @hide
4940 * NORMAL_POWER
4941 **/
4942 public static final String NORMAL_POWER = "Normal_Power";
4943
4944 // Values for HFR settings.
4945 /** @hide
4946 * VIDEO_HFR_OFF
4947 **/
4948 public static final String VIDEO_HFR_OFF = "off";
4949 /** @hide
4950 * VIDEO_HFR_2X
4951 **/
4952 public static final String VIDEO_HFR_2X = "60";
4953 /** @hide
4954 * VIDEO_HFR_3X
4955 **/
4956 public static final String VIDEO_HFR_3X = "90";
4957 /** @hide
4958 * VIDEO_HFR_4X
4959 **/
4960 public static final String VIDEO_HFR_4X = "120";
4961
4962 // Values for auto scene detection settings.
4963 /** @hide
4964 * SCENE_DETECT_OFF
4965 **/
4966 public static final String SCENE_DETECT_OFF = "off";
4967 /** @hide
4968 * SCENE_DETECT_ON
4969 **/
4970 public static final String SCENE_DETECT_ON = "on";
4971
4972 //Values for Continuous AF
4973
4974 /** @hide
4975 * CAF off
4976 **/
4977 public static final String CONTINUOUS_AF_OFF = "caf-off";
4978 /** @hide
4979 * CAF on
4980 **/
4981 public static final String CONTINUOUS_AF_ON = "caf-on";
4982 /** @hide
4983 * Denoise off
4984 **/
4985 public static final String DENOISE_OFF = "denoise-off";
4986 /** @hide
4987 * Denoise on
4988 **/
4989 public static final String DENOISE_ON = "denoise-on";
4990
4991 // Values for Redeye Reduction settings.
4992 /** @hide
4993 * REDEYE_REDUCTION_ENABLE
4994 **/
4995 public static final String REDEYE_REDUCTION_ENABLE = "enable";
4996 /** @hide
4997 * REDEYE_REDUCTION_DISABLE
4998 **/
4999 public static final String REDEYE_REDUCTION_DISABLE = "disable";
5000
5001 // Values for selectable zone af settings.
5002 /** @hide
5003 * SELECTABLE_ZONE_AF_AUTO
5004 **/
5005 public static final String SELECTABLE_ZONE_AF_AUTO = "auto";
5006 /** @hide
5007 * SELECTABLE_ZONE_AF_SPOTMETERING
5008 **/
5009 public static final String SELECTABLE_ZONE_AF_SPOTMETERING = "spot-metering";
5010 /** @hide
5011 * SELECTABLE_ZONE_AF_CENTER_WEIGHTED
5012 **/
5013 public static final String SELECTABLE_ZONE_AF_CENTER_WEIGHTED = "center-weighted";
5014 /** @hide
5015 * SELECTABLE_ZONE_AF_FRAME_AVERAGE
5016 **/
5017 public static final String SELECTABLE_ZONE_AF_FRAME_AVERAGE = "frame-average";
5018
5019 // Values for Face Detection settings.
5020 /** @hide
5021 * Face Detection off
5022 **/
5023 public static final String FACE_DETECTION_OFF = "off";
5024 /** @hide
5025 * Face Detction on
5026 **/
5027 public static final String FACE_DETECTION_ON = "on";
5028
5029 // Values for video rotation settings.
5030
5031 /** @hide
5032 * VIDEO_ROTATION_0
5033 **/
5034 public static final String VIDEO_ROTATION_0 = "0";
5035 /** @hide
5036 * VIDEO_ROTATION_90
5037 **/
5038 public static final String VIDEO_ROTATION_90 = "90";
5039 /** @hide
5040 * VIDEO_ROTATION_180
5041 **/
5042 public static final String VIDEO_ROTATION_180 = "180";
5043 /** @hide
5044 * VIDEO_ROTATION_270
5045 **/
5046 public static final String VIDEO_ROTATION_270 = "270";
5047
5048 /* ### QC ADDED PARAMETER APIS*/
5049 /** @hide
5050 * Gets the supported preview sizes in high frame rate recording mode.
5051 *
5052 * @return a list of Size object. This method will always return a list
5053 * with at least one element.
5054 */
5055 public List<Size> getSupportedHfrSizes() {
5056 String str = get(KEY_QC_HFR_SIZE + SUPPORTED_VALUES_SUFFIX);
5057 return splitSize(str);
5058 }
5059
5060 /** @hide
5061 * Gets the supported Touch AF/AEC setting.
5062 *
5063 * @return a List of TOUCH_AF_AEC_XXX string constants. null if TOUCH AF/AEC
5064 * setting is not supported.
5065 *
5066 */
5067 public List<String> getSupportedTouchAfAec() {
5068 String str = get(KEY_QC_TOUCH_AF_AEC + SUPPORTED_VALUES_SUFFIX);
5069 return split(str);
5070 }
5071
5072 /**
5073 * Gets the supported Touch AF/AEC setting.
5074 *
5075 * @return a List of TOUCH_AF_AEC_XXX string constants. null if TOUCH AF/AEC
5076 * setting is not supported.
5077 *
5078 */
5079
5080 /** @hide
5081 * Gets the supported frame rate modes.
5082 *
5083 * @return a List of FRAME_RATE_XXX_MODE string constant. null if this
5084 * setting is not supported.
5085 */
5086 public List<String> getSupportedPreviewFrameRateModes() {
5087 String str = get(KEY_QC_PREVIEW_FRAME_RATE_MODE + SUPPORTED_VALUES_SUFFIX);
5088 return split(str);
5089 }
5090
5091 /** @hide
5092 * Gets the supported auto scene detection modes.
5093 *
5094 * @return a List of SCENE_DETECT_XXX string constant. null if scene detection
5095 * setting is not supported.
5096 *
5097 */
5098 public List<String> getSupportedSceneDetectModes() {
5099 String str = get(KEY_QC_SCENE_DETECT + SUPPORTED_VALUES_SUFFIX);
5100 return split(str);
5101 }
5102
5103 /** @hide
5104 * Gets the supported ISO values.
5105 *
5106 * @return a List of FLASH_MODE_XXX string constants. null if flash mode
5107 * setting is not supported.
5108 */
5109 public List<String> getSupportedIsoValues() {
5110 String str = get(KEY_QC_ISO_MODE + SUPPORTED_VALUES_SUFFIX);
5111 return split(str);
5112 }
5113
5114 /** @hide
5115 * Gets the supported Lensshade modes.
5116 *
5117 * @return a List of LENS_MODE_XXX string constants. null if lens mode
5118 * setting is not supported.
5119 */
5120 public List<String> getSupportedLensShadeModes() {
5121 String str = get(KEY_QC_LENSSHADE + SUPPORTED_VALUES_SUFFIX);
5122 return split(str);
5123 }
5124
5125 /** @hide
5126 * Gets the supported Histogram modes.
5127 *
5128 * @return a List of HISTOGRAM_XXX string constants. null if histogram mode
5129 * setting is not supported.
5130 */
5131 public List<String> getSupportedHistogramModes() {
5132 String str = get(KEY_QC_HISTOGRAM + SUPPORTED_VALUES_SUFFIX);
5133 return split(str);
5134 }
5135
5136 /** @hide
5137 * Gets the supported Skin Tone Enhancement modes.
5138 *
5139 * @return a List of SKIN_TONE_ENHANCEMENT_XXX string constants. null if skin tone enhancement
5140 * setting is not supported.
5141 */
5142 public List<String> getSupportedSkinToneEnhancementModes() {
5143 String str = get(KEY_QC_SKIN_TONE_ENHANCEMENT + SUPPORTED_VALUES_SUFFIX);
5144 return split(str);
5145 }
5146
5147 /** @hide
5148 * Gets the supported auto exposure setting.
5149 *
5150 * @return a List of AUTO_EXPOSURE_XXX string constants. null if auto exposure
5151 * setting is not supported.
5152 */
5153 public List<String> getSupportedAutoexposure() {
5154 String str = get(KEY_QC_AUTO_EXPOSURE + SUPPORTED_VALUES_SUFFIX);
5155 return split(str);
5156 }
5157
5158 /** @hide
5159 * Gets the supported MCE modes.
5160 *
5161 * @return a List of MCE_ENABLE/DISABLE string constants. null if MCE mode
5162 * setting is not supported.
5163 */
5164 public List<String> getSupportedMemColorEnhanceModes() {
5165 String str = get(KEY_QC_MEMORY_COLOR_ENHANCEMENT + SUPPORTED_VALUES_SUFFIX);
5166 return split(str);
5167 }
5168
5169 /** @hide
5170 * Gets the supported ZSL modes.
5171 *
5172 * @return a List of ZSL_OFF/OFF string constants. null if ZSL mode
5173 * setting is not supported.
5174 */
5175 public List<String> getSupportedZSLModes() {
5176 String str = get(KEY_QC_ZSL + SUPPORTED_VALUES_SUFFIX);
5177 return split(str);
5178 }
5179
5180 /** @hide
5181 * Gets the supported Video HDR modes.
5182 *
5183 * @return a List of Video HDR_OFF/OFF string constants. null if
5184 * Video HDR mode setting is not supported.
5185 */
5186 public List<String> getSupportedVideoHDRModes() {
5187 String str = get(KEY_QC_VIDEO_HDR + SUPPORTED_VALUES_SUFFIX);
5188 return split(str);
5189 }
5190
5191 /** @hide
5192 * Gets the supported HFR modes.
5193 *
5194 * @return a List of VIDEO_HFR_XXX string constants. null if hfr mode
5195 * setting is not supported.
5196 */
5197 public List<String> getSupportedVideoHighFrameRateModes() {
5198 String str = get(KEY_QC_VIDEO_HIGH_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
5199 return split(str);
5200 }
5201
5202 /** @hide
5203 * Gets the supported Continuous AF modes.
5204 *
5205 * @return a List of CONTINUOUS_AF_XXX string constant. null if continuous AF
5206 * setting is not supported.
5207 *
5208 */
5209 public List<String> getSupportedContinuousAfModes() {
5210 String str = get(KEY_QC_CONTINUOUS_AF + SUPPORTED_VALUES_SUFFIX);
5211 return split(str);
5212 }
5213
5214 /** @hide
5215 * Gets the supported DENOISE modes.
5216 *
5217 * @return a List of DENOISE_XXX string constant. null if DENOISE
5218 * setting is not supported.
5219 *
5220 */
5221 public List<String> getSupportedDenoiseModes() {
5222 String str = get(KEY_QC_DENOISE + SUPPORTED_VALUES_SUFFIX);
5223 return split(str);
5224 }
5225
5226 /** @hide
5227 * Gets the supported selectable zone af setting.
5228 *
5229 * @return a List of SELECTABLE_ZONE_AF_XXX string constants. null if selectable zone af
5230 * setting is not supported.
5231 */
5232 public List<String> getSupportedSelectableZoneAf() {
5233 String str = get(KEY_QC_SELECTABLE_ZONE_AF + SUPPORTED_VALUES_SUFFIX);
5234 return split(str);
5235 }
5236
5237 /** @hide
5238 * Gets the supported face detection modes.
5239 *
5240 * @return a List of FACE_DETECTION_XXX string constant. null if face detection
5241 * setting is not supported.
5242 *
5243 */
5244 public List<String> getSupportedFaceDetectionModes() {
5245 String str = get(KEY_QC_FACE_DETECTION + SUPPORTED_VALUES_SUFFIX);
5246 return split(str);
5247 }
5248
5249 /** @hide
5250 * Gets the supported redeye reduction modes.
5251 *
5252 * @return a List of REDEYE_REDUCTION_XXX string constant. null if redeye reduction
5253 * setting is not supported.
5254 *
5255 */
5256 public List<String> getSupportedRedeyeReductionModes() {
5257 String str = get(KEY_QC_REDEYE_REDUCTION + SUPPORTED_VALUES_SUFFIX);
5258 return split(str);
5259 }
5260
5261 /** @hide
5262 * Sets GPS altitude reference. This will be stored in JPEG EXIF header.
5263 * @param altRef reference GPS altitude in meters.
5264 */
5265 public void setGpsAltitudeRef(double altRef) {
5266 set(KEY_QC_GPS_ALTITUDE_REF, Double.toString(altRef));
5267 }
5268
5269 /** @hide
5270 * Sets GPS Status. This will be stored in JPEG EXIF header.
5271 *
5272 * @param status GPS status (UTC in seconds since January 1,
5273 * 1970).
5274 */
5275 public void setGpsStatus(double status) {
5276 set(KEY_QC_GPS_STATUS, Double.toString(status));
5277 }
5278
5279 /** @hide
5280 * Sets the touch co-ordinate for Touch AEC.
5281 *
5282 * @param x the x co-ordinate of the touch event
5283 * @param y the y co-ordinate of the touch event
5284 *
5285 */
5286 public void setTouchIndexAec(int x, int y) {
5287 String v = Integer.toString(x) + "x" + Integer.toString(y);
5288 set(KEY_QC_TOUCH_INDEX_AEC, v);
5289 }
5290
5291 /** @hide
5292 * Returns the touch co-ordinates of the touch event.
5293 *
5294 * @return a Index object with the x and y co-ordinated
5295 * for the touch event
5296 *
5297 */
5298 public Coordinate getTouchIndexAec() {
5299 String pair = get(KEY_QC_TOUCH_INDEX_AEC);
5300 return strToCoordinate(pair);
5301 }
5302
5303 /** @hide
5304 * Sets the touch co-ordinate for Touch AF.
5305 *
5306 * @param x the x co-ordinate of the touch event
5307 * @param y the y co-ordinate of the touch event
5308 *
5309 */
5310 public void setTouchIndexAf(int x, int y) {
5311 String v = Integer.toString(x) + "x" + Integer.toString(y);
5312 set(KEY_QC_TOUCH_INDEX_AF, v);
5313 }
5314
5315 /** @hide
5316 * Returns the touch co-ordinates of the touch event.
5317 *
5318 * @return a Index object with the x and y co-ordinated
5319 * for the touch event
5320 *
5321 */
5322 public Coordinate getTouchIndexAf() {
5323 String pair = get(KEY_QC_TOUCH_INDEX_AF);
5324 return strToCoordinate(pair);
5325 }
5326 /** @hide
5327 * Set Sharpness Level
5328 *
5329 * @param sharpness level
5330 */
5331 public void setSharpness(int sharpness){
5332 if((sharpness < 0) || (sharpness > getMaxSharpness()) )
5333 throw new IllegalArgumentException(
5334 "Invalid Sharpness " + sharpness);
5335
5336 set(KEY_QC_SHARPNESS, String.valueOf(sharpness));
5337 }
5338
5339 /** @hide
5340 * Set Contrast Level
5341 *
5342 * @param contrast level
5343 */
5344 public void setContrast(int contrast){
5345 if((contrast < 0 ) || (contrast > getMaxContrast()))
5346 throw new IllegalArgumentException(
5347 "Invalid Contrast " + contrast);
5348
5349 set(KEY_QC_CONTRAST, String.valueOf(contrast));
5350 }
5351
5352 /** @hide
5353 * Set Saturation Level
5354 *
5355 * @param saturation level
5356 */
5357 public void setSaturation(int saturation){
5358 if((saturation < 0 ) || (saturation > getMaxSaturation()))
5359 throw new IllegalArgumentException(
5360 "Invalid Saturation " + saturation);
5361
5362 set(KEY_QC_SATURATION, String.valueOf(saturation));
5363 }
5364
5365 /** @hide
5366 * @return true if full size video snapshot is supported.
5367 */
5368 public boolean isPowerModeSupported() {
5369 String str = get(KEY_QC_POWER_MODE_SUPPORTED);
5370 return TRUE.equals(str);
5371 }
5372
5373 /** @hide
5374 * Get Sharpness level
5375 *
5376 * @return sharpness level
5377 */
5378 public int getSharpness(){
5379 return getInt(KEY_QC_SHARPNESS);
5380 }
5381
5382 /** @hide
5383 * Get Max Sharpness Level
5384 *
5385 * @return max sharpness level
5386 */
5387 public int getMaxSharpness(){
5388 return getInt(KEY_QC_MAX_SHARPNESS);
5389 }
5390
5391 /** @hide
5392 * Get Contrast level
5393 *
5394 * @return contrast level
5395 */
5396 public int getContrast(){
5397 return getInt(KEY_QC_CONTRAST);
5398 }
5399
5400 /** @hide
5401 * Get Max Contrast Level
5402 *
5403 * @return max contrast level
5404 */
5405 public int getMaxContrast(){
5406 return getInt(KEY_QC_MAX_CONTRAST);
5407 }
5408
5409 /** @hide
5410 * Get Saturation level
5411 *
5412 * @return saturation level
5413 */
5414 public int getSaturation(){
5415 return getInt(KEY_QC_SATURATION);
5416 }
5417
5418 /** @hide
5419 * Get Max Saturation Level
5420 *
5421 * @return max contrast level
5422 */
5423 public int getMaxSaturation(){
5424 return getInt(KEY_QC_MAX_SATURATION);
5425 }
5426
5427 /** @hide
5428 * Sets GPS latitude reference coordinate. This will be stored in JPEG EXIF
5429 * header.
5430 * @param latRef GPS latitude reference coordinate.
5431 */
5432 public void setGpsLatitudeRef(String latRef) {
5433 set(KEY_QC_GPS_LATITUDE_REF, latRef);
5434 }
5435
5436 /** @hide
5437 * Sets GPS longitude reference coordinate. This will be stored in JPEG EXIF
5438 * header.
5439 * @param lonRef GPS longitude reference coordinate.
5440 */
5441 public void setGpsLongitudeRef(String lonRef) {
5442 set(KEY_QC_GPS_LONGITUDE_REF, lonRef);
5443 }
5444
5445 /** @hide
5446 * Sets system timestamp. This will be stored in JPEG EXIF header.
5447 *
5448 * @param dateTime current timestamp (UTC in seconds since January 1,
5449 * 1970).
5450 */
5451 public void setExifDateTime(String dateTime) {
5452 set(KEY_QC_EXIF_DATETIME, dateTime);
5453 }
5454
5455 /** @hide
5456 * Gets the current Touch AF/AEC setting.
5457 *
5458 * @return one of TOUCH_AF_AEC_XXX string constant. null if Touch AF/AEC
5459 * setting is not supported.
5460 *
5461 */
5462 public String getTouchAfAec() {
5463 return get(KEY_QC_TOUCH_AF_AEC);
5464 }
5465
5466 /** @hide
5467 * Sets the current TOUCH AF/AEC setting.
5468 *
5469 * @param value TOUCH_AF_AEC_XXX string constants.
5470 *
5471 */
5472 public void setTouchAfAec(String value) {
5473 set(KEY_QC_TOUCH_AF_AEC, value);
5474 }
5475
5476 /** @hide
5477 * Gets the current redeye reduction setting.
5478 *
5479 * @return one of REDEYE_REDUCTION_XXX string constant. null if redeye reduction
5480 * setting is not supported.
5481 *
5482 */
5483 public String getRedeyeReductionMode() {
5484 return get(KEY_QC_REDEYE_REDUCTION);
5485 }
5486
5487 /** @hide
5488 * Sets the redeye reduction. Other parameters may be changed after changing
5489 * redeye reduction. After setting redeye reduction,
5490 * applications should call getParameters to know if some parameters are
5491 * changed.
5492 *
5493 * @param value REDEYE_REDUCTION_XXX string constants.
5494 *
5495 */
5496 public void setRedeyeReductionMode(String value) {
5497 set(KEY_QC_REDEYE_REDUCTION, value);
5498 }
5499
5500 /** @hide
5501 * Gets the frame rate mode setting.
5502 *
5503 * @return one of FRAME_RATE_XXX_MODE string constant. null if this
5504 * setting is not supported.
5505 */
5506 public String getPreviewFrameRateMode() {
5507 return get(KEY_QC_PREVIEW_FRAME_RATE_MODE);
5508 }
5509
5510 /** @hide
5511 * Sets the frame rate mode.
5512 *
5513 * @param value FRAME_RATE_XXX_MODE string constants.
5514 */
5515 public void setPreviewFrameRateMode(String value) {
5516 set(KEY_QC_PREVIEW_FRAME_RATE_MODE, value);
5517 }
5518
5519 /** @hide
5520 * Gets the current auto scene detection setting.
5521 *
5522 * @return one of SCENE_DETECT_XXX string constant. null if auto scene detection
5523 * setting is not supported.
5524 *
5525 */
5526 public String getSceneDetectMode() {
5527 return get(KEY_QC_SCENE_DETECT);
5528 }
5529
5530 /** @hide
5531 * Sets the auto scene detect. Other parameters may be changed after changing
5532 * scene detect. After setting auto scene detection,
5533 * applications should call getParameters to know if some parameters are
5534 * changed.
5535 *
5536 * @param value SCENE_DETECT_XXX string constants.
5537 *
5538 */
5539 public void setSceneDetectMode(String value) {
5540 set(KEY_QC_SCENE_DETECT, value);
5541 }
5542
5543 /** @hide
5544 * Gets the current hdr bracketing mode setting.
5545 *
5546 * @return current hdr bracketing mode.
5547 * @see #KEY_AE_BRACKET_OFF
5548 * @see #KEY_AE_BRACKET_HDR
5549 * @see #KEY_AE_BRACKET_BRACKATING
5550 */
5551 public String getAEBracket() {
5552 return get(KEY_QC_AE_BRACKET_HDR);
5553 }
5554
5555 /** @hide
5556 * Sets the Power mode.
5557 *
5558 * @param value Power mode.
5559 * @see #getPowerMode()
5560 */
5561 public void setPowerMode(String value) {
5562 set(KEY_QC_POWER_MODE, value);
5563 }
5564
5565 /** @hide
5566 * Gets the current power mode setting.
5567 *
5568 * @return current power mode. null if power mode setting is not
5569 * supported.
5570 * @see #POWER_MODE_LOW
5571 * @see #POWER_MODE_NORMAL
5572 */
5573 public String getPowerMode() {
5574 return get(KEY_QC_POWER_MODE);
5575 }
5576
5577 /** @hide
5578 * Set HDR-Bracketing Level
5579 *
5580 * @param value HDR-Bracketing
5581 */
5582 public void setAEBracket(String value){
5583 set(KEY_QC_AE_BRACKET_HDR, value);
5584 }
5585
5586 /** @hide
5587 * Gets the current ISO setting.
5588 *
5589 * @return one of ISO_XXX string constant. null if ISO
5590 * setting is not supported.
5591 */
5592 public String getISOValue() {
5593 return get(KEY_QC_ISO_MODE);
5594 }
5595
5596 /** @hide
5597 * Sets the ISO.
5598 *
5599 * @param iso ISO_XXX string constant.
5600 */
5601 public void setISOValue(String iso) {
5602 set(KEY_QC_ISO_MODE, iso);
5603 }
5604
5605 /** @hide
5606 * Sets the exposure time.
5607 *
5608 * @param value exposure time.
5609 */
5610 public void setExposureTime(int value) {
5611 set(KEY_QC_EXPOSURE_TIME, Integer.toString(value));
5612 }
5613
5614 /** @hide
5615 * Gets the current exposure time.
5616 *
5617 * @return exposure time.
5618 */
5619 public String getExposureTime() {
5620 return get(KEY_QC_EXPOSURE_TIME);
5621 }
5622
5623 /** @hide
5624 * Gets the min supported exposure time.
5625 *
5626 * @return min supported exposure time.
5627 */
5628 public String getMinExposureTime() {
5629 return get(KEY_QC_MIN_EXPOSURE_TIME);
5630 }
5631
5632 /** @hide
5633 * Gets the max supported exposure time.
5634 *
5635 * @return max supported exposure time.
5636 */
5637 public String getMaxExposureTime() {
5638 return get(KEY_QC_MAX_EXPOSURE_TIME);
5639 }
5640
5641 /** @hide
5642 * Gets the current LensShade Mode.
5643 *
5644 * @return LensShade Mode
5645 */
5646 public String getLensShade() {
5647 return get(KEY_QC_LENSSHADE);
5648 }
5649
5650 /** @hide
5651 * Sets the current LensShade Mode.
5652 *
5653 * @return LensShade Mode
5654 */
5655 public void setLensShade(String lensshade) {
5656 set(KEY_QC_LENSSHADE, lensshade);
5657 }
5658
5659 /** @hide
5660 * Gets the current auto exposure setting.
5661 *
5662 * @return one of AUTO_EXPOSURE_XXX string constant. null if auto exposure
5663 * setting is not supported.
5664 */
5665 public String getAutoExposure() {
5666 return get(KEY_QC_AUTO_EXPOSURE);
5667 }
5668
5669 /** @hide
5670 * Sets the current auto exposure setting.
5671 *
5672 * @param value AUTO_EXPOSURE_XXX string constants.
5673 */
5674 public void setAutoExposure(String value) {
5675 set(KEY_QC_AUTO_EXPOSURE, value);
5676 }
5677
5678 /** @hide
5679 * Gets the current MCE Mode.
5680 *
5681 * @return MCE value
5682 */
5683 public String getMemColorEnhance() {
5684 return get(KEY_QC_MEMORY_COLOR_ENHANCEMENT);
5685 }
5686
5687 /** @hide
5688 * Sets the current MCE Mode.
5689 *
5690 * @return MCE Mode
5691 */
5692 public void setMemColorEnhance(String mce) {
5693 set(KEY_QC_MEMORY_COLOR_ENHANCEMENT, mce);
5694 }
5695
5696 /** @hide
5697 * Set white balance manual cct value.
5698 *
5699 * @param cct user CCT setting.
5700 */
5701 public void setWBManualCCT(int cct) {
5702 set(KEY_QC_WB_MANUAL_CCT, Integer.toString(cct));
5703 }
5704
5705 /** @hide
5706 * Gets the WB min supported CCT.
5707 *
5708 * @return min cct value.
5709 */
5710 public String getWBMinCCT() {
5711 return get(KEY_QC_MIN_WB_CCT);
5712 }
5713
5714 /** @hide
5715 * Gets the WB max supported CCT.
5716 *
5717 * @return max cct value.
5718 */
5719 public String getMaxWBCCT() {
5720 return get(KEY_QC_MAX_WB_CCT);
5721 }
5722
5723 /** @hide
5724 * Gets the current WB CCT.
5725 *
5726 * @return CCT value
5727 */
5728 public String getWBCurrentCCT() {
5729 return get(KEY_QC_WB_MANUAL_CCT);
5730 }
5731
5732 /** @hide
5733 * Gets the current ZSL Mode.
5734 *
5735 * @return ZSL mode value
5736 */
5737 public String getZSLMode() {
5738 return get(KEY_QC_ZSL);
5739 }
5740
5741 /** @hide
5742 * Sets the current ZSL Mode. ZSL mode is set as a 0th bit in KEY_CAMERA_MODE.
5743 *
5744 * @return null
5745 */
5746 public void setZSLMode(String zsl) {
5747 set(KEY_QC_ZSL, zsl);
5748 }
5749
5750 /** @hide
5751 * Sets the current Auto HDR Mode.
5752 * @ auto_hdr auto hdr string for enable/disable
5753 * @return null
5754 */
5755 public void setAutoHDRMode(String auto_hdr){
5756 set(KEY_QC_AUTO_HDR_ENABLE,auto_hdr);
5757 }
5758
5759 /** @hide
5760 * Gets the current Camera Mode Flag. Camera mode includes a
5761 * flag(byte) which indicates different camera modes.
5762 * For now support for ZSL added at bit0
5763 *
5764 * @return Camera Mode.
5765 */
5766 public String getCameraMode() {
5767 return get(KEY_QC_CAMERA_MODE);
5768 }
5769
5770 /** @hide
5771 * Sets the current Camera Mode.
5772 *
5773 * @return null
5774 */
5775 public void setCameraMode(int cameraMode) {
5776 set(KEY_QC_CAMERA_MODE, cameraMode);
5777 }
5778
5779 private static final int MANUAL_FOCUS_POS_TYPE_INDEX = 0;
5780 private static final int MANUAL_FOCUS_POS_TYPE_DAC = 1;
5781 /** @hide
5782 * Set focus position.
5783 *
5784 * @param pos user setting of focus position.
5785 */
5786 public void setFocusPosition(int type, int pos) {
5787 set(KEY_QC_MANUAL_FOCUS_POS_TYPE, Integer.toString(type));
5788 set(KEY_QC_MANUAL_FOCUS_POSITION, Integer.toString(pos));
5789 }
5790
5791 /** @hide
5792 * Gets the current focus position.
5793 *
5794 * @return current focus position
5795 */
5796 public String getCurrentFocusPosition() {
5797 return get(KEY_QC_MANUAL_FOCUS_POSITION);
5798 }
5799
5800
5801 /** @hide
5802 * Gets the current HFR Mode.
5803 *
5804 * @return VIDEO_HFR_XXX string constants
5805 */
5806 public String getVideoHighFrameRate() {
5807 return get(KEY_QC_VIDEO_HIGH_FRAME_RATE);
5808 }
5809
5810 /** @hide
5811 * Sets the current HFR Mode.
5812 *
5813 * @param hfr VIDEO_HFR_XXX string constants
5814 */
5815 public void setVideoHighFrameRate(String hfr) {
5816 set(KEY_QC_VIDEO_HIGH_FRAME_RATE, hfr);
5817 }
5818
5819 /** @hide
5820 * Gets the current Video HDR Mode.
5821 *
5822 * @return Video HDR mode value
5823 */
5824 public String getVideoHDRMode() {
5825 return get(KEY_QC_VIDEO_HDR);
5826 }
5827
5828 /** @hide
5829 * Sets the current Video HDR Mode.
5830 *
5831 * @return null
5832 */
5833 public void setVideoHDRMode(String videohdr) {
5834 set(KEY_QC_VIDEO_HDR, videohdr);
5835 }
5836
5837 /** @hide
5838 * Gets the current DENOISE setting.
5839 *
5840 * @return one of DENOISE_XXX string constant. null if Denoise
5841 * setting is not supported.
5842 *
5843 */
5844 public String getDenoise() {
5845 return get(KEY_QC_DENOISE);
5846 }
5847
5848 /** @hide
5849 * Gets the current Continuous AF setting.
5850 *
5851 * @return one of CONTINUOUS_AF_XXX string constant. null if continuous AF
5852 * setting is not supported.
5853 *
5854 */
5855 public String getContinuousAf() {
5856 return get(KEY_QC_CONTINUOUS_AF);
5857 }
5858
5859 /** @hide
5860 * Sets the current Denoise mode.
5861 * @param value DENOISE_XXX string constants.
5862 *
5863 */
5864
5865 public void setDenoise(String value) {
5866 set(KEY_QC_DENOISE, value);
5867 }
5868
5869 /** @hide
5870 * Sets the current Continuous AF mode.
5871 * @param value CONTINUOUS_AF_XXX string constants.
5872 *
5873 */
5874 public void setContinuousAf(String value) {
5875 set(KEY_QC_CONTINUOUS_AF, value);
5876 }
5877
5878 /** @hide
5879 * Gets the current selectable zone af setting.
5880 *
5881 * @return one of SELECTABLE_ZONE_AF_XXX string constant. null if selectable zone af
5882 * setting is not supported.
5883 */
5884 public String getSelectableZoneAf() {
5885 return get(KEY_QC_SELECTABLE_ZONE_AF);
5886 }
5887
5888 /** @hide
5889 * Sets the current selectable zone af setting.
5890 *
5891 * @param value SELECTABLE_ZONE_AF_XXX string constants.
5892 */
5893 public void setSelectableZoneAf(String value) {
5894 set(KEY_QC_SELECTABLE_ZONE_AF, value);
5895 }
5896
5897 /** @hide
5898 * Gets the current face detection setting.
5899 *
5900 * @return one of FACE_DETECTION_XXX string constant. null if face detection
5901 * setting is not supported.
5902 *
5903 */
5904 public String getFaceDetectionMode() {
5905 return get(KEY_QC_FACE_DETECTION);
5906 }
5907
5908 /** @hide
5909 * Sets the auto scene detect. Other settings like Touch AF/AEC might be
5910 * changed after setting face detection.
5911 *
5912 * @param value FACE_DETECTION_XXX string constants.
5913 *
5914 */
5915 public void setFaceDetectionMode(String value) {
5916 set(KEY_QC_FACE_DETECTION, value);
5917 }
5918
5919 /** @hide
5920 * Gets the current video rotation setting.
5921 *
5922 * @return one of VIDEO_QC_ROTATION_XXX string constant. null if video rotation
5923 * setting is not supported.
5924 */
5925 public String getVideoRotation() {
5926 return get(KEY_QC_VIDEO_ROTATION);
5927 }
5928
5929 /** @hide
5930 * Sets the current video rotation setting.
5931 *
5932 * @param value VIDEO_QC_ROTATION_XXX string constants.
5933 */
5934 public void setVideoRotation(String value) {
5935 set(KEY_QC_VIDEO_ROTATION, value);
5936 }
5937 /** @hide
5938 * Gets the supported video rotation modes.
5939 *
5940 * @return a List of VIDEO_QC_ROTATION_XXX string constant. null if this
5941 * setting is not supported.
5942 */
5943 public List<String> getSupportedVideoRotationValues() {
5944 String str = get(KEY_QC_VIDEO_ROTATION + SUPPORTED_VALUES_SUFFIX);
5945 return split(str);
5946 }
5947
5948 // Splits a comma delimited string to an ArrayList of Coordinate.
5949 // Return null if the passing string is null or the Coordinate is 0.
5950 private ArrayList<Coordinate> splitCoordinate(String str) {
5951 if (str == null) return null;
5952 TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
5953 splitter.setString(str);
5954 ArrayList<Coordinate> coordinateList = new ArrayList<Coordinate>();
5955 for (String s : splitter) {
5956 Coordinate coordinate = strToCoordinate(s);
5957 if (coordinate != null) coordinateList.add(coordinate);
5958 }
5959 if (coordinateList.size() == 0) return null;
5960 return coordinateList;
5961 }
5962
5963 // Parses a string (ex: "500x500") to Coordinate object.
5964 // Return null if the passing string is null.
5965 private Coordinate strToCoordinate(String str) {
5966 if (str == null) return null;
5967
5968 int pos = str.indexOf('x');
5969 if (pos != -1) {
5970 String x = str.substring(0, pos);
5971 String y = str.substring(pos + 1);
5972 return new Coordinate(Integer.parseInt(x),
5973 Integer.parseInt(y));
5974 }
5975 Log.e(TAG, "Invalid Coordinate parameter string=" + str);
5976 return null;
5977 }
5978 /* ### QC ADD-ONS: END */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005979 };
5980}