问题:在机主空间使用微信正常,在私人空间使用微信发送朋友圈的图片无法显示;
原因:微信升级版本后导致的,与微信协商后,答复是微信不支持多用户,故微信不针对当前情况做出修改。
解决措施:针对微信修改Android原生机制,改变私人空间微信的安装路径。
基本思路:不改变机主空间的安装逻辑,只需要针对私人空间做出改变即可;保存数据的路径不变,只改变安装位置(修改保存apk和lib的目录)。
修改过程如下:
1、在PackageManagerService构造方法中调用ActivityManagerNative.getDefault()返回结果为空。
2、定义全局变量:
private File mWeChatInstallDir = null;
private PackageInfoLite appPkgLite;
3、在PackageManagerService的copyApk方法中,创建/data/app/wechat目录,使用命令行看不到该目录?
可以在PackageManagerService的构造方法中创建:
if (FEATURE_SECURE_SPACE) {
mWeChatInstallDir = new File(mAppInstallDir, "wechat");
mWeChatInstallDir.mkdirs();
FileUtils.setPermissions(mWeChatInstallDir.toString(),
FileUtils.S_IRWXU|FileUtils.S_IRWXG
|FileUtils.S_IROTH|FileUtils.S_IXOTH,
-1, -1);
Slog.d(TAG, "weChatAppDir = "+mWeChatInstallDir);
}
scanDirLI(mWeChatInstallDir, 0, scanFlags | SCAN_REQUIRE_KNOWN, 0);
4、在handlerStartCopy()方法中,为appPkgLite赋值:
appPkgLite = pkgLite;
5、在startCopy()方法中修改路径,
int FLAG_SECURE_BANKING_SPACE = 0x00010000;
boolean isSecureSpace = false;
UserInfo currentUser = null;
try {
currentUser = ActivityManagerNative.getDefault().getCurrentUser();
} catch (RemoteException e) {
e.printStackTrace();
}
if ((currentUser.flags & FLAG_SECURE_BANKING_SPACE) == FLAG_SECURE_BANKING_SPACE) {
isSecureSpace = true;
}
Slog.d(TAG, "isSecureSpace: " + isSecureSpace + "; appPkgLite.packageName: "
+ appPkgLite.packageName + "; mWeChatInstallDir: " + mWeChatInstallDir);
if (appPkgLite.packageName.equals("com.tencent.mm") && isSecureSpace) {
final File wechattempDir = mInstallerService.allocateStageDirLegacy(volumeUuid,
mWeChatInstallDir);
codeFile = wechattempDir;
resourceFile = wechattempDir;
} else {
final File tempDir = mInstallerService.allocateStageDirLegacy(volumeUuid);
codeFile = tempDir;
resourceFile = tempDir;
}
6、在PackageInstallerService类中封装allocateStageDirLegacy方法:
public File allocateStageDirLegacy(String volumeUuid, File weChatFile) throws IOException {
File stageDir = null;
synchronized (mSessions) {
try {
final int sessionId = allocateSessionIdLocked();
Slog.d(TAG, "sessionId = "+sessionId);
mLegacySessions.put(sessionId, true);
/*if (weChatFile.exists()) {
Slog.d(TAG, "wechat, tempStagingDir is exist : "+ weChatFile);
} else {
Slog.d(TAG, "wechat, tempStagingDir is not exist.");
}*/
stageDir = new File(weChatFile, "vmdl" + sessionId + ".tmp");
Slog.d(TAG, "stageDir = "+stageDir.getPath());
/*if (!stageDir.exists()) {
Slog.d(TAG, "wechat, stageDir is not exist");
} else {
Slog.d(TAG, "wechat, stageDir is exist.");
}*/
prepareStageDir(stageDir);
} catch (IllegalStateException e) {
throw new IOException(e);
}
}
return stageDir;
}
7、修改完毕。