Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
android_frameworks_base
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
android_frameworks_base
Commits
a2409db8
Commit
a2409db8
authored
Oct 15, 2020
by
aldrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(Application.java): Load Dreamland
在 attach 方法中加入dreamland 框架注入逻辑
parent
ab72fb60
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
1 deletion
+57
-1
Application.java
core/java/android/app/Application.java
+57
-1
No files found.
core/java/android/app/Application.java
View file @
a2409db8
...
...
@@ -29,7 +29,12 @@ import android.content.res.Configuration;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.autofill.AutofillManager
;
import
java.io.File
;
import
dalvik.system.DexClassLoader
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
java.lang.reflect.Method
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.ArrayList
;
/**
...
...
@@ -346,12 +351,63 @@ public class Application extends ContextWrapper implements ComponentCallbacks2 {
/**
* @hide
*/
private
static
AtomicBoolean
hasInited
=
new
AtomicBoolean
(
false
);
private
static
final
TAG
=
"LOAD_DREAMLAND"
;
@UnsupportedAppUsage
/* package */
final
void
attach
(
Context
context
)
{
if
(
hasInited
.
compareAndSet
(
false
,
true
))
{
Log
.
i
(
TAG
,
"attach: "
+
context
.
getPackageName
());
PackageInfo
runtimePkg
=
findDreamlandApkFromInstalled
(
context
);
if
(
runtimePkg
==
null
){
Log
.
w
(
TAG
,
"未找到 dreamland 运行时apk,请安装!"
);
}
else
{
String
targetPackageSourceDir
=
runtimePkg
.
applicationInfo
.
publicSourceDir
;
String
nativeLibraryDir
=
runtimePkg
.
applicationInfo
.
nativeLibraryDir
;
Log
.
i
(
TAG
,
"load apk path: "
+
targetPackageSourceDir
);
Log
.
i
(
TAG
,
"load native path: "
+
nativeLibraryDir
);
String
dexDir
=
dexDir
(
context
).
getAbsolutePath
();
try
{
ClassLoader
classLoader
=
new
DexClassLoader
(
targetPackageSourceDir
,
dexDir
,
nativeLibraryDir
,
context
.
getClassLoader
());
Class
<?>
runtimeClass
=
classLoader
.
loadClass
(
"com.dreamland.runtime.DreamlandRuntime"
);
Method
method
=
runtimeClass
.
getDeclaredMethod
(
"callApplicationAttach"
,
Context
.
class
);
method
.
invoke
(
null
,
context
);
Log
.
i
(
TAG
,
"加载 runtime 成功"
);
}
catch
(
Exception
e
){
Log
.
e
(
TAG
,
"加载模块发生异常"
,
e
);
}
}
}
attachBaseContext
(
context
);
mLoadedApk
=
ContextImpl
.
getImpl
(
context
).
mPackageInfo
;
}
private
static
PackageInfo
findDreamlandApkFromInstalled
(
Context
context
)
{
PackageManager
packageManager
=
context
.
getPackageManager
();
if
(
packageManager
==
null
){
Log
.
w
(
TAG
,
"packageManager 为 null"
);
return
null
;
}
for
(
PackageInfo
pkg
:
packageManager
.
getInstalledPackages
(
PackageManager
.
GET_META_DATA
))
{
if
(
"com.dreamland.runtime"
.
equals
(
pkg
.
packageName
))
return
pkg
;
}
return
null
;
}
private
static
File
dexDir
(
Context
context
)
{
return
makeSureDirExist
(
new
File
(
makeSureDirExist
(
context
.
getDir
(
"dreamland_resource"
,
Context
.
MODE_PRIVATE
)),
"dreamland_runtime_dex"
));
}
private
static
File
makeSureDirExist
(
File
file
)
{
if
(
file
.
exists
()
&&
file
.
isFile
())
{
return
file
;
}
file
.
mkdirs
();
return
file
;
}
@UnsupportedAppUsage
/* package */
void
dispatchActivityPreCreated
(
@NonNull
Activity
activity
,
@Nullable
Bundle
savedInstanceState
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment