1、Android10 源码编译相关问题
2、Android10 系统进程Zygote启动
3、Android10 系统进程SystemServer
4、Android10 launcher启动流程
5、Android10 系统发送开机广播时机
6、Android10 AppComponentFactory源码梳理
7、Android10 InputManagerService事件输入输出
8、Android10 InputManagerService本地实现
9、Android10 SystemUI系统手势导航
从Android9开始,android系统就添加了系统导航手势,对于现在高版本的手机,有些系统默认就是开启导航手势的,有些还是沿用以前导航栏,但是也是可以在设置中开启导航手势,导航栏会自动消失,这篇文章主要讲解的是系统导航收拾是如何实现的。
对于系统导航手势的实现,android10还是在SystemUI中实现的,在以后的版本中可能就是在Launcher3中,SystemUI是一个系统应用,在SystemServer中启动,先来看下是如何启动的:
private static void startSystemUi(Context context, WindowManagerService windowManager) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.systemui",
"com.android.systemui.SystemUIService"));
intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
//Slog.d(TAG, "Starting service: " + intent);
context.startServiceAsUser(intent, UserHandle.SYSTEM);
windowManager.onSystemUiStarted();
}
通过开启SystemUIService服务来拉起SystemUI,这里就直接来看下SystemUIService:
public class SystemUIService extends Service {
@Override
public void onCreate() {
super.onCreate();
((SystemUIApplication) getApplication()).startServicesIfNeeded();
... ...
}
}
没做啥,就是继续调用SystemUIApplication.startServicesIfNeeded(),在说这个方法前,可以先了解下Android10 AppComponentFactory源码梳理,这里先来看下Manifest中对application的配置:
<application
android:name=".SystemUIApplication"
... ...
tools:replace="android:appComponentFactory"
android:appComponentFactory=".SystemUIAppComponentFactory">
这里用SystemUIAppComponentFactory替换掉了android系统中默认的appComponentFactory,先来看看SystemUIAppComponentFactory:
public class SystemUIAppComponentFactory extends CoreComponentFactory {
@Inject
public ContextComponentHelper mComponentHelper;
public SystemUIAppComponentFactory() {
super();
}
@Override
public Application instantiateApplication(ClassLoader cl, String className)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
Application app = super.instantiateApplication(cl, className);
if (app instanceof SystemUIApplication) {
((SystemUIApplication) app).setContextAvailableCallback(
context -> {
SystemUIFactory.createFromConfig(context);
SystemUIFactory.getInstance().getRootComponent().inject(
SystemUIAppComponentFactory.this);
}
);
}
return app;
}
}
根据上面的配置,这里的if语句为true,会执行下面的回调语句,这里主要说下这个回调语句是做什么的,在SystemUI应用中,使用了Dagger对很多的实例进行初始化,这里就是对Dagger注入对象进行初始化,这里对appComponentFactory的作用就先到这了,接着上面的开启的服务,就进入到SystemUIApplication.startServicesIfNeeded():
public class SystemUIApplication extends Application implements SysUiServiceProvider {
public static final String TAG = "SystemUIService";
private static final boolean DEBUG = false;
/**
* Hold a reference on the stuff we start.
*/
//预先定义的SystemUI组件服务
private SystemUI[] mServices;
private boolean mServicesStarted;
private boolean mBootCompleted;
//SystemUI组件集合
private final Map<Class<?>, Object> mComponents = new HashMap<>();
private ContextAvailableCallback mContextAvailableCallback;
public SystemUIApplication() {
super();
Log.v(TAG, "SystemUIApplication constructed.");
}
@Override
public void onCreate() {
super.onCreate();
... ...
//在SystemUIAppComponentFactory中设置的回调立马就在这调用了,感觉是多此一举
//在android 11中就没有通过这个回调了,而是直接在这里初始化的Dagger
mContextAvailableCallback.onContextAvailable(this);
... ...
}
/**
* Makes sure that all the SystemUI services are running. If they are already running, this is a
* no-op. This is needed to conditinally start all the services, as we only need to have it in
* the main process.
* <p>This method must only be called from the main thread.</p>
*/
//开启SystemUI组件服务,组件服务预先定义在config_systemUIServiceComponents
public void startServicesIfNeeded() {
String[] names = getResources().getStringArray(R.array.config_systemUIServiceComponents);
startServicesIfNeeded(/* metricsPrefix= */ "StartServices", names);
}
private void startServicesIfNeeded(String metricsPrefix, String[] services) {
//服务已经开始就直接返回
if (mServicesStarted) {
return;
}
mServices = new SystemUI[services.length];
... ...