blob: 18069fe2572e7ae4178477e517d8f95071bc25a2 [file] [log] [blame]
Igor Murashkin44cfcf02013-03-01 16:22:28 -08001/*
2 * Copyright (C) 2013 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
17#define LOG_TAG "Camera2ClientBase"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
19//#define LOG_NDEBUG 0
20
Colin Crosse5729fa2014-03-21 15:04:25 -070021#include <inttypes.h>
22
Igor Murashkin44cfcf02013-03-01 16:22:28 -080023#include <utils/Log.h>
24#include <utils/Trace.h>
25
26#include <cutils/properties.h>
27#include <gui/Surface.h>
28#include <gui/Surface.h>
Igor Murashkin44cfcf02013-03-01 16:22:28 -080029
Jayant Chowdhary81d81b02024-02-15 19:13:39 +000030#include <android/hardware/ICameraService.h>
Shuzhen Wang316781a2020-08-18 18:11:01 -070031#include <camera/CameraSessionStats.h>
Austin Borger1c1bee02023-06-01 16:51:35 -070032#include <camera/StringUtils.h>
Jayant Chowdhary81d81b02024-02-15 19:13:39 +000033#include <com_android_window_flags.h>
Shuzhen Wang316781a2020-08-18 18:11:01 -070034
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070035#include "common/Camera2ClientBase.h"
Igor Murashkine7ee7632013-06-11 18:10:18 -070036
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070037#include "api2/CameraDeviceClient.h"
38
Eino-Ville Talvalad309fb92015-11-25 12:12:45 -080039#include "device3/Camera3Device.h"
Jayant Chowdhary35642f22022-01-08 00:39:39 +000040#include "device3/aidl/AidlCamera3Device.h"
Jayant Chowdhary22441f32021-12-26 18:35:41 -080041#include "device3/hidl/HidlCamera3Device.h"
Igor Murashkin44cfcf02013-03-01 16:22:28 -080042
43namespace android {
Jayant Chowdhary620763f2022-05-27 05:37:14 +000044
Igor Murashkin44cfcf02013-03-01 16:22:28 -080045using namespace camera2;
46
Jayant Chowdhary81d81b02024-02-15 19:13:39 +000047namespace wm_flags = com::android::window::flags;
48
Igor Murashkin44cfcf02013-03-01 16:22:28 -080049// Interface used by CameraService
50
51template <typename TClientBase>
52Camera2ClientBase<TClientBase>::Camera2ClientBase(
53 const sp<CameraService>& cameraService,
54 const sp<TCamCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070055 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger249e6592024-03-10 22:28:11 -070056 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borger1c1bee02023-06-01 16:51:35 -070057 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080058 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070059 const std::optional<std::string>& clientFeatureId,
60 const std::string& cameraId,
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080061 int api1CameraId,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080062 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070063 int sensorOrientation,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080064 int clientPid,
65 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070066 int servicePid,
Emilian Peev5104fe92021-10-21 14:27:09 -070067 bool overrideForPerfClass,
Jayant Chowdhary81d81b02024-02-15 19:13:39 +000068 int rotationOverride,
Emilian Peev5104fe92021-10-21 14:27:09 -070069 bool legacyClient):
Austin Borger249e6592024-03-10 22:28:11 -070070 TClientBase(cameraService, remoteCallback, attributionAndPermissionUtils, clientPackageName,
71 systemNativeClient, clientFeatureId, cameraId, api1CameraId, cameraFacing,
Jayant Chowdhary81d81b02024-02-15 19:13:39 +000072 sensorOrientation, clientPid, clientUid, servicePid, rotationOverride),
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -070073 mSharedCameraCallbacks(remoteCallback),
Austin Borger74fca042022-05-23 12:41:21 -070074 mCameraServiceProxyWrapper(cameraServiceProxyWrapper),
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080075 mDeviceActive(false), mApi1CameraId(api1CameraId)
Igor Murashkin44cfcf02013-03-01 16:22:28 -080076{
Austin Borger1c1bee02023-06-01 16:51:35 -070077 ALOGI("Camera %s: Opened. Client: %s (PID %d, UID %d)", cameraId.c_str(),
78 clientPackageName.c_str(), clientPid, clientUid);
Igor Murashkin98e24722013-06-19 19:51:04 -070079
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -070080 mInitialClientPid = clientPid;
Jayant Chowdhary22441f32021-12-26 18:35:41 -080081 mOverrideForPerfClass = overrideForPerfClass;
82 mLegacyClient = legacyClient;
Igor Murashkin44cfcf02013-03-01 16:22:28 -080083}
84
85template <typename TClientBase>
86status_t Camera2ClientBase<TClientBase>::checkPid(const char* checkLocation)
87 const {
88
Austin Borger22c5c852024-03-08 13:31:36 -080089 int callingPid = TClientBase::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -080090 if (callingPid == TClientBase::mClientPid) return NO_ERROR;
91
92 ALOGE("%s: attempt to use a locked camera from a different process"
93 " (old pid %d, new pid %d)", checkLocation, TClientBase::mClientPid, callingPid);
94 return PERMISSION_DENIED;
95}
96
97template <typename TClientBase>
Emilian Peevbd8c5032018-02-14 23:05:40 +000098status_t Camera2ClientBase<TClientBase>::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -070099 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000100 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800101}
102
103template <typename TClientBase>
104template <typename TProviderPtr>
Emilian Peevbd8c5032018-02-14 23:05:40 +0000105status_t Camera2ClientBase<TClientBase>::initializeImpl(TProviderPtr providerPtr,
Austin Borger1c1bee02023-06-01 16:51:35 -0700106 const std::string& monitorTags) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800107 ATRACE_CALL();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800108 ALOGV("%s: Initializing client for camera %s", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700109 TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800110 status_t res;
111
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800112 IPCTransport providerTransport = IPCTransport::INVALID;
Austin Borger1c1bee02023-06-01 16:51:35 -0700113 res = providerPtr->getCameraIdIPCTransport(TClientBase::mCameraIdStr,
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800114 &providerTransport);
115 if (res != OK) {
116 return res;
117 }
118 switch (providerTransport) {
119 case IPCTransport::HIDL:
120 mDevice =
Austin Borger74fca042022-05-23 12:41:21 -0700121 new HidlCamera3Device(mCameraServiceProxyWrapper,
Austin Borger22c5c852024-03-08 13:31:36 -0800122 TClientBase::mAttributionAndPermissionUtils,
Austin Borger18b30a72022-10-27 12:20:29 -0700123 TClientBase::mCameraIdStr, mOverrideForPerfClass,
Jayant Chowdhary81d81b02024-02-15 19:13:39 +0000124 TClientBase::mRotationOverride, mLegacyClient);
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800125 break;
126 case IPCTransport::AIDL:
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000127 mDevice =
Austin Borger74fca042022-05-23 12:41:21 -0700128 new AidlCamera3Device(mCameraServiceProxyWrapper,
Austin Borger22c5c852024-03-08 13:31:36 -0800129 TClientBase::mAttributionAndPermissionUtils,
Austin Borger18b30a72022-10-27 12:20:29 -0700130 TClientBase::mCameraIdStr, mOverrideForPerfClass,
Jayant Chowdhary81d81b02024-02-15 19:13:39 +0000131 TClientBase::mRotationOverride, mLegacyClient);
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000132 break;
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800133 default:
134 ALOGE("%s Invalid transport for camera id %s", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700135 TClientBase::mCameraIdStr.c_str());
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800136 return NO_INIT;
137 }
Igor Murashkine6800ce2013-03-04 17:25:57 -0800138 if (mDevice == NULL) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800139 ALOGE("%s: Camera %s: No device connected",
Austin Borger1c1bee02023-06-01 16:51:35 -0700140 __FUNCTION__, TClientBase::mCameraIdStr.c_str());
Igor Murashkine6800ce2013-03-04 17:25:57 -0800141 return NO_INIT;
142 }
143
Emilian Peev510546a2024-03-07 01:21:28 +0000144 // Verify ops permissions
145 res = TClientBase::startCameraOps();
146 if (res != OK) {
147 TClientBase::finishCameraOps();
148 return res;
149 }
150
Emilian Peevbd8c5032018-02-14 23:05:40 +0000151 res = mDevice->initialize(providerPtr, monitorTags);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800152 if (res != OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800153 ALOGE("%s: Camera %s: unable to initialize device: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700154 __FUNCTION__, TClientBase::mCameraIdStr.c_str(), strerror(-res), res);
Emilian Peevfa17f092022-07-29 13:28:55 -0700155 TClientBase::finishCameraOps();
Emilian Peevfa17f092022-07-29 13:28:55 -0700156 return res;
157 }
158
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800159 wp<NotificationListener> weakThis(this);
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700160 res = mDevice->setNotifyCallback(weakThis);
Austin Borger7b129542022-06-09 13:23:06 -0700161 if (res != OK) {
162 ALOGE("%s: Camera %s: Unable to set notify callback: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700163 __FUNCTION__, TClientBase::mCameraIdStr.c_str(), strerror(-res), res);
Austin Borger7b129542022-06-09 13:23:06 -0700164 return res;
165 }
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800166
167 return OK;
168}
169
170template <typename TClientBase>
171Camera2ClientBase<TClientBase>::~Camera2ClientBase() {
172 ATRACE_CALL();
173
174 TClientBase::mDestructionStarted = true;
175
176 disconnect();
177
Jayant Chowdhary3ab499d2022-06-15 15:43:33 -0700178 ALOGI("%s: Client object's dtor for Camera Id %s completed. Client was: %s (PID %d, UID %u)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700179 __FUNCTION__, TClientBase::mCameraIdStr.c_str(),
180 TClientBase::mClientPackageName.c_str(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -0700181 mInitialClientPid, TClientBase::mClientUid);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800182}
183
184template <typename TClientBase>
Eino-Ville Talvalac4003962016-01-13 10:07:04 -0800185status_t Camera2ClientBase<TClientBase>::dumpClient(int fd,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800186 const Vector<String16>& args) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700187 std::string result;
188 result += fmt::sprintf("Camera2ClientBase[%s] (%p) PID: %d, dump:\n",
189 TClientBase::mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -0800190 (TClientBase::getRemoteCallback() != NULL ?
Austin Borger1c1bee02023-06-01 16:51:35 -0700191 (void *)IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800192 TClientBase::mClientPid);
Austin Borger1c1bee02023-06-01 16:51:35 -0700193 result += " State: ";
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800194
Austin Borger1c1bee02023-06-01 16:51:35 -0700195 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800196 // TODO: print dynamic/request section from most recent requests
197
198 return dumpDevice(fd, args);
199}
200
201template <typename TClientBase>
Austin Borger1c1bee02023-06-01 16:51:35 -0700202status_t Camera2ClientBase<TClientBase>::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700203 sp<CameraDeviceBase> device = mDevice;
204 if (!device) {
205 dprintf(out, " Device is detached");
206 return OK;
207 }
208
209 return device->startWatchingTags(tags);
210}
211
212template <typename TClientBase>
213status_t Camera2ClientBase<TClientBase>::stopWatchingTags(int out) {
214 sp<CameraDeviceBase> device = mDevice;
215 if (!device) {
216 dprintf(out, " Device is detached");
217 return OK;
218 }
219
220 return device->stopWatchingTags();
221}
222
223template <typename TClientBase>
224status_t Camera2ClientBase<TClientBase>::dumpWatchedEventsToVector(std::vector<std::string> &out) {
225 sp<CameraDeviceBase> device = mDevice;
226 if (!device) {
227 // Nothing to dump if the device is detached
228 return OK;
229 }
230 return device->dumpWatchedEventsToVector(out);
231}
232
233template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800234status_t Camera2ClientBase<TClientBase>::dumpDevice(
235 int fd,
236 const Vector<String16>& args) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700237 std::string result;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800238
239 result = " Device dump:\n";
Austin Borger1c1bee02023-06-01 16:51:35 -0700240 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800241
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800242 sp<CameraDeviceBase> device = mDevice;
243 if (!device.get()) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800244 result = " *** Device is detached\n";
Austin Borger1c1bee02023-06-01 16:51:35 -0700245 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800246 return NO_ERROR;
247 }
248
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800249 status_t res = device->dump(fd, args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800250 if (res != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700251 result = fmt::sprintf(" Error dumping device: %s (%d)",
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800252 strerror(-res), res);
Austin Borger1c1bee02023-06-01 16:51:35 -0700253 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800254 }
255
256 return NO_ERROR;
257}
258
259// ICameraClient2BaseUser interface
260
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800261template <typename TClientBase>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800262binder::Status Camera2ClientBase<TClientBase>::disconnect() {
Ravneet Dhanjalbaa324b2023-10-11 01:19:18 +0000263
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000264 return disconnectImpl();
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000265}
266
267template <typename TClientBase>
268binder::Status Camera2ClientBase<TClientBase>::disconnectImpl() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800269 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -0700270 ALOGD("Camera %s: start to disconnect", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800271 Mutex::Autolock icl(mBinderSerializationLock);
272
Austin Borger1c1bee02023-06-01 16:51:35 -0700273 ALOGD("Camera %s: serializationLock acquired", TClientBase::mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800274 binder::Status res = binder::Status::ok();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800275 // Allow both client and the media server to disconnect at all times
Austin Borger22c5c852024-03-08 13:31:36 -0800276 int callingPid = TClientBase::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800277 if (callingPid != TClientBase::mClientPid &&
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800278 callingPid != TClientBase::mServicePid) return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800279
Austin Borger1c1bee02023-06-01 16:51:35 -0700280 ALOGD("Camera %s: Shutting down", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800281
Rucha Katakwardf223072021-06-15 10:21:00 -0700282 // Before detaching the device, cache the info from current open session.
283 // The disconnected check avoids duplication of info and also prevents
284 // deadlock while acquiring service lock in cacheDump.
285 if (!TClientBase::mDisconnected) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700286 ALOGD("Camera %s: start to cacheDump", TClientBase::mCameraIdStr.c_str());
Rucha Katakwardf223072021-06-15 10:21:00 -0700287 Camera2ClientBase::getCameraService()->cacheDump();
288 }
289
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800290 detachDevice();
291
Igor Murashkine6800ce2013-03-04 17:25:57 -0800292 CameraService::BasicClient::disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800293
Austin Borger1c1bee02023-06-01 16:51:35 -0700294 ALOGV("Camera %s: Shut down complete", TClientBase::mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800295
296 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800297}
298
299template <typename TClientBase>
300void Camera2ClientBase<TClientBase>::detachDevice() {
301 if (mDevice == 0) return;
302 mDevice->disconnect();
303
Austin Borger1c1bee02023-06-01 16:51:35 -0700304 ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800305}
306
307template <typename TClientBase>
308status_t Camera2ClientBase<TClientBase>::connect(
309 const sp<TCamCallbacks>& client) {
310 ATRACE_CALL();
311 ALOGV("%s: E", __FUNCTION__);
312 Mutex::Autolock icl(mBinderSerializationLock);
313
314 if (TClientBase::mClientPid != 0 &&
Austin Borger22c5c852024-03-08 13:31:36 -0800315 TClientBase::getCallingPid() != TClientBase::mClientPid) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800316
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800317 ALOGE("%s: Camera %s: Connection attempt from pid %d; "
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800318 "current locked to pid %d",
319 __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700320 TClientBase::mCameraIdStr.c_str(),
Austin Borger22c5c852024-03-08 13:31:36 -0800321 TClientBase::getCallingPid(),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800322 TClientBase::mClientPid);
323 return BAD_VALUE;
324 }
325
Austin Borger22c5c852024-03-08 13:31:36 -0800326 TClientBase::mClientPid = TClientBase::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800327
328 TClientBase::mRemoteCallback = client;
329 mSharedCameraCallbacks = client;
330
331 return OK;
332}
333
334/** Device-related methods */
335
336template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700337void Camera2ClientBase<TClientBase>::notifyError(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800338 int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -0700339 const CaptureResultExtras& resultExtras) {
340 ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
341 resultExtras.requestId);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800342}
343
344template <typename TClientBase>
Austin Borgerc8099762023-01-12 17:08:46 -0800345void Camera2ClientBase<TClientBase>::notifyPhysicalCameraChange(const std::string &physicalId) {
Jayant Chowdhary81d81b02024-02-15 19:13:39 +0000346 using android::hardware::ICameraService;
347 // We're only interested in this notification if rotationOverride is turned on.
348 if (TClientBase::mRotationOverride == ICameraService::ROTATION_OVERRIDE_NONE) {
Austin Borgerc8099762023-01-12 17:08:46 -0800349 return;
350 }
351
Austin Borger1c1bee02023-06-01 16:51:35 -0700352 auto physicalCameraMetadata = mDevice->infoPhysical(physicalId);
Austin Borgerc8099762023-01-12 17:08:46 -0800353 auto orientationEntry = physicalCameraMetadata.find(ANDROID_SENSOR_ORIENTATION);
354
355 if (orientationEntry.count == 1) {
356 int orientation = orientationEntry.data.i32[0];
357 int rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_NONE;
Jayant Chowdhary81d81b02024-02-15 19:13:39 +0000358 bool landscapeSensor = (orientation == 0 || orientation == 180);
359 if (((TClientBase::mRotationOverride ==
360 ICameraService::ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT) && landscapeSensor) ||
Mina Granicd19814a2024-06-18 10:08:58 +0000361 ((wm_flags::enable_camera_compat_for_desktop_windowing() &&
Jayant Chowdhary81d81b02024-02-15 19:13:39 +0000362 TClientBase::mRotationOverride ==
363 ICameraService::ROTATION_OVERRIDE_ROTATION_ONLY)
364 && !landscapeSensor)) {
Austin Borgerc8099762023-01-12 17:08:46 -0800365 rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_90;
366 }
367
Jayant Chowdhary44d5f622023-09-20 03:11:41 +0000368 static_cast<TClientBase *>(this)->setRotateAndCropOverride(rotateAndCropMode,
369 /*fromHal*/ true);
Austin Borgerc8099762023-01-12 17:08:46 -0800370 }
371}
372
373template <typename TClientBase>
Austin Borger4a870a32022-02-25 01:48:41 +0000374status_t Camera2ClientBase<TClientBase>::notifyActive(float maxPreviewFps) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700375 if (!mDeviceActive) {
376 status_t res = TClientBase::startCameraStreamingOps();
377 if (res != OK) {
378 ALOGE("%s: Camera %s: Error starting camera streaming ops: %d", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700379 TClientBase::mCameraIdStr.c_str(), res);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700380 return res;
381 }
Austin Borger74fca042022-05-23 12:41:21 -0700382 mCameraServiceProxyWrapper->logActive(TClientBase::mCameraIdStr, maxPreviewFps);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700383 }
384 mDeviceActive = true;
385
386 ALOGV("Camera device is now active");
387 return OK;
388}
389
390template <typename TClientBase>
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800391void Camera2ClientBase<TClientBase>::notifyIdleWithUserTag(
Shuzhen Wang316781a2020-08-18 18:11:01 -0700392 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700393 std::pair<int32_t, int32_t> mostRequestedFpsRange,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800394 const std::vector<hardware::CameraStreamStats>& streamStats,
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000395 const std::string& userTag, int videoStabilizationMode, bool usedUltraWide,
396 bool usedZoomOverride) {
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700397 if (mDeviceActive) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700398 status_t res = TClientBase::finishCameraStreamingOps();
399 if (res != OK) {
400 ALOGE("%s: Camera %s: Error finishing streaming ops: %d", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700401 TClientBase::mCameraIdStr.c_str(), res);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700402 }
Austin Borger74fca042022-05-23 12:41:21 -0700403 mCameraServiceProxyWrapper->logIdle(TClientBase::mCameraIdStr,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700404 requestCount, resultErrorCount, deviceError, userTag, videoStabilizationMode,
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700405 usedUltraWide, usedZoomOverride, mostRequestedFpsRange, streamStats);
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700406 }
407 mDeviceActive = false;
408
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700409 ALOGV("Camera device is now idle");
410}
411
412template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800413void Camera2ClientBase<TClientBase>::notifyShutter(
414 [[maybe_unused]] const CaptureResultExtras& resultExtras,
415 [[maybe_unused]] nsecs_t timestamp) {
Jianing Weicb0652e2014-03-12 18:29:36 -0700416 ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
417 __FUNCTION__, resultExtras.requestId, timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800418}
419
420template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800421void Camera2ClientBase<TClientBase>::notifyAutoFocus([[maybe_unused]] uint8_t newState,
422 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800423 ALOGV("%s: Autofocus state now %d, last trigger %d",
424 __FUNCTION__, newState, triggerId);
425
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800426}
427
428template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800429void Camera2ClientBase<TClientBase>::notifyAutoExposure([[maybe_unused]] uint8_t newState,
430 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800431 ALOGV("%s: Autoexposure state now %d, last trigger %d",
432 __FUNCTION__, newState, triggerId);
433}
434
435template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800436void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(
437 [[maybe_unused]] uint8_t newState,
438 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800439 ALOGV("%s: Auto-whitebalance state now %d, last trigger %d",
440 __FUNCTION__, newState, triggerId);
441}
442
443template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800444void Camera2ClientBase<TClientBase>::notifyPrepared([[maybe_unused]] int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700445 ALOGV("%s: Stream %d now prepared",
446 __FUNCTION__, streamId);
447}
448
449template <typename TClientBase>
Shuzhen Wang9d066012016-09-30 11:30:20 -0700450void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() {
451
452 ALOGV("%s: Request queue now empty", __FUNCTION__);
453}
454
455template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800456void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(
457 [[maybe_unused]] long lastFrameNumber) {
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700458 ALOGV("%s: Repeating request was stopped. Last frame number is %ld",
459 __FUNCTION__, lastFrameNumber);
460}
461
462template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800463int Camera2ClientBase<TClientBase>::getCameraId() const {
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800464 return mApi1CameraId;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800465}
466
467template <typename TClientBase>
468const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() {
469 return mDevice;
470}
471
472template <typename TClientBase>
473const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800474 return TClientBase::sCameraService;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800475}
476
477template <typename TClientBase>
478Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock(
479 SharedCameraCallbacks &client) :
480
481 mRemoteCallback(client.mRemoteCallback),
482 mSharedClient(client) {
483
484 mSharedClient.mRemoteCallbackLock.lock();
485}
486
487template <typename TClientBase>
488Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() {
489 mSharedClient.mRemoteCallbackLock.unlock();
490}
491
492template <typename TClientBase>
493Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks(
494 const sp<TCamCallbacks>&client) :
495
496 mRemoteCallback(client) {
497}
498
499template <typename TClientBase>
500typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks&
501Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=(
502 const sp<TCamCallbacks>&client) {
503
504 Mutex::Autolock l(mRemoteCallbackLock);
505 mRemoteCallback = client;
506 return *this;
507}
508
509template <typename TClientBase>
510void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() {
511 Mutex::Autolock l(mRemoteCallbackLock);
512 mRemoteCallback.clear();
513}
514
Cliff Wud3a05312021-04-26 23:07:31 +0800515template <typename TClientBase>
Austin Borger1c1bee02023-06-01 16:51:35 -0700516status_t Camera2ClientBase<TClientBase>::injectCamera(const std::string& injectedCamId,
Cliff Wud3a05312021-04-26 23:07:31 +0800517 sp<CameraProviderManager> manager) {
518 return mDevice->injectCamera(injectedCamId, manager);
519}
520
521template <typename TClientBase>
522status_t Camera2ClientBase<TClientBase>::stopInjection() {
523 return mDevice->stopInjection();
524}
525
malikakash22af94c2023-12-04 18:13:14 +0000526template <typename TClientBase>
527status_t Camera2ClientBase<TClientBase>::injectSessionParams(
528 const CameraMetadata& sessionParams) {
529 return mDevice->injectSessionParams(sessionParams);
530}
531
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800532template class Camera2ClientBase<CameraService::Client>;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700533template class Camera2ClientBase<CameraDeviceClientBase>;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800534
535} // namespace android