1 AIDL Camera Provider初始化
frameworks/av/services/camera/libcameraservice/common/CameraProviderManager.cpp
status_t CameraProviderManager::initialize(wp<CameraProviderManager::StatusListener> listener,
HidlServiceInteractionProxy* hidlProxy) {
std::lock_guard<std::mutex> lock(mInterfaceMutex);
if (hidlProxy == nullptr) {
ALOGE("%s: No valid service interaction proxy provided", __FUNCTION__);
return BAD_VALUE;
}
mListener = listener;
mDeviceState = 0;
auto res = tryToAddAidlProvidersLocked();
IPCThreadState::self()->flushCommands();
return res;
}
status_t CameraProviderManager::tryToAddAidlProvidersLocked() {
const char * aidlHalServiceDescriptor =
aidl::android::hardware::camera::provider::ICameraProvider::descriptor;
auto sm = defaultServiceManager();
auto aidlProviders = sm->getDeclaredInstances(
String16(aidlHalServiceDescriptor));
for (const auto &aidlInstance : aidlProviders) {
std::string aidlServiceName =
getFullAidlProviderName(std::string(String8(aidlInstance).c_str()));
auto res = sm->registerForNotifications(String16(aidlServiceName.c_str()), this);
if (res != OK) {
ALOGE("%s Unable to register for notifications with AIDL service manager",
__FUNCTION__);
return res;
}
addAidlProviderLocked(aidlServiceName);
}
return OK;
}
status_t AidlProviderInfo::initializeAidlProvider(
std::shared_ptr& interface, int64_t currentDeviceState) {
status_t res = parseProviderName(mProviderName, &mType, &mId);
if (res != OK) {
ALOGE("%s: Invalid provider name, ignoring", __FUNCTION__);
return BAD_VALUE;
}
ALOGI("Connecting to new camera provider: %s, isRemote? %d",
mProviderName.c_str(), interface->isRemote());
// cameraDeviceStatusChange callbacks may be called (and causing new devices added)
// before setCallback returns
mCallbacks =
ndk::SharedRefBase::make(this);
ndk::ScopedAStatus status =
interface->setCallback(mCallbacks);
if (!status.isOk()) {
ALOGE("%s: Transaction error setting up callbacks with camera provider '%s': %s",
__FUNCTION__, mProviderName.c_str(), status.getMessage());
return mapToStatusT(status);
}
mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(binderDied));
auto link = AIBinder_linkToDeath(interface->asBinder().get(), mDeathRecipient.get(), this);
if (link != STATUS_OK) {
ALOGW("%s: Unable to link to provider '%s' death notifications",
__FUNCTION__, mProviderName.c_str());
return DEAD_OBJECT;
}
if (!kEnableLazyHal) {
// Save HAL reference indefinitely
mSavedInterface = interface;
} else {
mActiveInterface = interface;
}
ALOGV("%s: Setting device state for %s: 0x%" PRIx64,
__FUNCTION__, mProviderName.c_str(), mDeviceState);
notifyDeviceStateChange(currentDeviceState);
res = setUpVendorTags();
if (res != OK) {
ALOGE("%s: Unable to set up vendor tags from provider '%s'",
__FUNCTION__, mProviderName.c_str());
return res;
}
// Get initial list of camera devices, if any
std::vector devices;
std::vector retDevices;
status = interface->getCameraIdList(&retDevices);
if (!status.isOk()) {
ALOGE("%s: Transaction error in getting camera ID list from provider '%s': %s",
__FUNCTION__, mProviderName.c_str(), status.getMessage());
return mapToStatusT(status);
}
for (auto& name : retDevices) {
uint16_t major, minor;
std::string type, id;
status_t res = parseDeviceName(name, &major, &minor, &type, &id);
if (res != OK) {
ALOGE("%s: Error parsing deviceName: %s: %d", __FUNCTION__, name.c_str(), res);
return res;
} else {
devices.push_back(name);
mProviderPublicCameraIds.push_back(id);
}
}
// Get list of concurrent streaming camera device combinations
res = getConcurrentCameraIdsInternalLocked(interface);
if (res != OK) {
return res;
}
mSetTorchModeSupported = true;
mIsRemote = interface->isRemote();
initializeProviderInfoCommon(devices);
return OK;
}
2 AIDL CameraDevice初始化
与HIDL CameraDevice初始化逻辑一样,请参考第10-14讲的内容。