V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kafukwen
V2EX  ›  Android

PackageManagerService.queryIntentReceivers 方法查询 intent 对应的静态广播,请问其中这个 reader synchronized 部分是干什么的

  •  
  •   kafukwen · 2019-03-20 16:49:14 +08:00 · 8454 次点击
    这是一个创建于 2111 天前的主题,其中的信息可能已经有所发展或是发生改变。
    private @NonNull List<ResolveInfo> queryIntentReceiversInternal(Intent intent,
                String resolvedType, int flags, int userId) {
            if (!sUserManager.exists(userId)) return Collections.emptyList();
            flags = updateFlagsForResolve(flags, userId, intent);
            ComponentName comp = intent.getComponent();
            if (comp == null) {
                if (intent.getSelector() != null) {
                    intent = intent.getSelector();
                    comp = intent.getComponent();
                }
            }
            if (comp != null) {
                List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
                ActivityInfo ai = getReceiverInfo(comp, flags, userId);
                if (ai != null) {
                    ResolveInfo ri = new ResolveInfo();
                    ri.activityInfo = ai;
                    list.add(ri);
                }
                return list;
            }
    
            // reader
            synchronized (mPackages) {
                String pkgName = intent.getPackage();
                if (pkgName == null) {
                    return mReceivers.queryIntent(intent, resolvedType, flags, userId);
                }
                final PackageParser.Package pkg = mPackages.get(pkgName);
                if (pkg != null) {
                    return mReceivers.queryIntentForPackage(intent, resolvedType, flags, pkg.receivers,
                            userId);
                }
                return Collections.emptyList();
            }
        }
    
    1 条回复    2019-03-20 17:12:07 +08:00
    cxtrinityy
        1
    cxtrinityy  
       2019-03-20 17:12:07 +08:00
    getReceiverInfo()是从 mSettings 里查找,未找到就从 mReceivers 查找呗,查找源不通而已
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2527 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 15:30 · PVG 23:30 · LAX 07:30 · JFK 10:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.