- May contain the shared library of an existing addon or a new addon created in plugin's native code, or only provide data e.g. tables/lua extensions
- Has a particular prefix in the package name:
org.fcitx.fcitx5.android.plugin - Has a plugin descriptor in resouce, a XML file which includes:
- plugin api version
- gettext message domain (optional)
- Has a data descriptor and FHS hierarchy in assets
- Always has an activity, either used for plugin version checking, i.e. warn the user if the version from the main program is different, or external configuration UI[1]
- May have foreground services
The main program (fcitx5-android) records a mapping of loaded plugins to their data descriptors (loadedPlugins).
loadedPlugins should be persisted.
Loading plugins:
-
Create a temp descriptor (
temp) that records the new FHS hierarchy being built. Initialize it with main program's data descriptor. -
Using package manager, list all packages with the specific package name prefix.
-
For each package,
- obtain the plugin descriptor (plugin.xml) from its resources.
- If failed to find or decode the plugin descriptor (descriptor.json), drop it.
- If the plugin api version is inconsistent with the one built in, generate a warning message and drop it.
- Go through assets and find out the data descriptor.
- For plugin's data descriptor, if its checksum matches the one in loadedPlugins, directly add the old one to temp and continue to the next plugin.
- If there is a path in plugin's data descriptor conflict with
temp, generate a warning message and drop it. - Copy files whose checksums mismatch with the old ones in
loadedPlugins(if have) from assets to main program's data dir. - Update
temp.
-
Delete files presented in the hierarchy built by loadedPlugins but not temp.
-
Update
loadedPluginstotemp. -
Process main program's data descriptor, which is already implemented.
-
Join each plugin's
nativeLibraryDirtoFCITX_ADDON_DIRS. -
Startup fcitx.
[1]: Does everything have to be implemented in JVM land? How to do that if the configuration requires addon's runtime, instead of a static data? How to reflect the changes to main program's data? Should it always be serialized?
A note by @rocka: for [1],
DocumentsProvidercan be used for those addons that need to read/write main program's data dir, but it's not clear how to deal with the case when some of the addon's code is required to be executed to modify the configuration.