• dumpsys-package


    dumpsys-package

    ams和pms是android系统最重要的系统服务,本文解析dumpsys package命令,看哪些PMS相关的系统信息,数据结构是运行时可以查看的。

    命令提示

    console:/ # dumpsys package -h
    Package manager dump options:
      [-h] [-f] [--checkin] [cmd] ...
        --checkin: dump for a checkin
        -f: print details of intent filters
        -h: print this help
      cmd may be one of:
        l[ibraries]: list known shared libraries                                   
        f[eatures]: list device features                                           
        k[eysets]: print known keysets                                             
        r[esolvers] [activity|service|receiver|content]: dump intent resolvers     
        perm[issions]: dump permissions                                            
        permission [name ...]: dump declaration and use of given permission        
        pref[erred]: print preferred package settings                              
        preferred-xml [--full]: print preferred package settings as xml            
        prov[iders]: dump content providers                                        
        p[ackages]: dump installed packages                                        
        s[hared-users]: dump shared user IDs                                       
        m[essages]: print collected runtime messages                               
        v[erifiers]: print package verifier info                                   
        d[omain-preferred-apps]: print domains preferred apps                      
        i[ntent-filter-verifiers]|ifv: print intent filter verifier info           
        version: print database version info                                       
        write: write current settings now                                          
        installs: details about install sessions                                   
        check-permission <permission> <package> [<user>]: does pkg hold perm?      
        dexopt: dump dexopt state                                                  
        compiler-stats: dump compiler statistics                                   
        service-permissions: dump permissions required by services                 
        <package.name>: info about given package                                   
    
    
    

    AuthBlog:秋城https://www.cnblogs.com/houser0323

    数据结构

    命令 源码 关键字 释义
    l[ibraries] mSharedLibraries Libraries: 所有库信息
    f[eatures] mAvailableFeatures Features: 系统支持的feature
    k[eysets] mSettings.mKeySetManagerService.dumpLPr() Key Set Manager: keyset信息
    r[esolvers] IntentResolver.java#dump() Activity Resolver Table: 所有四大组件intent接收器信息
    perm[issions] mSettings.dumpPermissionsLPr() Permissions: 所有权限信息
    permission [name ...] mSettings.dumpPermissionsLPr() Permissions: 特定权限信息
    pref[erred] PreferredIntentResolver#dump() Preferred Activities User launcher activity偏好信息
    preferred-xml [--full] mSettings.writePreferredActivitiesLPr 生成xml
    prov[iders] PackageParser.Provider mProviders.mProviders Registered ContentProviders: 所有ContentProvider信息
    p[ackages] mSettings.dumpPackagesLPr() Packages: 所有package信息
    s[hared-users] mSettings.dumpSharedUsersLPr() Shared users: 所有共享uid信息
    m[essages] mSettings.dumpReadMessagesLPr()/dumpCriticalInfo() Settings parse messages 读系统packageSetting解析信息mReadMessages、读uiderrors.txt
    v[erifiers] mRequiredVerifierPackage Verifiers: 需要验证的apk
    d[omain-preferred-apps] PackageSetting#getIntentFilterVerificationInfo() App verification status: 域验证信息
    i[ntent-filter-verifiers] mIntentFilterVerifierComponent Intent Filter Verifier: AppLink相关
    version mSettings.dumpVersionLPr() Database versions: 数据库版本
    write mSettings.writeLPr() 这是写操作用于替换packages.xml
    installs mInstallerService.dump() Active install sessions: 活动中的install session信息
    check-permission [] checkPermission() 返回值0表有;-1表无
    dexopt dumpDexoptStateLPr() Dexopt state: 所有apk的dexopt信息
    compiler-stats dumpCompilerStatsLPr() Compiler stats: 所有apk的编译器信息
    service-permissions serviceInfo.permission Service permissions: 所有service的权限信息
    <package.name> DumpState.OPTION_SHOW_FILTERS 特定apk的所有信息-最常用

    常用操作

    1.包名和apk名互查

    $ dumpsys package com.android.systemui |grep -i path
        codePath=/system/priv-app/SystemUI
        resourcePath=/system/priv-app/SystemUI
        path: /system/priv-app/SystemUI/SystemUI.apk
    

    知道包名查路径还可以用pm path <package name>更方便,但是知道apk名称查包名就需要dumpsys了,如下

    $ dumpsys package p |grep -B 5 SystemUI|grep Package
      Package [com.android.systemui] (633b2ed):
        pkg=Package{8e872f3 com.android.systemui}
    

    2.查看系统支持的feature

    pm list features命令作用相同

    $ dumpsys package f
    ......
      android.hardware.bluetooth
      android.hardware.usb.host
    ......
    

    3.查看apk权限信息

    $ dumpsys package <package name>
    

    打印中查找关键字

    • "declared permissions:"应用自定义权限
    • "requested permissions:"AndroidManifest.xml文件中所有request的权限
    • "install permissions:"安装时就赋予的权限
    • "runtime permissions:"运行时权限

    4.查看apk的flag信息

    查看某个apk的flag信息,如systemui

    $ dumpsys package com.android.systemui |grep Flags                               
        privateFlags=[ PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION DEFAULT_TO_DEVICE_PROTECTED_STORAGE DIRECT_BOOT_AWARE PRIVILEGED ]
        pkgFlags=[ SYSTEM HAS_CODE PERSISTENT ]
    
    

    可以看到systemui是system系统应用也是persistent应用,如果要查找所有的system应用可以用pm list packages -s,查找所有PERSISTENT的应用呢,可以dumpsys package p然后在结果中过滤,除此之外还有另外两种方法dumpsys meminfologcat -b events |grep -i am_proc_start

    总结

    dumpsys是一个很强大的命令,大多数的系统信息都可以用它抓出来,当你想快捷获取系统信息又没有思路时,不妨尝试一下dumpsys,会有惊喜。
    dumpsys package能轻松获取多数的PMS数据结构的值,还能替换更新packages.xml。
    示例中也多次提到pm命令,这俩结合的话,有关PMS模块的大部分系统信息和操作都可以便捷实现,有效提高开发调试速度。

  • 相关阅读:
    Grumpy: Go 上运行 Python!
    Qt5.7.0配置选项(configure非常详细的参数)
    vs2010 2013 2015+ 必备插件精选(15个)
    solr与.net主从复制
    MVC5模板部署到mono
    solr主从复制
    CentOS 5.5安装图解教程
    VMware7安装CentOS6.5教程
    VMware安装CentOS 图文教程
    在VirtualBox下安装CentOS教程(截图版)
  • 原文地址:https://www.cnblogs.com/houser0323/p/12871195.html
Copyright © 2020-2023  润新知