自学内容网 自学内容网

android关于framework层的中间件jar的流程

简述

基于android12的版本进行处理的,要达到的效果是一开机系统就自动加载完成所需要的jar包。

实现过程

1.jar包制作

framework/base下的代码实现如下所示

commit 9f37044be18cda8ec48ac1588c36b11bf2df2c3e (HEAD)
Author: xxxxxx <xxxxxx>
Date:   Sat May 18 23:14:27 2024 +0800

    test code
    
    Change-Id: I52c69e25f367a1314dcb0fa7fcef5a4c3a740c7b

diff --git a/cmds/custom_fra_jar/Android.bp b/cmds/custom_fra_jar/Android.bp
new file mode 100644
index 000000000000..f5d1a9bc41c6
--- /dev/null
+++ b/cmds/custom_fra_jar/Android.bp
@@ -0,0 +1,7 @@
+java_library{
+    name: "custom_fra_jar",
+    srcs: [
+        "src/**/*.java",
+    ],
+    installable:true,
+}
\ No newline at end of file
diff --git a/cmds/custom_fra_jar/src/com/custom/fra/CustomFraTest.java b/cmds/custom_fra_jar/src/com/custom/fra/CustomFraTest.java
new file mode 100644
index 000000000000..f1e15c1ad763
--- /dev/null
+++ b/cmds/custom_fra_jar/src/com/custom/fra/CustomFraTest.java
@@ -0,0 +1,13 @@
+package com.custom.fra;
+
+import android.util.Log;
+
+public class CustomFraTest {
+    private static final String TAG = "CustomFraTest";
+
+    public static void testFunction() {
+        Log.i(TAG, "testFunction is success");
+        Log.i(TAG, "testFunction is framework own log");
+
+    }
+}

2.PRODUCT_BOOT_JARS处理

在build/make/target/product/default_art_config.mk文件中添加custom_fra_jar配置

diff --git a/target/product/default_art_config.mk b/target/product/default_art_config.mk
index 0fa9058f0b..f4a5f841e3 100644
--- a/target/product/default_art_config.mk
+++ b/target/product/default_art_config.mk
@@ -43,6 +43,7 @@ PRODUCT_BOOT_JARS += \
     ext \
     telephony-common \
     voip-common \
+    custom_fra_jar \
     ims-common
 
 # Non-updatable APEX jars. Keep the list sorted.

3.PRODUCT_PACKAGES处理

在device/xxx/car/common/car.mk文件中添加custom_fra_jar配置,此处的配置路径需要随着项目存在一些差异。

diff --git a/common/car.mk b/common/car.mk
index d835123..99b1ed0 100644
--- a/common/car.mk
+++ b/common/car.mk
@@ -18,6 +18,7 @@
 PRODUCT_PACKAGES += \
     android.hardware.automotive.vehicle@2.0-service \
     android.hardware.broadcastradio@2.0-service \
+    custom_fra_jar \
     android.hardware.audio.service-caremu
 
 # Emulator configuration

4.白名单配置

在build/soong/scripts/check_boot_jars/package_allowed_list.txt文件中配置白名单

diff --git a/scripts/check_boot_jars/package_allowed_list.txt b/scripts/check_boot_jars/package_allowed_list.txt
index 18ab427b5..247c9ebf3 100644
--- a/scripts/check_boot_jars/package_allowed_list.txt
+++ b/scripts/check_boot_jars/package_allowed_list.txt
@@ -86,6 +86,8 @@ sun\.reflect.*
 sun\.nio.*
 sun\.net.*
 com\.sun\..*
+com\.custom\.fra
+com\.custom\.fra\..*
 
 # TODO: Move these internal org.apache.harmony classes to libcore.*
 org\.apache\.harmony\.crypto\.internal

编译整个系统代码,成功后进行烧录

命令验证

当前需要在系统中的以下两处查询到相关信息“custom_fra_jar”
1.进入系统中输入以下命令

xxx/ # /system/etc/permissions # $BOOTCLASSPATH 

可以看到输出了很多个jar包,其中可以看到里面有以下的名称

/system/framework/custom_fra_jar.jar

2.查看system/framework下的jar包

xxx:/system/framework # ls -la custom_fra_jar.jar                                                                                                                                                        
-rw-r--r-- 1 root root 1217 2024-05-18 22:23 custom_fra_jar.jar

以上表示framework层的中间件jar已经制作完成了。

系统应用验证

路径packages/apps/Car/Launcher
添加如下代码进行验证:

diff --git a/Android.bp b/Android.bp
index 77e8e3d..054c7e9 100644
--- a/Android.bp
+++ b/Android.bp
@@ -35,7 +35,9 @@ android_library {
         "WindowManager-Shell",
     ],
 
-    libs: ["android.car"],
+    libs: [
+    "android.car",
+    "custom_fra_jar",],
 
     manifest: "AndroidManifest.xml",
 }
diff --git a/src/com/android/car/carlauncher/CarLauncher.java b/src/com/android/car/carlauncher/CarLauncher.java
index 30c8c21..2bf3f17 100644
--- a/src/com/android/car/carlauncher/CarLauncher.java
+++ b/src/com/android/car/carlauncher/CarLauncher.java
@@ -20,6 +20,7 @@ import static android.app.ActivityTaskManager.INVALID_TASK_ID;
 import static android.car.user.CarUserManager.USER_LIFECYCLE_EVENT_TYPE_SWITCHING;
 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY;
 
+import com.custom.fra.CustomFraTest;
 import android.app.ActivityManager;
 import android.app.ActivityOptions;
 import android.app.ActivityTaskManager;
@@ -183,7 +184,9 @@ public class CarLauncher extends FragmentActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-
+        Log.d(TAG,"start");
+        CustomFraTest.testFunction();
+        Log.d(TAG,"end");
         if (CarLauncherUtils.isCustomDisplayPolicyDefined(this)) {
             Intent controlBarIntent = new Intent(this, ControlBarActivity.class);
             controlBarIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

重新编译系统,烧录最新镜像。

输出如下所示:

05-18 21:59:49.134  1892  1892 D CarLauncher:  start
05-18 21:59:49.134  1892  1892 I CustomFraTest: testFunction is success
05-18 21:59:49.134  1892  1892 I CustomFraTest: testFunction is framework own log
05-18 21:59:49.134  1892  1892 D CarLauncher:  end

原文地址:https://blog.csdn.net/qq_27840511/article/details/139032826

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!