<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                1. 客戶端查詢 客戶端通過ApplicationPackageManager輸出的queryIntentActivities函數向PKMS發起一次查詢請求,代碼如下: **ApplicationPackageManager.java::queryIntentActivities** ~~~ public List<ResolveInfo>queryIntentActivities(Intent intent, int flags) { try { return mPM.queryIntentActivities( intent,//下面這句話很重要 intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags); }...... } ~~~ 如果Intent的Data包含一個URI,那么就需要查詢該URI的提供者(即ContentProvider)以取得該數據的數據類型。讀者可自行閱讀resolveTypeIfNeeded函數的代碼。 另外,flags參數目前有3個可選值,分別是MATCH_DEFAULT_ONLY、GET_INTENT_FILTERS和GET_RESOLVED_FILTER。詳細信息讀者可查詢SDK相關文檔。 下面來看PKMS對匹配查詢的處理。 2. queryIntentActivities分析 該函數代碼如下: **PacakgeManagerService.java::queryIntentActivities** ~~~ public List<ResolveInfo>queryIntentActivities(Intent intent, String resolvedType, int flags) { final ComponentName comp = intent.getComponent(); if(comp != null) { //Explicit的Intents,直接根據component得到對應的ActivityInfo final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); final ActivityInfo ai = getActivityInfo(comp, flags); if (ai != null) { final ResolveInfo ri = new ResolveInfo(); //ResovlerInfo的activityInfo指向查詢得到的ActivityInfo ri.activityInfo = ai; list.add(ri); } return list; } synchronized (mPackages) { final String pkgName = intent.getPackage(); if (pkgName == null) { //Implicit Intents,我們重點分析此中情況 return mActivities.queryIntent(intent, resolvedType, flags); } //Intent指明了PackageName,比Explicit Intents情況差一點 final PackageParser.Package pkg = mPackages.get(pkgName); if (pkg != null) { //其實是從該Package包含的Activities中進行匹配查詢 return mActivities.queryIntentForPackage(intent, resolvedType, flags, pkg.activities); } return new ArrayList<ResolveInfo>(); } } ~~~ 上邊代碼分三種情況: - 如果Intent指明了Component,則直接查詢該Component對應的ActivityInfo。 - 如果Intent指明了Package名,則根據Package名找到該Package,然后再從該Package包含的Activities中進行匹配查詢。 - 如果上面條件都不滿足,則需要在全系統范圍內進行匹配查詢,這就是queryIntent的工作。 queryIntent函數的代碼如下: ~~~ public List<ResolveInfo> queryIntent(Intentintent, String resolvedType, intflags) { mFlags =flags; //調用基類的queryIntent函數 returnsuper.queryIntent(intent, resolvedType, (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); } ~~~ **IntentResolver.java::queryIntent** ~~~ public List<R> queryIntent(Intent intent,String resolvedType, booleandefaultOnly) { Stringscheme = intent.getScheme(); ArrayList<R> finalList = new ArrayList<R>(); //最多有四輪匹配工作要做 ArrayList<F> firstTypeCut = null; ArrayList<F> secondTypeCut = null; ArrayList<F> thirdTypeCut = null; ArrayList<F> schemeCut = null; //下面將設置各輪校驗者 if(resolvedType != null) { intslashpos = resolvedType.indexOf('/'); if(slashpos > 0) { final String baseType = resolvedType.substring(0, slashpos); if (!baseType.equals("*")) { if (resolvedType.length() != slashpos+2 || resolvedType.charAt(slashpos+1) != '*') { firstTypeCut =mTypeToFilter.get(resolvedType); secondTypeCut =mWildTypeToFilter.get(baseType); }......//略去一部分內容 } } if(scheme != null) { schemeCut = mSchemeToFilter.get(scheme); } if(resolvedType == null && scheme == null && intent.getAction()!= null) { //看來action的filter優先級最低 firstTypeCut = mActionToFilter.get(intent.getAction()); } //FastImmutableArraySet是一種特殊的數據結構,用于保存該Intent中攜帶的 //Category相關的信息。 FastImmutableArraySet<String>categories = getFastIntentCategories(intent); if(firstTypeCut != null) { //匹配查詢,第一輪過關斬將 buildResolveList(intent, categories, debug, defaultOnly, resolvedType, scheme, firstTypeCut,finalList); } if(secondTypeCut != null) { buildResolveList(intent, categories, debug, defaultOnly, resolvedType, scheme, secondTypeCut, finalList); } if(thirdTypeCut != null) { buildResolveList(intent, categories, debug, defaultOnly, resolvedType, scheme, thirdTypeCut, finalList); } if(schemeCut != null) { //生成符合schemeCut條件的finalList buildResolveList(intent, categories, debug, defaultOnly, resolvedType, scheme, schemeCut, finalList); } //將匹配結果按Priority的大小排序 sortResults(finalList); returnfinalList; } ~~~ 在以上代碼中設置了最多四輪匹配關卡,然后逐一執行匹配工作。具體的匹配代碼由buildResolveList完成,無非是一項查找工作而已。此處就不再深究細節了,建議讀者在研究代碼時以目的為導向,不宜深究其中的數據結構。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看