Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
Booster
提交
00486b79
B
Booster
项目概览
DiDi
/
Booster
通知
31
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Booster
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
00486b79
编写于
6月 04, 2019
作者:
N
neighbWang
提交者:
Johnson Lee
6月 04, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WebView optimization
上级
3cc21ae1
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
164 addition
and
0 deletion
+164
-0
booster-android-instrument-webview/build.gradle
booster-android-instrument-webview/build.gradle
+7
-0
booster-android-instrument-webview/src/main/java/com/didiglobal/booster/instrument/ShadowWebView.java
...java/com/didiglobal/booster/instrument/ShadowWebView.java
+41
-0
booster-transform-all/build.gradle
booster-transform-all/build.gradle
+1
-0
booster-transform-webview/build.gradle
booster-transform-webview/build.gradle
+10
-0
booster-transform-webview/src/main/kotlin/com/didiglobal/booster/transform/webview/WebViewTransformer.kt
...idiglobal/booster/transform/webview/WebViewTransformer.kt
+83
-0
booster-transform-webview/src/main/kotlin/com/didiglobal/booster/transform/webview/WebViewVariantProcessor.kt
...obal/booster/transform/webview/WebViewVariantProcessor.kt
+20
-0
settings.gradle
settings.gradle
+2
-0
未找到文件。
booster-android-instrument-webview/build.gradle
0 → 100644
浏览文件 @
00486b79
sourceCompatibility
=
JavaVersion
.
VERSION_1_7
targetCompatibility
=
JavaVersion
.
VERSION_1_7
dependencies
{
compileOnly
project
(
':booster-android-api'
)
compile
project
(
':booster-android-instrument'
)
}
\ No newline at end of file
booster-android-instrument-webview/src/main/java/com/didiglobal/booster/instrument/ShadowWebView.java
0 → 100644
浏览文件 @
00486b79
package
com.didiglobal.booster.instrument
;
import
android.app.Application
;
import
android.os.MessageQueue
;
import
android.os.SystemClock
;
import
android.util.Log
;
import
static
com
.
didiglobal
.
booster
.
android
.
bugfix
.
Constants
.
TAG
;
import
static
com
.
didiglobal
.
booster
.
android
.
bugfix
.
Reflection
.
invokeMethod
;
import
static
com
.
didiglobal
.
booster
.
android
.
bugfix
.
Reflection
.
invokeStaticMethod
;
/**
* @author neighbWang
*/
public
class
ShadowWebView
{
public
static
void
preloadWebView
(
final
Application
app
)
{
try
{
app
.
getMainLooper
().
getQueue
().
addIdleHandler
(
new
MessageQueue
.
IdleHandler
()
{
@Override
public
boolean
queueIdle
()
{
startChromiumEngine
();
return
false
;
}
});
}
catch
(
final
Throwable
t
)
{
Log
.
e
(
TAG
,
"Oops!"
,
t
);
}
}
private
static
void
startChromiumEngine
()
{
try
{
final
long
t0
=
SystemClock
.
uptimeMillis
();
final
Object
provider
=
invokeStaticMethod
(
Class
.
forName
(
"android.webkit.WebViewFactory"
),
"getProvider"
);
invokeMethod
(
provider
,
"startYourEngines"
,
new
Class
[]{
boolean
.
class
},
new
Object
[]{
true
});
Log
.
i
(
TAG
,
"Start chromium engine complete: "
+
(
SystemClock
.
uptimeMillis
()
-
t0
)
+
" ms"
);
}
catch
(
final
Throwable
t
)
{
Log
.
e
(
TAG
,
"Start chromium engine error"
,
t
);
}
}
}
\ No newline at end of file
booster-transform-all/build.gradle
浏览文件 @
00486b79
...
...
@@ -6,4 +6,5 @@ dependencies {
compile
project
(
':booster-transform-toast'
)
compile
project
(
':booster-transform-usage'
)
compile
project
(
':booster-transform-media-player'
)
compile
project
(
':booster-transform-webview'
)
}
booster-transform-webview/build.gradle
0 → 100644
浏览文件 @
00486b79
apply
from:
'../gradle/booster.gradle'
dependencies
{
kapt
"com.google.auto.service:auto-service:1.0-rc4"
implementation
project
(
':booster-android-gradle-api'
)
implementation
project
(
':booster-task-spi'
)
implementation
project
(
':booster-transform-asm'
)
compileOnly
'com.android.tools.build:gradle:3.0.0'
testCompileOnly
'com.android.tools.build:gradle:3.0.0'
}
booster-transform-webview/src/main/kotlin/com/didiglobal/booster/transform/webview/WebViewTransformer.kt
0 → 100644
浏览文件 @
00486b79
package
com.didiglobal.booster.transform.webview
import
com.didiglobal.booster.kotlinx.file
import
com.didiglobal.booster.kotlinx.touch
import
com.didiglobal.booster.transform.ArtifactManager
import
com.didiglobal.booster.transform.TransformContext
import
com.didiglobal.booster.transform.asm.ClassTransformer
import
com.didiglobal.booster.transform.asm.className
import
com.didiglobal.booster.transform.asm.findAll
import
com.didiglobal.booster.util.ComponentHandler
import
com.google.auto.service.AutoService
import
org.objectweb.asm.Opcodes.ACC_PUBLIC
import
org.objectweb.asm.Opcodes.ALOAD
import
org.objectweb.asm.Opcodes.ATHROW
import
org.objectweb.asm.Opcodes.INVOKESPECIAL
import
org.objectweb.asm.Opcodes.INVOKESTATIC
import
org.objectweb.asm.Opcodes.RETURN
import
org.objectweb.asm.tree.ClassNode
import
org.objectweb.asm.tree.InsnList
import
org.objectweb.asm.tree.InsnNode
import
org.objectweb.asm.tree.MethodInsnNode
import
org.objectweb.asm.tree.MethodNode
import
org.objectweb.asm.tree.VarInsnNode
import
java.io.PrintWriter
import
javax.xml.parsers.SAXParserFactory
/**
* Represents a class transformer for application optimization
*
* @author neighbWang
*/
@AutoService
(
ClassTransformer
::
class
)
class
WebViewTransformer
:
ClassTransformer
{
private
lateinit
var
logger
:
PrintWriter
private
val
applications
=
mutableSetOf
<
String
>()
override
fun
onPreTransform
(
context
:
TransformContext
)
{
val
parser
=
SAXParserFactory
.
newInstance
().
newSAXParser
()
context
.
artifacts
.
get
(
ArtifactManager
.
MERGED_MANIFESTS
).
forEach
{
manifest
->
val
handler
=
ComponentHandler
()
parser
.
parse
(
manifest
,
handler
)
applications
.
addAll
(
handler
.
applications
)
}
this
.
logger
=
context
.
reportsDir
.
file
(
Build
.
ARTIFACT
).
file
(
context
.
name
).
file
(
"report.txt"
).
touch
().
printWriter
()
}
override
fun
onPostTransform
(
context
:
TransformContext
)
{
this
.
logger
.
close
()
}
override
fun
transform
(
context
:
TransformContext
,
klass
:
ClassNode
):
ClassNode
{
if
(!
this
.
applications
.
contains
(
klass
.
className
))
{
return
klass
}
val
method
=
klass
.
methods
?.
find
{
"${it.name}${it.desc}"
==
"onCreate()V"
}
?:
klass
.
defaultOnCreate
()
method
.
instructions
?.
let
{
insn
->
insn
.
findAll
(
RETURN
,
ATHROW
).
forEach
{
ret
->
insn
.
insertBefore
(
ret
,
VarInsnNode
(
ALOAD
,
0
))
insn
.
insertBefore
(
ret
,
MethodInsnNode
(
INVOKESTATIC
,
SHADOW_WEBVIEW
,
"preloadWebView"
,
"(Landroid/app/Application;)V"
,
false
))
logger
.
println
(
" + $SHADOW_WEBVIEW.preloadWebView(Landroid/app/Application;)V before @${if (ret.opcode == ATHROW) "
athrow
" else "
return
"}: ${klass.name}.${method.name}${method.desc} "
)
}
}
return
klass
}
}
private
fun
ClassNode
.
defaultOnCreate
():
MethodNode
=
MethodNode
(
ACC_PUBLIC
,
"onCreate"
,
"()V"
,
null
,
null
).
apply
{
maxStack
=
1
instructions
.
add
(
InsnList
().
apply
{
add
(
VarInsnNode
(
ALOAD
,
0
))
add
(
MethodInsnNode
(
INVOKESPECIAL
,
superName
,
name
,
desc
,
false
))
add
(
InsnNode
(
RETURN
))
})
methods
?.
add
(
this
)
}
private
const
val
SHADOW_WEBVIEW
=
"com/didiglobal/booster/instrument/ShadowWebView"
\ No newline at end of file
booster-transform-webview/src/main/kotlin/com/didiglobal/booster/transform/webview/WebViewVariantProcessor.kt
0 → 100644
浏览文件 @
00486b79
package
com.didiglobal.booster.transform.webview
import
com.android.build.gradle.api.BaseVariant
import
com.didiglobal.booster.gradle.scope
import
com.didiglobal.booster.task.spi.VariantProcessor
import
com.google.auto.service.AutoService
/**
* @author neighbWang
*/
@AutoService
(
VariantProcessor
::
class
)
class
WebViewVariantProcessor
:
VariantProcessor
{
override
fun
process
(
variant
:
BaseVariant
)
{
variant
.
scope
.
globalScope
.
project
.
dependencies
.
add
(
"implementation"
,
"${Build.GROUP}:booster-android-instrument-webview:${Build.VERSION}"
)
}
}
\ No newline at end of file
settings.gradle
浏览文件 @
00486b79
...
...
@@ -5,6 +5,7 @@ include ':booster-android-instrument-media-player'
include
':booster-android-instrument-shared-preferences'
include
':booster-android-instrument-thread'
include
':booster-android-instrument-toast'
include
':booster-android-instrument-webview'
include
':booster-android-gradle-api'
include
':booster-android-gradle-v3_0'
include
':booster-android-gradle-v3_2'
...
...
@@ -28,4 +29,5 @@ include ':booster-transform-toast'
include
':booster-transform-usage'
include
':booster-transform-util'
include
':booster-kotlinx'
include
':booster-transform-webview'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录