android.hardware.camera2.impl.CameraDeviceImpl deviceImpl = new CameraDeviceImpl();
ICameraDeviceCallbacks callbacks = deviceImpl.getCallbacks()
if (supportsCamera2ApiLocked(cameraId)) {
// Use cameraservice's cameradeviceclient implementation for HAL3.2+ devices
ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
cameraService.connectDevice(callbacks, cameraId,mContext.getOpPackageName(), uid);
}else{
... ...
}
// TODO: factor out callback to be non-nested, then move setter to constructor
// For now, calling setRemoteDevice will fire initial
// onOpened/onUnconfigured callbacks.
// This function call may post onDisconnected and throw CAMERA_DISCONNECTED if
// cameraUser dies during setup.
deviceImpl.setRemoteDevice(cameraUser);
}
cameraService是通过Binder 继承 ICameraServiceListener.Stub
private static final class CameraManagerGlobal extends ICameraServiceListener.Stub
implements IBinder.DeathRecipient {
// This must match the ICameraService definition
private static final String CAMERA_SERVICE_BINDER_NAME = "media.camera";
public ICameraService getCameraService() {
synchronized(mLock) {
//
connectCameraServiceLocked();
return mCameraService;
}
}
private void connectCameraServiceLocked() {
IBinder cameraServiceBinder = ServiceManager.getService(CAMERA_SERVICE_BINDER_NAME);
ICameraService cameraService = ICameraService.Stub.asInterface(cameraServiceBinder);
for (CameraStatus c : cameraStatuses) {
onStatusChangedLocked(c.status, c.cameraId);
}
mCameraService = cameraService;
}
}
3.CameraService.cpp
(frameworks\\av\\services\\camera\\libcameraservice)
cameraService.connectDevice 通过AIDL 到用到 CameraService.cpp 中的connectDevice 方法。
Status CameraService::connectDevice(
const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
const String16& cameraId,
const String16& clientPackageName,
int clientUid,
/*out*/
sp<hardware::camera2::ICameraDeviceUser>* device) {
//调用connectHelper 方法
ret = connectHelper<hardware::camera2::ICameraDeviceCallbacks,CameraDeviceClient>(cameraCb, id,
/*api1CameraId*/-1,
CAMERA_HAL_API_VERSION_UNSPECIFIED, clientPackageNameAdj,
clientUid, USE_CALLING_PID, API_2, /*shimUpdateOnly*/ false, /*out*/client);
}
connectDevice 会调用到 connectHelper 方法
Status CameraService::connectHelper(){
// 闪光灯进入预准备阶段
mFlashlight->prepareDeviceOpen(cameraId);
//获取当前设备的Version
int deviceVersion = getDeviceVersion(cameraId, /*out*/&facing);
// 初始化CameraproviderManager
err = client->initialize(mCameraProviderManager, mMonitorTags);
}
4.CameraProviderManager.cpp
(frameworks\\av\\services\\camera\\libcameraservice\\common)
status_t CameraProviderManager::initialize(wpCameraProviderManager::StatusListener listener,
ServiceInteractionProxy* proxy) {
// 调用 addProviderLocked 方法
for (const auto& instance : mServiceProxy->listServices()) {
this->addProviderLocked(instance);
}
}
status_t CameraProviderManager::addProviderLocked(const std::string& newProvider) {
sp<ProviderInfo> providerInfo = new ProviderInfo(newProvider, this);
status_t res = providerInfo->initialize(interface, mDeviceState);
}
//ProviderInfo::initialize 初始化方法
status_t CameraProviderManager::ProviderInfo::initialize(){
status_t res = addDevice(device, common::V1_0::CameraDeviceStatus::PRESENT, &id);
}
status_t CameraProviderManager::ProviderInfo::addDevice(const std::string& name,
CameraDeviceStatus initialStatus, /*out*/ std::string* parsedId) {
//
deviceInfo = initializeDeviceInfo<DeviceInfo3>(name, mProviderTagid,
id, minor);
}
std::unique_ptrCameraProviderManager::ProviderInfo::DeviceInfo
CameraProviderManager::ProviderInfo::initializeDeviceInfo(){
// 后续调用待完善 如何 跳转到 Camera3device.cpp 的initialize 方法
return std::unique_ptr<DeviceInfo>(
new DeviceInfoT(name, tagId, id, minorVersion, resourceCost, this,
mProviderPublicCameraIds, cameraInterface));
}
5.Camera3Device.cpp
(frameworks\\av\\services\\camera\\libcameraservice\\device3)
status_t Camera3Device::initialize(sp manager, const String8& monitorTags) {
// 调用 CameraProviderManager openSession
ATRACE_BEGIN("CameraHal::openSession");
status_t res = manager->openSession(mId.string(), this,
/*out*/ &session);
ATRACE_END();
return initializeCommonLocked();
}
6.CameraProviderManager.cpp
(frameworks\\av\\services\\camera\\libcameraservice\\common)
status_t CameraProviderManager::openSession(const std::string &id,
const sp<device::V3_2::ICameraDeviceCallback>& callback,
/*out*/
sp<device::V3_2::ICameraDeviceSession> *session) {
auto interface = deviceInfo3->startDeviceInterface<
CameraProviderManager::ProviderInfo::DeviceInfo3::InterfaceT>();
ret = interface->open(callback, [&status, &session]
(Status s, const sp<device::V3_2::ICameraDeviceSession>& cameraSession) {
status = s;
if (status == Status::OK) {
*session = cameraSession;
}
});
}
7.ICameraDevice.hal
(hardware\\interfaces\\camera\\device\\3.2)
//Power on and initialize this camera device for active use, returning a
//session handle for active operations.
open(ICameraDeviceCallback callback) generates
(Status status, ICameraDeviceSession session);
8.CameraDevice.cpp
(hardware\\interfaces\\camera\\device\\3.2\\default)
Return CameraDevice::open(const sp& callback,
ICameraDevice::open_cb _hidl_cb) {
/** Open HAL device */
status_t res;
camera3_device_t *device;
// 1. 开始 open Hal Device
ATRACE_BEGIN("camera3->open");
res = mModule->open(mCameraId.c_str(),
reinterpret_cast<hw_device_t**>(&device));
ATRACE_END();
// 2. 获取Camera 信息
res = mModule->getCameraInfo(mCameraIdInt, &info);
// 3. 创建 CameraDeviceSession
session = createSession(device, info.static_camera_characteristics, callback);
}
1. CameraModule.cpp
(hardware\\interfaces\\camera\\common\\1.0\\default)
int CameraModule::open(const char* id, struct hw_device_t** device) {
int res;
ATRACE_BEGIN("camera_module->open");
res = filterOpenErrorCode(mModule->common.methods->open(&mModule->common, id, device));
ATRACE_END();
return res;
}
10.Camxhal3entry.cpp
(vendor\\qcom\\proprietary\\camx\\src\\core\\hal)
int open(
const struct hw_module_t* pHwModuleAPI,
const char* pCameraIdAPI,
struct hw_device_t** ppHwDeviceAPI)
{
/// @todo (CAMX-43) - Reload Jumptable from settings
JumpTableHAL3* pHAL3 = static_cast<JumpTableHAL3*>(g_dispatchHAL3.GetJumpTable());
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
总结
最后为了帮助大家深刻理解Android相关知识点的原理以及面试相关知识,这里放上相关的我搜集整理的24套腾讯、字节跳动、阿里、百度2019-2021面试真题解析,我把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包知识脉络 + 诸多细节。
还有 高级架构技术进阶脑图、Android开发面试专题资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。
2021年虽然路途坎坷,都在说Android要没落,但是,不要慌,做自己的计划,学自己的习,竞争无处不在,每个行业都是如此。相信自己,没有做不到的,只有想不到的。祝大家2021年万事大吉。
一个人可以走的很快,但一群人才能走的更远。如果你从事以下工作或对以下感兴趣,欢迎戳这里加入程序员的圈子,让我们一起学习成长!
AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算
堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。
2021年虽然路途坎坷,都在说Android要没落,但是,不要慌,做自己的计划,学自己的习,竞争无处不在,每个行业都是如此。相信自己,没有做不到的,只有想不到的。祝大家2021年万事大吉。
一个人可以走的很快,但一群人才能走的更远。如果你从事以下工作或对以下感兴趣,欢迎戳这里加入程序员的圈子,让我们一起学习成长!
AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算