Skip to content

Commit ac21af3

Browse files
bdcgoogleAndroid (Google) Code Review
authored andcommitted
Merge "Add support for native library paths with instrumentation"
2 parents e1bff46 + d893a89 commit ac21af3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ public final class ActivityThread {
174174
static final ThreadLocal<ActivityThread> sThreadLocal = new ThreadLocal<ActivityThread>();
175175
Instrumentation mInstrumentation;
176176
String mInstrumentationAppDir = null;
177+
String mInstrumentationAppLibraryDir = null;
177178
String mInstrumentationAppPackage = null;
178179
String mInstrumentedAppDir = null;
180+
String mInstrumentedAppLibraryDir = null;
179181
boolean mSystemThread = false;
180182
boolean mJitEnabled = false;
181183

@@ -3936,8 +3938,10 @@ private void handleBindApplication(AppBindData data) {
39363938
}
39373939

39383940
mInstrumentationAppDir = ii.sourceDir;
3941+
mInstrumentationAppLibraryDir = ii.nativeLibraryDir;
39393942
mInstrumentationAppPackage = ii.packageName;
39403943
mInstrumentedAppDir = data.info.getAppDir();
3944+
mInstrumentedAppLibraryDir = data.info.getLibDir();
39413945

39423946
ApplicationInfo instrApp = new ApplicationInfo();
39433947
instrApp.packageName = ii.packageName;

core/java/android/app/LoadedApk.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ public ClassLoader getClassLoader() {
261261

262262
if (mIncludeCode && !mPackageName.equals("android")) {
263263
String zip = mAppDir;
264+
String libraryPath = mLibDir;
264265

265266
/*
266267
* The following is a bit of a hack to inject
@@ -273,15 +274,20 @@ public ClassLoader getClassLoader() {
273274

274275
String instrumentationAppDir =
275276
mActivityThread.mInstrumentationAppDir;
277+
String instrumentationAppLibraryDir =
278+
mActivityThread.mInstrumentationAppLibraryDir;
276279
String instrumentationAppPackage =
277280
mActivityThread.mInstrumentationAppPackage;
278281
String instrumentedAppDir =
279282
mActivityThread.mInstrumentedAppDir;
283+
String instrumentedAppLibraryDir =
284+
mActivityThread.mInstrumentedAppLibraryDir;
280285
String[] instrumentationLibs = null;
281286

282287
if (mAppDir.equals(instrumentationAppDir)
283288
|| mAppDir.equals(instrumentedAppDir)) {
284289
zip = instrumentationAppDir + ":" + instrumentedAppDir;
290+
libraryPath = instrumentationAppLibraryDir + ":" + instrumentedAppLibraryDir;
285291
if (! instrumentedAppDir.equals(instrumentationAppDir)) {
286292
instrumentationLibs =
287293
getLibrariesFor(instrumentationAppPackage);
@@ -301,15 +307,15 @@ public ClassLoader getClassLoader() {
301307
*/
302308

303309
if (ActivityThread.localLOGV)
304-
Slog.v(ActivityThread.TAG, "Class path: " + zip + ", JNI path: " + mLibDir);
310+
Slog.v(ActivityThread.TAG, "Class path: " + zip + ", JNI path: " + libraryPath);
305311

306312
// Temporarily disable logging of disk reads on the Looper thread
307313
// as this is early and necessary.
308314
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
309315

310316
mClassLoader =
311317
ApplicationLoaders.getDefault().getClassLoader(
312-
zip, mLibDir, mBaseClassLoader);
318+
zip, libraryPath, mBaseClassLoader);
313319
initializeJavaContextClassLoader();
314320

315321
StrictMode.setThreadPolicy(oldPolicy);
@@ -442,6 +448,10 @@ public String getAppDir() {
442448
return mAppDir;
443449
}
444450

451+
public String getLibDir() {
452+
return mLibDir;
453+
}
454+
445455
public String getResDir() {
446456
return mResDir;
447457
}

0 commit comments

Comments
 (0)