Android6.0 不同方式安装apk copy lib流程

时间:2025-01-27 11:46:21
  • public void derivePackageAbi( pkg, File scanFile,  
  •                              String cpuAbiOverride, boolean extractLibs)  
  •         throws PackageManagerException {  
  •     setNativeLibraryPaths(pkg);  
  •   
  •     if (() || () ||  
  •             (isSystemApp(pkg) && !())) {  
  •         extractLibs = false;  
  •     }  
  •   
  •     final String nativeLibraryRootStr = ;  
  •     final boolean useIsaSpecificSubdirs = ;  
  •   
  •      handle = null;  
  •     try {  
  •         handle = (scanFile);  
  •         final File nativeLibraryRoot = new File(nativeLibraryRootStr);  
  •   
  •         // Null out the abis so that they can be recalculated.  
  •          = null;  
  •          = null;  
  •         if (isMultiArch()) {  
  •             // Warn if we've set an abiOverride for multi-lib packages..  
  •             // By definition, we need to copy both 32 and 64 bit libraries for  
  •             // such packages.  
  •             if ( != null  
  •                     && !NativeLibraryHelper.CLEAR_ABI_OVERRIDE.equals()) {  
  •                 (TAG, "Ignoring abiOverride for multi arch application.");  
  •             }  
  •   
  •             int abi32 = PackageManager.NO_NATIVE_LIBRARIES;  
  •             int abi64 = PackageManager.NO_NATIVE_LIBRARIES;  
  •             if (Build.SUPPORTED_32_BIT_ABIS.length > 0) {  
  •                 if (extractLibs) {  
  •                     abi32 = (handle,  
  •                             nativeLibraryRoot, Build.SUPPORTED_32_BIT_ABIS,  
  •                             useIsaSpecificSubdirs);  
  •                 } else {  
  •                     abi32 = (handle, Build.SUPPORTED_32_BIT_ABIS);  
  •                 }  
  •             }  
  •   
  •             maybeThrowExceptionForMultiArchCopy(  
  •                     "Error unpackaging 32 bit native libs for multiarch app.", abi32);  
  •   
  •             if (Build.SUPPORTED_64_BIT_ABIS.length > 0) {  
  •                 if (extractLibs) {  
  •                     abi64 = (handle,  
  •                             nativeLibraryRoot, Build.SUPPORTED_64_BIT_ABIS,  
  •                             useIsaSpecificSubdirs);  
  •                 } else {  
  •                     abi64 = (handle, Build.SUPPORTED_64_BIT_ABIS);  
  •                 }  
  •             }  
  •   
  •             maybeThrowExceptionForMultiArchCopy(  
  •                     "Error unpackaging 64 bit native libs for multiarch app.", abi64);  
  •   
  •             if (abi64 >= 0) {  
  •                  = Build.SUPPORTED_64_BIT_ABIS[abi64];  
  •             }  
  •   
  •             if (abi32 >= 0) {  
  •                 final String abi = Build.SUPPORTED_32_BIT_ABIS[abi32];  
  •                 if (abi64 >= 0) {  
  •                      = abi;  
  •                 } else {  
  •                      = abi;  
  •                 }  
  •             }  
  •         } else {  
  •             String[] abiList = (cpuAbiOverride != null) ?  
  •                     new String[] { cpuAbiOverride } : Build.SUPPORTED_ABIS;  
  •   
  •             // Enable gross and lame hacks for apps that are built with old  
  •             // SDK tools. We must scan their APKs for renderscript bitcode and  
  •             // not launch them if it's present. Don't bother checking on devices  
  •             // that don't have 64 bit support.  
  •             boolean needsRenderScriptOverride = false;  
  •             if (Build.SUPPORTED_64_BIT_ABIS.length > 0 && cpuAbiOverride == null &&  
  •                     (handle)) {  
  •                 abiList = Build.SUPPORTED_32_BIT_ABIS;  
  •                 needsRenderScriptOverride = true;  
  •             }  
  •             final int copyRet;  
  •             if (extractLibs) {  
  •                 copyRet = (handle,  
  •                         nativeLibraryRoot, abiList, useIsaSpecificSubdirs);  
  •             } else {  
  •                 copyRet = (handle, abiList);  
  •             }  
  •   
  •             if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES) {  
  •                 throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,  
  •                         "Error unpackaging native libs for app, errorCode=" + copyRet);  
  •             }  
  •   
  •             if (copyRet >= 0) {  
  •                  = abiList[copyRet];  
  •             } else if (copyRet == PackageManager.NO_NATIVE_LIBRARIES && cpuAbiOverride != null) {  
  •                  = cpuAbiOverride;  
  •             } else if (needsRenderScriptOverride) {  
  •                  = abiList[0];  
  •             }  
  •         }  
  •     } catch (IOException ioe) {  
  •         (TAG, "Unable to get canonical file " + ());  
  •     } finally {  
  •         (handle);  
  •     }  
  •   
  •     // Now that we've calculated the ABIs and determined if it's an internal app,  
  •     // we will go ahead and populate the nativeLibraryPath.  
  •     setNativeLibraryPaths(pkg);  
  • }