Skip to content

Commit

Permalink
fix(core.manager): 提供释放db接口,去掉getLastPlugins中关闭db的操作
Browse files Browse the repository at this point in the history
否则并发情况下,其他DB操作可能会因close而中断。

DB只能在不再使用manager时手工释放,sample演示了可以在操作manager的Activity onDestroy时通过enter接口控制manager自行close。

fix #604
  • Loading branch information
shifujun committed Sep 9, 2021
1 parent b3c9a9e commit a499e0d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ final public class Constant {

public static final int FROM_ID_NOOP = 1000;
public static final int FROM_ID_START_ACTIVITY = 1002;
public static final int FROM_ID_CLOSE = 1003;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void onEnterComplete() {
@Override
protected void onDestroy() {
super.onDestroy();
HostApplication.getApp().getPluginManager().enter(this, Constant.FROM_ID_CLOSE, null, null);
mViewGroup.removeAllViews();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public void enter(final Context context, long fromId, Bundle bundle, final Enter
//do nothing.
} else if (fromId == Constant.FROM_ID_START_ACTIVITY) {
onStartActivity(context, bundle, callback);
} else if (fromId == Constant.FROM_ID_CLOSE) {
close();
} else {
throw new IllegalArgumentException("不认识的fromId==" + fromId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public abstract class BasePluginManager {
/**
* 插件信息查询数据库接口
*/
private InstalledDao mInstalledDao;
final private InstalledDao mInstalledDao;

/**
* UI线程的handler
Expand Down Expand Up @@ -296,4 +296,11 @@ private boolean deletePart(InstalledPlugin.Part part) {
public String getAbi() {
return null;
}

/**
* 释放资源
*/
public void close() {
mInstalledDao.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class InstalledDao {

private InstalledPluginDBHelper mDBHelper;
final private InstalledPluginDBHelper mDBHelper;

public InstalledDao(InstalledPluginDBHelper dbHelper) {
mDBHelper = dbHelper;
Expand Down Expand Up @@ -171,7 +171,6 @@ public List<InstalledPlugin> getLastPlugins(int limit) {
for (String uuid : uuids) {
installedPlugins.add(getInstalledPluginByUUID(uuid));
}
db.close();
return installedPlugins;
}

Expand Down Expand Up @@ -218,4 +217,10 @@ private List<ContentValues> parseConfig(PluginConfig pluginConfig, String soDir,
}


/**
* 释放资源
*/
public void close() {
mDBHelper.close();
}
}

0 comments on commit a499e0d

Please sign in to comment.