Launcher3源码分析之启动分析

更新时间:2023-05-17 23:32:35 阅读: 评论:0

Launcher3源码分析之启动分析1、Launcher⼤体布局架构
2、Launcher3 主要⽬录解析
allapps ⽬录:主要存放主菜单界⾯相关代码。
anim⽬录:存放动画相关代码,主要是动画基类代码。
badge⽬录:主要存放图标标识相关代码,例如通知⼩圆点等
compat⽬录:主要存放解决兼容性相关的代码。
config⽬录:主要配置Launcher相关功能的宏开关,⽬前Launcher原⽣新增的功能宏开关都在这个⽬录。dragndrop⽬录:主要存放拖拽相关操作的代码
dynamicui⽬录:主要存放新增功能桌⾯主题效果跟随壁纸颜⾊⾃适应相关的代码。
graphics⽬录:主要存放处理图标⼤⼩、颜⾊、⾃适应等相关的代码
model⽬录:存放Launcher加载流程相关模块化的代码
notification⽬录:存放通知相关的代码
pageindicators⽬录:存放桌⾯页⾯指⽰器相关的代码
popu⽬录:存放长按图标显⽰弹出框相关的代码
provider⽬录:存放Launcher数据库相关的代码
qsb⽬录:存放搜索功能相关的代码
shortcuts⽬录:存放桌⾯所属应⽤某些功能的快捷图标相关的代码。
3、Launcher3 通电后启动流程分析
Launcher的启动是在ActivityManagerService中完成的
frameworks/ba/rvices/core/java/com/android/rver/am/ActivityManagerService.java
public void systemReady(final Runnable goingCallback, TimingsTraceLog traceLog) {
...
startHomeActivityLocked(currentUrId, "systemReady");
.....
}
在systemReady中会执⾏startHomeActivityLocked⽅法
boolean startHomeActivityLocked(int urId, String reason) {
if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL
&& mTopAction == null) {
// We are running in factory test mode, but unable to find中国有几个总警监
// the factory test app, so just sit around displaying the
// error message and don't try to start anything.
return fal;
}
Intent intent = getHomeIntent();
ActivityInfo aInfo = resolveActivityInfo(intent, STOCK_PM_FLAGS, urId);
if (aInfo != null) {
米黄是什么颜色
intent.tComponent(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 = getAppInfoForUr(aInfo.applicationInfo, urId);
ProcessRecord app = getProcessRecordLocked(aInfo.processName,
aInfo.applicationInfo.uid, true);
if (app == null || app.instr == null) {
intent.Flags() | Intent.FLAG_ACTIVITY_NEW_TASK);
final int resolvedUrId = UrId(aInfo.applicationInfo.uid);
// For ANR debugging to verify if the ur activity is the one that actually
/
/ launched.
final String myReason = reason + ":" + urId + ":" + resolvedUrId;
mActivityStarter.startHomeActivityLocked(intent, aInfo, myReason);
}
} el {
Slog.wtf(TAG, "No home screen found for " + intent, new Throwable());
}
return true;
}
在中间会执⾏getHomeIntent获取Intent
Intent getHomeIntent() {
Intent intent = new Intent(mTopAction, mTopData != null ? Uri.par(mTopData) : null);
intent.tComponent(mTopComponent);
intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
intent.addCategory(Intent.CATEGORY_HOME);
}
return intent;
}兰芝护肤品
这其中的mTopAction和mTopComponent,在⼯⼚模式(不是设计模式的那个,⽽是前⾯代码⾥的factory test mode,应该是⽤于⼯⼚⽣产使⽤的)下会被指定为其他内容,这个我们不需要关⼼。普通情况下就是ACTION_MAIN和null。那么category指定为CATEGORY_HOME后,查询的就是在Manifest中声明了该category的应⽤了。Launcher应⽤都会在AndroidManifest⽂件中声明 <category a
ndroid:name="android.intent.category.HOME" />。但是在这⼀步时,系统并没有直接启动Launcher3.
在Settings中的FallbackHome同样声明了CATEGORY_HOME。这个就涉及到DirectBoot模式模式
对⽐两个应⽤,Settings在AndroidManifest中声明了android:directBootAware="true",⽽Launcher没有,所以在刚开机时,只有FallbackHome这个页⾯会被检索到。在FallbackHome这个界⾯会⼀直检测当前是否已经具备唤醒正常Launcher的条件。
private void maybeFinish() {
if (getSystemService(UrManager.class).isUrUnlocked()) {
final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME);
final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
if (UrManager.isSplitSystemUr()
小学英语观课报告&& UrId() == UrHandle.USER_SYSTEM) {
// This avoids the situation where the system ur has no home activity after
加法运算定律教案// SUW and this activity continues to throw out warnings. See b/28870689.
return;
}
Log.d(TAG, "Ur unlocked but no home; let's hope someone enables one soon?");
mHandler.ndEmptyMessageDelayed(0, 500);
} el {
Log.d(TAG, "Ur unlocked and real home found; let's go!");
getSystemService(PowerManager.class).urActivity(
SystemClock.uptimeMillis(), fal);
finish();
}
}
}
当⼿机解锁了后,FallbackHome会执⾏finish,系统会再次调⽤startHomeActivityLocked,这个时候就已经可以查询到两个声明CATEGORY_HOME的activity了。但是此时依然不会有应⽤选择对话框。这个是因为FallbackHome在manifest中声明了
android:priority="-1000"(范围【-1000,1000】,值越⼤,优先级越⾼)。在PackageManagerService⾥⾯对这样的情况做了处理。这⾥可以分析⼀下PMS⾥⾯的resolveIntent来检索符合CATEGORY_HOME条件的应⽤是执⾏的逻辑。resolveIntent会调⽤
到resolveIntentInternal。
private ResolveInfo resolveIntentInternal(Intent intent, String resolvedType,
int flags, int urId, boolean resolveForStart) {
try {
if (!ists(urId)) return null;
鲁迅名言名句
final int callingUid = CallingUid();
flags = updateFlagsForResolve(flags, urId, intent, callingUid, resolveForStart);
enforceCrossUrPermission(callingUid, urId,
fal /*requireFullPermission*/, fal /*checkShell*/, "resolve intent");
final List<ResolveInfo> query = queryIntentActivitiesInternal(intent, resolvedType,
flags, callingUid, urId, resolveForStart, true /*allowDynamicSplits*/);
final ResolveInfo bestChoice =
chooBestActivity(intent, resolvedType, flags, query, urId);
return bestChoice;
旁边的英语} finally {
}
}
resolvIntentInternal中,query这个List就是符合查询条件的所有组件,在此场景下也是FallbackHome与Launcher3两个应⽤Activity。然后在chooBestActivity中,当出现⼀些优先级不同的情况时,系统会返回query List中的第⼀个元素(第⼀个元素在此情况下就是Launcher3的Activity,有兴趣的读者可以看下PMS的mResolvePrioritySorter,这⾥说明了返回List的排序规则)。
高中生社会实践活动记录表

本文发布于:2023-05-17 23:32:35,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/910215.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:相关   代码   存放   查询   功能   模式
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图