activity.as(Object).setVariable("enabled", value);
// OR
setvarnum(activity, "enabled", value);
These can set the source to be enabled (value == 1) or not (value == 0). To immediately update the icon, add
function_s(activity, "updateIcon");
The necessary code can be auto-generated by choosing a process flow source as reference for a parameter in the Parameters table.
Since you are asking about doing this is a custom code activity I presume your customer wants to switch the source on/off while the model is running? In that case a different solution would be required, since the "enabled" setting only takes effect on a reset.
A simple decide activity controlled by a global variable or process flow label that sends created tokens directly to a sink can achieve this. (You could of course also have the decide look at the "enabled" variable that is changed in the above code but that seems unnecessarily complicated).

