之前写过2篇关于PackageManager的学习笔记


Android中PackageManager学习笔记(1)-ApplicationInfo

Android中PackageManager学习笔记(2)-PackageInfo


今天继续学习PackageManager中PackageParser这个类。


PackageParser


该类存在于android.content.pm包中,官方文档并没有放出该类,所以只能查看源码


packageparser源码网站


PackageParser为PackageManager专门解析android配置档文件AndroidManifest.xml所建立的。里面的一系列方法都是通过XMLPullParser工具解析该xml文件。由于方法太多,主要对里面的内部类做一些简单的介绍,起一个抛砖的作用。首先进官网查看一下我们的主配置文件含有哪些节点?然后讲解就会很容易了。



public final static class  Activity extends Component


Activity节点信息


public final static class ActivityIntentInfo extends IntentInfo


activity中intent节点信息


public static class Component


保存所有组件,activity,provider,receiver都属于组件


public final static class  Instrumentation extends Component 


保存instrumentation节点信息



public static class IntentInfo extends IntentFilter


保存Intent的信息


public static class  NewPermissionInfo


新权限?信息。sdk版本号,文件版本号,权限名称


public final static class Package


保存了该包中所有文件节点信息


 public final static class Package {        public String packageName;        // For now we only support one application per package.        public final ApplicationInfo applicationInfo = new ApplicationInfo();        public final ArrayList permissions = new ArrayList(0);        public final ArrayList permissionGroups = new ArrayList(0);        public final ArrayList activities = new ArrayList(0);        public final ArrayList receivers = new ArrayList(0);        public final ArrayList providers = new ArrayList(0);        public final ArrayList services = new ArrayList(0);        public final ArrayList instrumentation = new ArrayList(0);        public final ArrayList requestedPermissions = new ArrayList();        public final ArrayList requestedPermissionsRequired = new ArrayList();        public ArrayList protectedBroadcasts;        public ArrayList libraryNames = null;        public ArrayList usesLibraries = null;        public ArrayList usesOptionalLibraries = null;        public String[] usesLibraryFiles = null;        public ArrayList preferredActivityFilters = null;        public ArrayList mOriginalPackages = null;        public String mRealPackage = null;        public ArrayList mAdoptPermissions = null;                // We store the application meta-data independently to avoid multiple unwanted references        public Bundle mAppMetaData = null;        // If this is a 3rd party app, this is the path of the zip file.        public String mPath;        // The version code declared for this package.        public int mVersionCode;                // The version name declared for this package.        public String mVersionName;                // The shared user id that this package wants to use.        public String mSharedUserId;        // The shared user label that this package wants to use.        public int mSharedUserLabel;        // Signatures that were read from the package.        public Signature mSignatures[];        // For use by package manager service for quick lookup of        // preferred up order.        public int mPreferredOrder = 0;        // For use by the package manager to keep track of the path to the        // file an app came from.        public String mScanPath;                // For use by package manager to keep track of where it has done dexopt.        public boolean mDidDexOpt;                // // User set enabled state.        // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;        //        // // Whether the package has been stopped.        // public boolean mSetStopped = false;        // Additional data supplied by callers.        public Object mExtras;        // Whether an operation is currently pending on this package        public boolean mOperationPending;        /*         *  Applications hardware preferences         */        public final ArrayList configPreferences =                new ArrayList();        /*         *  Applications requested features         */        public ArrayList reqFeatures = null;        public int installLocation;        /* An app that's required for all users and cannot be uninstalled for a user */        public boolean mRequiredForAllUsers;        /* The restricted account authenticator type that is used by this application */        public String mRestrictedAccountType;        /* The required account type without which this application will not function */        public String mRequiredAccountType;        /**         * Digest suitable for comparing whether this package's manifest is the         * same as another.         */        public ManifestDigest manifestDigest;        /**         * Data used to feed the KeySetManager         */        public Set mSigningKeys;        public Map> mKeySetMapping;        public Package(String _name) {            packageName = _name;            applicationInfo.packageName = _name;            applicationInfo.uid = -1;        }        public void setPackageName(String newName) {            packageName = newName;            applicationInfo.packageName = newName;            for (int i=permissions.size()-1; i>=0; i--) {                permissions.get(i).setPackageName(newName);            }            for (int i=permissionGroups.size()-1; i>=0; i--) {                permissionGroups.get(i).setPackageName(newName);            }            for (int i=activities.size()-1; i>=0; i--) {                activities.get(i).setPackageName(newName);            }            for (int i=receivers.size()-1; i>=0; i--) {                receivers.get(i).setPackageName(newName);            }            for (int i=providers.size()-1; i>=0; i--) {                providers.get(i).setPackageName(newName);            }            for (int i=services.size()-1; i>=0; i--) {                services.get(i).setPackageName(newName);            }            for (int i=instrumentation.size()-1; i>=0; i--) {                instrumentation.get(i).setPackageName(newName);            }        }        public boolean hasComponentClassName(String name) {            for (int i=activities.size()-1; i>=0; i--) {                if (name.equals(activities.get(i).className)) {                    return true;                }            }            for (int i=receivers.size()-1; i>=0; i--) {                if (name.equals(receivers.get(i).className)) {                    return true;                }            }            for (int i=providers.size()-1; i>=0; i--) {                if (name.equals(providers.get(i).className)) {                    return true;                }            }            for (int i=services.size()-1; i>=0; i--) {                if (name.equals(services.get(i).className)) {                    return true;                }            }            for (int i=instrumentation.size()-1; i>=0; i--) {                if (name.equals(instrumentation.get(i).className)) {                    return true;                }            }            return false;        }        public String toString() {            return "Package{"                + Integer.toHexString(System.identityHashCode(this))                + " " + packageName + "}";        }    }


public static class PackageLite 

节点信息

            . . .    


static class ParseComponentArgs extends ParsePackageItemArgs

ParsePackageItemArgs


自己创造,保存一些ParsePackage自身用于唯一标识的信息


public final static class Permission extends Component


保存permission节点信息


public final static class PermissionGroup extends Component 


保存节点信息


public final static class  Provider extends Component


保存provider节点信息


public static final class ProviderIntentInfo extends IntentInfo


保存provider中的intent节点信息


public final static class  Service extends Component


保存service标签的信息


public final static class  ServiceIntentInfo extends IntentInfo


保存Service标签中的intent属性节点信息


public static class SplitPermissionInfo


将权限信息保存在String数组中


  public static class SplitPermissionInfo {        public final String rootPerm;        public final String[] newPerms;        public final int targetSdk;        public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {            this.rootPerm = rootPerm;            this.newPerms = newPerms;            this.targetSdk = targetSdk;        }    }


                                

更多相关文章

  1. Android studio 提取文件指定字符串
  2. Android http协议实现文件下载
  3. android 扫描SD卡与系统文件
  4. android 获取sim卡运营商信息
  5. Android sdcard文件读写操作
  6. android 调用 SharedPreferences 实现偏好信息设置
  7. android的文件读写
  8. Android Android.mk 文件一点感悟

随机推荐

  1. XML模式-详细介绍DocBook XML
  2. xml解析java基础的详细介绍
  3. 使用XML将机器内码转换为人们能够理解的
  4. XML模式-RDF的详细介绍
  5. XML模式-vCard结构详解
  6. 具体介绍历数Firefox2.0对XML处理的改进
  7. 详细介绍(javascript+asp)XML、XSL转换输
  8. XML模式-WSD的描述
  9. 简单介绍XML模式相关常用的缩写词
  10. 在XML模式中扩展枚举列表的示例代码详解