Android13预装APP到data分区

修改步骤与Android11是差不多的,只是有部分代码所在位置不一样。
Android 11®内置APP到data/app
Android 8(O)预置APP到data/app

默认内置应用到data会出错

1970-01-01 08:03:54.499 1177-1177/system_process I/PackageManager: /data/app/xx changed; collecting certs

1970-01-01 08:03:54.547 1177-1177/system_process W/PackageManager: Failed to scan /data/app/xx: Application package com.benew.ntt.cloud not found; ignoring.

1970-01-01 08:03:54.547 1177-1177/system_process W/PackageManager: Deleting invalid package at /data/app/xx

userdata.img只有几十k的问题

往data中加了几百M大小的app,在out/xx/data/app中也看到编译出来了,

但是编译后却发现userdata.img只有90k,是空的分区,

在.mk中修改userdata分区大小,.mk里面默认是64M, 改成512M解决了。

patch 复制代码
diff --git a/device/sprd/mpool/module/generic/partition/main.mk b/device/sprd/mpool/module/generic/partition/main.mk
index 37b0b79d0e9..d2f2322d6b3 100755
--- a/device/sprd/mpool/module/generic/partition/main.mk
+++ b/device/sprd/mpool/module/generic/partition/main.mk
@@ -25,8 +25,8 @@ endif
 $(call md-set, BOARD_BOOTIMAGE_PARTITION_SIZE, 67108864)
 $(call md-set, BOARD_CACHEIMAGE_PARTITION_SIZE, 67108864)
 
-# default value is 64M, using resize to adapter real size
-BOARD_USERDATAIMAGE_PARTITION_SIZE ?= 67108864
+# default value is 512M, using resize to adapter real size
+BOARD_USERDATAIMAGE_PARTITION_SIZE ?= 536870912

实现

Android11中修改的是

frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java

Android 13不同,需要修改

frameworks/base/services/core/java/com/android/server/pm/InstallPackageHelper.java

注释掉

else {
                        throw new PackageManagerException(INSTALL_FAILED_INVALID_INSTALL_LOCATION,
                                "Application package " + pkg.getPackageName()
                                        + " not found; ignoring.");
                    }

完整代码如下

java 复制代码
            if ((scanFlags & SCAN_REQUIRE_KNOWN) != 0) {
                if (mPm.isExpectingBetter(pkg.getPackageName())) {
                    Slog.w(TAG, "Relax SCAN_REQUIRE_KNOWN requirement for package "
                            + pkg.getPackageName());
                } else {
                    PackageSetting known = mPm.mSettings.getPackageLPr(pkg.getPackageName());
                    if (known != null) {
                        if (DEBUG_PACKAGE_SCANNING) {
                            Log.d(TAG, "Examining " + pkg.getPath()
                                    + " and requiring known path " + known.getPathString());
                        }
                        if (!pkg.getPath().equals(known.getPathString())) {
                            throw new PackageManagerException(INSTALL_FAILED_PACKAGE_CHANGED,
                                    "Application package " + pkg.getPackageName()
                                            + " found at " + pkg.getPath()
                                            + " but expected at " + known.getPathString()
                                            + "; ignoring.");
                        }
                    } /*else {
                        throw new PackageManagerException(INSTALL_FAILED_INVALID_INSTALL_LOCATION,
                                "Application package " + pkg.getPackageName()
                                        + " not found; ignoring.");
                    }*/
                }
            }
patch 复制代码
diff --git a/system/core/init/util.cpp b/system/core/init/util.cpp
index d1e518b5795..bee7a8bb70d 100644
--- a/system/core/init/util.cpp
+++ b/system/core/init/util.cpp
@@ -485,7 +485,7 @@ static FscryptAction FscryptInferAction(const std::string& dir) {
     std::vector<std::string> directories_to_exclude = {
             "lost+found", "system_ce", "system_de", "misc_ce",     "misc_de",
             "vendor_ce",  "vendor_de", "media",     "data",        "user",
-            "user_de",    "apex",      "preloads",  "app-staging", "gsi",
+            "user_de",    "apex",      "preloads",  "app-staging", "gsi", "app",
     };
     for (const auto& d : directories_to_exclude) {
         if ((prefix + d) == dir) {
diff --git a/system/core/rootdir/init.rc b/system/core/rootdir/init.rc
index 405667cf8df..1a8bc1215eb 100644
--- a/system/core/rootdir/init.rc
+++ b/system/core/rootdir/init.rc
@@ -853,7 +853,7 @@ on post-fs-data
     mkdir /data/app-ephemeral 0771 system system encryption=Require
     mkdir /data/app-asec 0700 root root encryption=Require
     mkdir /data/app-lib 0771 system system encryption=Require
-    mkdir /data/app 0771 system system encryption=Require
+    mkdir /data/app 0771 system system encryption=None
     mkdir /data/property 0700 root root encryption=Require
 
     # create directory for updated font files.

作者:帅得不敢出门 原创文件谢绝转载收录

相关推荐
2401_8979078632 分钟前
10天学会flutter DAY2 玩转dart 类
android·flutter
m0_748233641 小时前
【PHP】部署和发布PHP网站到IIS服务器
android·服务器·php
Yeats_Liao2 小时前
Spring 定时任务:@Scheduled 注解四大参数解析
android·java·spring
雾里看山4 小时前
【MySQL】 库的操作
android·数据库·笔记·mysql
水瓶丫头站住12 小时前
安卓APP如何适配不同的手机分辨率
android·智能手机
xvch13 小时前
Kotlin 2.1.0 入门教程(五)
android·kotlin
xvch17 小时前
Kotlin 2.1.0 入门教程(七)
android·kotlin
望风的懒蜗牛17 小时前
编译Android平台使用的FFmpeg库
android
浩宇软件开发17 小时前
Android开发,待办事项提醒App的设计与实现(个人中心页)
android·android studio·android开发
ac-er888818 小时前
Yii框架中的多语言支持:如何实现国际化
android·开发语言·php