之前写过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中InstanceState()使用详解
  2. android 建议在onPause和onStop处理的事情
  3. 好的android 相关的技术博客
  4. android 获取sim卡运营商信息
  5. android 扫描SD卡与系统文件
  6. Android开发小技巧
  7. Android(安卓)系统搜索框(有浏览记录)
  8. Android(安卓)Studio 获取数字签名信息
  9. android系统学习笔记二

随机推荐

  1. Android-SQLite3基本操作指令集合
  2. Android下pm 命令详解
  3. Android快速开发-选项卡
  4. Android成长之路-Android组件_EditView例
  5. 遇到的Android eclipse 问题
  6. 关于 Android 4.4 系统屏幕旋转调研
  7. Android按钮事件响应顺序
  8. android studio 使用入门 (快捷键等收集)
  9. Android中使用高德地图inflating class c
  10. android phone电话拨出上层java流程