分享

Android4.4 Framework分析

 quasiceo 2015-11-15

Android4.4 Framework分析——Android默认Home应用Launcher3的加载过程分析

来源:互联网作者:佚名 时间: 2015年08月08日 19:56:23
Android4.4 Framework分析——Android默认Home应用Launcher3的加载过程分析

本文主要介绍Android4.4默认Home应用Launcher3的启动过程和Launcher3的数据加载过程。Launcher的启动是开机时,ActivityManagerService准备好后开始的,下图是它的启动序列图:

\

step1,SystemServer中,ActivityManagerService准备好了。

step3,

 

     boolean resumeTopActivitiesLocked(ActivityStack targetStack, ActivityRecord target,             Bundle targetOptions) {         if (targetStack == null) {             targetStack = getFocusedStack(); //获得mHomeStack         }         boolean result = false;         for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {             final ActivityStack stack = mStacks.get(stackNdx);             if (isFrontStack(stack)) {                 if (stack == targetStack) {                     result = stack.resumeTopActivityLocked(target, targetOptions);                 } else {                     stack.resumeTopActivityLocked(null);                 }             }         }         return result;     }

mStacks中已经添加过mHomeStack,mStacks的内容介绍请查看 Android4.4 Framework分析——ActivityManagerService的启动和对Activity的管理 ,目前mStacks中只有mHomeStack这个ActivityStacK。

 

step6,

 

    boolean startHomeActivityLocked(int userId) {         if (mHeadless) {             // Added because none of the other calls to ensureBootCompleted seem to fire             // when running headless.             ensureBootCompleted();             return false;         }         Intent intent = getHomeIntent(); //HOME intent         ActivityInfo aInfo =             resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);//查找home应用信息         if (aInfo != null) {             intent.setComponent(new ComponentName(                     aInfo.applicationInfo.packageName, aInfo.name));             // Don't do this if the home app is currently being             // instrumented.             aInfo = new ActivityInfo(aInfo);             aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId);             ProcessRecord app = getProcessRecordLocked(aInfo.processName,                     aInfo.applicationInfo.uid, true);//home应用未启动,返回null             if (app == null || app.instrumentationClass == null) {                 intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);                 mStackSupervisor.startHomeActivity(intent, aInfo); //step7             }         }          return true;     }

     Intent getHomeIntent() {         Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null);         intent.setComponent(mTopComponent);         if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {             intent.addCategory(Intent.CATEGORY_HOME);//Home应用的标志         }         return intent;     }

step7~step10,Activity的启动过程参照Android4.4 Framework分析——Launcher中启动应用程序(startActivity)的过程

 

的step14之后的过程。

step11~step14,开始异步加载应用图标,工作线程sWorkerThread。

step15~step20,加载workspace的图标,step16读取LauncherProvider的Favorites数据,favorites表的数据是Launcher数据库创建时从default_workspace.xml解析读取的。step18绑定图标信息。

step22,睡眠等待空闲进程,然后加载主菜单的所有app图标。

step23,从睡眠中醒来,准备加载所有app图标,包括widget等。

step24,

 

         private void loadAllApps() {             final long loadTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;             .....             final PackageManager packageManager = mContext.getPackageManager();             final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); //在PackageManagerService查询所有要显示在桌面上的app             mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);              // Clear the list of apps             mBgAllAppsList.clear();              // Query for the set of apps             final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;             List apps = packageManager.queryIntentActivities(mainIntent, 0);             if (DEBUG_LOADERS) {                 Log.d(TAG, queryIntentActivities took                          + (SystemClock.uptimeMillis()-qiaTime) + ms);                 Log.d(TAG, queryIntentActivities got  + apps.size() +  apps);             }             // Fail if we don't have any apps             if (apps == null || apps.isEmpty()) {                 return;             }             // Sort the applications by name             final long sortTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;             Collections.sort(apps,                     new LauncherModel.ShortcutNameComparator(packageManager, mLabelCache));//按应用名称排序              // Create the ApplicationInfos             for (int i = 0; i < apps.size(); i++) {                 ResolveInfo app = apps.get(i);                 // This builds the icon bitmaps.                 mBgAllAppsList.add(new AppInfo(packageManager, app,                         mIconCache, mLabelCache));             }              // Huh? Shouldn't this be inside the Runnable below?             final ArrayList added = mBgAllAppsList.added;             mBgAllAppsList.added = new ArrayList();              // Post callback on main thread             mHandler.post(new Runnable() {                 public void run() {                     final long bindTime = SystemClock.uptimeMillis();                     final Callbacks callbacks = tryGetCallbacks(oldCallbacks);                     if (callbacks != null) {                         callbacks.bindAllApplications(added); //step26,绑定                         if (DEBUG_LOADERS) {                             Log.d(TAG, bound  + added.size() +  apps in                                  + (SystemClock.uptimeMillis() - bindTime) + ms);                         }                     } else {                         Log.i(TAG, not binding apps: no Launcher activity);                     }                 }             });         }


 

 

 

 

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多