Android 4.4 PM机制系列(四) APK安装需要空间分析

前言

Android 9.0 PM机制系列(四) APK安装需要空间分析以及 Android 6.0 PM机制系列(四) APK安装需要空间分析两篇文章中,我们重点分析了Android9.0以及Android6.0所需要的最小APK安装存储空间大小。本篇我们要分析Android4.4安装APK所需要空间大小。

1. 开始安装

分析源码,一直跟到PMS里面,发现和Android9.0,6.0一样,安装核心代码开始处就在handleStartCopy方法,代码如下:
/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java

public void handleStartCopy() throws RemoteException {
   
    int ret = PackageManager.INSTALL_SUCCEEDED;
    final boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0;
    final boolean onInt = (flags & PackageManager.INSTALL_INTERNAL) != 0;
    PackageInfoLite pkgLite = null;

    if (onInt && onSd) {
   
        // Check if both bits are set.
        Slog.w(TAG, "Conflicting flags specified for installing on both internal and external");
        ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
    } else {
   
        final long lowThreshold;

        final DeviceStorageMonitorService dsm = (DeviceStorageMonitorService) ServiceManager
                .getService(DeviceStorageMonitorService.SERVICE);
        if (dsm == null) {
   
            Log.w(TAG, "Couldn't get low memory threshold; no free limit imposed");
            lowThreshold = 0L;
        } else {
   
            lowThreshold = dsm.getMemoryLowThreshold(); //1
        }

        try {
   
            mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, mPackageURI,
                    Intent.FLAG_GRANT_READ_URI_PERMISSION);

            final File packageFile;
            if (encryptionParams != null || !"file".equals(mPackageURI.getScheme())) {
   //2
                mTempPackage = createTempPackageFile(mDrmAppPrivateInstallDir);
                if (mTempPackage != null) {
   
                    ParcelFileDescriptor out;
                    try {
   
                        out = ParcelFileDescriptor.open(mTempPackage,
                                ParcelFileDescriptor.MODE_READ_WRITE);
                    } catch (FileNotFoundException e) {
   
                        out = null;
                        Slog.e(TAG, "Failed to create temporary file for : " + mPackageURI);
                    }

                    // Make a temporary file for decryption.
                    ret = mContainerService
                            .copyResource(mPackageURI, encryptionParams, out);
                    IoUtils.closeQuietly(out);

                    packageFile = mTempPackage;

                    FileUtils.setPermissions(packageFile.getAbsolutePath(),
                            FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP
                                    | FileUtils.S_IROTH,
                            -1, -1);
                } else {
   
                    packageFile = null;
                }
            } else {
   
                packageFile = new File(mPackageURI.getPath());
            }

            if (packageFile != null) {
   
                // Remote call to find
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值