yuandaimaahao / androidframeworktutorial Goto Github PK
View Code? Open in Web Editor NEW写给应用开发的 Android Framework 教程
License: Apache License 2.0
写给应用开发的 Android Framework 教程
License: Apache License 2.0
Android 11 应用层 binder 改用 libbiner 库实现,改用 C++ 语言,更复杂,不易学习。
Android 10 是最后一个使用 linux 系统 Api 使用 binder 的版本,更适合初学者学习。
开发机器需要什么样的配置?有推荐的吗?
大家有没有碰到 android.bp文件里引入aar文件,aar文件里包含so库,编译时报找不到so库的情况(解压过aar里面确实有so文件)?
aar声明 :
android_library_import {
name: "lib-voiceAssistant",
aars: ["app/libs/voiceAssistant-debug.aar"],
sdk_version: "current",
}
aar引入:
android_app {
static_libs: ["lib-voiceAssistant"]
}
把开发者模式里window animation scale设置为0就不会了
感觉就是这个window animation scale引起的,系统叫我们应用层屏蔽掉,感觉应用层做不到
搜了下是windowManagerService处理的
app开发,跟着学到什么程度可以找到fw工作
`static struct binder_thread *binder_get_thread_ilocked(
struct binder_proc *proc, struct binder_thread *new_thread)
{
struct binder_thread *thread = NULL;
struct rb_node *parent = NULL;
struct rb_node **p = &proc->threads.rb_node;
while (*p) {
parent = *p;
thread = rb_entry(parent, struct binder_thread, rb_node);
if (current->pid < thread->pid)
p = &(*p)->rb_left;
else if (current->pid > thread->pid)
p = &(*p)->rb_right;
else
return thread;
}
if (!new_thread)
return NULL;
thread = new_thread;
binder_stats_created(BINDER_STAT_THREAD);
thread->proc = proc;
thread->pid = current->pid;
get_task_struct(current);
thread->task = current;
atomic_set(&thread->tmp_ref, 0);
init_waitqueue_head(&thread->wait);
INIT_LIST_HEAD(&thread->todo);
rb_link_node(&thread->rb_node, parent, p);
rb_insert_color(&thread->rb_node, &proc->threads);
thread->looper_need_return = true;
thread->return_error.work.type = BINDER_WORK_RETURN_ERROR;
thread->return_error.cmd = BR_OK;
thread->reply_error.work.type = BINDER_WORK_RETURN_ERROR;
thread->reply_error.cmd = BR_OK;
spin_lock_init(&thread->prio_lock);
thread->prio_state = BINDER_PRIO_SET;
INIT_LIST_HEAD(&new_thread->waiting_thread_node);
return thread;
}`
以上代码中可以看到赋值语句thread->pid = current->pid;
#define get_current() (current_thread_info()->task)
#define current get_current()
thread->pid拿到的其实是当前线程对应的 task_struct中的pid,这个pid其实是线程id,不同线程的id是不同的
配置好的 vmware 17 虚拟机:
链接:https://pan.baidu.com/s/1_XHOpEr7egN1cQs1uSZ2ug
提取码:1234
下载下来,使用7zip解压,vmware17打开,根据自己电脑情况调整虚拟机的内存和cpu核心数
账号: android
密码: android
源码路径:~/aosp/android10_r41
进入源码路径:
source build/envsetup.sh
lunch aosp_x86_64-eng
m
emulator
就可以看到启动的模拟器了
SeAndroid 中有个很坑的问题:
file_contexts 文件最后一行必须是空格,否则编译不过,会报类似下面的错误:
file_contexts.device.tmp has invalid file type
dipper:/ # echo $BOOTCLASSPATH
/apex/com.android.runtime/javalib/core-oj.jar:/apex/com.android.runtime/javalib/core-libart.jar:/apex/com.android.runtime/javalib/okhttp.jar:/apex/com.android.runtime/javalib/bouncycastle.jar:/apex/com.android.runtime/javalib/apache-xml.jar:/system/framework/framework.jar:/system/framework/ext.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/android.test.base.jar:/apex/com.android.conscrypt/javalib/conscrypt.jar:/apex/com.android.media/javalib/updatable-media.jar
这些就是bootjar,现在还没有我们自己定制的jar
假设我们的包名是api.cat.xxx
as中创建我们的模块,其他项目结构也行。
当然我的业务代码肯定比这个多,但是都是在这个包名下就行,因为要加入白名单。
开始预置
\192.168.216.128\aosp\aosp\android-10.0.0_r41\device\google\crosshatch\blueline
在p3产品目录下增加一个文件夹api.cat
把业务代码复制到这个目录下。
不要直接创建bp文件,从其他地方找一个bp复制过来,修改里面的json:
bp文件配置:
预置到product分区用product_specific: true,不加就是system分区,开始的时候参考豪哥文章加入这个配置,导致预置到了product分区了。
java_library {
name: "api.cat",
installable: true,
srcs: ["**/*.java"],
sdk_version: "current"
}
代码配置完成,需要把新增的模块加入到白名单中:
在\192.168.216.128\aosp\aosp\android-10.0.0_r41\device\google\crosshatch目录找找到device.mk
找到节点PRODUCT_PACKAGES加入
PRODUCT_PACKAGES += \
messaging \
api.cat
PRODUCT_BOOT_JARS += \
api.cat \
PRODUCT_ARTIFACT_PATH_REQUIREMENT_WHITELIST += \
system/framework/api.cat.jar
配置包名白名单\192.168.216.128\aosp\aosp\android-10.0.0_r41\build\core\tasks\check_boot_jars\package_whitelist.txt中增加
api\.cat
api\.cat\..*
刷机完成后进入shell查询环境:
dipper:/ # echo $BOOTCLASSPATH
/apex/com.android.runtime/javalib/core-oj.jar:/apex/com.android.runtime/javalib/core-libart.jar:/apex/com.android.runtime/javalib/okhttp.jar:/apex/com.android.runtime/javalib/bouncycastle.jar:/apex/com.android.runtime/javalib/apache-xml.jar:/system/framework/framework.jar:/system/framework/ext.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/android.test.base.jar:/system/framework/api.cat.jar:/apex/com.android.conscrypt/javalib/conscrypt.jar:/apex/com.android.media/javalib/updatable-media.jar
#这个时候进入system/framework中也能找到jar
dipper:/system/framework # ls -l | grep cat
-rw-r--r-- 1 root root 882 2023-04-28 20:30 api.cat.jar
非常感谢豪哥的指导~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.