【原创】Android x86上Camera流程

CleanLi(黎涛) 发表于2017-07-17    类别: 技术(66)    标签: 原创(65) Android(23) Camera(10)

【记录】编译测试Android nougat-x86这里编译了Android nougat-x86之后,安装在电脑上,可以正常启动,而且插上usb camera之后还可以打开相机。于是想验证一下Camera的流程。

这里使用的Camera app是自己写的GoldCam
【原创】写了一个Camera App:GoldCam
安装在电脑的Android上,可以打开usb的camera。

先观察Camera.open(cameraId)这个动作,这里使用的是Camera API 1,所以framework这边会走
core/java/android/hardware/Camera.java
这边,通过JNI走到
core/jni/android_hardware_Camera.cpp

在刚刚这两个文件里加了下面的log:

diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index 218cc37..d869fee 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -342,6 +342,7 @@ public class Camera {
      * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
      */
     public static Camera open(int cameraId) {
+       Log.e(TAG, "cam_track_fwth Camera open(int cameraId) " + cameraId);
         return new Camera(cameraId);
     }
 
@@ -462,11 +463,13 @@ public class Camera {
             mEventHandler = null;
         }
 
+       Log.e(TAG, "cam_track_fwth cameraInitVersion(int cameraId, int halVersion) " + cameraId + " " + halVersion);
         return native_setup(new WeakReference<Camera>(this), cameraId, halVersion,
                 ActivityThread.currentOpPackageName());
     }
 
     private int cameraInitNormal(int cameraId) {
+       Log.e(TAG, "cam_track_fwth cameraInitNormal(int cameraId) " + cameraId);
         return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT);
     }
 
@@ -490,6 +493,7 @@ public class Camera {
 
     /** used by Camera#open, Camera#open(int) */
     Camera(int cameraId) {
+       Log.e(TAG, "cam_track_fwth Camera(int cameraId) " + cameraId);
         int err = cameraInitNormal(cameraId);
         if (checkInitErrors(err)) {
             if (err == -EACCES) {
diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp
index b926270..0868253 100644
--- a/core/jni/android_hardware_Camera.cpp
+++ b/core/jni/android_hardware_Camera.cpp
@@ -543,6 +543,7 @@ static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz,
     env->ReleaseStringChars(clientPackageName,
                             reinterpret_cast<const jchar*>(rawClientName));
 
+    ALOGE("%s: camera ID %d halVersion %d", __FUNCTION__, cameraId, halVersion);
     sp<Camera> camera;
     if (halVersion == CAMERA_HAL_API_VERSION_NORMAL_CONNECT) {
         // Default path: hal version is don't care, do normal camera connect.

编译的话JNI要到frameworks/base/core/jni下面mm,生成libandroid_runtime.so

adb push ~/Projects/aosp/out/target/product/x86/system/lib/libandroid_runtime.so /system/lib

Camera.java的改动,需要到frameworks/base下面mm,然后编译的log只提示生成了boot.art

Running kati to generate build-android_x86-mmm-frameworks_base_Android.mk.ninja...
No need to regenerate ninja file
Starting build with ninja
ninja: Entering directory `.'
[  2% 1/34] Ensure Jack server is installed and started
Jack server already installed in "/home/clean/.jack-server"
Server is already running
[100% 34/34] Install: out/target/product/x86/system/framework/x86/boot.art
make: Leaving directory '/home/clean/Projects/aosp'

但只把这个放到电脑里面发现不行,于是把boot-framework.artboot-framework.oat一起更新

clean@cl:/tmp/test$ adb push ~/Projects/aosp/out/target/product/x86/system/framework/x86/boot.art /system/framework/x86
3547 KB/s (2125824 bytes in 0.585s)
clean@cl:/tmp/test$ adb push ~/Projects/aosp/out/target/product/x86/system/framework/x86/boot-framework.art /system/framework/x86
2933 KB/s (6049792 bytes in 2.013s)
clean@cl:/tmp/test$ adb push ~/Projects/aosp/out/target/product/x86/system/framework/x86/boot-framework.oat /system/framework/x86
3464 KB/s (39312492 bytes in 11.080s)
clean@cl:/tmp/test$ adb reboot

打开GoldCam,刚才加的log都有了,证明其在framework的流程正是如前面分析。

clean@cl:/tmp/test$ grep -Irn "native_setup\|cam_track_fwth" l
5650:07-17 14:23:46.143  3707  3707 E Camera  : cam_track_fwth Camera open(int cameraId) 0
5651:07-17 14:23:46.143  3707  3707 E Camera  : cam_track_fwth Camera(int cameraId) 0
5652:07-17 14:23:46.143  3707  3707 E Camera  : cam_track_fwth cameraInitNormal(int cameraId) 0
5653:07-17 14:23:46.143  3707  3707 E Camera  : cam_track_fwth cameraInitVersion(int cameraId, int halVersion) 0 -2
5654:07-17 14:23:46.143  3707  3707 E Camera-JNI: android_hardware_Camera_native_setup: camera ID 0 halVersion -2
6237:07-17 14:23:48.018  3707  3707 E Camera  : cam_track_fwth Camera open(int cameraId) 0
6238:07-17 14:23:48.018  3707  3707 E Camera  : cam_track_fwth Camera(int cameraId) 0
6239:07-17 14:23:48.018  3707  3707 E Camera  : cam_track_fwth cameraInitNormal(int cameraId) 0
6240:07-17 14:23:48.018  3707  3707 E Camera  : cam_track_fwth cameraInitVersion(int cameraId, int halVersion) 0 -2
6241:07-17 14:23:48.018  3707  3707 E Camera-JNI: android_hardware_Camera_native_setup: camera ID 0 halVersion -2

halVersion = -2,这个就是这个定义

private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2;

这个表示走正常的connect,区别于指定hal版本的connectLegacy。

相关文章

   2018-01-23 【记录】Win8安装adb
   2017-08-26 【原创】Android x86上的Camera HAL(2)
   2017-08-20 【原创】Steps of Camera HAL Module Searching
   2017-08-16 【转载】Android Camera Overview
   2017-08-05 【转载】Android x86睡眠触发时间修改
   2017-07-27 【原创】Camera不同版本API与HAL流程
   2017-07-18 【原创】在Github上建立clean study
   2017-06-27 【原创】写了一个Camera App:GoldCam
   2017-06-14 【原创】Android x86屏幕旋转设定apk
   2017-06-13 【记录】USB硬盘安装Android x86
   2017-06-09 【记录】Ubuntu 16.04安装Android Studio
   2017-06-09 【记录】编译测试Android nougat-x86