Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin uninstall functionality optimized for synchronizing multiple p… #199

Merged
merged 4 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public static final boolean pluginUninstall(String pluginName) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "MP.pluginUninstall ... pluginName=" + pluginName);
}
PluginInfo pi = getPlugin(pluginName, false);
PluginInfo pi = getPlugin(pluginName, true);

// 插件未安装
if (pi == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,11 @@ final void pluginUninstalled(PluginInfo info) {
LogDebug.d(PLUGIN_TAG, "Clear plugin cache. pn=" + info.getName());
}

// 移除卸载插件的HashMap缓存
if (mPlugins.containsKey(info.getName())) {
mPlugins.remove(info.getName());
}

// 移除卸载插件表快照
PluginTable.removeInfo(info);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public void remove(String pn) {
JSONHelper.remove(mJson, i);
}
}
if (mMap.containsKey(pn)) {
mMap.remove(pn);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是也应该清掉mList?

}

public PluginInfo get(String pn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.qihoo360.loader2.CertUtils;
import com.qihoo360.loader2.MP;
import com.qihoo360.loader2.PluginNativeLibsHelper;
import com.qihoo360.mobilesafe.api.Tasks;
import com.qihoo360.mobilesafe.utils.pkg.PackageFilesUtil;
import com.qihoo360.replugin.RePlugin;
import com.qihoo360.replugin.RePluginEventCallbacks;
Expand Down Expand Up @@ -340,10 +341,8 @@ private boolean updateIfNeeded(PluginInfo curInfo) {
LogDebug.d(TAG, "updateIfNeeded: delete plugin. pn=" + curInfo.getName());
}

// 移除插件及其已释放的Dex、Native库等文件
PackageFilesUtil.forceDelete(curInfo.getPendingDelete());
mList.remove(curInfo.getName());
return true;
// 移除插件及其已释放的Dex、Native库等文件并向各进程发送广播,同步更新
return uninstallNow(curInfo.getPendingDelete());

} else if (curInfo.isNeedUpdate()) {
// 需要更新插件?那就直接来
Expand Down Expand Up @@ -436,14 +435,25 @@ private boolean uninstallNow(PluginInfo info) {
// 1. 移除插件及其已释放的Dex、Native库等文件
PackageFilesUtil.forceDelete(info);

// 2. 给各进程发送广播,同步更新
Intent intent = new Intent(PluginInfoUpdater.ACTION_UNINSTALL_PLUGIN);
intent.putExtra("obj", info);
IPC.sendLocalBroadcast2AllSync(RePluginInternal.getAppContext(), intent);

// 3. 保存插件信息到文件中
// 2. 保存插件信息到文件中
mList.remove(info.getName());
mList.save(mContext);

// 3. 给各进程发送广播,同步更新
final Intent intent = new Intent(PluginInfoUpdater.ACTION_UNINSTALL_PLUGIN);
intent.putExtra("obj", info);
// 注意:attachBaseContext内部获取getApplicationContext会为空,则此情况仅在UI线程进行更新
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块儿的注释还是不够清晰。建议改为:

“注意:若在attachBaseContext中调用此方法,则由于此时getApplicationContext为空,导致发送广播时会出现空指针异常。则应该Post一下,待getApplicationContext有值后再发送广播”

if (RePluginInternal.getAppContext().getApplicationContext() != null) {
IPC.sendLocalBroadcast2AllSync(RePluginInternal.getAppContext(), intent);
} else {
Tasks.init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RePlugin.onCreate内部也调用了Tasks.init,不如挪到attachBaseContext中靠前位置,这样这里就不用调用了。

Tasks.post2UI(new Runnable() {
@Override
public void run() {
IPC.sendLocalBroadcast2All(RePluginInternal.getAppContext(), intent);
}
});
}
return true;
}

Expand Down