Skip to content

Commit

Permalink
Fix (64位手机的问题): 适配64位手机:
Browse files Browse the repository at this point in the history
1、在64位手机上运行:在宿主apk的lib中,如果没有so,则宿主运行在64位进程中。
2、在64位手机上运行:在宿主apk的lib中,如果有so,但没有64位ABI的so,则宿主运行在32位进程中。
3、在32位手机上运行:在宿主apk的lib中,如果有so,但有64位ABI的so,则宿主运行在64位进程中。
所以:在宿主程序运行在64位进程中的时候,默认插件只能加载64位的so;在宿主程序运行在32位进程中的时候,插件只是加载32位的so。

目前,插件so的abi必须与宿主一致,即,宿主64位,插件必须64位;宿主32位,插件必须32位。否则插件是无法加载对应的so的。
  • Loading branch information
cmzy committed Feb 4, 2016
1 parent 4950792 commit 534a970
Showing 1 changed file with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import android.content.pm.Signature;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.RemoteException;
Expand All @@ -54,8 +53,10 @@
import com.morgoo.droidplugin.pm.parser.IntentMatcher;
import com.morgoo.droidplugin.pm.parser.PluginPackageParser;
import com.morgoo.helper.Log;
import com.morgoo.helper.compat.PackageManagerCompat;
import com.morgoo.helper.Utils;
import com.morgoo.helper.compat.BuildCompat;
import com.morgoo.helper.compat.PackageManagerCompat;
import com.morgoo.helper.compat.VMRuntimeCompat;

import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -1009,9 +1010,9 @@ private void copyNativeLibs(Context context, String apkfile, ApplicationInfo app
}

for (String soName : soList.keySet()) {
Log.e(TAG, "==========so name=" + soName);
Log.e(TAG, "try so =" + soName);
Set<String> soPaths = soList.get(soName);
String soPath = findSoPath(soPaths);
String soPath = findSoPath(soPaths, soName);
if (soPath != null) {
File file = new File(nativeLibraryDir, soName);
if (file.exists()) {
Expand Down Expand Up @@ -1061,17 +1062,26 @@ private void copyNativeLibs(Context context, String apkfile, ApplicationInfo app
}
}

private String findSoPath(Set<String> soPaths) {

private String findSoPath(Set<String> soPaths, String soName) {
if (soPaths != null && soPaths.size() > 0) {
for (String soPath : soPaths) {
if (!TextUtils.isEmpty(Build.CPU_ABI) && soPath.contains(Build.CPU_ABI)) {
return soPath;
if (VMRuntimeCompat.is64Bit()) {
//在宿主程序运行在64位进程中的时候,插件的so也只拷贝64位,否则会出现不支持的情况。
for (String soPath : soPaths) {
String abi = soPath.replaceFirst("lib/", "");
abi = abi.replace("/" + soName, "");
if (!TextUtils.isEmpty(abi) && Arrays.binarySearch(BuildCompat.SUPPORTED_64_BIT_ABIS, abi) >= 0) {
return soPath;
}
}
}

for (String soPath : soPaths) {
if (!TextUtils.isEmpty(Build.CPU_ABI2) && soPath.contains(Build.CPU_ABI2)) {
return soPath;
} else {
//在宿主程序运行在32位进程中的时候,插件的so也只拷贝64位,否则会出现不支持的情况。
for (String soPath : soPaths) {
String abi = soPath.replaceFirst("lib/", "");
abi = abi.replace("/" + soName, "");
if (!TextUtils.isEmpty(abi) && Arrays.binarySearch(BuildCompat.SUPPORTED_32_BIT_ABIS, abi) >= 0) {
return soPath;
}
}
}
}
Expand Down Expand Up @@ -1347,12 +1357,12 @@ public void onDestroy() {
}

@Override
public void onActivtyOnNewIntent(ActivityInfo stubInfo, ActivityInfo targetInfo, Intent intent) throws RemoteException{
public void onActivtyOnNewIntent(ActivityInfo stubInfo, ActivityInfo targetInfo, Intent intent) throws RemoteException {
mActivityManagerService.onActivtyOnNewIntent(Binder.getCallingPid(), Binder.getCallingUid(), stubInfo, targetInfo, intent);
}

@Override
public int getMyPid(){
public int getMyPid() {
return android.os.Process.myPid();
}

Expand Down

0 comments on commit 534a970

Please sign in to comment.