Q
最近遇到一个问题:多个应用打不开,闪退。
A
调查发现闪退的应用都在首屏加载了webview,而在android p上webview的渲染是在另外一个进程上进行的,进程名字类似webview:sandboxed_process0,这个进程是由webview_zygote这样一个进程fork出来的,而webview_zygote由于缺少权限runtime崩溃,从而导致webview加载失败,应用闪退。
S
增加相应权限
webview_zygote.te
allow webview_zygote ion_device:chr_file r_file_perms;
简单调查了下加载webview的应用,随android版本升级进程关系的变化
1.在android o以前
webview运行在app进程里
2.android o
webview运行在单独的进程里com.android.webview:sandboxed_process(n)
webview进程是由webview_zygote进程fork出来的
而webview_zygote进程是由1号进程init进程forkc出来的
能看出不管应用进程运行时是32bit还是64bit,wevview进程的运行时应该是32bit,因为webview_zygote是32bit的,它只能fork 32bit进程出来,生不出别的孩子
可以看到32bit,64bit运行时应用的祖宗zygote和zygote64也是init进程fork出来的
USER PID PPID VSZ RSS WCHAN ADDR S NAME
root 1 0 60588 1576 0 0 S init
root 983 1 4287904 19896 0 0 S zygote64
root 984 1 1618076 18836 0 0 S zygote
webview_zygote 1943 1 1396420 11180 0 0 S webview_zygote32
u0_i188 3756 1943 1474636 20108 0 0 S com.android.webview:sandboxe
u0_i185 29184 1943 1474636 18096 0 0 S com.android.webview:sandboxe
3.android p总体上和android o一样,但是有些区别
webview运行在单独的进程里com.android.webview:sandboxed_process(n)
webview进程是由webview_zygote进程fork出来的
这里稍有不同webview_zygote进程是由zygote fork出来的,当然它也只能是32bit的运行时,它儿子孙子都是
USER PID PPID VSZ RSS WCHAN ADDR S NAME
root 1 0 60588 1576 0 0 S init
root 572 1 4316640 133916 poll_schedule_timeout 0 S zygote64
root 573 1 1628984 120228 poll_schedule_timeout 0 S zygote
webview_zygote 2003 573 1631044 58384 poll_schedule_timeout 0 S webview_zygote
u0_i1 6247 2003 1181360 18528 ep_poll 0 S com.android.webview:sandboxed_process0
4.不但如此android o和android p编译链接关系上有不同
zygote,webview_zygote编译链接关系发生了变化,链接了不同的库
问题错误栈
I WebViewFactory: Loading com.android.webview version 66.0.3359.158 (code 336015855)
W cr_ChildProcLH: Create a new ChildConnectionAllocator with package name = com.android.webview, sandboxed = true
W libprocessgroup: kill(-4305, 9) failed: No such process
I libprocessgroup: Successfully killed process cgroup uid 10064 pid 4305 in 95ms
I cr_BrowserStartup: Initializing chromium process, singleProcess=false
I cr_base : Android Locale: en_US requires .pak files: []
E webview_zygote: Unable to restat fd 28: Permission denied
F webview_zygote: jni_internal.cc:616] JNI FatalError called: (com.android.webview:sandboxed_process0) Unable to stat 28
W webview_zygote: type=1400 audit(0.0:27): avc: denied { getattr } for path="/dev/ion" dev="tmpfs" ino=12718 scontext=u:r:webview_zygote:s0 tcontext=u:object_r:ion_device:s0 tclass=chr_file permissive=0
W webview_zygote: type=1400 audit(0.0:28): avc: denied { getattr } for path="/dev/ion" dev="tmpfs" ino=12718 scontext=u:r:webview_zygote:s0 tcontext=u:object_r:ion_device:s0 tclass=chr_file permissive=0
W webview_zygote: type=1400 audit(0.0:29): avc: denied { read } for name="app_process32" dev="mmcblk0p25" ino=467 scontext=u:r:webview_zygote:s0 tcontext=u:object_r:zygote_exec:s0 tclass=file permissive=0
F webview_zygote: runtime.cc:558] Runtime aborting...
F webview_zygote: runtime.cc:558] Dumping all threads without appropriate locks held: thread list lock mutator lock
F webview_zygote: runtime.cc:558] All threads:
F webview_zygote: runtime.cc:558] DALVIK THREADS (1):
F webview_zygote: runtime.cc:558] "main" prio=5 tid=1 Runnable
F webview_zygote: runtime.cc:558] | group="" sCount=0 dsCount=0 flags=0 obj=0x74d7cf48 self=0xf2f73000
F webview_zygote: runtime.cc:558] | sysTid=2332 nice=0 cgrp=default sched=0/0 handle=0xf6b54494
F webview_zygote: runtime.cc:558] | state=R schedstat=( 80557599 15727867 94 ) utm=5 stm=3 core=5 HZ=100
F webview_zygote: runtime.cc:558] | stack=0xff72b000-0xff72d000 stackSize=8MB
F webview_zygote: runtime.cc:558] | held mutexes= "abort lock" "mutator lock"(shared held)
F webview_zygote: runtime.cc:558] native: #00 pc 002d975f /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream>&, int, BacktraceMap, char const, art::ArtMethod, void, bool)+134)
F webview_zygote: runtime.cc:558] native: #01 pc 0036e98b /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream>&, bool, BacktraceMap*, bool) const+210)
F webview_zygote: runtime.cc:558] native: #02 pc 0036b143 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream>&, bool, BacktraceMap*, bool) const+34)
F webview_zygote: runtime.cc:558] native: #03 pc 00383df9 /system/lib/libart.so (art::DumpCheckpoint::Run(art::Thread*)+624)
F webview_zygote: runtime.cc:558] native: #04 pc 0037e0df /system/lib/libart.so (art::ThreadList::RunCheckpoint(art::Closure, art::Closure)+314)
F webview_zygote: runtime.cc:558] native: #05 pc 0037d7d7 /system/lib/libart.so (art::ThreadList::Dump(std::__1::basic_ostream>&, bool)+758)
F webview_zygote: runtime.cc:558] native: #06 pc 0034d8fb /system/lib/libart.so (art::Runtime::Abort(char const*)+314)
F webview_zygote: runtime.cc:558] native: #07 pc 000071b3 /system/lib/libbase.so (android::base::LogMessage::~LogMessage()&