Skip to content

Commit 8cf615f

Browse files
committed
modify
1 parent d8b76f8 commit 8cf615f

File tree

89 files changed

+9157
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+9157
-89
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
官方文档:https://source.android.google.cn/setup/start
2+
3+
清华源:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
4+
5+
参考:https://www.jianshu.com/p/a7b90c3b5c76
6+
7+
1. 安装 Repo
8+
9+
```shell
10+
brew install repo
11+
```
12+
13+
2. 使用每月更新的初始化包
14+
15+
```shell
16+
wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下载初始化包
17+
tar xf aosp-latest.tar
18+
cd AOSP # 解压得到的 AOSP 工程目录
19+
# 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录
20+
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-12.0.0_r28
21+
# 罗升阳 android-2.3_r1
22+
repo sync # 正常同步一遍即可得到完整目录
23+
# 或 repo sync -l 仅checkout代码
24+
```
25+
26+
3. 编译失败~
27+
28+
------------------------
29+
30+
[如何在 macOS 上安装虚拟机软件 VMware Fusion Player (个人版免费)](https://blog.csdn.net/wuyujin1997/article/details/128776714)
31+
32+
参考[VMware Fusion在M1上安装Ubuntu虚拟机](https://www.bilibili.com/video/av421832011)
33+
34+
Ubuntu arm版本镜像:https://ubuntu.com/download/server/arm
35+
36+
```shell
37+
# 可以考虑换源
38+
sudo apt-get update
39+
sudo apt install ubuntu-desktop
40+
reboot
41+
# Ubuntu 安装 VMware Tools
42+
sudo apt install open-vm-tools
43+
sudo apt install open-vm-tools-desktop
44+
```
45+
46+
```shell
47+
# 这一段是准备工作,无所谓,Ubuntu最新版已经是python3
48+
# 安装git:
49+
sudo apt install git
50+
# 安装依赖工具:
51+
sudo apt install git-core libssl-dev libffi-dev gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev libz-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip
52+
# 下载Python3:
53+
cd Downloads
54+
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
55+
# 解压Python3:
56+
tar xvf Python-3.7.1.tgz
57+
# 编译与安装Python3:
58+
./configure
59+
sudo make install
60+
# 配置update-alternatives:
61+
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
62+
sudo update-alternatives --install /usr/bin/python python python3的安装地址(/usr/local/bin/python3.7) 3(权重号)
63+
# 选择Python版本:
64+
sudo update-alternatives --config python
65+
```
66+
67+
AOSP官方地址:https://source.android.google.cn/setup/build/downloading
68+
中科大镜像:https://mirrors.ustc.edu.cn/help/aosp.html
69+
清华镜像:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
70+
71+
教程使用中科大初始同步方法 2安装:
72+
73+
```shell
74+
mkdir ~/bin
75+
cd ~/bin
76+
PATH=~/bin:$PATH
77+
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
78+
chmod a+x ~/bin/repo
79+
mkdir ~/WORKING_DIRECTORY
80+
cd ~/WORKING_DIRECTORY
81+
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest
82+
# 可以编译 Android 8
83+
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-2.3.1_r1
84+
# 使用清华源
85+
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-2.3.1_r1
86+
repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.1_r1
87+
repo sync
88+
```
89+
90+
#### 错误一
91+
92+
如果提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,把 REPO_URL 一行替换成下面的: REPO_URL = 'https://gerrit-googlesource.proxy.ustclug.org/git-repo'
93+
94+
#### 错误二
95+
96+
如果提示无法进行SSL证书校验,执行:
97+
98+
错误:error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
99+
100+
```shell
101+
git config --global http.sslverify false
102+
git config --global https.sslverify false
103+
```
104+
105+
#### 错误三
106+
107+
如果出现git身份不存在:
108+
109+
```shell
110+
git config --global user.email "[email protected]"
111+
git config --global user.name sec
112+
```
113+
114+
#### 错误四
115+
116+
ubuntu /usr/bin/env: python : no such file or directory
117+
118+
```shell
119+
whereis python3
120+
sudo ln -s /usr/bin/python3 /usr/bin/python
121+
```
122+
123+
-----------
124+
125+
------------
126+
127+
### 自定义ROM刷机实战
128+
129+
[wget 下载官方驱动](https://developers.google.cn/android/drivers),解压,chmod +x ,运行 shell 脚本
130+
131+
```shell
132+
make -j 4
133+
adb devices
134+
# 进入Bootloader模式:(解BL锁)
135+
# https://source.android.google.cn/setup/build/running 查看如何解锁引导加载程序
136+
# 可以淘宝购买已解锁的设备,或者去小米官网看如何OEM解锁
137+
adb reboot bootloader
138+
# 查看连接设备:
139+
fastboot devices
140+
# 正式刷机
141+
fastboot flashall -w
142+
```
143+
144+
```shell
145+
# 编译 Android 12 源码先设置交换空间再正常编译
146+
# 配置环境
147+
source build/envsetup.sh
148+
# 选择要编译的选项:
149+
lunch
150+
# 执行编译
151+
make -j 4
152+
# 交换空间
153+
swapon -s
154+
# 停止交换空间
155+
sudo swapoff /swapfile
156+
sudo rm /swapfile
157+
sudo fallocate -l 20G /swapfile
158+
ls -l /swapfile
159+
sudo mkswap /swapfile
160+
sudo swapon /swapfile
161+
free -m
162+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Zygote的作用:
2+
3+
1. 启动System Server
4+
2. 孵化应用进程
5+
6+
启动三段式:
7+
8+
1. 进程启动
9+
2. 准备工作
10+
3. loop
11+
12+
Zygote的启动流程:
13+
14+
1. Zygote进程是怎么启动的?
15+
16+
init.rc -> init 进程 -> Zygote
17+
18+
可以查看下启动配置和信号处理SIGCHID
19+
20+
2. Zygote进程启动之后做了什么?
21+
22+
1. Zygote的Native世界(为进入Java做准备)
23+
24+
1. 启动Android虚拟机
25+
2. 注册Android的JNI函数
26+
3. 进入Java世界
27+
28+
2. Zygote的Java世界
29+
30+
1. 加载资源 Preload Resources
31+
32+
2. 启动System Server -> fork System Server
33+
34+
3. 进入loop循环等待Socket消息
35+
36+
可以查看如何处理Socket请求
37+
38+
要注意的细节
39+
40+
1. Zygote fork要单线程
41+
2. Zygote 的跨进程通信(IPC)没有采用binder
42+
43+
两个问题
44+
45+
1. 孵化应用进程为什么不交给System Server来做,而专门设计一个Zygote
46+
2. Zygote的IPC通信机制为什么不采用binder?如果采用binder的话会有什么问题?
47+
48+
谈谈对Zygote的理解
49+
50+
1. what:Zygote的作用是什么
51+
2. how:Zygote的启动流程是什么
52+
3. why:Zygote的工作原理是什么,怎么孵化进程,怎么通信
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Android 有哪些主要的系统进程?查看 init.rc
2+
3+
1. zygote
4+
5+
1. zygote是怎么启动的
6+
7+
1. init进程fork出zygote进程
8+
2. 启动虚拟机,注册jni函数
9+
3. 预加载系统资源
10+
4. 启动SystemServer
11+
5. 进入Socket loop
12+
13+
2. zygote工作流程
14+
15+
3. SystemServer是怎么启动的
16+
17+
Zygote.forkSystemService
18+
19+
2. servicemanager
20+
21+
3. surfaceflinger
22+
23+
4. media
24+
25+
这些系统进程是怎么启动的?
26+
27+
1. 系统服务怎么发布,让应用程序可见?
28+
29+
publicBinderServices
30+
31+
2. 系统服务跑在什么线程
32+
33+
问题:
34+
35+
1. 为什么系统服务不都跑在binder线程里呢?
36+
2. 为什么系统服务不都跑在自己私有的工作线程里呢?
37+
3. 跑在binder线程和跑在工作线程,如何取舍?
38+
39+
怎么解决系统服务之间的相互依赖问题?
40+
41+
1. 分批启动
42+
43+
AMS PMS PKMS先启动
44+
45+
2. 分阶段启动
46+
47+
进程启动之后主要做了些什么事?
48+
49+
桌面的启动
50+
51+
说说Android系统的启动流程?
52+
53+
1. 首先启动zygote,再启动SystemServer,最后启动桌面(简单版本)
54+
2. zygote是怎么启动的?
55+
3. SystemServer是怎么启动的?
56+
4. 系统服务是怎么启动的?怎么解决相互依赖?桌面是怎么启动的?
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
如何使用系统服务
2+
3+
1. context.getSystemService(name)
4+
2. SYSTEM_SERVICE_FETCHERS 中查找
5+
6+
什么时候注册系统服务?
7+
8+
1. SystemServer启动
9+
1. 启动binder机制
10+
1. 打开binder驱动
11+
2. 映射内存,分配缓冲区
12+
3. 启动binder线程,进入binder loop
13+
2. 启动各类系统服务
14+
1. 注册到ServiceManager
15+
3. 进入loop循环
16+
17+
系统服务调用的基本原理
18+
19+
了解服务的注册原理
20+
21+
怎么添加一个系统服务
22+
23+
1. 为什么要添加系统服务?
24+
25+
添加系统服务的时机,加在SystemServer启动的时候
26+
27+
或者修改init.rc
28+
29+
2. 怎么样能让别人用?
30+
31+
1. 启动binder机制,可以IPC通信
32+
2. 注册开放出去
33+
34+
3. 具体有哪些事要干?
35+
36+
1. 服务端要做的事情
37+
2. 应用端要做的事情
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
启动方式上有什么区别
2+
3+
1. 系统服务在SystemServer上启动
4+
2. 应用服务由应用端发起通过AMS调用
5+
6+
注册方式上有什么区别
7+
8+
1.
9+
2. 应用服务由应用端发起通过AMS判断是否注册过,未注册会请求binder
10+
11+
使用方式上有什么区别
12+
13+
```kotlin
14+
context.getSystemService
15+
```
16+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ServiceManager启动流程是怎么样的?
2+
3+
1. 启动进程
4+
2. 启动Binder机制
5+
3. 发布自己的服务
6+
4. 等待并响应请求
7+
8+
怎么获取ServiceManager的binder对象?
9+
10+
怎么向ServiceManager添加服务?
11+
12+
```
13+
addService 函数
14+
```
15+
16+
怎么从ServiceManager获取服务?
17+
18+
```
19+
getService 函数
20+
```
21+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
**Linux下进程启动的方式**
2+
3+
1. fork 函数
4+
5+
**应用进程启动的基本流程**
6+
7+
**深入理解应用进程启动的原理**
8+
9+
1. 什么时候触发的进程启动?谁发起的?
10+
1. AMS#startProcessLocked
11+
1. 打开本地socket:openZygoteSocketIfNeeded
12+
2. 发送参数列表:zygoteSendArgsAndGetResult
13+
3. 返回创建的进程ID
14+
2. Zygote处理socket请求:runOnce 函数
15+
2. 进程是谁启动的?怎么启动的?
16+
17+
**问题:**
18+
19+
1. 为什么是Zygote来创建进程,而不是SystemServer
20+
2. AMS和Zygote为什么不用Binder通信
21+
22+
**总结:应用进程是怎么启动的?**
23+
24+
1. 应用进程是什么时候启动的?
25+
2. 由AMS向Zygote发起的,通过socket通信
26+
3. Zygote fork出应用进程,执行ActivityThread的main函数
27+
4. 进程启动之后向AMS报告,整个启动才算结束

0 commit comments

Comments
 (0)