Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
VirtualAPK
提交
7857a51c
V
VirtualAPK
项目概览
门心叼龙
/
VirtualAPK
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VirtualAPK
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7857a51c
编写于
5月 31, 2018
作者:
S
superq_sky
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed some null pointer exception.
上级
c5e3a88b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
74 addition
and
56 deletion
+74
-56
CoreLibrary/src/main/java/com/didi/virtualapk/PluginManager.java
...rary/src/main/java/com/didi/virtualapk/PluginManager.java
+4
-2
CoreLibrary/src/main/java/com/didi/virtualapk/internal/LoadedPlugin.java
.../main/java/com/didi/virtualapk/internal/LoadedPlugin.java
+1
-1
CoreLibrary/src/main/java/com/didi/virtualapk/internal/VAInstrumentation.java
.../java/com/didi/virtualapk/internal/VAInstrumentation.java
+31
-16
CoreLibrary/src/main/java/com/didi/virtualapk/utils/DexUtil.java
...rary/src/main/java/com/didi/virtualapk/utils/DexUtil.java
+11
-23
CoreLibrary/src/main/java/com/didi/virtualapk/utils/PluginUtil.java
...y/src/main/java/com/didi/virtualapk/utils/PluginUtil.java
+14
-5
CoreLibrary/src/main/java/com/didi/virtualapk/utils/RunUtil.java
...rary/src/main/java/com/didi/virtualapk/utils/RunUtil.java
+13
-9
未找到文件。
CoreLibrary/src/main/java/com/didi/virtualapk/PluginManager.java
浏览文件 @
7857a51c
...
...
@@ -253,11 +253,13 @@ public class PluginManager {
}
public
LoadedPlugin
getLoadedPlugin
(
Intent
intent
)
{
ComponentName
component
=
PluginUtil
.
getComponent
(
intent
);
return
getLoadedPlugin
(
component
.
getPackageName
());
return
getLoadedPlugin
(
PluginUtil
.
getComponent
(
intent
));
}
public
LoadedPlugin
getLoadedPlugin
(
ComponentName
component
)
{
if
(
component
==
null
)
{
return
null
;
}
return
this
.
getLoadedPlugin
(
component
.
getPackageName
());
}
...
...
CoreLibrary/src/main/java/com/didi/virtualapk/internal/LoadedPlugin.java
浏览文件 @
7857a51c
...
...
@@ -88,7 +88,7 @@ public final class LoadedPlugin {
if
(
Constants
.
COMBINE_CLASSLOADER
)
{
try
{
DexUtil
.
insertDex
(
loader
);
DexUtil
.
insertDex
(
loader
,
parent
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
CoreLibrary/src/main/java/com/didi/virtualapk/internal/VAInstrumentation.java
浏览文件 @
7857a51c
...
...
@@ -18,6 +18,7 @@ package com.didi.virtualapk.internal;
import
android.annotation.TargetApi
;
import
android.app.Activity
;
import
android.app.Application
;
import
android.app.Fragment
;
import
android.app.Instrumentation
;
import
android.content.ComponentName
;
...
...
@@ -91,30 +92,44 @@ public class VAInstrumentation extends Instrumentation implements Handler.Callba
public
Activity
newActivity
(
ClassLoader
cl
,
String
className
,
Intent
intent
)
throws
InstantiationException
,
IllegalAccessException
,
ClassNotFoundException
{
try
{
cl
.
loadClass
(
className
);
Log
.
i
(
TAG
,
String
.
format
(
"newActivity[%s]"
,
className
));
}
catch
(
ClassNotFoundException
e
)
{
ComponentName
component
=
PluginUtil
.
getComponent
(
intent
);
LoadedPlugin
plugin
=
this
.
mPluginManager
.
getLoadedPlugin
(
component
);
if
(
component
==
null
)
{
return
mBase
.
newActivity
(
cl
,
className
,
intent
);
}
String
targetClassName
=
component
.
getClassName
();
Log
.
i
(
TAG
,
String
.
format
(
"newActivity[%s : %s/%s]"
,
className
,
component
.
getPackageName
(),
targetClassName
));
if
(
plugin
!=
null
)
{
Activity
activity
=
mBase
.
newActivity
(
plugin
.
getClassLoader
(),
targetClassName
,
intent
);
activity
.
setIntent
(
intent
);
try
{
// for 4.1+
Reflector
.
with
(
activity
).
field
(
"mResources"
).
set
(
plugin
.
getResources
());
}
catch
(
Exception
ignored
)
{
// ignored.
}
return
activity
;
LoadedPlugin
plugin
=
this
.
mPluginManager
.
getLoadedPlugin
(
component
);
if
(
plugin
==
null
)
{
return
mBase
.
newActivity
(
cl
,
className
,
intent
);
}
Activity
activity
=
mBase
.
newActivity
(
plugin
.
getClassLoader
(),
targetClassName
,
intent
);
activity
.
setIntent
(
intent
);
try
{
// for 4.1+
Reflector
.
with
(
activity
).
field
(
"mResources"
).
set
(
plugin
.
getResources
());
}
catch
(
Exception
ignored
)
{
// ignored.
}
return
activity
;
}
return
mBase
.
newActivity
(
cl
,
className
,
intent
);
}
@Override
public
Application
newApplication
(
ClassLoader
cl
,
String
className
,
Context
context
)
throws
InstantiationException
,
IllegalAccessException
,
ClassNotFoundException
{
return
mBase
.
newApplication
(
cl
,
className
,
context
);
}
@Override
public
void
callActivityOnCreate
(
Activity
activity
,
Bundle
icicle
)
{
...
...
@@ -159,7 +174,7 @@ public class VAInstrumentation extends Instrumentation implements Handler.Callba
try
{
Reflector
reflector
=
Reflector
.
with
(
r
);
Intent
intent
=
reflector
.
field
(
"intent"
).
get
();
intent
.
setExtrasClassLoader
(
VAInstrumentation
.
class
.
getClassLoader
());
intent
.
setExtrasClassLoader
(
mPluginManager
.
getHostContext
()
.
getClassLoader
());
ActivityInfo
activityInfo
=
reflector
.
field
(
"activityInfo"
).
get
();
if
(
PluginUtil
.
isIntentFromPlugin
(
intent
))
{
...
...
CoreLibrary/src/main/java/com/didi/virtualapk/utils/DexUtil.java
浏览文件 @
7857a51c
...
...
@@ -28,58 +28,46 @@ import java.lang.reflect.Field;
import
java.util.List
;
import
dalvik.system.DexClassLoader
;
import
dalvik.system.PathClassLoader
;
public
class
DexUtil
{
private
static
boolean
sHasInsertedNativeLibrary
=
false
;
public
static
void
insertDex
(
DexClassLoader
dexClassLoader
)
throws
Exception
{
Object
baseDexElements
=
getDexElements
(
getPathList
(
getPathClassLoader
()
));
public
static
void
insertDex
(
DexClassLoader
dexClassLoader
,
ClassLoader
baseClassLoader
)
throws
Exception
{
Object
baseDexElements
=
getDexElements
(
getPathList
(
baseClassLoader
));
Object
newDexElements
=
getDexElements
(
getPathList
(
dexClassLoader
));
Object
allDexElements
=
combineArray
(
baseDexElements
,
newDexElements
);
Object
pathList
=
getPathList
(
getPathClassLoader
()
);
Object
pathList
=
getPathList
(
baseClassLoader
);
Reflector
.
with
(
pathList
).
field
(
"dexElements"
).
set
(
allDexElements
);
insertNativeLibrary
(
dexClassLoader
);
}
private
static
PathClassLoader
getPathClassLoader
()
{
PathClassLoader
pathClassLoader
=
(
PathClassLoader
)
DexUtil
.
class
.
getClassLoader
();
return
pathClassLoader
;
insertNativeLibrary
(
dexClassLoader
,
baseClassLoader
);
}
private
static
Object
getDexElements
(
Object
pathList
)
throws
Exception
{
return
Reflector
.
with
(
pathList
).
field
(
"dexElements"
).
get
();
}
private
static
Object
getPathList
(
Object
baseDexClassLoader
)
throws
Exception
{
private
static
Object
getPathList
(
ClassLoader
baseDexClassLoader
)
throws
Exception
{
return
Reflector
.
with
(
baseDexClassLoader
).
field
(
"pathList"
).
get
();
}
private
static
Object
combineArray
(
Object
firstArray
,
Object
secondArray
)
{
Class
<?>
localClass
=
firstArray
.
getClass
().
getComponentType
();
int
firstArrayLength
=
Array
.
getLength
(
firstArray
);
int
allLength
=
firstArrayLength
+
Array
.
getLength
(
secondArray
);
Object
result
=
Array
.
newInstance
(
localClass
,
allLength
);
for
(
int
k
=
0
;
k
<
allLength
;
++
k
)
{
if
(
k
<
firstArrayLength
)
{
Array
.
set
(
result
,
k
,
Array
.
get
(
firstArray
,
k
));
}
else
{
Array
.
set
(
result
,
k
,
Array
.
get
(
secondArray
,
k
-
firstArrayLength
));
}
}
int
secondArrayLength
=
Array
.
getLength
(
secondArray
);
Object
result
=
Array
.
newInstance
(
localClass
,
firstArrayLength
+
secondArrayLength
);
System
.
arraycopy
(
firstArray
,
0
,
result
,
0
,
firstArrayLength
);
System
.
arraycopy
(
secondArray
,
0
,
result
,
firstArrayLength
,
secondArrayLength
);
return
result
;
}
private
static
synchronized
void
insertNativeLibrary
(
DexClassLoader
dexClassLoader
)
throws
Exception
{
private
static
synchronized
void
insertNativeLibrary
(
DexClassLoader
dexClassLoader
,
ClassLoader
baseClassLoader
)
throws
Exception
{
if
(
sHasInsertedNativeLibrary
)
{
return
;
}
sHasInsertedNativeLibrary
=
true
;
Context
context
=
ActivityThread
.
currentApplication
();
Object
basePathList
=
getPathList
(
getPathClassLoader
()
);
Object
basePathList
=
getPathList
(
baseClassLoader
);
if
(
Build
.
VERSION
.
SDK_INT
>
Build
.
VERSION_CODES
.
LOLLIPOP_MR1
)
{
Reflector
reflector
=
Reflector
.
with
(
basePathList
);
List
<
File
>
nativeLibraryDirectories
=
reflector
.
field
(
"nativeLibraryDirectories"
).
get
();
...
...
CoreLibrary/src/main/java/com/didi/virtualapk/utils/PluginUtil.java
浏览文件 @
7857a51c
...
...
@@ -51,16 +51,22 @@ import java.util.zip.ZipFile;
*/
public
class
PluginUtil
{
public
static
String
getTargetActivity
(
Intent
intent
)
{
return
intent
.
getStringExtra
(
Constants
.
KEY_TARGET_ACTIVITY
);
}
public
static
ComponentName
getComponent
(
Intent
intent
)
{
return
new
ComponentName
(
intent
.
getStringExtra
(
Constants
.
KEY_TARGET_PACKAGE
),
if
(
intent
==
null
)
{
return
null
;
}
if
(
isIntentFromPlugin
(
intent
))
{
return
new
ComponentName
(
intent
.
getStringExtra
(
Constants
.
KEY_TARGET_PACKAGE
),
intent
.
getStringExtra
(
Constants
.
KEY_TARGET_ACTIVITY
));
}
return
intent
.
getComponent
();
}
public
static
boolean
isIntentFromPlugin
(
Intent
intent
)
{
if
(
intent
==
null
)
{
return
false
;
}
return
intent
.
getBooleanExtra
(
Constants
.
KEY_IS_PLUGIN
,
false
);
}
...
...
@@ -166,6 +172,9 @@ public class PluginUtil {
}
public
static
IBinder
getBinder
(
Bundle
bundle
,
String
key
)
{
if
(
bundle
==
null
)
{
return
null
;
}
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN_MR2
)
{
return
bundle
.
getBinder
(
key
);
}
else
{
...
...
CoreLibrary/src/main/java/com/didi/virtualapk/utils/RunUtil.java
浏览文件 @
7857a51c
...
...
@@ -28,7 +28,6 @@ import android.util.Pair;
import
java.util.List
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.ThreadPoolExecutor
;
/**
* Created by renyugang on 16/11/10.
...
...
@@ -77,17 +76,22 @@ public class RunUtil {
return
AsyncTask
.
THREAD_POOL_EXECUTOR
;
}
public
static
String
getProcessNameByPid
(
Context
context
,
int
pid
)
{
ActivityManager
manager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
List
<
ActivityManager
.
RunningAppProcessInfo
>
appProcessList
=
manager
.
getRunningAppProcesses
();
if
(
appProcessList
!=
null
)
{
for
(
ActivityManager
.
RunningAppProcessInfo
appProcessInfo
:
appProcessList
)
{
if
(
pid
==
appProcessInfo
.
pid
)
{
return
appProcessInfo
.
processName
;
private
static
String
getProcessNameByPid
(
Context
context
,
int
pid
)
{
try
{
ActivityManager
manager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
List
<
ActivityManager
.
RunningAppProcessInfo
>
appProcessList
=
manager
.
getRunningAppProcesses
();
if
(
appProcessList
!=
null
)
{
for
(
ActivityManager
.
RunningAppProcessInfo
appProcessInfo
:
appProcessList
)
{
if
(
pid
==
appProcessInfo
.
pid
)
{
return
appProcessInfo
.
processName
;
}
}
}
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录